diff --git a/src/core/common/pokerthexception.cpp b/src/core/common/pokerthexception.cpp index b6dc1364..c61b78c5 100644 --- a/src/core/common/pokerthexception.cpp +++ b/src/core/common/pokerthexception.cpp @@ -18,8 +18,27 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "pokerthexception.h" +#include + +using namespace std; + +PokerTHException::PokerTHException(const char *sourcefile, int sourceline, int errorId, int osErrorCode) +: m_errorId(errorId), m_osErrorCode(osErrorCode) +{ + ostringstream msgStream; + msgStream << sourcefile << " (" << sourceline << "): Error " << errorId; + if (osErrorCode) + msgStream << " (system error " << osErrorCode << ")"; + m_msg = msgStream.str(); +} PokerTHException::~PokerTHException() { } +const char * +PokerTHException::what() const +{ + return m_msg.c_str(); +} + diff --git a/src/core/pokerthexception.h b/src/core/pokerthexception.h index 286a1236..b021ef87 100644 --- a/src/core/pokerthexception.h +++ b/src/core/pokerthexception.h @@ -21,21 +21,26 @@ #ifndef _POKERTHEXCEPTION_H_ #define _POKERTHEXCEPTION_H_ +#include +#include -class PokerTHException +class PokerTHException : public std::exception { public: - PokerTHException(int errorId, int osErrorCode) - : m_errorId(errorId), m_osErrorCode(osErrorCode) {} + PokerTHException(const char *sourcefile, int sourceline, int errorId, int osErrorCode); virtual ~PokerTHException(); int GetErrorId() const {return m_errorId;} int GetOsErrorCode() const {return m_osErrorCode;} + virtual const char *what() const; + private: int m_errorId; int m_osErrorCode; + + std::string m_msg; }; #endif diff --git a/src/engine/local_engine/localbero.cpp b/src/engine/local_engine/localbero.cpp index 4e1c0095..37693252 100644 --- a/src/engine/local_engine/localbero.cpp +++ b/src/engine/local_engine/localbero.cpp @@ -40,7 +40,7 @@ LocalBeRo::LocalBeRo(HandInterface* hi, int id, unsigned dP, int sB, GameState g } } if(it_c == myHand->getActivePlayerList()->end()) { - throw LocalException(ERR_ACTIVE_PLAYER_NOT_FOUND); + throw LocalException(__FILE__, __LINE__, ERR_ACTIVE_PLAYER_NOT_FOUND); } // determine smallBlindPosition @@ -51,7 +51,7 @@ LocalBeRo::LocalBeRo(HandInterface* hi, int id, unsigned dP, int sB, GameState g } } if(it_c == myHand->getActivePlayerList()->end()) { - throw LocalException(ERR_ACTIVE_PLAYER_NOT_FOUND); + throw LocalException(__FILE__, __LINE__, ERR_ACTIVE_PLAYER_NOT_FOUND); } @@ -87,7 +87,7 @@ void LocalBeRo::nextPlayer() { PlayerListConstIterator currentPlayersTurnConstIt = myHand->getRunningPlayerIt(currentPlayersTurnId); if(currentPlayersTurnConstIt == myHand->getRunningPlayerList()->end()) { - throw LocalException(ERR_RUNNING_PLAYER_NOT_FOUND); + throw LocalException(__FILE__, __LINE__, ERR_RUNNING_PLAYER_NOT_FOUND); } (*currentPlayersTurnConstIt)->action(); @@ -178,7 +178,7 @@ void LocalBeRo::run() { it_1 = myHand->getActivePlayerIt(smallBlindPositionId); if(it_1 == myHand->getActivePlayerList()->end()) { - throw LocalException(ERR_ACTIVE_PLAYER_NOT_FOUND); + throw LocalException(__FILE__, __LINE__, ERR_ACTIVE_PLAYER_NOT_FOUND); } for(i=0; igetActivePlayerList()->size(); i++) { @@ -195,7 +195,7 @@ void LocalBeRo::run() { } } if(!formerRunningPlayerFound) { - throw LocalException(ERR_FORMER_RUNNING_PLAYER_NOT_FOUND); + throw LocalException(__FILE__, __LINE__, ERR_FORMER_RUNNING_PLAYER_NOT_FOUND); } } // heads up: bigBlind begins -> dealer/smallBlind is running player before bigBlind @@ -343,7 +343,7 @@ void LocalBeRo::run() { // determine next running player PlayerListConstIterator currentPlayersTurnIt = myHand->getRunningPlayerIt( currentPlayersTurnId ); if(currentPlayersTurnIt == myHand->getRunningPlayerList()->end()) { - throw LocalException(ERR_RUNNING_PLAYER_NOT_FOUND); + throw LocalException(__FILE__, __LINE__, ERR_RUNNING_PLAYER_NOT_FOUND); } currentPlayersTurnIt++; @@ -386,7 +386,7 @@ void LocalBeRo::run() { currentPlayersTurnIt = myHand->getRunningPlayerIt( currentPlayersTurnId ); if(currentPlayersTurnIt == myHand->getRunningPlayerList()->end()) { - throw LocalException(ERR_RUNNING_PLAYER_NOT_FOUND); + throw LocalException(__FILE__, __LINE__, ERR_RUNNING_PLAYER_NOT_FOUND); } (*currentPlayersTurnIt)->setMyTurn(true); diff --git a/src/engine/local_engine/localberopreflop.cpp b/src/engine/local_engine/localberopreflop.cpp index e973b5c8..249cea0e 100644 --- a/src/engine/local_engine/localberopreflop.cpp +++ b/src/engine/local_engine/localberopreflop.cpp @@ -91,7 +91,7 @@ void LocalBeRoPreflop::run() { it = getMyHand()->getActivePlayerIt(getSmallBlindPositionId()); if(it == getMyHand()->getActivePlayerList()->end()) { - throw LocalException(ERR_ACTIVE_PLAYER_NOT_FOUND); + throw LocalException(__FILE__, __LINE__, ERR_ACTIVE_PLAYER_NOT_FOUND); } if(it == getMyHand()->getActivePlayerList()->begin()) it = getMyHand()->getActivePlayerList()->end(); @@ -227,7 +227,7 @@ void LocalBeRoPreflop::run() { PlayerListConstIterator currentPlayersTurnIt = getMyHand()->getRunningPlayerIt( getCurrentPlayersTurnId() ); if(currentPlayersTurnIt == getMyHand()->getRunningPlayerList()->end()) { - throw LocalException(ERR_RUNNING_PLAYER_NOT_FOUND); + throw LocalException(__FILE__, __LINE__, ERR_RUNNING_PLAYER_NOT_FOUND); } currentPlayersTurnIt++; @@ -353,7 +353,7 @@ void LocalBeRoPreflop::run() { currentPlayersTurnIt = getMyHand()->getRunningPlayerIt( getCurrentPlayersTurnId() ); if(currentPlayersTurnIt == getMyHand()->getRunningPlayerList()->end()) { - throw LocalException(ERR_RUNNING_PLAYER_NOT_FOUND); + throw LocalException(__FILE__, __LINE__, ERR_RUNNING_PLAYER_NOT_FOUND); } (*currentPlayersTurnIt)->setMyTurn(true); diff --git a/src/engine/local_engine/localboard.cpp b/src/engine/local_engine/localboard.cpp index 7ab9ab2b..8f5b1709 100755 --- a/src/engine/local_engine/localboard.cpp +++ b/src/engine/local_engine/localboard.cpp @@ -162,7 +162,7 @@ void LocalBoard::distributePot() { // determine the number of level winners winnerCount = potLevel.size()-2; if (!winnerCount) { - throw LocalException(ERR_NO_WINNER); + throw LocalException(__FILE__, __LINE__, ERR_NO_WINNER); } // distribute the pot level sum to level winners @@ -176,7 +176,7 @@ void LocalBoard::distributePot() { for(j=2; jgetSeatIt(potLevel[j]); if(it == seatsList->end()) { - throw LocalException(ERR_SEAT_NOT_FOUND); + throw LocalException(__FILE__, __LINE__, ERR_SEAT_NOT_FOUND); } (*it)->setMyCash( (*it)->getMyCash() + ((potLevel[1])/winnerCount)); @@ -216,7 +216,7 @@ void LocalBoard::distributePot() { it = currentHand->getSeatIt(winnerPointer); if(it == seatsList->end()) { - throw LocalException(ERR_SEAT_NOT_FOUND); + throw LocalException(__FILE__, __LINE__, ERR_SEAT_NOT_FOUND); } if(jsetMyCash( (*it)->getMyCash() + (int)((potLevel[1])/winnerCount) + 1); diff --git a/src/engine/local_engine/localexception.h b/src/engine/local_engine/localexception.h index 1296a2e9..1d448dbf 100644 --- a/src/engine/local_engine/localexception.h +++ b/src/engine/local_engine/localexception.h @@ -27,8 +27,8 @@ class LocalException : public PokerTHException { public: - LocalException(int errorId) - : PokerTHException(errorId, 0) {} + LocalException(const char *sourcefile, int sourceline, int errorId) + : PokerTHException(sourcefile, sourceline, errorId, 0) {} virtual ~LocalException(); }; diff --git a/src/engine/local_engine/localhand.cpp b/src/engine/local_engine/localhand.cpp index 206f2ee4..50d5ee0f 100755 --- a/src/engine/local_engine/localhand.cpp +++ b/src/engine/local_engine/localhand.cpp @@ -381,7 +381,7 @@ void LocalHand::assignButtons() { // DealerButton zuweisen it = getSeatIt(dealerPosition); if(it == seatsList->end()) { - throw LocalException(ERR_SEAT_NOT_FOUND); + throw LocalException(__FILE__, __LINE__, ERR_SEAT_NOT_FOUND); } (*it)->setMyButton(BUTTON_DEALER); @@ -417,7 +417,7 @@ void LocalHand::assignButtons() { bool nextActivePlayerFound = false; PlayerListIterator dealerPositionIt = getSeatIt(dealerPosition); if(dealerPositionIt == seatsList->end()) { - throw LocalException(ERR_SEAT_NOT_FOUND); + throw LocalException(__FILE__, __LINE__, ERR_SEAT_NOT_FOUND); } for(i=0; isize(); i++) { @@ -442,7 +442,7 @@ void LocalHand::assignButtons() { } if(!nextActivePlayerFound) { - throw LocalException(ERR_NEXT_ACTIVE_PLAYER_NOT_FOUND); + throw LocalException(__FILE__, __LINE__, ERR_NEXT_ACTIVE_PLAYER_NOT_FOUND); } diff --git a/src/game.cpp b/src/game.cpp index 0b53abcd..df03d447 100755 --- a/src/game.cpp +++ b/src/game.cpp @@ -26,7 +26,6 @@ #include "engine_msg.h" #include -#include using namespace std; @@ -67,7 +66,7 @@ Game::Game(GuiInterface* gui, boost::shared_ptr factory, ++player_i; } if (player_i == player_end) - throw LocalException(ERR_DEALER_NOT_FOUND); + throw LocalException(__FILE__, __LINE__, ERR_DEALER_NOT_FOUND); dealerPosition = startData.startDealerPlayerId; // Board erstellen @@ -204,7 +203,7 @@ void Game::initHand() bool nextDealerFound = false; PlayerListConstIterator dealerPositionIt = currentHand->getSeatIt(dealerPosition); if(dealerPositionIt == seatsList->end()) { - throw LocalException(ERR_SEAT_NOT_FOUND); + throw LocalException(__FILE__, __LINE__, ERR_SEAT_NOT_FOUND); } for(i=0; isize(); i++) { @@ -221,7 +220,7 @@ void Game::initHand() } if(!nextDealerFound) { - throw LocalException(ERR_NEXT_DEALER_NOT_FOUND); + throw LocalException(__FILE__, __LINE__, ERR_NEXT_DEALER_NOT_FOUND); } @@ -260,7 +259,7 @@ boost::shared_ptr Game::getCurrentPlayer() { boost::shared_ptr tmpPlayer = getPlayerByUniqueId(getCurrentHand()->getCurrentBeRo()->getCurrentPlayersTurnId()); if (!tmpPlayer.get()) - throw LocalException(ERR_CURRENT_PLAYER_NOT_FOUND); + throw LocalException(__FILE__, __LINE__, ERR_CURRENT_PLAYER_NOT_FOUND); return tmpPlayer; } diff --git a/src/net/clientexception.h b/src/net/clientexception.h index 29bcdeaa..66148c0c 100644 --- a/src/net/clientexception.h +++ b/src/net/clientexception.h @@ -27,8 +27,8 @@ class ClientException : public NetException { public: - ClientException(int errorId, int osErrorCode) - : NetException(errorId, osErrorCode) {} + ClientException(const char *sourcefile, int sourceline, int errorId, int osErrorCode) + : NetException(sourcefile, sourceline, errorId, osErrorCode) {} virtual ~ClientException(); }; diff --git a/src/net/common/clientstate.cpp b/src/net/common/clientstate.cpp index 1a3dc011..d7cd4144 100644 --- a/src/net/common/clientstate.cpp +++ b/src/net/common/clientstate.cpp @@ -69,18 +69,18 @@ ClientStateInit::Process(ClientThread &client) ClientContext &context = client.GetContext(); if (context.GetServerAddr().empty()) - throw ClientException(ERR_SOCK_SERVERADDR_NOT_SET, 0); + throw ClientException(__FILE__, __LINE__, ERR_SOCK_SERVERADDR_NOT_SET, 0); if (context.GetServerPort() < 1024) - throw ClientException(ERR_SOCK_INVALID_PORT, 0); + throw ClientException(__FILE__, __LINE__, ERR_SOCK_INVALID_PORT, 0); context.SetSocket(socket(context.GetAddrFamily(), SOCK_STREAM, context.GetProtocol())); if (!IS_VALID_SOCKET(context.GetSocket())) - throw ClientException(ERR_SOCK_CREATION_FAILED, SOCKET_ERRNO()); + throw ClientException(__FILE__, __LINE__, ERR_SOCK_CREATION_FAILED, SOCKET_ERRNO()); unsigned long mode = 1; if (IOCTLSOCKET(context.GetSocket(), FIONBIO, &mode) == SOCKET_ERROR) - throw ClientException(ERR_SOCK_CREATION_FAILED, SOCKET_ERRNO()); + throw ClientException(__FILE__, __LINE__, ERR_SOCK_CREATION_FAILED, SOCKET_ERRNO()); // The following call is optional - the return value is not checked. int nodelay = 1; @@ -126,7 +126,7 @@ ClientStateStartResolve::Process(ClientThread &client) { // Success - but we still need to set the port. if (!socket_set_port(context.GetServerPort(), context.GetAddrFamily(), (struct sockaddr *)context.GetClientSockaddr(), context.GetClientSockaddrSize())) - throw ClientException(ERR_SOCK_SET_PORT_FAILED, 0); + throw ClientException(__FILE__, __LINE__, ERR_SOCK_SET_PORT_FAILED, 0); // No need to resolve - start connecting. client.SetState(ClientStateStartConnect::Instance()); @@ -181,7 +181,7 @@ ClientStateResolving::Process(ClientThread &client) int retVal; if (!m_resolver) - throw ClientException(ERR_SOCK_RESOLVE_FAILED, 0); + throw ClientException(__FILE__, __LINE__, ERR_SOCK_RESOLVE_FAILED, 0); if (m_resolver->Join(CLIENT_WAIT_TIMEOUT_MSEC)) { @@ -190,7 +190,7 @@ ClientStateResolving::Process(ClientThread &client) Cleanup(); // Not required, but better keep things clean. if (!success) - throw ClientException(ERR_SOCK_RESOLVE_FAILED, 0); + throw ClientException(__FILE__, __LINE__, ERR_SOCK_RESOLVE_FAILED, 0); client.SetState(ClientStateStartConnect::Instance()); retVal = MSG_SOCK_RESOLVE_DONE; @@ -256,7 +256,7 @@ ClientStateStartConnect::Process(ClientThread &client) retVal = MSG_SOCK_INTERNAL_PENDING; } else - throw ClientException(ERR_SOCK_CONNECT_FAILED, SOCKET_ERRNO()); + throw ClientException(__FILE__, __LINE__, ERR_SOCK_CONNECT_FAILED, SOCKET_ERRNO()); } return retVal; @@ -308,19 +308,19 @@ ClientStateConnecting::Process(ClientThread &client) socklen_t tmpSize = sizeof(connectResult); getsockopt(context.GetSocket(), SOL_SOCKET, SO_ERROR, (char *)&connectResult, &tmpSize); if (connectResult != 0) - throw ClientException(ERR_SOCK_CONNECT_FAILED, connectResult); + throw ClientException(__FILE__, __LINE__, ERR_SOCK_CONNECT_FAILED, connectResult); client.SetState(ClientStateStartSession::Instance()); retVal = MSG_SOCK_CONNECT_DONE; } else if (selectResult == 0) // timeout { if (m_connectTimer.elapsed().total_seconds() >= CLIENT_CONNECT_TIMEOUT_SEC) - throw ClientException(ERR_SOCK_CONNECT_TIMEOUT, 0); + throw ClientException(__FILE__, __LINE__, ERR_SOCK_CONNECT_TIMEOUT, 0); else retVal = MSG_SOCK_INTERNAL_PENDING; } else - throw ClientException(ERR_SOCK_SELECT_FAILED, SOCKET_ERRNO()); + throw ClientException(__FILE__, __LINE__, ERR_SOCK_SELECT_FAILED, SOCKET_ERRNO()); return retVal; @@ -524,7 +524,7 @@ AbstractClientStateReceiving::Process(ClientThread &client) NetPacketError::Data errorData; tmpPacket->ToNetPacketError()->GetData(errorData); // Show the error. - throw ClientException(errorData.errorCode, 0); + throw ClientException(__FILE__, __LINE__, errorData.errorCode, 0); } else retVal = InternalProcess(client, tmpPacket); @@ -587,7 +587,7 @@ ClientStateWaitSession::InternalProcess(ClientThread &client, boost::shared_ptr< if (!avatarError) client.GetSender().SendLowPrio(client.GetContext().GetSocket(), tmpList); else - throw NetException(avatarError, 0); + throw ClientException(__FILE__, __LINE__, avatarError, 0); } return retVal; @@ -746,7 +746,7 @@ ClientStateSynchronizeStart::InternalProcess(ClientThread &/*client*/, boost::sh int retVal = MSG_SOCK_INTERNAL_PENDING; if (packet->ToNetPacketGameStart()) - throw ClientException(ERR_NET_START_TIMEOUT, 0); + throw ClientException(__FILE__, __LINE__, ERR_NET_START_TIMEOUT, 0); return retVal; } @@ -791,7 +791,7 @@ ClientStateWaitStart::InternalProcess(ClientThread &client, boost::shared_ptr tmpPlayer = client.GetPlayerDataByUniqueId(playerId); if (!tmpPlayer.get()) - throw ClientException(ERR_NET_UNKNOWN_PLAYER_ID, 0); + throw ClientException(__FILE__, __LINE__, ERR_NET_UNKNOWN_PLAYER_ID, 0); tmpPlayer->SetNumber(num); ++num; @@ -860,7 +860,7 @@ ClientStateWaitHand::InternalProcess(ClientThread &client, boost::shared_ptrToNetPacketEndOfGame()->GetData(endData); boost::shared_ptr tmpPlayer = curGame->getPlayerByUniqueId(endData.winnerPlayerId); if (!tmpPlayer) - throw ClientException(ERR_NET_UNKNOWN_PLAYER_ID, 0); + throw ClientException(__FILE__, __LINE__, ERR_NET_UNKNOWN_PLAYER_ID, 0); client.GetGui().logPlayerWinGame(tmpPlayer->getMyName(), curGame->getMyGameID()); client.GetCallback().SignalNetClientWaitDialog(); client.SetState(ClientStateWaitGame::Instance()); @@ -902,7 +902,7 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptrToNetPacketPlayersActionDone()->GetData(actionDoneData); boost::shared_ptr tmpPlayer = curGame->getPlayerByUniqueId(actionDoneData.playerId); if (!tmpPlayer) - throw ClientException(ERR_NET_UNKNOWN_PLAYER_ID, 0); + throw ClientException(__FILE__, __LINE__, ERR_NET_UNKNOWN_PLAYER_ID, 0); bool isBigBlind = false; @@ -964,7 +964,7 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptrToNetPacketPlayersTurn()->GetData(turnData); boost::shared_ptr tmpPlayer = curGame->getPlayerByUniqueId(turnData.playerId); if (!tmpPlayer) - throw ClientException(ERR_NET_UNKNOWN_PLAYER_ID, 0); + throw ClientException(__FILE__, __LINE__, ERR_NET_UNKNOWN_PLAYER_ID, 0); // Set round. if (curGame->getCurrentHand()->getCurrentRound() != turnData.gameState) @@ -1059,7 +1059,7 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptr tmpPlayer = curGame->getPlayerByUniqueId((*i).playerId); if (!tmpPlayer) - throw ClientException(ERR_NET_UNKNOWN_PLAYER_ID, 0); + throw ClientException(__FILE__, __LINE__, ERR_NET_UNKNOWN_PLAYER_ID, 0); int tmpCards[2]; tmpCards[0] = static_cast((*i).cards[0]); @@ -1085,7 +1085,7 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptr tmpPlayer = curGame->getPlayerByUniqueId(endHandData.playerId); if (!tmpPlayer) - throw ClientException(ERR_NET_UNKNOWN_PLAYER_ID, 0); + throw ClientException(__FILE__, __LINE__, ERR_NET_UNKNOWN_PLAYER_ID, 0); tmpPlayer->setMyCash(endHandData.playerMoney); // TODO use moneyWon @@ -1121,7 +1121,7 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptr tmpPlayer = curGame->getPlayerByUniqueId((*i).playerId); if (!tmpPlayer) - throw ClientException(ERR_NET_UNKNOWN_PLAYER_ID, 0); + throw ClientException(__FILE__, __LINE__, ERR_NET_UNKNOWN_PLAYER_ID, 0); int tmpCards[2]; int bestHandPos[5]; diff --git a/src/net/common/clientthread.cpp b/src/net/common/clientthread.cpp index 1c13fd56..dffcec08 100644 --- a/src/net/common/clientthread.cpp +++ b/src/net/common/clientthread.cpp @@ -305,7 +305,7 @@ ClientThread::Main() MapPlayerDataList(); if (GetPlayerDataList().size() != (unsigned)GetStartData().numberOfPlayers) - throw NetException(ERR_NET_INVALID_PLAYER_COUNT, 0); + throw ClientException(__FILE__, __LINE__, ERR_NET_INVALID_PLAYER_COUNT, 0); m_game.reset(new Game(&m_gui, factory, GetPlayerDataList(), GetGameData(), GetStartData(), m_curGameId++)); // Initialize GUI speed. GetGui().initGui(GetGameData().guiSpeed); @@ -316,7 +316,7 @@ ClientThread::Main() if (IsSessionEstablished()) SendPacketLoop(); } - } catch (const NetException &e) + } catch (const PokerTHException &e) { GetCallback().SignalNetClientError(e.GetErrorId(), e.GetOsErrorCode()); } @@ -462,7 +462,7 @@ ClientThread::StoreInTempAvatarData(unsigned playerId, const vectorsecond->fileData)); } @@ -472,16 +472,16 @@ ClientThread::CompleteTempAvatarData(unsigned playerId) { AvatarDataMap::iterator pos = m_tempAvatarMap.find(playerId); if (pos == m_tempAvatarMap.end()) - throw NetException(ERR_NET_INVALID_REQUEST_ID, 0); + throw ClientException(__FILE__, __LINE__, ERR_NET_INVALID_REQUEST_ID, 0); boost::shared_ptr tmpAvatar = pos->second; unsigned avatarSize = (unsigned)tmpAvatar->fileData.size(); if (avatarSize != tmpAvatar->reportedSize) - throw NetException(ERR_NET_WRONG_AVATAR_SIZE, 0); + throw ClientException(__FILE__, __LINE__, ERR_NET_WRONG_AVATAR_SIZE, 0); PlayerInfo tmpPlayerInfo; if (!GetCachedPlayerInfo(playerId, tmpPlayerInfo)) - throw NetException(ERR_NET_UNKNOWN_PLAYER_ID, 0); + throw ClientException(__FILE__, __LINE__, ERR_NET_UNKNOWN_PLAYER_ID, 0); GetAvatarManager().StoreAvatarInCache(tmpPlayerInfo.avatar, tmpAvatar->fileType, &tmpAvatar->fileData[0], avatarSize); // TODO log error @@ -772,7 +772,7 @@ ClientThread::GetGameIdByName(const std::string &name) const } if (i == end) - throw NetException(ERR_NET_UNKNOWN_GAME, 0); + throw ClientException(__FILE__, __LINE__, ERR_NET_UNKNOWN_GAME, 0); return i->first; } diff --git a/src/net/common/netpacket.cpp b/src/net/common/netpacket.cpp index fe831616..e4097b7b 100644 --- a/src/net/common/netpacket.cpp +++ b/src/net/common/netpacket.cpp @@ -586,7 +586,7 @@ CheckGameInfoData(const GameInfoData *tmpData) || !ntohl(tmpData->firstSmallBlind) || !ntohl(tmpData->startMoney)) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } } @@ -598,7 +598,7 @@ NetPacket::Create(char *data, unsigned &dataSize) // Check minimum requirements. if (!data || dataSize < sizeof(NetPacketHeader)) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } NetPacketHeader *tmpHeader = (NetPacketHeader *)data; @@ -608,7 +608,7 @@ NetPacket::Create(char *data, unsigned &dataSize) if (tmpLen < sizeof(NetPacketHeader) || tmpLen > MAX_PACKET_SIZE) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } else if (dataSize >= tmpLen) { @@ -748,7 +748,7 @@ NetPacket::Create(char *data, unsigned &dataSize) tmpPacket = boost::shared_ptr(new NetPacketError); break; default: - throw NetException(ERR_SOCK_INVALID_TYPE, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_TYPE, 0); } if (tmpPacket.get()) tmpPacket->SetRawData(tmpHeader); @@ -810,7 +810,7 @@ NetPacket::SetRawData(const NetPacketHeader *p) u_int16_t tmpLen = ntohs(p->length); if (ntohs(p->type) != GetType()) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } // Check whether the data is valid. Check(p); @@ -1097,12 +1097,12 @@ NetPacket::Resize(u_int16_t newLen) if (newLen != oldLen) { if (newLen < sizeof(NetPacketHeader)) - throw NetException(ERR_SOCK_INTERNAL, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INTERNAL, 0); else { NetPacketHeader *newData = (NetPacketHeader *)malloc(newLen); if (!newData) - throw NetException(ERR_SOCK_INTERNAL, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INTERNAL, 0); else { // Copy as much data as possible. @@ -1130,7 +1130,7 @@ NetPacket::Check(const NetPacketHeader *data) const u_int16_t dataLen = ntohs(data->length); if (dataLen < m_initialSize || dataLen > m_maxSize) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } InternalCheck(data); @@ -1173,9 +1173,9 @@ NetPacketInit::SetData(const NetPacketInit::Data &inData) // Some basic checks, so we don't use up too much memory. // The constructed packet will also be checked. if (!playerNameLen || playerNameLen > MAX_NAME_SIZE) - throw NetException(ERR_NET_INVALID_PLAYER_NAME, 0); + throw NetException(__FILE__, __LINE__, ERR_NET_INVALID_PLAYER_NAME, 0); if (passwordLen > MAX_PASSWORD_SIZE) - throw NetException(ERR_NET_INVALID_PASSWORD_STR, 0); + throw NetException(__FILE__, __LINE__, ERR_NET_INVALID_PASSWORD_STR, 0); int avatarSize = inData.showAvatar ? MD5_DATA_SIZE : 0; // Resize the packet so that the data fits in. @@ -1255,20 +1255,20 @@ NetPacketInit::InternalCheck(const NetPacketHeader* data) const + ADD_PADDING(passwordLength) + ADD_PADDING(playerNameLength)) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } // Check string sizes. if (passwordLength > MAX_PASSWORD_SIZE || !playerNameLength || playerNameLength > MAX_NAME_SIZE) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } // Check name string. char *namePtr = (char *)tmpData + sizeof(NetPacketInitData) + avatarSize + ADD_PADDING(passwordLength); if (namePtr[0] == 0) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } } @@ -1483,7 +1483,7 @@ NetPacketAvatarFile::SetData(const NetPacketAvatarFile::Data &inData) int fileDataSize = static_cast(inData.fileData.size()); if (fileDataSize > MAX_FILE_DATA_SIZE) - throw NetException(ERR_NET_BUF_INVALID_SIZE, 0); + throw NetException(__FILE__, __LINE__, ERR_NET_BUF_INVALID_SIZE, 0); Resize((u_int16_t) (sizeof(NetPacketAvatarFileData) @@ -1532,11 +1532,11 @@ NetPacketAvatarFile::InternalCheck(const NetPacketHeader *data) const sizeof(NetPacketAvatarFileData) + ADD_PADDING(fileDataSize)) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } if (!fileDataSize || fileDataSize > MAX_FILE_DATA_SIZE) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } } @@ -1689,9 +1689,9 @@ NetPacketGameListNew::SetData(const NetPacketGameListNew::Data &inData) // Some basic checks, so we don't use up too much memory. // The constructed packet will also be checked. if (!gameNameLen || gameNameLen > MAX_NAME_SIZE) - throw NetException(ERR_NET_INVALID_GAME_NAME, 0); + throw NetException(__FILE__, __LINE__, ERR_NET_INVALID_GAME_NAME, 0); if (numManualBlinds > MAX_NUM_MANUAL_BLINDS) - throw NetException(ERR_NET_TOO_MANY_MANUAL_BLINDS, 0); + throw NetException(__FILE__, __LINE__, ERR_NET_TOO_MANY_MANUAL_BLINDS, 0); // Resize the packet so that the data fits in. Resize((u_int16_t) @@ -1786,24 +1786,24 @@ NetPacketGameListNew::InternalCheck(const NetPacketHeader* data) const + ADD_PADDING(gameNameLength) + curNumPlayers * sizeof(unsigned)) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } // Check manual blind list size if (numManualBlinds > MAX_NUM_MANUAL_BLINDS) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } // Check string size. if (!gameNameLength || gameNameLength > MAX_NAME_SIZE) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } // Check name string. char *namePtr = (char *)tmpData + sizeof(NetPacketGameListNewData) + manualBlindsLength; if (namePtr[0] == 0) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } } @@ -2135,7 +2135,7 @@ NetPacketPlayerInfo::SetData(const NetPacketPlayerInfo::Data &inData) u_int16_t playerNameLen = (u_int16_t)inData.playerInfo.playerName.length(); if (!playerNameLen || playerNameLen > MAX_NAME_SIZE) - throw NetException(ERR_NET_INVALID_PLAYER_NAME, 0); + throw NetException(__FILE__, __LINE__, ERR_NET_INVALID_PLAYER_NAME, 0); int avatarSize = inData.playerInfo.hasAvatar ? MD5_DATA_SIZE : 0; // Resize the packet so that the data fits in. @@ -2206,13 +2206,13 @@ NetPacketPlayerInfo::InternalCheck(const NetPacketHeader* data) const + avatarSize + ADD_PADDING(playerNameLength)) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } // Check string sizes. if (!playerNameLength || playerNameLength > MAX_NAME_SIZE) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } } @@ -2308,11 +2308,11 @@ NetPacketCreateGame::SetData(const NetPacketCreateGame::Data &inData) // Some basic checks, so we don't use up too much memory. // The constructed packet will also be checked. if (!gameNameLen || gameNameLen > MAX_NAME_SIZE) - throw NetException(ERR_NET_INVALID_PLAYER_NAME, 0); + throw NetException(__FILE__, __LINE__, ERR_NET_INVALID_PLAYER_NAME, 0); if (passwordLen > MAX_PASSWORD_SIZE) - throw NetException(ERR_NET_INVALID_PASSWORD_STR, 0); + throw NetException(__FILE__, __LINE__, ERR_NET_INVALID_PASSWORD_STR, 0); if (numManualBlinds > MAX_NUM_MANUAL_BLINDS) - throw NetException(ERR_NET_TOO_MANY_MANUAL_BLINDS, 0); + throw NetException(__FILE__, __LINE__, ERR_NET_TOO_MANY_MANUAL_BLINDS, 0); int manualBlindsSize = numManualBlinds * sizeof(u_int32_t); // Resize the packet so that the data fits in. @@ -2374,25 +2374,25 @@ NetPacketCreateGame::InternalCheck(const NetPacketHeader* data) const + ADD_PADDING(passwordLength) + ADD_PADDING(gameNameLength)) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } // Check manual blind list size if (numManualBlinds > MAX_NUM_MANUAL_BLINDS) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } // Check string sizes. if (passwordLength > MAX_PASSWORD_SIZE || !gameNameLength || gameNameLength > MAX_NAME_SIZE) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } // Check name string. char *namePtr = (char *)tmpData + sizeof(NetPacketCreateGameData) + manualBlindsLength + ADD_PADDING(passwordLength); if (namePtr[0] == 0) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } CheckGameInfoData(&tmpData->gameData); } @@ -2430,7 +2430,7 @@ NetPacketJoinGame::SetData(const NetPacketJoinGame::Data &inData) // Some basic checks, so we don't use up too much memory. // The constructed packet will also be checked. if (passwordLen > MAX_PASSWORD_SIZE) - throw NetException(ERR_NET_INVALID_PASSWORD_STR, 0); + throw NetException(__FILE__, __LINE__, ERR_NET_INVALID_PASSWORD_STR, 0); // Resize the packet so that the data fits in. Resize((u_int16_t) @@ -2479,12 +2479,12 @@ NetPacketJoinGame::InternalCheck(const NetPacketHeader* data) const sizeof(NetPacketJoinGameData) + ADD_PADDING(passwordLength)) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } // Check string size. if (passwordLength > MAX_PASSWORD_SIZE) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } } @@ -2521,7 +2521,7 @@ NetPacketJoinGameAck::SetData(const NetPacketJoinGameAck::Data &inData) // Some basic checks, so we don't use up too much memory. // The constructed packet will also be checked. if (numManualBlinds > MAX_NUM_MANUAL_BLINDS) - throw NetException(ERR_NET_TOO_MANY_MANUAL_BLINDS, 0); + throw NetException(__FILE__, __LINE__, ERR_NET_TOO_MANY_MANUAL_BLINDS, 0); int manualBlindsSize = numManualBlinds * sizeof(u_int32_t); // Resize the packet so that the data fits in. @@ -2570,13 +2570,13 @@ NetPacketJoinGameAck::InternalCheck(const NetPacketHeader* data) const sizeof(NetPacketJoinGameAckData) + manualBlindsLength) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } // Check manual blind list size if (numManualBlinds > MAX_NUM_MANUAL_BLINDS) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } // Semantic checks CheckGameInfoData(&tmpData->gameData); @@ -3067,7 +3067,7 @@ NetPacketGameStart::SetData(const NetPacketGameStart::Data &inData) // Basic checking. if (numPlayers < MIN_NUMBER_OF_PLAYERS || numPlayers > MAX_NUMBER_OF_PLAYERS || numPlayers != inData.startData.numberOfPlayers) - throw NetException(ERR_NET_INVALID_PLAYER_COUNT, 0); + throw NetException(__FILE__, __LINE__, ERR_NET_INVALID_PLAYER_COUNT, 0); // Resize the packet so that the data fits in. Resize((u_int16_t) @@ -3135,7 +3135,7 @@ NetPacketGameStart::InternalCheck(const NetPacketHeader* data) const sizeof(NetPacketGameStartData) + numPlayers * sizeof(PlayerSlotData)) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } // Semantic checks not needed. } @@ -3200,7 +3200,7 @@ NetPacketHandStart::InternalCheck(const NetPacketHeader* data) const NetPacketHandStartData *tmpData = (NetPacketHandStartData *)data; if (ntohs(tmpData->yourCard1) > 51 || ntohs(tmpData->yourCard2) > 51) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } } @@ -3265,7 +3265,7 @@ NetPacketPlayersTurn::InternalCheck(const NetPacketHeader* data) const NetPacketPlayersTurnData *tmpData = (NetPacketPlayersTurnData *)data; if (ntohs(tmpData->gameState) > GAME_STATE_RIVER) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } } @@ -3330,12 +3330,12 @@ NetPacketPlayersAction::InternalCheck(const NetPacketHeader* data) const // Check whether the state is valid. if (ntohs(tmpData->gameState) > GAME_STATE_RIVER) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } // Check whether the player action is valid. if (ntohs(tmpData->playerAction) > PLAYER_ACTION_ALLIN) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } // Semantic checks are done by the server process. } @@ -3410,12 +3410,12 @@ NetPacketPlayersActionDone::InternalCheck(const NetPacketHeader* data) const && gameState != GAME_STATE_PREFLOP_SMALL_BLIND && gameState != GAME_STATE_PREFLOP_BIG_BLIND) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } // Check whether the player action is valid. if (ntohs(tmpData->playerAction) > PLAYER_ACTION_ALLIN) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } } @@ -3482,16 +3482,16 @@ NetPacketPlayersActionRejected::InternalCheck(const NetPacketHeader* data) const NetPacketPlayersActionRejectedData *tmpData = (NetPacketPlayersActionRejectedData *)data; if (ntohs(tmpData->gameState) > GAME_STATE_RIVER) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } // Check whether the player action is valid. if (ntohs(tmpData->playerAction) > PLAYER_ACTION_ALLIN) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } if (!ntohs(tmpData->rejectionReason)) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } } @@ -3555,7 +3555,7 @@ NetPacketDealFlopCards::InternalCheck(const NetPacketHeader* data) const NetPacketDealFlopCardsData *tmpData = (NetPacketDealFlopCardsData *)data; if (ntohs(tmpData->flopCard1) > 51 || ntohs(tmpData->flopCard2) > 51 || ntohs(tmpData->flopCard3) > 51) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } } @@ -3615,7 +3615,7 @@ NetPacketDealTurnCard::InternalCheck(const NetPacketHeader* data) const NetPacketDealTurnCardData *tmpData = (NetPacketDealTurnCardData *)data; if (ntohs(tmpData->turnCard) > 51) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } } @@ -3675,7 +3675,7 @@ NetPacketDealRiverCard::InternalCheck(const NetPacketHeader* data) const NetPacketDealRiverCardData *tmpData = (NetPacketDealRiverCardData *)data; if (ntohs(tmpData->riverCard) > 51) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } } @@ -3710,7 +3710,7 @@ NetPacketAllInShowCards::SetData(const NetPacketAllInShowCards::Data &inData) u_int16_t numPlayerCards = (u_int16_t)inData.playerCards.size(); if (!numPlayerCards || numPlayerCards > MAX_NUM_PLAYER_CARDS) - throw NetException(ERR_NET_INVALID_PLAYER_CARDS, 0); + throw NetException(__FILE__, __LINE__, ERR_NET_INVALID_PLAYER_CARDS, 0); // Resize the packet so that the data fits in. Resize((u_int16_t) @@ -3780,11 +3780,11 @@ NetPacketAllInShowCards::InternalCheck(const NetPacketHeader* data) const sizeof(NetPacketAllInShowCardsData) + numPlayerCards * sizeof(PlayerCardsData)) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } if (ntohs(tmpData->numberOfPlayerCards) > MAX_NUMBER_OF_PLAYERS) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } // Semantic checks not needed, this packet is sent by the server. } @@ -3820,7 +3820,7 @@ NetPacketEndOfHandShowCards::SetData(const NetPacketEndOfHandShowCards::Data &in u_int16_t numPlayerResults = (u_int16_t)inData.playerResults.size(); if (!numPlayerResults || numPlayerResults > MAX_NUM_PLAYER_RESULTS) - throw NetException(ERR_NET_INVALID_PLAYER_RESULTS, 0); + throw NetException(__FILE__, __LINE__, ERR_NET_INVALID_PLAYER_RESULTS, 0); // Resize the packet so that the data fits in. Resize((u_int16_t) @@ -3906,11 +3906,11 @@ NetPacketEndOfHandShowCards::InternalCheck(const NetPacketHeader* data) const sizeof(NetPacketEndOfHandShowCardsData) + numPlayerResults * sizeof(PlayerResultData)) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } if (ntohs(tmpData->numberOfPlayerResults) > MAX_NUMBER_OF_PLAYERS) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } // Semantic checks not needed, this packet is sent by the server. } @@ -4153,7 +4153,7 @@ NetPacketSendChatText::SetData(const NetPacketSendChatText::Data &inData) u_int16_t textLen = (u_int16_t)inData.text.length(); if (!textLen || textLen > MAX_CHAT_TEXT_SIZE) - throw NetException(ERR_NET_INVALID_CHAT_TEXT, 0); + throw NetException(__FILE__, __LINE__, ERR_NET_INVALID_CHAT_TEXT, 0); // Resize the packet so that the data fits in. Resize((u_int16_t) @@ -4197,19 +4197,19 @@ NetPacketSendChatText::InternalCheck(const NetPacketHeader* data) const sizeof(NetPacketSendChatTextData) + ADD_PADDING(textLength)) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } // Check string size. if (!textLength || textLength > MAX_CHAT_TEXT_SIZE) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } // Check text string. char *textPtr = (char *)tmpData + sizeof(NetPacketSendChatTextData); if (textPtr[0] == 0) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } } @@ -4244,7 +4244,7 @@ NetPacketChatText::SetData(const NetPacketChatText::Data &inData) u_int16_t textLen = (u_int16_t)inData.text.length(); if (!textLen || textLen > MAX_CHAT_TEXT_SIZE) - throw NetException(ERR_NET_INVALID_CHAT_TEXT, 0); + throw NetException(__FILE__, __LINE__, ERR_NET_INVALID_CHAT_TEXT, 0); // Resize the packet so that the data fits in. Resize((u_int16_t) @@ -4290,13 +4290,13 @@ NetPacketChatText::InternalCheck(const NetPacketHeader* data) const sizeof(NetPacketChatTextData) + ADD_PADDING(textLength)) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } // Check string size. if (!textLength || textLength > MAX_CHAT_TEXT_SIZE) { - throw NetException(ERR_SOCK_INVALID_PACKET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_INVALID_PACKET, 0); } // No more checks required - this packet is sent by the server. } diff --git a/src/net/common/receiverhelper.cpp b/src/net/common/receiverhelper.cpp index 8557158e..9940b1f3 100644 --- a/src/net/common/receiverhelper.cpp +++ b/src/net/common/receiverhelper.cpp @@ -57,7 +57,7 @@ ReceiverHelper::Recv(SOCKET sock, ReceiveBuffer &buf) int selectResult = select(sock + 1, &readSet, NULL, NULL, &timeout); if (!IS_VALID_SELECT(selectResult)) { - throw NetException(ERR_SOCK_SELECT_FAILED, SOCKET_ERRNO()); + throw NetException(__FILE__, __LINE__, ERR_SOCK_SELECT_FAILED, SOCKET_ERRNO()); } if (selectResult > 0) // recv is possible { @@ -65,11 +65,11 @@ ReceiverHelper::Recv(SOCKET sock, ReceiveBuffer &buf) if (!IS_VALID_RECV(bytesRecvd)) { - throw NetException(ERR_SOCK_RECV_FAILED, SOCKET_ERRNO()); + throw NetException(__FILE__, __LINE__, ERR_SOCK_RECV_FAILED, SOCKET_ERRNO()); } else if (bytesRecvd == 0) { - throw NetException(ERR_SOCK_CONN_RESET, 0); + throw NetException(__FILE__, __LINE__, ERR_SOCK_CONN_RESET, 0); } else { diff --git a/src/net/common/serveracceptthread.cpp b/src/net/common/serveracceptthread.cpp index 6e15feba..792d7462 100644 --- a/src/net/common/serveracceptthread.cpp +++ b/src/net/common/serveracceptthread.cpp @@ -84,7 +84,7 @@ ServerAcceptThread::Main() // The main server thread is simple. It only accepts connections. AcceptLoop(); } - } catch (const NetException &e) + } catch (const PokerTHException &e) { GetCallback().SignalNetServerError(e.GetErrorId(), e.GetOsErrorCode()); } @@ -98,15 +98,15 @@ ServerAcceptThread::Listen() ServerContext &context = GetContext(); if (context.GetServerPort() < 1024) - throw ServerException(ERR_SOCK_INVALID_PORT, 0); + throw ServerException(__FILE__, __LINE__, ERR_SOCK_INVALID_PORT, 0); context.SetSocket(socket(context.GetAddrFamily(), SOCK_STREAM, context.GetProtocol())); if (!IS_VALID_SOCKET(context.GetSocket())) - throw ServerException(ERR_SOCK_CREATION_FAILED, SOCKET_ERRNO()); + throw ServerException(__FILE__, __LINE__, ERR_SOCK_CREATION_FAILED, SOCKET_ERRNO()); unsigned long mode = 1; if (IOCTLSOCKET(context.GetSocket(), FIONBIO, &mode) == SOCKET_ERROR) - throw ServerException(ERR_SOCK_CREATION_FAILED, SOCKET_ERRNO()); + throw ServerException(__FILE__, __LINE__, ERR_SOCK_CREATION_FAILED, SOCKET_ERRNO()); // The following three calls are optional. If they fail, we don't care. int reuse = 1; @@ -126,7 +126,7 @@ ServerAcceptThread::Listen() (struct sockaddr *)context.GetServerSockaddr(), context.GetServerSockaddrSize())) { - throw ServerException(ERR_SOCK_SET_ADDR_FAILED, 0); + throw ServerException(__FILE__, __LINE__, ERR_SOCK_SET_ADDR_FAILED, 0); } if (!socket_set_port( context.GetServerPort(), @@ -134,7 +134,7 @@ ServerAcceptThread::Listen() (struct sockaddr *)context.GetServerSockaddr(), context.GetServerSockaddrSize())) { - throw ServerException(ERR_SOCK_SET_PORT_FAILED, 0); + throw ServerException(__FILE__, __LINE__, ERR_SOCK_SET_PORT_FAILED, 0); } if (!IS_VALID_BIND(bind( @@ -142,12 +142,12 @@ ServerAcceptThread::Listen() (const struct sockaddr *)context.GetServerSockaddr(), context.GetServerSockaddrSize()))) { - throw ServerException(ERR_SOCK_BIND_FAILED, SOCKET_ERRNO()); + throw ServerException(__FILE__, __LINE__, ERR_SOCK_BIND_FAILED, SOCKET_ERRNO()); } if (!IS_VALID_LISTEN(listen(context.GetSocket(), NET_SERVER_LISTEN_BACKLOG))) { - throw ServerException(ERR_SOCK_LISTEN_FAILED, SOCKET_ERRNO()); + throw ServerException(__FILE__, __LINE__, ERR_SOCK_LISTEN_FAILED, SOCKET_ERRNO()); } } @@ -167,7 +167,7 @@ ServerAcceptThread::AcceptLoop() int selectResult = select(context.GetSocket() + 1, &readSet, NULL, NULL, &timeout); if (!IS_VALID_SELECT(selectResult)) { - throw ServerException(ERR_SOCK_SELECT_FAILED, SOCKET_ERRNO()); + throw ServerException(__FILE__, __LINE__, ERR_SOCK_SELECT_FAILED, SOCKET_ERRNO()); } if (selectResult > 0) // accept is possible { @@ -176,7 +176,7 @@ ServerAcceptThread::AcceptLoop() if (!IS_VALID_SOCKET(tmpData->GetSocket())) { - throw ServerException(ERR_SOCK_ACCEPT_FAILED, SOCKET_ERRNO()); + throw ServerException(__FILE__, __LINE__, ERR_SOCK_ACCEPT_FAILED, SOCKET_ERRNO()); } GetLobbyThread().AddConnection(tmpData); diff --git a/src/net/common/servergamestate.cpp b/src/net/common/servergamestate.cpp index 92b86039..97f17d47 100644 --- a/src/net/common/servergamestate.cpp +++ b/src/net/common/servergamestate.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include @@ -684,9 +684,9 @@ ServerGameStateStartRound::Process(ServerGameThread &server) // Retrieve current player. boost::shared_ptr curPlayer = curGame.getCurrentPlayer(); if (!curPlayer.get()) - throw NetException(ERR_NET_NO_CURRENT_PLAYER, 0); + throw ServerException(__FILE__, __LINE__, ERR_NET_NO_CURRENT_PLAYER, 0); if (!curPlayer->getMyActiveStatus()) - throw NetException(ERR_NET_PLAYER_NOT_ACTIVE, 0); + throw ServerException(__FILE__, __LINE__, ERR_NET_PLAYER_NOT_ACTIVE, 0); boost::shared_ptr notification(new NetPacketPlayersTurn); NetPacketPlayersTurn::Data playersTurnData; @@ -816,7 +816,7 @@ ServerGameStateWaitPlayerAction::Process(ServerGameThread &server) boost::shared_ptr curPlayer = server.GetGame().getCurrentPlayer(); if (!curPlayer.get()) - throw NetException(ERR_NET_NO_CURRENT_PLAYER, 0); + throw ServerException(__FILE__, __LINE__, ERR_NET_NO_CURRENT_PLAYER, 0); // If the player is computer controlled, let the engine act. if (curPlayer->getMyType() == PLAYER_TYPE_COMPUTER) @@ -862,7 +862,7 @@ ServerGameStateWaitPlayerAction::InternalProcess(ServerGameThread &server, Sessi Game &curGame = server.GetGame(); boost::shared_ptr tmpPlayer = curGame.getPlayerByUniqueId(session.playerData->GetUniqueId()); if (!tmpPlayer.get()) - throw NetException(ERR_NET_UNKNOWN_PLAYER_ID, 0); + throw ServerException(__FILE__, __LINE__, ERR_NET_UNKNOWN_PLAYER_ID, 0); // Check whether this is the correct round. PlayerActionCode code = ACTION_CODE_VALID; diff --git a/src/net/common/servergamethread.cpp b/src/net/common/servergamethread.cpp index 78fe5ef7..217cc1fe 100644 --- a/src/net/common/servergamethread.cpp +++ b/src/net/common/servergamethread.cpp @@ -146,7 +146,7 @@ ServerGameThread::Main() // Process current state. GetState().Process(*this); } while (!ShouldTerminate() && GetSessionManager().HasSessions()); - } catch (const NetException &e) + } catch (const PokerTHException &e) { GetCallback().SignalNetServerError(e.GetErrorId(), e.GetOsErrorCode()); } diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index 40b2a517..b8930f34 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -281,7 +281,7 @@ ServerLobbyThread::Main() // Remove games. RemoveGameLoop(); } - } catch (const NetException &e) + } catch (const PokerTHException &e) { GetCallback().SignalNetServerError(e.GetErrorId(), e.GetOsErrorCode()); } diff --git a/src/net/common/sessionmanager.cpp b/src/net/common/sessionmanager.cpp index b2a2f197..c83f08fb 100644 --- a/src/net/common/sessionmanager.cpp +++ b/src/net/common/sessionmanager.cpp @@ -58,7 +58,7 @@ SessionManager::AddSession(SessionWrapper session) // already exists within the list. if (pos != m_sessionMap.end() && session.sessionData->GetSocket() == pos->first) { - throw ServerException(ERR_SOCK_CONN_EXISTS, 0); + throw ServerException(__FILE__, __LINE__, ERR_SOCK_CONN_EXISTS, 0); } m_sessionMap.insert(pos, SessionMap::value_type(session.sessionData->GetSocket(), session)); } @@ -126,7 +126,7 @@ SessionManager::Select(unsigned timeoutMsec) int selectResult = select(maxSock + 1, &rdset, NULL, NULL, &timeout); if (!IS_VALID_SELECT(selectResult)) { - throw ServerException(ERR_SOCK_SELECT_FAILED, SOCKET_ERRNO()); + throw ServerException(__FILE__, __LINE__, ERR_SOCK_SELECT_FAILED, SOCKET_ERRNO()); } if (selectResult > 0) // one (or more) of the sockets is readable { diff --git a/src/net/netexception.h b/src/net/netexception.h index b911de9b..19e47921 100644 --- a/src/net/netexception.h +++ b/src/net/netexception.h @@ -27,8 +27,8 @@ class NetException : public PokerTHException { public: - NetException(int errorId, int osErrorCode) - : PokerTHException(errorId, osErrorCode) {} + NetException(const char *sourcefile, int sourceline, int errorId, int osErrorCode) + : PokerTHException(sourcefile, sourceline, errorId, osErrorCode) {} virtual ~NetException(); }; diff --git a/src/net/serverexception.h b/src/net/serverexception.h index 8b98d393..c4e2999d 100644 --- a/src/net/serverexception.h +++ b/src/net/serverexception.h @@ -27,8 +27,8 @@ class ServerException : public NetException { public: - ServerException(int errorId, int osErrorCode) - : NetException(errorId, osErrorCode) {} + ServerException(const char *sourcefile, int sourceline, int errorId, int osErrorCode) + : NetException(sourcefile, sourceline, errorId, osErrorCode) {} virtual ~ServerException(); };