everything compiles again; enough for today

This commit is contained in:
Max-Wilhelm Bruker 2009-11-12 00:09:24 +01:00
parent dd5ae4d74d
commit cb0e4d07e4
29 changed files with 340 additions and 766 deletions

View file

@ -69,7 +69,7 @@ void ProtocolItem::initializeHash()
int Command::lastCmdId = 0;
Command::Command(const QString &_itemName, int _cmdId)
: ProtocolItem(_itemName), cmdId(_cmdId)
: ProtocolItem(_itemName), cmdId(_cmdId), ticks(0)
{
if (cmdId == -1)
cmdId = lastCmdId++;
@ -84,7 +84,7 @@ void Command::extractParameters()
cmdId = -1;
}
QHash<QString, ProtocolResponse::ResponseCode> ProtocolResponse::responseHash;
QHash<QString, ResponseCode> ProtocolResponse::responseHash;
ProtocolResponse::ProtocolResponse(int _cmdId, ResponseCode _responseCode)
: ProtocolItem(QString()), cmdId(_cmdId), responseCode(_responseCode)
@ -151,7 +151,7 @@ ChatEvent::ChatEvent(const QString &_eventName, const QString &_channel)
bool Event_ChatListChannels::readElement(QXmlStreamReader *xml)
{
if (xml->isStartElement() && (xml->name() == "channel")) {
channelList.append(ChannelInfo(
channelList.append(ServerChatChannelInfo(
xml->attributes().value("name").toString(),
xml->attributes().value("description").toString(),
xml->attributes().value("player_count").toString().toInt(),
@ -177,7 +177,7 @@ void Event_ChatListChannels::writeElement(QXmlStreamWriter *xml)
bool Event_ChatListPlayers::readElement(QXmlStreamReader *xml)
{
if (xml->isStartElement() && ((xml->name() == "player"))) {
playerList.append(PlayerInfo(
playerList.append(ServerPlayerInfo(
xml->attributes().value("name").toString()
));
return true;
@ -197,7 +197,7 @@ void Event_ChatListPlayers::writeElement(QXmlStreamWriter *xml)
bool Event_ListGames::readElement(QXmlStreamReader *xml)
{
if (xml->isStartElement() && (xml->name() == "game")) {
gameList.append(GameInfo(
gameList.append(ServerGameInfo(
xml->attributes().value("id").toString().toInt(),
xml->attributes().value("description").toString(),
xml->attributes().value("has_password").toString().toInt(),

View file

@ -7,6 +7,7 @@
#include <QObject>
#include <QDebug>
#include "protocol_item_ids.h"
#include "protocol_datastructures.h"
class QXmlStreamReader;
class QXmlStreamWriter;
@ -52,6 +53,7 @@ class Command : public ProtocolItem {
Q_OBJECT
private:
int cmdId;
int ticks;
static int lastCmdId;
protected:
QString getItemType() const { return "cmd"; }
@ -59,6 +61,7 @@ protected:
public:
Command(const QString &_itemName = QString(), int _cmdId = -1);
int getCmdId() const { return cmdId; }
int tick() { return ++ticks; }
};
class InvalidCommand : public Command {
@ -106,8 +109,6 @@ public:
class ProtocolResponse : public ProtocolItem {
Q_OBJECT
public:
enum ResponseCode { RespNothing, RespOk, RespInvalidCommand, RespNameNotFound, RespLoginNeeded, RespContextError, RespWrongPassword, RespSpectatorsNotAllowed };
private:
int cmdId;
ResponseCode responseCode;
@ -158,31 +159,16 @@ public:
class Event_ChatListChannels : public GenericEvent {
Q_OBJECT
public:
class ChannelInfo {
private:
QString name;
QString description;
int playerCount;
bool autoJoin;
public:
ChannelInfo(const QString &_name, const QString &_description, int _playerCount, bool _autoJoin)
: name(_name), description(_description), playerCount(_playerCount), autoJoin(_autoJoin) { }
QString getName() const { return name; }
QString getDescription() const { return description; }
int getPlayerCount() const { return playerCount; }
bool getAutoJoin() const { return autoJoin; }
};
private:
QList<ChannelInfo> channelList;
QList<ServerChatChannelInfo> channelList;
public:
Event_ChatListChannels() : GenericEvent("chat_list_channels") { }
int getItemId() const { return ItemId_Event_ChatListChannels; }
void addChannel(const QString &_name, const QString &_description, int _playerCount, bool _autoJoin)
{
channelList.append(ChannelInfo(_name, _description, _playerCount, _autoJoin));
channelList.append(ServerChatChannelInfo(_name, _description, _playerCount, _autoJoin));
}
const QList<ChannelInfo> &getChannelList() const { return channelList; }
const QList<ServerChatChannelInfo> &getChannelList() const { return channelList; }
bool readElement(QXmlStreamReader *xml);
void writeElement(QXmlStreamWriter *xml);
@ -190,25 +176,16 @@ public:
class Event_ChatListPlayers : public ChatEvent {
Q_OBJECT
public:
class PlayerInfo {
private:
QString name;
public:
PlayerInfo(const QString &_name)
: name(_name) { }
QString getName() const { return name; }
};
private:
QList<PlayerInfo> playerList;
QList<ServerPlayerInfo> playerList;
public:
Event_ChatListPlayers(const QString &_channel) : ChatEvent("chat_list_players", _channel) { }
int getItemId() const { return ItemId_Event_ChatListPlayers; }
void addPlayer(const QString &_name)
{
playerList.append(PlayerInfo(_name));
playerList.append(ServerPlayerInfo(_name));
}
const QList<PlayerInfo> &getPlayerList() const { return playerList; }
const QList<ServerPlayerInfo> &getPlayerList() const { return playerList; }
bool readElement(QXmlStreamReader *xml);
void writeElement(QXmlStreamWriter *xml);
@ -216,39 +193,16 @@ public:
class Event_ListGames : public GenericEvent {
Q_OBJECT
public:
class GameInfo {
private:
int gameId;
QString description;
bool hasPassword;
int playerCount;
int maxPlayers;
QString creatorName;
bool spectatorsAllowed;
int spectatorCount;
public:
GameInfo(int _gameId, const QString &_description, bool _hasPassword, int _playerCount, int _maxPlayers, const QString &_creatorName, bool _spectatorsAllowed, int _spectatorCount)
: gameId(_gameId), description(_description), hasPassword(_hasPassword), playerCount(_playerCount), maxPlayers(_maxPlayers), creatorName(_creatorName), spectatorsAllowed(_spectatorsAllowed), spectatorCount(_spectatorCount) { }
int getGameId() const { return gameId; }
QString getDescription() const { return description; }
bool getHasPassword() const { return hasPassword; }
int getPlayerCount() const { return playerCount; }
int getMaxPlayers() const { return maxPlayers; }
QString getCreatorName() const { return creatorName; }
bool getSpectatorsAllowed() const { return spectatorsAllowed; }
int getSpectatorCount() const { return spectatorCount; }
};
private:
QList<GameInfo> gameList;
QList<ServerGameInfo> gameList;
public:
Event_ListGames() : GenericEvent("list_games") { }
int getItemId() const { return ItemId_Event_ListGames; }
void addGame(int _gameId, const QString &_description, bool _hasPassword, int _playerCount, int _maxPlayers, const QString &_creatorName, bool _spectatorsAllowed, int _spectatorCount)
{
gameList.append(GameInfo(_gameId, _description, _hasPassword, _playerCount, _maxPlayers, _creatorName, _spectatorsAllowed, _spectatorCount));
gameList.append(ServerGameInfo(_gameId, _description, _hasPassword, _playerCount, _maxPlayers, _creatorName, _spectatorsAllowed, _spectatorCount));
}
const QList<GameInfo> &getGameList() const { return gameList; }
const QList<ServerGameInfo> &getGameList() const { return gameList; }
bool readElement(QXmlStreamReader *xml);
void writeElement(QXmlStreamWriter *xml);

View file

@ -77,17 +77,17 @@ void Server_Game::startGameIfReady()
setActivePlayer(0);
}
ProtocolResponse::ResponseCode Server_Game::checkJoin(const QString &_password, bool spectator)
ResponseCode Server_Game::checkJoin(const QString &_password, bool spectator)
{
if (_password != password)
return ProtocolResponse::RespWrongPassword;
return RespWrongPassword;
if (spectator) {
if (!spectatorsAllowed)
return ProtocolResponse::RespSpectatorsNotAllowed;
return RespSpectatorsNotAllowed;
} else if (gameStarted || (getPlayerCount() >= getMaxPlayers()))
return ProtocolResponse::RespContextError;
return RespContextError;
return ProtocolResponse::RespOk;
return RespOk;
}
Server_Player *Server_Game::addPlayer(Server_ProtocolHandler *handler, bool spectator)

View file

@ -56,7 +56,7 @@ public:
QString getPassword() const { return password; }
int getMaxPlayers() const { return maxPlayers; }
bool getSpectatorsAllowed() const { return spectatorsAllowed; }
ProtocolResponse::ResponseCode checkJoin(const QString &_password, bool spectator);
ResponseCode checkJoin(const QString &_password, bool spectator);
Server_Player *addPlayer(Server_ProtocolHandler *handler, bool spectator);
void removePlayer(Server_Player *player);
void startGameIfReady();

View file

@ -22,7 +22,7 @@ Server_ProtocolHandler::~Server_ProtocolHandler()
void Server_ProtocolHandler::processCommand(Command *command)
{
ProtocolResponse::ResponseCode response = ProtocolResponse::RespInvalidCommand;
ResponseCode response = RespInvalidCommand;
ChatCommand *chatCommand = qobject_cast<ChatCommand *>(command);
GameCommand *gameCommand = qobject_cast<GameCommand *>(command);
@ -30,7 +30,7 @@ void Server_ProtocolHandler::processCommand(Command *command)
qDebug() << "received ChatCommand: channel =" << chatCommand->getChannel();
Server_ChatChannel *channel = chatChannels.value(chatCommand->getChannel(), 0);
if (!channel) {
sendProtocolItem(new ProtocolResponse(gameCommand->getCmdId(), ProtocolResponse::RespNameNotFound));
sendProtocolItem(new ProtocolResponse(gameCommand->getCmdId(), RespNameNotFound));
return;
}
switch (command->getItemId()) {
@ -40,7 +40,7 @@ void Server_ProtocolHandler::processCommand(Command *command)
} else if (gameCommand) {
qDebug() << "received GameCommand: game =" << gameCommand->getGameId();
if (!games.contains(gameCommand->getGameId())) {
sendProtocolItem(new ProtocolResponse(gameCommand->getCmdId(), ProtocolResponse::RespNameNotFound));
sendProtocolItem(new ProtocolResponse(gameCommand->getCmdId(), RespNameNotFound));
return;
}
QPair<Server_Game *, Server_Player *> gamePair = games.value(gameCommand->getGameId());
@ -82,7 +82,7 @@ void Server_ProtocolHandler::processCommand(Command *command)
case ItemId_Command_JoinGame: response = cmdJoinGame(qobject_cast<Command_JoinGame *>(command)); break;
}
}
if (response != ProtocolResponse::RespNothing)
if (response != RespNothing)
sendProtocolItem(new ProtocolResponse(command->getCmdId(), response));
delete command;
@ -103,23 +103,23 @@ QPair<Server_Game *, Server_Player *> Server_ProtocolHandler::getGame(int gameId
return QPair<Server_Game *, Server_Player *>(0, 0);
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdPing(Command_Ping * /*cmd*/)
ResponseCode Server_ProtocolHandler::cmdPing(Command_Ping * /*cmd*/)
{
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdLogin(Command_Login *cmd)
ResponseCode Server_ProtocolHandler::cmdLogin(Command_Login *cmd)
{
authState = server->checkUserPassword(cmd->getUsername(), cmd->getPassword());
if (authState == PasswordWrong)
return ProtocolResponse::RespWrongPassword;
return RespWrongPassword;
playerName = cmd->getUsername();
enqueueProtocolItem(new Event_ChatServerMessage(QString(), server->getLoginMessage()));
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdChatListChannels(Command_ChatListChannels * /*cmd*/)
ResponseCode Server_ProtocolHandler::cmdChatListChannels(Command_ChatListChannels * /*cmd*/)
{
Event_ChatListChannels *event = new Event_ChatListChannels;
QMapIterator<QString, Server_ChatChannel *> channelIterator(server->getChatChannels());
@ -130,38 +130,38 @@ ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdChatListChannels(Comma
sendProtocolItem(event);
acceptsChatChannelListChanges = true;
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdChatJoinChannel(Command_ChatJoinChannel *cmd)
ResponseCode Server_ProtocolHandler::cmdChatJoinChannel(Command_ChatJoinChannel *cmd)
{
if (chatChannels.contains(cmd->getChannel()))
return ProtocolResponse::RespContextError;
return RespContextError;
QMap<QString, Server_ChatChannel *> allChannels = server->getChatChannels();
Server_ChatChannel *c = allChannels.value(cmd->getChannel(), 0);
if (!c)
return ProtocolResponse::RespNameNotFound;
return RespNameNotFound;
c->addClient(this);
chatChannels.insert(cmd->getChannel(), c);
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdChatLeaveChannel(Command_ChatLeaveChannel * /*cmd*/, Server_ChatChannel *channel)
ResponseCode Server_ProtocolHandler::cmdChatLeaveChannel(Command_ChatLeaveChannel * /*cmd*/, Server_ChatChannel *channel)
{
chatChannels.remove(channel->getName());
channel->removeClient(this);
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdChatSay(Command_ChatSay *cmd, Server_ChatChannel *channel)
ResponseCode Server_ProtocolHandler::cmdChatSay(Command_ChatSay *cmd, Server_ChatChannel *channel)
{
channel->say(this, cmd->getMessage());
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdListGames(Command_ListGames * /*cmd*/)
ResponseCode Server_ProtocolHandler::cmdListGames(Command_ListGames * /*cmd*/)
{
Event_ListGames *event = new Event_ListGames;
const QList<Server_Game *> &gameList = server->getGames();
@ -181,57 +181,57 @@ ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdListGames(Command_List
sendProtocolItem(event);
acceptsGameListChanges = true;
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd)
ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd)
{
Server_Game *game = server->createGame(cmd->getDescription(), cmd->getPassword(), cmd->getMaxPlayers(), cmd->getSpectatorsAllowed(), this);
games.insert(game->getGameId(), QPair<Server_Game *, Server_Player *>(game, game->getCreator()));
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdJoinGame(Command_JoinGame *cmd)
ResponseCode Server_ProtocolHandler::cmdJoinGame(Command_JoinGame *cmd)
{
Server_Game *g = server->getGame(cmd->getGameId());
if (!g)
return ProtocolResponse::RespNameNotFound;
return RespNameNotFound;
ProtocolResponse::ResponseCode result = g->checkJoin(cmd->getPassword(), cmd->getSpectator());
if (result == ProtocolResponse::RespOk) {
ResponseCode result = g->checkJoin(cmd->getPassword(), cmd->getSpectator());
if (result == RespOk) {
Server_Player *player = g->addPlayer(this, cmd->getSpectator());
games.insert(cmd->getGameId(), QPair<Server_Game *, Server_Player *>(g, player));
}
return result;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdLeaveGame(Command_LeaveGame * /*cmd*/, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdLeaveGame(Command_LeaveGame * /*cmd*/, Server_Game *game, Server_Player *player)
{
game->removePlayer(player);
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdSay(Command_Say *cmd, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdSay(Command_Say *cmd, Server_Game *game, Server_Player *player)
{
game->sendGameEvent(new Event_Say(-1, player->getPlayerId(), cmd->getMessage()));
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdShuffle(Command_Shuffle * /*cmd*/, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdShuffle(Command_Shuffle * /*cmd*/, Server_Game *game, Server_Player *player)
{
player->getZones().value("deck")->shuffle();
game->sendGameEvent(new Event_Shuffle(-1, player->getPlayerId()));
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdRollDie(Command_RollDie *cmd, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdRollDie(Command_RollDie *cmd, Server_Game *game, Server_Player *player)
{
game->sendGameEvent(new Event_RollDie(-1, player->getPlayerId(), cmd->getSides(), rng->getNumber(1, cmd->getSides())));
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdDrawCards(Command_DrawCards *cmd, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdDrawCards(Command_DrawCards *cmd, Server_Game *game, Server_Player *player)
{
Server_CardZone *deck = player->getZones().value("deck");
Server_CardZone *hand = player->getZones().value("hand");
@ -246,21 +246,21 @@ ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdDrawCards(Command_Draw
}
// game->broadcastEvent(QString("draw|%1").arg(number), player);
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdMoveCard(Command_MoveCard *cmd, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdMoveCard(Command_MoveCard *cmd, Server_Game *game, Server_Player *player)
{
// ID Karte, Startzone, Zielzone, Koordinaten X, Y, Facedown
Server_CardZone *startzone = player->getZones().value(cmd->getStartZone());
Server_CardZone *targetzone = player->getZones().value(cmd->getTargetZone());
if ((!startzone) || (!targetzone))
return ProtocolResponse::RespNameNotFound;
return RespNameNotFound;
int position = -1;
Server_Card *card = startzone->getCard(cmd->getCardId(), true, &position);
if (!card)
return ProtocolResponse::RespNameNotFound;
return RespNameNotFound;
int x = cmd->getX();
if (x == -1)
x = targetzone->cards.size();
@ -345,42 +345,42 @@ ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdMoveCard(Command_MoveC
}
}
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdCreateToken(Command_CreateToken *cmd, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdCreateToken(Command_CreateToken *cmd, Server_Game *game, Server_Player *player)
{
// powtough wird erst mal ignoriert
Server_CardZone *zone = player->getZones().value(cmd->getZone());
if (!zone)
return ProtocolResponse::RespNameNotFound;
return RespNameNotFound;
Server_Card *card = new Server_Card(cmd->getCardName(), player->newCardId(), cmd->getX(), cmd->getY());
zone->insertCard(card, cmd->getX(), cmd->getY());
game->sendGameEvent(new Event_CreateToken(-1, player->getPlayerId(), zone->getName(), card->getId(), card->getName(), cmd->getPt(), cmd->getX(), cmd->getY()));
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdCreateArrow(Command_CreateArrow *cmd, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdCreateArrow(Command_CreateArrow *cmd, Server_Game *game, Server_Player *player)
{
Server_Player *startPlayer = game->getPlayer(cmd->getStartPlayerId());
Server_Player *targetPlayer = game->getPlayer(cmd->getTargetPlayerId());
if (!startPlayer || !targetPlayer)
return ProtocolResponse::RespNameNotFound;
return RespNameNotFound;
Server_CardZone *startZone = startPlayer->getZones().value(cmd->getStartZone());
Server_CardZone *targetZone = targetPlayer->getZones().value(cmd->getTargetZone());
if (!startZone || !targetZone)
return ProtocolResponse::RespNameNotFound;
return RespNameNotFound;
Server_Card *startCard = startZone->getCard(cmd->getStartCardId(), false);
Server_Card *targetCard = targetZone->getCard(cmd->getTargetCardId(), false);
if (!startCard || !targetCard || (startCard == targetCard))
return ProtocolResponse::RespContextError;
return RespContextError;
QMapIterator<int, Server_Arrow *> arrowIterator(player->getArrows());
while (arrowIterator.hasNext()) {
Server_Arrow *temp = arrowIterator.next().value();
if ((temp->getStartCard() == startCard) && (temp->getTargetCard() == targetCard))
return ProtocolResponse::RespContextError;
return RespContextError;
}
Server_Arrow *arrow = new Server_Arrow(player->newArrowId(), startCard, targetCard, cmd->getColor());
@ -397,148 +397,148 @@ ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdCreateArrow(Command_Cr
targetCard->getId(),
cmd->getColor()
));
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdDeleteArrow(Command_DeleteArrow *cmd, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdDeleteArrow(Command_DeleteArrow *cmd, Server_Game *game, Server_Player *player)
{
if (!player->deleteArrow(cmd->getArrowId()))
return ProtocolResponse::RespNameNotFound;
return RespNameNotFound;
game->sendGameEvent(new Event_DeleteArrow(-1, player->getPlayerId(), cmd->getArrowId()));
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdSetCardAttr(Command_SetCardAttr *cmd, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdSetCardAttr(Command_SetCardAttr *cmd, Server_Game *game, Server_Player *player)
{
// zone, card id, attr name, attr value
// card id = -1 => affects all cards in the specified zone
Server_CardZone *zone = player->getZones().value(cmd->getZone());
if (!zone)
return ProtocolResponse::RespNameNotFound;
return RespNameNotFound;
if (cmd->getCardId() == -1) {
QListIterator<Server_Card *> CardIterator(zone->cards);
while (CardIterator.hasNext())
if (!CardIterator.next()->setAttribute(cmd->getAttrName(), cmd->getAttrValue(), true))
return ProtocolResponse::RespInvalidCommand;
return RespInvalidCommand;
} else {
Server_Card *card = zone->getCard(cmd->getCardId(), false);
if (!card)
return ProtocolResponse::RespNameNotFound;
return RespNameNotFound;
if (!card->setAttribute(cmd->getAttrName(), cmd->getAttrValue(), false))
return ProtocolResponse::RespInvalidCommand;
return RespInvalidCommand;
}
game->sendGameEvent(new Event_SetCardAttr(-1, player->getPlayerId(), zone->getName(), cmd->getCardId(), cmd->getAttrName(), cmd->getAttrValue()));
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdReadyStart(Command_ReadyStart * /*cmd*/, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdReadyStart(Command_ReadyStart * /*cmd*/, Server_Game *game, Server_Player *player)
{
player->setStatus(StatusReadyStart);
game->sendGameEvent(new Event_ReadyStart(-1, player->getPlayerId()));
game->startGameIfReady();
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdIncCounter(Command_IncCounter *cmd, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdIncCounter(Command_IncCounter *cmd, Server_Game *game, Server_Player *player)
{
const QMap<int, Server_Counter *> counters = player->getCounters();
Server_Counter *c = counters.value(cmd->getCounterId(), 0);
if (!c)
return ProtocolResponse::RespNameNotFound;
return RespNameNotFound;
c->setCount(c->getCount() + cmd->getDelta());
game->sendGameEvent(new Event_SetCounter(-1, player->getPlayerId(), c->getId(), c->getCount()));
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdAddCounter(Command_AddCounter *cmd, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdAddCounter(Command_AddCounter *cmd, Server_Game *game, Server_Player *player)
{
Server_Counter *c = new Server_Counter(player->newCounterId(), cmd->getCounterName(), cmd->getColor(), cmd->getRadius(), cmd->getValue());
player->addCounter(c);
game->sendGameEvent(new Event_AddCounter(-1, player->getPlayerId(), c->getId(), c->getName(), c->getColor(), c->getRadius(), c->getCount()));
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdSetCounter(Command_SetCounter *cmd, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdSetCounter(Command_SetCounter *cmd, Server_Game *game, Server_Player *player)
{
Server_Counter *c = player->getCounters().value(cmd->getCounterId(), 0);;
if (!c)
return ProtocolResponse::RespNameNotFound;
return RespNameNotFound;
c->setCount(cmd->getValue());
game->sendGameEvent(new Event_SetCounter(-1, player->getPlayerId(), c->getId(), c->getCount()));
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdDelCounter(Command_DelCounter *cmd, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdDelCounter(Command_DelCounter *cmd, Server_Game *game, Server_Player *player)
{
if (!player->deleteCounter(cmd->getCounterId()))
return ProtocolResponse::RespNameNotFound;
return RespNameNotFound;
game->sendGameEvent(new Event_DelCounter(-1, player->getPlayerId(), cmd->getCounterId()));
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdNextTurn(Command_NextTurn * /*cmd*/, Server_Game *game, Server_Player * /*player*/)
ResponseCode Server_ProtocolHandler::cmdNextTurn(Command_NextTurn * /*cmd*/, Server_Game *game, Server_Player * /*player*/)
{
int activePlayer = game->getActivePlayer();
if (++activePlayer == game->getPlayerCount())
activePlayer = 0;
game->setActivePlayer(activePlayer);
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdSetActivePhase(Command_SetActivePhase *cmd, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdSetActivePhase(Command_SetActivePhase *cmd, Server_Game *game, Server_Player *player)
{
if (game->getActivePlayer() != player->getPlayerId())
return ProtocolResponse::RespContextError;
return RespContextError;
game->setActivePhase(cmd->getPhase());
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdDumpZone(Command_DumpZone *cmd, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdDumpZone(Command_DumpZone *cmd, Server_Game *game, Server_Player *player)
{
Server_Player *otherPlayer = game->getPlayer(cmd->getPlayerId());
if (!otherPlayer)
return ProtocolResponse::RespNameNotFound;
return RespNameNotFound;
Server_CardZone *zone = otherPlayer->getZones().value(cmd->getZoneName());
if (!zone)
return ProtocolResponse::RespNameNotFound;
return RespNameNotFound;
if (!((zone->getType() == Server_CardZone::PublicZone) || (player == otherPlayer)))
return ProtocolResponse::RespContextError;
return RespContextError;
if (zone->getType() == Server_CardZone::HiddenZone) {
// game->broadcastEvent(QString("dump_zone|%1|%2|%3").arg(player_id).arg(zone->getName()).arg(number_cards), player);
}
// remsg->sendList(dumpZoneHelper(otherPlayer, zone, number_cards));
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdStopDumpZone(Command_StopDumpZone *cmd, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdStopDumpZone(Command_StopDumpZone *cmd, Server_Game *game, Server_Player *player)
{
Server_Player *otherPlayer = game->getPlayer(cmd->getPlayerId());
if (!otherPlayer)
return ProtocolResponse::RespNameNotFound;
return RespNameNotFound;
Server_CardZone *zone = otherPlayer->getZones().value(cmd->getZoneName());
if (!zone)
return ProtocolResponse::RespNameNotFound;
return RespNameNotFound;
if (zone->getType() == Server_CardZone::HiddenZone) {
zone->setCardsBeingLookedAt(0);
game->sendGameEvent(new Event_StopDumpZone(-1, player->getPlayerId(), cmd->getPlayerId(), zone->getName()));
}
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdDumpAll(Command_DumpAll *cmd, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdDumpAll(Command_DumpAll *cmd, Server_Game *game, Server_Player *player)
{
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdSubmitDeck(Command_SubmitDeck *cmd, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdSubmitDeck(Command_SubmitDeck *cmd, Server_Game *game, Server_Player *player)
{
return ProtocolResponse::RespOk;
return RespOk;
}

View file

@ -26,36 +26,36 @@ private:
QList<ProtocolItem *> itemQueue;
ProtocolResponse::ResponseCode cmdPing(Command_Ping *cmd);
ProtocolResponse::ResponseCode cmdLogin(Command_Login *cmd);
ProtocolResponse::ResponseCode cmdChatListChannels(Command_ChatListChannels *cmd);
ProtocolResponse::ResponseCode cmdChatJoinChannel(Command_ChatJoinChannel *cmd);
ProtocolResponse::ResponseCode cmdChatLeaveChannel(Command_ChatLeaveChannel *cmd, Server_ChatChannel *channel);
ProtocolResponse::ResponseCode cmdChatSay(Command_ChatSay *cmd, Server_ChatChannel *channel);
ProtocolResponse::ResponseCode cmdListGames(Command_ListGames *cmd);
ProtocolResponse::ResponseCode cmdCreateGame(Command_CreateGame *cmd);
ProtocolResponse::ResponseCode cmdJoinGame(Command_JoinGame *cmd);
ProtocolResponse::ResponseCode cmdLeaveGame(Command_LeaveGame *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdSay(Command_Say *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdShuffle(Command_Shuffle *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdRollDie(Command_RollDie *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdDrawCards(Command_DrawCards *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdMoveCard(Command_MoveCard *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdCreateToken(Command_CreateToken *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdCreateArrow(Command_CreateArrow *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdDeleteArrow(Command_DeleteArrow *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdSetCardAttr(Command_SetCardAttr *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdReadyStart(Command_ReadyStart *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdIncCounter(Command_IncCounter *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdAddCounter(Command_AddCounter *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdSetCounter(Command_SetCounter *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdDelCounter(Command_DelCounter *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdNextTurn(Command_NextTurn *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdSetActivePhase(Command_SetActivePhase *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdDumpZone(Command_DumpZone *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdStopDumpZone(Command_StopDumpZone *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdDumpAll(Command_DumpAll *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdSubmitDeck(Command_SubmitDeck *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdPing(Command_Ping *cmd);
ResponseCode cmdLogin(Command_Login *cmd);
ResponseCode cmdChatListChannels(Command_ChatListChannels *cmd);
ResponseCode cmdChatJoinChannel(Command_ChatJoinChannel *cmd);
ResponseCode cmdChatLeaveChannel(Command_ChatLeaveChannel *cmd, Server_ChatChannel *channel);
ResponseCode cmdChatSay(Command_ChatSay *cmd, Server_ChatChannel *channel);
ResponseCode cmdListGames(Command_ListGames *cmd);
ResponseCode cmdCreateGame(Command_CreateGame *cmd);
ResponseCode cmdJoinGame(Command_JoinGame *cmd);
ResponseCode cmdLeaveGame(Command_LeaveGame *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdSay(Command_Say *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdShuffle(Command_Shuffle *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdRollDie(Command_RollDie *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdDrawCards(Command_DrawCards *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdMoveCard(Command_MoveCard *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdCreateToken(Command_CreateToken *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdCreateArrow(Command_CreateArrow *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdDeleteArrow(Command_DeleteArrow *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdSetCardAttr(Command_SetCardAttr *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdReadyStart(Command_ReadyStart *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdIncCounter(Command_IncCounter *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdAddCounter(Command_AddCounter *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdSetCounter(Command_SetCounter *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdDelCounter(Command_DelCounter *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdNextTurn(Command_NextTurn *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdSetActivePhase(Command_SetActivePhase *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdDumpZone(Command_DumpZone *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdStopDumpZone(Command_StopDumpZone *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdDumpAll(Command_DumpAll *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdSubmitDeck(Command_SubmitDeck *cmd, Server_Game *game, Server_Player *player);
public:
Server_ProtocolHandler(Server *_server, QObject *parent = 0);
~Server_ProtocolHandler();