Fixing ticket #81: Do not show a "you were kicked from the server" message if your username is already present in the lobby. Instead, kick the existing user from the lobby.

This commit is contained in:
lotodore
2011-12-27 17:26:03 +00:00
parent fb5938ef46
commit 0d71521559
2 changed files with 24 additions and 15 deletions
+22 -13
View File
@@ -1486,18 +1486,24 @@ ServerLobbyThread::EstablishSession(boost::shared_ptr<SessionData> session)
if (!session->GetPlayerData()) if (!session->GetPlayerData())
throw ServerException(__FILE__, __LINE__, ERR_NET_INVALID_SESSION, 0); throw ServerException(__FILE__, __LINE__, ERR_NET_INVALID_SESSION, 0);
u_int32_t rejoinPlayerId = 0; unsigned rejoinPlayerId = 0;
u_int32_t rejoinGameId = GetRejoinGameIdForPlayer(session->GetPlayerData()->GetName(), session->GetPlayerData()->GetOldGuid(), rejoinPlayerId); u_int32_t rejoinGameId = GetRejoinGameIdForPlayer(session->GetPlayerData()->GetName(), session->GetPlayerData()->GetOldGuid(), rejoinPlayerId);
if (rejoinGameId != 0) { if (rejoinGameId != 0) {
// Offer rejoin, and disconnect current player with the same name. // Offer rejoin, and disconnect current player with the same name.
InternalRemovePlayer(rejoinPlayerId, ERR_NET_PLAYER_NAME_IN_USE); InternalRemovePlayer(rejoinPlayerId, ERR_NET_PLAYER_NAME_IN_USE);
} } else {
// Check whether this player is already connected. // Check whether this player is already connected.
// We need to enforce this here to prevent duplicates. #ifdef POKERTH_OFFICIAL_SERVER
if (IsPlayerConnected(session->GetPlayerData()->GetName())) { // If so, and this is a login server, disconnect the already connected player.
SessionError(session, ERR_NET_PLAYER_KICKED); unsigned previousPlayerId = GetPlayerId(session->GetPlayerData()->GetName());
if (previousPlayerId != 0) {
InternalRemovePlayer(previousPlayerId, ERR_NET_PLAYER_NAME_IN_USE);
}
#else
// If this is a server without password protection, close this new session and return.
SessionError(session, ERR_NET_PLAYER_NAME_IN_USE);
return; return;
#endif
} }
// Run postlogin for DB // Run postlogin for DB
@@ -2027,17 +2033,20 @@ ServerLobbyThread::GetGui()
return m_gui; return m_gui;
} }
bool unsigned
ServerLobbyThread::IsPlayerConnected(const string &name) const ServerLobbyThread::GetPlayerId(const string &name) const
{ {
bool retVal = false; unsigned playerId = 0;
retVal = m_sessionManager.IsPlayerConnected(name); boost::shared_ptr<SessionData> tmpSession(m_sessionManager.GetSessionByPlayerName(name));
if (!retVal) if (!tmpSession)
retVal = m_gameSessionManager.IsPlayerConnected(name); tmpSession = m_gameSessionManager.GetSessionByPlayerName(name);
return retVal; if (tmpSession && tmpSession->GetPlayerData())
playerId = tmpSession->GetPlayerData()->GetUniqueId();
return playerId;
} }
boost::shared_ptr<NetPacket> boost::shared_ptr<NetPacket>
+1 -1
View File
@@ -188,7 +188,7 @@ protected:
GuiInterface &GetGui(); GuiInterface &GetGui();
ServerIrcBotCallback &GetIrcBotCallback(); ServerIrcBotCallback &GetIrcBotCallback();
bool IsPlayerConnected(const std::string &name) const; unsigned GetPlayerId(const std::string &name) const;
static boost::shared_ptr<NetPacket> CreateNetPacketPlayerListNew(unsigned playerId); static boost::shared_ptr<NetPacket> CreateNetPacketPlayerListNew(unsigned playerId);
static boost::shared_ptr<NetPacket> CreateNetPacketPlayerListLeft(unsigned playerId); static boost::shared_ptr<NetPacket> CreateNetPacketPlayerListLeft(unsigned playerId);