Get guest users from session manager
This commit is contained in:
@@ -248,9 +248,6 @@ NetPacket::GameErrorToNetError(int gameErrorReason)
|
||||
case ERR_NET_SESSION_TIMED_OUT :
|
||||
retVal = ErrorMessage::sessionTimeout;
|
||||
break;
|
||||
case ERR_NET_FULL_GUESTS :
|
||||
retVal = ErrorMessage::initServerFull; // LG: @TODO: maybe create a better error message, if possible
|
||||
break;
|
||||
default :
|
||||
retVal = ErrorMessage::reserved;
|
||||
break;
|
||||
|
||||
@@ -223,7 +223,7 @@ ServerLobbyThread::ServerLobbyThread(GuiInterface &gui, ServerMode mode, ServerI
|
||||
m_mode(mode), m_serverConfig(serverConfig), m_curGameId(0), m_curUniquePlayerId(0), m_curSessionId(INVALID_SESSION + 1),
|
||||
m_statDataChanged(false), m_removeGameTimer(*ioService),
|
||||
m_saveStatisticsTimer(*ioService), m_loginLockTimer(*ioService),
|
||||
m_startTime(boost::posix_time::second_clock::local_time()), guests_(0)
|
||||
m_startTime(boost::posix_time::second_clock::local_time())
|
||||
{
|
||||
m_internalServerCallback.reset(new InternalServerCallback(*this));
|
||||
m_sender.reset(new SenderHelper(m_ioService));
|
||||
@@ -397,9 +397,6 @@ ServerLobbyThread::CloseSession(boost::shared_ptr<SessionData> session)
|
||||
m_gameSessionManager.RemoveSession(session->GetId());
|
||||
|
||||
if (session->GetPlayerData()) {
|
||||
if (session->GetPlayerData()->GetRights() == PLAYER_RIGHTS_GUEST) {
|
||||
DecrementGuests();
|
||||
}
|
||||
NotifyPlayerLeftLobby(session->GetPlayerData()->GetUniqueId());
|
||||
}
|
||||
// Update stats (if needed).
|
||||
@@ -1066,7 +1063,11 @@ ServerLobbyThread::HandleNetPacketInit(boost::shared_ptr<SessionData> session, c
|
||||
}
|
||||
// check if a guest session with same ip is already connected - decline if true
|
||||
if(m_sessionManager.IsGuestConnectedMultiple(session->GetClientAddr())) {
|
||||
SessionError(session, ERR_NET_FULL_GUESTS);
|
||||
SessionError(session, ERR_NET_SERVER_FULL);
|
||||
return;
|
||||
}
|
||||
if (m_sessionManager.GetGuestsCount() + m_gameSessionManager.GetGuestsCount() > SERVER_MAX_GUEST_USERS) {
|
||||
SessionError(session, ERR_NET_SERVER_FULL);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1075,12 +1076,6 @@ ServerLobbyThread::HandleNetPacketInit(boost::shared_ptr<SessionData> session, c
|
||||
SessionError(session, ERR_NET_INVALID_PLAYER_NAME);
|
||||
return;
|
||||
}
|
||||
// LG: If user is guest, and SERVER_MAX_GUEST_USERS reached, don't allow connection.
|
||||
else if (getGuests() > SERVER_MAX_GUEST_USERS) {
|
||||
SessionError(session, ERR_NET_FULL_GUESTS);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
#ifdef POKERTH_OFFICIAL_SERVER
|
||||
else if (initMessage.login() == InitMessage::authenticatedLogin) {
|
||||
@@ -1755,11 +1750,6 @@ ServerLobbyThread::EstablishSession(boost::shared_ptr<SessionData> session)
|
||||
// Session is now established.
|
||||
session->SetState(SessionData::Established);
|
||||
|
||||
// LG: Increment guests
|
||||
if (session->GetPlayerData()->GetRights() == PLAYER_RIGHTS_GUEST) {
|
||||
IncrementGuests();
|
||||
}
|
||||
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_statMutex);
|
||||
++m_statData.totalPlayersEverLoggedIn;
|
||||
@@ -2389,16 +2379,3 @@ ServerLobbyThread::GetRejoinGameIdForPlayer(const std::string &playerName, const
|
||||
}
|
||||
return retGameId;
|
||||
}
|
||||
|
||||
// LG: Handle guests_ variable. Remove in production to access variable itself
|
||||
void ServerLobbyThread::DecrementGuests() {
|
||||
this->guests_.fetch_sub(1);
|
||||
}
|
||||
|
||||
void ServerLobbyThread::IncrementGuests() {
|
||||
this->guests_.fetch_add(1);
|
||||
}
|
||||
|
||||
int ServerLobbyThread::getGuests() {
|
||||
return this->guests_;
|
||||
}
|
||||
|
||||
@@ -432,3 +432,21 @@ SessionManager::SendToAllButOneSessions(SenderHelper &sender, boost::shared_ptr<
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned
|
||||
SessionManager::GetGuestsCount() const
|
||||
{
|
||||
unsigned counter = 0;
|
||||
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
|
||||
|
||||
SessionMap::const_iterator i = m_sessionMap.begin();
|
||||
SessionMap::const_iterator end = m_sessionMap.end();
|
||||
|
||||
while (i != end) {
|
||||
if (i->second && i->second->GetPlayerData() &&
|
||||
i->second->GetPlayerData()->GetRights() == PLAYER_RIGHTS_GUEST)
|
||||
++counter;
|
||||
++i;
|
||||
}
|
||||
return counter;
|
||||
}
|
||||
|
||||
@@ -225,11 +225,6 @@ protected:
|
||||
|
||||
u_int32_t GetRejoinGameIdForPlayer(const std::string &playerName, const std::string &guid, unsigned &outPlayerUniqueId);
|
||||
|
||||
// LG: Handle guests_ counter. NOTE: These functions in production could be removed and access directly to guest_
|
||||
void IncrementGuests();
|
||||
void DecrementGuests();
|
||||
int getGuests();
|
||||
|
||||
private:
|
||||
|
||||
boost::shared_ptr<boost::asio::io_service> m_ioService;
|
||||
@@ -282,9 +277,6 @@ private:
|
||||
|
||||
const boost::posix_time::ptime m_startTime;
|
||||
|
||||
// LG: guest_ is thread safe, even if ServerLobbyThread pointer is shared accross the code, as long as it is ONLY ONE running instance
|
||||
boost::atomic<int> guests_;
|
||||
|
||||
friend class InternalServerCallback;
|
||||
};
|
||||
|
||||
|
||||
@@ -75,6 +75,7 @@ public:
|
||||
unsigned GetRawSessionCount() const;
|
||||
unsigned GetSessionCountWithState(int state) const;
|
||||
bool HasSessionWithState(int state) const;
|
||||
unsigned GetGuestsCount() const;
|
||||
|
||||
void SendToAllSessions(SenderHelper &sender, boost::shared_ptr<NetPacket> packet, int state);
|
||||
void SendLobbyMsgToAllSessions(SenderHelper &sender, boost::shared_ptr<NetPacket> packet, int state);
|
||||
|
||||
@@ -98,8 +98,6 @@
|
||||
#define ERR_NET_GSASL_INIT_FAILED 134
|
||||
#define ERR_NET_GSASL_NO_SCRAM 135
|
||||
#define ERR_NET_DB_CONNECT_FAILED 136
|
||||
// LG: New code for max number of guest users
|
||||
#define ERR_NET_FULL_GUESTS 137
|
||||
|
||||
#define ERR_IRC_INTERNAL 151
|
||||
#define ERR_IRC_CONNECT_FAILED 152
|
||||
|
||||
Reference in New Issue
Block a user