mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 08:14:47 -07:00
Fixed elevation of spectator rights; added some spectator options; closes bug 0000005
This commit is contained in:
parent
604d1ffa94
commit
befafa28ae
26 changed files with 430 additions and 220 deletions
|
|
@ -104,7 +104,7 @@ void Command::processResponse(ProtocolResponse *response)
|
|||
}
|
||||
|
||||
CommandContainer::CommandContainer(const QList<Command *> &_commandList, int _cmdId)
|
||||
: ProtocolItem("container", "cmd"), ticks(0), resp(0), gameEventQueuePublic(0), gameEventQueuePrivate(0)
|
||||
: ProtocolItem("container", "cmd"), ticks(0), resp(0), gameEventQueuePublic(0), gameEventQueueOmniscient(0), gameEventQueuePrivate(0)
|
||||
{
|
||||
if (_cmdId == -1)
|
||||
_cmdId = lastCmdId++;
|
||||
|
|
@ -137,6 +137,13 @@ void CommandContainer::enqueueGameEventPublic(GameEvent *event, int gameId)
|
|||
gameEventQueuePublic->appendItem(event);
|
||||
}
|
||||
|
||||
void CommandContainer::enqueueGameEventOmniscient(GameEvent *event, int gameId)
|
||||
{
|
||||
if (!gameEventQueueOmniscient)
|
||||
gameEventQueueOmniscient = new GameEventContainer(QList<GameEvent *>(), gameId);
|
||||
gameEventQueueOmniscient->appendItem(event);
|
||||
}
|
||||
|
||||
void CommandContainer::enqueueGameEventPrivate(GameEvent *event, int gameId)
|
||||
{
|
||||
if (!gameEventQueuePrivate)
|
||||
|
|
|
|||
|
|
@ -103,6 +103,7 @@ private:
|
|||
ProtocolResponse *resp;
|
||||
QList<ProtocolItem *> itemQueue;
|
||||
GameEventContainer *gameEventQueuePublic;
|
||||
GameEventContainer *gameEventQueueOmniscient;
|
||||
GameEventContainer *gameEventQueuePrivate;
|
||||
public:
|
||||
CommandContainer(const QList<Command *> &_commandList = QList<Command *>(), int _cmdId = -1);
|
||||
|
|
@ -119,6 +120,8 @@ public:
|
|||
void enqueueItem(ProtocolItem *item) { itemQueue.append(item); }
|
||||
GameEventContainer *getGameEventQueuePublic() const { return gameEventQueuePublic; }
|
||||
void enqueueGameEventPublic(GameEvent *event, int gameId);
|
||||
GameEventContainer *getGameEventQueueOmniscient() const { return gameEventQueueOmniscient; }
|
||||
void enqueueGameEventOmniscient(GameEvent *event, int gameId);
|
||||
GameEventContainer *getGameEventQueuePrivate() const { return gameEventQueuePrivate; }
|
||||
void enqueueGameEventPrivate(GameEvent *event, int gameId);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ ServerInfo_ChatUser::ServerInfo_ChatUser(const QString &_name)
|
|||
insertItem(new SerializableItem_String("name", _name));
|
||||
}
|
||||
|
||||
ServerInfo_Game::ServerInfo_Game(int _gameId, const QString &_description, bool _hasPassword, int _playerCount, int _maxPlayers, const QString &_creatorName, bool _spectatorsAllowed, int _spectatorCount)
|
||||
ServerInfo_Game::ServerInfo_Game(int _gameId, const QString &_description, bool _hasPassword, int _playerCount, int _maxPlayers, const QString &_creatorName, bool _spectatorsAllowed, bool _spectatorsNeedPassword, int _spectatorCount)
|
||||
: SerializableItem_Map("game")
|
||||
{
|
||||
insertItem(new SerializableItem_Int("game_id", _gameId));
|
||||
|
|
@ -28,6 +28,7 @@ ServerInfo_Game::ServerInfo_Game(int _gameId, const QString &_description, bool
|
|||
insertItem(new SerializableItem_Int("max_players", _maxPlayers));
|
||||
insertItem(new SerializableItem_String("creator_name", _creatorName));
|
||||
insertItem(new SerializableItem_Bool("spectators_allowed", _spectatorsAllowed));
|
||||
insertItem(new SerializableItem_Bool("spectators_need_password", _spectatorsNeedPassword));
|
||||
insertItem(new SerializableItem_Int("spectator_count", _spectatorCount));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public:
|
|||
|
||||
class ServerInfo_Game : public SerializableItem_Map {
|
||||
public:
|
||||
ServerInfo_Game(int _gameId = -1, const QString &_description = QString(), bool _hasPassword = false, int _playerCount = -1, int _maxPlayers = -1, const QString &_creatorName = QString(), bool _spectatorsAllowed = false, int _spectatorCount = -1);
|
||||
ServerInfo_Game(int _gameId = -1, const QString &_description = QString(), bool _hasPassword = false, int _playerCount = -1, int _maxPlayers = -1, const QString &_creatorName = QString(), bool _spectatorsAllowed = false, bool _spectatorsNeedPassword = false, int _spectatorCount = -1);
|
||||
static SerializableItem *newItem() { return new ServerInfo_Game; }
|
||||
int getGameId() const { return static_cast<SerializableItem_Int *>(itemMap.value("game_id"))->getData(); }
|
||||
QString getDescription() const { return static_cast<SerializableItem_String *>(itemMap.value("description"))->getData(); }
|
||||
|
|
@ -48,6 +48,7 @@ public:
|
|||
int getMaxPlayers() const { return static_cast<SerializableItem_Int *>(itemMap.value("max_players"))->getData(); }
|
||||
QString getCreatorName() const { return static_cast<SerializableItem_String *>(itemMap.value("creator_name"))->getData(); }
|
||||
bool getSpectatorsAllowed() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_allowed"))->getData(); }
|
||||
bool getSpectatorsNeedPassword() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_need_password"))->getData(); }
|
||||
int getSpectatorCount() const { return static_cast<SerializableItem_Int *>(itemMap.value("spectator_count"))->getData(); }
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -58,13 +58,16 @@ Command_ListGames::Command_ListGames()
|
|||
: Command("list_games")
|
||||
{
|
||||
}
|
||||
Command_CreateGame::Command_CreateGame(const QString &_description, const QString &_password, int _maxPlayers, bool _spectatorsAllowed)
|
||||
Command_CreateGame::Command_CreateGame(const QString &_description, const QString &_password, int _maxPlayers, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything)
|
||||
: Command("create_game")
|
||||
{
|
||||
insertItem(new SerializableItem_String("description", _description));
|
||||
insertItem(new SerializableItem_String("password", _password));
|
||||
insertItem(new SerializableItem_Int("max_players", _maxPlayers));
|
||||
insertItem(new SerializableItem_Bool("spectators_allowed", _spectatorsAllowed));
|
||||
insertItem(new SerializableItem_Bool("spectators_need_password", _spectatorsNeedPassword));
|
||||
insertItem(new SerializableItem_Bool("spectators_can_talk", _spectatorsCanTalk));
|
||||
insertItem(new SerializableItem_Bool("spectators_see_everything", _spectatorsSeeEverything));
|
||||
}
|
||||
Command_JoinGame::Command_JoinGame(int _gameId, const QString &_password, bool _spectator)
|
||||
: Command("join_game")
|
||||
|
|
@ -297,13 +300,15 @@ Event_ServerMessage::Event_ServerMessage(const QString &_message)
|
|||
{
|
||||
insertItem(new SerializableItem_String("message", _message));
|
||||
}
|
||||
Event_GameJoined::Event_GameJoined(int _gameId, const QString &_gameDescription, int _playerId, bool _spectator, bool _resuming)
|
||||
Event_GameJoined::Event_GameJoined(int _gameId, const QString &_gameDescription, int _playerId, bool _spectator, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, bool _resuming)
|
||||
: GenericEvent("game_joined")
|
||||
{
|
||||
insertItem(new SerializableItem_Int("game_id", _gameId));
|
||||
insertItem(new SerializableItem_String("game_description", _gameDescription));
|
||||
insertItem(new SerializableItem_Int("player_id", _playerId));
|
||||
insertItem(new SerializableItem_Bool("spectator", _spectator));
|
||||
insertItem(new SerializableItem_Bool("spectators_can_talk", _spectatorsCanTalk));
|
||||
insertItem(new SerializableItem_Bool("spectators_see_everything", _spectatorsSeeEverything));
|
||||
insertItem(new SerializableItem_Bool("resuming", _resuming));
|
||||
}
|
||||
Event_ChatJoinChannel::Event_ChatJoinChannel(const QString &_channel, const QString &_playerName)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
1:chat_leave_channel
|
||||
1:chat_say:s,message
|
||||
0:list_games
|
||||
0:create_game:s,description:s,password:i,max_players:b,spectators_allowed
|
||||
0:create_game:s,description:s,password:i,max_players:b,spectators_allowed:b,spectators_need_password:b,spectators_can_talk:b,spectators_see_everything
|
||||
0:join_game:i,game_id:s,password:b,spectator
|
||||
2:leave_game
|
||||
2:say:s,message
|
||||
|
|
@ -49,7 +49,7 @@
|
|||
3:dump_zone:i,zone_owner_id:s,zone:i,number_cards
|
||||
3:stop_dump_zone:i,zone_owner_id:s,zone
|
||||
4:server_message:s,message
|
||||
4:game_joined:i,game_id:s,game_description:i,player_id:b,spectator:b,resuming
|
||||
4:game_joined:i,game_id:s,game_description:i,player_id:b,spectator:b,spectators_can_talk:b,spectators_see_everything:b,resuming
|
||||
5:chat_join_channel:s,player_name
|
||||
5:chat_leave_channel:s,player_name
|
||||
5:chat_say:s,player_name:s,message
|
||||
|
|
|
|||
|
|
@ -99,11 +99,14 @@ public:
|
|||
class Command_CreateGame : public Command {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Command_CreateGame(const QString &_description = QString(), const QString &_password = QString(), int _maxPlayers = -1, bool _spectatorsAllowed = false);
|
||||
Command_CreateGame(const QString &_description = QString(), const QString &_password = QString(), int _maxPlayers = -1, bool _spectatorsAllowed = false, bool _spectatorsNeedPassword = false, bool _spectatorsCanTalk = false, bool _spectatorsSeeEverything = false);
|
||||
QString getDescription() const { return static_cast<SerializableItem_String *>(itemMap.value("description"))->getData(); };
|
||||
QString getPassword() const { return static_cast<SerializableItem_String *>(itemMap.value("password"))->getData(); };
|
||||
int getMaxPlayers() const { return static_cast<SerializableItem_Int *>(itemMap.value("max_players"))->getData(); };
|
||||
bool getSpectatorsAllowed() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_allowed"))->getData(); };
|
||||
bool getSpectatorsNeedPassword() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_need_password"))->getData(); };
|
||||
bool getSpectatorsCanTalk() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_can_talk"))->getData(); };
|
||||
bool getSpectatorsSeeEverything() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_see_everything"))->getData(); };
|
||||
static SerializableItem *newItem() { return new Command_CreateGame; }
|
||||
int getItemId() const { return ItemId_Command_CreateGame; }
|
||||
};
|
||||
|
|
@ -455,11 +458,13 @@ public:
|
|||
class Event_GameJoined : public GenericEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_GameJoined(int _gameId = -1, const QString &_gameDescription = QString(), int _playerId = -1, bool _spectator = false, bool _resuming = false);
|
||||
Event_GameJoined(int _gameId = -1, const QString &_gameDescription = QString(), int _playerId = -1, bool _spectator = false, bool _spectatorsCanTalk = false, bool _spectatorsSeeEverything = false, bool _resuming = false);
|
||||
int getGameId() const { return static_cast<SerializableItem_Int *>(itemMap.value("game_id"))->getData(); };
|
||||
QString getGameDescription() const { return static_cast<SerializableItem_String *>(itemMap.value("game_description"))->getData(); };
|
||||
int getPlayerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("player_id"))->getData(); };
|
||||
bool getSpectator() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectator"))->getData(); };
|
||||
bool getSpectatorsCanTalk() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_can_talk"))->getData(); };
|
||||
bool getSpectatorsSeeEverything() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_see_everything"))->getData(); };
|
||||
bool getResuming() const { return static_cast<SerializableItem_Bool *>(itemMap.value("resuming"))->getData(); };
|
||||
static SerializableItem *newItem() { return new Event_GameJoined; }
|
||||
int getItemId() const { return ItemId_Event_GameJoined; }
|
||||
|
|
|
|||
|
|
@ -32,9 +32,9 @@ Server::~Server()
|
|||
{
|
||||
}
|
||||
|
||||
Server_Game *Server::createGame(const QString &description, const QString &password, int maxPlayers, bool spectatorsAllowed, Server_ProtocolHandler *creator)
|
||||
Server_Game *Server::createGame(const QString &description, const QString &password, int maxPlayers, bool spectatorsAllowed, bool spectatorsNeedPassword, bool spectatorsCanTalk, bool spectatorsSeeEverything, Server_ProtocolHandler *creator)
|
||||
{
|
||||
Server_Game *newGame = new Server_Game(creator, nextGameId++, description, password, maxPlayers, spectatorsAllowed, this);
|
||||
Server_Game *newGame = new Server_Game(creator, nextGameId++, description, password, maxPlayers, spectatorsAllowed, spectatorsNeedPassword, spectatorsCanTalk, spectatorsSeeEverything, this);
|
||||
games.insert(newGame->getGameId(), newGame);
|
||||
connect(newGame, SIGNAL(gameClosing()), this, SLOT(gameClosing()));
|
||||
|
||||
|
|
@ -84,6 +84,7 @@ void Server::broadcastGameListUpdate(Server_Game *game)
|
|||
game->getMaxPlayers(),
|
||||
game->getCreatorName(),
|
||||
game->getSpectatorsAllowed(),
|
||||
game->getSpectatorsNeedPassword(),
|
||||
game->getSpectatorCount()
|
||||
));
|
||||
else
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ public:
|
|||
void removeClient(Server_ProtocolHandler *player);
|
||||
void closeOldSession(const QString &playerName);
|
||||
virtual QString getLoginMessage() const = 0;
|
||||
Server_Game *createGame(const QString &description, const QString &password, int maxPlayers, bool spectatorsAllowed, Server_ProtocolHandler *creator);
|
||||
Server_Game *createGame(const QString &description, const QString &password, int maxPlayers, bool spectatorsAllowed, bool spectatorsNeedPassword, bool spectatorsCanTalk, bool spectatorsSeeEverything, Server_ProtocolHandler *creator);
|
||||
|
||||
virtual int getMaxGameInactivityTime() const = 0;
|
||||
virtual int getMaxPlayerInactivityTime() const = 0;
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@
|
|||
#include <QSqlQuery>
|
||||
#include <QTimer>
|
||||
|
||||
Server_Game::Server_Game(Server_ProtocolHandler *_creator, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, bool _spectatorsAllowed, QObject *parent)
|
||||
: QObject(parent), gameStarted(false), gameId(_gameId), description(_description), password(_password), maxPlayers(_maxPlayers), activePlayer(-1), activePhase(-1), spectatorsAllowed(_spectatorsAllowed), inactivityCounter(0)
|
||||
Server_Game::Server_Game(Server_ProtocolHandler *_creator, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, QObject *parent)
|
||||
: QObject(parent), gameStarted(false), gameId(_gameId), description(_description), password(_password), maxPlayers(_maxPlayers), activePlayer(-1), activePhase(-1), spectatorsAllowed(_spectatorsAllowed), spectatorsNeedPassword(_spectatorsNeedPassword), spectatorsCanTalk(_spectatorsCanTalk), spectatorsSeeEverything(_spectatorsSeeEverything), inactivityCounter(0)
|
||||
{
|
||||
creator = addPlayer(_creator, false, false);
|
||||
|
||||
|
|
@ -168,7 +168,7 @@ void Server_Game::stopGameIfFinished()
|
|||
|
||||
ResponseCode Server_Game::checkJoin(const QString &_password, bool spectator)
|
||||
{
|
||||
if (_password != password)
|
||||
if ((_password != password) && !(spectator && !spectatorsNeedPassword))
|
||||
return RespWrongPassword;
|
||||
if (spectator) {
|
||||
if (!spectatorsAllowed)
|
||||
|
|
@ -292,13 +292,26 @@ void Server_Game::sendGameEvent(GameEvent *event, GameEventContext *context, Ser
|
|||
sendGameEventContainer(new GameEventContainer(QList<GameEvent *>() << event, -1, context), exclude);
|
||||
}
|
||||
|
||||
void Server_Game::sendGameEventContainer(GameEventContainer *cont, Server_Player *exclude)
|
||||
void Server_Game::sendGameEventContainer(GameEventContainer *cont, Server_Player *exclude, bool excludeOmniscient)
|
||||
{
|
||||
cont->setGameId(gameId);
|
||||
QMapIterator<int, Server_Player *> playerIterator(players);
|
||||
while (playerIterator.hasNext()) {
|
||||
Server_Player *p = playerIterator.next().value();
|
||||
if (p != exclude)
|
||||
if ((p != exclude) && !(excludeOmniscient && p->getSpectator() && spectatorsSeeEverything))
|
||||
p->sendProtocolItem(cont, false);
|
||||
}
|
||||
|
||||
delete cont;
|
||||
}
|
||||
|
||||
void Server_Game::sendGameEventContainerOmniscient(GameEventContainer *cont, Server_Player *exclude)
|
||||
{
|
||||
cont->setGameId(gameId);
|
||||
QMapIterator<int, Server_Player *> playerIterator(players);
|
||||
while (playerIterator.hasNext()) {
|
||||
Server_Player *p = playerIterator.next().value();
|
||||
if ((p != exclude) && (p->getSpectator() && spectatorsSeeEverything))
|
||||
p->sendProtocolItem(cont, false);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,6 +40,9 @@ private:
|
|||
int maxPlayers;
|
||||
int activePlayer, activePhase;
|
||||
bool spectatorsAllowed;
|
||||
bool spectatorsNeedPassword;
|
||||
bool spectatorsCanTalk;
|
||||
bool spectatorsSeeEverything;
|
||||
int inactivityCounter;
|
||||
QTimer *pingClock;
|
||||
signals:
|
||||
|
|
@ -47,7 +50,7 @@ signals:
|
|||
private slots:
|
||||
void pingClockTimeout();
|
||||
public:
|
||||
Server_Game(Server_ProtocolHandler *_creator, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, bool _spectatorsAllowed, QObject *parent = 0);
|
||||
Server_Game(Server_ProtocolHandler *_creator, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, QObject *parent = 0);
|
||||
~Server_Game();
|
||||
Server_Player *getCreator() const { return creator; }
|
||||
QString getCreatorName() const { return creator ? creator->getPlayerName() : QString(); }
|
||||
|
|
@ -61,6 +64,9 @@ public:
|
|||
QString getPassword() const { return password; }
|
||||
int getMaxPlayers() const { return maxPlayers; }
|
||||
bool getSpectatorsAllowed() const { return spectatorsAllowed; }
|
||||
bool getSpectatorsNeedPassword() const { return spectatorsNeedPassword; }
|
||||
bool getSpectatorsCanTalk() const { return spectatorsCanTalk; }
|
||||
bool getSpectatorsSeeEverything() const { return spectatorsSeeEverything; }
|
||||
ResponseCode checkJoin(const QString &_password, bool spectator);
|
||||
Server_Player *addPlayer(Server_ProtocolHandler *handler, bool spectator, bool broadcastUpdate = true);
|
||||
void removePlayer(Server_Player *player);
|
||||
|
|
@ -73,7 +79,8 @@ public:
|
|||
|
||||
QList<ServerInfo_Player *> getGameState(Server_Player *playerWhosAsking) const;
|
||||
void sendGameEvent(GameEvent *event, GameEventContext *context = 0, Server_Player *exclude = 0);
|
||||
void sendGameEventContainer(GameEventContainer *cont, Server_Player *exclude = 0);
|
||||
void sendGameEventContainer(GameEventContainer *cont, Server_Player *exclude = 0, bool excludeOmniscient = false);
|
||||
void sendGameEventContainerOmniscient(GameEventContainer *cont, Server_Player *exclude = 0);
|
||||
void sendGameEventToPlayer(Server_Player *player, GameEvent *event);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -148,8 +148,13 @@ void Server_ProtocolHandler::processCommandContainer(CommandContainer *cont)
|
|||
Server_Game *game = games.value(gQPublic->getGameId()).first;
|
||||
Server_Player *player = games.value(gQPublic->getGameId()).second;
|
||||
GameEventContainer *gQPrivate = cont->getGameEventQueuePrivate();
|
||||
GameEventContainer *gQOmniscient = cont->getGameEventQueueOmniscient();
|
||||
if (gQPrivate) {
|
||||
game->sendGameEventContainer(gQPublic, player);
|
||||
if (gQOmniscient) {
|
||||
game->sendGameEventContainer(gQPublic, player, true);
|
||||
game->sendGameEventContainerOmniscient(gQOmniscient, player);
|
||||
} else
|
||||
game->sendGameEventContainer(gQPublic, player);
|
||||
player->sendProtocolItem(gQPrivate);
|
||||
} else
|
||||
game->sendGameEventContainer(gQPublic);
|
||||
|
|
@ -214,7 +219,7 @@ ResponseCode Server_ProtocolHandler::cmdLogin(Command_Login *cmd, CommandContain
|
|||
gamePlayers[j]->setProtocolHandler(this);
|
||||
games.insert(serverGames[i]->getGameId(), QPair<Server_Game *, Server_Player *>(serverGames[i], gamePlayers[j]));
|
||||
|
||||
enqueueProtocolItem(new Event_GameJoined(serverGames[i]->getGameId(), serverGames[i]->getDescription(), gamePlayers[j]->getPlayerId(), gamePlayers[j]->getSpectator(), true));
|
||||
enqueueProtocolItem(new Event_GameJoined(serverGames[i]->getGameId(), serverGames[i]->getDescription(), gamePlayers[j]->getPlayerId(), gamePlayers[j]->getSpectator(), serverGames[i]->getSpectatorsCanTalk(), serverGames[i]->getSpectatorsSeeEverything(), true));
|
||||
enqueueProtocolItem(GameEventContainer::makeNew(new Event_GameStateChanged(serverGames[i]->getGameStarted(), serverGames[i]->getActivePlayer(), serverGames[i]->getActivePhase(), serverGames[i]->getGameState(gamePlayers[j])), serverGames[i]->getGameId()));
|
||||
}
|
||||
}
|
||||
|
|
@ -285,6 +290,7 @@ ResponseCode Server_ProtocolHandler::cmdListGames(Command_ListGames * /*cmd*/, C
|
|||
g->getMaxPlayers(),
|
||||
g->getCreatorName(),
|
||||
g->getSpectatorsAllowed(),
|
||||
g->getSpectatorsNeedPassword(),
|
||||
g->getSpectatorCount()
|
||||
));
|
||||
}
|
||||
|
|
@ -296,11 +302,11 @@ ResponseCode Server_ProtocolHandler::cmdListGames(Command_ListGames * /*cmd*/, C
|
|||
|
||||
ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd, CommandContainer *cont)
|
||||
{
|
||||
Server_Game *game = server->createGame(cmd->getDescription(), cmd->getPassword(), cmd->getMaxPlayers(), cmd->getSpectatorsAllowed(), this);
|
||||
Server_Game *game = server->createGame(cmd->getDescription(), cmd->getPassword(), cmd->getMaxPlayers(), cmd->getSpectatorsAllowed(), cmd->getSpectatorsNeedPassword(), cmd->getSpectatorsCanTalk(), cmd->getSpectatorsSeeEverything(), this);
|
||||
Server_Player *creator = game->getCreator();
|
||||
games.insert(game->getGameId(), QPair<Server_Game *, Server_Player *>(game, creator));
|
||||
|
||||
enqueueProtocolItem(new Event_GameJoined(game->getGameId(), game->getDescription(), creator->getPlayerId(), false, false));
|
||||
enqueueProtocolItem(new Event_GameJoined(game->getGameId(), game->getDescription(), creator->getPlayerId(), false, game->getSpectatorsCanTalk(), game->getSpectatorsSeeEverything(), false));
|
||||
enqueueProtocolItem(GameEventContainer::makeNew(new Event_GameStateChanged(game->getGameStarted(), game->getActivePlayer(), game->getActivePhase(), game->getGameState(creator)), game->getGameId()));
|
||||
return RespOk;
|
||||
}
|
||||
|
|
@ -318,7 +324,7 @@ ResponseCode Server_ProtocolHandler::cmdJoinGame(Command_JoinGame *cmd, CommandC
|
|||
if (result == RespOk) {
|
||||
Server_Player *player = g->addPlayer(this, cmd->getSpectator());
|
||||
games.insert(cmd->getGameId(), QPair<Server_Game *, Server_Player *>(g, player));
|
||||
enqueueProtocolItem(new Event_GameJoined(cmd->getGameId(), g->getDescription(), player->getPlayerId(), cmd->getSpectator(), false));
|
||||
enqueueProtocolItem(new Event_GameJoined(cmd->getGameId(), g->getDescription(), player->getPlayerId(), cmd->getSpectator(), g->getSpectatorsCanTalk(), g->getSpectatorsSeeEverything(), false));
|
||||
enqueueProtocolItem(GameEventContainer::makeNew(new Event_GameStateChanged(g->getGameStarted(), g->getActivePlayer(), g->getActivePhase(), g->getGameState(player)), cmd->getGameId()));
|
||||
}
|
||||
return result;
|
||||
|
|
@ -332,6 +338,9 @@ ResponseCode Server_ProtocolHandler::cmdLeaveGame(Command_LeaveGame * /*cmd*/, C
|
|||
|
||||
ResponseCode Server_ProtocolHandler::cmdDeckSelect(Command_DeckSelect *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (player->getSpectator())
|
||||
return RespFunctionNotAllowed;
|
||||
|
||||
DeckList *deck;
|
||||
if (cmd->getDeckId() == -1) {
|
||||
if (!cmd->getDeck())
|
||||
|
|
@ -354,6 +363,9 @@ ResponseCode Server_ProtocolHandler::cmdDeckSelect(Command_DeckSelect *cmd, Comm
|
|||
|
||||
ResponseCode Server_ProtocolHandler::cmdSetSideboardPlan(Command_SetSideboardPlan *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (player->getSpectator())
|
||||
return RespFunctionNotAllowed;
|
||||
|
||||
DeckList *deck = player->getDeck();
|
||||
if (!deck)
|
||||
return RespContextError;
|
||||
|
|
@ -364,6 +376,9 @@ ResponseCode Server_ProtocolHandler::cmdSetSideboardPlan(Command_SetSideboardPla
|
|||
|
||||
ResponseCode Server_ProtocolHandler::cmdConcede(Command_Concede * /*cmd*/, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (player->getSpectator())
|
||||
return RespFunctionNotAllowed;
|
||||
|
||||
player->setConceded(true);
|
||||
game->sendGameEvent(new Event_PlayerPropertiesChanged(player->getProperties()), new Context_Concede);
|
||||
game->stopGameIfFinished();
|
||||
|
|
@ -372,6 +387,9 @@ ResponseCode Server_ProtocolHandler::cmdConcede(Command_Concede * /*cmd*/, Comma
|
|||
|
||||
ResponseCode Server_ProtocolHandler::cmdReadyStart(Command_ReadyStart * /*cmd*/, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (player->getSpectator())
|
||||
return RespFunctionNotAllowed;
|
||||
|
||||
if (!player->getDeck())
|
||||
return RespContextError;
|
||||
|
||||
|
|
@ -383,12 +401,18 @@ ResponseCode Server_ProtocolHandler::cmdReadyStart(Command_ReadyStart * /*cmd*/,
|
|||
|
||||
ResponseCode Server_ProtocolHandler::cmdSay(Command_Say *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (player->getSpectator() && !game->getSpectatorsCanTalk())
|
||||
return RespFunctionNotAllowed;
|
||||
|
||||
game->sendGameEvent(new Event_Say(player->getPlayerId(), cmd->getMessage()));
|
||||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdShuffle(Command_Shuffle * /*cmd*/, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (player->getSpectator())
|
||||
return RespFunctionNotAllowed;
|
||||
|
||||
if (!game->getGameStarted())
|
||||
return RespGameNotStarted;
|
||||
|
||||
|
|
@ -399,6 +423,9 @@ ResponseCode Server_ProtocolHandler::cmdShuffle(Command_Shuffle * /*cmd*/, Comma
|
|||
|
||||
ResponseCode Server_ProtocolHandler::cmdMulligan(Command_Mulligan * /*cmd*/, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (player->getSpectator())
|
||||
return RespFunctionNotAllowed;
|
||||
|
||||
if (!game->getGameStarted())
|
||||
return RespGameNotStarted;
|
||||
|
||||
|
|
@ -422,12 +449,18 @@ ResponseCode Server_ProtocolHandler::cmdMulligan(Command_Mulligan * /*cmd*/, Com
|
|||
|
||||
ResponseCode Server_ProtocolHandler::cmdRollDie(Command_RollDie *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (player->getSpectator())
|
||||
return RespFunctionNotAllowed;
|
||||
|
||||
game->sendGameEvent(new Event_RollDie(player->getPlayerId(), cmd->getSides(), rng->getNumber(1, cmd->getSides())));
|
||||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::drawCards(Server_Game *game, Server_Player *player, CommandContainer *cont, int number)
|
||||
{
|
||||
if (player->getSpectator())
|
||||
return RespFunctionNotAllowed;
|
||||
|
||||
if (!game->getGameStarted())
|
||||
return RespGameNotStarted;
|
||||
|
||||
|
|
@ -436,15 +469,18 @@ ResponseCode Server_ProtocolHandler::drawCards(Server_Game *game, Server_Player
|
|||
if (deck->cards.size() < number)
|
||||
number = deck->cards.size();
|
||||
|
||||
QList<ServerInfo_Card *> cardList;
|
||||
QList<ServerInfo_Card *> cardListPrivate;
|
||||
QList<ServerInfo_Card *> cardListOmniscient;
|
||||
for (int i = 0; i < number; ++i) {
|
||||
Server_Card *card = deck->cards.takeFirst();
|
||||
hand->cards.append(card);
|
||||
cardList.append(new ServerInfo_Card(card->getId(), card->getName()));
|
||||
cardListPrivate.append(new ServerInfo_Card(card->getId(), card->getName()));
|
||||
cardListOmniscient.append(new ServerInfo_Card(card->getId(), card->getName()));
|
||||
}
|
||||
|
||||
cont->enqueueGameEventPrivate(new Event_DrawCards(player->getPlayerId(), cardList.size(), cardList), game->getGameId());
|
||||
cont->enqueueGameEventPublic(new Event_DrawCards(player->getPlayerId(), cardList.size()), game->getGameId());
|
||||
cont->enqueueGameEventPrivate(new Event_DrawCards(player->getPlayerId(), cardListPrivate.size(), cardListPrivate), game->getGameId());
|
||||
cont->enqueueGameEventOmniscient(new Event_DrawCards(player->getPlayerId(), cardListOmniscient.size(), cardListOmniscient), game->getGameId());
|
||||
cont->enqueueGameEventPublic(new Event_DrawCards(player->getPlayerId(), cardListPrivate.size()), game->getGameId());
|
||||
|
||||
return RespOk;
|
||||
}
|
||||
|
|
@ -457,6 +493,9 @@ ResponseCode Server_ProtocolHandler::cmdDrawCards(Command_DrawCards *cmd, Comman
|
|||
|
||||
ResponseCode Server_ProtocolHandler::moveCard(Server_Game *game, Server_Player *player, CommandContainer *cont, const QString &_startZone, int _cardId, const QString &_targetZone, int x, int y, bool faceDown, bool tapped)
|
||||
{
|
||||
if (player->getSpectator())
|
||||
return RespFunctionNotAllowed;
|
||||
|
||||
if (!game->getGameStarted())
|
||||
return RespGameNotStarted;
|
||||
|
||||
|
|
@ -508,6 +547,7 @@ ResponseCode Server_ProtocolHandler::moveCard(Server_Game *game, Server_Player *
|
|||
if (startzone->getType() == HiddenZone)
|
||||
privatePosition = position;
|
||||
cont->enqueueGameEventPrivate(new Event_MoveCard(player->getPlayerId(), privateOldCardId, privateCardName, startzone->getName(), privatePosition, targetzone->getName(), x, y, privateNewCardId, faceDown), game->getGameId());
|
||||
cont->enqueueGameEventOmniscient(new Event_MoveCard(player->getPlayerId(), privateOldCardId, privateCardName, startzone->getName(), privatePosition, targetzone->getName(), x, y, privateNewCardId, faceDown), game->getGameId());
|
||||
|
||||
// Other players do not get to see the start and/or target position of the card if the respective
|
||||
// part of the zone is being looked at. The information is not needed anyway because in hidden zones,
|
||||
|
|
@ -554,6 +594,9 @@ ResponseCode Server_ProtocolHandler::cmdMoveCard(Command_MoveCard *cmd, CommandC
|
|||
|
||||
ResponseCode Server_ProtocolHandler::cmdCreateToken(Command_CreateToken *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (player->getSpectator())
|
||||
return RespFunctionNotAllowed;
|
||||
|
||||
if (!game->getGameStarted())
|
||||
return RespGameNotStarted;
|
||||
|
||||
|
|
@ -571,6 +614,9 @@ ResponseCode Server_ProtocolHandler::cmdCreateToken(Command_CreateToken *cmd, Co
|
|||
|
||||
ResponseCode Server_ProtocolHandler::cmdCreateArrow(Command_CreateArrow *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (player->getSpectator())
|
||||
return RespFunctionNotAllowed;
|
||||
|
||||
if (!game->getGameStarted())
|
||||
return RespGameNotStarted;
|
||||
|
||||
|
|
@ -610,6 +656,9 @@ ResponseCode Server_ProtocolHandler::cmdCreateArrow(Command_CreateArrow *cmd, Co
|
|||
|
||||
ResponseCode Server_ProtocolHandler::cmdDeleteArrow(Command_DeleteArrow *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (player->getSpectator())
|
||||
return RespFunctionNotAllowed;
|
||||
|
||||
if (!game->getGameStarted())
|
||||
return RespGameNotStarted;
|
||||
|
||||
|
|
@ -622,6 +671,9 @@ ResponseCode Server_ProtocolHandler::cmdDeleteArrow(Command_DeleteArrow *cmd, Co
|
|||
|
||||
ResponseCode Server_ProtocolHandler::setCardAttrHelper(CommandContainer *cont, Server_Game *game, Server_Player *player, const QString &zoneName, int cardId, const QString &attrName, const QString &attrValue)
|
||||
{
|
||||
if (player->getSpectator())
|
||||
return RespFunctionNotAllowed;
|
||||
|
||||
if (!game->getGameStarted())
|
||||
return RespGameNotStarted;
|
||||
|
||||
|
|
@ -655,6 +707,9 @@ ResponseCode Server_ProtocolHandler::cmdSetCardAttr(Command_SetCardAttr *cmd, Co
|
|||
|
||||
ResponseCode Server_ProtocolHandler::cmdIncCounter(Command_IncCounter *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (player->getSpectator())
|
||||
return RespFunctionNotAllowed;
|
||||
|
||||
if (!game->getGameStarted())
|
||||
return RespGameNotStarted;
|
||||
|
||||
|
|
@ -670,6 +725,9 @@ ResponseCode Server_ProtocolHandler::cmdIncCounter(Command_IncCounter *cmd, Comm
|
|||
|
||||
ResponseCode Server_ProtocolHandler::cmdCreateCounter(Command_CreateCounter *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (player->getSpectator())
|
||||
return RespFunctionNotAllowed;
|
||||
|
||||
if (!game->getGameStarted())
|
||||
return RespGameNotStarted;
|
||||
|
||||
|
|
@ -682,6 +740,9 @@ ResponseCode Server_ProtocolHandler::cmdCreateCounter(Command_CreateCounter *cmd
|
|||
|
||||
ResponseCode Server_ProtocolHandler::cmdSetCounter(Command_SetCounter *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (player->getSpectator())
|
||||
return RespFunctionNotAllowed;
|
||||
|
||||
if (!game->getGameStarted())
|
||||
return RespGameNotStarted;
|
||||
|
||||
|
|
@ -696,6 +757,9 @@ ResponseCode Server_ProtocolHandler::cmdSetCounter(Command_SetCounter *cmd, Comm
|
|||
|
||||
ResponseCode Server_ProtocolHandler::cmdDelCounter(Command_DelCounter *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (player->getSpectator())
|
||||
return RespFunctionNotAllowed;
|
||||
|
||||
if (!game->getGameStarted())
|
||||
return RespGameNotStarted;
|
||||
|
||||
|
|
@ -705,8 +769,11 @@ ResponseCode Server_ProtocolHandler::cmdDelCounter(Command_DelCounter *cmd, Comm
|
|||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdNextTurn(Command_NextTurn * /*cmd*/, CommandContainer *cont, Server_Game *game, Server_Player * /*player*/)
|
||||
ResponseCode Server_ProtocolHandler::cmdNextTurn(Command_NextTurn * /*cmd*/, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (player->getSpectator())
|
||||
return RespFunctionNotAllowed;
|
||||
|
||||
if (!game->getGameStarted())
|
||||
return RespGameNotStarted;
|
||||
|
||||
|
|
@ -727,6 +794,9 @@ ResponseCode Server_ProtocolHandler::cmdNextTurn(Command_NextTurn * /*cmd*/, Com
|
|||
|
||||
ResponseCode Server_ProtocolHandler::cmdSetActivePhase(Command_SetActivePhase *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (player->getSpectator())
|
||||
return RespFunctionNotAllowed;
|
||||
|
||||
if (!game->getGameStarted())
|
||||
return RespGameNotStarted;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue