Send notification to clients when a game in the lobby was started. Mark games as running in lobby dialog.
This commit is contained in:
@@ -116,6 +116,7 @@ void ServerGuiWrapper::SignalNetClientPlayerChanged(unsigned playerId, const std
|
||||
void ServerGuiWrapper::SignalNetClientPlayerLeft(unsigned playerId, const std::string &playerName) { if (myClientcb) myClientcb->SignalNetClientPlayerLeft(playerId, playerName); }
|
||||
void ServerGuiWrapper::SignalNetClientGameListNew(unsigned gameId) { if (myClientcb) myClientcb->SignalNetClientGameListNew(gameId); }
|
||||
void ServerGuiWrapper::SignalNetClientGameListRemove(unsigned gameId) { if (myClientcb) myClientcb->SignalNetClientGameListRemove(gameId); }
|
||||
void ServerGuiWrapper::SignalNetClientGameListUpdateMode(unsigned gameId, GameMode mode) { if (myClientcb) myClientcb->SignalNetClientGameListUpdateMode(gameId, mode); }
|
||||
void ServerGuiWrapper::SignalNetClientGameListPlayerJoined(unsigned gameId, unsigned playerId) { if (myClientcb) myClientcb->SignalNetClientGameListPlayerJoined(gameId, playerId); }
|
||||
void ServerGuiWrapper::SignalNetClientGameListPlayerLeft(unsigned gameId, unsigned playerId) { if (myClientcb) myClientcb->SignalNetClientGameListPlayerLeft(gameId, playerId); }
|
||||
void ServerGuiWrapper::SignalNetClientGameStart(boost::shared_ptr<Game> game) { if (myClientcb) myClientcb->SignalNetClientGameStart(game); }
|
||||
|
||||
@@ -103,6 +103,7 @@ public:
|
||||
|
||||
void SignalNetClientGameListNew(unsigned gameId);
|
||||
void SignalNetClientGameListRemove(unsigned gameId);
|
||||
void SignalNetClientGameListUpdateMode(unsigned gameId, GameMode mode);
|
||||
void SignalNetClientGameListPlayerJoined(unsigned gameId, unsigned playerId);
|
||||
void SignalNetClientGameListPlayerLeft(unsigned gameId, unsigned playerId);
|
||||
void SignalNetClientGameStart(boost::shared_ptr<Game> game);
|
||||
|
||||
@@ -209,8 +209,11 @@ void gameLobbyDialogImpl::updateGameItem(QTreeWidgetItem *item, unsigned gameId)
|
||||
playerStr.sprintf("%u/%u", info.players.size(), info.data.maxNumberOfPlayers);
|
||||
item->setData(1, Qt::DisplayRole, playerStr);
|
||||
|
||||
if (info.isPasswordProtected)
|
||||
if (info.mode == GAME_MODE_STARTED)
|
||||
item->setData(2, Qt::DisplayRole, "X");
|
||||
|
||||
if (info.isPasswordProtected)
|
||||
item->setData(3, Qt::DisplayRole, "X");
|
||||
}
|
||||
|
||||
void gameLobbyDialogImpl::addGame(unsigned gameId)
|
||||
@@ -220,6 +223,19 @@ void gameLobbyDialogImpl::addGame(unsigned gameId)
|
||||
updateGameItem(item, gameId);
|
||||
}
|
||||
|
||||
void gameLobbyDialogImpl::updateGameMode(unsigned gameId, int /*newMode*/)
|
||||
{
|
||||
QTreeWidgetItemIterator it(treeWidget_GameList);
|
||||
while (*it) {
|
||||
if ((*it)->data(0, Qt::UserRole) == gameId)
|
||||
{
|
||||
updateGameItem(*it, gameId);
|
||||
break;
|
||||
}
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
void gameLobbyDialogImpl::removeGame(unsigned gameId)
|
||||
{
|
||||
QTreeWidgetItemIterator it(treeWidget_GameList);
|
||||
|
||||
@@ -61,6 +61,7 @@ public slots:
|
||||
void updateGameItem(QTreeWidgetItem *item, unsigned gameId);
|
||||
|
||||
void addGame(unsigned gameId);
|
||||
void updateGameMode(unsigned gameId, int newMode);
|
||||
void removeGame(unsigned gameId);
|
||||
void gameAddPlayer(unsigned gameId, unsigned playerId);
|
||||
void gameRemovePlayer(unsigned gameId, unsigned playerId);
|
||||
|
||||
@@ -129,6 +129,7 @@ void GuiWrapper::SignalNetClientPlayerLeft(unsigned playerId, const string &play
|
||||
|
||||
void GuiWrapper::SignalNetClientGameListNew(unsigned gameId) { myW->signalNetClientGameListNew(gameId); }
|
||||
void GuiWrapper::SignalNetClientGameListRemove(unsigned gameId) { myW->signalNetClientGameListRemove(gameId); }
|
||||
void GuiWrapper::SignalNetClientGameListUpdateMode(unsigned gameId, GameMode mode) { myW->signalNetClientGameListUpdateMode(gameId, mode); }
|
||||
void GuiWrapper::SignalNetClientGameListPlayerJoined(unsigned gameId, unsigned playerId) { myW->signalNetClientGameListPlayerJoined(gameId, playerId); }
|
||||
void GuiWrapper::SignalNetClientGameListPlayerLeft(unsigned gameId, unsigned playerId) { myW->signalNetClientGameListPlayerLeft(gameId, playerId); }
|
||||
|
||||
|
||||
@@ -110,6 +110,7 @@ public:
|
||||
|
||||
void SignalNetClientGameListNew(unsigned gameId);
|
||||
void SignalNetClientGameListRemove(unsigned gameId);
|
||||
void SignalNetClientGameListUpdateMode(unsigned gameId, GameMode mode);
|
||||
void SignalNetClientGameListPlayerJoined(unsigned gameId, unsigned playerId);
|
||||
void SignalNetClientGameListPlayerLeft(unsigned gameId, unsigned playerId);
|
||||
|
||||
|
||||
@@ -666,6 +666,7 @@ mainWindowImpl::mainWindowImpl(ConfigFile *c, QMainWindow *parent)
|
||||
|
||||
connect(this, SIGNAL(signalNetClientGameListNew(unsigned)), myGameLobbyDialog, SLOT(addGame(unsigned)));
|
||||
connect(this, SIGNAL(signalNetClientGameListRemove(unsigned)), myGameLobbyDialog, SLOT(removeGame(unsigned)));
|
||||
connect(this, SIGNAL(signalNetClientGameListUpdateMode(unsigned, int)), myGameLobbyDialog, SLOT(updateGameMode(unsigned, int)));
|
||||
connect(this, SIGNAL(signalNetClientGameListPlayerJoined(unsigned, unsigned)), myGameLobbyDialog, SLOT(gameAddPlayer(unsigned, unsigned)));
|
||||
connect(this, SIGNAL(signalNetClientGameListPlayerLeft(unsigned, unsigned)), myGameLobbyDialog, SLOT(gameRemovePlayer(unsigned, unsigned)));
|
||||
connect(this, SIGNAL(signalNetClientRemovedFromGame(int)), myGameLobbyDialog, SLOT(removedFromGame(int)));
|
||||
|
||||
@@ -134,6 +134,7 @@ signals:
|
||||
void signalNetClientPlayerLeft(unsigned playerId, QString playerName);
|
||||
void signalNetClientGameListNew(unsigned gameId);
|
||||
void signalNetClientGameListRemove(unsigned gameId);
|
||||
void signalNetClientGameListUpdateMode(unsigned gameId, int mode);
|
||||
void signalNetClientGameListPlayerJoined(unsigned gameId, unsigned playerId);
|
||||
void signalNetClientGameListPlayerLeft(unsigned gameId, unsigned playerId);
|
||||
void signalNetClientGameStart(boost::shared_ptr<Game> game);
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <string>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <playerdata.h>
|
||||
#include <gamedata.h>
|
||||
|
||||
class Game;
|
||||
|
||||
@@ -40,6 +41,7 @@ public:
|
||||
|
||||
virtual void SignalNetClientGameListNew(unsigned gameId) = 0;
|
||||
virtual void SignalNetClientGameListRemove(unsigned gameId) = 0;
|
||||
virtual void SignalNetClientGameListUpdateMode(unsigned gameId, GameMode mode) = 0;
|
||||
virtual void SignalNetClientGameListPlayerJoined(unsigned gameId, unsigned playerId) = 0;
|
||||
virtual void SignalNetClientGameListPlayerLeft(unsigned gameId, unsigned playerId) = 0;
|
||||
|
||||
|
||||
@@ -119,6 +119,7 @@ protected:
|
||||
|
||||
unsigned GetGameIdByName(const std::string &name) const;
|
||||
void AddGameInfo(unsigned gameId, const GameInfo &info);
|
||||
void UpdateGameInfoMode(unsigned gameId, GameMode mode);
|
||||
void RemoveGameInfo(unsigned gameId);
|
||||
void ModifyGameInfoAddPlayer(unsigned gameId, unsigned playerId);
|
||||
void ModifyGameInfoRemovePlayer(unsigned gameId, unsigned playerId);
|
||||
|
||||
@@ -458,6 +458,8 @@ AbstractClientStateReceiving::Process(ClientThread &client)
|
||||
tmpPacket->ToNetPacketGameListUpdate()->GetData(gameListUpdateData);
|
||||
if (gameListUpdateData.gameMode == GAME_MODE_CLOSED)
|
||||
client.RemoveGameInfo(gameListUpdateData.gameId);
|
||||
else
|
||||
client.UpdateGameInfoMode(gameListUpdateData.gameId, gameListUpdateData.gameMode);
|
||||
}
|
||||
else if (tmpPacket->ToNetPacketGameListPlayerJoined())
|
||||
{
|
||||
|
||||
@@ -673,19 +673,36 @@ ClientThread::AddGameInfo(unsigned gameId, const GameInfo &info)
|
||||
}
|
||||
|
||||
void
|
||||
ClientThread::RemoveGameInfo(unsigned gameId)
|
||||
ClientThread::UpdateGameInfoMode(unsigned gameId, GameMode mode)
|
||||
{
|
||||
string name;
|
||||
bool found = false;
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_gameInfoMapMutex);
|
||||
GameInfoMap::iterator pos = m_gameInfoMap.find(gameId);
|
||||
if (pos != m_gameInfoMap.end())
|
||||
{
|
||||
name = pos->second.name;
|
||||
found = true;
|
||||
(*pos).second.mode = mode;
|
||||
}
|
||||
}
|
||||
if (found)
|
||||
GetCallback().SignalNetClientGameListUpdateMode(gameId, mode);
|
||||
}
|
||||
|
||||
void
|
||||
ClientThread::RemoveGameInfo(unsigned gameId)
|
||||
{
|
||||
bool found = false;
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_gameInfoMapMutex);
|
||||
GameInfoMap::iterator pos = m_gameInfoMap.find(gameId);
|
||||
if (pos != m_gameInfoMap.end())
|
||||
{
|
||||
found = true;
|
||||
m_gameInfoMap.erase(pos);
|
||||
}
|
||||
}
|
||||
if (!name.empty())
|
||||
if (found)
|
||||
GetCallback().SignalNetClientGameListRemove(gameId);
|
||||
}
|
||||
|
||||
|
||||
@@ -158,6 +158,8 @@ ServerGameThread::Main()
|
||||
void
|
||||
ServerGameThread::InternalStartGame()
|
||||
{
|
||||
GetLobbyThread().NotifyStartingGame(GetId());
|
||||
|
||||
// Set order of players.
|
||||
AssignPlayerNumbers();
|
||||
|
||||
@@ -180,19 +182,16 @@ ServerGameThread::InternalStartGame()
|
||||
PlayerDataList::const_iterator player_i = playerData.begin();
|
||||
PlayerDataList::const_iterator player_end = playerData.end();
|
||||
|
||||
bool randDealerFound = false;
|
||||
int tmpPos = 0;
|
||||
while (player_i != player_end)
|
||||
{
|
||||
if ((*player_i)->GetNumber() == tmpDealerPos)
|
||||
{
|
||||
// Get ID of the dealer.
|
||||
startData.startDealerPlayerId = static_cast<unsigned>((*player_i)->GetUniqueId());
|
||||
randDealerFound = true;
|
||||
startData.startDealerPlayerId = static_cast<unsigned>((*player_i)->GetUniqueId());
|
||||
if (tmpPos == tmpDealerPos)
|
||||
break;
|
||||
}
|
||||
++tmpPos;
|
||||
++player_i;
|
||||
}
|
||||
assert(randDealerFound); // TODO: Throw exception.
|
||||
assert(player_i != player_end);
|
||||
|
||||
SetStartData(startData);
|
||||
|
||||
|
||||
@@ -153,6 +153,14 @@ ServerLobbyThread::NotifyPlayerLeftGame(unsigned gameId, unsigned playerId)
|
||||
m_gameSessionManager.SendToAllSessions(GetSender(), packet, SessionData::Game);
|
||||
}
|
||||
|
||||
void
|
||||
ServerLobbyThread::NotifyStartingGame(unsigned gameId)
|
||||
{
|
||||
boost::shared_ptr<NetPacket> packet = CreateNetPacketGameListUpdate(gameId, GAME_MODE_STARTED);
|
||||
m_sessionManager.SendToAllSessions(GetSender(), packet, SessionData::Established);
|
||||
m_gameSessionManager.SendToAllSessions(GetSender(), packet, SessionData::Game);
|
||||
}
|
||||
|
||||
void
|
||||
ServerLobbyThread::HandleGameRetrievePlayerInfo(SessionWrapper session, const NetPacketRetrievePlayerInfo &tmpPacket)
|
||||
{
|
||||
@@ -485,8 +493,9 @@ ServerLobbyThread::InternalRemoveGame(boost::shared_ptr<ServerGameThread> game)
|
||||
// Remove all sessions left in the game.
|
||||
game->RemoveAllSessions();
|
||||
// Notify all players.
|
||||
m_sessionManager.SendToAllSessions(GetSender(), CreateNetPacketGameListUpdate(*game, GAME_MODE_CLOSED), SessionData::Established);
|
||||
m_gameSessionManager.SendToAllSessions(GetSender(), CreateNetPacketGameListUpdate(*game, GAME_MODE_CLOSED), SessionData::Game);
|
||||
boost::shared_ptr<NetPacket> packet = CreateNetPacketGameListUpdate(game->GetId(), GAME_MODE_CLOSED);
|
||||
m_sessionManager.SendToAllSessions(GetSender(), packet, SessionData::Established);
|
||||
m_gameSessionManager.SendToAllSessions(GetSender(), packet, SessionData::Game);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -672,11 +681,11 @@ ServerLobbyThread::CreateNetPacketGameListNew(const ServerGameThread &game)
|
||||
}
|
||||
|
||||
boost::shared_ptr<NetPacket>
|
||||
ServerLobbyThread::CreateNetPacketGameListUpdate(const ServerGameThread &game, GameMode mode)
|
||||
ServerLobbyThread::CreateNetPacketGameListUpdate(unsigned gameId, GameMode mode)
|
||||
{
|
||||
boost::shared_ptr<NetPacket> packet(new NetPacketGameListUpdate);
|
||||
NetPacketGameListUpdate::Data packetData;
|
||||
packetData.gameId = game.GetId();
|
||||
packetData.gameId = gameId;
|
||||
packetData.gameMode = mode;
|
||||
static_cast<NetPacketGameListUpdate *>(packet.get())->SetData(packetData);
|
||||
return packet;
|
||||
|
||||
@@ -57,6 +57,7 @@ public:
|
||||
void SessionError(SessionWrapper session, int errorCode);
|
||||
void NotifyPlayerJoinedGame(unsigned gameId, unsigned playerId);
|
||||
void NotifyPlayerLeftGame(unsigned gameId, unsigned playerId);
|
||||
void NotifyStartingGame(unsigned gameId);
|
||||
|
||||
void HandleGameRetrievePlayerInfo(SessionWrapper session, const NetPacketRetrievePlayerInfo &tmpPacket);
|
||||
|
||||
@@ -115,7 +116,7 @@ protected:
|
||||
bool IsPlayerConnected(const std::string &name);
|
||||
|
||||
static boost::shared_ptr<NetPacket> CreateNetPacketGameListNew(const ServerGameThread &game);
|
||||
static boost::shared_ptr<NetPacket> CreateNetPacketGameListUpdate(const ServerGameThread &game, GameMode mode);
|
||||
static boost::shared_ptr<NetPacket> CreateNetPacketGameListUpdate(unsigned gameId, GameMode mode);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user