First work on client code to support multiple games per server.

This commit is contained in:
lotodore
2007-08-20 23:25:12 +00:00
parent 95e5ee47cc
commit 697f063eb1
5 changed files with 75 additions and 2 deletions
+18
View File
@@ -201,6 +201,24 @@ protected:
virtual int InternalProcess(ClientThread &client, boost::shared_ptr<NetPacket> 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<NetPacket> packet);
};
// State: Wait for start of the game or start info.
class ClientStateWaitGame : public AbstractClientStateReceiving
{
+3
View File
@@ -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;
+40 -1
View File
@@ -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<NetPacket> 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<PlayerData> 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()
{
+12
View File
@@ -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()
{
+2 -1
View File
@@ -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