More work on server selection. Currently untested.
This commit is contained in:
@@ -188,6 +188,22 @@ protected:
|
|||||||
ClientStateReadingServerList();
|
ClientStateReadingServerList();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// State: Waiting for the user to choose a server.
|
||||||
|
class ClientStateWaitChooseServer : public ClientState
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static ClientStateWaitChooseServer &Instance();
|
||||||
|
|
||||||
|
virtual ~ClientStateWaitChooseServer();
|
||||||
|
|
||||||
|
virtual int Process(ClientThread &client);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
// Protected constructor - this is a singleton.
|
||||||
|
ClientStateWaitChooseServer();
|
||||||
|
};
|
||||||
|
|
||||||
// State: Initiate server connection.
|
// State: Initiate server connection.
|
||||||
class ClientStateStartConnect : public ClientState
|
class ClientStateStartConnect : public ClientState
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ public:
|
|||||||
void SendAskKickPlayer(unsigned playerId);
|
void SendAskKickPlayer(unsigned playerId);
|
||||||
void SendVoteKick(bool doKick);
|
void SendVoteKick(bool doKick);
|
||||||
|
|
||||||
|
void SelectServer(unsigned serverId);
|
||||||
ServerInfo GetServerInfo(unsigned serverId) const;
|
ServerInfo GetServerInfo(unsigned serverId) const;
|
||||||
|
|
||||||
GameInfo GetGameInfo(unsigned gameId) const;
|
GameInfo GetGameInfo(unsigned gameId) const;
|
||||||
@@ -153,6 +154,7 @@ protected:
|
|||||||
|
|
||||||
void AddServerInfo(unsigned serverId, const ServerInfo &info);
|
void AddServerInfo(unsigned serverId, const ServerInfo &info);
|
||||||
void ClearServerInfoMap();
|
void ClearServerInfoMap();
|
||||||
|
bool GetSelectedServer(unsigned &serverId) const;
|
||||||
void UseServer(unsigned serverId);
|
void UseServer(unsigned serverId);
|
||||||
|
|
||||||
unsigned GetGameIdByName(const std::string &name) const;
|
unsigned GetGameIdByName(const std::string &name) const;
|
||||||
@@ -199,6 +201,10 @@ private:
|
|||||||
ServerInfoMap m_serverInfoMap;
|
ServerInfoMap m_serverInfoMap;
|
||||||
mutable boost::mutex m_serverInfoMapMutex;
|
mutable boost::mutex m_serverInfoMapMutex;
|
||||||
|
|
||||||
|
bool m_isServerSelected;
|
||||||
|
unsigned m_selectedServerId;
|
||||||
|
mutable boost::mutex m_selectServerMutex;
|
||||||
|
|
||||||
GameInfoMap m_gameInfoMap;
|
GameInfoMap m_gameInfoMap;
|
||||||
mutable boost::mutex m_gameInfoMapMutex;
|
mutable boost::mutex m_gameInfoMapMutex;
|
||||||
|
|
||||||
|
|||||||
@@ -504,11 +504,12 @@ ClientStateReadingServerList::Process(ClientThread &client)
|
|||||||
if (serverCount == 1)
|
if (serverCount == 1)
|
||||||
{
|
{
|
||||||
client.UseServer(lastServerInfoId);
|
client.UseServer(lastServerInfoId);
|
||||||
|
client.SetState(ClientStateStartResolve::Instance());
|
||||||
retVal = MSG_SOCK_SERVER_LIST_DONE;
|
retVal = MSG_SOCK_SERVER_LIST_DONE;
|
||||||
}
|
}
|
||||||
else if (serverCount > 0)
|
else if (serverCount > 1)
|
||||||
{
|
{
|
||||||
// TODO....
|
client.SetState(ClientStateWaitChooseServer::Instance());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw ClientException(__FILE__, __LINE__, ERR_SOCK_INVALID_SERVERLIST_XML, 0);
|
throw ClientException(__FILE__, __LINE__, ERR_SOCK_INVALID_SERVERLIST_XML, 0);
|
||||||
@@ -516,7 +517,41 @@ ClientStateReadingServerList::Process(ClientThread &client)
|
|||||||
else
|
else
|
||||||
throw ClientException(__FILE__, __LINE__, ERR_SOCK_INVALID_SERVERLIST_XML, 0);
|
throw ClientException(__FILE__, __LINE__, ERR_SOCK_INVALID_SERVERLIST_XML, 0);
|
||||||
|
|
||||||
client.SetState(ClientStateStartResolve::Instance());
|
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
ClientStateWaitChooseServer &
|
||||||
|
ClientStateWaitChooseServer::Instance()
|
||||||
|
{
|
||||||
|
static ClientStateWaitChooseServer state;
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
ClientStateWaitChooseServer::ClientStateWaitChooseServer()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ClientStateWaitChooseServer::~ClientStateWaitChooseServer()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ClientStateWaitChooseServer::Process(ClientThread &client)
|
||||||
|
{
|
||||||
|
int retVal = MSG_SOCK_INTERNAL_PENDING;
|
||||||
|
|
||||||
|
unsigned serverId;
|
||||||
|
if (client.GetSelectedServer(serverid))
|
||||||
|
{
|
||||||
|
client.UseServer(serverid);
|
||||||
|
client.SetState(ClientStateStartResolve::Instance());
|
||||||
|
retVal = MSG_SOCK_SERVER_LIST_DONE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Thread::Msleep(20);
|
||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
@@ -1593,7 +1628,7 @@ ClientStateFinal::~ClientStateFinal()
|
|||||||
int
|
int
|
||||||
ClientStateFinal::Process(ClientThread &/*client*/)
|
ClientStateFinal::Process(ClientThread &/*client*/)
|
||||||
{
|
{
|
||||||
Thread::Msleep(10);
|
Thread::Msleep(20);
|
||||||
|
|
||||||
return MSG_SOCK_INTERNAL_PENDING;
|
return MSG_SOCK_INTERNAL_PENDING;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
ClientThread::ClientThread(GuiInterface &gui, AvatarManager &avatarManager)
|
ClientThread::ClientThread(GuiInterface &gui, AvatarManager &avatarManager)
|
||||||
: m_curState(NULL), m_gui(gui), m_avatarManager(avatarManager),
|
: m_curState(NULL), m_gui(gui), m_avatarManager(avatarManager), m_isServerSelected(false),
|
||||||
m_curGameId(0), m_curGameNum(1), m_guiPlayerId(0), m_sessionEstablished(false)
|
m_curGameId(0), m_curGameNum(1), m_guiPlayerId(0), m_sessionEstablished(false)
|
||||||
{
|
{
|
||||||
m_ioService.reset(new boost::asio::io_service());
|
m_ioService.reset(new boost::asio::io_service());
|
||||||
@@ -284,6 +284,14 @@ ClientThread::SendVoteKick(bool doKick)
|
|||||||
m_outPacketList.push_back(vote);
|
m_outPacketList.push_back(vote);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ClientThread::SelectServer(unsigned serverId)
|
||||||
|
{
|
||||||
|
boost::mutex::scoped_lock lock(m_selectServerMutex);
|
||||||
|
m_isServerSelected = true;
|
||||||
|
m_selectedServerId = serverId;
|
||||||
|
}
|
||||||
|
|
||||||
ServerInfo
|
ServerInfo
|
||||||
ClientThread::GetServerInfo(unsigned serverId) const
|
ClientThread::GetServerInfo(unsigned serverId) const
|
||||||
{
|
{
|
||||||
@@ -974,6 +982,18 @@ ClientThread::ClearServerInfoMap()
|
|||||||
//GetCallback().SignalNetClientServerListClear();
|
//GetCallback().SignalNetClientServerListClear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ClientThread::GetSelectedServer(unsigned &serverId) const
|
||||||
|
{
|
||||||
|
bool retVal = false;
|
||||||
|
boost::mutex::scoped_lock lock(m_selectServerMutex);
|
||||||
|
if (m_isServerSelected)
|
||||||
|
{
|
||||||
|
retVal = true;
|
||||||
|
serverId = m_selectedServerId;
|
||||||
|
}
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ClientThread::UseServer(unsigned serverId)
|
ClientThread::UseServer(unsigned serverId)
|
||||||
|
|||||||
@@ -404,6 +404,13 @@ void Session::startVoteKickPlayer(unsigned playerId)
|
|||||||
myNetClient->SendAskKickPlayer(playerId);
|
myNetClient->SendAskKickPlayer(playerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Session::selectServer(unsigned serverId)
|
||||||
|
{
|
||||||
|
if (!myNetClient)
|
||||||
|
return; // only act if client is running.
|
||||||
|
myNetClient->SelectServer(serverId);
|
||||||
|
}
|
||||||
|
|
||||||
void Session::voteKick(bool doKick)
|
void Session::voteKick(bool doKick)
|
||||||
{
|
{
|
||||||
if (!myNetClient)
|
if (!myNetClient)
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ public:
|
|||||||
void kickPlayer(const std::string &playerName);
|
void kickPlayer(const std::string &playerName);
|
||||||
void startVoteKickPlayer(unsigned playerId);
|
void startVoteKickPlayer(unsigned playerId);
|
||||||
void voteKick(bool doKick);
|
void voteKick(bool doKick);
|
||||||
|
void selectServer(unsigned serverId);
|
||||||
|
|
||||||
void resetNetworkTimeout();
|
void resetNetworkTimeout();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user