Switching from ASN.1 (asn1c) to google protocol buffers. Some things are still missing (packet verification, tests, ...), this is very early stuff.

This commit is contained in:
lotodore
2012-09-18 15:57:58 +02:00
parent 9c33f6e08a
commit 86c58fc7c8
16 changed files with 52009 additions and 1828 deletions
+197 -111
View File
@@ -73,23 +73,41 @@ message NetGameInfo {
} }
required NetGameType netGameType = 2; required NetGameType netGameType = 2;
required uint32 maxNumPlayers = 3; required uint32 maxNumPlayers = 3;
optional uint32 raiseEveryHands = 4; enum RaiseIntervalMode {
optional uint32 raiseEveryMinutes = 5; raiseOnHandNum = 1;
raiseOnMinutes = 2;
}
required RaiseIntervalMode raiseIntervalMode = 4;
optional uint32 raiseEveryHands = 5;
optional uint32 raiseEveryMinutes = 6;
enum EndRaiseMode { enum EndRaiseMode {
doubleBlinds = 1; doubleBlinds = 1;
raiseByEndValue = 2; raiseByEndValue = 2;
keepLastBlind = 3; keepLastBlind = 3;
} }
required EndRaiseMode endRaiseMode = 6; required EndRaiseMode endRaiseMode = 7;
optional uint32 endRaiseSmallBlindValue = 7; optional uint32 endRaiseSmallBlindValue = 8;
required uint32 proposedGuiSpeed = 8; required uint32 proposedGuiSpeed = 9;
required uint32 delayBetweenHands = 9; // These are seconds required uint32 delayBetweenHands = 10; // These are seconds
required uint32 playerActionTimeout = 10; // These are seconds required uint32 playerActionTimeout = 11; // These are seconds
required uint32 firstSmallBlind = 11; required uint32 firstSmallBlind = 12;
required uint32 startMoney = 12; required uint32 startMoney = 13;
repeated uint32 manualBlinds = 13 [packed = true]; repeated uint32 manualBlinds = 14 [packed = true];
} }
// Message Part containing player result.
message PlayerResult {
required uint32 playerId = 1;
required uint32 resultCard1 = 2;
required uint32 resultCard2 = 3;
repeated uint32 bestHandPosition = 4 [packed = true];
required uint32 moneyWon = 5;
required uint32 playerMoney = 6;
optional uint32 cardsValue = 7;
}
// All messages used in the network protocol. // All messages used in the network protocol.
message AnnounceMessage { message AnnounceMessage {
@@ -240,7 +258,7 @@ message SubscriptionRequestMessage {
required SubscriptionAction subscriptionAction = 1; required SubscriptionAction subscriptionAction = 1;
} }
message JoinExistingGameRequestMessage { message JoinExistingGameMessage {
required uint32 gameId = 1; required uint32 gameId = 1;
optional string password = 2; optional string password = 2;
optional bool autoLeave = 3; optional bool autoLeave = 3;
@@ -411,7 +429,7 @@ message MyActionRequestMessage {
message YourActionRejectedMessage { message YourActionRejectedMessage {
required uint32 gameId = 1; required uint32 gameId = 1;
required NetGameState gameState = 2; required NetGameState gameState = 2;
required NetPlayerAction myAction = 3; required NetPlayerAction yourAction = 3;
required uint32 yourRelativeBet = 4; required uint32 yourRelativeBet = 4;
enum RejectionReason { enum RejectionReason {
rejectedInvalidGameState = 1; rejectedInvalidGameState = 1;
@@ -461,15 +479,6 @@ message AllInShowCardsMessage {
message EndOfHandShowCardsMessage { message EndOfHandShowCardsMessage {
required uint32 gameId = 1; required uint32 gameId = 1;
message PlayerResult {
required uint32 playerId = 1;
required uint32 resultCard1 = 2;
required uint32 resultCard2 = 3;
repeated uint32 bestHandPosition = 4 [packed = true];
required uint32 moneyWon = 5;
required uint32 playerMoney = 6;
optional uint32 cardsValue = 7;
}
repeated PlayerResult playerResults = 2; repeated PlayerResult playerResults = 2;
} }
@@ -484,7 +493,7 @@ message ShowMyCardsRequestMessage {
} }
message AfterHandShowCardsMessage { message AfterHandShowCardsMessage {
required EndOfHandShowCardsMessage.PlayerResult playerResult = 1; required PlayerResult playerResult = 1;
} }
message EndOfGameMessage { message EndOfGameMessage {
@@ -618,7 +627,7 @@ message ResetTimeoutMessage {
message ReportAvatarMessage { message ReportAvatarMessage {
required uint32 reportedPlayerId = 1; required uint32 reportedPlayerId = 1;
required uint32 reportedAvatarHash = 2; required bytes reportedAvatarHash = 2;
} }
message ReportAvatarAckMessage { message ReportAvatarAckMessage {
@@ -647,21 +656,21 @@ message ReportGameAckMessage {
message ErrorMessage { message ErrorMessage {
enum ErrorReason { enum ErrorReason {
errorReserved = 0; reserved = 0;
errorInitVersionNotSupported = 1; initVersionNotSupported = 1;
errorInitServerFull = 2; initServerFull = 2;
errorInitAuthFailure = 3; initAuthFailure = 3;
errorInitPlayerNameInUse = 4; initPlayerNameInUse = 4;
errorInitInvalidPlayerName = 5; initInvalidPlayerName = 5;
errorInitServerMaintenance = 6; initServerMaintenance = 6;
errorInitBlocked = 7; initBlocked = 7;
errorAvatarTooLarge = 8; avatarTooLarge = 8;
errorInvalidPacket = 9; invalidPacket = 9;
errorInvalidState = 10; invalidState = 10;
errorKickedFromServer = 11; kickedFromServer = 11;
errorBannedFromServer = 12; bannedFromServer = 12;
errorBlockedByServer = 13; blockedByServer = 13;
errorSessionTimeout = 14; sessionTimeout = 14;
} }
required ErrorReason errorReason = 1; required ErrorReason errorReason = 1;
} }
@@ -669,77 +678,154 @@ message ErrorMessage {
// The main message type (it is prefixed by 4 bytes length of the message). // The main message type (it is prefixed by 4 bytes length of the message).
message PokerTHMessage { message PokerTHMessage {
optional AnnounceMessage announceMessage = 1; enum PokerTHMessageType {
optional InitMessage initMessage = 2; Type_AnnounceMessage = 1;
optional AuthServerChallengeMessage authServerChallengeMessage = 3; Type_InitMessage = 2;
optional AuthClientResponseMessage authClientResponseMessage = 4; Type_AuthServerChallengeMessage = 3;
optional AuthServerVerificationMessage authServerVerificationMessage = 5; Type_AuthClientResponseMessage = 4;
optional InitAckMessage initAckMessage = 6; Type_AuthServerVerificationMessage = 5;
optional AvatarRequestMessage avatarRequestMessage = 7; Type_InitAckMessage = 6;
optional AvatarHeaderMessage avatarHeaderMessage = 8; Type_AvatarRequestMessage = 7;
optional AvatarDataMessage avatarDataMessage = 9; Type_AvatarHeaderMessage = 8;
optional AvatarEndMessage avatarEndMessage = 10; Type_AvatarDataMessage = 9;
optional UnknownAvatarMessage unknownAvatarMessage = 11; Type_AvatarEndMessage = 10;
optional PlayerListMessage playerListMessage = 12; Type_UnknownAvatarMessage = 11;
optional GameListNewMessage gameListNewMessage = 13; Type_PlayerListMessage = 12;
optional GameListUpdateMessage gameListUpdateMessage = 14; Type_GameListNewMessage = 13;
optional GameListPlayerJoinedMessage gameListPlayerJoinedMessage = 15; Type_GameListUpdateMessage = 14;
optional GameListPlayerLeftMessage gameListPlayerLeftMessage = 16; Type_GameListPlayerJoinedMessage = 15;
optional GameListAdminChangedMessage gameListAdminChangedMessage = 17; Type_GameListPlayerLeftMessage = 16;
optional PlayerInfoRequestMessage playerInfoRequestMessage = 18; Type_GameListAdminChangedMessage = 17;
optional PlayerInfoReplyMessage playerInfoReplyMessage = 19; Type_PlayerInfoRequestMessage = 18;
optional SubscriptionRequestMessage subscriptionRequestMessage = 20; Type_PlayerInfoReplyMessage = 19;
optional JoinExistingGameRequestMessage joinExistingGameRequestMessage = 21; Type_SubscriptionRequestMessage = 20;
optional JoinNewGameMessage joinNewGameMessage = 22; Type_JoinExistingGameMessage = 21;
optional RejoinExistingGameMessage rejoinExistingGameMessage = 23; Type_JoinNewGameMessage = 22;
optional JoinGameAckMessage joinGameAckMessage = 24; Type_RejoinExistingGameMessage = 23;
optional JoinGameFailedMessage joinGameFailedMessage = 25; Type_JoinGameAckMessage = 24;
optional GamePlayerJoinedMessage gamePlayerJoinedMessage = 26; Type_JoinGameFailedMessage = 25;
optional GamePlayerLeftMessage gamePlayerLeftMessage = 27; Type_GamePlayerJoinedMessage = 26;
optional GameAdminChangedMessage gameAdminChangedMessage = 28; Type_GamePlayerLeftMessage = 27;
optional RemovedFromGameMessage removedFromGameMessage = 29; Type_GameAdminChangedMessage = 28;
optional KickPlayerRequestMessage kickPlayerRequestMessage = 30; Type_RemovedFromGameMessage = 29;
optional LeaveGameRequestMessage leaveGameRequestMessage = 31; Type_KickPlayerRequestMessage = 30;
optional InvitePlayerToGameMessage invitePlayerToGameMessage = 32; Type_LeaveGameRequestMessage = 31;
optional InviteNotifyMessage inviteNotifyMessage = 33; Type_InvitePlayerToGameMessage = 32;
optional RejectGameInvitationMessage rejectGameInvitationMessage = 34; Type_InviteNotifyMessage = 33;
optional RejectInvNotifyMessage rejectInvNotifyMessage = 35; Type_RejectGameInvitationMessage = 34;
optional StartEventMessage startEventMessage = 36; Type_RejectInvNotifyMessage = 35;
optional StartEventAckMessage startEventAckMessage = 37; Type_StartEventMessage = 36;
optional GameStartInitialMessage gameStartInitialMessage = 38; Type_StartEventAckMessage = 37;
optional GameStartRejoinMessage gameStartRejoinMessage = 39; Type_GameStartInitialMessage = 38;
optional HandStartMessage handStartMessage = 40; Type_GameStartRejoinMessage = 39;
optional PlayersTurnMessage playersTurnMessage = 41; Type_HandStartMessage = 40;
optional MyActionRequestMessage myActionRequestMessage = 42; Type_PlayersTurnMessage = 41;
optional YourActionRejectedMessage yourActionRejectedMessage = 43; Type_MyActionRequestMessage = 42;
optional PlayersActionDoneMessage playersActionDoneMessage = 44; Type_YourActionRejectedMessage = 43;
optional DealFlopCardsMessage dealFlopCardsMessage = 45; Type_PlayersActionDoneMessage = 44;
optional DealTurnCardMessage dealTurnCardMessage = 46; Type_DealFlopCardsMessage = 45;
optional DealRiverCardMessage dealRiverCardMessage = 47; Type_DealTurnCardMessage = 46;
optional AllInShowCardsMessage allInShowCardsMessage = 48; Type_DealRiverCardMessage = 47;
optional EndOfHandShowCardsMessage endOfHandShowCardsMessage = 49; Type_AllInShowCardsMessage = 48;
optional EndOfHandHideCardsMessage endOfHandHideCardsMessage = 50; Type_EndOfHandShowCardsMessage = 49;
optional ShowMyCardsRequestMessage showMyCardsRequestMessage = 51; Type_EndOfHandHideCardsMessage = 50;
optional AfterHandShowCardsMessage afterHandShowCardsMessage = 52; Type_ShowMyCardsRequestMessage = 51;
optional EndOfGameMessage endOfGameMessage = 53; Type_AfterHandShowCardsMessage = 52;
optional PlayerIdChangedMessage playerIdChangedMessage = 54; Type_EndOfGameMessage = 53;
optional AskKickPlayerMessage askKickPlayerMessage = 55; Type_PlayerIdChangedMessage = 54;
optional AskKickDeniedMessage askKickDeniedMessage = 56; Type_AskKickPlayerMessage = 55;
optional StartKickPetitionMessage startKickPetitionMessage = 57; Type_AskKickDeniedMessage = 56;
optional VoteKickRequestMessage voteKickRequestMessage = 58; Type_StartKickPetitionMessage = 57;
optional VoteKickReplyMessage voteKickReplyMessage = 59; Type_VoteKickRequestMessage = 58;
optional KickPetitionUpdateMessage kickPetitionUpdateMessage = 60; Type_VoteKickReplyMessage = 59;
optional EndKickPetitionMessage endKickPetitionMessage = 61; Type_KickPetitionUpdateMessage = 60;
optional StatisticsMessage statisticsMessage = 62; Type_EndKickPetitionMessage = 61;
optional ChatRequestMessage chatRequestMessage = 63; Type_StatisticsMessage = 62;
optional ChatMessage chatMessage = 64; Type_ChatRequestMessage = 63;
optional ChatRejectMessage chatRejectMessage = 65; Type_ChatMessage = 64;
optional DialogMessage dialogMessage = 66; Type_ChatRejectMessage = 65;
optional TimeoutWarningMessage timeoutWarningMessage = 67; Type_DialogMessage = 66;
optional ResetTimeoutMessage resetTimeoutMessage = 68; Type_TimeoutWarningMessage = 67;
optional ReportAvatarMessage reportAvatarMessage = 69; Type_ResetTimeoutMessage = 68;
optional ReportAvatarAckMessage reportAvatarAckMessage = 70; Type_ReportAvatarMessage = 69;
optional ReportGameMessage reportGameMessage = 71; Type_ReportAvatarAckMessage = 70;
optional ReportGameAckMessage reportGameAckMessage = 72; Type_ReportGameMessage = 71;
optional ErrorMessage errorMessage = 73; Type_ReportGameAckMessage = 72;
Type_ErrorMessage = 73;
}
required PokerTHMessageType messageType = 1;
optional AnnounceMessage announceMessage = 2;
optional InitMessage initMessage = 3;
optional AuthServerChallengeMessage authServerChallengeMessage = 4;
optional AuthClientResponseMessage authClientResponseMessage = 5;
optional AuthServerVerificationMessage authServerVerificationMessage = 6;
optional InitAckMessage initAckMessage = 7;
optional AvatarRequestMessage avatarRequestMessage = 8;
optional AvatarHeaderMessage avatarHeaderMessage = 9;
optional AvatarDataMessage avatarDataMessage = 10;
optional AvatarEndMessage avatarEndMessage = 11;
optional UnknownAvatarMessage unknownAvatarMessage = 12;
optional PlayerListMessage playerListMessage = 13;
optional GameListNewMessage gameListNewMessage = 14;
optional GameListUpdateMessage gameListUpdateMessage = 15;
optional GameListPlayerJoinedMessage gameListPlayerJoinedMessage = 16;
optional GameListPlayerLeftMessage gameListPlayerLeftMessage = 17;
optional GameListAdminChangedMessage gameListAdminChangedMessage = 18;
optional PlayerInfoRequestMessage playerInfoRequestMessage = 19;
optional PlayerInfoReplyMessage playerInfoReplyMessage = 20;
optional SubscriptionRequestMessage subscriptionRequestMessage = 21;
optional JoinExistingGameMessage joinExistingGameMessage = 22;
optional JoinNewGameMessage joinNewGameMessage = 23;
optional RejoinExistingGameMessage rejoinExistingGameMessage = 24;
optional JoinGameAckMessage joinGameAckMessage = 25;
optional JoinGameFailedMessage joinGameFailedMessage = 26;
optional GamePlayerJoinedMessage gamePlayerJoinedMessage = 27;
optional GamePlayerLeftMessage gamePlayerLeftMessage = 28;
optional GameAdminChangedMessage gameAdminChangedMessage = 29;
optional RemovedFromGameMessage removedFromGameMessage = 30;
optional KickPlayerRequestMessage kickPlayerRequestMessage = 31;
optional LeaveGameRequestMessage leaveGameRequestMessage = 32;
optional InvitePlayerToGameMessage invitePlayerToGameMessage = 33;
optional InviteNotifyMessage inviteNotifyMessage = 34;
optional RejectGameInvitationMessage rejectGameInvitationMessage = 35;
optional RejectInvNotifyMessage rejectInvNotifyMessage = 36;
optional StartEventMessage startEventMessage = 37;
optional StartEventAckMessage startEventAckMessage = 38;
optional GameStartInitialMessage gameStartInitialMessage = 39;
optional GameStartRejoinMessage gameStartRejoinMessage = 40;
optional HandStartMessage handStartMessage = 41;
optional PlayersTurnMessage playersTurnMessage = 42;
optional MyActionRequestMessage myActionRequestMessage = 43;
optional YourActionRejectedMessage yourActionRejectedMessage = 44;
optional PlayersActionDoneMessage playersActionDoneMessage = 45;
optional DealFlopCardsMessage dealFlopCardsMessage = 46;
optional DealTurnCardMessage dealTurnCardMessage = 47;
optional DealRiverCardMessage dealRiverCardMessage = 48;
optional AllInShowCardsMessage allInShowCardsMessage = 49;
optional EndOfHandShowCardsMessage endOfHandShowCardsMessage = 50;
optional EndOfHandHideCardsMessage endOfHandHideCardsMessage = 51;
optional ShowMyCardsRequestMessage showMyCardsRequestMessage = 52;
optional AfterHandShowCardsMessage afterHandShowCardsMessage = 53;
optional EndOfGameMessage endOfGameMessage = 54;
optional PlayerIdChangedMessage playerIdChangedMessage = 55;
optional AskKickPlayerMessage askKickPlayerMessage = 56;
optional AskKickDeniedMessage askKickDeniedMessage = 57;
optional StartKickPetitionMessage startKickPetitionMessage = 58;
optional VoteKickRequestMessage voteKickRequestMessage = 59;
optional VoteKickReplyMessage voteKickReplyMessage = 60;
optional KickPetitionUpdateMessage kickPetitionUpdateMessage = 61;
optional EndKickPetitionMessage endKickPetitionMessage = 62;
optional StatisticsMessage statisticsMessage = 63;
optional ChatRequestMessage chatRequestMessage = 64;
optional ChatMessage chatMessage = 65;
optional ChatRejectMessage chatRejectMessage = 66;
optional DialogMessage dialogMessage = 67;
optional TimeoutWarningMessage timeoutWarningMessage = 68;
optional ResetTimeoutMessage resetTimeoutMessage = 69;
optional ReportAvatarMessage reportAvatarMessage = 70;
optional ReportAvatarAckMessage reportAvatarAckMessage = 71;
optional ReportGameMessage reportGameMessage = 72;
optional ReportGameAckMessage reportGameAckMessage = 73;
optional ErrorMessage errorMessage = 74;
} }
+1
View File
@@ -343,6 +343,7 @@ SOURCES += src/third_party/asn1/ChatCleanerMessage.c \
src/third_party/asn1/CleanerChatType.c \ src/third_party/asn1/CleanerChatType.c \
src/third_party/asn1/ChatTypePrivate.c \ src/third_party/asn1/ChatTypePrivate.c \
src/third_party/asn1/ChatRejectMessage.c src/third_party/asn1/ChatRejectMessage.c
SOURCES += src/third_party/protobuf/pokerth.pb.cc
win32 { win32 {
DEFINES += CURL_STATICLIB DEFINES += CURL_STATICLIB
DEFINES += _WIN32_WINNT=0x0501 DEFINES += _WIN32_WINNT=0x0501
+15 -21
View File
@@ -182,13 +182,12 @@ AvatarManager::AvatarFileToNetPackets(const string &fileName, unsigned requestId
AvatarFileType fileType; AvatarFileType fileType;
boost::shared_ptr<AvatarFileState> tmpState = OpenAvatarFileForChunkRead(fileName, fileSize, fileType); boost::shared_ptr<AvatarFileState> tmpState = OpenAvatarFileForChunkRead(fileName, fileSize, fileType);
if (tmpState.get() && fileSize && fileType != AVATAR_FILE_TYPE_UNKNOWN) { if (tmpState.get() && fileSize && fileType != AVATAR_FILE_TYPE_UNKNOWN) {
boost::shared_ptr<NetPacket> avatarHeader(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> avatarHeader(new NetPacket);
avatarHeader->GetMsg()->present = PokerTHMessage_PR_avatarReplyMessage; avatarHeader->GetMsg()->set_messagetype(PokerTHMessage::Type_AvatarHeaderMessage);
AvatarReplyMessage_t *netHeader = &avatarHeader->GetMsg()->choice.avatarReplyMessage; AvatarHeaderMessage *netHeader = avatarHeader->GetMsg()->mutable_avatarheadermessage();
netHeader->requestId = requestId; netHeader->set_requestid(requestId);
netHeader->avatarResult.present = avatarResult_PR_avatarHeader; netHeader->set_avatartype(static_cast<NetAvatarType>(fileType));
netHeader->avatarResult.choice.avatarHeader.avatarType = fileType; netHeader->set_avatarsize(fileSize);
netHeader->avatarResult.choice.avatarHeader.avatarSize = fileSize;
packets.push_back(avatarHeader); packets.push_back(avatarHeader);
unsigned numBytes = 0; unsigned numBytes = 0;
@@ -199,15 +198,11 @@ AvatarManager::AvatarFileToNetPackets(const string &fileName, unsigned requestId
if (numBytes) { if (numBytes) {
totalBytesRead += numBytes; totalBytesRead += numBytes;
boost::shared_ptr<NetPacket> avatarFile(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> avatarFile(new NetPacket);
avatarFile->GetMsg()->present = PokerTHMessage_PR_avatarReplyMessage; avatarFile->GetMsg()->set_messagetype(PokerTHMessage::Type_AvatarDataMessage);
AvatarReplyMessage_t *netFile = &avatarFile->GetMsg()->choice.avatarReplyMessage; AvatarDataMessage *netFile = avatarFile->GetMsg()->mutable_avatardatamessage();
netFile->requestId = requestId; netFile->set_requestid(requestId);
netFile->avatarResult.present = avatarResult_PR_avatarData; netFile->set_avatarblock((const char *)&tmpData[0], numBytes);
OCTET_STRING_fromBuf(
&netFile->avatarResult.choice.avatarData.avatarBlock,
(const char *)&tmpData[0],
numBytes);
packets.push_back(avatarFile); packets.push_back(avatarFile);
} }
} while (numBytes); } while (numBytes);
@@ -215,11 +210,10 @@ AvatarManager::AvatarFileToNetPackets(const string &fileName, unsigned requestId
if (fileSize != totalBytesRead) if (fileSize != totalBytesRead)
retVal = ERR_NET_WRONG_AVATAR_SIZE; retVal = ERR_NET_WRONG_AVATAR_SIZE;
else { else {
boost::shared_ptr<NetPacket> avatarEnd(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> avatarEnd(new NetPacket);
avatarEnd->GetMsg()->present = PokerTHMessage_PR_avatarReplyMessage; avatarEnd->GetMsg()->set_messagetype(PokerTHMessage::Type_AvatarEndMessage);
AvatarReplyMessage_t *netEnd = &avatarEnd->GetMsg()->choice.avatarReplyMessage; AvatarEndMessage *netEnd = avatarEnd->GetMsg()->mutable_avatarendmessage();
netEnd->requestId = requestId; netEnd->set_requestid(requestId);
netEnd->avatarResult.present = avatarResult_PR_avatarEnd;
packets.push_back(avatarEnd); packets.push_back(avatarEnd);
retVal = 0; retVal = 0;
} }
File diff suppressed because it is too large Load Diff
+115 -152
View File
@@ -106,21 +106,21 @@ ClientThread::SignalTermination()
void void
ClientThread::SendKickPlayer(unsigned playerId) ClientThread::SendKickPlayer(unsigned playerId)
{ {
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_kickPlayerRequestMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_KickPlayerRequestMessage);
KickPlayerRequestMessage_t *netKick = &packet->GetMsg()->choice.kickPlayerRequestMessage; KickPlayerRequestMessage *netKick = packet->GetMsg()->mutable_kickplayerrequestmessage();
netKick->gameId = GetGameId(); netKick->set_gameid(GetGameId());
netKick->playerId = playerId; netKick->set_playerid(playerId);
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet)); m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
} }
void void
ClientThread::SendLeaveCurrentGame() ClientThread::SendLeaveCurrentGame()
{ {
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_leaveGameRequestMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_LeaveGameRequestMessage);
LeaveGameRequestMessage_t *netLeave = &packet->GetMsg()->choice.leaveGameRequestMessage; LeaveGameRequestMessage *netLeave = packet->GetMsg()->mutable_leavegamerequestmessage();
netLeave->gameId = GetGameId(); netLeave->set_gameid(GetGameId());
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet)); m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
} }
@@ -129,14 +129,12 @@ ClientThread::SendStartEvent(bool fillUpWithCpuPlayers)
{ {
// Warning: This function is called in the context of the GUI thread. // Warning: This function is called in the context of the GUI thread.
// Create a network packet for the server start event. // Create a network packet for the server start event.
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_startEventMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_StartEventMessage);
StartEventMessage_t *netStartEvent = &packet->GetMsg()->choice.startEventMessage; StartEventMessage *netStartEvent = packet->GetMsg()->mutable_starteventmessage();
netStartEvent->gameId = GetGameId(); netStartEvent->set_starteventtype(StartEventMessage::startEvent);
netStartEvent->set_gameid(GetGameId());
netStartEvent->startEventType.present = startEventType_PR_startEvent; netStartEvent->set_fillwithcomputerplayers(fillUpWithCpuPlayers);
StartEvent_t *start = &netStartEvent->startEventType.choice.startEvent;
start->fillWithComputerPlayers = fillUpWithCpuPlayers;
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet)); m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
} }
@@ -145,19 +143,19 @@ ClientThread::SendPlayerAction()
{ {
// Warning: This function is called in the context of the GUI thread. // Warning: This function is called in the context of the GUI thread.
// Create a network packet containing the current player action. // Create a network packet containing the current player action.
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_myActionRequestMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_MyActionRequestMessage);
MyActionRequestMessage_t *netMyAction = &packet->GetMsg()->choice.myActionRequestMessage; MyActionRequestMessage *netMyAction = packet->GetMsg()->mutable_myactionrequestmessage();
netMyAction->gameId = GetGameId(); netMyAction->set_gameid(GetGameId());
boost::shared_ptr<PlayerInterface> myPlayer = GetGame()->getSeatsList()->front(); boost::shared_ptr<PlayerInterface> myPlayer = GetGame()->getSeatsList()->front();
netMyAction->handNum = GetGame()->getCurrentHandID(); netMyAction->set_handnum(GetGame()->getCurrentHandID());
netMyAction->gameState = GetGame()->getCurrentHand()->getCurrentRound(); netMyAction->set_gamestate(static_cast<NetGameState>(GetGame()->getCurrentHand()->getCurrentRound()));
netMyAction->myAction = myPlayer->getMyAction(); netMyAction->set_myaction(static_cast<NetPlayerAction>(myPlayer->getMyAction()));
// Only send last bet if not fold/checked. // Only send last bet if not fold/checked.
if (myPlayer->getMyAction() != PLAYER_ACTION_FOLD && myPlayer->getMyAction() != PLAYER_ACTION_CHECK) if (myPlayer->getMyAction() != PLAYER_ACTION_FOLD && myPlayer->getMyAction() != PLAYER_ACTION_CHECK)
netMyAction->myRelativeBet = myPlayer->getMyLastRelativeSet(); netMyAction->set_myrelativebet(myPlayer->getMyLastRelativeSet());
else else
netMyAction->myRelativeBet = 0; netMyAction->set_myrelativebet(0);
// Just dump the packet. // Just dump the packet.
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet)); m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
} }
@@ -167,15 +165,11 @@ ClientThread::SendGameChatMessage(const std::string &msg)
{ {
// Warning: This function is called in the context of the GUI thread. // Warning: This function is called in the context of the GUI thread.
// Create a network packet containing the chat message. // Create a network packet containing the chat message.
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_chatRequestMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_ChatRequestMessage);
ChatRequestMessage_t *netChat = &packet->GetMsg()->choice.chatRequestMessage; ChatRequestMessage *netChat = packet->GetMsg()->mutable_chatrequestmessage();
OCTET_STRING_fromBuf(&netChat->chatText, netChat->set_targetgameid(GetGameId());
msg.c_str(), netChat->set_chattext(msg);
(int)msg.length());
netChat->chatRequestType.present = chatRequestType_PR_chatRequestTypeGame;
netChat->chatRequestType.choice.chatRequestTypeGame.gameId = GetGameId();
// Just dump the packet. // Just dump the packet.
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet)); m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
@@ -186,14 +180,10 @@ ClientThread::SendLobbyChatMessage(const std::string &msg)
{ {
// Warning: This function is called in the context of the GUI thread. // Warning: This function is called in the context of the GUI thread.
// Create a network packet containing the chat message. // Create a network packet containing the chat message.
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_chatRequestMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_ChatRequestMessage);
ChatRequestMessage_t *netChat = &packet->GetMsg()->choice.chatRequestMessage; ChatRequestMessage *netChat = packet->GetMsg()->mutable_chatrequestmessage();
OCTET_STRING_fromBuf(&netChat->chatText, netChat->set_chattext(msg);
msg.c_str(),
(int)msg.length());
netChat->chatRequestType.present = chatRequestType_PR_chatRequestTypeLobby;
// Just dump the packet. // Just dump the packet.
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet)); m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
@@ -204,15 +194,11 @@ ClientThread::SendPrivateChatMessage(unsigned targetPlayerId, const std::string
{ {
// Warning: This function is called in the context of the GUI thread. // Warning: This function is called in the context of the GUI thread.
// Create a network packet containing the chat message. // Create a network packet containing the chat message.
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_chatRequestMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_ChatRequestMessage);
ChatRequestMessage_t *netChat = &packet->GetMsg()->choice.chatRequestMessage; ChatRequestMessage *netChat = packet->GetMsg()->mutable_chatrequestmessage();
OCTET_STRING_fromBuf(&netChat->chatText, netChat->set_targetplayerid(targetPlayerId);
msg.c_str(), netChat->set_chattext(msg);
(int)msg.length());
netChat->chatRequestType.present = chatRequestType_PR_chatRequestTypePrivate;
netChat->chatRequestType.choice.chatRequestTypePrivate.targetPlayerId = targetPlayerId;
// Just dump the packet. // Just dump the packet.
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet)); m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
@@ -223,19 +209,14 @@ ClientThread::SendJoinFirstGame(const std::string &password, bool autoLeave)
{ {
// Warning: This function is called in the context of the GUI thread. // Warning: This function is called in the context of the GUI thread.
// Create a network packet to request joining a game. // Create a network packet to request joining a game.
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_joinGameRequestMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_JoinExistingGameMessage);
JoinGameRequestMessage_t *netJoinGame = &packet->GetMsg()->choice.joinGameRequestMessage; JoinExistingGameMessage *netJoinGame = packet->GetMsg()->mutable_joinexistinggamemessage();
netJoinGame->autoLeave = autoLeave; netJoinGame->set_gameid(1);
netJoinGame->joinGameAction.present = joinGameAction_PR_joinExistingGame; netJoinGame->set_autoleave(autoLeave);
JoinExistingGame_t *joinExisting = &netJoinGame->joinGameAction.choice.joinExistingGame;
joinExisting->gameId = 1;
if (!password.empty()) { if (!password.empty()) {
joinExisting->password = OCTET_STRING_new_fromBuf( netJoinGame->set_password(password);
&asn_DEF_UTF8String,
password.c_str(),
(int)password.length());
} }
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet)); m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
} }
@@ -245,19 +226,14 @@ ClientThread::SendJoinGame(unsigned gameId, const std::string &password, bool au
{ {
// Warning: This function is called in the context of the GUI thread. // Warning: This function is called in the context of the GUI thread.
// Create a network packet to request joining a game. // Create a network packet to request joining a game.
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_joinGameRequestMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_JoinExistingGameMessage);
JoinGameRequestMessage_t *netJoinGame = &packet->GetMsg()->choice.joinGameRequestMessage; JoinExistingGameMessage *netJoinGame = packet->GetMsg()->mutable_joinexistinggamemessage();
netJoinGame->autoLeave = autoLeave; netJoinGame->set_gameid(gameId);
netJoinGame->joinGameAction.present = joinGameAction_PR_joinExistingGame; netJoinGame->set_autoleave(autoLeave);
JoinExistingGame_t *joinExisting = &netJoinGame->joinGameAction.choice.joinExistingGame;
joinExisting->gameId = gameId;
if (!password.empty()) { if (!password.empty()) {
joinExisting->password = OCTET_STRING_new_fromBuf( netJoinGame->set_password(password);
&asn_DEF_UTF8String,
password.c_str(),
(int)password.length());
} }
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet)); m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
} }
@@ -267,14 +243,12 @@ ClientThread::SendRejoinGame(unsigned gameId, bool autoLeave)
{ {
// Warning: This function is called in the context of the GUI thread. // Warning: This function is called in the context of the GUI thread.
// Create a network packet to request rejoining a running game. // Create a network packet to request rejoining a running game.
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_joinGameRequestMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_RejoinExistingGameMessage);
JoinGameRequestMessage_t *netJoinGame = &packet->GetMsg()->choice.joinGameRequestMessage; RejoinExistingGameMessage *netJoinGame = packet->GetMsg()->mutable_rejoinexistinggamemessage();
netJoinGame->autoLeave = autoLeave; netJoinGame->set_gameid(gameId);
netJoinGame->joinGameAction.present = joinGameAction_PR_rejoinExistingGame; netJoinGame->set_autoleave(autoLeave);
RejoinExistingGame_t *rejoinExisting = &netJoinGame->joinGameAction.choice.rejoinExistingGame;
rejoinExisting->gameId = gameId;
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet)); m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
} }
@@ -283,22 +257,16 @@ ClientThread::SendCreateGame(const GameData &gameData, const std::string &name,
{ {
// Warning: This function is called in the context of the GUI thread. // Warning: This function is called in the context of the GUI thread.
// Create a network packet to request creating a new game. // Create a network packet to request creating a new game.
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_joinGameRequestMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_JoinNewGameMessage);
JoinGameRequestMessage_t *netJoinGame = &packet->GetMsg()->choice.joinGameRequestMessage; JoinNewGameMessage *netJoinGame = packet->GetMsg()->mutable_joinnewgamemessage();
netJoinGame->autoLeave = autoLeave; netJoinGame->set_autoleave(autoLeave);
netJoinGame->joinGameAction.present = joinGameAction_PR_joinNewGame; NetGameInfo *gameInfo = netJoinGame->mutable_gameinfo();
NetPacket::SetGameData(gameData, *gameInfo);
gameInfo->set_gamename(name);
JoinNewGame_t *joinNew = &netJoinGame->joinGameAction.choice.joinNewGame;
NetPacket::SetGameData(gameData, &joinNew->gameInfo);
OCTET_STRING_fromBuf(&joinNew->gameInfo.gameName,
name.c_str(),
(int)name.length());
if (!password.empty()) { if (!password.empty()) {
joinNew->password = OCTET_STRING_new_fromBuf( netJoinGame->set_password(password);
&asn_DEF_UTF8String,
password.c_str(),
(int)password.length());
} }
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet)); m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
} }
@@ -306,80 +274,77 @@ ClientThread::SendCreateGame(const GameData &gameData, const std::string &name,
void void
ClientThread::SendResetTimeout() ClientThread::SendResetTimeout()
{ {
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_resetTimeoutMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_ResetTimeoutMessage);
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet)); m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
} }
void void
ClientThread::SendAskKickPlayer(unsigned playerId) ClientThread::SendAskKickPlayer(unsigned playerId)
{ {
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_askKickPlayerMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_AskKickPlayerMessage);
AskKickPlayerMessage_t *netAsk = &packet->GetMsg()->choice.askKickPlayerMessage; AskKickPlayerMessage *netAsk = packet->GetMsg()->mutable_askkickplayermessage();
netAsk->gameId = GetGameId(); netAsk->set_gameid(GetGameId());
netAsk->playerId = playerId; netAsk->set_playerid(playerId);
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet)); m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
} }
void void
ClientThread::SendVoteKick(bool doKick) ClientThread::SendVoteKick(bool doKick)
{ {
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_voteKickRequestMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_VoteKickRequestMessage);
VoteKickRequestMessage_t *netVote = &packet->GetMsg()->choice.voteKickRequestMessage; VoteKickRequestMessage *netVote = packet->GetMsg()->mutable_votekickrequestmessage();
netVote->gameId = GetGameId(); netVote->set_gameid(GetGameId());
{ {
boost::mutex::scoped_lock lock(m_curPetitionIdMutex); boost::mutex::scoped_lock lock(m_curPetitionIdMutex);
netVote->petitionId = m_curPetitionId; netVote->set_petitionid(m_curPetitionId);
} }
netVote->voteKick = doKick; netVote->set_votekick(doKick);
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet)); m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
} }
void void
ClientThread::SendShowMyCards() ClientThread::SendShowMyCards()
{ {
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_showMyCardsRequestMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_ShowMyCardsRequestMessage);
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet)); m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
} }
void void
ClientThread::SendInvitePlayerToCurrentGame(unsigned playerId) ClientThread::SendInvitePlayerToCurrentGame(unsigned playerId)
{ {
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_invitePlayerToGameMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_InvitePlayerToGameMessage);
InvitePlayerToGameMessage_t *netInvite = &packet->GetMsg()->choice.invitePlayerToGameMessage; InvitePlayerToGameMessage *netInvite = packet->GetMsg()->mutable_inviteplayertogamemessage();
netInvite->gameId = GetGameId(); netInvite->set_gameid(GetGameId());
netInvite->playerId = playerId; netInvite->set_playerid(playerId);
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet)); m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
} }
void void
ClientThread::SendRejectGameInvitation(unsigned gameId, DenyGameInvitationReason reason) ClientThread::SendRejectGameInvitation(unsigned gameId, DenyGameInvitationReason reason)
{ {
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_rejectGameInvitationMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_RejectGameInvitationMessage);
RejectGameInvitationMessage_t *netReject = &packet->GetMsg()->choice.rejectGameInvitationMessage; RejectGameInvitationMessage *netReject = packet->GetMsg()->mutable_rejectgameinvitationmessage();
netReject->gameId = gameId; netReject->set_gameid(gameId);
netReject->myRejectReason = static_cast<RejectGameInvReason_t>(reason); netReject->set_myrejectreason(static_cast<RejectGameInvitationMessage::RejectGameInvReason>(reason));
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet)); m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
} }
void void
ClientThread::SendReportAvatar(unsigned reportedPlayerId, const std::string &avatarHash) ClientThread::SendReportAvatar(unsigned reportedPlayerId, const std::string &avatarHash)
{ {
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_reportAvatarMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_ReportAvatarMessage);
ReportAvatarMessage_t *netReport = &packet->GetMsg()->choice.reportAvatarMessage; ReportAvatarMessage *netReport = packet->GetMsg()->mutable_reportavatarmessage();
netReport->reportedPlayerId = reportedPlayerId; netReport->set_reportedplayerid(reportedPlayerId);
MD5Buf tmpMD5; MD5Buf tmpMD5;
if (tmpMD5.FromString(avatarHash) && !tmpMD5.IsZero()) { if (tmpMD5.FromString(avatarHash) && !tmpMD5.IsZero()) {
OCTET_STRING_fromBuf( netReport->set_reportedavatarhash(tmpMD5.GetData(), MD5_DATA_SIZE);
&netReport->reportedAvatar,
(const char *)tmpMD5.GetData(),
MD5_DATA_SIZE);
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet)); m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
} }
@@ -388,10 +353,10 @@ ClientThread::SendReportAvatar(unsigned reportedPlayerId, const std::string &ava
void void
ClientThread::SendReportGameName(unsigned reportedGameId) ClientThread::SendReportGameName(unsigned reportedGameId)
{ {
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_reportGameMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_ReportGameMessage);
ReportGameMessage_t *netReport = &packet->GetMsg()->choice.reportGameMessage; ReportGameMessage *netReport = packet->GetMsg()->mutable_reportgamemessage();
netReport->reportedGameId = reportedGameId; netReport->set_reportedgameid(reportedGameId);
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet)); m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
} }
@@ -625,7 +590,7 @@ ClientThread::InitGame()
// TODO // TODO
//if (GetPlayerDataList().size() != (unsigned)GetStartData().numberOfPlayers) //if (GetPlayerDataList().size() != (unsigned)GetStartData().numberOfPlayers)
// throw ClientException(__FILE__, __LINE__, ERR_NET_INVALID_PLAYER_COUNT, 0); // throw ClientException(__FILE__, __LINE__, ERR_NET_INVALID_PLAYER_COUNT, 0);
m_startData.numberOfPlayers = GetPlayerDataList().size(); m_startData.numberOfPlayers = (int)GetPlayerDataList().size();
m_game.reset(new Game(&m_gui, factory, GetPlayerDataList(), GetGameData(), GetStartData(), m_curGameNum++, m_clientLog.get())); m_game.reset(new Game(&m_gui, factory, GetPlayerDataList(), GetGameData(), GetStartData(), m_curGameNum++, m_clientLog.get()));
// Initialize Minimum GUI speed. // Initialize Minimum GUI speed.
int minimumGuiSpeed = 1; int minimumGuiSpeed = 1;
@@ -680,10 +645,10 @@ void
ClientThread::RequestPlayerInfo(unsigned id, bool requestAvatar) ClientThread::RequestPlayerInfo(unsigned id, bool requestAvatar)
{ {
if (find(m_playerInfoRequestList.begin(), m_playerInfoRequestList.end(), id) == m_playerInfoRequestList.end()) { if (find(m_playerInfoRequestList.begin(), m_playerInfoRequestList.end(), id) == m_playerInfoRequestList.end()) {
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_playerInfoRequestMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_PlayerInfoRequestMessage);
PlayerInfoRequestMessage_t *netPlayerInfo = &packet->GetMsg()->choice.playerInfoRequestMessage; PlayerInfoRequestMessage *netPlayerInfo = packet->GetMsg()->mutable_playerinforequestmessage();
netPlayerInfo->playerId = id; netPlayerInfo->set_playerid(id);
GetSender().Send(GetContext().GetSessionData(), packet); GetSender().Send(GetContext().GetSessionData(), packet);
m_playerInfoRequestList.push_back(id); m_playerInfoRequestList.push_back(id);
@@ -789,13 +754,11 @@ ClientThread::RetrieveAvatarIfNeeded(unsigned id, const PlayerInfo &info)
m_avatarDownloader->QueueDownload( m_avatarDownloader->QueueDownload(
id, avatarServerAddress + serverFileName, GetContext().GetCacheDir() + TEMP_AVATAR_FILENAME); id, avatarServerAddress + serverFileName, GetContext().GetCacheDir() + TEMP_AVATAR_FILENAME);
} else { } else {
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_avatarRequestMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_AvatarRequestMessage);
AvatarRequestMessage_t *netAvatar = &packet->GetMsg()->choice.avatarRequestMessage; AvatarRequestMessage *netAvatar = packet->GetMsg()->mutable_avatarrequestmessage();
netAvatar->requestId = id; netAvatar->set_requestid(id);
OCTET_STRING_fromBuf(&netAvatar->avatar, netAvatar->set_avatarhash(info.avatar.GetData(), MD5_DATA_SIZE);
(const char *)info.avatar.GetData(),
MD5_DATA_SIZE);
GetSender().Send(GetContext().GetSessionData(), packet); GetSender().Send(GetContext().GetSessionData(), packet);
} }
} }
@@ -894,10 +857,10 @@ ClientThread::UnsubscribeLobbyMsg()
{ {
if (GetContext().GetSubscribeLobbyMsg()) { if (GetContext().GetSubscribeLobbyMsg()) {
// Send unsubscribe request. // Send unsubscribe request.
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_subscriptionRequestMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_SubscriptionRequestMessage);
SubscriptionRequestMessage_t *netRequest = &packet->GetMsg()->choice.subscriptionRequestMessage; SubscriptionRequestMessage *netRequest = packet->GetMsg()->mutable_subscriptionrequestmessage();
netRequest->subscriptionAction = subscriptionAction_unsubscribeGameList; netRequest->set_subscriptionaction(SubscriptionRequestMessage::unsubscribeGameList);
GetSender().Send(GetContext().GetSessionData(), packet); GetSender().Send(GetContext().GetSessionData(), packet);
GetContext().SetSubscribeLobbyMsg(false); GetContext().SetSubscribeLobbyMsg(false);
} }
@@ -910,10 +873,10 @@ ClientThread::ResubscribeLobbyMsg()
// Clear game info map as it is outdated. // Clear game info map as it is outdated.
ClearGameInfoMap(); ClearGameInfoMap();
// Send resubscribe request. // Send resubscribe request.
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_subscriptionRequestMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_SubscriptionRequestMessage);
SubscriptionRequestMessage_t *netRequest = &packet->GetMsg()->choice.subscriptionRequestMessage; SubscriptionRequestMessage *netRequest = packet->GetMsg()->mutable_subscriptionrequestmessage();
netRequest->subscriptionAction = subscriptionAction_resubscribeGameList; netRequest->set_subscriptionaction(SubscriptionRequestMessage::resubscribeGameList);
GetSender().Send(GetContext().GetSessionData(), packet); GetSender().Send(GetContext().GetSessionData(), packet);
GetContext().SetSubscribeLobbyMsg(true); GetContext().SetSubscribeLobbyMsg(true);
} }
+90 -123
View File
@@ -1,6 +1,6 @@
/***************************************************************************** /*****************************************************************************
* PokerTH - The open source texas holdem engine * * PokerTH - The open source texas holdem engine *
* Copyright (C) 2006-2011 Felix Hammer, Florian Thauer, Lothar May * * Copyright (C) 2006-2012 Felix Hammer, Florian Thauer, Lothar May *
* * * *
* This program is free software: you can redistribute it and/or modify * * This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as * * it under the terms of the GNU Affero General Public License as *
@@ -19,42 +19,37 @@
#include <net/netpacket.h> #include <net/netpacket.h>
#include <net/socket_msg.h> #include <net/socket_msg.h>
#include <boost/foreach.hpp>
using namespace std; using namespace std;
NetPacket::NetPacket(MemAllocType alloc) NetPacket::NetPacket()
: m_msg(NULL) {
m_msg = PokerTHMessage::default_instance().New();
}
NetPacket::NetPacket(PokerTHMessage *msg)
: m_msg(msg)
{ {
if (alloc != NoAlloc)
m_msg = (PokerTHMessage_t *)calloc(1, sizeof(PokerTHMessage_t));
} }
NetPacket::~NetPacket() NetPacket::~NetPacket()
{ {
ASN_STRUCT_FREE(asn_DEF_PokerTHMessage, m_msg); delete m_msg;
} }
boost::shared_ptr<NetPacket> boost::shared_ptr<NetPacket>
NetPacket::Create(char *data, size_t &dataSize) NetPacket::Create(char *data, size_t dataSize)
{ {
boost::shared_ptr<NetPacket> tmpPacket; boost::shared_ptr<NetPacket> tmpPacket;
// Check minimum requirements. // Check minimum requirements.
if (data && dataSize > 0) { if (data && dataSize > 0) {
PokerTHMessage_t *msg = NULL; PokerTHMessage *msg = PokerTHMessage::default_instance().New();
asn_dec_rval_t retVal = ber_decode(0, &asn_DEF_PokerTHMessage, (void **)&msg, data, dataSize); if (msg->ParseFromArray(data, static_cast<int>(dataSize))) {
if(retVal.code == RC_OK) { tmpPacket.reset(new NetPacket(msg));
// ASN.1 BER decoding was successful.
tmpPacket.reset(new NetPacket(NoAlloc));
tmpPacket->m_msg = msg;
// Consume the bytes.
if (retVal.consumed < dataSize) {
dataSize -= retVal.consumed;
memmove(data, data + retVal.consumed, dataSize);
} else
dataSize = 0;
} else { } else {
// Free the partially decoded message (if applicable). delete msg;
ASN_STRUCT_FREE(asn_DEF_PokerTHMessage, msg);
} }
} }
return tmpPacket; return tmpPacket;
@@ -65,151 +60,123 @@ NetPacket::IsClientActivity() const
{ {
bool retVal = false; bool retVal = false;
if (m_msg && if (m_msg &&
(m_msg->present == PokerTHMessage_PR_initMessage (m_msg->messagetype() == PokerTHMessage::Type_InitMessage
|| m_msg->present == PokerTHMessage_PR_joinGameRequestMessage || m_msg->messagetype() == PokerTHMessage::Type_JoinNewGameMessage
|| m_msg->present == PokerTHMessage_PR_kickPlayerRequestMessage || m_msg->messagetype() == PokerTHMessage::Type_JoinExistingGameMessage
|| m_msg->present == PokerTHMessage_PR_leaveGameRequestMessage || m_msg->messagetype() == PokerTHMessage::Type_RejoinExistingGameMessage
|| m_msg->present == PokerTHMessage_PR_startEventMessage || m_msg->messagetype() == PokerTHMessage::Type_KickPlayerRequestMessage
|| m_msg->present == PokerTHMessage_PR_myActionRequestMessage || m_msg->messagetype() == PokerTHMessage::Type_LeaveGameRequestMessage
|| m_msg->present == PokerTHMessage_PR_resetTimeoutMessage || m_msg->messagetype() == PokerTHMessage::Type_StartEventMessage
|| m_msg->present == PokerTHMessage_PR_chatRequestMessage)) { || m_msg->messagetype() == PokerTHMessage::Type_MyActionRequestMessage
|| m_msg->messagetype() == PokerTHMessage::Type_ResetTimeoutMessage
|| m_msg->messagetype() == PokerTHMessage::Type_ChatRequestMessage)) {
retVal = true; retVal = true;
} }
return retVal; return retVal;
} }
static int
net_packet_print_to_string(const void *buffer, size_t size, void *packetStr)
{
string *tmpString = (string *)packetStr;
*tmpString += string((const char *)buffer, size);
return 0;
}
string string
NetPacket::ToString() const NetPacket::ToString() const
{ {
string packetString; return m_msg ? m_msg->SerializeAsString() : "NULL";
xer_encode(&asn_DEF_PokerTHMessage, m_msg, XER_F_BASIC, &net_packet_print_to_string, &packetString);
return packetString;
} }
void void
NetPacket::SetGameData(const GameData &inData, NetGameInfo_t *outData) NetPacket::SetGameData(const GameData &inData, NetGameInfo &outData)
{ {
assert(outData); outData.set_netgametype(static_cast<NetGameInfo::NetGameType>(inData.gameType));
outData.set_maxnumplayers(inData.maxNumberOfPlayers);
int numManualBlinds = (int)inData.manualBlindsList.size(); outData.set_raiseintervalmode(static_cast<NetGameInfo::RaiseIntervalMode>(inData.raiseIntervalMode));
outData->netGameType = inData.gameType;
outData->maxNumPlayers = inData.maxNumberOfPlayers;
outData->raiseIntervalMode.present = static_cast<raiseIntervalMode_PR>(inData.raiseIntervalMode);
if (inData.raiseIntervalMode == RAISE_ON_HANDNUMBER) { if (inData.raiseIntervalMode == RAISE_ON_HANDNUMBER) {
outData->raiseIntervalMode.present = raiseIntervalMode_PR_raiseEveryHands; outData.set_raiseeveryhands(inData.raiseSmallBlindEveryHandsValue);
outData->raiseIntervalMode.choice.raiseEveryHands = inData.raiseSmallBlindEveryHandsValue;
} else { } else {
outData->raiseIntervalMode.present = raiseIntervalMode_PR_raiseEveryMinutes; outData.set_raiseeveryminutes(inData.raiseSmallBlindEveryMinutesValue);
outData->raiseIntervalMode.choice.raiseEveryMinutes = inData.raiseSmallBlindEveryMinutesValue;
} }
outData->endRaiseMode = inData.afterManualBlindsMode; outData.set_endraisemode(static_cast<NetGameInfo::EndRaiseMode>(inData.afterManualBlindsMode));
outData->proposedGuiSpeed = inData.guiSpeed; outData.set_proposedguispeed(inData.guiSpeed);
outData->delayBetweenHands = inData.delayBetweenHandsSec; outData.set_delaybetweenhands(inData.delayBetweenHandsSec);
outData->playerActionTimeout = inData.playerActionTimeoutSec; outData.set_playeractiontimeout(inData.playerActionTimeoutSec);
outData->endRaiseSmallBlindValue = inData.afterMBAlwaysRaiseValue; outData.set_endraisesmallblindvalue(inData.afterMBAlwaysRaiseValue);
outData->firstSmallBlind = inData.firstSmallBlind; outData.set_firstsmallblind(inData.firstSmallBlind);
outData->startMoney = inData.startMoney; outData.set_startmoney(inData.startMoney);
if (numManualBlinds) { BOOST_FOREACH(int manualBlind, inData.manualBlindsList) {
list<int>::const_iterator i = inData.manualBlindsList.begin(); outData.add_manualblinds(manualBlind);
list<int>::const_iterator end = inData.manualBlindsList.end();
while (i != end) {
long *manualBlind = (long *)calloc(1, sizeof(long));
*manualBlind = *i;
ASN_SEQUENCE_ADD(&outData->manualBlinds.list, manualBlind);
++i;
}
} }
} }
void void
NetPacket::GetGameData(const NetGameInfo_t *inData, GameData &outData) NetPacket::GetGameData(const NetGameInfo &inData, GameData &outData)
{ {
assert(inData); int numManualBlinds = inData.manualblinds_size();
int numManualBlinds = (int)inData->manualBlinds.list.count; outData.gameType = static_cast<GameType>(inData.netgametype());
outData.maxNumberOfPlayers = inData.maxnumplayers();
outData.gameType = static_cast<GameType>(inData->netGameType); outData.raiseIntervalMode = static_cast<RaiseIntervalMode>(inData.raiseintervalmode());
outData.maxNumberOfPlayers = inData->maxNumPlayers;
outData.raiseIntervalMode = static_cast<RaiseIntervalMode>(inData->raiseIntervalMode.present);
outData.raiseSmallBlindEveryHandsValue = outData.raiseSmallBlindEveryMinutesValue = 0; outData.raiseSmallBlindEveryHandsValue = outData.raiseSmallBlindEveryMinutesValue = 0;
if (inData->raiseIntervalMode.present == raiseIntervalMode_PR_raiseEveryHands) if (outData.raiseIntervalMode == RAISE_ON_HANDNUMBER)
outData.raiseSmallBlindEveryHandsValue = inData->raiseIntervalMode.choice.raiseEveryHands; outData.raiseSmallBlindEveryHandsValue = inData.raiseeveryhands();
else else
outData.raiseSmallBlindEveryMinutesValue = inData->raiseIntervalMode.choice.raiseEveryMinutes; outData.raiseSmallBlindEveryMinutesValue = inData.raiseeveryminutes();
outData.raiseMode = numManualBlinds > 0 ? MANUAL_BLINDS_ORDER : DOUBLE_BLINDS; outData.raiseMode = numManualBlinds > 0 ? MANUAL_BLINDS_ORDER : DOUBLE_BLINDS;
outData.afterManualBlindsMode = static_cast<AfterManualBlindsMode>(inData->endRaiseMode); outData.afterManualBlindsMode = static_cast<AfterManualBlindsMode>(inData.endraisemode());
outData.guiSpeed = inData->proposedGuiSpeed; outData.guiSpeed = inData.proposedguispeed();
outData.delayBetweenHandsSec = inData->delayBetweenHands; outData.delayBetweenHandsSec = inData.delaybetweenhands();
outData.playerActionTimeoutSec = inData->playerActionTimeout; outData.playerActionTimeoutSec = inData.playeractiontimeout();
outData.firstSmallBlind = inData->firstSmallBlind; outData.firstSmallBlind = inData.firstsmallblind();
outData.afterMBAlwaysRaiseValue = inData->endRaiseSmallBlindValue; outData.afterMBAlwaysRaiseValue = inData.endraisesmallblindvalue();
outData.startMoney = inData->startMoney; outData.startMoney = inData.startmoney();
if (numManualBlinds) {
long **manualBlindsPtr = inData->manualBlinds.list.array;
int counter = 0;
for (int i = 0; i < numManualBlinds; i++) { for (int i = 0; i < numManualBlinds; i++) {
outData.manualBlindsList.push_back((int)*manualBlindsPtr[i]); outData.manualBlindsList.push_back(static_cast<int>(inData.manualblinds(i)));
counter++;
}
} }
} }
int int
NetPacket::NetErrorToGameError(long netErrorReason) NetPacket::NetErrorToGameError(ErrorMessage::ErrorReason netErrorReason)
{ {
int retVal; int retVal;
switch(netErrorReason) { switch(netErrorReason) {
case errorReason_errorInitVersionNotSupported : case ErrorMessage::initVersionNotSupported :
retVal = ERR_NET_VERSION_NOT_SUPPORTED; retVal = ERR_NET_VERSION_NOT_SUPPORTED;
break; break;
case errorReason_errorInitServerFull : case ErrorMessage::initServerFull :
retVal = ERR_NET_SERVER_FULL; retVal = ERR_NET_SERVER_FULL;
break; break;
case errorReason_errorInitAuthFailure : case ErrorMessage::initAuthFailure :
retVal = ERR_NET_INVALID_PASSWORD; retVal = ERR_NET_INVALID_PASSWORD;
break; break;
case errorReason_errorInitPlayerNameInUse : case ErrorMessage::initPlayerNameInUse :
retVal = ERR_NET_PLAYER_NAME_IN_USE; retVal = ERR_NET_PLAYER_NAME_IN_USE;
break; break;
case errorReason_errorInitInvalidPlayerName : case ErrorMessage::initInvalidPlayerName :
retVal = ERR_NET_INVALID_PLAYER_NAME; retVal = ERR_NET_INVALID_PLAYER_NAME;
break; break;
case errorReason_errorInitServerMaintenance : case ErrorMessage::initServerMaintenance :
retVal = ERR_NET_SERVER_MAINTENANCE; retVal = ERR_NET_SERVER_MAINTENANCE;
break; break;
case errorReason_errorInitBlocked : case ErrorMessage::initBlocked :
retVal = ERR_NET_INIT_BLOCKED; retVal = ERR_NET_INIT_BLOCKED;
break; break;
case errorReason_errorAvatarTooLarge : case ErrorMessage::avatarTooLarge :
retVal = ERR_NET_AVATAR_TOO_LARGE; retVal = ERR_NET_AVATAR_TOO_LARGE;
break; break;
case errorReason_errorInvalidPacket : case ErrorMessage::invalidPacket :
retVal = ERR_SOCK_INVALID_PACKET; retVal = ERR_SOCK_INVALID_PACKET;
break; break;
case errorReason_errorInvalidState : case ErrorMessage::invalidState :
retVal = ERR_SOCK_INVALID_STATE; retVal = ERR_SOCK_INVALID_STATE;
break; break;
case errorReason_errorKickedFromServer : case ErrorMessage::kickedFromServer :
retVal = ERR_NET_PLAYER_KICKED; retVal = ERR_NET_PLAYER_KICKED;
break; break;
case errorReason_errorBannedFromServer : case ErrorMessage::bannedFromServer :
retVal = ERR_NET_PLAYER_BANNED; retVal = ERR_NET_PLAYER_BANNED;
break; break;
case errorReason_errorBlockedByServer : case ErrorMessage::blockedByServer :
retVal = ERR_NET_PLAYER_BLOCKED; retVal = ERR_NET_PLAYER_BLOCKED;
break; break;
case errorReason_errorSessionTimeout : case ErrorMessage::sessionTimeout :
retVal = ERR_NET_SESSION_TIMED_OUT; retVal = ERR_NET_SESSION_TIMED_OUT;
break; break;
default : default :
@@ -219,55 +186,55 @@ NetPacket::NetErrorToGameError(long netErrorReason)
return retVal; return retVal;
} }
long ErrorMessage::ErrorReason
NetPacket::GameErrorToNetError(int gameErrorReason) NetPacket::GameErrorToNetError(int gameErrorReason)
{ {
int retVal; ErrorMessage::ErrorReason retVal;
switch(gameErrorReason) { switch(gameErrorReason) {
case ERR_NET_VERSION_NOT_SUPPORTED : case ERR_NET_VERSION_NOT_SUPPORTED :
retVal = errorReason_errorInitVersionNotSupported; retVal = ErrorMessage::initVersionNotSupported;
break; break;
case ERR_NET_SERVER_FULL : case ERR_NET_SERVER_FULL :
retVal = errorReason_errorInitServerFull; retVal = ErrorMessage::initServerFull;
break; break;
case ERR_NET_INVALID_PASSWORD : case ERR_NET_INVALID_PASSWORD :
retVal = errorReason_errorInitAuthFailure; retVal = ErrorMessage::initAuthFailure;
break; break;
case ERR_NET_PLAYER_NAME_IN_USE : case ERR_NET_PLAYER_NAME_IN_USE :
retVal = errorReason_errorInitPlayerNameInUse; retVal = ErrorMessage::initPlayerNameInUse;
break; break;
case ERR_NET_INVALID_PLAYER_NAME : case ERR_NET_INVALID_PLAYER_NAME :
retVal = errorReason_errorInitInvalidPlayerName; retVal = ErrorMessage::initInvalidPlayerName;
break; break;
case ERR_NET_SERVER_MAINTENANCE : case ERR_NET_SERVER_MAINTENANCE :
retVal = errorReason_errorInitServerMaintenance; retVal = ErrorMessage::initServerMaintenance;
break; break;
case ERR_NET_INIT_BLOCKED : case ERR_NET_INIT_BLOCKED :
retVal = errorReason_errorInitBlocked; retVal = ErrorMessage::initBlocked;
break; break;
case ERR_NET_AVATAR_TOO_LARGE : case ERR_NET_AVATAR_TOO_LARGE :
retVal = errorReason_errorAvatarTooLarge; retVal = ErrorMessage::avatarTooLarge;
break; break;
case ERR_SOCK_INVALID_PACKET : case ERR_SOCK_INVALID_PACKET :
retVal = errorReason_errorInvalidPacket; retVal = ErrorMessage::invalidPacket;
break; break;
case ERR_SOCK_INVALID_STATE : case ERR_SOCK_INVALID_STATE :
retVal = errorReason_errorInvalidState; retVal = ErrorMessage::invalidState;
break; break;
case ERR_NET_PLAYER_KICKED : case ERR_NET_PLAYER_KICKED :
retVal = errorReason_errorKickedFromServer; retVal = ErrorMessage::kickedFromServer;
break; break;
case ERR_NET_PLAYER_BLOCKED : case ERR_NET_PLAYER_BLOCKED :
retVal = errorReason_errorBlockedByServer; retVal = ErrorMessage::blockedByServer;
break; break;
case ERR_NET_PLAYER_BANNED : case ERR_NET_PLAYER_BANNED :
retVal = errorReason_errorBannedFromServer; retVal = ErrorMessage::bannedFromServer;
break; break;
case ERR_NET_SESSION_TIMED_OUT : case ERR_NET_SESSION_TIMED_OUT :
retVal = errorReason_errorSessionTimeout; retVal = ErrorMessage::sessionTimeout;
break; break;
default : default :
retVal = errorReason_errorReserved; retVal = ErrorMessage::reserved;
break; break;
} }
return retVal; return retVal;
+14 -8
View File
@@ -80,23 +80,29 @@ ReceiveBuffer::ScanPackets()
// This is necessary, because we use TCP. // This is necessary, because we use TCP.
// Packets may be received in multiple chunks or // Packets may be received in multiple chunks or
// several packets may be received at once. // several packets may be received at once.
if (recvBufUsed) { if (recvBufUsed >= NET_HEADER_SIZE) {
// Read the size of the packet (first 4 bytes in network byte order).
size_t packetSize = ntohl(*((uint32_t *)recvBuf));
if (recvBufUsed >= packetSize + NET_HEADER_SIZE)
{
try { try {
// This call will also handle the memmove stuff, i.e. tmpPacket = NetPacket::Create(&recvBuf[NET_HEADER_SIZE], packetSize);
// buffering for partial packets. if (tmpPacket) {
tmpPacket = NetPacket::Create(recvBuf, recvBufUsed); recvBufUsed -= (packetSize + NET_HEADER_SIZE);
if (recvBufUsed) {
memmove(recvBuf, recvBuf + packetSize + NET_HEADER_SIZE, recvBufUsed);
}
}
} catch (const exception &e) { } catch (const exception &e) {
// Reset buffer on error. // Reset buffer on error.
recvBufUsed = 0; recvBufUsed = 0;
LOG_ERROR(e.what()); LOG_ERROR(e.what());
} }
} }
}
if (tmpPacket) { if (tmpPacket) {
//cerr << "IN:" << endl << tmpPacket->ToString() << endl; // TODO check constraints.
if (asn_check_constraints(&asn_DEF_PokerTHMessage, tmpPacket->GetMsg(), NULL, NULL) == 0)
receivedPackets.push_back(tmpPacket); receivedPackets.push_back(tmpPacket);
else
LOG_ERROR("Invalid packet: " << endl << tmpPacket->ToString());
} else } else
dataAvailable = false; dataAvailable = false;
} while(dataAvailable); } while(dataAvailable);
+5 -4
View File
@@ -83,9 +83,10 @@ SenderHelper::SetCloseAfterSend(boost::shared_ptr<SessionData> session)
void void
SenderHelper::InternalStorePacket(SendBuffer &tmpBuffer, boost::shared_ptr<NetPacket> packet) SenderHelper::InternalStorePacket(SendBuffer &tmpBuffer, boost::shared_ptr<NetPacket> packet)
{ {
asn_enc_rval_t e = der_encode(&asn_DEF_PokerTHMessage, packet->GetMsg(), &SendBuffer::EncodeToBuf, &tmpBuffer); uint32_t packetSize = packet->GetMsg()->ByteSize();
//cerr << "OUT:" << endl << packet->ToString() << endl; char *buf = new char[packetSize + NET_HEADER_SIZE];
if (e.encoded == -1) *((uint32_t *)buf) = htonl(packetSize);
LOG_ERROR("Failed to encode NetPacket: " << packet->GetMsg()->present); packet->GetMsg()->SerializeToArray(&buf[NET_HEADER_SIZE], packetSize);
SendBuffer::EncodeToBuf(buf, packetSize + NET_HEADER_SIZE, &tmpBuffer);
} }
+58 -60
View File
@@ -225,15 +225,15 @@ ServerGame::TimerVoteKick(const boost::system::error_code &ec)
abortPetition = true; abortPetition = true;
} }
if (abortPetition) { if (abortPetition) {
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_endKickPetitionMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_EndKickPetitionMessage);
EndKickPetitionMessage_t *netEndPetition = &packet->GetMsg()->choice.endKickPetitionMessage; EndKickPetitionMessage *netEndPetition = packet->GetMsg()->mutable_endkickpetitionmessage();
netEndPetition->gameId = GetId(); netEndPetition->set_gameid(GetId());
netEndPetition->petitionId = m_voteKickData->petitionId; netEndPetition->set_petitionid(m_voteKickData->petitionId);
netEndPetition->numVotesAgainstKicking = m_voteKickData->numVotesAgainstKicking; netEndPetition->set_numvotesagainstkicking(m_voteKickData->numVotesAgainstKicking);
netEndPetition->numVotesInFavourOfKicking = m_voteKickData->numVotesInFavourOfKicking; netEndPetition->set_numvotesinfavourofkicking(m_voteKickData->numVotesInFavourOfKicking);
netEndPetition->resultPlayerKicked = doKick; netEndPetition->set_resultplayerkicked(doKick);
netEndPetition->petitionEndReason = reason; netEndPetition->set_petitionendreason(static_cast<EndKickPetitionMessage::PetitionEndReason>(reason));
SendToAllPlayers(packet, SessionData::Game); SendToAllPlayers(packet, SessionData::Game);
// Perform kick. // Perform kick.
@@ -469,15 +469,15 @@ ServerGame::InternalAskVoteKick(boost::shared_ptr<SessionData> byWhom, unsigned
m_voteKickData->numVotesInFavourOfKicking = 1; m_voteKickData->numVotesInFavourOfKicking = 1;
m_voteKickData->votedPlayerIds.push_back(playerIdByWhom); m_voteKickData->votedPlayerIds.push_back(playerIdByWhom);
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_startKickPetitionMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_StartKickPetitionMessage);
StartKickPetitionMessage_t *netStartPetition = &packet->GetMsg()->choice.startKickPetitionMessage; StartKickPetitionMessage *netStartPetition = packet->GetMsg()->mutable_startkickpetitionmessage();
netStartPetition->gameId = GetId(); netStartPetition->set_gameid(GetId());
netStartPetition->petitionId = m_voteKickData->petitionId; netStartPetition->set_petitionid(m_voteKickData->petitionId);
netStartPetition->proposingPlayerId = playerIdByWhom; netStartPetition->set_proposingplayerid(playerIdByWhom);
netStartPetition->kickPlayerId = m_voteKickData->kickPlayerId; netStartPetition->set_kickplayerid(m_voteKickData->kickPlayerId);
netStartPetition->kickTimeoutSec = timeoutSec; netStartPetition->set_kicktimeoutsec(timeoutSec);
netStartPetition->numVotesNeededToKick = m_voteKickData->numVotesToKick; netStartPetition->set_numvotesneededtokick(m_voteKickData->numVotesToKick);
SendToAllPlayers(packet, SessionData::Game); SendToAllPlayers(packet, SessionData::Game);
m_voteKickTimer.expires_from_now( m_voteKickTimer.expires_from_now(
@@ -499,12 +499,12 @@ ServerGame::InternalAskVoteKick(boost::shared_ptr<SessionData> byWhom, unsigned
void void
ServerGame::InternalDenyAskVoteKick(boost::shared_ptr<SessionData> byWhom, unsigned playerIdWho, DenyKickPlayerReason reason) ServerGame::InternalDenyAskVoteKick(boost::shared_ptr<SessionData> byWhom, unsigned playerIdWho, DenyKickPlayerReason reason)
{ {
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_askKickDeniedMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_AskKickDeniedMessage);
AskKickDeniedMessage_t *netKickDenied = &packet->GetMsg()->choice.askKickDeniedMessage; AskKickDeniedMessage *netKickDenied = packet->GetMsg()->mutable_askkickdeniedmessage();
netKickDenied->gameId = GetId(); netKickDenied->set_gameid(GetId());
netKickDenied->playerId = playerIdWho; netKickDenied->set_playerid(playerIdWho);
netKickDenied->kickDeniedReason = reason; netKickDenied->set_kickdeniedreason(static_cast<AskKickDeniedMessage::KickDeniedReason>(reason));
GetLobbyThread().GetSender().Send(byWhom, packet); GetLobbyThread().GetSender().Send(byWhom, packet);
} }
@@ -523,14 +523,14 @@ ServerGame::InternalVoteKick(boost::shared_ptr<SessionData> byWhom, unsigned pet
else else
m_voteKickData->numVotesAgainstKicking++; m_voteKickData->numVotesAgainstKicking++;
// Send update notification. // Send update notification.
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_kickPetitionUpdateMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_KickPetitionUpdateMessage);
KickPetitionUpdateMessage_t *netKickUpdate = &packet->GetMsg()->choice.kickPetitionUpdateMessage; KickPetitionUpdateMessage *netKickUpdate = packet->GetMsg()->mutable_kickpetitionupdatemessage();
netKickUpdate->gameId = GetId(); netKickUpdate->set_gameid(GetId());
netKickUpdate->petitionId = m_voteKickData->petitionId; netKickUpdate->set_petitionid(m_voteKickData->petitionId);
netKickUpdate->numVotesAgainstKicking = m_voteKickData->numVotesAgainstKicking; netKickUpdate->set_numvotesagainstkicking(m_voteKickData->numVotesAgainstKicking);
netKickUpdate->numVotesInFavourOfKicking = m_voteKickData->numVotesInFavourOfKicking; netKickUpdate->set_numvotesinfavourofkicking(m_voteKickData->numVotesInFavourOfKicking);
netKickUpdate->numVotesNeededToKick = m_voteKickData->numVotesToKick; netKickUpdate->set_numvotesneededtokick(m_voteKickData->numVotesToKick);
SendToAllPlayers(packet, SessionData::Game); SendToAllPlayers(packet, SessionData::Game);
} else } else
InternalDenyVoteKick(byWhom, petitionId, VOTE_DENIED_ALREADY_VOTED); InternalDenyVoteKick(byWhom, petitionId, VOTE_DENIED_ALREADY_VOTED);
@@ -543,15 +543,19 @@ ServerGame::InternalVoteKick(boost::shared_ptr<SessionData> byWhom, unsigned pet
void void
ServerGame::InternalDenyVoteKick(boost::shared_ptr<SessionData> byWhom, unsigned petitionId, DenyVoteReason reason) ServerGame::InternalDenyVoteKick(boost::shared_ptr<SessionData> byWhom, unsigned petitionId, DenyVoteReason reason)
{ {
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_voteKickReplyMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_VoteKickReplyMessage);
VoteKickReplyMessage_t *netVoteReply = &packet->GetMsg()->choice.voteKickReplyMessage; VoteKickReplyMessage *netVoteReply = packet->GetMsg()->mutable_votekickreplymessage();
netVoteReply->gameId = GetId(); netVoteReply->set_gameid(GetId());
netVoteReply->petitionId = petitionId; netVoteReply->set_petitionid(petitionId);
netVoteReply->voteKickReplyType.present = voteKickReplyType_PR_voteKickDenied; switch(reason) {
case VOTE_DENIED_ALREADY_VOTED :
VoteKickDenied_t *kickDenied = &netVoteReply->voteKickReplyType.choice.voteKickDenied; netVoteReply->set_votekickreplytype(VoteKickReplyMessage::voteKickDeniedAlreadyVoted);
kickDenied->voteKickDeniedReason = reason; break;
default:
netVoteReply->set_votekickreplytype(VoteKickReplyMessage::voteKickDeniedInvalid);
break;
}
GetLobbyThread().GetSender().Send(byWhom, packet); GetLobbyThread().GetSender().Send(byWhom, packet);
} }
@@ -827,14 +831,11 @@ ServerGame::RemovePlayerData(boost::shared_ptr<PlayerData> player, int reason)
// Notify game state on admin change // Notify game state on admin change
GetState().NotifyGameAdminChanged(shared_from_this()); GetState().NotifyGameAdminChanged(shared_from_this());
// Send "Game Admin Changed" to clients. // Send "Game Admin Changed" to clients.
boost::shared_ptr<NetPacket> adminChanged(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> adminChanged(new NetPacket);
adminChanged->GetMsg()->present = PokerTHMessage_PR_gamePlayerMessage; adminChanged->GetMsg()->set_messagetype(PokerTHMessage::Type_GameAdminChangedMessage);
GamePlayerMessage_t *netGameAdmin = &adminChanged->GetMsg()->choice.gamePlayerMessage; GameAdminChangedMessage *netGameAdmin = adminChanged->GetMsg()->mutable_gameadminchangedmessage();
netGameAdmin->gameId = GetId(); netGameAdmin->set_gameid(GetId());
netGameAdmin->set_newadminplayerid(newAdmin->GetUniqueId()); // Choose next player as admin.
netGameAdmin->gamePlayerNotification.present = gamePlayerNotification_PR_gameAdminChanged;
GameAdminChanged_t *gameAdmin = &netGameAdmin->gamePlayerNotification.choice.gameAdminChanged;
gameAdmin->newAdminPlayerId = newAdmin->GetUniqueId(); // Choose next player as admin.
GetSessionManager().SendToAllSessions(GetLobbyThread().GetSender(), adminChanged, SessionData::Game); GetSessionManager().SendToAllSessions(GetLobbyThread().GetSender(), adminChanged, SessionData::Game);
GetLobbyThread().NotifyGameAdminChanged(GetId(), newAdmin->GetUniqueId()); GetLobbyThread().NotifyGameAdminChanged(GetId(), newAdmin->GetUniqueId());
@@ -844,23 +845,20 @@ ServerGame::RemovePlayerData(boost::shared_ptr<PlayerData> player, int reason)
player->SetGameAdmin(false); player->SetGameAdmin(false);
// Send "Player Left" to clients. // Send "Player Left" to clients.
boost::shared_ptr<NetPacket> thisPlayerLeft(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> thisPlayerLeft(new NetPacket);
thisPlayerLeft->GetMsg()->present = PokerTHMessage_PR_gamePlayerMessage; thisPlayerLeft->GetMsg()->set_messagetype(PokerTHMessage::Type_GamePlayerLeftMessage);
GamePlayerMessage_t *netPlayerLeft = &thisPlayerLeft->GetMsg()->choice.gamePlayerMessage; GamePlayerLeftMessage *netPlayerLeft = thisPlayerLeft->GetMsg()->mutable_gameplayerleftmessage();
netPlayerLeft->gameId = GetId(); netPlayerLeft->set_gameid(GetId());
netPlayerLeft->set_playerid(player->GetUniqueId());
netPlayerLeft->gamePlayerNotification.present = gamePlayerNotification_PR_gamePlayerLeft;
GamePlayerLeft_t *gamePlayer = &netPlayerLeft->gamePlayerNotification.choice.gamePlayerLeft;
gamePlayer->playerId = player->GetUniqueId();
switch (reason) { switch (reason) {
case NTF_NET_REMOVED_ON_REQUEST : case NTF_NET_REMOVED_ON_REQUEST :
gamePlayer->gamePlayerLeftReason = gamePlayerLeftReason_leftOnRequest; netPlayerLeft->set_gameplayerleftreason(GamePlayerLeftMessage::leftOnRequest);
break; break;
case NTF_NET_REMOVED_KICKED : case NTF_NET_REMOVED_KICKED :
gamePlayer->gamePlayerLeftReason = gamePlayerLeftReason_leftKicked; netPlayerLeft->set_gameplayerleftreason(GamePlayerLeftMessage::leftKicked);
break; break;
default : default :
gamePlayer->gamePlayerLeftReason = gamePlayerLeftReason_leftError; netPlayerLeft->set_gameplayerleftreason(GamePlayerLeftMessage::leftError);
break; break;
} }
GetSessionManager().SendToAllSessions(GetLobbyThread().GetSender(), thisPlayerLeft, SessionData::Game); GetSessionManager().SendToAllSessions(GetLobbyThread().GetSender(), thisPlayerLeft, SessionData::Game);
+260 -304
View File
@@ -1,6 +1,6 @@
/***************************************************************************** /*****************************************************************************
* PokerTH - The open source texas holdem engine * * PokerTH - The open source texas holdem engine *
* Copyright (C) 2006-2011 Felix Hammer, Florian Thauer, Lothar May * * Copyright (C) 2006-2012 Felix Hammer, Florian Thauer, Lothar May *
* * * *
* This program is free software: you can redistribute it and/or modify * * This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as * * it under the terms of the GNU Affero General Public License as *
@@ -77,18 +77,18 @@ static void SendPlayerAction(ServerGame &server, boost::shared_ptr<PlayerInterfa
if (!player.get()) if (!player.get())
throw ServerException(__FILE__, __LINE__, ERR_NET_NO_CURRENT_PLAYER, 0); throw ServerException(__FILE__, __LINE__, ERR_NET_NO_CURRENT_PLAYER, 0);
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_playersActionDoneMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_PlayersActionDoneMessage);
PlayersActionDoneMessage_t *netActionDone = &packet->GetMsg()->choice.playersActionDoneMessage; PlayersActionDoneMessage *netActionDone = packet->GetMsg()->mutable_playersactiondonemessage();
netActionDone->gameId = server.GetId(); netActionDone->set_gameid(server.GetId());
netActionDone->gameState = server.GetCurRound(); netActionDone->set_gamestate(static_cast<NetGameState>(server.GetCurRound()));
netActionDone->highestSet = server.GetGame().getCurrentHand()->getCurrentBeRo()->getHighestSet(); netActionDone->set_highestset(server.GetGame().getCurrentHand()->getCurrentBeRo()->getHighestSet());
netActionDone->minimumRaise = server.GetGame().getCurrentHand()->getCurrentBeRo()->getMinimumRaise(); netActionDone->set_minimumraise(server.GetGame().getCurrentHand()->getCurrentBeRo()->getMinimumRaise());
netActionDone->playerAction = player->getMyAction(); netActionDone->set_playeraction(static_cast<NetPlayerAction>(player->getMyAction()));
netActionDone->playerId = player->getMyUniqueID(); netActionDone->set_playerid(player->getMyUniqueID());
netActionDone->playerMoney = player->getMyCash(); netActionDone->set_playermoney(player->getMyCash());
netActionDone->totalPlayerBet = player->getMySet(); netActionDone->set_totalplayerbet(player->getMySet());
server.SendToAllPlayers(packet, SessionData::Game); server.SendToAllPlayers(packet, SessionData::Game);
} }
@@ -102,33 +102,33 @@ static void SendNewRoundCards(ServerGame &server, Game &curGame, int state)
} break; } break;
case GAME_STATE_FLOP: { case GAME_STATE_FLOP: {
// deal flop cards // deal flop cards
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_dealFlopCardsMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_DealFlopCardsMessage);
DealFlopCardsMessage_t *netDealFlop = &packet->GetMsg()->choice.dealFlopCardsMessage; DealFlopCardsMessage *netDealFlop = packet->GetMsg()->mutable_dealflopcardsmessage();
netDealFlop->gameId = server.GetId(); netDealFlop->set_gameid(server.GetId());
netDealFlop->flopCard1 = cards[0]; netDealFlop->set_flopcard1(cards[0]);
netDealFlop->flopCard2 = cards[1]; netDealFlop->set_flopcard2(cards[1]);
netDealFlop->flopCard3 = cards[2]; netDealFlop->set_flopcard3(cards[2]);
server.SendToAllPlayers(packet, SessionData::Game); server.SendToAllPlayers(packet, SessionData::Game);
} }
break; break;
case GAME_STATE_TURN: { case GAME_STATE_TURN: {
// deal turn card // deal turn card
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_dealTurnCardMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_DealTurnCardMessage);
DealTurnCardMessage_t *netDealTurn = &packet->GetMsg()->choice.dealTurnCardMessage; DealTurnCardMessage *netDealTurn = packet->GetMsg()->mutable_dealturncardmessage();
netDealTurn->gameId = server.GetId(); netDealTurn->set_gameid(server.GetId());
netDealTurn->turnCard = cards[3]; netDealTurn->set_turncard(cards[3]);
server.SendToAllPlayers(packet, SessionData::Game); server.SendToAllPlayers(packet, SessionData::Game);
} }
break; break;
case GAME_STATE_RIVER: { case GAME_STATE_RIVER: {
// deal river card // deal river card
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_dealRiverCardMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_DealRiverCardMessage);
DealRiverCardMessage_t *netDealRiver = &packet->GetMsg()->choice.dealRiverCardMessage; DealRiverCardMessage *netDealRiver = packet->GetMsg()->mutable_dealrivercardmessage();
netDealRiver->gameId = server.GetId(); netDealRiver->set_gameid(server.GetId());
netDealRiver->riverCard = cards[4]; netDealRiver->set_rivercard(cards[4]);
server.SendToAllPlayers(packet, SessionData::Game); server.SendToAllPlayers(packet, SessionData::Game);
} }
break; break;
@@ -185,27 +185,24 @@ static void PerformPlayerAction(ServerGame &server, boost::shared_ptr<PlayerInte
} }
static void static void
SetPlayerResult(PlayerResult_t &playerResult, boost::shared_ptr<PlayerInterface> tmpPlayer, GameState roundBeforePostRiver) SetPlayerResult(PlayerResult &playerResult, boost::shared_ptr<PlayerInterface> tmpPlayer, GameState roundBeforePostRiver)
{ {
playerResult.playerId = tmpPlayer->getMyUniqueID(); playerResult.set_playerid(tmpPlayer->getMyUniqueID());
int tmpCards[2]; int tmpCards[2];
int bestHandPos[5]; int bestHandPos[5];
tmpPlayer->getMyCards(tmpCards); tmpPlayer->getMyCards(tmpCards);
playerResult.resultCard1 = tmpCards[0]; playerResult.set_resultcard1(tmpCards[0]);
playerResult.resultCard2 = tmpCards[1]; playerResult.set_resultcard2(tmpCards[1]);
tmpPlayer->getMyBestHandPosition(bestHandPos); tmpPlayer->getMyBestHandPosition(bestHandPos);
for (int num = 0; num < 5; num++) { for (int num = 0; num < 5; num++) {
long *handPos = (long *)calloc(1, sizeof(long)); playerResult.add_besthandposition(bestHandPos[num]);
*handPos = bestHandPos[num];
ASN_SEQUENCE_ADD(&playerResult.bestHandPosition.list, handPos);
} }
if (roundBeforePostRiver == GAME_STATE_RIVER) { if (roundBeforePostRiver == GAME_STATE_RIVER) {
playerResult.cardsValue = (long *)calloc(1, sizeof(long)); playerResult.set_cardsvalue(tmpPlayer->getMyCardsValueInt());
*playerResult.cardsValue = tmpPlayer->getMyCardsValueInt();
} }
playerResult.moneyWon = tmpPlayer->getLastMoneyWon(); playerResult.set_moneywon(tmpPlayer->getLastMoneyWon());
playerResult.playerMoney = tmpPlayer->getMyCash(); playerResult.set_playermoney(tmpPlayer->getMyCash());
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -226,61 +223,56 @@ AbstractServerGameStateReceiving::ProcessPacket(boost::shared_ptr<ServerGame> se
if (packet->IsClientActivity()) { if (packet->IsClientActivity()) {
session->ResetActivityTimer(); session->ResetActivityTimer();
} }
if (packet->GetMsg()->present == PokerTHMessage_PR_playerInfoRequestMessage) { if (packet->GetMsg()->messagetype() == PokerTHMessage::Type_PlayerInfoRequestMessage) {
// Delegate to Lobby. // Delegate to Lobby.
server->GetLobbyThread().HandleGameRetrievePlayerInfo(session, packet->GetMsg()->choice.playerInfoRequestMessage); server->GetLobbyThread().HandleGameRetrievePlayerInfo(session, packet->GetMsg()->playerinforequestmessage());
} else if (packet->GetMsg()->present == PokerTHMessage_PR_avatarRequestMessage) { } else if (packet->GetMsg()->messagetype() == PokerTHMessage::Type_AvatarRequestMessage) {
// Delegate to Lobby. // Delegate to Lobby.
server->GetLobbyThread().HandleGameRetrieveAvatar(session, packet->GetMsg()->choice.avatarRequestMessage); server->GetLobbyThread().HandleGameRetrieveAvatar(session, packet->GetMsg()->avatarrequestmessage());
} else if (packet->GetMsg()->present == PokerTHMessage_PR_leaveGameRequestMessage) { } else if (packet->GetMsg()->messagetype() == PokerTHMessage::Type_LeaveGameRequestMessage) {
server->MoveSessionToLobby(session, NTF_NET_REMOVED_ON_REQUEST); server->MoveSessionToLobby(session, NTF_NET_REMOVED_ON_REQUEST);
} else if (packet->GetMsg()->present == PokerTHMessage_PR_kickPlayerRequestMessage) { } else if (packet->GetMsg()->messagetype() == PokerTHMessage::Type_KickPlayerRequestMessage) {
// Only admins are allowed to kick, and only in the lobby. // Only admins are allowed to kick, and only in the lobby.
// After leaving the lobby, a vote needs to be initiated to kick. // After leaving the lobby, a vote needs to be initiated to kick.
KickPlayerRequestMessage_t *netKickRequest = &packet->GetMsg()->choice.kickPlayerRequestMessage; const KickPlayerRequestMessage &netKickRequest = packet->GetMsg()->kickplayerrequestmessage();
if (session->GetPlayerData()->IsGameAdmin() && !server->IsRunning() if (session->GetPlayerData()->IsGameAdmin() && !server->IsRunning()
&& netKickRequest->gameId == server->GetId() && server->GetGameData().gameType != GAME_TYPE_RANKING) { && netKickRequest.gameid() == server->GetId() && server->GetGameData().gameType != GAME_TYPE_RANKING) {
server->KickPlayer(netKickRequest->playerId); server->KickPlayer(netKickRequest.playerid());
} }
} else if (packet->GetMsg()->present == PokerTHMessage_PR_askKickPlayerMessage) { } else if (packet->GetMsg()->messagetype() == PokerTHMessage::Type_AskKickPlayerMessage) {
if (server->GetGameData().gameType != GAME_TYPE_RANKING) { if (server->GetGameData().gameType != GAME_TYPE_RANKING) {
AskKickPlayerMessage_t *netAskKick = &packet->GetMsg()->choice.askKickPlayerMessage; const AskKickPlayerMessage &netAskKick = packet->GetMsg()->askkickplayermessage();
server->InternalAskVoteKick(session, netAskKick->playerId, SERVER_VOTE_KICK_TIMEOUT_SEC); server->InternalAskVoteKick(session, netAskKick.playerid(), SERVER_VOTE_KICK_TIMEOUT_SEC);
} }
} else if (packet->GetMsg()->present == PokerTHMessage_PR_voteKickRequestMessage) { } else if (packet->GetMsg()->messagetype() == PokerTHMessage::Type_VoteKickRequestMessage) {
VoteKickRequestMessage_t *netVoteKick = &packet->GetMsg()->choice.voteKickRequestMessage; const VoteKickRequestMessage &netVoteKick = packet->GetMsg()->votekickrequestmessage();
server->InternalVoteKick(session, netVoteKick->petitionId, netVoteKick->voteKick ? KICK_VOTE_IN_FAVOUR : KICK_VOTE_AGAINST); server->InternalVoteKick(session, netVoteKick.petitionid(), netVoteKick.votekick() ? KICK_VOTE_IN_FAVOUR : KICK_VOTE_AGAINST);
} }
// Chat text is always allowed. // Chat text is always allowed.
else if (packet->GetMsg()->present == PokerTHMessage_PR_chatRequestMessage) { else if (packet->GetMsg()->messagetype() == PokerTHMessage::Type_ChatRequestMessage) {
bool chatSent = false; bool chatSent = false;
ChatRequestMessage_t *netChatRequest = &packet->GetMsg()->choice.chatRequestMessage; const ChatRequestMessage &netChatRequest = packet->GetMsg()->chatrequestmessage();
// Only forward if this player is known and not a guest. // Only forward if this player is known and not a guest.
if (session->GetPlayerData()->GetRights() != PLAYER_RIGHTS_GUEST) { if (session->GetPlayerData()->GetRights() != PLAYER_RIGHTS_GUEST) {
// Forward chat text to all players. // Forward chat text to all players.
// TODO: Some limitation needed. // TODO: Some limitation needed.
if (netChatRequest->chatRequestType.present == chatRequestType_PR_chatRequestTypeLobby if (!netChatRequest.has_targetgameid()) {
|| netChatRequest->chatRequestType.present == chatRequestType_PR_chatRequestTypePrivate) {
if (!server->IsRunning()) { if (!server->IsRunning()) {
server->GetLobbyThread().HandleChatRequest(session, *netChatRequest); server->GetLobbyThread().HandleChatRequest(session, netChatRequest);
chatSent = true; chatSent = true;
} }
} else if (netChatRequest->chatRequestType.present == chatRequestType_PR_chatRequestTypeGame) { } else {
boost::shared_ptr<PlayerInterface> tmpPlayer (server->GetPlayerInterfaceFromGame(session->GetPlayerData()->GetUniqueId())); boost::shared_ptr<PlayerInterface> tmpPlayer (server->GetPlayerInterfaceFromGame(session->GetPlayerData()->GetUniqueId()));
// If we did not find the player, then the game did not start yet. Allow chat for now. // If we did not find the player, then the game did not start yet. Allow chat for now.
// Otherwise, check whether the player is muted. // Otherwise, check whether the player is muted.
if (!tmpPlayer || !tmpPlayer->isMuted()) { if (!tmpPlayer || !tmpPlayer->isMuted()) {
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_chatMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_ChatMessage);
ChatMessage_t *netChat = &packet->GetMsg()->choice.chatMessage; ChatMessage *netChat = packet->GetMsg()->mutable_chatmessage();
netChat->chatType.present = chatType_PR_chatTypeGame; netChat->set_gameid(server->GetId());
ChatTypeGame_t *netGameChat = &netChat->chatType.choice.chatTypeGame; netChat->set_playerid(session->GetPlayerData()->GetUniqueId());
netGameChat->gameId = server->GetId(); netChat->set_chattype(ChatMessage::chatTypeGame);
netGameChat->playerId = session->GetPlayerData()->GetUniqueId(); netChat->set_chattext(netChatRequest.chattext());
OCTET_STRING_fromBuf(
&netChat->chatText,
(char *)netChatRequest->chatText.buf,
netChatRequest->chatText.size);
server->SendToAllPlayers(packet, SessionData::Game); server->SendToAllPlayers(packet, SessionData::Game);
chatSent = true; chatSent = true;
@@ -291,34 +283,31 @@ AbstractServerGameStateReceiving::ProcessPacket(boost::shared_ptr<ServerGame> se
server->GetId(), server->GetId(),
session->GetPlayerData()->GetUniqueId(), session->GetPlayerData()->GetUniqueId(),
session->GetPlayerData()->GetName(), session->GetPlayerData()->GetName(),
string((char *)netChatRequest->chatText.buf, netChatRequest->chatText.size)); netChatRequest.chattext());
//} //}
} }
} }
} }
// Reject chat otherwise. // Reject chat otherwise.
if (!chatSent) { if (!chatSent) {
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_chatRejectMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_ChatRejectMessage);
ChatRejectMessage_t *netReject = &packet->GetMsg()->choice.chatRejectMessage; ChatRejectMessage *netReject = packet->GetMsg()->mutable_chatrejectmessage();
OCTET_STRING_fromBuf( netReject->set_chattext(netChatRequest.chattext());
&netReject->chatText,
(char *)netChatRequest->chatText.buf,
netChatRequest->chatText.size);
server->GetLobbyThread().GetSender().Send(session, packet); server->GetLobbyThread().GetSender().Send(session, packet);
} }
} else if (packet->GetMsg()->present == PokerTHMessage_PR_subscriptionRequestMessage) { } else if (packet->GetMsg()->messagetype() == PokerTHMessage::Type_SubscriptionRequestMessage) {
SubscriptionRequestMessage_t *netSubscription = &packet->GetMsg()->choice.subscriptionRequestMessage; const SubscriptionRequestMessage &netSubscription = packet->GetMsg()->subscriptionrequestmessage();
if (netSubscription->subscriptionAction == subscriptionAction_resubscribeGameList) { if (netSubscription.subscriptionaction() == SubscriptionRequestMessage::resubscribeGameList) {
if (!session->WantsLobbyMsg()) if (!session->WantsLobbyMsg())
server->GetLobbyThread().ResubscribeLobbyMsg(session); server->GetLobbyThread().ResubscribeLobbyMsg(session);
} else } else
session->ResetWantsLobbyMsg(); session->ResetWantsLobbyMsg();
} else if (packet->GetMsg()->present == PokerTHMessage_PR_reportAvatarMessage) { } else if (packet->GetMsg()->messagetype() == PokerTHMessage::Type_ReportAvatarMessage) {
ReportAvatarMessage_t *netReport = &packet->GetMsg()->choice.reportAvatarMessage; const ReportAvatarMessage &netReport = packet->GetMsg()->reportavatarmessage();
boost::shared_ptr<PlayerData> tmpPlayer = server->GetPlayerDataByUniqueId(netReport->reportedPlayerId); boost::shared_ptr<PlayerData> tmpPlayer = server->GetPlayerDataByUniqueId(netReport.reportedplayerid());
MD5Buf tmpMD5; MD5Buf tmpMD5;
memcpy(tmpMD5.GetData(), netReport->reportedAvatar.buf, MD5_DATA_SIZE); memcpy(tmpMD5.GetData(), netReport.reportedavatarhash().data(), MD5_DATA_SIZE);
if (tmpPlayer && tmpPlayer->GetDBId() && !tmpMD5.IsZero() && tmpPlayer->GetAvatarMD5() == tmpMD5) { if (tmpPlayer && tmpPlayer->GetDBId() && !tmpMD5.IsZero() && tmpPlayer->GetAvatarMD5() == tmpMD5) {
if (!server->IsAvatarReported(tmpPlayer->GetUniqueId())) { if (!server->IsAvatarReported(tmpPlayer->GetUniqueId())) {
// Temporarily note that this avatar was reported. // Temporarily note that this avatar was reported.
@@ -343,25 +332,25 @@ AbstractServerGameStateReceiving::ProcessPacket(boost::shared_ptr<ServerGame> se
myDBid != 0 ? &myDBid : NULL myDBid != 0 ? &myDBid : NULL
); );
} else { } else {
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_reportAvatarAckMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_ReportAvatarAckMessage);
ReportAvatarAckMessage_t *netReportAck = &packet->GetMsg()->choice.reportAvatarAckMessage; ReportAvatarAckMessage *netReportAck = packet->GetMsg()->mutable_reportavatarackmessage();
netReportAck->reportedPlayerId = netReport->reportedPlayerId; netReportAck->set_reportedplayerid(netReport.reportedplayerid());
netReportAck->reportAvatarResult = reportAvatarResult_avatarReportDuplicate; netReportAck->set_reportavatarresult(ReportAvatarAckMessage::avatarReportDuplicate);
server->GetLobbyThread().GetSender().Send(session, packet); server->GetLobbyThread().GetSender().Send(session, packet);
} }
} else { } else {
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_reportAvatarAckMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_ReportAvatarAckMessage);
ReportAvatarAckMessage_t *netReportAck = &packet->GetMsg()->choice.reportAvatarAckMessage; ReportAvatarAckMessage *netReportAck = packet->GetMsg()->mutable_reportavatarackmessage();
netReportAck->reportedPlayerId = netReport->reportedPlayerId; netReportAck->set_reportedplayerid(netReport.reportedplayerid());
netReportAck->reportAvatarResult = reportAvatarResult_avatarReportInvalid; netReportAck->set_reportavatarresult(ReportAvatarAckMessage::avatarReportInvalid);
server->GetLobbyThread().GetSender().Send(session, packet); server->GetLobbyThread().GetSender().Send(session, packet);
} }
} else if (packet->GetMsg()->present == PokerTHMessage_PR_reportGameMessage) { } else if (packet->GetMsg()->messagetype() == PokerTHMessage::Type_ReportGameMessage) {
// Delegate to Lobby. // Delegate to Lobby.
server->GetLobbyThread().HandleGameReportGame(session, packet->GetMsg()->choice.reportGameMessage); server->GetLobbyThread().HandleGameReportGame(session, packet->GetMsg()->reportgamemessage());
} else if (packet->GetMsg()->present == PokerTHMessage_PR_joinGameRequestMessage) { } else if (packet->GetMsg()->messagetype() == PokerTHMessage::Type_JoinExistingGameMessage) {
// Ignore join game requests in this state (may be multiple clicks from the lobby). // Ignore join game requests in this state (may be multiple clicks from the lobby).
} else { } else {
// Packet processing in subclass. // Packet processing in subclass.
@@ -372,33 +361,27 @@ AbstractServerGameStateReceiving::ProcessPacket(boost::shared_ptr<ServerGame> se
boost::shared_ptr<NetPacket> boost::shared_ptr<NetPacket>
AbstractServerGameStateReceiving::CreateNetPacketPlayerJoined(unsigned gameId, const PlayerData &playerData) AbstractServerGameStateReceiving::CreateNetPacketPlayerJoined(unsigned gameId, const PlayerData &playerData)
{ {
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_gamePlayerMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_GamePlayerJoinedMessage);
GamePlayerMessage_t *netGamePlayer = &packet->GetMsg()->choice.gamePlayerMessage; GamePlayerJoinedMessage *netGamePlayer = packet->GetMsg()->mutable_gameplayerjoinedmessage();
netGamePlayer->gameId = gameId; netGamePlayer->set_gameid(gameId);
netGamePlayer->gamePlayerNotification.present = gamePlayerNotification_PR_gamePlayerJoined; netGamePlayer->set_playerid(playerData.GetUniqueId());
GamePlayerJoined_t *playerJoined = &netGamePlayer->gamePlayerNotification.choice.gamePlayerJoined; netGamePlayer->set_isgameadmin(playerData.IsGameAdmin());
playerJoined->playerId = playerData.GetUniqueId();
playerJoined->isGameAdmin = playerData.IsGameAdmin();
return packet; return packet;
} }
boost::shared_ptr<NetPacket> boost::shared_ptr<NetPacket>
AbstractServerGameStateReceiving::CreateNetPacketJoinGameAck(const ServerGame &server, const PlayerData &playerData) AbstractServerGameStateReceiving::CreateNetPacketJoinGameAck(const ServerGame &server, const PlayerData &playerData)
{ {
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_joinGameReplyMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_JoinGameAckMessage);
JoinGameReplyMessage_t *netJoinReply = &packet->GetMsg()->choice.joinGameReplyMessage; JoinGameAckMessage *netJoinReply = packet->GetMsg()->mutable_joingameackmessage();
netJoinReply->gameId = server.GetId(); netJoinReply->set_gameid(server.GetId());
netJoinReply->joinGameResult.present = joinGameResult_PR_joinGameAck; netJoinReply->set_areyougameadmin(playerData.IsGameAdmin());
JoinGameAck_t *joinAck = &netJoinReply->joinGameResult.choice.joinGameAck;
joinAck->areYouGameAdmin = static_cast<PlayerInfoRights>(playerData.IsGameAdmin());
NetPacket::SetGameData(server.GetGameData(), &joinAck->gameInfo); NetGameInfo *gameInfo = netJoinReply->mutable_gameinfo();
OCTET_STRING_fromBuf( NetPacket::SetGameData(server.GetGameData(), *gameInfo);
&joinAck->gameInfo.gameName, gameInfo->set_gamename(server.GetName());
server.GetName().c_str(),
(int)server.GetName().length());
return packet; return packet;
} }
@@ -548,11 +531,11 @@ ServerGameStateInit::TimerAdminWarning(const boost::system::error_code &ec, boos
boost::shared_ptr<SessionData> session = server->GetSessionManager().GetSessionByUniquePlayerId(server->GetAdminPlayerId()); boost::shared_ptr<SessionData> session = server->GetSessionManager().GetSessionByUniquePlayerId(server->GetAdminPlayerId());
if (session) { if (session) {
// Send him a warning. // Send him a warning.
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_timeoutWarningMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_TimeoutWarningMessage);
TimeoutWarningMessage_t *netWarning = &packet->GetMsg()->choice.timeoutWarningMessage; TimeoutWarningMessage *netWarning = packet->GetMsg()->mutable_timeoutwarningmessage();
netWarning->timeoutReason = NETWORK_TIMEOUT_GAME_ADMIN_IDLE; netWarning->set_timeoutreason(TimeoutWarningMessage::timeoutInactiveGame);
netWarning->remainingSeconds = SERVER_GAME_ADMIN_WARNING_REMAINING_SEC; netWarning->set_remainingseconds(SERVER_GAME_ADMIN_WARNING_REMAINING_SEC);
server->GetLobbyThread().GetSender().Send(session, packet); server->GetLobbyThread().GetSender().Send(session, packet);
} }
// Start timeout timer. // Start timeout timer.
@@ -598,14 +581,12 @@ ServerGameStateInit::SendStartEvent(ServerGame &server, bool fillWithComputerPla
server.GetLobbyThread().NotifyPlayerJoinedGame(server.GetId(), tmpPlayerData->GetUniqueId()); server.GetLobbyThread().NotifyPlayerJoinedGame(server.GetId(), tmpPlayerData->GetUniqueId());
} }
} }
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_startEventMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_StartEventMessage);
StartEventMessage_t *netStartEvent = &packet->GetMsg()->choice.startEventMessage; StartEventMessage *netStartEvent = packet->GetMsg()->mutable_starteventmessage();
netStartEvent->gameId = server.GetId(); netStartEvent->set_starteventtype(StartEventMessage::startEvent);
netStartEvent->set_gameid(server.GetId());
netStartEvent->startEventType.present = startEventType_PR_startEvent; netStartEvent->set_fillwithcomputerplayers(fillWithComputerPlayers);
StartEvent_t *start = &netStartEvent->startEventType.choice.startEvent;
start->fillWithComputerPlayers = fillWithComputerPlayers;
// Wait for all players to confirm start of game. // Wait for all players to confirm start of game.
server.SendToAllPlayers(packet, SessionData::Game); server.SendToAllPlayers(packet, SessionData::Game);
@@ -618,48 +599,48 @@ ServerGameStateInit::SendStartEvent(ServerGame &server, bool fillWithComputerPla
void void
ServerGameStateInit::InternalProcessPacket(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet) ServerGameStateInit::InternalProcessPacket(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet)
{ {
if (packet->GetMsg()->present == PokerTHMessage_PR_startEventMessage) { if (packet->GetMsg()->messagetype() == PokerTHMessage::Type_StartEventMessage) {
StartEventMessage_t *netStartEvent = &packet->GetMsg()->choice.startEventMessage; const StartEventMessage &netStartEvent = packet->GetMsg()->starteventmessage();
// Only admins are allowed to start the game. // Only admins are allowed to start the game.
if (session->GetPlayerData()->IsGameAdmin() if (session->GetPlayerData()->IsGameAdmin()
&& netStartEvent->gameId == server->GetId() && netStartEvent.gameid() == server->GetId()
&& netStartEvent->startEventType.present == startEventType_PR_startEvent && netStartEvent.starteventtype() == StartEventMessage::startEvent
&& (server->GetGameData().gameType != GAME_TYPE_RANKING // ranking games need to be full && (server->GetGameData().gameType != GAME_TYPE_RANKING // ranking games need to be full
|| server->GetGameData().maxNumberOfPlayers == server->GetCurNumberOfPlayers())) { || server->GetGameData().maxNumberOfPlayers == server->GetCurNumberOfPlayers())) {
SendStartEvent(*server, netStartEvent->startEventType.choice.startEvent.fillWithComputerPlayers != 0); SendStartEvent(*server, netStartEvent.fillwithcomputerplayers());
} else { // kick players who try to start but are not allowed to } else { // kick players who try to start but are not allowed to
server->MoveSessionToLobby(session, NTF_NET_REMOVED_START_FAILED); server->MoveSessionToLobby(session, NTF_NET_REMOVED_START_FAILED);
} }
} else if (packet->GetMsg()->present == PokerTHMessage_PR_invitePlayerToGameMessage) { } else if (packet->GetMsg()->messagetype() == PokerTHMessage::Type_InvitePlayerToGameMessage) {
InvitePlayerToGameMessage_t *netInvite = &packet->GetMsg()->choice.invitePlayerToGameMessage; const InvitePlayerToGameMessage &netInvite = packet->GetMsg()->inviteplayertogamemessage();
// Only invite players which are not already within the group. // Only invite players which are not already within the group.
if (netInvite->gameId == server->GetId() && !server->IsPlayerConnected(netInvite->playerId)) { if (netInvite.gameid() == server->GetId() && !server->IsPlayerConnected(netInvite.playerid())) {
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_inviteNotifyMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_InviteNotifyMessage);
InviteNotifyMessage_t *netInvNotif = &packet->GetMsg()->choice.inviteNotifyMessage; InviteNotifyMessage *netInvNotif = packet->GetMsg()->mutable_invitenotifymessage();
netInvNotif->gameId = netInvite->gameId; netInvNotif->set_gameid(netInvite.gameid());
netInvNotif->playerIdByWhom = session->GetPlayerData()->GetUniqueId(); netInvNotif->set_playeridbywhom(session->GetPlayerData()->GetUniqueId());
netInvNotif->playerIdWho = netInvite->playerId; netInvNotif->set_playeridwho(netInvite.playerid());
bool requestSent = server->GetLobbyThread().SendToLobbyPlayer(netInvite->playerId, packet); bool requestSent = server->GetLobbyThread().SendToLobbyPlayer(netInvite.playerid(), packet);
server->SendToAllPlayers(packet, SessionData::Game); server->SendToAllPlayers(packet, SessionData::Game);
if (requestSent) { if (requestSent) {
// This player has been invited. // This player has been invited.
server->AddPlayerInvitation(netInvite->playerId); server->AddPlayerInvitation(netInvite.playerid());
} else { } else {
// Player is not in lobby - send reject message. // Player is not in lobby - send reject message.
boost::shared_ptr<NetPacket> p2(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> p2(new NetPacket);
p2->GetMsg()->present = PokerTHMessage_PR_rejectInvNotifyMessage; p2->GetMsg()->set_messagetype(PokerTHMessage::Type_RejectInvNotifyMessage);
RejectInvNotifyMessage_t *netRejNotif = &p2->GetMsg()->choice.rejectInvNotifyMessage; RejectInvNotifyMessage *netRejNotif = p2->GetMsg()->mutable_rejectinvnotifymessage();
netRejNotif->gameId = netInvite->gameId; netRejNotif->set_gameid(netInvite.gameid());
netRejNotif->playerId = netInvite->playerId; netRejNotif->set_playerid(netInvite.playerid());
netRejNotif->playerRejectReason = RejectGameInvReason_busy; netRejNotif->set_playerrejectreason(RejectGameInvitationMessage::rejectReasonBusy);
server->SendToAllPlayers(p2, SessionData::Game); server->SendToAllPlayers(p2, SessionData::Game);
} }
} }
} else if (packet->GetMsg()->present == PokerTHMessage_PR_resetTimeoutMessage) { } else if (packet->GetMsg()->messagetype() == PokerTHMessage::Type_ResetTimeoutMessage) {
if (session->GetPlayerData()->IsGameAdmin()) { if (session->GetPlayerData()->IsGameAdmin()) {
RegisterAdminTimer(server); RegisterAdminTimer(server);
} }
@@ -712,7 +693,7 @@ ServerGameStateStartGame::HandleNewSession(boost::shared_ptr<ServerGame> server,
void void
ServerGameStateStartGame::InternalProcessPacket(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet) ServerGameStateStartGame::InternalProcessPacket(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet)
{ {
if (packet->GetMsg()->present == PokerTHMessage_PR_startEventAckMessage) { if (packet->GetMsg()->messagetype() == PokerTHMessage::Type_StartEventAckMessage) {
session->SetReadyFlag(); session->SetReadyFlag();
if (server->GetSessionManager().CountReadySessions() == server->GetSessionManager().GetRawSessionCount()) { if (server->GetSessionManager().CountReadySessions() == server->GetSessionManager().GetRawSessionCount()) {
// Everyone is ready. // Everyone is ready.
@@ -746,23 +727,18 @@ ServerGameStateStartGame::DoStart(boost::shared_ptr<ServerGame> server)
server->MoveSessionToLobby(tmpSession, NTF_NET_REMOVED_START_FAILED); server->MoveSessionToLobby(tmpSession, NTF_NET_REMOVED_START_FAILED);
} }
} else { } else {
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_gameStartMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_GameStartInitialMessage);
GameStartMessage_t *netGameStart = &packet->GetMsg()->choice.gameStartMessage; GameStartInitialMessage *netGameStart = packet->GetMsg()->mutable_gamestartinitialmessage();
netGameStart->gameId = server->GetId(); netGameStart->set_gameid(server->GetId());
netGameStart->startDealerPlayerId = server->GetStartData().startDealerPlayerId; netGameStart->set_startdealerplayerid(server->GetStartData().startDealerPlayerId);
netGameStart->gameStartMode.present = gameStartMode_PR_gameStartModeInitial;
GameStartModeInitial_t *netStartModeInitial = &netGameStart->gameStartMode.choice.gameStartModeInitial;
// Send player order to clients. // Send player order to clients.
// Assume player list is sorted by number. // Assume player list is sorted by number.
PlayerDataList::iterator player_i = tmpPlayerList.begin(); PlayerDataList::iterator player_i = tmpPlayerList.begin();
PlayerDataList::iterator player_end = tmpPlayerList.end(); PlayerDataList::iterator player_end = tmpPlayerList.end();
while (player_i != player_end) { while (player_i != player_end) {
NonZeroId_t *playerSlot = (NonZeroId_t *)calloc(1, sizeof(NonZeroId_t)); netGameStart->add_playerseats((*player_i)->GetUniqueId());
*playerSlot = (*player_i)->GetUniqueId();
ASN_SEQUENCE_ADD(&netStartModeInitial->playerSeats.list, playerSlot);
++player_i; ++player_i;
} }
@@ -794,11 +770,11 @@ AbstractServerGameStateRunning::HandleNewSession(boost::shared_ptr<ServerGame> s
server->AddRejoinPlayer(session->GetPlayerData()->GetUniqueId()); server->AddRejoinPlayer(session->GetPlayerData()->GetUniqueId());
// Send start event right away. // Send start event right away.
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_startEventMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_StartEventMessage);
StartEventMessage_t *netStartEvent = &packet->GetMsg()->choice.startEventMessage; StartEventMessage *netStartEvent = packet->GetMsg()->mutable_starteventmessage();
netStartEvent->gameId = server->GetId(); netStartEvent->set_starteventtype(StartEventMessage::rejoinEvent);
netStartEvent->startEventType.present = startEventType_PR_rejoinEvent; netStartEvent->set_gameid(server->GetId());
// Wait for rejoining player to confirm start of game. // Wait for rejoining player to confirm start of game.
server->GetLobbyThread().GetSender().Send(session, packet); server->GetLobbyThread().GetSender().Send(session, packet);
@@ -812,7 +788,7 @@ AbstractServerGameStateRunning::HandleNewSession(boost::shared_ptr<ServerGame> s
void void
AbstractServerGameStateRunning::InternalProcessPacket(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet) AbstractServerGameStateRunning::InternalProcessPacket(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet)
{ {
if (packet->GetMsg()->present == PokerTHMessage_PR_resetTimeoutMessage) { if (packet->GetMsg()->messagetype() == PokerTHMessage::Type_ResetTimeoutMessage) {
// Reactivate session. // Reactivate session.
server->AddReactivatePlayer(session->GetPlayerData()->GetUniqueId()); server->AddReactivatePlayer(session->GetPlayerData()->GetUniqueId());
} }
@@ -896,23 +872,21 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr<ServerGame> server)
&& !curGame.getCurrentHand()->getCardsShown() && !curGame.getCurrentHand()->getCardsShown()
&& nonFoldPlayers.size() > 1) { && nonFoldPlayers.size() > 1) {
// Send cards of all active players to all players (all in). // Send cards of all active players to all players (all in).
boost::shared_ptr<NetPacket> allIn(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> allIn(new NetPacket);
allIn->GetMsg()->present = PokerTHMessage_PR_allInShowCardsMessage; allIn->GetMsg()->set_messagetype(PokerTHMessage::Type_AllInShowCardsMessage);
AllInShowCardsMessage_t *netAllInShow = &allIn->GetMsg()->choice.allInShowCardsMessage; AllInShowCardsMessage *netAllInShow = allIn->GetMsg()->mutable_allinshowcardsmessage();
netAllInShow->gameId = server->GetId(); netAllInShow->set_gameid(server->GetId());
PlayerListConstIterator i = nonFoldPlayers.begin(); PlayerListConstIterator i = nonFoldPlayers.begin();
PlayerListConstIterator end = nonFoldPlayers.end(); PlayerListConstIterator end = nonFoldPlayers.end();
while (i != end) { while (i != end) {
PlayerAllIn_t *playerAllIn = (PlayerAllIn_t *)calloc(1, sizeof(PlayerAllIn_t)); AllInShowCardsMessage::PlayerAllIn *playerAllIn = netAllInShow->add_playersallin();
playerAllIn->playerId = (*i)->getMyUniqueID(); playerAllIn->set_playerid((*i)->getMyUniqueID());
int tmpCards[2]; int tmpCards[2];
(*i)->getMyCards(tmpCards); (*i)->getMyCards(tmpCards);
playerAllIn->allInCard1 = tmpCards[0]; playerAllIn->set_allincard1(tmpCards[0]);
playerAllIn->allInCard2 = tmpCards[1]; playerAllIn->set_allincard2(tmpCards[1]);
ASN_SEQUENCE_ADD(&netAllInShow->playersAllIn.list, playerAllIn);
++i; ++i;
} }
server->SendToAllPlayers(allIn, SessionData::Game); server->SendToAllPlayers(allIn, SessionData::Game);
@@ -944,12 +918,12 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr<ServerGame> server)
if (!curPlayer->getMyActiveStatus()) if (!curPlayer->getMyActiveStatus())
throw ServerException(__FILE__, __LINE__, ERR_NET_PLAYER_NOT_ACTIVE, 0); throw ServerException(__FILE__, __LINE__, ERR_NET_PLAYER_NOT_ACTIVE, 0);
boost::shared_ptr<NetPacket> notification(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> notification(new NetPacket);
notification->GetMsg()->present = PokerTHMessage_PR_playersTurnMessage; notification->GetMsg()->set_messagetype(PokerTHMessage::Type_PlayersTurnMessage);
PlayersTurnMessage_t *netPlayersTurn = &notification->GetMsg()->choice.playersTurnMessage; PlayersTurnMessage *netPlayersTurn = notification->GetMsg()->mutable_playersturnmessage();
netPlayersTurn->gameId = server->GetId(); netPlayersTurn->set_gameid(server->GetId());
netPlayersTurn->gameState = curGame.getCurrentHand()->getCurrentRound(); netPlayersTurn->set_gamestate(static_cast<NetGameState>(curGame.getCurrentHand()->getCurrentRound()));
netPlayersTurn->playerId = curPlayer->getMyUniqueID(); netPlayersTurn->set_playerid(curPlayer->getMyUniqueID());
server->SendToAllPlayers(notification, SessionData::Game); server->SendToAllPlayers(notification, SessionData::Game);
// If the player is computer controlled, let the engine act. // If the player is computer controlled, let the engine act.
@@ -985,27 +959,21 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr<ServerGame> server)
if (nonFoldPlayers.size() == 1) { if (nonFoldPlayers.size() == 1) {
// End of Hand, but keep cards hidden. // End of Hand, but keep cards hidden.
boost::shared_ptr<PlayerInterface> player = nonFoldPlayers.front(); boost::shared_ptr<PlayerInterface> player = nonFoldPlayers.front();
boost::shared_ptr<NetPacket> endHand(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> endHand(new NetPacket);
endHand->GetMsg()->present = PokerTHMessage_PR_endOfHandMessage; endHand->GetMsg()->set_messagetype(PokerTHMessage::Type_EndOfHandHideCardsMessage);
EndOfHandMessage_t *netEndHand = &endHand->GetMsg()->choice.endOfHandMessage; EndOfHandHideCardsMessage *netEndHand = endHand->GetMsg()->mutable_endofhandhidecardsmessage();
netEndHand->gameId = server->GetId(); netEndHand->set_gameid(server->GetId());
netEndHand->set_playerid(player->getMyUniqueID());
netEndHand->endOfHandType.present = endOfHandType_PR_endOfHandHideCards; netEndHand->set_moneywon(player->getLastMoneyWon());
EndOfHandHideCards_t *endHandHide = &netEndHand->endOfHandType.choice.endOfHandHideCards; netEndHand->set_playermoney(player->getMyCash());
endHandHide->playerId = player->getMyUniqueID();
endHandHide->moneyWon = player->getLastMoneyWon();
endHandHide->playerMoney = player->getMyCash();
server->SendToAllPlayers(endHand, SessionData::Game); server->SendToAllPlayers(endHand, SessionData::Game);
} else { } else {
// End of Hand - show cards. // End of Hand - show cards.
const PlayerIdList showList(curGame.getCurrentHand()->getBoard()->getPlayerNeedToShowCards()); const PlayerIdList showList(curGame.getCurrentHand()->getBoard()->getPlayerNeedToShowCards());
boost::shared_ptr<NetPacket> endHand(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> endHand(new NetPacket);
endHand->GetMsg()->present = PokerTHMessage_PR_endOfHandMessage; endHand->GetMsg()->set_messagetype(PokerTHMessage::Type_EndOfHandShowCardsMessage);
EndOfHandMessage_t *netEndHand = &endHand->GetMsg()->choice.endOfHandMessage; EndOfHandShowCardsMessage *netEndHand = endHand->GetMsg()->mutable_endofhandshowcardsmessage();
netEndHand->gameId = server->GetId(); netEndHand->set_gameid(server->GetId());
netEndHand->endOfHandType.present = endOfHandType_PR_endOfHandShowCards;
EndOfHandShowCards_t *endHandShow = &netEndHand->endOfHandType.choice.endOfHandShowCards;
PlayerIdList::const_iterator i = showList.begin(); PlayerIdList::const_iterator i = showList.begin();
PlayerIdList::const_iterator end = showList.end(); PlayerIdList::const_iterator end = showList.end();
@@ -1013,10 +981,8 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr<ServerGame> server)
while (i != end) { while (i != end) {
boost::shared_ptr<PlayerInterface> tmpPlayer(curGame.getPlayerByUniqueId(*i)); boost::shared_ptr<PlayerInterface> tmpPlayer(curGame.getPlayerByUniqueId(*i));
if (tmpPlayer) { if (tmpPlayer) {
PlayerResult_t *playerResult = (PlayerResult_t *)calloc(1, sizeof(PlayerResult_t)); PlayerResult *playerResult = netEndHand->add_playerresults();
SetPlayerResult(*playerResult, tmpPlayer, GAME_STATE_RIVER); SetPlayerResult(*playerResult, tmpPlayer, GAME_STATE_RIVER);
ASN_SEQUENCE_ADD(&endHandShow->playerResults.list, playerResult);
} }
++i; ++i;
} }
@@ -1100,11 +1066,11 @@ void
ServerGameStateHand::TimerNextGame(const boost::system::error_code &ec, boost::shared_ptr<ServerGame> server, unsigned winnerPlayerId) ServerGameStateHand::TimerNextGame(const boost::system::error_code &ec, boost::shared_ptr<ServerGame> server, unsigned winnerPlayerId)
{ {
if (!ec && &server->GetState() == this) { if (!ec && &server->GetState() == this) {
boost::shared_ptr<NetPacket> endGame(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> endGame(new NetPacket);
endGame->GetMsg()->present = PokerTHMessage_PR_endOfGameMessage; endGame->GetMsg()->set_messagetype(PokerTHMessage::Type_EndOfGameMessage);
EndOfGameMessage_t *netEndGame = &endGame->GetMsg()->choice.endOfGameMessage; EndOfGameMessage *netEndGame = endGame->GetMsg()->mutable_endofgamemessage();
netEndGame->gameId = server->GetId(); netEndGame->set_gameid(server->GetId());
netEndGame->winnerPlayerId = winnerPlayerId; netEndGame->set_winnerplayerid(winnerPlayerId);
server->SendToAllPlayers(endGame, SessionData::Game); server->SendToAllPlayers(endGame, SessionData::Game);
// Wait for the start of a new game. // Wait for the start of a new game.
@@ -1175,16 +1141,15 @@ ServerGameStateHand::StartNewHand(boost::shared_ptr<ServerGame> server)
bool errorFlag = false; bool errorFlag = false;
tmpPlayer->getMyCards(cards); tmpPlayer->getMyCards(cards);
boost::shared_ptr<NetPacket> notifyCards(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> notifyCards(new NetPacket);
notifyCards->GetMsg()->present = PokerTHMessage_PR_handStartMessage; notifyCards->GetMsg()->set_messagetype(PokerTHMessage::Type_HandStartMessage);
HandStartMessage_t *netHandStart = &notifyCards->GetMsg()->choice.handStartMessage; HandStartMessage *netHandStart = notifyCards->GetMsg()->mutable_handstartmessage();
netHandStart->gameId = server->GetId(); netHandStart->set_gameid(server->GetId());
string tmpPassword(tmpSession->AuthGetPassword()); string tmpPassword(tmpSession->AuthGetPassword());
if (tmpPassword.empty()) { // encrypt only if password is present if (tmpPassword.empty()) { // encrypt only if password is present
netHandStart->yourCards.present = yourCards_PR_plainCards; HandStartMessage::PlainCards *plainCards = netHandStart->mutable_plaincards();
PlainCards_t *plainCards = &netHandStart->yourCards.choice.plainCards; plainCards->set_plaincard1(cards[0]);
plainCards->plainCard1 = cards[0]; plainCards->set_plaincard2(cards[1]);
plainCards->plainCard2 = cards[1];
} else { } else {
ostringstream cardDataStream; ostringstream cardDataStream;
vector<unsigned char> tmpCipher; vector<unsigned char> tmpCipher;
@@ -1199,12 +1164,7 @@ ServerGameStateHand::StartNewHand(boost::shared_ptr<ServerGame> server)
cardDataStream.str(), cardDataStream.str(),
tmpCipher) tmpCipher)
&& !tmpCipher.empty()) { && !tmpCipher.empty()) {
netHandStart->yourCards.present = yourCards_PR_encryptedCards; netHandStart->set_encryptedcards((const char *)&tmpCipher[0], tmpCipher.size());
EncryptedCards_t *encryptedCards = &netHandStart->yourCards.choice.encryptedCards;
OCTET_STRING_fromBuf(
&encryptedCards->cardData,
(const char *)&tmpCipher[0],
(int)tmpCipher.size());
} else { } else {
server->RemovePlayer(tmpPlayer->getMyUniqueID(), ERR_SOCK_INVALID_STATE); server->RemovePlayer(tmpPlayer->getMyUniqueID(), ERR_SOCK_INVALID_STATE);
errorFlag = true; errorFlag = true;
@@ -1214,21 +1174,21 @@ ServerGameStateHand::StartNewHand(boost::shared_ptr<ServerGame> server)
PlayerListIterator player_end = curGame.getSeatsList()->end(); PlayerListIterator player_end = curGame.getSeatsList()->end();
int playerCounter = 0; int playerCounter = 0;
while (player_i != player_end && playerCounter < server->GetStartData().numberOfPlayers) { while (player_i != player_end && playerCounter < server->GetStartData().numberOfPlayers) {
NetPlayerState_t *seatState = (NetPlayerState_t *)calloc(1, sizeof(NetPlayerState_t)); NetPlayerState seatState;
if (!(*player_i)->getMyActiveStatus()) { if (!(*player_i)->getMyActiveStatus()) {
*seatState = NetPlayerState_playerStateNoMoney; seatState = playerStateNoMoney;
} else if (!(*player_i)->isSessionActive()) { } else if (!(*player_i)->isSessionActive()) {
*seatState = NetPlayerState_playerStateSessionInactive; seatState = playerStateSessionInactive;
} else { } else {
*seatState = NetPlayerState_playerStateNormal; seatState = playerStateNormal;
} }
ASN_SEQUENCE_ADD(&netHandStart->seatStates.list, seatState); netHandStart->add_seatstates(seatState);
++player_i; ++player_i;
++playerCounter; ++playerCounter;
} }
if (!errorFlag) { if (!errorFlag) {
netHandStart->smallBlind = curGame.getCurrentHand()->getSmallBlind(); netHandStart->set_smallblind(curGame.getCurrentHand()->getSmallBlind());
server->GetLobbyThread().GetSender().Send(tmpSession, notifyCards); server->GetLobbyThread().GetSender().Send(tmpSession, notifyCards);
} }
} }
@@ -1245,17 +1205,17 @@ ServerGameStateHand::StartNewHand(boost::shared_ptr<ServerGame> server)
while (i != end) { while (i != end) {
boost::shared_ptr<PlayerInterface> tmpPlayer = *i; boost::shared_ptr<PlayerInterface> tmpPlayer = *i;
if (tmpPlayer->getMyButton() == BUTTON_SMALL_BLIND) { if (tmpPlayer->getMyButton() == BUTTON_SMALL_BLIND) {
boost::shared_ptr<NetPacket> notifySmallBlind(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> notifySmallBlind(new NetPacket);
notifySmallBlind->GetMsg()->present = PokerTHMessage_PR_playersActionDoneMessage; notifySmallBlind->GetMsg()->set_messagetype(PokerTHMessage::Type_PlayersActionDoneMessage);
PlayersActionDoneMessage_t *netSmallBlind = &notifySmallBlind->GetMsg()->choice.playersActionDoneMessage; PlayersActionDoneMessage *netSmallBlind = notifySmallBlind->GetMsg()->mutable_playersactiondonemessage();
netSmallBlind->gameId = server->GetId(); netSmallBlind->set_gameid(server->GetId());
netSmallBlind->gameState = NetGameState_statePreflopSmallBlind; netSmallBlind->set_gamestate(statePreflopSmallBlind);
netSmallBlind->playerId = tmpPlayer->getMyUniqueID(); netSmallBlind->set_playerid(tmpPlayer->getMyUniqueID());
netSmallBlind->playerAction = tmpPlayer->getMyAction(); netSmallBlind->set_playeraction(static_cast<NetPlayerAction>(tmpPlayer->getMyAction()));
netSmallBlind->totalPlayerBet = tmpPlayer->getMySet(); netSmallBlind->set_totalplayerbet(tmpPlayer->getMySet());
netSmallBlind->playerMoney = tmpPlayer->getMyCash(); netSmallBlind->set_playermoney(tmpPlayer->getMyCash());
netSmallBlind->highestSet = server->GetGame().getCurrentHand()->getCurrentBeRo()->getHighestSet(); netSmallBlind->set_highestset(server->GetGame().getCurrentHand()->getCurrentBeRo()->getHighestSet());
netSmallBlind->minimumRaise = server->GetGame().getCurrentHand()->getCurrentBeRo()->getMinimumRaise(); netSmallBlind->set_minimumraise(server->GetGame().getCurrentHand()->getCurrentBeRo()->getMinimumRaise());
server->SendToAllPlayers(notifySmallBlind, SessionData::Game); server->SendToAllPlayers(notifySmallBlind, SessionData::Game);
break; break;
} }
@@ -1267,17 +1227,17 @@ ServerGameStateHand::StartNewHand(boost::shared_ptr<ServerGame> server)
while (i != end) { while (i != end) {
boost::shared_ptr<PlayerInterface> tmpPlayer = *i; boost::shared_ptr<PlayerInterface> tmpPlayer = *i;
if (tmpPlayer->getMyButton() == BUTTON_BIG_BLIND) { if (tmpPlayer->getMyButton() == BUTTON_BIG_BLIND) {
boost::shared_ptr<NetPacket> notifyBigBlind(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> notifyBigBlind(new NetPacket);
notifyBigBlind->GetMsg()->present = PokerTHMessage_PR_playersActionDoneMessage; notifyBigBlind->GetMsg()->set_messagetype(PokerTHMessage::Type_PlayersActionDoneMessage);
PlayersActionDoneMessage_t *netBigBlind = &notifyBigBlind->GetMsg()->choice.playersActionDoneMessage; PlayersActionDoneMessage *netBigBlind = notifyBigBlind->GetMsg()->mutable_playersactiondonemessage();
netBigBlind->gameId = server->GetId(); netBigBlind->set_gameid(server->GetId());
netBigBlind->gameState = NetGameState_statePreflopBigBlind; netBigBlind->set_gamestate(statePreflopBigBlind);
netBigBlind->playerId = tmpPlayer->getMyUniqueID(); netBigBlind->set_playerid(tmpPlayer->getMyUniqueID());
netBigBlind->playerAction = tmpPlayer->getMyAction(); netBigBlind->set_playeraction(static_cast<NetPlayerAction>(tmpPlayer->getMyAction()));
netBigBlind->totalPlayerBet = tmpPlayer->getMySet(); netBigBlind->set_totalplayerbet(tmpPlayer->getMySet());
netBigBlind->playerMoney = tmpPlayer->getMyCash(); netBigBlind->set_playermoney(tmpPlayer->getMyCash());
netBigBlind->highestSet = server->GetGame().getCurrentHand()->getCurrentBeRo()->getHighestSet(); netBigBlind->set_highestset(server->GetGame().getCurrentHand()->getCurrentBeRo()->getHighestSet());
netBigBlind->minimumRaise = server->GetGame().getCurrentHand()->getCurrentBeRo()->getMinimumRaise(); netBigBlind->set_minimumraise(server->GetGame().getCurrentHand()->getCurrentBeRo()->getMinimumRaise());
server->SendToAllPlayers(notifyBigBlind, SessionData::Game); server->SendToAllPlayers(notifyBigBlind, SessionData::Game);
break; break;
} }
@@ -1304,11 +1264,11 @@ ServerGameStateHand::CheckPlayerTimeouts(boost::shared_ptr<ServerGame> server)
tmpPlayer->setIsSessionActive(false); tmpPlayer->setIsSessionActive(false);
boost::shared_ptr<SessionData> session = server->GetSessionManager().GetSessionByUniquePlayerId(tmpPlayer->getMyUniqueID()); boost::shared_ptr<SessionData> session = server->GetSessionManager().GetSessionByUniquePlayerId(tmpPlayer->getMyUniqueID());
if (session) { if (session) {
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_timeoutWarningMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_TimeoutWarningMessage);
TimeoutWarningMessage_t *netWarning = &packet->GetMsg()->choice.timeoutWarningMessage; TimeoutWarningMessage *netWarning = packet->GetMsg()->mutable_timeoutwarningmessage();
netWarning->timeoutReason = NETWORK_TIMEOUT_KICK_AFTER_AUTOFOLD; netWarning->set_timeoutreason(TimeoutWarningMessage::timeoutKickAfterAutofold);
netWarning->remainingSeconds = actionTimeout * SERVER_GAME_FORCED_TIMEOUT_FACTOR - tmpPlayer->getTimeSecSinceLastRemoteAction(); netWarning->set_remainingseconds(actionTimeout * SERVER_GAME_FORCED_TIMEOUT_FACTOR - tmpPlayer->getTimeSecSinceLastRemoteAction());
server->GetLobbyThread().GetSender().Send(session, packet); server->GetLobbyThread().GetSender().Send(session, packet);
} }
} }
@@ -1360,11 +1320,11 @@ ServerGameStateHand::PerformRejoin(boost::shared_ptr<ServerGame> server, boost::
boost::shared_ptr<PlayerInterface> rejoinPlayer = curGame.getPlayerByName(session->GetPlayerData()->GetName()); boost::shared_ptr<PlayerInterface> rejoinPlayer = curGame.getPlayerByName(session->GetPlayerData()->GetName());
if (rejoinPlayer) { if (rejoinPlayer) {
// Notify other clients about id change. // Notify other clients about id change.
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_playerIdChangedMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_PlayerIdChangedMessage);
PlayerIdChangedMessage_t *netIdChanged = &packet->GetMsg()->choice.playerIdChangedMessage; PlayerIdChangedMessage *netIdChanged = packet->GetMsg()->mutable_playeridchangedmessage();
netIdChanged->oldPlayerId = rejoinPlayer->getMyUniqueID(); netIdChanged->set_oldplayerid(rejoinPlayer->getMyUniqueID());
netIdChanged->newPlayerId = session->GetPlayerData()->GetUniqueId(); netIdChanged->set_newplayerid(session->GetPlayerData()->GetUniqueId());
server->SendToAllButOnePlayers(packet, session->GetId(), SessionData::Game); server->SendToAllButOnePlayers(packet, session->GetId(), SessionData::Game);
// Update the dealer, if necessary. // Update the dealer, if necessary.
@@ -1378,24 +1338,20 @@ ServerGameStateHand::PerformRejoin(boost::shared_ptr<ServerGame> server, boost::
rejoinPlayer->setIsSessionActive(true); rejoinPlayer->setIsSessionActive(true);
// Send game start notification to rejoining client. // Send game start notification to rejoining client.
packet.reset(new NetPacket(NetPacket::Alloc)); packet.reset(new NetPacket);
packet->GetMsg()->present = PokerTHMessage_PR_gameStartMessage; packet->GetMsg()->set_messagetype(PokerTHMessage::Type_GameStartRejoinMessage);
GameStartMessage_t *netGameStart = &packet->GetMsg()->choice.gameStartMessage; GameStartRejoinMessage *netGameStart = packet->GetMsg()->mutable_gamestartrejoinmessage();
netGameStart->gameId = server->GetId(); netGameStart->set_gameid(server->GetId());
netGameStart->startDealerPlayerId = curGame.getDealerPosition(); netGameStart->set_startdealerplayerid(curGame.getDealerPosition());
netGameStart->gameStartMode.present = gameStartMode_PR_gameStartModeRejoin; netGameStart->set_handnum(curGame.getCurrentHandID());
GameStartModeRejoin_t *netStartModeRejoin = &netGameStart->gameStartMode.choice.gameStartModeRejoin;
netStartModeRejoin->handNum = curGame.getCurrentHandID();
PlayerListIterator player_i = curGame.getSeatsList()->begin(); PlayerListIterator player_i = curGame.getSeatsList()->begin();
PlayerListIterator player_end = curGame.getSeatsList()->end(); PlayerListIterator player_end = curGame.getSeatsList()->end();
int player_count = 0; int player_count = 0;
while (player_i != player_end && player_count < server->GetStartData().numberOfPlayers) { while (player_i != player_end && player_count < server->GetStartData().numberOfPlayers) {
boost::shared_ptr<PlayerInterface> tmpPlayer = *player_i; boost::shared_ptr<PlayerInterface> tmpPlayer = *player_i;
RejoinPlayerData_t *playerSlot = (RejoinPlayerData_t *)calloc(1, sizeof(RejoinPlayerData_t)); GameStartRejoinMessage::RejoinPlayerData *playerSlot = netGameStart->add_rejoinplayerdata();
playerSlot->playerId = tmpPlayer->getMyUniqueID(); playerSlot->set_playerid(tmpPlayer->getMyUniqueID());
playerSlot->playerMoney = tmpPlayer->getMyCash(); playerSlot->set_playermoney(tmpPlayer->getMyCash());
ASN_SEQUENCE_ADD(&netStartModeRejoin->rejoinPlayerData.list, playerSlot);
++player_i; ++player_i;
++player_count; ++player_count;
} }
@@ -1453,8 +1409,8 @@ ServerGameStateWaitPlayerAction::InternalProcessPacket(boost::shared_ptr<ServerG
{ {
AbstractServerGameStateRunning::InternalProcessPacket(server, session, packet); AbstractServerGameStateRunning::InternalProcessPacket(server, session, packet);
if (packet->GetMsg()->present == PokerTHMessage_PR_myActionRequestMessage) { if (packet->GetMsg()->messagetype() == PokerTHMessage::Type_MyActionRequestMessage) {
MyActionRequestMessage_t *netMyAction = &packet->GetMsg()->choice.myActionRequestMessage; MyActionRequestMessage *netMyAction = packet->GetMsg()->mutable_myactionrequestmessage();
// TODO consider game id. // TODO consider game id.
Game &curGame = server->GetGame(); Game &curGame = server->GetGame();
@@ -1464,7 +1420,7 @@ ServerGameStateWaitPlayerAction::InternalProcessPacket(boost::shared_ptr<ServerG
// Check whether this is the correct round. // Check whether this is the correct round.
PlayerActionCode code = ACTION_CODE_VALID; PlayerActionCode code = ACTION_CODE_VALID;
if (curGame.getCurrentHand()->getCurrentRound() != netMyAction->gameState) if (curGame.getCurrentHand()->getCurrentRound() != netMyAction->gamestate())
code = ACTION_CODE_INVALID_STATE; code = ACTION_CODE_INVALID_STATE;
// Check whether this is the correct player. // Check whether this is the correct player.
@@ -1475,20 +1431,20 @@ ServerGameStateWaitPlayerAction::InternalProcessPacket(boost::shared_ptr<ServerG
} }
// If the client omitted some values, fill them in. // If the client omitted some values, fill them in.
if (netMyAction->myAction == PLAYER_ACTION_CALL && netMyAction->myRelativeBet == 0) { if (netMyAction->myaction() == PLAYER_ACTION_CALL && netMyAction->myrelativebet() == 0) {
if (curGame.getCurrentHand()->getCurrentBeRo()->getHighestSet() >= tmpPlayer->getMySet() + tmpPlayer->getMyCash()) if (curGame.getCurrentHand()->getCurrentBeRo()->getHighestSet() >= tmpPlayer->getMySet() + tmpPlayer->getMyCash())
netMyAction->myAction = PLAYER_ACTION_ALLIN; netMyAction->set_myaction(actionAllIn);
else else
netMyAction->myRelativeBet = curGame.getCurrentHand()->getCurrentBeRo()->getHighestSet() - tmpPlayer->getMySet(); netMyAction->set_myrelativebet(curGame.getCurrentHand()->getCurrentBeRo()->getHighestSet() - tmpPlayer->getMySet());
} }
if (netMyAction->myAction == PLAYER_ACTION_ALLIN && netMyAction->myRelativeBet == 0) if (netMyAction->myaction() == PLAYER_ACTION_ALLIN && netMyAction->myrelativebet() == 0)
netMyAction->myRelativeBet = tmpPlayer->getMyCash(); netMyAction->set_myrelativebet(tmpPlayer->getMyCash());
// Check whether the action is valid. // Check whether the action is valid.
if (code == ACTION_CODE_VALID if (code == ACTION_CODE_VALID
&& (tmpPlayer->checkMyAction( && (tmpPlayer->checkMyAction(
netMyAction->myAction, netMyAction->myaction(),
netMyAction->myRelativeBet, netMyAction->myrelativebet(),
curGame.getCurrentHand()->getCurrentBeRo()->getHighestSet(), curGame.getCurrentHand()->getCurrentBeRo()->getHighestSet(),
curGame.getCurrentHand()->getCurrentBeRo()->getMinimumRaise(), curGame.getCurrentHand()->getCurrentBeRo()->getMinimumRaise(),
curGame.getCurrentHand()->getSmallBlind()) != 0)) { curGame.getCurrentHand()->getSmallBlind()) != 0)) {
@@ -1498,18 +1454,18 @@ ServerGameStateWaitPlayerAction::InternalProcessPacket(boost::shared_ptr<ServerG
if (code == ACTION_CODE_VALID) { if (code == ACTION_CODE_VALID) {
tmpPlayer->setIsSessionActive(true); tmpPlayer->setIsSessionActive(true);
tmpPlayer->markRemoteAction(); tmpPlayer->markRemoteAction();
PerformPlayerAction(*server, tmpPlayer, static_cast<PlayerAction>(netMyAction->myAction), netMyAction->myRelativeBet); PerformPlayerAction(*server, tmpPlayer, static_cast<PlayerAction>(netMyAction->myaction()), netMyAction->myrelativebet());
server->SetState(ServerGameStateHand::Instance()); server->SetState(ServerGameStateHand::Instance());
} else { } else {
// Send reject message. // Send reject message.
boost::shared_ptr<NetPacket> reject(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> reject(new NetPacket);
reject->GetMsg()->present = PokerTHMessage_PR_yourActionRejectedMessage; reject->GetMsg()->set_messagetype(PokerTHMessage::Type_YourActionRejectedMessage);
YourActionRejectedMessage_t *netActionRejected = &reject->GetMsg()->choice.yourActionRejectedMessage; YourActionRejectedMessage *netActionRejected = reject->GetMsg()->mutable_youractionrejectedmessage();
netActionRejected->gameId = server->GetId(); netActionRejected->set_gameid(server->GetId());
netActionRejected->gameState = netMyAction->gameState; netActionRejected->set_gamestate(netMyAction->gamestate());
netActionRejected->yourAction = netMyAction->myAction; netActionRejected->set_youraction(netMyAction->myaction());
netActionRejected->yourRelativeBet = netMyAction->myRelativeBet; netActionRejected->set_yourrelativebet(netMyAction->myrelativebet());
netActionRejected->rejectionReason = code; netActionRejected->set_rejectionreason(static_cast<YourActionRejectedMessage::RejectionReason>(code));
server->GetLobbyThread().GetSender().Send(session, reject); server->GetLobbyThread().GetSender().Send(session, reject);
} }
} }
@@ -1587,15 +1543,15 @@ ServerGameStateWaitNextHand::InternalProcessPacket(boost::shared_ptr<ServerGame>
{ {
AbstractServerGameStateRunning::InternalProcessPacket(server, session, packet); AbstractServerGameStateRunning::InternalProcessPacket(server, session, packet);
if (packet->GetMsg()->present == PokerTHMessage_PR_showMyCardsRequestMessage) { if (packet->GetMsg()->messagetype() == PokerTHMessage::Type_ShowMyCardsRequestMessage) {
Game &curGame = server->GetGame(); Game &curGame = server->GetGame();
boost::shared_ptr<NetPacket> show(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> show(new NetPacket);
show->GetMsg()->present = PokerTHMessage_PR_afterHandShowCardsMessage; show->GetMsg()->set_messagetype(PokerTHMessage::Type_AfterHandShowCardsMessage);
AfterHandShowCardsMessage_t *netShowCards = &show->GetMsg()->choice.afterHandShowCardsMessage; AfterHandShowCardsMessage *netShowCards = show->GetMsg()->mutable_afterhandshowcardsmessage();
boost::shared_ptr<PlayerInterface> tmpPlayer(curGame.getPlayerByUniqueId(session->GetPlayerData()->GetUniqueId())); boost::shared_ptr<PlayerInterface> tmpPlayer(curGame.getPlayerByUniqueId(session->GetPlayerData()->GetUniqueId()));
if (tmpPlayer) { if (tmpPlayer) {
SetPlayerResult(netShowCards->playerResult, tmpPlayer, curGame.getCurrentHand()->getRoundBeforePostRiver()); SetPlayerResult(*netShowCards->mutable_playerresult(), tmpPlayer, curGame.getCurrentHand()->getRoundBeforePostRiver());
server->SendToAllPlayers(show, SessionData::Game); server->SendToAllPlayers(show, SessionData::Game);
} }
} }
File diff suppressed because it is too large Load Diff
+15 -15
View File
@@ -1,6 +1,6 @@
/***************************************************************************** /*****************************************************************************
* PokerTH - The open source texas holdem engine * * PokerTH - The open source texas holdem engine *
* Copyright (C) 2006-2011 Felix Hammer, Florian Thauer, Lothar May * * Copyright (C) 2006-2012 Felix Hammer, Florian Thauer, Lothar May *
* * * *
* This program is free software: you can redistribute it and/or modify * * This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as * * it under the terms of the GNU Affero General Public License as *
@@ -23,12 +23,14 @@
#include <string> #include <string>
#include <list> #include <list>
#include <third_party/asn1/PokerTHMessage.h> #include <third_party/protobuf/pokerth.pb.h>
#include <gamedata.h> #include <gamedata.h>
#define NET_VERSION_MAJOR 5 #define NET_VERSION_MAJOR 5
#define NET_VERSION_MINOR 1 #define NET_VERSION_MINOR 1
#define NET_HEADER_SIZE 4
#define MAX_FILE_DATA_SIZE 256 #define MAX_FILE_DATA_SIZE 256
#define MAX_PACKET_SIZE 384 #define MAX_PACKET_SIZE 384
#define MAX_CHAT_TEXT_SIZE 128 #define MAX_CHAT_TEXT_SIZE 128
@@ -40,22 +42,20 @@
#define MAX_NUM_PLAYER_RESULTS MAX_NUMBER_OF_PLAYERS #define MAX_NUM_PLAYER_RESULTS MAX_NUMBER_OF_PLAYERS
#define MAX_NUM_PLAYER_CARDS MAX_NUMBER_OF_PLAYERS*/ #define MAX_NUM_PLAYER_CARDS MAX_NUMBER_OF_PLAYERS*/
#define STL_STRING_FROM_OCTET_STRING(_a) (string((const char *)(_a).buf, (_a).size)) // This is just a wrapper class for the protocol buffer.
// This is just a wrapper class for the ASN.1 structure.
class NetPacket class NetPacket
{ {
public: public:
enum MemAllocType { NoAlloc = 0, Alloc }; NetPacket();
NetPacket(MemAllocType alloc = NoAlloc); NetPacket(PokerTHMessage *msg);
~NetPacket(); ~NetPacket();
static boost::shared_ptr<NetPacket> Create(char *data, size_t &dataSize); static boost::shared_ptr<NetPacket> Create(char *data, size_t dataSize);
const PokerTHMessage_t *GetMsg() const { const PokerTHMessage *GetMsg() const {
return m_msg; return m_msg;
} }
PokerTHMessage_t *GetMsg() { PokerTHMessage *GetMsg() {
return m_msg; return m_msg;
} }
@@ -63,14 +63,14 @@ public:
std::string ToString() const; std::string ToString() const;
static void SetGameData(const GameData &inData, NetGameInfo_t *outData); static void SetGameData(const GameData &inData, NetGameInfo &outData);
static void GetGameData(const NetGameInfo_t *inData, GameData &outData); static void GetGameData(const NetGameInfo &inData, GameData &outData);
static int NetErrorToGameError(long netErrorReason); static int NetErrorToGameError(ErrorMessage::ErrorReason netErrorReason);
static long GameErrorToNetError(int gameErrorReason); static ErrorMessage::ErrorReason GameErrorToNetError(int gameErrorReason);
private: private:
PokerTHMessage_t *m_msg; PokerTHMessage *m_msg;
}; };
typedef std::list<boost::shared_ptr<NetPacket> > NetPacketList; typedef std::list<boost::shared_ptr<NetPacket> > NetPacketList;
+18 -18
View File
@@ -71,10 +71,10 @@ public:
void NotifyReopeningGame(unsigned gameId); void NotifyReopeningGame(unsigned gameId);
void DispatchPacket(boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet); void DispatchPacket(boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet);
void HandleGameRetrievePlayerInfo(boost::shared_ptr<SessionData> session, const PlayerInfoRequestMessage_t &playerInfoRequest); void HandleGameRetrievePlayerInfo(boost::shared_ptr<SessionData> session, const PlayerInfoRequestMessage &playerInfoRequest);
void HandleGameRetrieveAvatar(boost::shared_ptr<SessionData> session, const AvatarRequestMessage_t &retrieveAvatar); void HandleGameRetrieveAvatar(boost::shared_ptr<SessionData> session, const AvatarRequestMessage &retrieveAvatar);
void HandleGameReportGame(boost::shared_ptr<SessionData> session, const ReportGameMessage_t &reportGame); void HandleGameReportGame(boost::shared_ptr<SessionData> session, const ReportGameMessage &reportGame);
void HandleChatRequest(boost::shared_ptr<SessionData> session, const ChatRequestMessage_t &chatRequest); void HandleChatRequest(boost::shared_ptr<SessionData> session, const ChatRequestMessage &chatRequest);
bool KickPlayerByName(const std::string &playerName); bool KickPlayerByName(const std::string &playerName);
bool RemoveGameByPlayerName(const std::string &playerName); bool RemoveGameByPlayerName(const std::string &playerName);
@@ -129,20 +129,20 @@ protected:
void InitChatCleaner(); void InitChatCleaner();
void HandlePacket(boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet); void HandlePacket(boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet);
void HandleNetPacketInit(boost::shared_ptr<SessionData> session, const InitMessage_t &initMessage); void HandleNetPacketInit(boost::shared_ptr<SessionData> session, const InitMessage &initMessage);
void HandleNetPacketAuthClientResponse(boost::shared_ptr<SessionData> session, const AuthClientResponse_t &clientResponse); void HandleNetPacketAuthClientResponse(boost::shared_ptr<SessionData> session, const AuthClientResponseMessage &clientResponse);
void HandleNetPacketAvatarHeader(boost::shared_ptr<SessionData> session, unsigned requestId, const AvatarHeader_t &avatarHeader); void HandleNetPacketAvatarHeader(boost::shared_ptr<SessionData> session, const AvatarHeaderMessage &avatarHeader);
void HandleNetPacketUnknownAvatar(boost::shared_ptr<SessionData> session, unsigned requestId, const UnknownAvatar_t &unknownAvatar); void HandleNetPacketUnknownAvatar(boost::shared_ptr<SessionData> session, const UnknownAvatarMessage &unknownAvatar);
void HandleNetPacketAvatarFile(boost::shared_ptr<SessionData> session, unsigned requestId, const AvatarData_t &avatarData); void HandleNetPacketAvatarFile(boost::shared_ptr<SessionData> session, const AvatarDataMessage &avatarData);
void HandleNetPacketAvatarEnd(boost::shared_ptr<SessionData> session, unsigned requestId, const AvatarEnd_t &avatarEnd); void HandleNetPacketAvatarEnd(boost::shared_ptr<SessionData> session, const AvatarEndMessage &avatarEnd);
void HandleNetPacketRetrievePlayerInfo(boost::shared_ptr<SessionData> session, const PlayerInfoRequestMessage_t &playerInfoRequest); void HandleNetPacketRetrievePlayerInfo(boost::shared_ptr<SessionData> session, const PlayerInfoRequestMessage &playerInfoRequest);
void HandleNetPacketRetrieveAvatar(boost::shared_ptr<SessionData> session, const AvatarRequestMessage_t &retrieveAvatar); void HandleNetPacketRetrieveAvatar(boost::shared_ptr<SessionData> session, const AvatarRequestMessage &retrieveAvatar);
void HandleNetPacketCreateGame(boost::shared_ptr<SessionData> session, bool autoLeave, const JoinNewGame_t &newGame); void HandleNetPacketCreateGame(boost::shared_ptr<SessionData> session, const JoinNewGameMessage &newGame);
void HandleNetPacketJoinGame(boost::shared_ptr<SessionData> session, bool autoLeave, const JoinExistingGame_t &joinGame); void HandleNetPacketJoinGame(boost::shared_ptr<SessionData> session, const JoinExistingGameMessage &joinGame);
void HandleNetPacketRejoinGame(boost::shared_ptr<SessionData> session, bool autoLeave, const RejoinExistingGame_t &rejoinGame); void HandleNetPacketRejoinGame(boost::shared_ptr<SessionData> session, const RejoinExistingGameMessage &rejoinGame);
void HandleNetPacketChatRequest(boost::shared_ptr<SessionData> session, const ChatRequestMessage_t &chatRequest); void HandleNetPacketChatRequest(boost::shared_ptr<SessionData> session, const ChatRequestMessage &chatRequest);
void HandleNetPacketRejectGameInvitation(boost::shared_ptr<SessionData> session, const RejectGameInvitationMessage_t &reject); void HandleNetPacketRejectGameInvitation(boost::shared_ptr<SessionData> session, const RejectGameInvitationMessage &reject);
void HandleNetPacketReportGame(boost::shared_ptr<SessionData> session, const ReportGameMessage_t &report); void HandleNetPacketReportGame(boost::shared_ptr<SessionData> session, const ReportGameMessage &report);
// TODO would be better to use state pattern here. // TODO would be better to use state pattern here.
void AuthChallenge(boost::shared_ptr<SessionData> session, const std::string &secret); void AuthChallenge(boost::shared_ptr<SessionData> session, const std::string &secret);
void CheckAvatarBlacklist(boost::shared_ptr<SessionData> session); void CheckAvatarBlacklist(boost::shared_ptr<SessionData> session);
+3 -6
View File
@@ -21,15 +21,12 @@
#ifdef _WIN32 #ifdef _WIN32
#ifdef __GNUC__ /* mingw provides stdint.h */
#include <stdint.h> #include <stdint.h>
typedef uint16_t u_int16_t; typedef uint16_t u_int16_t;
typedef uint32_t u_int32_t; typedef uint32_t u_int32_t;
#else #ifndef __GNUC__ /* ssize_t not defined in MSVC */
typedef unsigned __int16 u_int16_t; typedef _W64 int ssize_t;
typedef unsigned __int32 u_int32_t; #define _SSIZE_T_
typedef __int16 int16_t;
typedef __int32 int32_t;
#endif #endif
typedef unsigned char u_char; typedef unsigned char u_char;
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff