(Hopefully) fixing guest & game admin stuff.
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
|
||||
#include <net/receivebuffer.h>
|
||||
#include <net/sessiondata.h>
|
||||
#include <playerdata.h>
|
||||
|
||||
|
||||
class ClientContext
|
||||
@@ -73,6 +74,10 @@ public:
|
||||
{return m_playerName;}
|
||||
void SetPlayerName(const std::string &playerName)
|
||||
{m_playerName = playerName;}
|
||||
PlayerRights GetPlayerRights() const
|
||||
{return m_playerRights;}
|
||||
void SetPlayerRights(PlayerRights rights)
|
||||
{m_playerRights = rights;}
|
||||
const std::string &GetAvatarFile() const
|
||||
{return m_avatarFile;}
|
||||
void SetAvatarFile(const std::string &avatarFile)
|
||||
@@ -101,6 +106,7 @@ private:
|
||||
std::string m_avatarServerAddr;
|
||||
std::string m_password;
|
||||
std::string m_playerName;
|
||||
PlayerRights m_playerRights;
|
||||
std::string m_avatarFile;
|
||||
std::string m_cacheDir;
|
||||
bool m_hasSubscribedLobbyMsg;
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
ClientContext::ClientContext()
|
||||
: m_sctp(false), m_addrFamily(AF_INET), m_useServerList(false), m_serverPort(0),
|
||||
m_hasSubscribedLobbyMsg(true)
|
||||
m_playerRights(PLAYER_RIGHTS_NORMAL), m_hasSubscribedLobbyMsg(true)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1088,6 +1088,7 @@ ClientStateWaitEnterLogin::TimerLoop(const boost::system::error_code& ec, boost:
|
||||
if (loginData.isGuest)
|
||||
{
|
||||
context.SetPassword("");
|
||||
context.SetPlayerRights(PLAYER_RIGHTS_GUEST);
|
||||
netInit->login.present = login_PR_guestLogin;
|
||||
GuestLogin_t *guestLogin = &netInit->login.choice.guestLogin;
|
||||
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.
|
||||
boost::shared_ptr<PlayerData> playerData(
|
||||
new PlayerData(client->GetGuiPlayerId(), 0, PLAYER_TYPE_HUMAN,
|
||||
static_cast<PlayerRights>(netJoinAck->yourRights)));
|
||||
context.GetPlayerRights(), netJoinAck->areYouGameAdmin));
|
||||
playerData->SetName(context.GetPlayerName());
|
||||
playerData->SetAvatarFile(context.GetAvatarFile());
|
||||
client->AddPlayerData(playerData);
|
||||
@@ -1444,7 +1445,8 @@ ClientStateWaitGame::InternalHandlePacket(boost::shared_ptr<ClientThread> client
|
||||
if (client->GetCachedPlayerInfo(netPlayerJoined->playerId, info))
|
||||
{
|
||||
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);
|
||||
if (info.hasAvatar)
|
||||
{
|
||||
@@ -1464,7 +1466,7 @@ ClientStateWaitGame::InternalHandlePacket(boost::shared_ptr<ClientThread> 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, static_cast<PlayerRights>(netPlayerJoined->curPlayerRights)));
|
||||
new PlayerData(netPlayerJoined->playerId, 0, PLAYER_TYPE_HUMAN, PLAYER_RIGHTS_NORMAL, netPlayerJoined->isGameAdmin));
|
||||
playerData->SetName(name.str());
|
||||
}
|
||||
client->AddPlayerData(playerData);
|
||||
|
||||
@@ -675,7 +675,7 @@ ClientThread::SetNewGameAdmin(unsigned id)
|
||||
boost::shared_ptr<PlayerData> playerData = GetPlayerDataByUniqueId(id);
|
||||
if (playerData.get())
|
||||
{
|
||||
playerData->SetRights(PLAYER_RIGHTS_ADMIN);
|
||||
playerData->SetGameAdmin(true);
|
||||
GetCallback().SignalNetClientNewGameAdmin(id, playerData->GetName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -574,7 +574,7 @@ ServerGame::RemovePlayerData(boost::shared_ptr<PlayerData> player, int reason)
|
||||
{
|
||||
boost::shared_ptr<PlayerData> newAdmin = playerList.front();
|
||||
SetAdminPlayerId(newAdmin->GetUniqueId());
|
||||
newAdmin->SetRights(PLAYER_RIGHTS_ADMIN);
|
||||
newAdmin->SetGameAdmin(true);
|
||||
// Notify game state on admin change
|
||||
GetState().NotifyGameAdminChanged(shared_from_this());
|
||||
// Send "Game Admin Changed" to clients.
|
||||
@@ -592,7 +592,7 @@ ServerGame::RemovePlayerData(boost::shared_ptr<PlayerData> player, int reason)
|
||||
}
|
||||
}
|
||||
// Reset player rights.
|
||||
player->SetRights(PLAYER_RIGHTS_NORMAL);
|
||||
player->SetGameAdmin(false);
|
||||
|
||||
// Send "Player Left" to clients.
|
||||
boost::shared_ptr<NetPacket> thisPlayerLeft(new NetPacket(NetPacket::Alloc));
|
||||
|
||||
@@ -326,11 +326,7 @@ ServerGameStateInit::HandleNewSession(boost::shared_ptr<ServerGame> server, Sess
|
||||
}
|
||||
else
|
||||
{
|
||||
if (session.playerData->GetUniqueId() == server->GetAdminPlayerId())
|
||||
{
|
||||
// This is the admin player.
|
||||
session.playerData->SetRights(PLAYER_RIGHTS_ADMIN);
|
||||
}
|
||||
session.playerData->SetGameAdmin(session.playerData->GetUniqueId() == server->GetAdminPlayerId());
|
||||
|
||||
// Send ack to client.
|
||||
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->joinGameResult.present = joinGameResult_PR_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);
|
||||
OCTET_STRING_fromBuf(
|
||||
@@ -445,7 +441,7 @@ ServerGameStateInit::InternalProcessPacket(boost::shared_ptr<ServerGame> server,
|
||||
for (int i = 1; i <= remainingSlots; i++)
|
||||
{
|
||||
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;
|
||||
name << SERVER_COMPUTER_PLAYER_NAME << i;
|
||||
@@ -488,7 +484,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->curPlayerRights = static_cast<PlayerInfoRights>(playerData.GetRights());
|
||||
playerJoined->isGameAdmin = playerData.IsGameAdmin();
|
||||
return packet;
|
||||
}
|
||||
|
||||
|
||||
@@ -1042,7 +1042,7 @@ ServerLobbyThread::HandleNetPacketInit(SessionWrapper session, const InitMessage
|
||||
|
||||
// Create player data object.
|
||||
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->SetNetSessionData(session.sessionData);
|
||||
tmpPlayerData->SetAvatarMD5(avatarMD5);
|
||||
|
||||
+13
-6
@@ -21,15 +21,15 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
PlayerData::PlayerData(unsigned uniqueId, int number, PlayerType type, PlayerRights rights)
|
||||
: m_uniqueId(uniqueId), m_dbId(DB_ID_INVALID), m_number(number), m_type(type), m_rights(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_isGameAdmin(isGameAdmin)
|
||||
{
|
||||
}
|
||||
|
||||
PlayerData::PlayerData(const PlayerData &other)
|
||||
: 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_netSessionData(other.GetNetSessionData())
|
||||
m_isGameAdmin(other.IsGameAdmin()), m_netSessionData(other.GetNetSessionData())
|
||||
{
|
||||
}
|
||||
|
||||
@@ -139,11 +139,18 @@ PlayerData::GetRights() const
|
||||
return m_rights;
|
||||
}
|
||||
|
||||
void
|
||||
PlayerData::SetRights(PlayerRights rights)
|
||||
bool
|
||||
PlayerData::IsGameAdmin() const
|
||||
{
|
||||
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
|
||||
|
||||
+4
-2
@@ -75,7 +75,7 @@ struct PlayerInfo
|
||||
class PlayerData
|
||||
{
|
||||
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();
|
||||
|
||||
@@ -94,7 +94,8 @@ public:
|
||||
PlayerType GetType() const;
|
||||
void SetType(PlayerType type);
|
||||
PlayerRights GetRights() const;
|
||||
void SetRights(PlayerRights rights);
|
||||
bool IsGameAdmin() const;
|
||||
void SetGameAdmin(bool isAdmin);
|
||||
unsigned GetUniqueId() const;
|
||||
int GetNumber() const;
|
||||
void SetNumber(int number);
|
||||
@@ -113,6 +114,7 @@ private:
|
||||
MD5Buf m_avatarMD5;
|
||||
PlayerType m_type;
|
||||
PlayerRights m_rights;
|
||||
bool m_isGameAdmin;
|
||||
boost::shared_ptr<SessionData> m_netSessionData;
|
||||
boost::shared_ptr<AvatarFile> m_netAvatarFile;
|
||||
|
||||
|
||||
+2
-1
@@ -110,7 +110,8 @@ void Session::startLocalGame(const GameData &gameData, const StartData &startDat
|
||||
// UniqueId = PlayerNumber for local games.
|
||||
boost::shared_ptr<PlayerData> playerData(new PlayerData(i, i,
|
||||
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->SetAvatarFile(myConfig->readConfigString(myAvatar.str()));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user