Limit Guests users
This commit is contained in:
@@ -248,8 +248,8 @@ NetPacket::GameErrorToNetError(int gameErrorReason)
|
|||||||
case ERR_NET_SESSION_TIMED_OUT :
|
case ERR_NET_SESSION_TIMED_OUT :
|
||||||
retVal = ErrorMessage::sessionTimeout;
|
retVal = ErrorMessage::sessionTimeout;
|
||||||
break;
|
break;
|
||||||
case ERR_NET_TOO_MANY_GUESTS :
|
case ERR_NET_FULL_GUESTS :
|
||||||
retVal = ErrorMessage::initServerFull; // @TODO: maybe create a better error message
|
retVal = ErrorMessage::initServerFull; // LG: @TODO: maybe create a better error message, if possible
|
||||||
break;
|
break;
|
||||||
default :
|
default :
|
||||||
retVal = ErrorMessage::reserved;
|
retVal = ErrorMessage::reserved;
|
||||||
|
|||||||
@@ -65,7 +65,7 @@
|
|||||||
|
|
||||||
#define SERVER_MAX_NUM_LOBBY_SESSIONS 512 // Maximum number of idle users in lobby.
|
#define SERVER_MAX_NUM_LOBBY_SESSIONS 512 // Maximum number of idle users in lobby.
|
||||||
#define SERVER_MAX_NUM_TOTAL_SESSIONS 2000 // Total maximum of sessions, fitting a 2048 handle limit
|
#define SERVER_MAX_NUM_TOTAL_SESSIONS 2000 // Total maximum of sessions, fitting a 2048 handle limit
|
||||||
#define SERVER_MAX_GUEST_USERS 150 // Maximum number of guests users allowed
|
#define SERVER_MAX_GUEST_USERS 100 // LG: Maximum number of guests users allowed
|
||||||
|
|
||||||
#define SERVER_SAVE_STATISTICS_INTERVAL_SEC 60
|
#define SERVER_SAVE_STATISTICS_INTERVAL_SEC 60
|
||||||
#define SERVER_CHECK_SESSION_TIMEOUTS_INTERVAL_MSEC 500
|
#define SERVER_CHECK_SESSION_TIMEOUTS_INTERVAL_MSEC 500
|
||||||
@@ -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_mode(mode), m_serverConfig(serverConfig), m_curGameId(0), m_curUniquePlayerId(0), m_curSessionId(INVALID_SESSION + 1),
|
||||||
m_statDataChanged(false), m_removeGameTimer(*ioService),
|
m_statDataChanged(false), m_removeGameTimer(*ioService),
|
||||||
m_saveStatisticsTimer(*ioService), m_loginLockTimer(*ioService),
|
m_saveStatisticsTimer(*ioService), m_loginLockTimer(*ioService),
|
||||||
m_startTime(boost::posix_time::second_clock::local_time())
|
m_startTime(boost::posix_time::second_clock::local_time()), guests_(0)
|
||||||
{
|
{
|
||||||
m_internalServerCallback.reset(new InternalServerCallback(*this));
|
m_internalServerCallback.reset(new InternalServerCallback(*this));
|
||||||
m_sender.reset(new SenderHelper(m_ioService));
|
m_sender.reset(new SenderHelper(m_ioService));
|
||||||
@@ -397,8 +397,8 @@ ServerLobbyThread::CloseSession(boost::shared_ptr<SessionData> session)
|
|||||||
m_gameSessionManager.RemoveSession(session->GetId());
|
m_gameSessionManager.RemoveSession(session->GetId());
|
||||||
|
|
||||||
if (session->GetPlayerData()){
|
if (session->GetPlayerData()){
|
||||||
if (session->GetPlayerData()->GetRights() == PLAYER_RIGHTS_GUEST){
|
if (session->GetPlayerData()->GetRights() == PLAYER_RIGHTS_GUEST) {
|
||||||
m_sessionManager.DecrementGuest();
|
DecrementGuests();
|
||||||
}
|
}
|
||||||
NotifyPlayerLeftLobby(session->GetPlayerData()->GetUniqueId());
|
NotifyPlayerLeftLobby(session->GetPlayerData()->GetUniqueId());
|
||||||
}
|
}
|
||||||
@@ -1015,7 +1015,6 @@ ServerLobbyThread::HandleNetPacketInit(boost::shared_ptr<SessionData> session, c
|
|||||||
// @XXX: debug tests
|
// @XXX: debug tests
|
||||||
//if(m_sessionManager.IsGuestConnectedMultiple(session->GetClientAddr())){
|
//if(m_sessionManager.IsGuestConnectedMultiple(session->GetClientAddr())){
|
||||||
// LOG_ERROR("Guest with IP " << session->GetClientAddr() << " already connected! Should be declined!");
|
// LOG_ERROR("Guest with IP " << session->GetClientAddr() << " already connected! Should be declined!");
|
||||||
//LOG_ERROR("number of guests (before this session is accepted) = " << m_sessionManager.GetGuestUsers() << ".");
|
|
||||||
//}
|
//}
|
||||||
// @XXX: end debug tests
|
// @XXX: end debug tests
|
||||||
|
|
||||||
@@ -1074,18 +1073,21 @@ ServerLobbyThread::HandleNetPacketInit(boost::shared_ptr<SessionData> session, c
|
|||||||
// @XXX: check if a guest session with same ip is already connected - decline if true
|
// @XXX: check if a guest session with same ip is already connected - decline if true
|
||||||
if(m_sessionManager.IsGuestConnectedMultiple(session->GetClientAddr())){
|
if(m_sessionManager.IsGuestConnectedMultiple(session->GetClientAddr())){
|
||||||
//LOG_ERROR("Guest with IP " << session->GetClientAddr() << " already connected! Decline!");
|
//LOG_ERROR("Guest with IP " << session->GetClientAddr() << " already connected! Decline!");
|
||||||
SessionError(session, ERR_NET_TOO_MANY_GUESTS);
|
SessionError(session, ERR_NET_FULL_GUESTS);
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (m_sessionManager.GetGuestUsers() >= SERVER_MAX_GUEST_USERS) {
|
|
||||||
SessionError(session, ERR_NET_TOO_MANY_GUESTS);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!validGuest) {
|
if (!validGuest) {
|
||||||
SessionError(session, ERR_NET_INVALID_PLAYER_NAME);
|
SessionError(session, ERR_NET_INVALID_PLAYER_NAME);
|
||||||
return;
|
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
|
#ifdef POKERTH_OFFICIAL_SERVER
|
||||||
else if (initMessage.login() == InitMessage::authenticatedLogin) {
|
else if (initMessage.login() == InitMessage::authenticatedLogin) {
|
||||||
@@ -1146,10 +1148,6 @@ ServerLobbyThread::HandleNetPacketInit(boost::shared_ptr<SessionData> session, c
|
|||||||
m_sessionManager.SetSessionPlayerData(session->GetId(), tmpPlayerData);
|
m_sessionManager.SetSessionPlayerData(session->GetId(), tmpPlayerData);
|
||||||
session->SetPlayerData(tmpPlayerData);
|
session->SetPlayerData(tmpPlayerData);
|
||||||
|
|
||||||
if (validGuest){
|
|
||||||
m_sessionManager.IncrementGuest();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (noAuth)
|
if (noAuth)
|
||||||
InitAfterLogin(session);
|
InitAfterLogin(session);
|
||||||
else
|
else
|
||||||
@@ -1764,6 +1762,11 @@ ServerLobbyThread::EstablishSession(boost::shared_ptr<SessionData> session)
|
|||||||
// Session is now established.
|
// Session is now established.
|
||||||
session->SetState(SessionData::Established);
|
session->SetState(SessionData::Established);
|
||||||
|
|
||||||
|
// LG: Increment guests
|
||||||
|
if (session->GetPlayerData()->GetRights() == PLAYER_RIGHTS_GUEST) {
|
||||||
|
IncrementGuests();
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock lock(m_statMutex);
|
boost::mutex::scoped_lock lock(m_statMutex);
|
||||||
++m_statData.totalPlayersEverLoggedIn;
|
++m_statData.totalPlayersEverLoggedIn;
|
||||||
@@ -2394,3 +2397,15 @@ ServerLobbyThread::GetRejoinGameIdForPlayer(const std::string &playerName, const
|
|||||||
return retGameId;
|
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_;
|
||||||
|
}
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ using namespace std;
|
|||||||
|
|
||||||
SessionManager::SessionManager()
|
SessionManager::SessionManager()
|
||||||
{
|
{
|
||||||
guestUsers = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SessionManager::~SessionManager()
|
SessionManager::~SessionManager()
|
||||||
@@ -433,18 +432,3 @@ SessionManager::SendToAllButOneSessions(SenderHelper &sender, boost::shared_ptr<
|
|||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
SessionManager::IncrementGuest() {
|
|
||||||
guestUsers++;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
SessionManager::DecrementGuest() {
|
|
||||||
guestUsers--;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
SessionManager::GetGuestUsers() const {
|
|
||||||
return guestUsers;
|
|
||||||
}
|
|
||||||
@@ -36,6 +36,7 @@
|
|||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
#include <boost/enable_shared_from_this.hpp>
|
#include <boost/enable_shared_from_this.hpp>
|
||||||
#include <boost/uuid/uuid_generators.hpp>
|
#include <boost/uuid/uuid_generators.hpp>
|
||||||
|
#include <boost/atomic.hpp>
|
||||||
|
|
||||||
#include <net/sessionmanager.h>
|
#include <net/sessionmanager.h>
|
||||||
#include <net/netpacket.h>
|
#include <net/netpacket.h>
|
||||||
@@ -224,6 +225,11 @@ protected:
|
|||||||
|
|
||||||
u_int32_t GetRejoinGameIdForPlayer(const std::string &playerName, const std::string &guid, unsigned &outPlayerUniqueId);
|
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:
|
private:
|
||||||
|
|
||||||
boost::shared_ptr<boost::asio::io_service> m_ioService;
|
boost::shared_ptr<boost::asio::io_service> m_ioService;
|
||||||
@@ -276,6 +282,9 @@ private:
|
|||||||
|
|
||||||
const boost::posix_time::ptime m_startTime;
|
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;
|
friend class InternalServerCallback;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -80,10 +80,6 @@ public:
|
|||||||
void SendLobbyMsgToAllSessions(SenderHelper &sender, boost::shared_ptr<NetPacket> packet, int state);
|
void SendLobbyMsgToAllSessions(SenderHelper &sender, boost::shared_ptr<NetPacket> packet, int state);
|
||||||
void SendToAllButOneSessions(SenderHelper &sender, boost::shared_ptr<NetPacket> packet, SessionId except, int state);
|
void SendToAllButOneSessions(SenderHelper &sender, boost::shared_ptr<NetPacket> packet, SessionId except, int state);
|
||||||
|
|
||||||
void IncrementGuest();
|
|
||||||
void DecrementGuest();
|
|
||||||
int GetGuestUsers() const;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
typedef std::map<SessionId, boost::shared_ptr<SessionData> > SessionMap;
|
typedef std::map<SessionId, boost::shared_ptr<SessionData> > SessionMap;
|
||||||
@@ -92,8 +88,6 @@ private:
|
|||||||
|
|
||||||
SessionMap m_sessionMap;
|
SessionMap m_sessionMap;
|
||||||
mutable boost::recursive_mutex m_sessionMapMutex;
|
mutable boost::recursive_mutex m_sessionMapMutex;
|
||||||
|
|
||||||
int guestUsers;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -98,7 +98,8 @@
|
|||||||
#define ERR_NET_GSASL_INIT_FAILED 134
|
#define ERR_NET_GSASL_INIT_FAILED 134
|
||||||
#define ERR_NET_GSASL_NO_SCRAM 135
|
#define ERR_NET_GSASL_NO_SCRAM 135
|
||||||
#define ERR_NET_DB_CONNECT_FAILED 136
|
#define ERR_NET_DB_CONNECT_FAILED 136
|
||||||
#define ERR_NET_TOO_MANY_GUESTS 137
|
// LG: New code for max number of guest users
|
||||||
|
#define ERR_NET_FULL_GUESTS 137
|
||||||
|
|
||||||
#define ERR_IRC_INTERNAL 151
|
#define ERR_IRC_INTERNAL 151
|
||||||
#define ERR_IRC_CONNECT_FAILED 152
|
#define ERR_IRC_CONNECT_FAILED 152
|
||||||
|
|||||||
+1900
-3084
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user