From 0aef0d9e4229007112ee76b68e433e60f289a86b Mon Sep 17 00:00:00 2001 From: lotodore Date: Mon, 6 Aug 2007 21:38:09 +0000 Subject: [PATCH] Removed dependencies on old preflop/flop/turn/river interface from networking. Compiles, but networking is BROKEN. Also includes first try of computer players for networking, which is broken, too. --- src/engine/local_engine/localbero.h | 2 +- src/engine/local_engine/localberofactory.cpp | 6 +++ src/engine/local_engine/localberofactory.h | 5 -- .../network_engine/clientberofactory.cpp | 28 +++++++---- src/engine/network_engine/clientberofactory.h | 8 +++ .../network_engine/clientenginefactory.cpp | 8 +-- src/engine/network_engine/clientflop.cpp | 39 ++++++++------- src/engine/network_engine/clientflop.h | 23 ++++++--- src/engine/network_engine/clientpreflop.cpp | 22 ++++++--- src/engine/network_engine/clientpreflop.h | 26 +++++++--- src/engine/network_engine/clientriver.cpp | 49 +++++++++---------- src/engine/network_engine/clientriver.h | 25 +++++++--- src/engine/network_engine/clientturn.cpp | 39 ++++++++------- src/engine/network_engine/clientturn.h | 24 ++++++--- src/net/common/serverrecvstate.cpp | 35 ++++++++++++- src/net/common/serverrecvthread.cpp | 10 +++- src/net/serverrecvstate.h | 1 + src/net/serverrecvthread.h | 4 ++ 18 files changed, 233 insertions(+), 121 deletions(-) diff --git a/src/engine/local_engine/localbero.h b/src/engine/local_engine/localbero.h index a18adc7d..32dd812d 100644 --- a/src/engine/local_engine/localbero.h +++ b/src/engine/local_engine/localbero.h @@ -25,7 +25,7 @@ public: int getMyBeRoID() const { return myBeRoID; } - int getHighestCardsValue() const {} + int getHighestCardsValue() const {return 0;} void setHighestCardsValue(int theValue) {} void run() {} diff --git a/src/engine/local_engine/localberofactory.cpp b/src/engine/local_engine/localberofactory.cpp index 18222e09..cbc2823d 100644 --- a/src/engine/local_engine/localberofactory.cpp +++ b/src/engine/local_engine/localberofactory.cpp @@ -11,6 +11,12 @@ // #include "localberofactory.h" +#include +#include +#include +#include +#include + using namespace std; LocalBeRoFactory::LocalBeRoFactory (HandInterface* hi, int id, int aP, int dP, int sB) diff --git a/src/engine/local_engine/localberofactory.h b/src/engine/local_engine/localberofactory.h index 5df7be77..65079c11 100644 --- a/src/engine/local_engine/localberofactory.h +++ b/src/engine/local_engine/localberofactory.h @@ -21,11 +21,6 @@ #include #include #include -#include -#include -#include -#include -#include /** @author FThauer FHammer diff --git a/src/engine/network_engine/clientberofactory.cpp b/src/engine/network_engine/clientberofactory.cpp index 4624854e..3728490c 100644 --- a/src/engine/network_engine/clientberofactory.cpp +++ b/src/engine/network_engine/clientberofactory.cpp @@ -10,10 +10,13 @@ // // #include "clientberofactory.h" -#include "berointerface.h" +#include +#include +#include +#include ClientBeRoFactory::ClientBeRoFactory(HandInterface* hi, int id, int aP, int dP, int sB) - : BeRoFactoryInterface() +: myHand(hi), myID(id), actualQuantityPlayers(aP), dealerPosition(dP), smallBlind(sB) { } @@ -24,14 +27,19 @@ ClientBeRoFactory::~ClientBeRoFactory() std::vector > ClientBeRoFactory::createBeRo() { - std::vector > bettingRounds; -//         bettingRounds.push_back(boost::shared_ptr(new -// LocalBeRoPreflop(...))); -//         bettingRounds.push_back(boost::shared_ptr(new -// LocalBeRoFlop(...))); -// -//         ... - return bettingRounds; + std::vector > myBeRo; + + myBeRo.push_back(boost::shared_ptr(new ClientBeRoPreflop(myHand, myID, actualQuantityPlayers, dealerPosition, smallBlind))); + + myBeRo.push_back(boost::shared_ptr(new ClientBeRoFlop(myHand, myID, actualQuantityPlayers, dealerPosition, smallBlind))); + + myBeRo.push_back(boost::shared_ptr(new ClientBeRoTurn(myHand, myID, actualQuantityPlayers, dealerPosition, smallBlind))); + + myBeRo.push_back(boost::shared_ptr(new ClientBeRoRiver(myHand, myID, actualQuantityPlayers, dealerPosition, smallBlind))); + +// myBeRo.push_back(boost::shared_ptr(new ClientBeRoPostRiver(myHand, myID, actualQuantityPlayers, dealerPosition, smallBlind))); + + return myBeRo; } diff --git a/src/engine/network_engine/clientberofactory.h b/src/engine/network_engine/clientberofactory.h index fb7b1c3f..37c80c96 100644 --- a/src/engine/network_engine/clientberofactory.h +++ b/src/engine/network_engine/clientberofactory.h @@ -35,6 +35,14 @@ public: std::vector > createBeRo(); +private: + + HandInterface* myHand; + + int myID; + int actualQuantityPlayers; + int dealerPosition; + int smallBlind; }; #endif diff --git a/src/engine/network_engine/clientenginefactory.cpp b/src/engine/network_engine/clientenginefactory.cpp index 42b20f6d..c869c069 100644 --- a/src/engine/network_engine/clientenginefactory.cpp +++ b/src/engine/network_engine/clientenginefactory.cpp @@ -56,22 +56,22 @@ PlayerInterface* ClientEngineFactory::createPlayer(BoardInterface *b, int id, un PreflopInterface* ClientEngineFactory::createPreflop(HandInterface* hi, int id, int aP, int dP, int sB) { - return new ClientPreflop(hi, id, aP, dP, sB); + return NULL; } FlopInterface* ClientEngineFactory::createFlop(HandInterface* hi, int id, int aP, int dP, int sB) { - return new ClientFlop(hi, id, aP, dP, sB); + return NULL; } TurnInterface* ClientEngineFactory::createTurn(HandInterface* hi, int id, int aP, int dP, int sB) { - return new ClientTurn(hi, id, aP, dP, sB); + return NULL; } RiverInterface* ClientEngineFactory::createRiver(HandInterface* hi, int id, int aP, int dP, int sB) { - return new ClientRiver(hi, id, aP, dP, sB); + return NULL; } BeRoFactoryInterface* ClientEngineFactory::createBeRoFactory(HandInterface* hi, int id, int aP, int dP, int sB) diff --git a/src/engine/network_engine/clientflop.cpp b/src/engine/network_engine/clientflop.cpp index 46a3a16c..3bd7ec05 100644 --- a/src/engine/network_engine/clientflop.cpp +++ b/src/engine/network_engine/clientflop.cpp @@ -22,100 +22,101 @@ //using namespace std; -ClientFlop::ClientFlop(HandInterface* bR, int id, int qP, int dP, int sB) +ClientBeRoFlop::ClientBeRoFlop(HandInterface* bR, int id, int qP, int dP, int sB) : myHand(bR), myID(id), actualQuantityPlayers(qP), dealerPosition(dP), smallBlindPosition(0), smallBlind(sB), highestSet(0), firstFlopRun(1), firstFlopRound(1), playersTurn(dP) { } -ClientFlop::~ClientFlop() +ClientBeRoFlop::~ClientBeRoFlop() { } +int +ClientBeRoFlop::getMyBeRoID() const +{ + return GAME_STATE_FLOP; +} + void -ClientFlop::setPlayersTurn(int theValue) +ClientBeRoFlop::setPlayersTurn(int theValue) { boost::recursive_mutex::scoped_lock lock(m_syncMutex); playersTurn = theValue; } int -ClientFlop::getPlayersTurn() const +ClientBeRoFlop::getPlayersTurn() const { boost::recursive_mutex::scoped_lock lock(m_syncMutex); return playersTurn; } void -ClientFlop::setHighestSet(int theValue) +ClientBeRoFlop::setHighestSet(int theValue) { boost::recursive_mutex::scoped_lock lock(m_syncMutex); highestSet = theValue; } int -ClientFlop::getHighestSet() const +ClientBeRoFlop::getHighestSet() const { boost::recursive_mutex::scoped_lock lock(m_syncMutex); return highestSet; } void -ClientFlop::setFirstFlopRound(bool theValue) +ClientBeRoFlop::setFirstFlopRound(bool theValue) { boost::recursive_mutex::scoped_lock lock(m_syncMutex); firstFlopRound = theValue; } bool -ClientFlop::getFirstFlopRound() const +ClientBeRoFlop::getFirstFlopRound() const { boost::recursive_mutex::scoped_lock lock(m_syncMutex); return firstFlopRound; } void -ClientFlop::setSmallBlindPosition(int theValue) +ClientBeRoFlop::setSmallBlindPosition(int theValue) { boost::recursive_mutex::scoped_lock lock(m_syncMutex); smallBlindPosition = theValue; } int -ClientFlop::getSmallBlindPosition() const +ClientBeRoFlop::getSmallBlindPosition() const { boost::recursive_mutex::scoped_lock lock(m_syncMutex); return smallBlindPosition; } void -ClientFlop::setSmallBlind(int theValue) +ClientBeRoFlop::setSmallBlind(int theValue) { boost::recursive_mutex::scoped_lock lock(m_syncMutex); smallBlind = theValue; } int -ClientFlop::getSmallBlind() const +ClientBeRoFlop::getSmallBlind() const { boost::recursive_mutex::scoped_lock lock(m_syncMutex); return smallBlind; } void -ClientFlop::resetFirstRun() +ClientBeRoFlop::resetFirstRun() { boost::recursive_mutex::scoped_lock lock(m_syncMutex); firstFlopRun = false; } void -ClientFlop::flopRun() -{ -} - -void -ClientFlop::nextPlayer2() +ClientBeRoFlop::run() { } diff --git a/src/engine/network_engine/clientflop.h b/src/engine/network_engine/clientflop.h index 21c7a482..ccf1c1b8 100644 --- a/src/engine/network_engine/clientflop.h +++ b/src/engine/network_engine/clientflop.h @@ -19,17 +19,18 @@ #ifndef CLIENTFLOP_H #define CLIENTFLOP_H -#include "flopinterface.h" +#include "berointerface.h" #include class HandInterface; -class ClientFlop : public FlopInterface +class ClientBeRoFlop : public BeRoInterface { public: - ClientFlop(HandInterface*, int, int, int, int); - ~ClientFlop(); + ClientBeRoFlop(HandInterface*, int, int, int, int); + ~ClientBeRoFlop(); + int getMyBeRoID() const; void setPlayersTurn(int theValue); int getPlayersTurn() const; @@ -46,10 +47,20 @@ public: void setSmallBlind(int theValue); int getSmallBlind() const; + void setHighestCardsValue(int theValue) {} + int getHighestCardsValue() const {return 0;} + void resetFirstRun(); - void flopRun(); - void nextPlayer2(); + void run(); + + void preflopRun() {} + void flopRun() {} + void turnRun() {} + void riverRun() {} + void postRiverRun() {} + + void nextPlayer2() {} private: mutable boost::recursive_mutex m_syncMutex; diff --git a/src/engine/network_engine/clientpreflop.cpp b/src/engine/network_engine/clientpreflop.cpp index 26582eda..548b28d3 100644 --- a/src/engine/network_engine/clientpreflop.cpp +++ b/src/engine/network_engine/clientpreflop.cpp @@ -23,52 +23,58 @@ using namespace std; -ClientPreflop::ClientPreflop(HandInterface* bR, int id, int qP, int dP, int sB) +ClientBeRoPreflop::ClientBeRoPreflop(HandInterface* bR, int id, int qP, int dP, int sB) : myHand(bR), myID(id), actualQuantityPlayers(qP), dealerPosition(dP), bigBlindPosition(0), smallBlind(sB), highestSet(2*sB), preflopFirstRound(1), playersTurn(0) { } -ClientPreflop::~ClientPreflop() +ClientBeRoPreflop::~ClientBeRoPreflop() { } +int +ClientBeRoPreflop::getMyBeRoID() const +{ + return GAME_STATE_PREFLOP; +} + void -ClientPreflop::setPlayersTurn(int theValue) +ClientBeRoPreflop::setPlayersTurn(int theValue) { boost::recursive_mutex::scoped_lock lock(m_syncMutex); playersTurn = theValue; } int -ClientPreflop::getPlayersTurn() const +ClientBeRoPreflop::getPlayersTurn() const { boost::recursive_mutex::scoped_lock lock(m_syncMutex); return playersTurn; } void -ClientPreflop::setHighestSet(int theValue) +ClientBeRoPreflop::setHighestSet(int theValue) { boost::recursive_mutex::scoped_lock lock(m_syncMutex); highestSet = theValue; } int -ClientPreflop::getHighestSet() const +ClientBeRoPreflop::getHighestSet() const { boost::recursive_mutex::scoped_lock lock(m_syncMutex); return highestSet; } void -ClientPreflop::preflopRun() +ClientBeRoPreflop::resetFirstRun() { } void -ClientPreflop::nextPlayer2() +ClientBeRoPreflop::run() { } diff --git a/src/engine/network_engine/clientpreflop.h b/src/engine/network_engine/clientpreflop.h index 99d6ffbe..2d55c897 100644 --- a/src/engine/network_engine/clientpreflop.h +++ b/src/engine/network_engine/clientpreflop.h @@ -19,16 +19,18 @@ #ifndef CLIENTPREFLOP_H #define CLIENTPREFLOP_H -#include +#include #include class HandInterface; -class ClientPreflop : public PreflopInterface{ +class ClientBeRoPreflop : public BeRoInterface{ public: - ClientPreflop(HandInterface*, int, int, int, int); - ~ClientPreflop(); + ClientBeRoPreflop(HandInterface*, int, int, int, int); + ~ClientBeRoPreflop(); + + int getMyBeRoID() const; void setPlayersTurn(int theValue); int getPlayersTurn() const; @@ -36,8 +38,20 @@ public: void setHighestSet(int theValue); int getHighestSet() const; - void preflopRun(); - void nextPlayer2(); + void setHighestCardsValue(int theValue) {} + int getHighestCardsValue() const {return 0;} + + void resetFirstRun(); + + void run(); + + void preflopRun() {} + void flopRun() {} + void turnRun() {} + void riverRun() {} + void postRiverRun() {} + + void nextPlayer2() {} private: mutable boost::recursive_mutex m_syncMutex; diff --git a/src/engine/network_engine/clientriver.cpp b/src/engine/network_engine/clientriver.cpp index a910f906..d17b8f35 100644 --- a/src/engine/network_engine/clientriver.cpp +++ b/src/engine/network_engine/clientriver.cpp @@ -22,122 +22,119 @@ //using namespace std; -ClientRiver::ClientRiver(HandInterface* bR, int id, int qP, int dP, int sB) +ClientBeRoRiver::ClientBeRoRiver(HandInterface* bR, int id, int qP, int dP, int sB) : myHand(bR), myID(id), actualQuantityPlayers(qP), dealerPosition(dP), smallBlindPosition(0), smallBlind(sB), highestSet(0), firstRiverRun(1), firstRiverRound(1), playersTurn(dP), highestCardsValue(0) { } -ClientRiver::~ClientRiver() +ClientBeRoRiver::~ClientBeRoRiver() { } +int +ClientBeRoRiver::getMyBeRoID() const +{ + return GAME_STATE_RIVER; +} + void -ClientRiver::setPlayersTurn(int theValue) +ClientBeRoRiver::setPlayersTurn(int theValue) { boost::recursive_mutex::scoped_lock lock(m_syncMutex); playersTurn = theValue; } int -ClientRiver::getPlayersTurn() const +ClientBeRoRiver::getPlayersTurn() const { boost::recursive_mutex::scoped_lock lock(m_syncMutex); return playersTurn; } void -ClientRiver::setHighestSet(int theValue) +ClientBeRoRiver::setHighestSet(int theValue) { boost::recursive_mutex::scoped_lock lock(m_syncMutex); highestSet = theValue; } int -ClientRiver::getHighestSet() const +ClientBeRoRiver::getHighestSet() const { boost::recursive_mutex::scoped_lock lock(m_syncMutex); return highestSet; } void -ClientRiver::setFirstRiverRound(bool theValue) +ClientBeRoRiver::setFirstRiverRound(bool theValue) { boost::recursive_mutex::scoped_lock lock(m_syncMutex); firstRiverRound = theValue; } bool -ClientRiver::getFirstRiverRound() const +ClientBeRoRiver::getFirstRiverRound() const { boost::recursive_mutex::scoped_lock lock(m_syncMutex); return firstRiverRound; } void -ClientRiver::setSmallBlindPosition(int theValue) +ClientBeRoRiver::setSmallBlindPosition(int theValue) { boost::recursive_mutex::scoped_lock lock(m_syncMutex); smallBlindPosition = theValue; } int -ClientRiver::getSmallBlindPosition() const +ClientBeRoRiver::getSmallBlindPosition() const { boost::recursive_mutex::scoped_lock lock(m_syncMutex); return smallBlindPosition; } void -ClientRiver::setSmallBlind(int theValue) +ClientBeRoRiver::setSmallBlind(int theValue) { boost::recursive_mutex::scoped_lock lock(m_syncMutex); smallBlind = theValue; } int -ClientRiver::getSmallBlind() const +ClientBeRoRiver::getSmallBlind() const { boost::recursive_mutex::scoped_lock lock(m_syncMutex); return smallBlind; } void -ClientRiver::setHighestCardsValue(int theValue) +ClientBeRoRiver::setHighestCardsValue(int theValue) { boost::recursive_mutex::scoped_lock lock(m_syncMutex); highestCardsValue = theValue; } int -ClientRiver::getHighestCardsValue() const +ClientBeRoRiver::getHighestCardsValue() const { boost::recursive_mutex::scoped_lock lock(m_syncMutex); return highestCardsValue; } void -ClientRiver::resetFirstRun() +ClientBeRoRiver::resetFirstRun() { boost::recursive_mutex::scoped_lock lock(m_syncMutex); firstRiverRun = false; } void -ClientRiver::riverRun() +ClientBeRoRiver::distributePot() { } void -ClientRiver::postRiverRun() +ClientBeRoRiver::run() { } -void -ClientRiver::nextPlayer2() -{ -} - -void -ClientRiver::distributePot() -{ -} diff --git a/src/engine/network_engine/clientriver.h b/src/engine/network_engine/clientriver.h index 15c2001a..85658da7 100644 --- a/src/engine/network_engine/clientriver.h +++ b/src/engine/network_engine/clientriver.h @@ -19,16 +19,18 @@ #ifndef CLIENTRIVER_H #define CLIENTRIVER_H -#include +#include #include class HandInterface; -class ClientRiver : public RiverInterface{ +class ClientBeRoRiver : public BeRoInterface{ public: - ClientRiver(HandInterface*, int, int, int, int); - ~ClientRiver(); + ClientBeRoRiver(HandInterface*, int, int, int, int); + ~ClientBeRoRiver(); + + int getMyBeRoID() const; void setPlayersTurn(int theValue); int getPlayersTurn() const; @@ -50,11 +52,18 @@ public: void resetFirstRun(); - void riverRun(); - void postRiverRun(); - void nextPlayer2(); void distributePot(); - + + void run(); + + void preflopRun() {} + void flopRun() {} + void turnRun() {} + void riverRun() {} + void postRiverRun() {} + + void nextPlayer2() {} + private: mutable boost::recursive_mutex m_syncMutex; diff --git a/src/engine/network_engine/clientturn.cpp b/src/engine/network_engine/clientturn.cpp index 353acaf4..b1dcb92e 100644 --- a/src/engine/network_engine/clientturn.cpp +++ b/src/engine/network_engine/clientturn.cpp @@ -22,99 +22,100 @@ //using namespace std; -ClientTurn::ClientTurn(HandInterface* bR, int id, int qP, int dP, int sB) +ClientBeRoTurn::ClientBeRoTurn(HandInterface* bR, int id, int qP, int dP, int sB) : myHand(bR), myID(id), actualQuantityPlayers(qP), dealerPosition(dP), smallBlindPosition(0), smallBlind(sB), highestSet(0), firstTurnRun(1), firstTurnRound(1), playersTurn(dP) { } -ClientTurn::~ClientTurn() +ClientBeRoTurn::~ClientBeRoTurn() { } +int +ClientBeRoTurn::getMyBeRoID() const +{ + return GAME_STATE_TURN; +} + void -ClientTurn::setPlayersTurn(int theValue) +ClientBeRoTurn::setPlayersTurn(int theValue) { boost::recursive_mutex::scoped_lock lock(m_syncMutex); playersTurn = theValue; } int -ClientTurn::getPlayersTurn() const +ClientBeRoTurn::getPlayersTurn() const { boost::recursive_mutex::scoped_lock lock(m_syncMutex); return playersTurn; } void -ClientTurn::setHighestSet(int theValue) +ClientBeRoTurn::setHighestSet(int theValue) { boost::recursive_mutex::scoped_lock lock(m_syncMutex); highestSet = theValue; } int -ClientTurn::getHighestSet() const +ClientBeRoTurn::getHighestSet() const { boost::recursive_mutex::scoped_lock lock(m_syncMutex); return highestSet; } void -ClientTurn::setFirstTurnRound(bool theValue) +ClientBeRoTurn::setFirstTurnRound(bool theValue) { boost::recursive_mutex::scoped_lock lock(m_syncMutex); firstTurnRound = theValue; } bool -ClientTurn::getFirstTurnRound() const +ClientBeRoTurn::getFirstTurnRound() const { boost::recursive_mutex::scoped_lock lock(m_syncMutex); return firstTurnRound; } void -ClientTurn::setSmallBlindPosition(int theValue) +ClientBeRoTurn::setSmallBlindPosition(int theValue) { boost::recursive_mutex::scoped_lock lock(m_syncMutex); smallBlindPosition = theValue; } int -ClientTurn::getSmallBlindPosition() const +ClientBeRoTurn::getSmallBlindPosition() const { boost::recursive_mutex::scoped_lock lock(m_syncMutex); return smallBlindPosition; } void -ClientTurn::setSmallBlind(int theValue) +ClientBeRoTurn::setSmallBlind(int theValue) { boost::recursive_mutex::scoped_lock lock(m_syncMutex); smallBlind = theValue; } int -ClientTurn::getSmallBlind() const +ClientBeRoTurn::getSmallBlind() const { boost::recursive_mutex::scoped_lock lock(m_syncMutex); return smallBlind; } void -ClientTurn::resetFirstRun() +ClientBeRoTurn::resetFirstRun() { boost::recursive_mutex::scoped_lock lock(m_syncMutex); firstTurnRun = false; } void -ClientTurn::turnRun() -{ -} - -void -ClientTurn::nextPlayer2() +ClientBeRoTurn::run() { } diff --git a/src/engine/network_engine/clientturn.h b/src/engine/network_engine/clientturn.h index 71815427..e048e57e 100644 --- a/src/engine/network_engine/clientturn.h +++ b/src/engine/network_engine/clientturn.h @@ -19,15 +19,17 @@ #ifndef CLIENTTURN_H #define CLIENTTURN_H -#include +#include #include class HandInterface; -class ClientTurn : public TurnInterface{ +class ClientBeRoTurn : public BeRoInterface{ public: - ClientTurn(HandInterface*, int, int, int, int); - ~ClientTurn(); + ClientBeRoTurn(HandInterface*, int, int, int, int); + ~ClientBeRoTurn(); + + int getMyBeRoID() const; void setPlayersTurn(int theValue); int getPlayersTurn() const; @@ -44,10 +46,20 @@ public: void setSmallBlind(int theValue); int getSmallBlind() const; + void setHighestCardsValue(int theValue) {} + int getHighestCardsValue() const {return 0;} + void resetFirstRun(); - void turnRun(); - void nextPlayer2(); + void run(); + + void preflopRun() {} + void flopRun() {} + void turnRun() {} + void riverRun() {} + void postRiverRun() {} + + void nextPlayer2() {} private: mutable boost::recursive_mutex m_syncMutex; diff --git a/src/net/common/serverrecvstate.cpp b/src/net/common/serverrecvstate.cpp index 00faa6da..cd0d469b 100644 --- a/src/net/common/serverrecvstate.cpp +++ b/src/net/common/serverrecvstate.cpp @@ -340,6 +340,22 @@ ServerRecvStateInit::InternalProcess(ServerRecvThread &server, SessionWrapper se } else if (packet->ToNetPacketStartEvent()) { + boost::shared_ptr tmpPlayerData( + new PlayerData(m_curUniquePlayerId++, 0, PLAYER_TYPE_COMPUTER, PLAYER_RIGHTS_NORMAL)); + tmpPlayerData->SetName("Computer"); + + // Send "Player Joined" to other fully connected clients. + boost::shared_ptr thisPlayerJoined(new NetPacketPlayerJoined); + NetPacketPlayerJoined::Data thisPlayerJoinedData; + thisPlayerJoinedData.playerId = tmpPlayerData->GetUniqueId(); + thisPlayerJoinedData.playerName = tmpPlayerData->GetName(); + thisPlayerJoinedData.ptype = tmpPlayerData->GetType(); + thisPlayerJoinedData.prights = tmpPlayerData->GetRights(); + static_cast(thisPlayerJoined.get())->SetData(thisPlayerJoinedData); + server.SendToAllPlayers(thisPlayerJoined); + + server.AddComputerPlayer(tmpPlayerData); + server.InternalStartGame(); server.SetState(SERVER_START_GAME_STATE::Instance()); } @@ -762,11 +778,17 @@ ServerRecvStateWaitPlayerAction::Process(ServerRecvThread &server) { int retVal; - // If the player we are waiting for left, continue without him. PlayerInterface *tmpPlayer = GetCurrentPlayer(server.GetGame()); assert(tmpPlayer); assert(!tmpPlayer->getMyName().empty()); - if (!server.IsPlayerConnected(tmpPlayer->getMyName())) + + // If the player is computer controlled, let the engine act. + if (tmpPlayer->getMyType() == PLAYER_TYPE_COMPUTER) + { + tmpPlayer->action(); + } + // If the player we are waiting for left, continue without him. + else if (!server.IsPlayerConnected(tmpPlayer->getMyName())) { PerformPlayerAction(server, tmpPlayer, PLAYER_ACTION_FOLD, 0); @@ -832,6 +854,15 @@ ServerRecvStateWaitPlayerAction::PerformPlayerAction(ServerRecvThread &server, P curGame.getCurrentHand()->getBoard()->collectSets(); } + SendPlayerAction(server, player); +} + +void +ServerRecvStateWaitPlayerAction::SendPlayerAction(ServerRecvThread &server, PlayerInterface *player) +{ + Game &curGame = server.GetGame(); + assert(player); + boost::shared_ptr notifyActionDone(new NetPacketPlayersActionDone); NetPacketPlayersActionDone::Data actionDoneData; actionDoneData.gameState = static_cast(curGame.getCurrentHand()->getActualRound()); diff --git a/src/net/common/serverrecvthread.cpp b/src/net/common/serverrecvthread.cpp index d62855e2..3b16a299 100644 --- a/src/net/common/serverrecvthread.cpp +++ b/src/net/common/serverrecvthread.cpp @@ -469,7 +469,7 @@ ServerRecvThread::RemoveDisconnectedPlayers() for (int i = 0; i < m_game->getStartQuantityPlayers(); i++) { PlayerInterface *tmpPlayer = m_game->getPlayerArray()[i]; - if (!IsPlayerConnected(tmpPlayer->getMyUniqueID())) + if (!IsPlayerConnected(tmpPlayer->getMyUniqueID()) && tmpPlayer->getMyType() == PLAYER_TYPE_HUMAN) { tmpPlayer->setMyCash(0); tmpPlayer->setMyActiveStatus(false); @@ -479,6 +479,12 @@ ServerRecvThread::RemoveDisconnectedPlayers() } } +void +ServerRecvThread::AddComputerPlayer(boost::shared_ptr player) +{ + m_computerPlayers.push_back(player); +} + size_t ServerRecvThread::GetCurNumberOfPlayers() const { @@ -552,6 +558,8 @@ ServerRecvThread::GetPlayerDataList() const } ++session_i; } + if (!m_computerPlayers.empty()) + playerList.insert(playerList.end(), m_computerPlayers.begin(), m_computerPlayers.end()); return playerList; } diff --git a/src/net/serverrecvstate.h b/src/net/serverrecvstate.h index ff93d354..8d064c19 100644 --- a/src/net/serverrecvstate.h +++ b/src/net/serverrecvstate.h @@ -208,6 +208,7 @@ protected: virtual int InternalProcess(ServerRecvThread &server, SessionWrapper session, boost::shared_ptr packet); static void PerformPlayerAction(ServerRecvThread &server, PlayerInterface *player, PlayerAction action, int bet); + static void SendPlayerAction(ServerRecvThread &server, PlayerInterface *player); static int GetHighestSet(Game &curGame); static void SetHighestSet(Game &curGame, int highestSet); }; diff --git a/src/net/serverrecvthread.h b/src/net/serverrecvthread.h index e1ef511b..402d4831 100644 --- a/src/net/serverrecvthread.h +++ b/src/net/serverrecvthread.h @@ -112,6 +112,8 @@ protected: void RemoveNotEstablishedSessions(); void RemoveDisconnectedPlayers(); + void AddComputerPlayer(boost::shared_ptr player); + size_t GetCurNumberOfPlayers() const; bool IsPlayerConnected(const std::string &playerName) const; bool IsPlayerConnected(unsigned uniquePlayerId) const; @@ -147,6 +149,8 @@ private: SocketSessionMap m_sessionMap; mutable boost::mutex m_sessionMapMutex; + PlayerDataList m_computerPlayers; + CloseSessionList m_closeSessionList; std::auto_ptr m_receiver;