First work on client code to support multiple games per server.
This commit is contained in:
@@ -201,6 +201,24 @@ protected:
|
|||||||
virtual int InternalProcess(ClientThread &client, boost::shared_ptr<NetPacket> packet);
|
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.
|
// State: Wait for start of the game or start info.
|
||||||
class ClientStateWaitGame : public AbstractClientStateReceiving
|
class ClientStateWaitGame : public AbstractClientStateReceiving
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ public:
|
|||||||
void SendStartEvent();
|
void SendStartEvent();
|
||||||
void SendPlayerAction();
|
void SendPlayerAction();
|
||||||
void SendChatMessage(const std::string &msg);
|
void SendChatMessage(const std::string &msg);
|
||||||
|
void SendJoinGame(const std::string &name);
|
||||||
|
void SendCreateGame(const GameData &gameData);
|
||||||
|
|
||||||
ClientCallback &GetCallback();
|
ClientCallback &GetCallback();
|
||||||
GuiInterface &GetGui();
|
GuiInterface &GetGui();
|
||||||
@@ -122,6 +124,7 @@ friend class ClientStateStartConnect;
|
|||||||
friend class ClientStateConnecting;
|
friend class ClientStateConnecting;
|
||||||
friend class ClientStateStartSession;
|
friend class ClientStateStartSession;
|
||||||
friend class ClientStateWaitSession;
|
friend class ClientStateWaitSession;
|
||||||
|
friend class ClientStateWaitJoin;
|
||||||
friend class ClientStateWaitGame;
|
friend class ClientStateWaitGame;
|
||||||
friend class ClientStateWaitHand;
|
friend class ClientStateWaitHand;
|
||||||
friend class ClientStateRunHand;
|
friend class ClientStateRunHand;
|
||||||
|
|||||||
@@ -448,7 +448,7 @@ ClientStateWaitSession::InternalProcess(ClientThread &client, boost::shared_ptr<
|
|||||||
playerData->SetName(context.GetPlayerName());
|
playerData->SetName(context.GetPlayerName());
|
||||||
client.AddPlayerData(playerData);
|
client.AddPlayerData(playerData);
|
||||||
|
|
||||||
client.SetState(ClientStateWaitGame::Instance());
|
client.SetState(ClientStateWaitJoin::Instance());
|
||||||
retVal = MSG_SOCK_SESSION_DONE;
|
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 &
|
||||||
ClientStateWaitGame::Instance()
|
ClientStateWaitGame::Instance()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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 &
|
ClientCallback &
|
||||||
ClientThread::GetCallback()
|
ClientThread::GetCallback()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -72,7 +72,8 @@
|
|||||||
#define MSG_SOCK_LAST MSG_SOCK_SESSION_DONE
|
#define MSG_SOCK_LAST MSG_SOCK_SESSION_DONE
|
||||||
|
|
||||||
// The following messages are game messages.
|
// 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_START 7
|
||||||
#define MSG_NET_GAME_CLIENT_HAND_END 8
|
#define MSG_NET_GAME_CLIENT_HAND_END 8
|
||||||
#define MSG_NET_GAME_CLIENT_END 9
|
#define MSG_NET_GAME_CLIENT_END 9
|
||||||
|
|||||||
Reference in New Issue
Block a user