/*************************************************************************** * Copyright (C) 2008 by Max-Wilhelm Bruker * * brukie@laptop * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef SERVERSOCKET_H #define SERVERSOCKET_H #include #include #include #include "server.h" #include "returnmessage.h" class Server; class ServerGame; class PlayerZone; class Counter; enum PlayerStatusEnum { StatusNormal, StatusSubmitDeck, StatusReadyStart, StatusPlaying }; class ServerSocket : public QTcpSocket { Q_OBJECT private slots: void readClient(); void catchSocketError(QAbstractSocket::SocketError socketError); signals: void createGame(const QString description, const QString password, const int maxPlayers, ServerSocket *creator); void joinGame(int gameId, ServerSocket *player); void commandReceived(QString cmd, ServerSocket *player); void broadcastEvent(const QString &event, ServerSocket *player); void startGameIfReady(); private: typedef ReturnMessage::ReturnCode (ServerSocket::*CommandHandler)(const QList &); struct CommandProperties { QString name; bool needsLogin; bool needsGame; bool needsStartedGame; QList paramTypes; CommandHandler handler; }; static const int numberCommands = 31; static const CommandProperties commandList[numberCommands]; ReturnMessage::ReturnCode cmdPing(const QList ¶ms); ReturnMessage::ReturnCode cmdLogin(const QList ¶ms); ReturnMessage::ReturnCode cmdChatListChannels(const QList ¶ms); ReturnMessage::ReturnCode cmdChatJoinChannel(const QList ¶ms); ReturnMessage::ReturnCode cmdChatLeaveChannel(const QList ¶ms); ReturnMessage::ReturnCode cmdChatSay(const QList ¶ms); ReturnMessage::ReturnCode cmdListGames(const QList ¶ms); ReturnMessage::ReturnCode cmdCreateGame(const QList ¶ms); ReturnMessage::ReturnCode cmdJoinGame(const QList ¶ms); ReturnMessage::ReturnCode cmdLeaveGame(const QList ¶ms); ReturnMessage::ReturnCode cmdListPlayers(const QList ¶ms); ReturnMessage::ReturnCode cmdSay(const QList ¶ms); ReturnMessage::ReturnCode cmdSubmitDeck(const QList ¶ms); ReturnMessage::ReturnCode cmdReadyStart(const QList ¶ms); ReturnMessage::ReturnCode cmdShuffle(const QList ¶ms); ReturnMessage::ReturnCode cmdDrawCards(const QList ¶ms); ReturnMessage::ReturnCode cmdRevealCard(const QList ¶ms); ReturnMessage::ReturnCode cmdMoveCard(const QList ¶ms); ReturnMessage::ReturnCode cmdCreateToken(const QList ¶ms); ReturnMessage::ReturnCode cmdSetCardAttr(const QList ¶ms); ReturnMessage::ReturnCode cmdIncCounter(const QList ¶ms); ReturnMessage::ReturnCode cmdAddCounter(const QList ¶ms); ReturnMessage::ReturnCode cmdSetCounter(const QList ¶ms); ReturnMessage::ReturnCode cmdDelCounter(const QList ¶ms); ReturnMessage::ReturnCode cmdListCounters(const QList ¶ms); ReturnMessage::ReturnCode cmdListZones(const QList ¶ms); ReturnMessage::ReturnCode cmdDumpZone(const QList ¶ms); ReturnMessage::ReturnCode cmdStopDumpZone(const QList ¶ms); ReturnMessage::ReturnCode cmdRollDie(const QList ¶ms); ReturnMessage::ReturnCode cmdNextTurn(const QList ¶ms); ReturnMessage::ReturnCode cmdSetActivePhase(const QList ¶ms); Server *server; ServerGame *game; QList chatChannels; QList DeckList; QList SideboardList; QList zones; QList counters; int playerId; QString playerName; int nextCardId; int newCardId(); PlayerZone *getZone(const QString &name) const; Counter *getCounter(const QString &name) const; void clearZones(); void leaveGame(); bool parseCommand(QString line); PlayerStatusEnum PlayerStatus; ReturnMessage *remsg; AuthenticationResult authState; bool acceptsGameListChanges; bool acceptsChatChannelListChanges; public: ServerSocket(Server *_server, QObject *parent = 0); ~ServerSocket(); void msg(const QString &s); void setGame(ServerGame *g); PlayerStatusEnum getStatus(); void setStatus(PlayerStatusEnum status); void initConnection(); int getPlayerId() const { return playerId; } void setPlayerId(int _id) { playerId = _id; } QString getPlayerName() const { return playerName; } bool getAcceptsGameListChanges() const { return acceptsGameListChanges; } bool getAcceptsChatChannelListChanges() const { return acceptsChatChannelListChanges; } QStringList listCounters() const; QStringList listZones() const; void setupZones(); }; #endif