diff --git a/src/engine/network_engine/clientboard.cpp b/src/engine/network_engine/clientboard.cpp index fa1fff77..a1ec1d58 100644 --- a/src/engine/network_engine/clientboard.cpp +++ b/src/engine/network_engine/clientboard.cpp @@ -141,13 +141,13 @@ ClientBoard::setWinners(const std::list &w) std::list ClientBoard::getPlayerNeedToShowCards() const { - boost::recursive_mutex::scoped_lock lock(m_syncMutex); - return playerNeedToShowCards; + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return playerNeedToShowCards; } void ClientBoard::setPlayerNeedToShowCards(const std::list &p) { - boost::recursive_mutex::scoped_lock lock(m_syncMutex); - playerNeedToShowCards = p; + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + playerNeedToShowCards = p; } diff --git a/src/engine/network_engine/clientplayer.cpp b/src/engine/network_engine/clientplayer.cpp index 764f9392..03960a27 100644 --- a/src/engine/network_engine/clientplayer.cpp +++ b/src/engine/network_engine/clientplayer.cpp @@ -517,7 +517,8 @@ boost::shared_ptr ClientPlayer::getNetSessionData() bool ClientPlayer::checkIfINeedToShowCards() { - std::list playerNeedToShowCardsList = currentBoard->getPlayerNeedToShowCards(); + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + std::list playerNeedToShowCardsList = currentBoard->getPlayerNeedToShowCards(); for(std::list::iterator it = playerNeedToShowCardsList.begin(); it != playerNeedToShowCardsList.end(); it++) { if(*it == myUniqueID) return true; diff --git a/src/gui/generic/serverguiwrapper.cpp b/src/gui/generic/serverguiwrapper.cpp index 885fc9ca..0ec328d4 100644 --- a/src/gui/generic/serverguiwrapper.cpp +++ b/src/gui/generic/serverguiwrapper.cpp @@ -90,7 +90,6 @@ void ServerGuiWrapper::riverAnimation2() {} void ServerGuiWrapper::postRiverAnimation1() {} void ServerGuiWrapper::postRiverRunAnimation1() {} -void ServerGuiWrapper::postRiverShowCards(unsigned /*playerId*/) {} void ServerGuiWrapper::flipHolecardsAllIn() {} void ServerGuiWrapper::nextRoundCleanGui() {} @@ -123,6 +122,7 @@ void ServerGuiWrapper::SignalNetClientServerListClear() { if (myClientcb) myClie void ServerGuiWrapper::SignalNetClientServerListShow() { if (myClientcb) myClientcb->SignalNetClientServerListShow(); } void ServerGuiWrapper::SignalNetClientLoginShow() { if (myClientcb) myClientcb->SignalNetClientLoginShow(); } +void ServerGuiWrapper::SignalNetClientPostRiverShowCards(unsigned playerId) { if (myClientcb) myClientcb->SignalNetClientPostRiverShowCards(playerId); } void ServerGuiWrapper::SignalNetClientConnect(int actionID) { if (myClientcb) myClientcb->SignalNetClientConnect(actionID); } void ServerGuiWrapper::SignalNetClientGameInfo(int actionID) { if (myClientcb) myClientcb->SignalNetClientGameInfo(actionID); } diff --git a/src/gui/generic/serverguiwrapper.h b/src/gui/generic/serverguiwrapper.h index 753b4390..90e98dd1 100644 --- a/src/gui/generic/serverguiwrapper.h +++ b/src/gui/generic/serverguiwrapper.h @@ -78,7 +78,6 @@ public: void postRiverAnimation1(); void postRiverRunAnimation1(); - void postRiverShowCards(unsigned playerId); void flipHolecardsAllIn(); @@ -135,6 +134,7 @@ public: void SignalNetClientServerListShow(); void SignalNetClientLoginShow(); + void SignalNetClientPostRiverShowCards(unsigned playerId); void SignalNetServerSuccess(int actionID); void SignalNetServerError(int errorID, int osErrorID); diff --git a/src/gui/guiinterface.h b/src/gui/guiinterface.h index 2aaebc5c..1905e963 100644 --- a/src/gui/guiinterface.h +++ b/src/gui/guiinterface.h @@ -84,7 +84,6 @@ public: virtual void postRiverAnimation1()=0; virtual void postRiverRunAnimation1()=0; - virtual void postRiverShowCards(unsigned playerId)=0; virtual void flipHolecardsAllIn()=0; virtual void nextRoundCleanGui()=0; diff --git a/src/gui/qt/guiwrapper.cpp b/src/gui/qt/guiwrapper.cpp index 02332114..ec3e0470 100644 --- a/src/gui/qt/guiwrapper.cpp +++ b/src/gui/qt/guiwrapper.cpp @@ -97,7 +97,6 @@ void GuiWrapper::riverAnimation2() { myW->signalRiverAnimation2(); } void GuiWrapper::postRiverAnimation1() { myW->signalPostRiverAnimation1(); } void GuiWrapper::postRiverRunAnimation1() { myW->signalPostRiverRunAnimation1(); } -void GuiWrapper::postRiverShowCards(unsigned playerId) { myW->signalPostRiverShowCards(playerId); } void GuiWrapper::flipHolecardsAllIn() { myW->signalFlipHolecardsAllIn(); } @@ -130,6 +129,7 @@ void GuiWrapper::SignalNetClientConnect(int actionID) { myStartWindow->signalNet void GuiWrapper::SignalNetClientServerListAdd(unsigned serverId) { myStartWindow->signalNetClientServerListAdd(serverId); } void GuiWrapper::SignalNetClientServerListShow() { myStartWindow->signalNetClientServerListShow(); } void GuiWrapper::SignalNetClientLoginShow() { myStartWindow->signalNetClientLoginShow(); } +void GuiWrapper::SignalNetClientPostRiverShowCards(unsigned playerId) { myW->signalPostRiverShowCards(playerId); } void GuiWrapper::SignalNetClientServerListClear() { myStartWindow->signalNetClientServerListClear(); } void GuiWrapper::SignalNetClientGameInfo(int actionID) { myStartWindow->signalNetClientGameInfo(actionID); } void GuiWrapper::SignalNetClientError(int errorID, int osErrorID) { myStartWindow->signalNetClientError(errorID, osErrorID); } diff --git a/src/gui/qt/guiwrapper.h b/src/gui/qt/guiwrapper.h index ecd6bc12..34a989f5 100644 --- a/src/gui/qt/guiwrapper.h +++ b/src/gui/qt/guiwrapper.h @@ -85,7 +85,6 @@ public: void postRiverAnimation1(); void postRiverRunAnimation1(); - void postRiverShowCards(unsigned playerId); void flipHolecardsAllIn(); @@ -118,6 +117,7 @@ public: void SignalNetClientServerListShow(); void SignalNetClientServerListClear(); void SignalNetClientLoginShow(); + void SignalNetClientPostRiverShowCards(unsigned playerId); void SignalNetClientGameInfo(int actionID); void SignalNetClientError(int errorID, int osErrorID); void SignalNetClientNotification(int notificationId); diff --git a/src/net/clientcallback.h b/src/net/clientcallback.h index 00ddb531..4d980596 100644 --- a/src/net/clientcallback.h +++ b/src/net/clientcallback.h @@ -60,12 +60,13 @@ public: virtual void SignalNetClientLobbyChatMsg(const std::string &playerName, const std::string &msg) = 0; virtual void SignalNetClientMsgBox(const std::string &msg) = 0; virtual void SignalNetClientWaitDialog() = 0; - + virtual void SignalNetClientServerListAdd(unsigned serverId) = 0; virtual void SignalNetClientServerListClear() = 0; virtual void SignalNetClientServerListShow() = 0; virtual void SignalNetClientLoginShow() = 0; + virtual void SignalNetClientPostRiverShowCards(unsigned playerId) = 0; virtual void SignalLobbyPlayerJoined(unsigned playerId, const std::string &nickName) = 0; virtual void SignalLobbyPlayerKicked(const std::string &nickName, const std::string &byWhom, const std::string &reason) = 0; diff --git a/src/net/common/clientstate.cpp b/src/net/common/clientstate.cpp index 81c4330b..88727035 100644 --- a/src/net/common/clientstate.cpp +++ b/src/net/common/clientstate.cpp @@ -1718,6 +1718,29 @@ ClientStateWaitHand::InternalHandlePacket(boost::shared_ptr client client->SetState(ClientStateWaitGame::Instance()); } } + else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_afterHandShowCardsMessage) + { + AfterHandShowCardsMessage_t *showCards = &tmpPacket->GetMsg()->choice.afterHandShowCardsMessage; + PlayerResult_t *r = &showCards->playerResult; + + boost::shared_ptr tmpPlayer = client->GetGame()->getPlayerByUniqueId(r->playerId); + if (!tmpPlayer) + throw ClientException(__FILE__, __LINE__, ERR_NET_UNKNOWN_PLAYER_ID, 0); + + int tmpCards[2]; + int bestHandPos[5]; + tmpCards[0] = static_cast(r->resultCard1); + tmpCards[1] = static_cast(r->resultCard2); + tmpPlayer->setMyCards(tmpCards); + for (int num = 0; num < 5; num++) + bestHandPos[num] = *r->bestHandPosition.list.array[num]; + tmpPlayer->setMyCardsValueInt(r->cardsValue); + tmpPlayer->setMyBestHandPosition(bestHandPos); + tmpPlayer->setMyCash(r->playerMoney); + tmpPlayer->setLastMoneyWon(r->moneyWon); + + client->GetCallback().SignalNetClientPostRiverShowCards(r->playerId); + } } //----------------------------------------------------------------------------- diff --git a/src/net/common/servergame.cpp b/src/net/common/servergame.cpp index 76de2086..4ca1aaa5 100644 --- a/src/net/common/servergame.cpp +++ b/src/net/common/servergame.cpp @@ -134,6 +134,12 @@ ServerGame::SendToAllPlayers(boost::shared_ptr packet, SessionData::S GetSessionManager().SendToAllSessions(GetLobbyThread().GetSender(), packet, state); } +void +ServerGame::SendToAllButOnePlayers(boost::shared_ptr packet, SessionId except, SessionData::State state) +{ + GetSessionManager().SendToAllButOneSessions(GetLobbyThread().GetSender(), packet, except, state); +} + void ServerGame::RemoveAllSessions() { diff --git a/src/net/common/servergamestate.cpp b/src/net/common/servergamestate.cpp index 187c8f69..208f0a38 100644 --- a/src/net/common/servergamestate.cpp +++ b/src/net/common/servergamestate.cpp @@ -170,6 +170,28 @@ static void PerformPlayerAction(ServerGame &server, boost::shared_ptr tmpPlayer) +{ + playerResult.playerId = tmpPlayer->getMyUniqueID(); + int tmpCards[2]; + int bestHandPos[5]; + tmpPlayer->getMyCards(tmpCards); + playerResult.resultCard1 = tmpCards[0]; + playerResult.resultCard2 = tmpCards[1]; + tmpPlayer->getMyBestHandPosition(bestHandPos); + for (int num = 0; num < 5; num++) + { + long *handPos = (long *)calloc(1, sizeof(long)); + *handPos = bestHandPos[num]; + ASN_SEQUENCE_ADD(&playerResult.bestHandPosition.list, handPos); + } + + playerResult.cardsValue = tmpPlayer->getMyCardsValueInt(); + playerResult.moneyWon = tmpPlayer->getLastMoneyWon(); + playerResult.playerMoney = tmpPlayer->getMyCash(); +} + //----------------------------------------------------------------------------- ServerGameState::~ServerGameState() @@ -876,23 +898,7 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr server) while (i != end) { PlayerResult_t *playerResult = (PlayerResult_t *)calloc(1, sizeof(PlayerResult_t)); - playerResult->playerId = (*i)->getMyUniqueID(); - int tmpCards[2]; - int bestHandPos[5]; - (*i)->getMyCards(tmpCards); - playerResult->resultCard1 = tmpCards[0]; - playerResult->resultCard2 = tmpCards[1]; - (*i)->getMyBestHandPosition(bestHandPos); - for (int num = 0; num < 5; num++) - { - long *handPos = (long *)calloc(1, sizeof(long)); - *handPos = bestHandPos[num]; - ASN_SEQUENCE_ADD(&playerResult->bestHandPosition.list, handPos); - } - - playerResult->cardsValue = (*i)->getMyCardsValueInt(); - playerResult->moneyWon = (*i)->getLastMoneyWon(); - playerResult->playerMoney = (*i)->getMyCash(); + SetPlayerResult(*playerResult, (*i)); ASN_SEQUENCE_ADD(&endHandShow->playerResults.list, playerResult); ++i; @@ -1332,7 +1338,16 @@ ServerGameStateWaitNextHand::InternalProcessPacket(boost::shared_ptr { if (packet->GetMsg()->present == PokerTHMessage_PR_showMyCardsRequestMessage) { - // TODO perform action. + Game &curGame = server->GetGame(); + boost::shared_ptr show(new NetPacket(NetPacket::Alloc)); + show->GetMsg()->present = PokerTHMessage_PR_afterHandShowCardsMessage; + + AfterHandShowCardsMessage_t *netShowCards = &packet->GetMsg()->choice.afterHandShowCardsMessage; + boost::shared_ptr tmpPlayer(curGame.getPlayerByUniqueId(session.playerData->GetUniqueId())); + if (tmpPlayer) + SetPlayerResult(netShowCards->playerResult, tmpPlayer); + + server->SendToAllButOnePlayers(show, session.sessionData->GetId(), SessionData::Game); } } diff --git a/src/net/servergame.h b/src/net/servergame.h index efb0c204..1ff2dff4 100644 --- a/src/net/servergame.h +++ b/src/net/servergame.h @@ -63,7 +63,8 @@ public: GameState GetCurRound() const; void SendToAllPlayers(boost::shared_ptr packet, SessionData::State state); - void RemoveAllSessions(); + void SendToAllButOnePlayers(boost::shared_ptr packet, SessionId except, SessionData::State state); + void RemoveAllSessions(); bool IsPasswordProtected() const; bool CheckPassword(const std::string &password) const;