From f10e4c34231fc50d2c8c06c91a2f1950c740d006 Mon Sep 17 00:00:00 2001 From: lotodore Date: Wed, 24 Mar 2010 15:54:04 +0000 Subject: [PATCH] Extending player rights by guest mode. Kind of broken, because it interferes with the current system where you automatically gain admin rights when creating a game. --- pokerth_protocol.pro | 2 ++ src/net/common/clientstate.cpp | 12 +++++------- src/net/common/servergamestate.cpp | 5 +++-- src/net/common/serverlobbythread.cpp | 3 ++- src/playerdata.h | 4 +++- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/pokerth_protocol.pro b/pokerth_protocol.pro index fab2be4c..fdcd7f46 100644 --- a/pokerth_protocol.pro +++ b/pokerth_protocol.pro @@ -124,6 +124,7 @@ HEADERS += src/third_party/asn1/AllInShowCardsMessage.h \ src/third_party/asn1/per_support.h \ src/third_party/asn1/PlayerAllIn.h \ src/third_party/asn1/PlayerInfoData.h \ + src/third_party/asn1/PlayerInfoRights.h \ src/third_party/asn1/PlayerInfoReplyMessage.h \ src/third_party/asn1/PlayerInfoRequestMessage.h \ src/third_party/asn1/PlayerListMessage.h \ @@ -192,6 +193,7 @@ SOURCES += src/third_party/asn1/ChatCleanerMessage.c \ src/third_party/asn1/PlayerInfoRequestMessage.c \ src/third_party/asn1/PlayerInfoReplyMessage.c \ src/third_party/asn1/PlayerInfoData.c \ + src/third_party/asn1/PlayerInfoRights.c \ src/third_party/asn1/PlayerAllIn.c \ src/third_party/asn1/PlayerListMessage.c \ src/third_party/asn1/per_support.c \ diff --git a/src/net/common/clientstate.cpp b/src/net/common/clientstate.cpp index 4c51a574..78183bc7 100644 --- a/src/net/common/clientstate.cpp +++ b/src/net/common/clientstate.cpp @@ -668,10 +668,8 @@ AbstractClientStateReceiving::HandlePacket(boost::shared_ptr clien PlayerInfo tmpInfo; PlayerInfoData_t *netInfo = &tmpPacket->GetMsg()->choice.playerInfoReplyMessage.playerInfoResult.choice.playerInfoData; tmpInfo.playerName = STL_STRING_FROM_OCTET_STRING(netInfo->playerName); - if (netInfo->isHuman) - tmpInfo.ptype = PLAYER_TYPE_HUMAN; - else - tmpInfo.ptype = PLAYER_TYPE_COMPUTER; + tmpInfo.ptype = netInfo->isHuman ? PLAYER_TYPE_HUMAN : PLAYER_TYPE_COMPUTER; + tmpInfo.isGuest = netInfo->playerRights == PlayerInfoRights_playerRightsGuest; if (netInfo->avatarData != NULL) { tmpInfo.hasAvatar = true; @@ -1360,7 +1358,7 @@ ClientStateWaitJoin::InternalHandlePacket(boost::shared_ptr client // Player number is 0 on init. Will be set when the game starts. boost::shared_ptr playerData( new PlayerData(client->GetGuiPlayerId(), 0, PLAYER_TYPE_HUMAN, - netJoinAck->areYouAdmin ? PLAYER_RIGHTS_ADMIN : PLAYER_RIGHTS_NORMAL)); + static_cast(netJoinAck->yourRights))); playerData->SetName(context.GetPlayerName()); playerData->SetAvatarFile(context.GetAvatarFile()); client->AddPlayerData(playerData); @@ -1446,7 +1444,7 @@ ClientStateWaitGame::InternalHandlePacket(boost::shared_ptr client if (client->GetCachedPlayerInfo(netPlayerJoined->playerId, info)) { playerData.reset( - new PlayerData(netPlayerJoined->playerId, 0, info.ptype, netPlayerJoined->isAdmin ? PLAYER_RIGHTS_ADMIN : PLAYER_RIGHTS_NORMAL)); + new PlayerData(netPlayerJoined->playerId, 0, info.ptype, static_cast(netPlayerJoined->curPlayerRights))); playerData->SetName(info.playerName); if (info.hasAvatar) { @@ -1466,7 +1464,7 @@ ClientStateWaitGame::InternalHandlePacket(boost::shared_ptr client client->RequestPlayerInfo(netPlayerJoined->playerId, true); // Use temporary data until the PlayerInfo request is completed. playerData.reset( - new PlayerData(netPlayerJoined->playerId, 0, PLAYER_TYPE_HUMAN, netPlayerJoined->isAdmin ? PLAYER_RIGHTS_ADMIN : PLAYER_RIGHTS_NORMAL)); + new PlayerData(netPlayerJoined->playerId, 0, PLAYER_TYPE_HUMAN, static_cast(netPlayerJoined->curPlayerRights))); playerData->SetName(name.str()); } client->AddPlayerData(playerData); diff --git a/src/net/common/servergamestate.cpp b/src/net/common/servergamestate.cpp index a3825956..78198b7a 100644 --- a/src/net/common/servergamestate.cpp +++ b/src/net/common/servergamestate.cpp @@ -339,7 +339,8 @@ ServerGameStateInit::HandleNewSession(boost::shared_ptr server, Sess netJoinReply->gameId = server->GetId(); netJoinReply->joinGameResult.present = joinGameResult_PR_joinGameAck; JoinGameAck_t *joinAck = &netJoinReply->joinGameResult.choice.joinGameAck; - joinAck->areYouAdmin = session.playerData->GetRights() == PLAYER_RIGHTS_ADMIN; + joinAck->yourRights = static_cast(session.playerData->GetRights()); + NetPacket::SetGameData(server->GetGameData(), &joinAck->gameInfo); OCTET_STRING_fromBuf( &joinAck->gameInfo.gameName, @@ -487,7 +488,7 @@ ServerGameStateInit::CreateNetPacketPlayerJoined(unsigned gameId, const PlayerDa netGamePlayer->gamePlayerNotification.present = gamePlayerNotification_PR_gamePlayerJoined; GamePlayerJoined_t *playerJoined = &netGamePlayer->gamePlayerNotification.choice.gamePlayerJoined; playerJoined->playerId = playerData.GetUniqueId(); - playerJoined->isAdmin = playerData.GetRights() == PLAYER_RIGHTS_ADMIN; + playerJoined->curPlayerRights = static_cast(playerData.GetRights()); return packet; } diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index 9bfa9824..8116fb73 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -1042,7 +1042,7 @@ ServerLobbyThread::HandleNetPacketInit(SessionWrapper session, const InitMessage // Create player data object. boost::shared_ptr tmpPlayerData( - new PlayerData(GetNextUniquePlayerId(), 0, PLAYER_TYPE_HUMAN, PLAYER_RIGHTS_NORMAL)); + new PlayerData(GetNextUniquePlayerId(), 0, PLAYER_TYPE_HUMAN, validGuest ? PLAYER_RIGHTS_GUEST : PLAYER_RIGHTS_NORMAL)); tmpPlayerData->SetName(playerName); tmpPlayerData->SetNetSessionData(session.sessionData); tmpPlayerData->SetAvatarMD5(avatarMD5); @@ -1197,6 +1197,7 @@ ServerLobbyThread::HandleNetPacketRetrievePlayerInfo(SessionWrapper session, con PlayerInfoData *data = &netPlayerInfoReply->playerInfoResult.choice.playerInfoData; data->isHuman = tmpPlayer->GetType() == PLAYER_TYPE_HUMAN; + data->playerRights = static_cast(tmpPlayer->GetRights()); OCTET_STRING_fromBuf( &data->playerName, tmpPlayer->GetName().c_str(), diff --git a/src/playerdata.h b/src/playerdata.h index ea5fcddf..8e78e698 100644 --- a/src/playerdata.h +++ b/src/playerdata.h @@ -40,6 +40,7 @@ enum PlayerType enum PlayerRights { + PLAYER_RIGHTS_GUEST = 1, PLAYER_RIGHTS_NORMAL, PLAYER_RIGHTS_ADMIN }; @@ -62,9 +63,10 @@ struct AvatarFile struct PlayerInfo { - PlayerInfo() : ptype(PLAYER_TYPE_HUMAN), hasAvatar(false), avatarType(AVATAR_FILE_TYPE_UNKNOWN) {} + PlayerInfo() : ptype(PLAYER_TYPE_HUMAN), isGuest(false), hasAvatar(false), avatarType(AVATAR_FILE_TYPE_UNKNOWN) {} std::string playerName; PlayerType ptype; + bool isGuest; bool hasAvatar; MD5Buf avatar; AvatarFileType avatarType;