guest IP-check and number of guest in lobby check combined now in one function
This commit is contained in:
@@ -65,7 +65,6 @@
|
||||
|
||||
#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_GUEST_USERS 100 // LG: Maximum number of guests users allowed
|
||||
|
||||
#define SERVER_SAVE_STATISTICS_INTERVAL_SEC 60
|
||||
#define SERVER_CHECK_SESSION_TIMEOUTS_INTERVAL_MSEC 500
|
||||
@@ -1051,7 +1050,7 @@ ServerLobbyThread::HandleNetPacketInit(boost::shared_ptr<SessionData> session, c
|
||||
bool validGuest = false;
|
||||
// productive: if (initMessage.login() == InitMessage::guestLogin) {
|
||||
// debug: if (initMessage.login() == InitMessage::unauthenticatedLogin) {
|
||||
if (initMessage.login() == InitMessage::guestLogin) {
|
||||
if (initMessage.login() == InitMessage::unauthenticatedLogin) {
|
||||
playerName = initMessage.nickname();
|
||||
// Verify guest player name.
|
||||
if (playerName.length() > sizeof(SERVER_GUEST_PLAYER_NAME - 1)
|
||||
@@ -1061,12 +1060,9 @@ ServerLobbyThread::HandleNetPacketInit(boost::shared_ptr<SessionData> session, c
|
||||
validGuest = true;
|
||||
noAuth = true;
|
||||
}
|
||||
// check if a guest session with same ip is already connected - decline if true
|
||||
if(m_sessionManager.IsGuestConnectedMultiple(session->GetClientAddr())) {
|
||||
SessionError(session, ERR_NET_SERVER_FULL);
|
||||
return;
|
||||
}
|
||||
if (m_sessionManager.GetGuestsCount() + m_gameSessionManager.GetGuestsCount() > SERVER_MAX_GUEST_USERS) {
|
||||
// check if a guest session in lobby with same ip is already connected and
|
||||
// if number of lobby guests >= SERVER_MAX_GUEST_USERS_LOBBY
|
||||
if(!m_sessionManager.IsGuestAllowedToConnect(session->GetClientAddr())) {
|
||||
SessionError(session, ERR_NET_SERVER_FULL);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -34,8 +34,11 @@
|
||||
#include <net/serverexception.h>
|
||||
#include <net/socket_msg.h>
|
||||
|
||||
#include <core/loghelper.h> // debug - remove me
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define SERVER_MAX_GUEST_USERS_LOBBY 50 // LG: Maximum number of guests users in lobby allowed
|
||||
|
||||
SessionManager::SessionManager()
|
||||
{
|
||||
@@ -248,23 +251,25 @@ SessionManager::IsClientAddressConnected(const std::string &clientAddress) const
|
||||
}
|
||||
|
||||
bool
|
||||
SessionManager::IsGuestConnectedMultiple(const std::string &clientAddress) const
|
||||
SessionManager::IsGuestAllowedToConnect(const std::string &clientAddress) const
|
||||
{
|
||||
bool retVal = false;
|
||||
bool retVal = true;
|
||||
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
|
||||
|
||||
SessionMap::const_iterator i = m_sessionMap.begin();
|
||||
SessionMap::const_iterator end = m_sessionMap.end();
|
||||
|
||||
int num = 0;
|
||||
while (i != end) {
|
||||
boost::shared_ptr<PlayerData> tmpPlayer(i->second->GetPlayerData());
|
||||
// productive:
|
||||
//if(tmpPlayer && tmpPlayer->GetRights() == PLAYER_RIGHTS_GUEST && i->second->GetClientAddr() == clientAddress){
|
||||
// debug:
|
||||
// if(tmpPlayer && tmpPlayer->GetRights() == PLAYER_RIGHTS_NORMAL && i->second->GetClientAddr() == clientAddress){
|
||||
if(tmpPlayer && tmpPlayer->GetRights() == PLAYER_RIGHTS_GUEST && i->second->GetClientAddr() == clientAddress) {
|
||||
retVal = true;
|
||||
break;
|
||||
if(tmpPlayer && tmpPlayer->GetRights() == PLAYER_RIGHTS_GUEST){
|
||||
num++;
|
||||
if(i->second->GetClientAddr() == clientAddress || num >= SERVER_MAX_GUEST_USERS_LOBBY) {
|
||||
// guest has same ip as another guest in lobby or
|
||||
// number of guests in lobby >= SERVER_MAX_GUEST_USERS_LOBBY => not allowed
|
||||
retVal = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
++i;
|
||||
}
|
||||
@@ -433,20 +438,3 @@ SessionManager::SendToAllButOneSessions(SenderHelper &sender, boost::shared_ptr<
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public:
|
||||
bool IsPlayerConnected(const std::string &playerName) const;
|
||||
bool IsPlayerConnected(unsigned uniqueId) const;
|
||||
bool IsClientAddressConnected(const std::string &clientAddress) const;
|
||||
bool IsGuestConnectedMultiple(const std::string &clientAddress) const;
|
||||
bool IsGuestAllowedToConnect(const std::string &clientAddress) const;
|
||||
|
||||
void ForEach(boost::function<void (boost::shared_ptr<SessionData>)> func);
|
||||
|
||||
@@ -75,7 +75,6 @@ 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);
|
||||
|
||||
Reference in New Issue
Block a user