diff --git a/src/net/clientstate.h b/src/net/clientstate.h index 42f2274d..2017984f 100644 --- a/src/net/clientstate.h +++ b/src/net/clientstate.h @@ -201,6 +201,24 @@ protected: virtual int InternalProcess(ClientThread &client, boost::shared_ptr packet); }; +// State: Wait for Join. +class ClientStateWaitJoin : public AbstractClientStateReceiving +{ +public: + // Access the state singleton. + static ClientStateWaitJoin &Instance(); + + virtual ~ClientStateWaitJoin(); + + +protected: + + // Protected constructor - this is a singleton. + ClientStateWaitJoin(); + + virtual int InternalProcess(ClientThread &client, boost::shared_ptr packet); +}; + // State: Wait for start of the game or start info. class ClientStateWaitGame : public AbstractClientStateReceiving { diff --git a/src/net/clientthread.h b/src/net/clientthread.h index 194b1ec8..f5c10e44 100644 --- a/src/net/clientthread.h +++ b/src/net/clientthread.h @@ -56,6 +56,8 @@ public: void SendStartEvent(); void SendPlayerAction(); void SendChatMessage(const std::string &msg); + void SendJoinGame(const std::string &name); + void SendCreateGame(const GameData &gameData); ClientCallback &GetCallback(); GuiInterface &GetGui(); @@ -122,6 +124,7 @@ friend class ClientStateStartConnect; friend class ClientStateConnecting; friend class ClientStateStartSession; friend class ClientStateWaitSession; +friend class ClientStateWaitJoin; friend class ClientStateWaitGame; friend class ClientStateWaitHand; friend class ClientStateRunHand; diff --git a/src/net/common/clientstate.cpp b/src/net/common/clientstate.cpp index 69a0af01..d2f8450c 100644 --- a/src/net/common/clientstate.cpp +++ b/src/net/common/clientstate.cpp @@ -448,7 +448,7 @@ ClientStateWaitSession::InternalProcess(ClientThread &client, boost::shared_ptr< playerData->SetName(context.GetPlayerName()); client.AddPlayerData(playerData); - client.SetState(ClientStateWaitGame::Instance()); + client.SetState(ClientStateWaitJoin::Instance()); retVal = MSG_SOCK_SESSION_DONE; } @@ -457,6 +457,45 @@ ClientStateWaitSession::InternalProcess(ClientThread &client, boost::shared_ptr< //----------------------------------------------------------------------------- +ClientStateWaitJoin & +ClientStateWaitJoin::Instance() +{ + static ClientStateWaitJoin state; + return state; +} + +ClientStateWaitJoin::ClientStateWaitJoin() +{ +} + +ClientStateWaitJoin::~ClientStateWaitJoin() +{ +} + +int +ClientStateWaitJoin::InternalProcess(ClientThread &client, boost::shared_ptr packet) +{ + int retVal = MSG_SOCK_INTERNAL_PENDING; + + if (packet->ToNetPacketJoinGameAck()) + { + // Successfully joined a game. + NetPacketJoinGameAck::Data joinGameAckData; + packet->ToNetPacketJoinGameAck()->GetData(joinGameAckData); + client.SetGameData(joinGameAckData.gameData); + boost::shared_ptr tmpPlayer = client.GetPlayerDataByUniqueId(client.GetGuiPlayerId()); + assert(tmpPlayer.get()); + tmpPlayer->SetRights(joinGameAckData.prights); + + client.SetState(ClientStateWaitGame::Instance()); + retVal = MSG_NET_GAME_CLIENT_JOIN; + } + + return retVal; +} + +//----------------------------------------------------------------------------- + ClientStateWaitGame & ClientStateWaitGame::Instance() { diff --git a/src/net/common/clientthread.cpp b/src/net/common/clientthread.cpp index 2cdd2025..8ea5d3ef 100644 --- a/src/net/common/clientthread.cpp +++ b/src/net/common/clientthread.cpp @@ -146,6 +146,18 @@ ClientThread::SendChatMessage(const std::string &msg) } } +void +ClientThread::SendJoinGame(const std::string &name) +{ + // TODO +} + +void +ClientThread::SendCreateGame(const GameData &gameData) +{ + // TODO +} + ClientCallback & ClientThread::GetCallback() { diff --git a/src/net/socket_msg.h b/src/net/socket_msg.h index f8df2ff1..9da53f74 100644 --- a/src/net/socket_msg.h +++ b/src/net/socket_msg.h @@ -72,7 +72,8 @@ #define MSG_SOCK_LAST MSG_SOCK_SESSION_DONE // The following messages are game messages. -#define MSG_NET_GAME_CLIENT_START 5 +#define MSG_NET_GAME_CLIENT_JOIN 5 +#define MSG_NET_GAME_CLIENT_START 6 #define MSG_NET_GAME_CLIENT_HAND_START 7 #define MSG_NET_GAME_CLIENT_HAND_END 8 #define MSG_NET_GAME_CLIENT_END 9