Added error handling for networking stuff. Now checking the player action.

This commit is contained in:
lotodore
2007-10-10 22:21:24 +00:00
parent de0f16a6fc
commit 253778bf30
15 changed files with 176 additions and 85 deletions
+30 -7
View File
@@ -100,6 +100,9 @@ using namespace std;
#define NET_ERR_INIT_INVALID_PASSWORD 0x0004
#define NET_ERR_INIT_PLAYER_NAME_IN_USE 0x0005
#define NET_ERR_INIT_INVALID_PLAYER_NAME 0x0006
#define NET_ERR_AVATAR_TOO_LARGE 0x0010
#define NET_ERR_AVATAR_WRONG_SIZE 0x0011
#define NET_ERR_JOIN_GAME_UNKNOWN_GAME 0x0020
#define NET_ERR_GENERAL_INVALID_PACKET 0xFF01
#define NET_ERR_GENERAL_INVALID_STATE 0xFF02
#define NET_ERR_GENERAL_PLAYER_KICKED 0xFF03
@@ -3200,9 +3203,7 @@ NetPacketPlayersActionRejected::SetData(const NetPacketPlayersActionRejected::Da
tmpData->gameState = htons(inData.gameState);
tmpData->playerAction = htons(inData.playerAction);
tmpData->playerBet = htonl(inData.playerBet);
// TODO: set rejection reason
tmpData->rejectionReason = htons(0);
tmpData->rejectionReason = htons(inData.rejectionReason);
// Check the packet - just in case.
Check(GetRawData());
@@ -3216,8 +3217,7 @@ NetPacketPlayersActionRejected::GetData(NetPacketPlayersActionRejected::Data &ou
outData.gameState = static_cast<GameState>(ntohs(tmpData->gameState));
outData.playerAction = static_cast<PlayerAction>(ntohs(tmpData->playerAction));
outData.playerBet = ntohl(tmpData->playerBet);
// TODO: set rejection reason
outData.rejectionReason = static_cast<PlayerActionCode>(ntohs(tmpData->rejectionReason));
}
const NetPacketPlayersActionRejected *
@@ -3240,7 +3240,10 @@ NetPacketPlayersActionRejected::InternalCheck(const NetPacketHeader* data) const
{
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
}
// TODO: check rejection reason
if (!ntohs(tmpData->rejectionReason))
{
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
}
}
//-----------------------------------------------------------------------------
@@ -4097,7 +4100,17 @@ NetPacketError::SetData(const NetPacketError::Data &inData)
case ERR_NET_INVALID_PLAYER_NAME :
tmpData->errorReason = htons(NET_ERR_INIT_INVALID_PLAYER_NAME);
break;
// General Errors.
case ERR_NET_AVATAR_TOO_LARGE :
tmpData->errorReason = htons(NET_ERR_AVATAR_TOO_LARGE);
break;
case ERR_NET_WRONG_AVATAR_SIZE :
tmpData->errorReason = htons(NET_ERR_AVATAR_WRONG_SIZE);
break;
case ERR_NET_UNKNOWN_GAME :
tmpData->errorReason = htons(NET_ERR_JOIN_GAME_UNKNOWN_GAME);
break;
// General Errors.
case ERR_SOCK_INVALID_PACKET :
tmpData->errorReason = htons(NET_ERR_GENERAL_INVALID_PACKET);
break;
@@ -4139,6 +4152,16 @@ NetPacketError::GetData(NetPacketError::Data &outData) const
case NET_ERR_INIT_INVALID_PLAYER_NAME :
outData.errorCode = ERR_NET_INVALID_PLAYER_NAME;
break;
case NET_ERR_AVATAR_TOO_LARGE :
outData.errorCode = ERR_NET_AVATAR_TOO_LARGE;
break;
case NET_ERR_AVATAR_WRONG_SIZE :
outData.errorCode = ERR_NET_WRONG_AVATAR_SIZE;
break;
case NET_ERR_JOIN_GAME_UNKNOWN_GAME :
outData.errorCode = ERR_NET_UNKNOWN_GAME;
break;
// General Errors.
case NET_ERR_GENERAL_INVALID_PACKET :
outData.errorCode = ERR_SOCK_INVALID_PACKET;