Network timeout system also works from within a game now.

This commit is contained in:
lotodore
2008-03-06 15:27:31 +00:00
parent a3aee2b33a
commit e107cf98fa
7 changed files with 100 additions and 95 deletions
+11 -11
View File
@@ -68,10 +68,10 @@ ServerGameThread::AddSession(SessionWrapper session)
} }
void void
ServerGameThread::KickPlayer(unsigned playerId) ServerGameThread::RemovePlayer(unsigned playerId, unsigned errorCode)
{ {
boost::mutex::scoped_lock lock(m_kickPlayerListMutex); boost::mutex::scoped_lock lock(m_removePlayerListMutex);
m_kickPlayerList.push_back(playerId); m_removePlayerList.push_back(RemovePlayerList::value_type(playerId, errorCode));
} }
GameState GameState
@@ -127,7 +127,7 @@ ServerGameThread::Main()
} }
// Process current state. // Process current state.
GetState().Process(*this); GetState().Process(*this);
KickPlayerLoop(); RemovePlayerLoop();
} while (!ShouldTerminate() && GetSessionManager().HasSessions()); } while (!ShouldTerminate() && GetSessionManager().HasSessions());
} catch (const PokerTHException &e) } catch (const PokerTHException &e)
{ {
@@ -140,22 +140,22 @@ ServerGameThread::Main()
} }
void void
ServerGameThread::KickPlayerLoop() ServerGameThread::RemovePlayerLoop()
{ {
boost::mutex::scoped_lock lock(m_kickPlayerListMutex); boost::mutex::scoped_lock lock(m_removePlayerListMutex);
PlayerIdList::iterator i = m_kickPlayerList.begin(); RemovePlayerList::iterator i = m_removePlayerList.begin();
PlayerIdList::iterator end = m_kickPlayerList.end(); RemovePlayerList::iterator end = m_removePlayerList.end();
while (i != end) while (i != end)
{ {
SessionWrapper tmpSession = GetSessionManager().GetSessionByUniquePlayerId(*i); SessionWrapper tmpSession = GetSessionManager().GetSessionByUniquePlayerId(i->first);
// Only kick if the player was found. // Only kick if the player was found.
if (tmpSession.sessionData.get()) if (tmpSession.sessionData.get())
SessionError(tmpSession, ERR_NET_PLAYER_KICKED); SessionError(tmpSession, i->second);
++i; ++i;
} }
m_kickPlayerList.clear(); m_removePlayerList.clear();
} }
void void
+57 -39
View File
@@ -34,21 +34,23 @@
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#define SERVER_MAX_NUM_SESSIONS 512 // Maximum number of idle users in lobby. #define SERVER_MAX_NUM_SESSIONS 512 // Maximum number of idle users in lobby.
#define SERVER_CACHE_CLEANUP_INTERVAL_SEC 86400 // 1 day #define SERVER_CACHE_CLEANUP_INTERVAL_SEC 86400 // 1 day
#define SERVER_SAVE_STATISTICS_INTERVAL_SEC 60 #define SERVER_SAVE_STATISTICS_INTERVAL_SEC 60
#define SERVER_INIT_AVATAR_CLIENT_LOCK_SEC 30 // Forbid a client to send an additional avatar. #define SERVER_INIT_AVATAR_CLIENT_LOCK_SEC 30 // Forbid a client to send an additional avatar.
#define SERVER_INIT_SESSION_TIMEOUT_SEC 20 #define SERVER_INIT_SESSION_TIMEOUT_SEC 20
#define SERVER_TIMEOUT_WARNING_REMAINING_SEC 60 #define SERVER_TIMEOUT_WARNING_REMAINING_SEC 60
#define SERVER_SESSION_ACTIVITY_TIMEOUT_SEC 90 // MUST be > SERVER_TIMEOUT_WARNING_REMAINING_SEC #define SERVER_SESSION_ACTIVITY_TIMEOUT_SEC 90 // MUST be > SERVER_TIMEOUT_WARNING_REMAINING_SEC
#define SERVER_SESSION_FORCED_TIMEOUT_SEC 300 // Should be quite large. #define SERVER_SESSION_FORCED_TIMEOUT_SEC 300 // Should be quite large.
#define SERVER_STATISTICS_FILE_NAME "server_statistics.log" #define SERVER_CHECK_SESSION_TIMEOUTS_INTERVAL_MSEC 500
#define SERVER_STATISTICS_STR_TOTAL_PLAYERS "TotalNumPlayersLoggedIn"
#define SERVER_STATISTICS_STR_TOTAL_GAMES "TotalNumGamesCreated" #define SERVER_STATISTICS_FILE_NAME "server_statistics.log"
#define SERVER_STATISTICS_STR_MAX_GAMES "MaxGamesOpen" #define SERVER_STATISTICS_STR_TOTAL_PLAYERS "TotalNumPlayersLoggedIn"
#define SERVER_STATISTICS_STR_MAX_PLAYERS "MaxPlayersLoggedIn" #define SERVER_STATISTICS_STR_TOTAL_GAMES "TotalNumGamesCreated"
#define SERVER_STATISTICS_STR_MAX_GAMES "MaxGamesOpen"
#define SERVER_STATISTICS_STR_MAX_PLAYERS "MaxPlayersLoggedIn"
using namespace std; using namespace std;
@@ -232,14 +234,20 @@ ServerLobbyThread::KickPlayerByName(const std::string &playerName)
if (session.sessionData.get() && session.playerData.get()) if (session.sessionData.get() && session.playerData.get())
{ {
boost::mutex::scoped_lock lock(m_kickPlayerListMutex); RemovePlayer(session.playerData->GetUniqueId(), ERR_NET_PLAYER_KICKED);
m_kickPlayerList.push_back(session.playerData->GetUniqueId());
retVal = true; retVal = true;
} }
return retVal; return retVal;
} }
void
ServerLobbyThread::RemovePlayer(unsigned playerId, unsigned errorCode)
{
boost::mutex::scoped_lock lock(m_removePlayerListMutex);
m_removePlayerList.push_back(RemovePlayerList::value_type(playerId, errorCode));
}
void void
ServerLobbyThread::AddComputerPlayer(boost::shared_ptr<PlayerData> player) ServerLobbyThread::AddComputerPlayer(boost::shared_ptr<PlayerData> player)
{ {
@@ -311,10 +319,9 @@ ServerLobbyThread::Main()
// Remove games. // Remove games.
RemoveGameLoop(); RemoveGameLoop();
// Kick players. // Kick players.
KickPlayerLoop(); RemovePlayerLoop();
// Check session timeouts. // Check session timeouts.
m_sessionManager.ForEachRemoveIf(boost::bind(&ServerLobbyThread::CheckSessionTimeouts, boost::ref(*this), _1)); CheckSessionTimeoutsLoop();
m_gameSessionManager.ForEachRemoveIf(boost::bind(&ServerLobbyThread::CheckSessionTimeouts, boost::ref(*this), _1));
// Update avatar limitation lock. // Update avatar limitation lock.
UpdateAvatarClientTimerLoop(); UpdateAvatarClientTimerLoop();
// Cleanup cache. // Cleanup cache.
@@ -792,19 +799,31 @@ ServerLobbyThread::RemoveGameLoop()
} }
void void
ServerLobbyThread::KickPlayerLoop() ServerLobbyThread::RemovePlayerLoop()
{ {
boost::mutex::scoped_lock lock(m_kickPlayerListMutex); boost::mutex::scoped_lock lock(m_removePlayerListMutex);
PlayerIdList::iterator i = m_kickPlayerList.begin(); RemovePlayerList::iterator i = m_removePlayerList.begin();
PlayerIdList::iterator end = m_kickPlayerList.end(); RemovePlayerList::iterator end = m_removePlayerList.end();
while (i != end) while (i != end)
{ {
InternalKickPlayer(*i); InternalRemovePlayer(i->first, i->second);
++i; ++i;
} }
m_kickPlayerList.clear(); m_removePlayerList.clear();
}
void
ServerLobbyThread::CheckSessionTimeoutsLoop()
{
if (m_checkSessionTimeoutsTimer.elapsed().total_milliseconds() >= SERVER_CHECK_SESSION_TIMEOUTS_INTERVAL_MSEC)
{
m_sessionManager.ForEach(boost::bind(&ServerLobbyThread::InternalCheckSessionTimeouts, boost::ref(*this), _1));
m_gameSessionManager.ForEach(boost::bind(&ServerLobbyThread::InternalCheckSessionTimeouts, boost::ref(*this), _1));
m_checkSessionTimeoutsTimer.reset();
m_checkSessionTimeoutsTimer.start();
}
} }
void void
@@ -829,7 +848,7 @@ void
ServerLobbyThread::CleanupAvatarCache() ServerLobbyThread::CleanupAvatarCache()
{ {
// Only act on timer and if there are no sessions. // Only act on timer and if there are no sessions.
if (m_cacheCleanupTimer.elapsed().total_seconds() > SERVER_CACHE_CLEANUP_INTERVAL_SEC if (m_cacheCleanupTimer.elapsed().total_seconds() >= SERVER_CACHE_CLEANUP_INTERVAL_SEC
&& !m_sessionManager.HasSessions() && !m_gameSessionManager.HasSessions()) && !m_sessionManager.HasSessions() && !m_gameSessionManager.HasSessions())
{ {
m_avatarManager.RemoveOldAvatarCacheEntries(); m_avatarManager.RemoveOldAvatarCacheEntries();
@@ -871,11 +890,11 @@ ServerLobbyThread::InternalRemoveGame(boost::shared_ptr<ServerGameThread> game)
} }
void void
ServerLobbyThread::InternalKickPlayer(unsigned playerId) ServerLobbyThread::InternalRemovePlayer(unsigned playerId, unsigned errorCode)
{ {
SessionWrapper session = m_sessionManager.GetSessionByUniquePlayerId(playerId); SessionWrapper session = m_sessionManager.GetSessionByUniquePlayerId(playerId);
if (session.sessionData.get()) if (session.sessionData.get())
SessionError(session, ERR_NET_PLAYER_KICKED); SessionError(session, errorCode);
else else
{ {
// Scan games for the player. // Scan games for the player.
@@ -887,7 +906,7 @@ ServerLobbyThread::InternalKickPlayer(unsigned playerId)
boost::shared_ptr<ServerGameThread> tmpGame = i->second; boost::shared_ptr<ServerGameThread> tmpGame = i->second;
if (tmpGame->GetPlayerDataByUniqueId(playerId).get()) if (tmpGame->GetPlayerDataByUniqueId(playerId).get())
{ {
tmpGame->KickPlayer(playerId); tmpGame->RemovePlayer(playerId, errorCode);
break; break;
} }
++i; ++i;
@@ -966,14 +985,14 @@ ServerLobbyThread::HandleReAddedSession(SessionWrapper session)
} }
} }
bool void
ServerLobbyThread::CheckSessionTimeouts(SessionWrapper session) ServerLobbyThread::InternalCheckSessionTimeouts(SessionWrapper session)
{ {
bool retVal = false; bool closeSession = false;
if (session.sessionData.get()) if (session.sessionData.get() && session.playerData.get())
{ {
if (session.sessionData->GetState() == SessionData::Init && session.sessionData->GetAutoDisconnectTimerElapsedSec() >= SERVER_INIT_SESSION_TIMEOUT_SEC) if (session.sessionData->GetState() == SessionData::Init && session.sessionData->GetAutoDisconnectTimerElapsedSec() >= SERVER_INIT_SESSION_TIMEOUT_SEC)
retVal = true; closeSession = true;
else if (session.sessionData->GetActivityTimerElapsedSec() >= SERVER_SESSION_ACTIVITY_TIMEOUT_SEC - SERVER_TIMEOUT_WARNING_REMAINING_SEC else if (session.sessionData->GetActivityTimerElapsedSec() >= SERVER_SESSION_ACTIVITY_TIMEOUT_SEC - SERVER_TIMEOUT_WARNING_REMAINING_SEC
&& !session.sessionData->HasActivityNoticeBeenSent()) && !session.sessionData->HasActivityNoticeBeenSent())
{ {
@@ -987,16 +1006,15 @@ ServerLobbyThread::CheckSessionTimeouts(SessionWrapper session)
} }
else if (session.sessionData->GetActivityTimerElapsedSec() >= SERVER_SESSION_ACTIVITY_TIMEOUT_SEC) else if (session.sessionData->GetActivityTimerElapsedSec() >= SERVER_SESSION_ACTIVITY_TIMEOUT_SEC)
{ {
// TODO SendError(session.sessionData, errorCode); closeSession = true;
retVal = true;
} }
else if (session.sessionData->GetAutoDisconnectTimerElapsedSec() >= SERVER_SESSION_FORCED_TIMEOUT_SEC) else if (session.sessionData->GetAutoDisconnectTimerElapsedSec() >= SERVER_SESSION_FORCED_TIMEOUT_SEC)
{ {
// TODO SendError(session.sessionData, errorCode); closeSession = true;
retVal = true;
} }
} }
return retVal; if (closeSession)
RemovePlayer(session.playerData->GetUniqueId(), ERR_NET_PLAYER_KICKED); // TODO new error code
} }
void void
@@ -1120,7 +1138,7 @@ ServerLobbyThread::ReadStatisticsFile()
void void
ServerLobbyThread::SaveStatisticsFile() ServerLobbyThread::SaveStatisticsFile()
{ {
if (m_saveStatisticsTimer.elapsed().total_seconds() > SERVER_SAVE_STATISTICS_INTERVAL_SEC) if (m_saveStatisticsTimer.elapsed().total_seconds() >= SERVER_SAVE_STATISTICS_INTERVAL_SEC)
{ {
{ {
boost::mutex::scoped_lock lock(m_statMutex); boost::mutex::scoped_lock lock(m_statMutex);
+18 -34
View File
@@ -37,7 +37,7 @@ SessionManager::~SessionManager()
bool bool
SessionManager::HasSessions() const SessionManager::HasSessions() const
{ {
boost::mutex::scoped_lock lock(m_sessionMapMutex); boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
return !m_sessionMap.empty(); return !m_sessionMap.empty();
} }
@@ -50,7 +50,7 @@ SessionManager::AddSession(boost::shared_ptr<SessionData> sessionData)
void void
SessionManager::AddSession(SessionWrapper session) SessionManager::AddSession(SessionWrapper session)
{ {
boost::mutex::scoped_lock lock(m_sessionMapMutex); boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
SessionMap::iterator pos = m_sessionMap.lower_bound(session.sessionData->GetId()); SessionMap::iterator pos = m_sessionMap.lower_bound(session.sessionData->GetId());
@@ -66,7 +66,7 @@ SessionManager::AddSession(SessionWrapper session)
void void
SessionManager::SetSessionPlayerData(SessionId session, boost::shared_ptr<PlayerData> playerData) SessionManager::SetSessionPlayerData(SessionId session, boost::shared_ptr<PlayerData> playerData)
{ {
boost::mutex::scoped_lock lock(m_sessionMapMutex); boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
SessionMap::iterator pos = m_sessionMap.find(session); SessionMap::iterator pos = m_sessionMap.find(session);
if (pos != m_sessionMap.end()) if (pos != m_sessionMap.end())
@@ -76,7 +76,7 @@ SessionManager::SetSessionPlayerData(SessionId session, boost::shared_ptr<Player
void void
SessionManager::RemoveSession(SessionId session) SessionManager::RemoveSession(SessionId session)
{ {
boost::mutex::scoped_lock lock(m_sessionMapMutex); boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
m_sessionMap.erase(session); m_sessionMap.erase(session);
} }
@@ -89,7 +89,7 @@ SessionManager::Select(unsigned timeoutMsec)
FD_ZERO(&rdset); FD_ZERO(&rdset);
{ {
boost::mutex::scoped_lock lock(m_sessionMapMutex); boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
SessionMap::iterator i = m_sessionMap.begin(); SessionMap::iterator i = m_sessionMap.begin();
SessionMap::iterator end = m_sessionMap.end(); SessionMap::iterator end = m_sessionMap.end();
@@ -131,7 +131,7 @@ SessionManager::Select(unsigned timeoutMsec)
if (selectResult > 0) // one (or more) of the sockets is readable if (selectResult > 0) // one (or more) of the sockets is readable
{ {
// Check which socket is readable, return the first. // Check which socket is readable, return the first.
boost::mutex::scoped_lock lock(m_sessionMapMutex); boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
SessionMap::iterator i = m_sessionMap.begin(); SessionMap::iterator i = m_sessionMap.begin();
SessionMap::iterator end = m_sessionMap.end(); SessionMap::iterator end = m_sessionMap.end();
@@ -154,7 +154,7 @@ SessionWrapper
SessionManager::GetSessionByPlayerName(const string playerName) const SessionManager::GetSessionByPlayerName(const string playerName) const
{ {
SessionWrapper tmpSession; SessionWrapper tmpSession;
boost::mutex::scoped_lock lock(m_sessionMapMutex); boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
SessionMap::const_iterator session_i = m_sessionMap.begin(); SessionMap::const_iterator session_i = m_sessionMap.begin();
SessionMap::const_iterator session_end = m_sessionMap.end(); SessionMap::const_iterator session_end = m_sessionMap.end();
@@ -183,7 +183,7 @@ SessionWrapper
SessionManager::GetSessionByUniquePlayerId(unsigned uniqueId) const SessionManager::GetSessionByUniquePlayerId(unsigned uniqueId) const
{ {
SessionWrapper tmpSession; SessionWrapper tmpSession;
boost::mutex::scoped_lock lock(m_sessionMapMutex); boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
SessionMap::const_iterator session_i = m_sessionMap.begin(); SessionMap::const_iterator session_i = m_sessionMap.begin();
SessionMap::const_iterator session_end = m_sessionMap.end(); SessionMap::const_iterator session_end = m_sessionMap.end();
@@ -212,7 +212,7 @@ PlayerDataList
SessionManager::GetPlayerDataList() const SessionManager::GetPlayerDataList() const
{ {
PlayerDataList playerList; PlayerDataList playerList;
boost::mutex::scoped_lock lock(m_sessionMapMutex); boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
SessionMap::const_iterator session_i = m_sessionMap.begin(); SessionMap::const_iterator session_i = m_sessionMap.begin();
SessionMap::const_iterator session_end = m_sessionMap.end(); SessionMap::const_iterator session_end = m_sessionMap.end();
@@ -236,7 +236,7 @@ PlayerIdList
SessionManager::GetPlayerIdList() const SessionManager::GetPlayerIdList() const
{ {
PlayerIdList playerList; PlayerIdList playerList;
boost::mutex::scoped_lock lock(m_sessionMapMutex); boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
SessionMap::const_iterator session_i = m_sessionMap.begin(); SessionMap::const_iterator session_i = m_sessionMap.begin();
SessionMap::const_iterator session_end = m_sessionMap.end(); SessionMap::const_iterator session_end = m_sessionMap.end();
@@ -282,22 +282,7 @@ SessionManager::IsPlayerConnected(unsigned uniqueId) const
void void
SessionManager::ForEach(boost::function<void (SessionWrapper)> func) SessionManager::ForEach(boost::function<void (SessionWrapper)> func)
{ {
boost::mutex::scoped_lock lock(m_sessionMapMutex); boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
SessionMap::iterator i = m_sessionMap.begin();
SessionMap::iterator end = m_sessionMap.end();
while (i != end)
{
func((*i).second);
++i;
}
}
void
SessionManager::ForEachRemoveIf(boost::function<bool (SessionWrapper)> func)
{
boost::mutex::scoped_lock lock(m_sessionMapMutex);
SessionMap::iterator i = m_sessionMap.begin(); SessionMap::iterator i = m_sessionMap.begin();
SessionMap::iterator end = m_sessionMap.end(); SessionMap::iterator end = m_sessionMap.end();
@@ -306,8 +291,7 @@ SessionManager::ForEachRemoveIf(boost::function<bool (SessionWrapper)> func)
{ {
SessionMap::iterator next = i; SessionMap::iterator next = i;
next++; next++;
if (func((*i).second)) func((*i).second);
m_sessionMap.erase(i);
i = next; i = next;
} }
} }
@@ -316,7 +300,7 @@ unsigned
SessionManager::CountReadySessions() const SessionManager::CountReadySessions() const
{ {
unsigned counter = 0; unsigned counter = 0;
boost::mutex::scoped_lock lock(m_sessionMapMutex); boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
SessionMap::const_iterator i = m_sessionMap.begin(); SessionMap::const_iterator i = m_sessionMap.begin();
SessionMap::const_iterator end = m_sessionMap.end(); SessionMap::const_iterator end = m_sessionMap.end();
@@ -333,7 +317,7 @@ SessionManager::CountReadySessions() const
void void
SessionManager::ResetAllReadyFlags() SessionManager::ResetAllReadyFlags()
{ {
boost::mutex::scoped_lock lock(m_sessionMapMutex); boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
SessionMap::iterator i = m_sessionMap.begin(); SessionMap::iterator i = m_sessionMap.begin();
SessionMap::iterator end = m_sessionMap.end(); SessionMap::iterator end = m_sessionMap.end();
@@ -348,7 +332,7 @@ SessionManager::ResetAllReadyFlags()
void void
SessionManager::Clear() SessionManager::Clear()
{ {
boost::mutex::scoped_lock lock(m_sessionMapMutex); boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
// Sockets will be closed automatically. // Sockets will be closed automatically.
m_sessionMap.clear(); m_sessionMap.clear();
@@ -357,14 +341,14 @@ SessionManager::Clear()
unsigned unsigned
SessionManager::GetRawSessionCount() SessionManager::GetRawSessionCount()
{ {
boost::mutex::scoped_lock lock(m_sessionMapMutex); boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
return m_sessionMap.size(); return m_sessionMap.size();
} }
void void
SessionManager::SendToAllSessions(SenderThread &sender, boost::shared_ptr<NetPacket> packet, SessionData::State state) SessionManager::SendToAllSessions(SenderThread &sender, boost::shared_ptr<NetPacket> packet, SessionData::State state)
{ {
boost::mutex::scoped_lock lock(m_sessionMapMutex); boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
SessionMap::iterator i = m_sessionMap.begin(); SessionMap::iterator i = m_sessionMap.begin();
SessionMap::iterator end = m_sessionMap.end(); SessionMap::iterator end = m_sessionMap.end();
@@ -384,7 +368,7 @@ SessionManager::SendToAllSessions(SenderThread &sender, boost::shared_ptr<NetPac
void void
SessionManager::SendToAllButOneSessions(SenderThread &sender, boost::shared_ptr<NetPacket> packet, SessionId except, SessionData::State state) SessionManager::SendToAllButOneSessions(SenderThread &sender, boost::shared_ptr<NetPacket> packet, SessionId except, SessionData::State state)
{ {
boost::mutex::scoped_lock lock(m_sessionMapMutex); boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
SessionMap::iterator i = m_sessionMap.begin(); SessionMap::iterator i = m_sessionMap.begin();
SessionMap::iterator end = m_sessionMap.end(); SessionMap::iterator end = m_sessionMap.end();
+4 -4
View File
@@ -49,7 +49,7 @@ public:
const std::string &GetName() const; const std::string &GetName() const;
void AddSession(SessionWrapper session); void AddSession(SessionWrapper session);
void KickPlayer(unsigned playerId); void RemovePlayer(unsigned playerId, unsigned errorCode);
ServerCallback &GetCallback(); ServerCallback &GetCallback();
GameState GetCurRound() const; GameState GetCurRound() const;
@@ -80,7 +80,7 @@ protected:
// Main function of the thread. // Main function of the thread.
virtual void Main(); virtual void Main();
void KickPlayerLoop(); void RemovePlayerLoop();
void InternalStartGame(); void InternalStartGame();
void ResetGame(); void ResetGame();
@@ -132,8 +132,8 @@ private:
PlayerDataList m_computerPlayerList; PlayerDataList m_computerPlayerList;
mutable boost::mutex m_computerPlayerListMutex; mutable boost::mutex m_computerPlayerListMutex;
PlayerIdList m_kickPlayerList; RemovePlayerList m_removePlayerList;
mutable boost::mutex m_kickPlayerListMutex; mutable boost::mutex m_removePlayerListMutex;
unsigned m_adminPlayerId; unsigned m_adminPlayerId;
mutable boost::mutex m_adminPlayerIdMutex; mutable boost::mutex m_adminPlayerIdMutex;
+8 -5
View File
@@ -68,6 +68,7 @@ public:
void HandleGameRetrieveAvatar(SessionWrapper session, const NetPacketRetrieveAvatar &tmpPacket); void HandleGameRetrieveAvatar(SessionWrapper session, const NetPacketRetrieveAvatar &tmpPacket);
bool KickPlayerByName(const std::string &playerName); bool KickPlayerByName(const std::string &playerName);
void RemovePlayer(unsigned playerId, unsigned errorCode);
void AddComputerPlayer(boost::shared_ptr<PlayerData> player); void AddComputerPlayer(boost::shared_ptr<PlayerData> player);
void RemoveComputerPlayer(boost::shared_ptr<PlayerData> player); void RemoveComputerPlayer(boost::shared_ptr<PlayerData> player);
@@ -114,20 +115,21 @@ protected:
void NewConnectionLoop(); void NewConnectionLoop();
void NewSessionLoop(); void NewSessionLoop();
void RemoveGameLoop(); void RemoveGameLoop();
void KickPlayerLoop(); void RemovePlayerLoop();
void CheckSessionTimeoutsLoop();
void UpdateAvatarClientTimerLoop(); void UpdateAvatarClientTimerLoop();
void CleanupAvatarCache(); void CleanupAvatarCache();
void InternalAddGame(boost::shared_ptr<ServerGameThread> game); void InternalAddGame(boost::shared_ptr<ServerGameThread> game);
void InternalRemoveGame(boost::shared_ptr<ServerGameThread> game); void InternalRemoveGame(boost::shared_ptr<ServerGameThread> game);
void InternalKickPlayer(unsigned playerId); void InternalRemovePlayer(unsigned playerId, unsigned errorCode);
void TerminateGames(); void TerminateGames();
void HandleNewConnection(boost::shared_ptr<ConnectData> connData); void HandleNewConnection(boost::shared_ptr<ConnectData> connData);
void HandleReAddedSession(SessionWrapper session); void HandleReAddedSession(SessionWrapper session);
bool CheckSessionTimeouts(SessionWrapper session); void InternalCheckSessionTimeouts(SessionWrapper session);
void CleanupConnectQueue(); void CleanupConnectQueue();
void CleanupSessionMap(); void CleanupSessionMap();
@@ -171,8 +173,8 @@ private:
RemoveGameList m_removeGameList; RemoveGameList m_removeGameList;
mutable boost::mutex m_removeGameListMutex; mutable boost::mutex m_removeGameListMutex;
PlayerIdList m_kickPlayerList; RemovePlayerList m_removePlayerList;
mutable boost::mutex m_kickPlayerListMutex; mutable boost::mutex m_removePlayerListMutex;
PlayerDataMap m_computerPlayers; PlayerDataMap m_computerPlayers;
mutable boost::mutex m_computerPlayersMutex; mutable boost::mutex m_computerPlayersMutex;
@@ -202,6 +204,7 @@ private:
boost::timers::portable::microsec_timer m_cacheCleanupTimer; boost::timers::portable::microsec_timer m_cacheCleanupTimer;
boost::timers::portable::microsec_timer m_saveStatisticsTimer; boost::timers::portable::microsec_timer m_saveStatisticsTimer;
boost::timers::portable::microsec_timer m_checkSessionTimeoutsTimer;
const boost::posix_time::ptime m_startTime; const boost::posix_time::ptime m_startTime;
}; };
+1 -2
View File
@@ -66,7 +66,6 @@ public:
bool IsPlayerConnected(unsigned uniqueId) const; bool IsPlayerConnected(unsigned uniqueId) const;
void ForEach(boost::function<void (SessionWrapper)> func); void ForEach(boost::function<void (SessionWrapper)> func);
void ForEachRemoveIf(boost::function<bool (SessionWrapper)> func);
unsigned CountReadySessions() const; unsigned CountReadySessions() const;
void ResetAllReadyFlags(); void ResetAllReadyFlags();
@@ -84,7 +83,7 @@ protected:
private: private:
SessionMap m_sessionMap; SessionMap m_sessionMap;
mutable boost::mutex m_sessionMapMutex; mutable boost::recursive_mutex m_sessionMapMutex;
}; };
#endif #endif
+1
View File
@@ -110,6 +110,7 @@ private:
}; };
typedef std::list<unsigned> PlayerIdList; typedef std::list<unsigned> PlayerIdList;
typedef std::list<std::pair<unsigned, unsigned> > RemovePlayerList;
typedef std::list<boost::shared_ptr<PlayerData> > PlayerDataList; typedef std::list<boost::shared_ptr<PlayerData> > PlayerDataList;
typedef std::map<unsigned, boost::shared_ptr<PlayerData> > PlayerDataMap; typedef std::map<unsigned, boost::shared_ptr<PlayerData> > PlayerDataMap;