Sending error if guest tries to join non-standard game.

This commit is contained in:
lotodore
2010-03-28 14:53:08 +00:00
parent 02ebb0d2b3
commit 93b45c1371
2 changed files with 39 additions and 17 deletions
+3
View File
@@ -1387,6 +1387,9 @@ ClientStateWaitJoin::InternalHandlePacket(boost::shared_ptr<ClientThread> client
case joinGameFailureReason_invalidPassword :
failureCode = NTF_NET_JOIN_INVALID_PASSWORD;
break;
case joinGameFailureReason_notAllowedAsGuest :
failureCode = NTF_NET_JOIN_GUEST_FORBIDDEN;
break;
default :
failureCode = NTF_NET_INTERNAL;
break;
+36 -17
View File
@@ -1261,22 +1261,31 @@ ServerLobbyThread::HandleNetPacketCreateGame(SessionWrapper session, const std::
// Create a new game.
GameData tmpData;
NetPacket::GetGameData(&newGame.gameInfo, tmpData);
boost::shared_ptr<ServerGame> game(
new ServerGame(
shared_from_this(),
GetNextGameId(),
STL_STRING_FROM_OCTET_STRING(newGame.gameInfo.gameName),
password,
tmpData,
session.playerData->GetUniqueId(),
GetGui(),
m_playerConfig));
game->Init();
// Add game to list of games.
InternalAddGame(game);
if (session.playerData->GetRights() == PLAYER_RIGHTS_GUEST
&& tmpData.gameType != GAME_TYPE_NORMAL)
{
SendJoinGameFailed(session.sessionData, NTF_NET_JOIN_GUEST_FORBIDDEN);
}
else
{
boost::shared_ptr<ServerGame> game(
new ServerGame(
shared_from_this(),
GetNextGameId(),
STL_STRING_FROM_OCTET_STRING(newGame.gameInfo.gameName),
password,
tmpData,
session.playerData->GetUniqueId(),
GetGui(),
m_playerConfig));
game->Init();
MoveSessionToGame(*game, session);
// Add game to list of games.
InternalAddGame(game);
MoveSessionToGame(*game, session);
}
}
void
@@ -1287,15 +1296,22 @@ ServerLobbyThread::HandleNetPacketJoinGame(SessionWrapper session, const std::st
if (pos != m_gameMap.end())
{
bool joinGame = true;
ServerGame &game = *pos->second;
if (game.CheckPassword(password))
const GameData &tmpData = game.GetGameData();
if (session.playerData->GetRights() == PLAYER_RIGHTS_GUEST
&& tmpData.gameType != GAME_TYPE_NORMAL)
{
MoveSessionToGame(game, session);
SendJoinGameFailed(session.sessionData, NTF_NET_JOIN_GUEST_FORBIDDEN);
joinGame = false;
}
else
else if (!game.CheckPassword(password))
{
SendJoinGameFailed(session.sessionData, NTF_NET_JOIN_INVALID_PASSWORD);
joinGame = false;
}
if (joinGame)
MoveSessionToGame(game, session);
}
else
{
@@ -1779,6 +1795,9 @@ ServerLobbyThread::SendJoinGameFailed(boost::shared_ptr<SessionData> s, int reas
case NTF_NET_JOIN_INVALID_PASSWORD :
joinFailed->joinGameFailureReason = joinGameFailureReason_invalidPassword;
break;
case NTF_NET_JOIN_GUEST_FORBIDDEN :
joinFailed->joinGameFailureReason = joinGameFailureReason_notAllowedAsGuest;
break;
default :
joinFailed->joinGameFailureReason = joinGameFailureReason_invalidGame;
break;