mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 08:14:47 -07:00
added menu item: game->game information, issue #1 fixed
This commit is contained in:
parent
5ff1fd8ec6
commit
542fd2c5c8
12 changed files with 182 additions and 88 deletions
|
|
@ -1,16 +1,15 @@
|
|||
import "session_event.proto";
|
||||
import "serverinfo_game.proto";
|
||||
import "serverinfo_gametype.proto";
|
||||
|
||||
message Event_GameJoined {
|
||||
extend SessionEvent {
|
||||
optional Event_GameJoined ext = 1009;
|
||||
}
|
||||
optional sint32 room_id = 1;
|
||||
optional sint32 game_id = 2;
|
||||
optional string game_description = 3;
|
||||
optional sint32 host_id = 4;
|
||||
optional sint32 player_id = 5;
|
||||
optional bool spectator = 6;
|
||||
optional bool spectators_can_talk = 7;
|
||||
optional bool spectators_see_everything = 8;
|
||||
optional bool resuming = 9;
|
||||
optional ServerInfo_Game game_info = 1;
|
||||
repeated ServerInfo_GameType game_types = 2;
|
||||
optional sint32 host_id = 3;
|
||||
optional sint32 player_id = 4;
|
||||
optional bool spectator = 5;
|
||||
optional bool resuming = 6;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,22 @@
|
|||
import "serverinfo_user.proto";
|
||||
|
||||
message ServerInfo_Game {
|
||||
optional sint32 room_id = 1;
|
||||
optional sint32 game_id = 2;
|
||||
optional string description = 3;
|
||||
optional bool with_password = 4;
|
||||
optional uint32 player_count = 5;
|
||||
optional sint32 server_id = 1 [default = -1];
|
||||
optional sint32 room_id = 2 [default = -1];
|
||||
optional sint32 game_id = 3 [default = -1];
|
||||
optional string description = 4;
|
||||
optional bool with_password = 5;
|
||||
optional uint32 max_players = 6;
|
||||
optional bool started = 7;
|
||||
repeated sint32 game_types = 8;
|
||||
optional ServerInfo_User creator_info = 9;
|
||||
optional bool only_buddies = 10;
|
||||
optional bool only_registered = 11;
|
||||
optional bool spectators_allowed = 12;
|
||||
optional bool spectators_need_password = 13;
|
||||
optional uint32 spectators_count = 14;
|
||||
optional uint32 start_time = 15;
|
||||
optional sint32 server_id = 16 [default = -1];
|
||||
repeated sint32 game_types = 7;
|
||||
optional ServerInfo_User creator_info = 8;
|
||||
optional bool only_buddies = 9;
|
||||
optional bool only_registered = 10;
|
||||
optional bool spectators_allowed = 11;
|
||||
optional bool spectators_need_password = 12;
|
||||
optional bool spectators_can_chat = 13;
|
||||
optional bool spectators_omniscient = 14;
|
||||
optional uint32 player_count = 30;
|
||||
optional uint32 spectators_count = 31;
|
||||
optional bool started = 50;
|
||||
optional uint32 start_time = 51;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ protected:
|
|||
QMap<QString, Server_AbstractUserInterface *> externalUsers;
|
||||
QMap<int, Server_Room *> rooms;
|
||||
|
||||
virtual qint64 startSession(const QString &userName, const QString &address) { return -1; }
|
||||
virtual qint64 startSession(const QString &userName, const QString &address) { return 0; }
|
||||
virtual void endSession(qint64 sessionId) { }
|
||||
virtual bool userExists(const QString &user) { return false; }
|
||||
virtual AuthenticationResult checkUserPassword(Server_ProtocolHandler *handler, const QString &user, const QString &password, QString &reason) { return UnknownUser; }
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ Server_Game::Server_Game(const ServerInfo_User &_creatorInfo, int _gameId, const
|
|||
|
||||
connect(this, SIGNAL(sigStartGameIfReady()), this, SLOT(doStartGameIfReady()), Qt::QueuedConnection);
|
||||
|
||||
currentReplay->mutable_game_info()->CopyFrom(getInfo());
|
||||
getInfo(*currentReplay->mutable_game_info());
|
||||
|
||||
if (room->getServer()->getGameShouldPing()) {
|
||||
pingClock = new QTimer(this);
|
||||
|
|
@ -271,7 +271,7 @@ void Server_Game::doStartGameIfReady()
|
|||
replayList.append(currentReplay);
|
||||
currentReplay = new GameReplay;
|
||||
currentReplay->set_replay_id(room->getServer()->getNextReplayId());
|
||||
currentReplay->mutable_game_info()->CopyFrom(getInfo());
|
||||
getInfo(*currentReplay->mutable_game_info());
|
||||
|
||||
Event_GameStateChanged omniscientEvent;
|
||||
QListIterator<ServerInfo_Player> omniscientGameStateIterator(getGameState(0, true, true));
|
||||
|
|
@ -294,7 +294,10 @@ void Server_Game::doStartGameIfReady()
|
|||
nextTurn();
|
||||
|
||||
locker.unlock();
|
||||
emit gameInfoChanged(getInfo());
|
||||
|
||||
ServerInfo_Game gameInfo;
|
||||
getInfo(gameInfo);
|
||||
emit gameInfoChanged(gameInfo);
|
||||
}
|
||||
|
||||
void Server_Game::startGameIfReady()
|
||||
|
|
@ -390,8 +393,11 @@ void Server_Game::addPlayer(Server_AbstractUserInterface *userInterface, Respons
|
|||
sendGameEventContainer(prepareGameEvent(Event_GameHostChanged(), hostId));
|
||||
}
|
||||
|
||||
if (broadcastUpdate)
|
||||
emit gameInfoChanged(getInfo());
|
||||
if (broadcastUpdate) {
|
||||
ServerInfo_Game gameInfo;
|
||||
getInfo(gameInfo);
|
||||
emit gameInfoChanged(gameInfo);
|
||||
}
|
||||
|
||||
if ((newPlayer->getUserInfo()->user_level() & ServerInfo_User::IsRegistered) && !spectator)
|
||||
room->getServer()->addPersistentPlayer(playerName, room->getId(), gameId, newPlayer->getPlayerId());
|
||||
|
|
@ -439,7 +445,10 @@ void Server_Game::removePlayer(Server_Player *player)
|
|||
if (gameStarted && playerActive)
|
||||
nextTurn();
|
||||
}
|
||||
emit gameInfoChanged(getInfo());
|
||||
|
||||
ServerInfo_Game gameInfo;
|
||||
getInfo(gameInfo);
|
||||
emit gameInfoChanged(gameInfo);
|
||||
}
|
||||
|
||||
void Server_Game::removeArrowsToPlayer(GameEventStorage &ges, Server_Player *player)
|
||||
|
|
@ -672,15 +681,19 @@ QList<ServerInfo_Player> Server_Game::getGameState(Server_Player *playerWhosAski
|
|||
void Server_Game::createGameJoinedEvent(Server_Player *player, ResponseContainer &rc, bool resuming)
|
||||
{
|
||||
Event_GameJoined event1;
|
||||
event1.set_room_id(room->getId());
|
||||
event1.set_game_id(gameId);
|
||||
event1.set_game_description(description.toStdString());
|
||||
getInfo(*event1.mutable_game_info());
|
||||
event1.set_host_id(hostId);
|
||||
event1.set_player_id(player->getPlayerId());
|
||||
event1.set_spectator(player->getSpectator());
|
||||
event1.set_spectators_can_talk(spectatorsCanTalk);
|
||||
event1.set_spectators_see_everything(spectatorsSeeEverything);
|
||||
event1.set_resuming(resuming);
|
||||
if (resuming) {
|
||||
const QStringList &allGameTypes = room->getGameTypes();
|
||||
for (int i = 0; i < allGameTypes.size(); ++i) {
|
||||
ServerInfo_GameType *newGameType = event1.add_game_types();
|
||||
newGameType->set_game_type_id(i);
|
||||
newGameType->set_description(allGameTypes[i].toStdString());
|
||||
}
|
||||
}
|
||||
rc.enqueuePostResponseItem(ServerMessage::SESSION_EVENT, Server_AbstractUserInterface::prepareSessionEvent(event1));
|
||||
|
||||
Event_GameStateChanged event2;
|
||||
|
|
@ -728,11 +741,10 @@ GameEventContainer *Server_Game::prepareGameEvent(const ::google::protobuf::Mess
|
|||
return cont;
|
||||
}
|
||||
|
||||
ServerInfo_Game Server_Game::getInfo() const
|
||||
void Server_Game::getInfo(ServerInfo_Game &result) const
|
||||
{
|
||||
QMutexLocker locker(&gameMutex);
|
||||
|
||||
ServerInfo_Game result;
|
||||
result.set_room_id(room->getId());
|
||||
result.set_game_id(getGameId());
|
||||
if (!players.isEmpty()) {
|
||||
|
|
@ -749,8 +761,9 @@ ServerInfo_Game Server_Game::getInfo() const
|
|||
result.set_only_registered(onlyRegistered);
|
||||
result.set_spectators_allowed(getSpectatorsAllowed());
|
||||
result.set_spectators_need_password(getSpectatorsNeedPassword());
|
||||
result.set_spectators_can_chat(spectatorsCanTalk);
|
||||
result.set_spectators_omniscient(spectatorsSeeEverything);
|
||||
result.set_spectators_count(getSpectatorCount());
|
||||
result.set_start_time(startTime.toTime_t());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ public:
|
|||
Server_Game(const ServerInfo_User &_creatorInfo, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, const QList<int> &_gameTypes, bool _onlyBuddies, bool _onlyRegistered, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, Server_Room *parent);
|
||||
~Server_Game();
|
||||
Server_Room *getRoom() const { return room; }
|
||||
ServerInfo_Game getInfo() const;
|
||||
void getInfo(ServerInfo_Game &result) const;
|
||||
int getHostId() const { return hostId; }
|
||||
ServerInfo_User *getCreatorInfo() const { return creatorInfo; }
|
||||
bool getGameStarted() const { return gameStarted; }
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ ServerInfo_Room Server_Room::getInfo(bool complete, bool showGameTypes, bool upd
|
|||
if (complete) {
|
||||
QMapIterator<int, Server_Game *> gameIterator(games);
|
||||
while (gameIterator.hasNext())
|
||||
result.add_game_list()->CopyFrom(gameIterator.next().value()->getInfo());
|
||||
gameIterator.next().value()->getInfo(*result.add_game_list());
|
||||
if (includeExternalData) {
|
||||
QMapIterator<int, ServerInfo_Game> externalGameIterator(externalGames);
|
||||
while (externalGameIterator.hasNext())
|
||||
|
|
@ -231,9 +231,11 @@ void Server_Room::addGame(Server_Game *game)
|
|||
|
||||
game->gameMutex.lock();
|
||||
games.insert(game->getGameId(), game);
|
||||
emit gameListChanged(game->getInfo());
|
||||
ServerInfo_Game gameInfo;
|
||||
game->getInfo(gameInfo);
|
||||
game->gameMutex.unlock();
|
||||
|
||||
emit gameListChanged(gameInfo);
|
||||
emit roomInfoChanged(getInfo(false, false, true));
|
||||
}
|
||||
|
||||
|
|
@ -243,7 +245,11 @@ void Server_Room::removeGame(Server_Game *game)
|
|||
// called from ~Server_Game, which locks both mutexes anyway beforehand.
|
||||
|
||||
disconnect(game, 0, this, 0);
|
||||
emit gameListChanged(game->getInfo());
|
||||
|
||||
ServerInfo_Game gameInfo;
|
||||
game->getInfo(gameInfo);
|
||||
emit gameListChanged(gameInfo);
|
||||
|
||||
games.remove(game->getGameId());
|
||||
|
||||
emit roomInfoChanged(getInfo(false, false, true));
|
||||
|
|
@ -269,8 +275,11 @@ QList<ServerInfo_Game> Server_Room::getGamesOfUser(const QString &userName) cons
|
|||
QMapIterator<int, Server_Game *> gamesIterator(games);
|
||||
while (gamesIterator.hasNext()) {
|
||||
Server_Game *game = gamesIterator.next().value();
|
||||
if (game->containsUser(userName))
|
||||
result.append(game->getInfo());
|
||||
if (game->containsUser(userName)) {
|
||||
ServerInfo_Game gameInfo;
|
||||
game->getInfo(gameInfo);
|
||||
result.append(gameInfo);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue