The server now sends a notification if the game name is already in use.
This commit is contained in:
@@ -1283,9 +1283,14 @@ ServerLobbyThread::HandleNetPacketCreateGame(SessionWrapper session, const std::
|
||||
// Create a new game.
|
||||
GameData tmpData;
|
||||
NetPacket::GetGameData(&newGame.gameInfo, tmpData);
|
||||
string gameName(STL_STRING_FROM_OCTET_STRING(newGame.gameInfo.gameName));
|
||||
unsigned gameId = GetNextGameId();
|
||||
|
||||
if (session.playerData->GetRights() == PLAYER_RIGHTS_GUEST
|
||||
if (IsGameNameInUse(gameName))
|
||||
{
|
||||
SendJoinGameFailed(session.sessionData, gameId, NTF_NET_JOIN_GAME_NAME_IN_USE);
|
||||
}
|
||||
else if (session.playerData->GetRights() == PLAYER_RIGHTS_GUEST
|
||||
&& tmpData.gameType != GAME_TYPE_NORMAL)
|
||||
{
|
||||
SendJoinGameFailed(session.sessionData, gameId, NTF_NET_JOIN_GUEST_FORBIDDEN);
|
||||
@@ -1296,7 +1301,7 @@ ServerLobbyThread::HandleNetPacketCreateGame(SessionWrapper session, const std::
|
||||
new ServerGame(
|
||||
shared_from_this(),
|
||||
gameId,
|
||||
STL_STRING_FROM_OCTET_STRING(newGame.gameInfo.gameName),
|
||||
gameName,
|
||||
password,
|
||||
tmpData,
|
||||
session.playerData->GetUniqueId(),
|
||||
@@ -1639,6 +1644,25 @@ ServerLobbyThread::TimerCleanupAvatarCache(const boost::system::error_code &ec)
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
ServerLobbyThread::IsGameNameInUse(const std::string &gameName) const
|
||||
{
|
||||
bool found = false;
|
||||
GameMap::const_iterator i = m_gameMap.begin();
|
||||
GameMap::const_iterator end = m_gameMap.end();
|
||||
|
||||
while (i != end)
|
||||
{
|
||||
if ((*i).second->GetName() == gameName)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
boost::shared_ptr<ServerGame>
|
||||
ServerLobbyThread::InternalGetGameFromId(unsigned gameId)
|
||||
{
|
||||
|
||||
@@ -199,7 +199,7 @@ SessionManager::IsPlayerConnected(const string &playerName) const
|
||||
|
||||
SessionWrapper tmpSession = GetSessionByPlayerName(playerName);
|
||||
|
||||
if (tmpSession.sessionData.get() && tmpSession.playerData.get())
|
||||
if (tmpSession.sessionData && tmpSession.playerData)
|
||||
retVal = true;
|
||||
|
||||
return retVal;
|
||||
@@ -212,7 +212,7 @@ SessionManager::IsPlayerConnected(unsigned uniqueId) const
|
||||
|
||||
SessionWrapper tmpSession = GetSessionByUniquePlayerId(uniqueId);
|
||||
|
||||
if (tmpSession.sessionData.get() && tmpSession.playerData.get())
|
||||
if (tmpSession.sessionData && tmpSession.playerData)
|
||||
retVal = true;
|
||||
|
||||
return retVal;
|
||||
|
||||
@@ -154,6 +154,7 @@ protected:
|
||||
void TimerCheckSessionTimeouts(const boost::system::error_code &ec);
|
||||
void TimerCleanupAvatarCache(const boost::system::error_code &ec);
|
||||
|
||||
bool IsGameNameInUse(const std::string &gameName) const;
|
||||
boost::shared_ptr<ServerGame> InternalGetGameFromId(unsigned gameId);
|
||||
void InternalAddGame(boost::shared_ptr<ServerGame> game);
|
||||
void InternalRemoveGame(boost::shared_ptr<ServerGame> game);
|
||||
|
||||
Reference in New Issue
Block a user