Show and update admin player of a game even when in lobby and not in the game.
This commit is contained in:
@@ -42,6 +42,7 @@ public:
|
||||
virtual void SignalNetClientGameListNew(unsigned gameId) = 0;
|
||||
virtual void SignalNetClientGameListRemove(unsigned gameId) = 0;
|
||||
virtual void SignalNetClientGameListUpdateMode(unsigned gameId, GameMode mode) = 0;
|
||||
virtual void SignalNetClientGameListUpdateAdmin(unsigned gameId, unsigned adminPlayerId) = 0;
|
||||
virtual void SignalNetClientGameListPlayerJoined(unsigned gameId, unsigned playerId) = 0;
|
||||
virtual void SignalNetClientGameListPlayerLeft(unsigned gameId, unsigned playerId) = 0;
|
||||
|
||||
|
||||
@@ -128,6 +128,7 @@ protected:
|
||||
unsigned GetGameIdByName(const std::string &name) const;
|
||||
void AddGameInfo(unsigned gameId, const GameInfo &info);
|
||||
void UpdateGameInfoMode(unsigned gameId, GameMode mode);
|
||||
void UpdateGameInfoAdmin(unsigned gameId, unsigned adminPlayerId);
|
||||
void RemoveGameInfo(unsigned gameId);
|
||||
void ModifyGameInfoAddPlayer(unsigned gameId, unsigned playerId);
|
||||
void ModifyGameInfoRemovePlayer(unsigned gameId, unsigned playerId);
|
||||
|
||||
@@ -488,6 +488,12 @@ AbstractClientStateReceiving::Process(ClientThread &client)
|
||||
tmpPacket->ToNetPacketGameListPlayerLeft()->GetData(playerLeftData);
|
||||
client.ModifyGameInfoRemovePlayer(playerLeftData.gameId, playerLeftData.playerId);
|
||||
}
|
||||
else if (tmpPacket->ToNetPacketGameListAdminChanged())
|
||||
{
|
||||
NetPacketGameListAdminChanged::Data adminChangedData;
|
||||
tmpPacket->ToNetPacketGameListAdminChanged()->GetData(adminChangedData);
|
||||
client.UpdateGameInfoAdmin(adminChangedData.gameId, adminChangedData.newAdminplayerId);
|
||||
}
|
||||
else if (tmpPacket->ToNetPacketAvatarHeader())
|
||||
{
|
||||
NetPacketAvatarHeader::Data headerData;
|
||||
|
||||
@@ -784,6 +784,23 @@ ClientThread::UpdateGameInfoMode(unsigned gameId, GameMode mode)
|
||||
GetCallback().SignalNetClientGameListUpdateMode(gameId, mode);
|
||||
}
|
||||
|
||||
void
|
||||
ClientThread::UpdateGameInfoAdmin(unsigned gameId, unsigned adminPlayerId)
|
||||
{
|
||||
bool found = false;
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_gameInfoMapMutex);
|
||||
GameInfoMap::iterator pos = m_gameInfoMap.find(gameId);
|
||||
if (pos != m_gameInfoMap.end())
|
||||
{
|
||||
found = true;
|
||||
(*pos).second.adminPlayerId = adminPlayerId;
|
||||
}
|
||||
}
|
||||
if (found)
|
||||
GetCallback().SignalNetClientGameListUpdateAdmin(gameId, adminPlayerId);
|
||||
}
|
||||
|
||||
void
|
||||
ClientThread::RemoveGameInfo(unsigned gameId)
|
||||
{
|
||||
|
||||
@@ -38,6 +38,7 @@ using namespace std;
|
||||
#define NET_TYPE_GAME_LIST_UPDATE 0x0011
|
||||
#define NET_TYPE_GAME_LIST_PLAYER_JOINED 0x0012
|
||||
#define NET_TYPE_GAME_LIST_PLAYER_LEFT 0x0013
|
||||
#define NET_TYPE_GAME_LIST_ADMIN_CHANGED 0x0014
|
||||
#define NET_TYPE_RETRIEVE_PLAYER_INFO 0x0020
|
||||
#define NET_TYPE_PLAYER_INFO 0x0021
|
||||
#define NET_TYPE_UNKNOWN_PLAYER_ID 0x0022
|
||||
@@ -197,6 +198,7 @@ struct GCC_PACKED NetPacketGameListNewData
|
||||
{
|
||||
NetPacketHeader head;
|
||||
u_int32_t gameId;
|
||||
u_int32_t adminPlayerId;
|
||||
u_int16_t gameMode;
|
||||
u_int16_t gameNameLength;
|
||||
u_int16_t curNumberOfPlayers;
|
||||
@@ -226,6 +228,13 @@ struct GCC_PACKED NetPacketGameListPlayerLeftData
|
||||
u_int32_t playerId;
|
||||
};
|
||||
|
||||
struct GCC_PACKED NetPacketGameListAdminChangedData
|
||||
{
|
||||
NetPacketHeader head;
|
||||
u_int32_t gameId;
|
||||
u_int32_t newAdminPlayerId;
|
||||
};
|
||||
|
||||
struct GCC_PACKED NetPacketRetrievePlayerInfoData
|
||||
{
|
||||
NetPacketHeader head;
|
||||
@@ -638,6 +647,9 @@ NetPacket::Create(char *data, unsigned &dataSize)
|
||||
case NET_TYPE_GAME_LIST_PLAYER_LEFT:
|
||||
tmpPacket = boost::shared_ptr<NetPacket>(new NetPacketGameListPlayerLeft);
|
||||
break;
|
||||
case NET_TYPE_GAME_LIST_ADMIN_CHANGED:
|
||||
tmpPacket = boost::shared_ptr<NetPacket>(new NetPacketGameListAdminChanged);
|
||||
break;
|
||||
case NET_TYPE_RETRIEVE_PLAYER_INFO:
|
||||
tmpPacket = boost::shared_ptr<NetPacket>(new NetPacketRetrievePlayerInfo);
|
||||
break;
|
||||
@@ -881,6 +893,12 @@ NetPacket::ToNetPacketGameListPlayerLeft() const
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const NetPacketGameListAdminChanged *
|
||||
NetPacket::ToNetPacketGameListAdminChanged() const
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const NetPacketRetrievePlayerInfo *
|
||||
NetPacket::ToNetPacketRetrievePlayerInfo() const
|
||||
{
|
||||
@@ -1668,6 +1686,7 @@ NetPacketGameListNew::SetData(const NetPacketGameListNew::Data &inData)
|
||||
|
||||
// Set the data.
|
||||
tmpData->gameId = htonl(inData.gameId);
|
||||
tmpData->adminPlayerId = htonl(inData.gameInfo.adminPlayerId);
|
||||
tmpData->gameMode = htons(inData.gameInfo.mode);
|
||||
tmpData->gameNameLength = htons(gameNameLen);
|
||||
tmpData->curNumberOfPlayers = htons(curNumPlayers);
|
||||
@@ -1705,6 +1724,7 @@ NetPacketGameListNew::GetData(NetPacketGameListNew::Data &outData) const
|
||||
int manualBlindsSize = numManualBlinds * sizeof(u_int32_t);
|
||||
|
||||
outData.gameId = ntohl(tmpData->gameId);
|
||||
outData.gameInfo.adminPlayerId = ntohl(tmpData->adminPlayerId);
|
||||
outData.gameInfo.mode = static_cast<GameMode>(ntohs(tmpData->gameMode));
|
||||
u_int16_t gameNameLen = ntohs(tmpData->gameNameLength);
|
||||
u_int16_t curNumPlayers = ntohs(tmpData->curNumberOfPlayers);
|
||||
@@ -1949,6 +1969,66 @@ NetPacketGameListPlayerLeft::InternalCheck(const NetPacketHeader*) const
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
NetPacketGameListAdminChanged::NetPacketGameListAdminChanged()
|
||||
: NetPacket(NET_TYPE_GAME_LIST_ADMIN_CHANGED, sizeof(NetPacketGameListAdminChangedData), sizeof(NetPacketGameListAdminChangedData))
|
||||
{
|
||||
}
|
||||
|
||||
NetPacketGameListAdminChanged::~NetPacketGameListAdminChanged()
|
||||
{
|
||||
}
|
||||
|
||||
boost::shared_ptr<NetPacket>
|
||||
NetPacketGameListAdminChanged::Clone() const
|
||||
{
|
||||
boost::shared_ptr<NetPacket> newPacket(new NetPacketGameListAdminChanged);
|
||||
try
|
||||
{
|
||||
newPacket->SetRawData(GetRawData());
|
||||
} catch (const NetException &)
|
||||
{
|
||||
// Need to return the new packet anyway.
|
||||
}
|
||||
return newPacket;
|
||||
}
|
||||
|
||||
void
|
||||
NetPacketGameListAdminChanged::SetData(const NetPacketGameListAdminChanged::Data &inData)
|
||||
{
|
||||
NetPacketGameListAdminChangedData *tmpData = (NetPacketGameListAdminChangedData *)GetRawData();
|
||||
|
||||
// Set the data.
|
||||
tmpData->gameId = htonl(inData.gameId);
|
||||
tmpData->newAdminPlayerId = htonl(inData.newAdminplayerId);
|
||||
|
||||
// Check the packet - just in case.
|
||||
Check(GetRawData());
|
||||
}
|
||||
|
||||
void
|
||||
NetPacketGameListAdminChanged::GetData(NetPacketGameListAdminChanged::Data &outData) const
|
||||
{
|
||||
// We assume that the data is valid. Validity has already been checked.
|
||||
NetPacketGameListAdminChangedData *tmpData = (NetPacketGameListAdminChangedData *)GetRawData();
|
||||
|
||||
outData.gameId = ntohl(tmpData->gameId);
|
||||
outData.newAdminplayerId = ntohl(tmpData->newAdminPlayerId);
|
||||
}
|
||||
|
||||
const NetPacketGameListAdminChanged *
|
||||
NetPacketGameListAdminChanged::ToNetPacketGameListAdminChanged() const
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
void
|
||||
NetPacketGameListAdminChanged::InternalCheck(const NetPacketHeader*) const
|
||||
{
|
||||
// Nothing to do.
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
NetPacketRetrievePlayerInfo::NetPacketRetrievePlayerInfo()
|
||||
: NetPacket(NET_TYPE_RETRIEVE_PLAYER_INFO, sizeof(NetPacketRetrievePlayerInfoData), sizeof(NetPacketRetrievePlayerInfoData))
|
||||
{
|
||||
|
||||
@@ -247,9 +247,9 @@ ServerGameStateInit::HandleNewSession(ServerGameThread &server, SessionWrapper s
|
||||
}
|
||||
else
|
||||
{
|
||||
if (curNumPlayers == 0)
|
||||
if (session.playerData->GetUniqueId() == server.GetAdminPlayerId())
|
||||
{
|
||||
// First player is admin.
|
||||
// This is the admin player.
|
||||
session.playerData->SetRights(PLAYER_RIGHTS_ADMIN);
|
||||
}
|
||||
|
||||
|
||||
@@ -52,8 +52,9 @@ private:
|
||||
};
|
||||
|
||||
|
||||
ServerGameThread::ServerGameThread(ServerLobbyThread &lobbyThread, u_int32_t id, const string &name, const string &pwd, GuiInterface &gui, ConfigFile *playerConfig)
|
||||
: m_lobbyThread(lobbyThread), m_gui(gui), m_id(id), m_name(name), m_password(pwd), m_playerConfig(playerConfig), m_curState(NULL), m_gameNum(1)
|
||||
ServerGameThread::ServerGameThread(ServerLobbyThread &lobbyThread, u_int32_t id, const string &name, const string &pwd, unsigned adminPlayerId, GuiInterface &gui, ConfigFile *playerConfig)
|
||||
: m_lobbyThread(lobbyThread), m_adminPlayerId(adminPlayerId), m_gui(gui), m_id(id),
|
||||
m_name(name), m_password(pwd), m_playerConfig(playerConfig), m_curState(NULL), m_gameNum(1)
|
||||
{
|
||||
m_senderCallback.reset(new ServerSenderCallback(*this));
|
||||
m_sender.reset(new SenderThread(GetSenderCallback()));
|
||||
@@ -277,6 +278,20 @@ ServerGameThread::IsRunning() const
|
||||
return m_game.get() != NULL;
|
||||
}
|
||||
|
||||
unsigned
|
||||
ServerGameThread::GetAdminPlayerId() const
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_adminPlayerIdMutex);
|
||||
return m_adminPlayerId;
|
||||
}
|
||||
|
||||
void
|
||||
ServerGameThread::SetAdminPlayerId(unsigned playerId)
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_adminPlayerIdMutex);
|
||||
m_adminPlayerId = playerId;
|
||||
}
|
||||
|
||||
void
|
||||
ServerGameThread::AddComputerPlayer(boost::shared_ptr<PlayerData> player)
|
||||
{
|
||||
@@ -321,13 +336,6 @@ ServerGameThread::GracefulRemoveSession(SessionWrapper session)
|
||||
void
|
||||
ServerGameThread::RemovePlayerData(boost::shared_ptr<PlayerData> player)
|
||||
{
|
||||
// Send "Player Left" to clients.
|
||||
boost::shared_ptr<NetPacket> thisPlayerLeft(new NetPacketPlayerLeft);
|
||||
NetPacketPlayerLeft::Data thisPlayerLeftData;
|
||||
thisPlayerLeftData.playerId = player->GetUniqueId();
|
||||
static_cast<NetPacketPlayerLeft *>(thisPlayerLeft.get())->SetData(thisPlayerLeftData);
|
||||
GetSessionManager().SendToAllSessions(GetSender(), thisPlayerLeft, SessionData::Game);
|
||||
|
||||
if (player->GetRights() == PLAYER_RIGHTS_ADMIN)
|
||||
{
|
||||
// Find new admin for the game
|
||||
@@ -335,6 +343,7 @@ ServerGameThread::RemovePlayerData(boost::shared_ptr<PlayerData> player)
|
||||
if (!playerList.empty())
|
||||
{
|
||||
boost::shared_ptr<PlayerData> newAdmin = playerList.front();
|
||||
SetAdminPlayerId(newAdmin->GetUniqueId());
|
||||
newAdmin->SetRights(PLAYER_RIGHTS_ADMIN);
|
||||
// Send "Game Admin Changed" to clients.
|
||||
boost::shared_ptr<NetPacket> adminChanged(new NetPacketGameAdminChanged);
|
||||
@@ -342,11 +351,20 @@ ServerGameThread::RemovePlayerData(boost::shared_ptr<PlayerData> player)
|
||||
adminChangedData.playerId = newAdmin->GetUniqueId(); // Choose next player as admin.
|
||||
static_cast<NetPacketGameAdminChanged *>(adminChanged.get())->SetData(adminChangedData);
|
||||
GetSessionManager().SendToAllSessions(GetSender(), adminChanged, SessionData::Game);
|
||||
|
||||
GetLobbyThread().NotifyGameAdminChanged(GetId(), newAdmin->GetUniqueId());
|
||||
}
|
||||
}
|
||||
// Reset player rights.
|
||||
player->SetRights(PLAYER_RIGHTS_NORMAL);
|
||||
|
||||
// Send "Player Left" to clients.
|
||||
boost::shared_ptr<NetPacket> thisPlayerLeft(new NetPacketPlayerLeft);
|
||||
NetPacketPlayerLeft::Data thisPlayerLeftData;
|
||||
thisPlayerLeftData.playerId = player->GetUniqueId();
|
||||
static_cast<NetPacketPlayerLeft *>(thisPlayerLeft.get())->SetData(thisPlayerLeftData);
|
||||
GetSessionManager().SendToAllSessions(GetSender(), thisPlayerLeft, SessionData::Game);
|
||||
|
||||
GetLobbyThread().NotifyPlayerLeftGame(GetId(), player->GetUniqueId());
|
||||
}
|
||||
|
||||
|
||||
@@ -154,6 +154,19 @@ ServerLobbyThread::NotifyPlayerLeftGame(unsigned gameId, unsigned playerId)
|
||||
m_gameSessionManager.SendToAllSessions(GetSender(), packet, SessionData::Game);
|
||||
}
|
||||
|
||||
void
|
||||
ServerLobbyThread::NotifyGameAdminChanged(unsigned gameId, unsigned newAdminPlayerId)
|
||||
{
|
||||
// Send notification to players in lobby.
|
||||
boost::shared_ptr<NetPacket> packet(new NetPacketGameListAdminChanged);
|
||||
NetPacketGameListAdminChanged::Data packetData;
|
||||
packetData.gameId = gameId;
|
||||
packetData.newAdminplayerId = newAdminPlayerId;
|
||||
static_cast<NetPacketGameListAdminChanged *>(packet.get())->SetData(packetData);
|
||||
m_sessionManager.SendToAllSessions(GetSender(), packet, SessionData::Established);
|
||||
m_gameSessionManager.SendToAllSessions(GetSender(), packet, SessionData::Game);
|
||||
}
|
||||
|
||||
void
|
||||
ServerLobbyThread::NotifyStartingGame(unsigned gameId)
|
||||
{
|
||||
@@ -556,9 +569,11 @@ ServerLobbyThread::HandleNetPacketCreateGame(SessionWrapper session, const NetPa
|
||||
|
||||
boost::shared_ptr<ServerGameThread> game(
|
||||
new ServerGameThread(
|
||||
*this, GetNextGameId(),
|
||||
*this,
|
||||
GetNextGameId(),
|
||||
createGameData.gameName,
|
||||
createGameData.password,
|
||||
session.playerData->GetUniqueId(),
|
||||
GetGui(),
|
||||
m_playerConfig));
|
||||
game->Init(createGameData.gameData);
|
||||
@@ -870,6 +885,7 @@ ServerLobbyThread::CreateNetPacketGameListNew(const ServerGameThread &game)
|
||||
boost::shared_ptr<NetPacket> packet(new NetPacketGameListNew);
|
||||
NetPacketGameListNew::Data packetData;
|
||||
packetData.gameId = game.GetId();
|
||||
packetData.gameInfo.adminPlayerId = game.GetAdminPlayerId();
|
||||
packetData.gameInfo.mode = game.IsRunning() ? GAME_MODE_STARTED : GAME_MODE_CREATED;
|
||||
packetData.gameInfo.name = game.GetName();
|
||||
packetData.gameInfo.data = game.GetGameData();
|
||||
|
||||
@@ -57,6 +57,7 @@ class NetPacketGameListNew;
|
||||
class NetPacketGameListUpdate;
|
||||
class NetPacketGameListPlayerJoined;
|
||||
class NetPacketGameListPlayerLeft;
|
||||
class NetPacketGameListAdminChanged;
|
||||
class NetPacketRetrievePlayerInfo;
|
||||
class NetPacketPlayerInfo;
|
||||
class NetPacketUnknownPlayerId;
|
||||
@@ -117,6 +118,7 @@ public:
|
||||
virtual const NetPacketGameListUpdate *ToNetPacketGameListUpdate() const;
|
||||
virtual const NetPacketGameListPlayerJoined *ToNetPacketGameListPlayerJoined() const;
|
||||
virtual const NetPacketGameListPlayerLeft *ToNetPacketGameListPlayerLeft() const;
|
||||
virtual const NetPacketGameListAdminChanged *ToNetPacketGameListAdminChanged() const;
|
||||
virtual const NetPacketRetrievePlayerInfo *ToNetPacketRetrievePlayerInfo() const;
|
||||
virtual const NetPacketPlayerInfo *ToNetPacketPlayerInfo() const;
|
||||
virtual const NetPacketUnknownPlayerId *ToNetPacketUnknownPlayerId() const;
|
||||
@@ -436,6 +438,30 @@ protected:
|
||||
virtual void InternalCheck(const NetPacketHeader* data) const;
|
||||
};
|
||||
|
||||
class NetPacketGameListAdminChanged : public NetPacket
|
||||
{
|
||||
public:
|
||||
struct Data
|
||||
{
|
||||
u_int32_t gameId;
|
||||
u_int32_t newAdminplayerId;
|
||||
};
|
||||
|
||||
NetPacketGameListAdminChanged();
|
||||
virtual ~NetPacketGameListAdminChanged();
|
||||
|
||||
virtual boost::shared_ptr<NetPacket> Clone() const;
|
||||
|
||||
void SetData(const Data &inData);
|
||||
void GetData(Data &outData) const;
|
||||
|
||||
virtual const NetPacketGameListAdminChanged *ToNetPacketGameListAdminChanged() const;
|
||||
|
||||
protected:
|
||||
|
||||
virtual void InternalCheck(const NetPacketHeader* data) const;
|
||||
};
|
||||
|
||||
class NetPacketRetrievePlayerInfo : public NetPacket
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -42,7 +42,8 @@ class Game;
|
||||
class ServerGameThread : public Thread
|
||||
{
|
||||
public:
|
||||
ServerGameThread(ServerLobbyThread &lobbyThread, u_int32_t id, const std::string &name, const std::string &pwd, GuiInterface &gui, ConfigFile *playerConfig);
|
||||
ServerGameThread(
|
||||
ServerLobbyThread &lobbyThread, u_int32_t id, const std::string &name, const std::string &pwd, unsigned adminPlayerId, GuiInterface &gui, ConfigFile *playerConfig);
|
||||
virtual ~ServerGameThread();
|
||||
|
||||
void Init(const GameData &gameData);
|
||||
@@ -68,6 +69,9 @@ public:
|
||||
|
||||
bool IsRunning() const;
|
||||
|
||||
unsigned GetAdminPlayerId() const;
|
||||
void SetAdminPlayerId(unsigned playerId);
|
||||
|
||||
// should be protected, but is needed in function.
|
||||
const Game &GetGame() const;
|
||||
Game &GetGame();
|
||||
@@ -127,6 +131,9 @@ private:
|
||||
PlayerDataList m_computerPlayerList;
|
||||
mutable boost::mutex m_computerPlayerListMutex;
|
||||
|
||||
unsigned m_adminPlayerId;
|
||||
mutable boost::mutex m_adminPlayerIdMutex;
|
||||
|
||||
ServerLobbyThread &m_lobbyThread;
|
||||
std::auto_ptr<ReceiverHelper> m_receiver;
|
||||
std::auto_ptr<SenderThread> m_sender;
|
||||
|
||||
@@ -58,6 +58,7 @@ public:
|
||||
void SessionError(SessionWrapper session, int errorCode);
|
||||
void NotifyPlayerJoinedGame(unsigned gameId, unsigned playerId);
|
||||
void NotifyPlayerLeftGame(unsigned gameId, unsigned playerId);
|
||||
void NotifyGameAdminChanged(unsigned gameId, unsigned newAdminPlayerId);
|
||||
void NotifyStartingGame(unsigned gameId);
|
||||
void NotifyReopeningGame(unsigned gameId);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user