Game List is now dynamically updated.
This commit is contained in:
@@ -816,6 +816,8 @@ void mainWindowImpl::callGameLobbyDialog() {
|
|||||||
|
|
||||||
myGameLobbyDialog->setSession(&getSession());
|
myGameLobbyDialog->setSession(&getSession());
|
||||||
myGameLobbyDialog->treeWidget_GameList->clear();
|
myGameLobbyDialog->treeWidget_GameList->clear();
|
||||||
|
myStartNetworkGameDialog->treeWidget->clear();
|
||||||
|
myStartNetworkGameDialog->setSession(&getSession());
|
||||||
|
|
||||||
// Just for testing
|
// Just for testing
|
||||||
mySession->startNetworkClientForLocalServer();
|
mySession->startNetworkClientForLocalServer();
|
||||||
@@ -824,9 +826,6 @@ void mainWindowImpl::callGameLobbyDialog() {
|
|||||||
|
|
||||||
if (myGameLobbyDialog->result() == QDialog::Accepted)
|
if (myGameLobbyDialog->result() == QDialog::Accepted)
|
||||||
{
|
{
|
||||||
myStartNetworkGameDialog->setSession(&getSession());
|
|
||||||
myStartNetworkGameDialog->treeWidget->clear();
|
|
||||||
|
|
||||||
showNetworkStartDialog();
|
showNetworkStartDialog();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public:
|
|||||||
GuiInterface &GetGui();
|
GuiInterface &GetGui();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
typedef std::map<std::string, unsigned> GameMap;
|
typedef std::map<unsigned, std::string> GameMap;
|
||||||
|
|
||||||
// Main function of the thread.
|
// Main function of the thread.
|
||||||
virtual void Main();
|
virtual void Main();
|
||||||
@@ -98,7 +98,8 @@ protected:
|
|||||||
void RemoveDisconnectedPlayers();
|
void RemoveDisconnectedPlayers();
|
||||||
|
|
||||||
unsigned GetGameIdByName(const std::string &name) const;
|
unsigned GetGameIdByName(const std::string &name) const;
|
||||||
void AddGameInformation(const std::string &name, unsigned id);
|
void AddGameInformation(unsigned id, const std::string &name);
|
||||||
|
void RemoveGameInformation(unsigned id);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|||||||
@@ -476,7 +476,15 @@ ClientStateWaitJoin::InternalProcess(ClientThread &client, boost::shared_ptr<Net
|
|||||||
// A new game was created on the server.
|
// A new game was created on the server.
|
||||||
NetPacketGameListNew::Data gameListNewData;
|
NetPacketGameListNew::Data gameListNewData;
|
||||||
packet->ToNetPacketGameListNew()->GetData(gameListNewData);
|
packet->ToNetPacketGameListNew()->GetData(gameListNewData);
|
||||||
client.AddGameInformation(gameListNewData.gameName, gameListNewData.gameId);
|
client.AddGameInformation(gameListNewData.gameId, gameListNewData.gameName);
|
||||||
|
}
|
||||||
|
else if (packet->ToNetPacketGameListUpdate())
|
||||||
|
{
|
||||||
|
// An existing game was updated on the server.
|
||||||
|
NetPacketGameListUpdate::Data gameListUpdateData;
|
||||||
|
packet->ToNetPacketGameListUpdate()->GetData(gameListUpdateData);
|
||||||
|
if (gameListUpdateData.gameMode == GAME_MODE_CLOSED)
|
||||||
|
client.RemoveGameInformation(gameListUpdateData.gameId);
|
||||||
}
|
}
|
||||||
else if (packet->ToNetPacketJoinGameAck())
|
else if (packet->ToNetPacketJoinGameAck())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -475,21 +475,48 @@ unsigned
|
|||||||
ClientThread::GetGameIdByName(const std::string &name) const
|
ClientThread::GetGameIdByName(const std::string &name) const
|
||||||
{
|
{
|
||||||
// Find the game.
|
// Find the game.
|
||||||
bool retVal = false;
|
|
||||||
boost::mutex::scoped_lock lock(m_gameMapMutex);
|
boost::mutex::scoped_lock lock(m_gameMapMutex);
|
||||||
GameMap::const_iterator pos = m_gameMap.find(name);
|
GameMap::const_iterator i = m_gameMap.begin();
|
||||||
if (pos == m_gameMap.end())
|
GameMap::const_iterator end = m_gameMap.end();
|
||||||
|
while (i != end)
|
||||||
|
{
|
||||||
|
if (i->second == name)
|
||||||
|
break;
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i == end)
|
||||||
throw NetException(ERR_NET_UNKNOWN_GAME, 0);
|
throw NetException(ERR_NET_UNKNOWN_GAME, 0);
|
||||||
return pos->second;
|
return i->first;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ClientThread::AddGameInformation(const std::string &name, unsigned id)
|
ClientThread::AddGameInformation(unsigned id, const std::string &name)
|
||||||
{
|
{
|
||||||
|
if (!name.empty())
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock lock(m_gameMapMutex);
|
{
|
||||||
m_gameMap.insert(GameMap::value_type(name, id));
|
boost::mutex::scoped_lock lock(m_gameMapMutex);
|
||||||
|
m_gameMap.insert(GameMap::value_type(id, name));
|
||||||
|
}
|
||||||
|
GetCallback().SignalNetClientGameListNew(name);
|
||||||
}
|
}
|
||||||
GetCallback().SignalNetClientGameListNew(name);
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ClientThread::RemoveGameInformation(unsigned id)
|
||||||
|
{
|
||||||
|
string name;
|
||||||
|
{
|
||||||
|
boost::mutex::scoped_lock lock(m_gameMapMutex);
|
||||||
|
GameMap::iterator pos = m_gameMap.find(id);
|
||||||
|
if (pos != m_gameMap.end())
|
||||||
|
{
|
||||||
|
name = pos->second;
|
||||||
|
m_gameMap.erase(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!name.empty())
|
||||||
|
GetCallback().SignalNetClientGameListRemove(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -282,8 +282,8 @@ ServerLobbyThread::HandleNetPacketCreateGame(SessionWrapper session, const NetPa
|
|||||||
// Add session to the game.
|
// Add session to the game.
|
||||||
game->AddSession(session);
|
game->AddSession(session);
|
||||||
|
|
||||||
// Add game to list.
|
// Add game to list of games.
|
||||||
m_gameMap.insert(GameMap::value_type(game->GetId(), game));
|
InternalAddGame(game);
|
||||||
|
|
||||||
// Start the game.
|
// Start the game.
|
||||||
game->Run();
|
game->Run();
|
||||||
@@ -353,13 +353,31 @@ ServerLobbyThread::RemoveGameLoop()
|
|||||||
boost::shared_ptr<ServerGameThread> tmpGame = pos->second;
|
boost::shared_ptr<ServerGameThread> tmpGame = pos->second;
|
||||||
tmpGame->SignalTermination();
|
tmpGame->SignalTermination();
|
||||||
tmpGame->Join(GAME_THREAD_TERMINATE_TIMEOUT);
|
tmpGame->Join(GAME_THREAD_TERMINATE_TIMEOUT);
|
||||||
m_gameMap.erase(pos);
|
InternalRemoveGame(tmpGame);
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
m_removeGameList.clear();
|
m_removeGameList.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ServerLobbyThread::InternalAddGame(boost::shared_ptr<ServerGameThread> game)
|
||||||
|
{
|
||||||
|
// Add game to list.
|
||||||
|
m_gameMap.insert(GameMap::value_type(game->GetId(), game));
|
||||||
|
// Notify all players.
|
||||||
|
m_sessionManager.SendToAllSessions(GetSender(), CreateNetPacketGameListNew(*game), SessionData::Established);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ServerLobbyThread::InternalRemoveGame(boost::shared_ptr<ServerGameThread> game)
|
||||||
|
{
|
||||||
|
// Remove game from list.
|
||||||
|
m_gameMap.erase(game->GetId());
|
||||||
|
// Notify all players.
|
||||||
|
m_sessionManager.SendToAllSessions(GetSender(), CreateNetPacketGameListUpdate(*game, GAME_MODE_CLOSED), SessionData::Established);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ServerLobbyThread::TerminateGames()
|
ServerLobbyThread::TerminateGames()
|
||||||
{
|
{
|
||||||
@@ -503,3 +521,14 @@ ServerLobbyThread::CreateNetPacketGameListNew(const ServerGameThread &game)
|
|||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boost::shared_ptr<NetPacket>
|
||||||
|
ServerLobbyThread::CreateNetPacketGameListUpdate(const ServerGameThread &game, GameMode mode)
|
||||||
|
{
|
||||||
|
boost::shared_ptr<NetPacket> packet(new NetPacketGameListUpdate);
|
||||||
|
NetPacketGameListUpdate::Data packetData;
|
||||||
|
packetData.gameId = game.GetId();
|
||||||
|
packetData.gameMode = mode;
|
||||||
|
static_cast<NetPacketGameListUpdate *>(packet.get())->SetData(packetData);
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,6 +77,9 @@ protected:
|
|||||||
void CloseSessionLoop();
|
void CloseSessionLoop();
|
||||||
void RemoveGameLoop();
|
void RemoveGameLoop();
|
||||||
|
|
||||||
|
void InternalAddGame(boost::shared_ptr<ServerGameThread> game);
|
||||||
|
void InternalRemoveGame(boost::shared_ptr<ServerGameThread> game);
|
||||||
|
|
||||||
void TerminateGames();
|
void TerminateGames();
|
||||||
|
|
||||||
void HandleNewConnection(boost::shared_ptr<ConnectData> connData);
|
void HandleNewConnection(boost::shared_ptr<ConnectData> connData);
|
||||||
@@ -100,6 +103,7 @@ protected:
|
|||||||
bool IsPlayerConnected(const std::string &name);
|
bool IsPlayerConnected(const std::string &name);
|
||||||
|
|
||||||
static boost::shared_ptr<NetPacket> CreateNetPacketGameListNew(const ServerGameThread &game);
|
static boost::shared_ptr<NetPacket> CreateNetPacketGameListNew(const ServerGameThread &game);
|
||||||
|
static boost::shared_ptr<NetPacket> CreateNetPacketGameListUpdate(const ServerGameThread &game, GameMode mode);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user