(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
+1 -1
View File
@@ -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)
{
}
+5 -3
View File
@@ -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);
+1 -1
View File
@@ -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());
}
}
+2 -2
View File
@@ -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));
+4 -8
View File
@@ -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;
}
+1 -1
View File
@@ -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);