diff --git a/src/gui/generic/serverguiwrapper.cpp b/src/gui/generic/serverguiwrapper.cpp index 1f71cea4..35f7d22f 100644 --- a/src/gui/generic/serverguiwrapper.cpp +++ b/src/gui/generic/serverguiwrapper.cpp @@ -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) { if (myClientcb) myClientcb->SignalNetClientGameStart(game); } diff --git a/src/gui/generic/serverguiwrapper.h b/src/gui/generic/serverguiwrapper.h index 358c527a..a3496e96 100644 --- a/src/gui/generic/serverguiwrapper.h +++ b/src/gui/generic/serverguiwrapper.h @@ -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); diff --git a/src/gui/qt/gamelobbydialog/gamelobbydialogimpl.cpp b/src/gui/qt/gamelobbydialog/gamelobbydialogimpl.cpp index 2bb218f1..978fa658 100644 --- a/src/gui/qt/gamelobbydialog/gamelobbydialogimpl.cpp +++ b/src/gui/qt/gamelobbydialog/gamelobbydialogimpl.cpp @@ -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); diff --git a/src/gui/qt/gamelobbydialog/gamelobbydialogimpl.h b/src/gui/qt/gamelobbydialog/gamelobbydialogimpl.h index 6e5bca5e..0d4d93c1 100644 --- a/src/gui/qt/gamelobbydialog/gamelobbydialogimpl.h +++ b/src/gui/qt/gamelobbydialog/gamelobbydialogimpl.h @@ -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); diff --git a/src/gui/qt/guiwrapper.cpp b/src/gui/qt/guiwrapper.cpp index b4d3b144..39ac37c7 100644 --- a/src/gui/qt/guiwrapper.cpp +++ b/src/gui/qt/guiwrapper.cpp @@ -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); } diff --git a/src/gui/qt/guiwrapper.h b/src/gui/qt/guiwrapper.h index a4c6ee70..ba169983 100644 --- a/src/gui/qt/guiwrapper.h +++ b/src/gui/qt/guiwrapper.h @@ -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); diff --git a/src/gui/qt/mainwindow/mainwindowimpl.cpp b/src/gui/qt/mainwindow/mainwindowimpl.cpp index fc6ed25a..1ecb7535 100755 --- a/src/gui/qt/mainwindow/mainwindowimpl.cpp +++ b/src/gui/qt/mainwindow/mainwindowimpl.cpp @@ -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))); diff --git a/src/gui/qt/mainwindow/mainwindowimpl.h b/src/gui/qt/mainwindow/mainwindowimpl.h index 2b33f90e..4c8e3d9c 100755 --- a/src/gui/qt/mainwindow/mainwindowimpl.h +++ b/src/gui/qt/mainwindow/mainwindowimpl.h @@ -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); diff --git a/src/net/clientcallback.h b/src/net/clientcallback.h index b4bc89c0..024d3a73 100644 --- a/src/net/clientcallback.h +++ b/src/net/clientcallback.h @@ -24,6 +24,7 @@ #include #include #include +#include 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; diff --git a/src/net/clientthread.h b/src/net/clientthread.h index b350958c..ba5a24ae 100644 --- a/src/net/clientthread.h +++ b/src/net/clientthread.h @@ -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); diff --git a/src/net/common/clientstate.cpp b/src/net/common/clientstate.cpp index 8111e777..e0348ecc 100644 --- a/src/net/common/clientstate.cpp +++ b/src/net/common/clientstate.cpp @@ -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()) { diff --git a/src/net/common/clientthread.cpp b/src/net/common/clientthread.cpp index b06f652c..3e524760 100644 --- a/src/net/common/clientthread.cpp +++ b/src/net/common/clientthread.cpp @@ -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); } diff --git a/src/net/common/servergamethread.cpp b/src/net/common/servergamethread.cpp index 21ed2c54..9047f636 100644 --- a/src/net/common/servergamethread.cpp +++ b/src/net/common/servergamethread.cpp @@ -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((*player_i)->GetUniqueId()); - randDealerFound = true; + startData.startDealerPlayerId = static_cast((*player_i)->GetUniqueId()); + if (tmpPos == tmpDealerPos) break; - } + ++tmpPos; ++player_i; } - assert(randDealerFound); // TODO: Throw exception. + assert(player_i != player_end); SetStartData(startData); diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index 96b9df7f..2b53e348 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -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 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 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 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 -ServerLobbyThread::CreateNetPacketGameListUpdate(const ServerGameThread &game, GameMode mode) +ServerLobbyThread::CreateNetPacketGameListUpdate(unsigned gameId, GameMode mode) { boost::shared_ptr packet(new NetPacketGameListUpdate); NetPacketGameListUpdate::Data packetData; - packetData.gameId = game.GetId(); + packetData.gameId = gameId; packetData.gameMode = mode; static_cast(packet.get())->SetData(packetData); return packet; diff --git a/src/net/serverlobbythread.h b/src/net/serverlobbythread.h index d32f1b23..a67ee501 100644 --- a/src/net/serverlobbythread.h +++ b/src/net/serverlobbythread.h @@ -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 CreateNetPacketGameListNew(const ServerGameThread &game); - static boost::shared_ptr CreateNetPacketGameListUpdate(const ServerGameThread &game, GameMode mode); + static boost::shared_ptr CreateNetPacketGameListUpdate(unsigned gameId, GameMode mode); private: