Fixed kick bug by letting the client reverse iterate over its cached player data when looking for a player name. Added several exceptions.
This commit is contained in:
@@ -269,8 +269,8 @@ ClientThread::GetPlayerIdFromName(const string &playerName, unsigned &playerId)
|
||||
bool retVal = false;
|
||||
|
||||
boost::mutex::scoped_lock lock(m_playerInfoMapMutex);
|
||||
PlayerInfoMap::const_iterator i = m_playerInfoMap.begin();
|
||||
PlayerInfoMap::const_iterator end = m_playerInfoMap.end();
|
||||
PlayerInfoMap::const_reverse_iterator i = m_playerInfoMap.rbegin();
|
||||
PlayerInfoMap::const_reverse_iterator end = m_playerInfoMap.rend();
|
||||
|
||||
while (i != end)
|
||||
{
|
||||
|
||||
@@ -69,8 +69,8 @@ using namespace std;
|
||||
|
||||
static void SendPlayerAction(ServerGameThread &server, boost::shared_ptr<PlayerInterface> player)
|
||||
{
|
||||
assert(player);
|
||||
|
||||
if (!player.get())
|
||||
throw ServerException(__FILE__, __LINE__, ERR_NET_NO_CURRENT_PLAYER, 0);
|
||||
boost::shared_ptr<NetPacket> notifyActionDone(new NetPacketPlayersActionDone);
|
||||
NetPacketPlayersActionDone::Data actionDoneData;
|
||||
actionDoneData.gameState = server.GetCurRound();
|
||||
@@ -648,7 +648,9 @@ ServerGameStateStartRound::Process(ServerGameThread &server)
|
||||
// If round changes, deal cards if needed.
|
||||
if (newRound != curRound && newRound != GAME_STATE_POST_RIVER)
|
||||
{
|
||||
assert(newRound > curRound);
|
||||
if (newRound <= curRound)
|
||||
throw ServerException(__FILE__, __LINE__, ERR_NET_INVALID_GAME_ROUND, 0);
|
||||
|
||||
// Retrieve non-fold players. If only one player is left, no cards are shown.
|
||||
list<boost::shared_ptr<PlayerInterface> > nonFoldPlayers = *curGame.getActivePlayerList();
|
||||
nonFoldPlayers.remove_if(boost::bind(&PlayerInterface::getMyAction, _1) == PLAYER_ACTION_FOLD);
|
||||
@@ -696,7 +698,8 @@ ServerGameStateStartRound::Process(ServerGameThread &server)
|
||||
{
|
||||
if (newRound != GAME_STATE_POST_RIVER) // continue hand
|
||||
{
|
||||
assert (!curGame.getCurrentHand()->getAllInCondition()); // this would be an error.
|
||||
if (curGame.getCurrentHand()->getAllInCondition())
|
||||
throw ServerException(__FILE__, __LINE__, ERR_NET_INTERNAL_GAME_ERROR, 0);
|
||||
|
||||
// Retrieve current player.
|
||||
boost::shared_ptr<PlayerInterface> curPlayer = curGame.getCurrentPlayer();
|
||||
@@ -937,7 +940,8 @@ void
|
||||
ServerGameStateWaitPlayerAction::PerformPlayerAction(ServerGameThread &server, boost::shared_ptr<PlayerInterface> player, PlayerAction action, int bet)
|
||||
{
|
||||
Game &curGame = server.GetGame();
|
||||
assert(player);
|
||||
if (!player.get())
|
||||
throw ServerException(__FILE__, __LINE__, ERR_NET_NO_CURRENT_PLAYER, 0);
|
||||
player->setMyAction(action);
|
||||
// Only change the player bet if action is not fold/check
|
||||
if (action != PLAYER_ACTION_FOLD && action != PLAYER_ACTION_CHECK)
|
||||
|
||||
@@ -189,7 +189,8 @@ ServerGameThread::InternalStartGame()
|
||||
++tmpPos;
|
||||
++player_i;
|
||||
}
|
||||
assert(player_i != player_end);
|
||||
if (player_i == player_end)
|
||||
throw ServerException(__FILE__, __LINE__, ERR_NET_DEALER_NOT_FOUND, 0);
|
||||
|
||||
SetStartData(startData);
|
||||
|
||||
@@ -323,7 +324,8 @@ ServerGameThread::ResetComputerPlayerList()
|
||||
void
|
||||
ServerGameThread::GracefulRemoveSession(SessionWrapper session)
|
||||
{
|
||||
assert(session.sessionData.get());
|
||||
if (!session.sessionData.get())
|
||||
throw ServerException(__FILE__, __LINE__, ERR_NET_INVALID_SESSION, 0);
|
||||
GetSessionManager().RemoveSession(session.sessionData->GetId());
|
||||
|
||||
boost::shared_ptr<PlayerData> tmpPlayerData = session.playerData;
|
||||
@@ -378,7 +380,8 @@ ServerGameThread::ErrorRemoveSession(SessionWrapper session)
|
||||
void
|
||||
ServerGameThread::SessionError(SessionWrapper session, int errorCode)
|
||||
{
|
||||
assert(session.sessionData.get());
|
||||
if (!session.sessionData.get())
|
||||
throw ServerException(__FILE__, __LINE__, ERR_NET_INVALID_SESSION, 0);
|
||||
ErrorRemoveSession(session);
|
||||
GetLobbyThread().SessionError(session, errorCode);
|
||||
}
|
||||
|
||||
@@ -608,7 +608,8 @@ ServerLobbyThread::HandleNetPacketJoinGame(SessionWrapper session, const NetPack
|
||||
void
|
||||
ServerLobbyThread::EstablishSession(SessionWrapper session)
|
||||
{
|
||||
assert(session.playerData.get());
|
||||
if (!session.playerData.get())
|
||||
throw ServerException(__FILE__, __LINE__, ERR_NET_INVALID_SESSION, 0);
|
||||
// Send ACK to client.
|
||||
boost::shared_ptr<NetPacket> initAck(new NetPacketInitAck);
|
||||
NetPacketInitAck::Data initAckData;
|
||||
@@ -640,7 +641,8 @@ ServerLobbyThread::EstablishSession(SessionWrapper session)
|
||||
void
|
||||
ServerLobbyThread::RequestPlayerAvatar(SessionWrapper session)
|
||||
{
|
||||
assert(session.playerData.get());
|
||||
if (!session.playerData.get())
|
||||
throw ServerException(__FILE__, __LINE__, ERR_NET_INVALID_SESSION, 0);
|
||||
// Ask the client to send its avatar.
|
||||
boost::shared_ptr<NetPacket> retrieveAvatar(new NetPacketRetrieveAvatar);
|
||||
NetPacketRetrieveAvatar::Data retrieveAvatarData;
|
||||
|
||||
@@ -165,7 +165,8 @@ SessionManager::GetSessionByPlayerName(const string playerName) const
|
||||
if (session_i->second.sessionData->GetState() != SessionData::Init)
|
||||
{
|
||||
boost::shared_ptr<PlayerData> tmpPlayer(session_i->second.playerData);
|
||||
assert(tmpPlayer.get());
|
||||
if (!tmpPlayer.get())
|
||||
throw ServerException(__FILE__, __LINE__, ERR_NET_INVALID_SESSION, 0);
|
||||
if (tmpPlayer->GetName() == playerName)
|
||||
{
|
||||
tmpSession = session_i->second;
|
||||
@@ -193,7 +194,8 @@ SessionManager::GetSessionByUniquePlayerId(unsigned uniqueId) const
|
||||
if (session_i->second.sessionData->GetState() != SessionData::Init)
|
||||
{
|
||||
boost::shared_ptr<PlayerData> tmpPlayer(session_i->second.playerData);
|
||||
assert(tmpPlayer.get());
|
||||
if (!tmpPlayer.get())
|
||||
throw ServerException(__FILE__, __LINE__, ERR_NET_INVALID_SESSION, 0);
|
||||
if (tmpPlayer->GetUniqueId() == uniqueId)
|
||||
{
|
||||
tmpSession = session_i->second;
|
||||
@@ -221,8 +223,8 @@ SessionManager::GetPlayerDataList() const
|
||||
if (session_i->second.sessionData->GetState() == SessionData::Game)
|
||||
{
|
||||
boost::shared_ptr<PlayerData> tmpPlayer(session_i->second.playerData);
|
||||
assert(tmpPlayer.get());
|
||||
assert(!tmpPlayer->GetName().empty());
|
||||
if (!tmpPlayer.get() || tmpPlayer->GetName().empty())
|
||||
throw ServerException(__FILE__, __LINE__, ERR_NET_INVALID_SESSION, 0);
|
||||
playerList.push_back(tmpPlayer);
|
||||
}
|
||||
++session_i;
|
||||
@@ -351,7 +353,8 @@ SessionManager::SendToAllSessions(SenderThread &sender, boost::shared_ptr<NetPac
|
||||
|
||||
while (i != end)
|
||||
{
|
||||
assert(i->second.sessionData.get());
|
||||
if (!i->second.sessionData.get())
|
||||
throw ServerException(__FILE__, __LINE__, ERR_NET_INVALID_SESSION, 0);
|
||||
|
||||
// Send each client (with a certain state) a copy of the packet.
|
||||
if (i->second.sessionData->GetState() == state)
|
||||
@@ -370,7 +373,8 @@ SessionManager::SendToAllSessionsLowPrio(SenderThread &sender, boost::shared_ptr
|
||||
|
||||
while (i != end)
|
||||
{
|
||||
assert(i->second.sessionData.get());
|
||||
if (!i->second.sessionData.get())
|
||||
throw ServerException(__FILE__, __LINE__, ERR_NET_INVALID_SESSION, 0);
|
||||
|
||||
// Send each client (with a certain state) a copy of the packet.
|
||||
if (i->second.sessionData->GetState() == state)
|
||||
|
||||
+19
-15
@@ -52,21 +52,25 @@
|
||||
#define ERR_NET_INVALID_PLAYER_CARDS 108
|
||||
#define ERR_NET_INVALID_PLAYER_RESULTS 109
|
||||
#define ERR_NET_INVALID_GAME_NAME 110
|
||||
#define ERR_NET_UNKNOWN_GAME 111
|
||||
#define ERR_NET_INVALID_CHAT_TEXT 112
|
||||
#define ERR_NET_UNKNOWN_PLAYER_ID 113
|
||||
#define ERR_NET_NO_CURRENT_PLAYER 114
|
||||
#define ERR_NET_PLAYER_NOT_ACTIVE 115
|
||||
#define ERR_NET_PLAYER_KICKED 116
|
||||
#define ERR_NET_INVALID_PLAYER_COUNT 117
|
||||
#define ERR_NET_TOO_MANY_MANUAL_BLINDS 118
|
||||
#define ERR_NET_INVALID_AVATAR_FILE 119
|
||||
#define ERR_NET_AVATAR_TOO_LARGE 120
|
||||
#define ERR_NET_BUF_INVALID_SIZE 121
|
||||
#define ERR_NET_INVALID_REQUEST_ID 122
|
||||
#define ERR_NET_WRONG_AVATAR_SIZE 123
|
||||
#define ERR_NET_START_TIMEOUT 124
|
||||
#define ERR_NET_GAME_TERMINATION_FAILED 125
|
||||
#define ERR_NET_INVALID_GAME_ROUND 111
|
||||
#define ERR_NET_INVALID_SESSION 112
|
||||
#define ERR_NET_UNKNOWN_GAME 113
|
||||
#define ERR_NET_INVALID_CHAT_TEXT 114
|
||||
#define ERR_NET_UNKNOWN_PLAYER_ID 115
|
||||
#define ERR_NET_NO_CURRENT_PLAYER 116
|
||||
#define ERR_NET_PLAYER_NOT_ACTIVE 117
|
||||
#define ERR_NET_PLAYER_KICKED 118
|
||||
#define ERR_NET_INVALID_PLAYER_COUNT 119
|
||||
#define ERR_NET_TOO_MANY_MANUAL_BLINDS 120
|
||||
#define ERR_NET_INVALID_AVATAR_FILE 121
|
||||
#define ERR_NET_AVATAR_TOO_LARGE 122
|
||||
#define ERR_NET_BUF_INVALID_SIZE 123
|
||||
#define ERR_NET_INVALID_REQUEST_ID 124
|
||||
#define ERR_NET_WRONG_AVATAR_SIZE 125
|
||||
#define ERR_NET_START_TIMEOUT 126
|
||||
#define ERR_NET_GAME_TERMINATION_FAILED 127
|
||||
#define ERR_NET_INTERNAL_GAME_ERROR 128
|
||||
#define ERR_NET_DEALER_NOT_FOUND 129
|
||||
|
||||
#define ERR_IRC_INTERNAL 151
|
||||
#define ERR_IRC_CONNECT_FAILED 152
|
||||
|
||||
Reference in New Issue
Block a user