Some work on protocol buffer details.

This commit is contained in:
lotodore
2012-09-23 23:19:53 +02:00
parent e16d4908bd
commit f0ee0af6ec
13 changed files with 1103 additions and 1096 deletions
+7 -7
View File
@@ -535,7 +535,7 @@ AbstractClientStateReceiving::HandlePacket(boost::shared_ptr<ClientThread> clien
const PlayerInfoReplyMessage::PlayerInfoData &netInfo = infoReply.playerinfodata();
tmpInfo.playerName = netInfo.playername();
tmpInfo.ptype = netInfo.ishuman() ? PLAYER_TYPE_HUMAN : PLAYER_TYPE_COMPUTER;
tmpInfo.isGuest = netInfo.playerrights() == playerRightsGuest;
tmpInfo.isGuest = netInfo.playerrights() == netPlayerRightsGuest;
if (netInfo.has_countrycode()) {
tmpInfo.countryCode = netInfo.countrycode();
}
@@ -696,7 +696,7 @@ AbstractClientStateReceiving::HandlePacket(boost::shared_ptr<ClientThread> clien
} else if (tmpPacket->GetMsg()->messagetype() == PokerTHMessage::Type_GameListUpdateMessage) {
// An existing game was updated on the server.
const GameListUpdateMessage &netListUpdate = tmpPacket->GetMsg()->gamelistupdatemessage();
if (netListUpdate.gamemode() == gameClosed)
if (netListUpdate.gamemode() == netGameClosed)
client->RemoveGameInfo(netListUpdate.gameid());
else
client->UpdateGameInfoMode(netListUpdate.gameid(), static_cast<GameMode>(netListUpdate.gamemode()));
@@ -1532,13 +1532,13 @@ ClientStateWaitHand::InternalHandlePacket(boost::shared_ptr<ClientThread> client
if (!tmpPlayer)
throw ClientException(__FILE__, __LINE__, ERR_NET_UNKNOWN_PLAYER_ID, 0);
switch (seatState) {
case playerStateNormal :
case netPlayerStateNormal :
tmpPlayer->setIsSessionActive(true);
break;
case playerStateSessionInactive :
case netPlayerStateSessionInactive :
tmpPlayer->setIsSessionActive(false);
break;
case playerStateNoMoney :
case netPlayerStateNoMoney :
tmpPlayer->setMyCash(0);
break;
}
@@ -1662,10 +1662,10 @@ ClientStateRunHand::InternalHandlePacket(boost::shared_ptr<ClientThread> client,
bool isBigBlind = false;
if (netActionDone.gamestate() == statePreflopSmallBlind) {
if (netActionDone.gamestate() == netStatePreflopSmallBlind) {
curGame->getCurrentHand()->getCurrentBeRo()->setSmallBlindPositionId(tmpPlayer->getMyUniqueID());
tmpPlayer->setMyButton(BUTTON_SMALL_BLIND);
} else if (netActionDone.gamestate() == statePreflopBigBlind) {
} else if (netActionDone.gamestate() == netStatePreflopBigBlind) {
curGame->getCurrentHand()->getCurrentBeRo()->setBigBlindPositionId(tmpPlayer->getMyUniqueID());
tmpPlayer->setMyButton(BUTTON_BIG_BLIND);
isBigBlind = true;
+3 -2
View File
@@ -84,9 +84,10 @@ void
SenderHelper::InternalStorePacket(SendBuffer &tmpBuffer, boost::shared_ptr<NetPacket> packet)
{
uint32_t packetSize = packet->GetMsg()->ByteSize();
char *buf = new char[packetSize + NET_HEADER_SIZE];
google::protobuf::uint8 *buf = new google::protobuf::uint8[packetSize + NET_HEADER_SIZE];
*((uint32_t *)buf) = htonl(packetSize);
packet->GetMsg()->SerializeToArray(&buf[NET_HEADER_SIZE], packetSize);
packet->GetMsg()->SerializeWithCachedSizesToArray(&buf[NET_HEADER_SIZE]);
SendBuffer::EncodeToBuf(buf, packetSize + NET_HEADER_SIZE, &tmpBuffer);
delete[] buf;
}
+8 -8
View File
@@ -1176,11 +1176,11 @@ ServerGameStateHand::StartNewHand(boost::shared_ptr<ServerGame> server)
while (player_i != player_end && playerCounter < server->GetStartData().numberOfPlayers) {
NetPlayerState seatState;
if (!(*player_i)->getMyActiveStatus()) {
seatState = playerStateNoMoney;
seatState = netPlayerStateNoMoney;
} else if (!(*player_i)->isSessionActive()) {
seatState = playerStateSessionInactive;
seatState = netPlayerStateSessionInactive;
} else {
seatState = playerStateNormal;
seatState = netPlayerStateNormal;
}
netHandStart->add_seatstates(seatState);
++player_i;
@@ -1209,7 +1209,7 @@ ServerGameStateHand::StartNewHand(boost::shared_ptr<ServerGame> server)
notifySmallBlind->GetMsg()->set_messagetype(PokerTHMessage::Type_PlayersActionDoneMessage);
PlayersActionDoneMessage *netSmallBlind = notifySmallBlind->GetMsg()->mutable_playersactiondonemessage();
netSmallBlind->set_gameid(server->GetId());
netSmallBlind->set_gamestate(statePreflopSmallBlind);
netSmallBlind->set_gamestate(netStatePreflopSmallBlind);
netSmallBlind->set_playerid(tmpPlayer->getMyUniqueID());
netSmallBlind->set_playeraction(static_cast<NetPlayerAction>(tmpPlayer->getMyAction()));
netSmallBlind->set_totalplayerbet(tmpPlayer->getMySet());
@@ -1231,7 +1231,7 @@ ServerGameStateHand::StartNewHand(boost::shared_ptr<ServerGame> server)
notifyBigBlind->GetMsg()->set_messagetype(PokerTHMessage::Type_PlayersActionDoneMessage);
PlayersActionDoneMessage *netBigBlind = notifyBigBlind->GetMsg()->mutable_playersactiondonemessage();
netBigBlind->set_gameid(server->GetId());
netBigBlind->set_gamestate(statePreflopBigBlind);
netBigBlind->set_gamestate(netStatePreflopBigBlind);
netBigBlind->set_playerid(tmpPlayer->getMyUniqueID());
netBigBlind->set_playeraction(static_cast<NetPlayerAction>(tmpPlayer->getMyAction()));
netBigBlind->set_totalplayerbet(tmpPlayer->getMySet());
@@ -1431,13 +1431,13 @@ ServerGameStateWaitPlayerAction::InternalProcessPacket(boost::shared_ptr<ServerG
}
// If the client omitted some values, fill them in.
if (netMyAction->myaction() == actionCall && netMyAction->myrelativebet() == 0) {
if (netMyAction->myaction() == netActionCall && netMyAction->myrelativebet() == 0) {
if (curGame.getCurrentHand()->getCurrentBeRo()->getHighestSet() >= tmpPlayer->getMySet() + tmpPlayer->getMyCash())
netMyAction->set_myaction(actionAllIn);
netMyAction->set_myaction(netActionAllIn);
else
netMyAction->set_myrelativebet(curGame.getCurrentHand()->getCurrentBeRo()->getHighestSet() - tmpPlayer->getMySet());
}
if (netMyAction->myaction() == actionAllIn && netMyAction->myrelativebet() == 0)
if (netMyAction->myaction() == netActionAllIn && netMyAction->myrelativebet() == 0)
netMyAction->set_myrelativebet(tmpPlayer->getMyCash());
// Check whether the action is valid.
+2 -2
View File
@@ -1172,7 +1172,7 @@ ServerLobbyThread::HandleNetPacketRetrievePlayerInfo(boost::shared_ptr<SessionDa
data->set_playername(tmpPlayer->GetName());
data->set_ishuman(tmpPlayer->GetType() == PLAYER_TYPE_HUMAN);
data->set_playerrights(static_cast<PlayerInfoRights>(tmpPlayer->GetRights()));
data->set_playerrights(static_cast<NetPlayerInfoRights>(tmpPlayer->GetRights()));
if (!tmpPlayer->GetCountry().empty()) {
data->set_countrycode(tmpPlayer->GetCountry());
}
@@ -2119,7 +2119,7 @@ ServerLobbyThread::CreateNetPacketGameListNew(const ServerGame &game)
GameListNewMessage *netGameList = packet->GetMsg()->mutable_gamelistnewmessage();
netGameList->set_gameid(game.GetId());
netGameList->set_adminplayerid(game.GetAdminPlayerId());
netGameList->set_gamemode(game.IsRunning() ? gameStarted : gameCreated);
netGameList->set_gamemode(game.IsRunning() ? netGameStarted : netGameCreated);
NetPacket::SetGameData(game.GetGameData(), *netGameList->mutable_gameinfo());
netGameList->mutable_gameinfo()->set_gamename(game.GetName());
netGameList->set_isprivate(game.IsPasswordProtected());