(Hopefully) fixing guest & game admin stuff.

This commit is contained in:
lotodore
2010-03-26 21:41:35 +00:00
parent 0cb1f11a52
commit a02a9cacf6
10 changed files with 39 additions and 25 deletions
+6
View File
@@ -25,6 +25,7 @@
#include <net/receivebuffer.h> #include <net/receivebuffer.h>
#include <net/sessiondata.h> #include <net/sessiondata.h>
#include <playerdata.h>
class ClientContext class ClientContext
@@ -73,6 +74,10 @@ public:
{return m_playerName;} {return m_playerName;}
void SetPlayerName(const std::string &playerName) void SetPlayerName(const std::string &playerName)
{m_playerName = playerName;} {m_playerName = playerName;}
PlayerRights GetPlayerRights() const
{return m_playerRights;}
void SetPlayerRights(PlayerRights rights)
{m_playerRights = rights;}
const std::string &GetAvatarFile() const const std::string &GetAvatarFile() const
{return m_avatarFile;} {return m_avatarFile;}
void SetAvatarFile(const std::string &avatarFile) void SetAvatarFile(const std::string &avatarFile)
@@ -101,6 +106,7 @@ private:
std::string m_avatarServerAddr; std::string m_avatarServerAddr;
std::string m_password; std::string m_password;
std::string m_playerName; std::string m_playerName;
PlayerRights m_playerRights;
std::string m_avatarFile; std::string m_avatarFile;
std::string m_cacheDir; std::string m_cacheDir;
bool m_hasSubscribedLobbyMsg; bool m_hasSubscribedLobbyMsg;
+1 -1
View File
@@ -23,7 +23,7 @@
ClientContext::ClientContext() ClientContext::ClientContext()
: m_sctp(false), m_addrFamily(AF_INET), m_useServerList(false), m_serverPort(0), : m_sctp(false), m_addrFamily(AF_INET), m_useServerList(false), m_serverPort(0),
m_hasSubscribedLobbyMsg(true) m_playerRights(PLAYER_RIGHTS_NORMAL), m_hasSubscribedLobbyMsg(true)
{ {
} }
+5 -3
View File
@@ -1088,6 +1088,7 @@ ClientStateWaitEnterLogin::TimerLoop(const boost::system::error_code& ec, boost:
if (loginData.isGuest) if (loginData.isGuest)
{ {
context.SetPassword(""); context.SetPassword("");
context.SetPlayerRights(PLAYER_RIGHTS_GUEST);
netInit->login.present = login_PR_guestLogin; netInit->login.present = login_PR_guestLogin;
GuestLogin_t *guestLogin = &netInit->login.choice.guestLogin; GuestLogin_t *guestLogin = &netInit->login.choice.guestLogin;
OCTET_STRING_fromBuf(&guestLogin->nickName, OCTET_STRING_fromBuf(&guestLogin->nickName,
@@ -1358,7 +1359,7 @@ ClientStateWaitJoin::InternalHandlePacket(boost::shared_ptr<ClientThread> client
// Player number is 0 on init. Will be set when the game starts. // Player number is 0 on init. Will be set when the game starts.
boost::shared_ptr<PlayerData> playerData( boost::shared_ptr<PlayerData> playerData(
new PlayerData(client->GetGuiPlayerId(), 0, PLAYER_TYPE_HUMAN, new PlayerData(client->GetGuiPlayerId(), 0, PLAYER_TYPE_HUMAN,
static_cast<PlayerRights>(netJoinAck->yourRights))); context.GetPlayerRights(), netJoinAck->areYouGameAdmin));
playerData->SetName(context.GetPlayerName()); playerData->SetName(context.GetPlayerName());
playerData->SetAvatarFile(context.GetAvatarFile()); playerData->SetAvatarFile(context.GetAvatarFile());
client->AddPlayerData(playerData); client->AddPlayerData(playerData);
@@ -1444,7 +1445,8 @@ ClientStateWaitGame::InternalHandlePacket(boost::shared_ptr<ClientThread> client
if (client->GetCachedPlayerInfo(netPlayerJoined->playerId, info)) if (client->GetCachedPlayerInfo(netPlayerJoined->playerId, info))
{ {
playerData.reset( playerData.reset(
new PlayerData(netPlayerJoined->playerId, 0, info.ptype, static_cast<PlayerRights>(netPlayerJoined->curPlayerRights))); new PlayerData(netPlayerJoined->playerId, 0, info.ptype,
info.isGuest ? PLAYER_RIGHTS_GUEST : PLAYER_RIGHTS_NORMAL, netPlayerJoined->isGameAdmin));
playerData->SetName(info.playerName); playerData->SetName(info.playerName);
if (info.hasAvatar) if (info.hasAvatar)
{ {
@@ -1464,7 +1466,7 @@ ClientStateWaitGame::InternalHandlePacket(boost::shared_ptr<ClientThread> client
client->RequestPlayerInfo(netPlayerJoined->playerId, true); client->RequestPlayerInfo(netPlayerJoined->playerId, true);
// Use temporary data until the PlayerInfo request is completed. // Use temporary data until the PlayerInfo request is completed.
playerData.reset( playerData.reset(
new PlayerData(netPlayerJoined->playerId, 0, PLAYER_TYPE_HUMAN, static_cast<PlayerRights>(netPlayerJoined->curPlayerRights))); new PlayerData(netPlayerJoined->playerId, 0, PLAYER_TYPE_HUMAN, PLAYER_RIGHTS_NORMAL, netPlayerJoined->isGameAdmin));
playerData->SetName(name.str()); playerData->SetName(name.str());
} }
client->AddPlayerData(playerData); client->AddPlayerData(playerData);
+1 -1
View File
@@ -675,7 +675,7 @@ ClientThread::SetNewGameAdmin(unsigned id)
boost::shared_ptr<PlayerData> playerData = GetPlayerDataByUniqueId(id); boost::shared_ptr<PlayerData> playerData = GetPlayerDataByUniqueId(id);
if (playerData.get()) if (playerData.get())
{ {
playerData->SetRights(PLAYER_RIGHTS_ADMIN); playerData->SetGameAdmin(true);
GetCallback().SignalNetClientNewGameAdmin(id, playerData->GetName()); GetCallback().SignalNetClientNewGameAdmin(id, playerData->GetName());
} }
} }
+2 -2
View File
@@ -574,7 +574,7 @@ ServerGame::RemovePlayerData(boost::shared_ptr<PlayerData> player, int reason)
{ {
boost::shared_ptr<PlayerData> newAdmin = playerList.front(); boost::shared_ptr<PlayerData> newAdmin = playerList.front();
SetAdminPlayerId(newAdmin->GetUniqueId()); SetAdminPlayerId(newAdmin->GetUniqueId());
newAdmin->SetRights(PLAYER_RIGHTS_ADMIN); newAdmin->SetGameAdmin(true);
// 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.
@@ -592,7 +592,7 @@ ServerGame::RemovePlayerData(boost::shared_ptr<PlayerData> player, int reason)
} }
} }
// Reset player rights. // Reset player rights.
player->SetRights(PLAYER_RIGHTS_NORMAL); 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(NetPacket::Alloc));
+4 -8
View File
@@ -326,11 +326,7 @@ ServerGameStateInit::HandleNewSession(boost::shared_ptr<ServerGame> server, Sess
} }
else else
{ {
if (session.playerData->GetUniqueId() == server->GetAdminPlayerId()) session.playerData->SetGameAdmin(session.playerData->GetUniqueId() == server->GetAdminPlayerId());
{
// This is the admin player.
session.playerData->SetRights(PLAYER_RIGHTS_ADMIN);
}
// Send ack to client. // Send ack to client.
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
@@ -339,7 +335,7 @@ ServerGameStateInit::HandleNewSession(boost::shared_ptr<ServerGame> server, Sess
netJoinReply->gameId = server->GetId(); netJoinReply->gameId = server->GetId();
netJoinReply->joinGameResult.present = joinGameResult_PR_joinGameAck; netJoinReply->joinGameResult.present = joinGameResult_PR_joinGameAck;
JoinGameAck_t *joinAck = &netJoinReply->joinGameResult.choice.joinGameAck; JoinGameAck_t *joinAck = &netJoinReply->joinGameResult.choice.joinGameAck;
joinAck->yourRights = static_cast<PlayerInfoRights>(session.playerData->GetRights()); joinAck->areYouGameAdmin = static_cast<PlayerInfoRights>(session.playerData->IsGameAdmin());
NetPacket::SetGameData(server->GetGameData(), &joinAck->gameInfo); NetPacket::SetGameData(server->GetGameData(), &joinAck->gameInfo);
OCTET_STRING_fromBuf( OCTET_STRING_fromBuf(
@@ -445,7 +441,7 @@ ServerGameStateInit::InternalProcessPacket(boost::shared_ptr<ServerGame> server,
for (int i = 1; i <= remainingSlots; i++) for (int i = 1; i <= remainingSlots; i++)
{ {
boost::shared_ptr<PlayerData> tmpPlayerData( boost::shared_ptr<PlayerData> tmpPlayerData(
new PlayerData(server->GetLobbyThread().GetNextUniquePlayerId(), 0, PLAYER_TYPE_COMPUTER, PLAYER_RIGHTS_NORMAL)); new PlayerData(server->GetLobbyThread().GetNextUniquePlayerId(), 0, PLAYER_TYPE_COMPUTER, PLAYER_RIGHTS_NORMAL, false));
ostringstream name; ostringstream name;
name << SERVER_COMPUTER_PLAYER_NAME << i; name << SERVER_COMPUTER_PLAYER_NAME << i;
@@ -488,7 +484,7 @@ ServerGameStateInit::CreateNetPacketPlayerJoined(unsigned gameId, const PlayerDa
netGamePlayer->gamePlayerNotification.present = gamePlayerNotification_PR_gamePlayerJoined; netGamePlayer->gamePlayerNotification.present = gamePlayerNotification_PR_gamePlayerJoined;
GamePlayerJoined_t *playerJoined = &netGamePlayer->gamePlayerNotification.choice.gamePlayerJoined; GamePlayerJoined_t *playerJoined = &netGamePlayer->gamePlayerNotification.choice.gamePlayerJoined;
playerJoined->playerId = playerData.GetUniqueId(); playerJoined->playerId = playerData.GetUniqueId();
playerJoined->curPlayerRights = static_cast<PlayerInfoRights>(playerData.GetRights()); playerJoined->isGameAdmin = playerData.IsGameAdmin();
return packet; return packet;
} }
+1 -1
View File
@@ -1042,7 +1042,7 @@ ServerLobbyThread::HandleNetPacketInit(SessionWrapper session, const InitMessage
// Create player data object. // Create player data object.
boost::shared_ptr<PlayerData> tmpPlayerData( boost::shared_ptr<PlayerData> tmpPlayerData(
new PlayerData(GetNextUniquePlayerId(), 0, PLAYER_TYPE_HUMAN, validGuest ? PLAYER_RIGHTS_GUEST : PLAYER_RIGHTS_NORMAL)); new PlayerData(GetNextUniquePlayerId(), 0, PLAYER_TYPE_HUMAN, validGuest ? PLAYER_RIGHTS_GUEST : PLAYER_RIGHTS_NORMAL, false));
tmpPlayerData->SetName(playerName); tmpPlayerData->SetName(playerName);
tmpPlayerData->SetNetSessionData(session.sessionData); tmpPlayerData->SetNetSessionData(session.sessionData);
tmpPlayerData->SetAvatarMD5(avatarMD5); tmpPlayerData->SetAvatarMD5(avatarMD5);
+13 -6
View File
@@ -21,15 +21,15 @@
using namespace std; using namespace std;
PlayerData::PlayerData(unsigned uniqueId, int number, PlayerType type, PlayerRights rights) PlayerData::PlayerData(unsigned uniqueId, int number, PlayerType type, PlayerRights rights, bool isGameAdmin)
: m_uniqueId(uniqueId), m_dbId(DB_ID_INVALID), m_number(number), m_type(type), m_rights(rights) : m_uniqueId(uniqueId), m_dbId(DB_ID_INVALID), m_number(number), m_type(type), m_rights(rights), m_isGameAdmin(isGameAdmin)
{ {
} }
PlayerData::PlayerData(const PlayerData &other) PlayerData::PlayerData(const PlayerData &other)
: m_uniqueId(other.GetUniqueId()), m_number(other.GetNumber()), m_name(other.GetName()), : m_uniqueId(other.GetUniqueId()), m_number(other.GetNumber()), m_name(other.GetName()),
m_avatarFile(other.GetAvatarFile()), m_type(other.GetType()), m_rights(other.GetRights()), m_avatarFile(other.GetAvatarFile()), m_type(other.GetType()), m_rights(other.GetRights()),
m_netSessionData(other.GetNetSessionData()) m_isGameAdmin(other.IsGameAdmin()), m_netSessionData(other.GetNetSessionData())
{ {
} }
@@ -139,11 +139,18 @@ PlayerData::GetRights() const
return m_rights; return m_rights;
} }
void bool
PlayerData::SetRights(PlayerRights rights) PlayerData::IsGameAdmin() const
{ {
boost::mutex::scoped_lock lock(m_dataMutex); boost::mutex::scoped_lock lock(m_dataMutex);
m_rights = rights; return m_isGameAdmin;
}
void
PlayerData::SetGameAdmin(bool isAdmin)
{
boost::mutex::scoped_lock lock(m_dataMutex);
m_isGameAdmin = isAdmin;
} }
unsigned unsigned
+4 -2
View File
@@ -75,7 +75,7 @@ struct PlayerInfo
class PlayerData class PlayerData
{ {
public: public:
PlayerData(unsigned uniqueId, int number, PlayerType type, PlayerRights rights); PlayerData(unsigned uniqueId, int number, PlayerType type, PlayerRights rights, bool isGameAdmin);
PlayerData(const PlayerData &other); PlayerData(const PlayerData &other);
~PlayerData(); ~PlayerData();
@@ -94,7 +94,8 @@ public:
PlayerType GetType() const; PlayerType GetType() const;
void SetType(PlayerType type); void SetType(PlayerType type);
PlayerRights GetRights() const; PlayerRights GetRights() const;
void SetRights(PlayerRights rights); bool IsGameAdmin() const;
void SetGameAdmin(bool isAdmin);
unsigned GetUniqueId() const; unsigned GetUniqueId() const;
int GetNumber() const; int GetNumber() const;
void SetNumber(int number); void SetNumber(int number);
@@ -113,6 +114,7 @@ private:
MD5Buf m_avatarMD5; MD5Buf m_avatarMD5;
PlayerType m_type; PlayerType m_type;
PlayerRights m_rights; PlayerRights m_rights;
bool m_isGameAdmin;
boost::shared_ptr<SessionData> m_netSessionData; boost::shared_ptr<SessionData> m_netSessionData;
boost::shared_ptr<AvatarFile> m_netAvatarFile; boost::shared_ptr<AvatarFile> m_netAvatarFile;
+2 -1
View File
@@ -110,7 +110,8 @@ void Session::startLocalGame(const GameData &gameData, const StartData &startDat
// UniqueId = PlayerNumber for local games. // UniqueId = PlayerNumber for local games.
boost::shared_ptr<PlayerData> playerData(new PlayerData(i, i, boost::shared_ptr<PlayerData> playerData(new PlayerData(i, i,
i == 0 ? PLAYER_TYPE_HUMAN : PLAYER_TYPE_COMPUTER, i == 0 ? PLAYER_TYPE_HUMAN : PLAYER_TYPE_COMPUTER,
i == 0 ? PLAYER_RIGHTS_ADMIN : PLAYER_RIGHTS_NORMAL)); PLAYER_RIGHTS_NORMAL,
i == 0));
playerData->SetName(myConfig->readConfigString(myName.str())); playerData->SetName(myConfig->readConfigString(myName.str()));
playerData->SetAvatarFile(myConfig->readConfigString(myAvatar.str())); playerData->SetAvatarFile(myConfig->readConfigString(myAvatar.str()));