From 3ea61381ef300341c900472310ca519d1865ae64 Mon Sep 17 00:00:00 2001 From: lotodore Date: Sun, 28 Oct 2007 19:38:49 +0000 Subject: [PATCH] Use client game id when kicking players during game. --- src/gui/qt/mainwindow/chat/chat.cpp | 2 +- src/gui/qt/mainwindow/mainwindowimpl.cpp | 2 +- src/net/clientthread.h | 9 +++++++-- src/net/common/clientstate.cpp | 1 + src/net/common/clientthread.cpp | 18 ++++++++++++++++-- src/session.cpp | 22 +++++++++++++++------- src/session.h | 12 +++++------- 7 files changed, 46 insertions(+), 20 deletions(-) diff --git a/src/gui/qt/mainwindow/chat/chat.cpp b/src/gui/qt/mainwindow/chat/chat.cpp index 401b531d..71553ace 100644 --- a/src/gui/qt/mainwindow/chat/chat.cpp +++ b/src/gui/qt/mainwindow/chat/chat.cpp @@ -47,7 +47,7 @@ void Chat::sendMessage() { QString playerToKick = myW->lineEdit_ChatInput->text().section(" ",1,1); myW->lineEdit_ChatInput->setText(""); - if(myW->getSession().getClientGameInfo(myW->getSession().getCurrentGame()->getMyGameID()).adminPlayerId == myW->getSession().getCurrentGame()->getSeatsList()->front()->getMyUniqueID()) { + if(myW->getSession().getClientGameInfo(myW->getSession().getClientCurrentGameId()).adminPlayerId == myW->getSession().getCurrentGame()->getSeatsList()->front()->getMyUniqueID()) { if(playerToKick.toUtf8().constData() == myW->getSession().getCurrentGame()->getSeatsList()->front()->getMyName()) { myW->textBrowser_Chat->append(""+tr("You cannot kick yourself!")+""); diff --git a/src/gui/qt/mainwindow/mainwindowimpl.cpp b/src/gui/qt/mainwindow/mainwindowimpl.cpp index 2c734e24..430abb02 100755 --- a/src/gui/qt/mainwindow/mainwindowimpl.cpp +++ b/src/gui/qt/mainwindow/mainwindowimpl.cpp @@ -3547,7 +3547,7 @@ void mainWindowImpl::networkGameModification() { void mainWindowImpl::mouseOverFlipCards(bool front) { - if(mySession->getCurrentGameID()) { + if(mySession->getCurrentGame()) { if(myConfig->readConfigInt("AntiPeekMode") && mySession->getCurrentGame()->getCurrentHand()->getSeatsList()->front()->getMyActiveStatus() && mySession->getCurrentGame()->getSeatsList()->front()->getMyAction() != PLAYER_ACTION_FOLD) { holeCardsArray[0][0]->signalFastFlipCards(front); holeCardsArray[0][1]->signalFastFlipCards(front); diff --git a/src/net/clientthread.h b/src/net/clientthread.h index 4cbaf3f0..c62bb8ec 100644 --- a/src/net/clientthread.h +++ b/src/net/clientthread.h @@ -65,10 +65,11 @@ public: void SendJoinGame(unsigned gameId, const std::string &password); void SendCreateGame(const GameData &gameData, const std::string &name, const std::string &password); - GameInfo GetGameInfo(unsigned playerId) const; + GameInfo GetGameInfo(unsigned gameId) const; PlayerInfo GetPlayerInfo(unsigned playerId) const; bool GetPlayerIdFromName(const std::string &playerName, unsigned &playerId) const; ServerStats GetStatData() const; + unsigned GetGameId() const; ClientCallback &GetCallback(); GuiInterface &GetGui(); @@ -106,6 +107,7 @@ protected: SenderThread &GetSender(); ReceiverHelper &GetReceiver(); + void SetGameId(unsigned id); const GameData &GetGameData() const; void SetGameData(const GameData &gameData); const StartData &GetStartData() const; @@ -170,9 +172,12 @@ private: mutable boost::mutex m_playerInfoMapMutex; PlayerIdList m_playerInfoRequestList; + unsigned m_curGameId; + mutable boost::mutex m_curGameIdMutex; + AvatarDataMap m_tempAvatarMap; - unsigned m_curGameId; + unsigned m_curGameNum; unsigned m_guiPlayerId; bool m_sessionEstablished; diff --git a/src/net/common/clientstate.cpp b/src/net/common/clientstate.cpp index 4ba317bb..e18f56a5 100644 --- a/src/net/common/clientstate.cpp +++ b/src/net/common/clientstate.cpp @@ -628,6 +628,7 @@ ClientStateWaitJoin::InternalProcess(ClientThread &client, boost::shared_ptrToNetPacketJoinGameAck()->GetData(joinGameAckData); + client.SetGameId(joinGameAckData.gameId); client.SetGameData(joinGameAckData.gameData); // Player number is 0 on init. Will be set when the game starts. diff --git a/src/net/common/clientthread.cpp b/src/net/common/clientthread.cpp index e0874c62..2cc16f66 100644 --- a/src/net/common/clientthread.cpp +++ b/src/net/common/clientthread.cpp @@ -56,7 +56,7 @@ private: ClientThread::ClientThread(GuiInterface &gui, AvatarManager &avatarManager) : m_curState(NULL), m_gui(gui), m_avatarManager(avatarManager), - m_curGameId(1), m_guiPlayerId(0), m_sessionEstablished(false) + m_curGameId(0), m_curGameNum(1), m_guiPlayerId(0), m_sessionEstablished(false) { m_context.reset(new ClientContext); m_senderCallback.reset(new ClientSenderCallback(*this)); @@ -331,7 +331,7 @@ ClientThread::Main() MapPlayerDataList(); if (GetPlayerDataList().size() != (unsigned)GetStartData().numberOfPlayers) throw ClientException(__FILE__, __LINE__, ERR_NET_INVALID_PLAYER_COUNT, 0); - m_game.reset(new Game(&m_gui, factory, GetPlayerDataList(), GetGameData(), GetStartData(), m_curGameId++)); + m_game.reset(new Game(&m_gui, factory, GetPlayerDataList(), GetGameData(), GetStartData(), m_curGameNum++)); // Initialize GUI speed. GetGui().initGui(GetGameData().guiSpeed); // Signal start of game to GUI. @@ -566,6 +566,20 @@ ClientThread::GetReceiver() return *m_receiver; } +unsigned +ClientThread::GetGameId() const +{ + boost::mutex::scoped_lock lock(m_curGameIdMutex); + return m_curGameId; +} + +void +ClientThread::SetGameId(unsigned id) +{ + boost::mutex::scoped_lock lock(m_curGameIdMutex); + m_curGameId = id; +} + const GameData & ClientThread::GetGameData() const { diff --git a/src/session.cpp b/src/session.cpp index 3396e6ec..dd8f54c5 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -39,7 +39,7 @@ using namespace std; Session::Session(GuiInterface *g, ConfigFile *c) -: currentGameID(0), myNetClient(NULL), myNetServer(NULL), myIrcThread(NULL), +: currentGameNum(0), myNetClient(NULL), myNetServer(NULL), myIrcThread(NULL), myGui(g), myConfig(c), myGameType(GAME_TYPE_NONE) { } @@ -71,7 +71,7 @@ void Session::startLocalGame(const GameData &gameData, const StartData &startDat myGameType = GAME_TYPE_LOCAL; currentGame.reset(); - currentGameID++; + currentGameNum++; myGui->initGui(gameData.guiSpeed); @@ -99,7 +99,7 @@ void Session::startLocalGame(const GameData &gameData, const StartData &startDat // EngineFactory erstellen boost::shared_ptr factory(new LocalEngineFactory(myConfig)); // LocalEngine erstellen - currentGame.reset(new Game(myGui, factory, playerDataList, gameData, startData, currentGameID)); + currentGame.reset(new Game(myGui, factory, playerDataList, gameData, startData, currentGameNum)); //// SPIEL-SCHLEIFE currentGame->initHand(); @@ -109,7 +109,7 @@ void Session::startLocalGame(const GameData &gameData, const StartData &startDat void Session::startClientGame(boost::shared_ptr game) { - currentGameID++; + currentGameNum++; currentGame = game; } @@ -358,7 +358,7 @@ bool Session::isNetworkServerRunning() const return myNetServer != NULL; } -GameInfo Session::getClientGameInfo(unsigned playerId) +GameInfo Session::getClientGameInfo(unsigned playerId) const { GameInfo info; if (myNetClient) @@ -366,7 +366,7 @@ GameInfo Session::getClientGameInfo(unsigned playerId) return info; } -PlayerInfo Session::getClientPlayerInfo(unsigned playerId) +PlayerInfo Session::getClientPlayerInfo(unsigned playerId) const { PlayerInfo info; if (myNetClient) @@ -374,7 +374,7 @@ PlayerInfo Session::getClientPlayerInfo(unsigned playerId) return info; } -ServerStats Session::getClientStats() +ServerStats Session::getClientStats() const { ServerStats stats; if (myNetClient) @@ -382,3 +382,11 @@ ServerStats Session::getClientStats() return stats; } +unsigned Session::getClientCurrentGameId() const +{ + unsigned id = 0; + if (myNetClient) + id = myNetClient->GetGameId(); + return id; +} + diff --git a/src/session.h b/src/session.h index d79209c0..21aa4da9 100755 --- a/src/session.h +++ b/src/session.h @@ -72,9 +72,6 @@ public: void sendClientPlayerAction(); - void setCurrentGameID(int theValue) { currentGameID = theValue; } - int getCurrentGameID() const { return currentGameID; } - void sendChatMessage(const std::string &message); void kickPlayer(unsigned playerId); void kickPlayer(const std::string &playerName); @@ -82,13 +79,14 @@ public: bool isNetworkClientRunning() const; // TODO hack bool isNetworkServerRunning() const; // TODO hack - GameInfo getClientGameInfo(unsigned gameId); - PlayerInfo getClientPlayerInfo(unsigned playerId); - ServerStats getClientStats(); + GameInfo getClientGameInfo(unsigned gameId) const; + PlayerInfo getClientPlayerInfo(unsigned playerId) const; + ServerStats getClientStats() const; + unsigned getClientCurrentGameId() const; private: - int currentGameID; + int currentGameNum; ClientThread *myNetClient; ServerAcceptThread *myNetServer;