diff --git a/src/engine/local_engine/localhand.cpp b/src/engine/local_engine/localhand.cpp index f2d6110b..eb3ff3cb 100755 --- a/src/engine/local_engine/localhand.cpp +++ b/src/engine/local_engine/localhand.cpp @@ -25,7 +25,10 @@ using namespace std; LocalHand::LocalHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, PlayerInterface **p, int id, int sP, int aP, int dP, int sB,int sC) -: HandInterface(), myFactory(f), myGui(g), myBoard(b), playerArray(p), myPreflop(0), myFlop(0), myTurn(0), myRiver(0), myID(id), actualQuantityPlayers(aP), startQuantityPlayers(sP), dealerPosition(dP), actualRound(0), smallBlind(sB), startCash(sC), lastPlayersTurn(0), allInCondition(0), bettingRoundsPlayed(0) +: myFactory(f), myGui(g), myBoard(b), playerArray(p), myPreflop(0), myFlop(0), myTurn(0), myRiver(0), + myID(id), actualQuantityPlayers(aP), startQuantityPlayers(sP), dealerPosition(dP), actualRound(0), + smallBlind(sB), startCash(sC), activePlayersCounter(aP), lastPlayersTurn(0), allInCondition(0), + bettingRoundsPlayed(0) { int i, j, k; @@ -39,6 +42,8 @@ LocalHand::LocalHand(boost::shared_ptr f, GuiInterface *g, BoardI if(playerArray[i]->getMyActiveStatus() != 0) { playerArray[i]->setHand(this); } + // myFlipCards auf 0 setzen + playerArray[i]->setMyCardsFlip(0, 0); } @@ -89,11 +94,6 @@ LocalHand::LocalHand(boost::shared_ptr f, GuiInterface *g, BoardI } delete[] cardsArray; - // myFlipCards auf 0 setzen - for(i=0; isetMyCardsFlip(0, 0); - } - // // // !!!!!!!!!!!!!!!!!!!!!!!!!!!!! testing !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // // // int *temp5Array; @@ -353,7 +353,7 @@ void LocalHand::switchRounds() { //unhighlight actual players groupbox if(playerArray[lastPlayersTurn]->getMyActiveStatus() == 1) myGui->refreshGroupbox(lastPlayersTurn,1); - myGui->refreshGameLabels(actualRound); + myGui->refreshGameLabels(); // /*/*/*/*cout <<*/*/*/*/ "NextPlayerSpeed1 stop" << endl; // // cout << "NextPlayerSpeed2 start" << endl; diff --git a/src/engine/network_engine/clienthand.cpp b/src/engine/network_engine/clienthand.cpp index 912ffc6c..d56d97ee 100644 --- a/src/engine/network_engine/clienthand.cpp +++ b/src/engine/network_engine/clienthand.cpp @@ -22,7 +22,10 @@ using namespace std; ClientHand::ClientHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, PlayerInterface **p, int id, int sP, int aP, int dP, int sB,int sC) -: myFactory(f), myGui(g), myBoard(b), playerArray(p), myPreflop(0), myFlop(0), myTurn(0), myRiver(0), myID(id), actualQuantityPlayers(aP), startQuantityPlayers(sP), dealerPosition(dP), actualRound(0), smallBlind(sB), startCash(sC), allInCondition(0), bettingRoundsPlayed(0) +: myFactory(f), myGui(g), myBoard(b), playerArray(p), myPreflop(0), myFlop(0), myTurn(0), myRiver(0), + myID(id), actualQuantityPlayers(aP), startQuantityPlayers(sP), dealerPosition(dP), actualRound(0), + smallBlind(sB), startCash(sC), activePlayersCounter(aP), lastPlayersTurn(0), allInCondition(0), + bettingRoundsPlayed(0) { int i; lastPlayersTurn = 0; @@ -34,6 +37,7 @@ ClientHand::ClientHand(boost::shared_ptr f, GuiInterface *g, Boar if(playerArray[i]->getMyActiveStatus() != 0) { playerArray[i]->setHand(this); } + // myFlipCards auf 0 setzen playerArray[i]->setMyCardsFlip(0, 0); } @@ -72,6 +76,11 @@ ClientHand::start() void ClientHand::switchRounds() { + // update active players counter. + activePlayersCounter = 0; + for (int i = 0; i < MAX_NUMBER_OF_PLAYERS; i++) { + if (playerArray[i]->getMyAction() != 1 && playerArray[i]->getMyActiveStatus() == 1) activePlayersCounter++; + } } diff --git a/src/gui/generic/serverguiwrapper.cpp b/src/gui/generic/serverguiwrapper.cpp index 2d6a8ee9..6a3c8dfd 100644 --- a/src/gui/generic/serverguiwrapper.cpp +++ b/src/gui/generic/serverguiwrapper.cpp @@ -60,15 +60,13 @@ void ServerGuiWrapper::refreshPot() const {} void ServerGuiWrapper::refreshGroupbox(int playerID, int status) const {} void ServerGuiWrapper::refreshPlayerName() const {} void ServerGuiWrapper::refreshButton() const {} +void ServerGuiWrapper::refreshGameLabels() const {} void ServerGuiWrapper::dealHoleCards() {} void ServerGuiWrapper::dealFlopCards() {} void ServerGuiWrapper::dealTurnCard() {} void ServerGuiWrapper::dealRiverCard() {} -void ServerGuiWrapper::refreshGameLabels(int round) const {} - - void ServerGuiWrapper::nextPlayerAnimation() {} void ServerGuiWrapper::preflopAnimation1() {} diff --git a/src/gui/generic/serverguiwrapper.h b/src/gui/generic/serverguiwrapper.h index 55a15b53..81019522 100644 --- a/src/gui/generic/serverguiwrapper.h +++ b/src/gui/generic/serverguiwrapper.h @@ -44,7 +44,7 @@ public: void refreshAll() const; void refreshPlayerName() const; void refreshButton() const; - void refreshGameLabels(int round) const; + void refreshGameLabels() const; void dealHoleCards(); void dealFlopCards(); diff --git a/src/gui/guiinterface.h b/src/gui/guiinterface.h index 318629ce..9340922a 100644 --- a/src/gui/guiinterface.h +++ b/src/gui/guiinterface.h @@ -49,6 +49,7 @@ public: virtual void refreshAll() const=0; virtual void refreshPlayerName() const=0; virtual void refreshButton() const =0; + virtual void refreshGameLabels() const=0; // // Karten-Funktionen virtual void dealHoleCards()=0; @@ -56,8 +57,6 @@ public: virtual void dealTurnCard()=0; virtual void dealRiverCard()=0; - virtual void refreshGameLabels(int) const=0; - virtual void nextPlayerAnimation()=0; virtual void preflopAnimation1()=0; diff --git a/src/gui/qt/guiwrapper.cpp b/src/gui/qt/guiwrapper.cpp index ced874d0..1268f093 100644 --- a/src/gui/qt/guiwrapper.cpp +++ b/src/gui/qt/guiwrapper.cpp @@ -44,7 +44,7 @@ GuiWrapper::~GuiWrapper() { } -void GuiWrapper::initGui(int speed) { myW->initGui(speed); } +void GuiWrapper::initGui(int speed) { myW->signalInitGui(speed); } Session &GuiWrapper::getSession() { return myW->getSession(); } void GuiWrapper::setSession(boost::shared_ptr session) { myW->setSession(session); } @@ -58,7 +58,7 @@ void GuiWrapper::refreshPot() const { myW->signalRefreshPot(); } void GuiWrapper::refreshGroupbox(int playerID, int status) const { myW->signalRefreshGroupbox(playerID, status); } void GuiWrapper::refreshPlayerName() const { myW->signalRefreshPlayerName(); } void GuiWrapper::refreshButton() const { myW->signalRefreshButton(); } -void GuiWrapper::refreshGameLabels(int round) const { myW->signalRefreshGameLabels(round); } +void GuiWrapper::refreshGameLabels() const { myW->signalRefreshGameLabels(); } void GuiWrapper::dealHoleCards() { myW->signalDealHoleCards(); } void GuiWrapper::dealFlopCards() { myW->signalDealFlopCards0(); } diff --git a/src/gui/qt/guiwrapper.h b/src/gui/qt/guiwrapper.h index 03f6ba6b..997697de 100644 --- a/src/gui/qt/guiwrapper.h +++ b/src/gui/qt/guiwrapper.h @@ -52,14 +52,13 @@ public: void refreshAll() const; void refreshPlayerName() const; void refreshButton() const; + void refreshGameLabels() const; void dealHoleCards(); void dealFlopCards(); void dealTurnCard(); void dealRiverCard(); - void refreshGameLabels(int round) const; - void nextPlayerAnimation(); void preflopAnimation1(); diff --git a/src/gui/qt/mainwindow/mainwindowimpl.cpp b/src/gui/qt/mainwindow/mainwindowimpl.cpp index 24744924..9474f570 100755 --- a/src/gui/qt/mainwindow/mainwindowimpl.cpp +++ b/src/gui/qt/mainwindow/mainwindowimpl.cpp @@ -572,6 +572,8 @@ mainWindowImpl::mainWindowImpl(ConfigFile *c, QMainWindow *parent) connect( lineEdit_ChatInput, SIGNAL( textChanged (QString) ), this, SLOT( checkChatInputLength(QString) ) ); //Nachrichten Thread-Save + connect(this, SIGNAL(signalInitGui(int)), this, SLOT(initGui(int))); + connect(this, SIGNAL(signalRefreshSet()), this, SLOT(refreshSet())); connect(this, SIGNAL(signalRefreshCash()), this, SLOT(refreshCash())); connect(this, SIGNAL(signalRefreshAction(int, int)), this, SLOT(refreshAction(int, int))); @@ -581,6 +583,7 @@ mainWindowImpl::mainWindowImpl(ConfigFile *c, QMainWindow *parent) connect(this, SIGNAL(signalRefreshAll()), this, SLOT(refreshAll())); connect(this, SIGNAL(signalRefreshPlayerName()), this, SLOT(refreshPlayerName())); connect(this, SIGNAL(signalRefreshButton()), this, SLOT(refreshButton())); + connect(this, SIGNAL(signalRefreshGameLabels()), this, SLOT(refreshGameLabels())); connect(this, SIGNAL(signalMeInAction()), this, SLOT(meInAction())); @@ -589,7 +592,6 @@ mainWindowImpl::mainWindowImpl(ConfigFile *c, QMainWindow *parent) connect(this, SIGNAL(signalDealTurnCards0()), this, SLOT(dealTurnCards0())); connect(this, SIGNAL(signalDealRiverCards0()), this, SLOT(dealRiverCards0())); - connect(this, SIGNAL(signalRefreshGameLabels(int)), this, SLOT(refreshGameLabels(int))); connect(this, SIGNAL(signalNextPlayerAnimation()), this, SLOT(nextPlayerAnimation())); connect(this, SIGNAL(signalPreflopAnimation1()), this, SLOT(preflopAnimation1())); @@ -1181,9 +1183,9 @@ void mainWindowImpl::refreshGroupbox(int playerID, int status) { } } -void mainWindowImpl::refreshGameLabels(int round) { +void mainWindowImpl::refreshGameLabels() { - switch(round) { + switch(mySession->getCurrentGame()->getCurrentHand()->getActualRound()) { case 0: { textLabel_handLabel->setText("Preflop"); } break; @@ -2472,6 +2474,11 @@ void mainWindowImpl::networkError(int errorID, int osErrorID) { { myChangeHumanPlayerNameDialog->label_Message->setText(tr("The player name is either too short or too long. Please choose another one.")); myChangeHumanPlayerNameDialog->exec(); } break; + case ERR_NET_UNKNOWN_PLAYER_ID: + { QMessageBox::warning(this, tr("Network Error"), + tr("The server referred to an unknown player. Aborting."), + QMessageBox::Close); } + break; default: { QMessageBox::warning(this, tr("Network Error"), tr("An internal error occured."), QMessageBox::Close); } diff --git a/src/gui/qt/mainwindow/mainwindowimpl.h b/src/gui/qt/mainwindow/mainwindowimpl.h index 5b4ac616..a83d1e2d 100755 --- a/src/gui/qt/mainwindow/mainwindowimpl.h +++ b/src/gui/qt/mainwindow/mainwindowimpl.h @@ -64,8 +64,6 @@ public: ~mainWindowImpl(); - void initGui(int speed); - Session &getSession(); void setSession(boost::shared_ptr session); @@ -75,6 +73,8 @@ public: void setSpeeds(); signals: + void signalInitGui(int speed); + void signalRefreshSet(); void signalRefreshCash(); void signalRefreshAction(int =-1, int=-1); @@ -92,7 +92,7 @@ signals: void signalDealTurnCards0(); void signalDealRiverCards0(); - void signalRefreshGameLabels(int); + void signalRefreshGameLabels(); void signalNextPlayerAnimation(); void signalPreflopAnimation1(); @@ -122,6 +122,8 @@ signals: public slots: + void initGui(int speed); + //refresh-Funktionen void refreshSet(); void refreshCash(); @@ -131,7 +133,7 @@ public slots: void refreshGroupbox(int =-1, int =-1); void refreshAll(); void refreshPlayerName(); - void refreshGameLabels(int); + void refreshGameLabels(); void refreshButton(); void refreshPlayerAvatar(); diff --git a/src/net/clientstate.h b/src/net/clientstate.h index 3e16ea64..ae25935c 100644 --- a/src/net/clientstate.h +++ b/src/net/clientstate.h @@ -257,7 +257,7 @@ protected: static void SetPlayersTurn(Game &curGame, int playersTurn); }; -// State: Final (TODO). +// State: Final (just for testing, should not be used). class ClientStateFinal : public ClientState { public: diff --git a/src/net/common/clientstate.cpp b/src/net/common/clientstate.cpp index c8cf1f3c..1be41e19 100644 --- a/src/net/common/clientstate.cpp +++ b/src/net/common/clientstate.cpp @@ -538,6 +538,7 @@ ClientStateWaitHand::InternalProcess(ClientThread &client, boost::shared_ptrinitHand(); client.GetGame()->startHand(); client.GetGui().dealHoleCards(); + client.GetGui().refreshGameLabels(); client.SetState(ClientStateRunHand::Instance()); retVal = MSG_NET_GAME_CLIENT_HAND_START; @@ -577,7 +578,8 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptrToNetPacketPlayersActionDone()->GetData(actionDoneData); PlayerInterface *tmpPlayer = curGame->getPlayerByUniqueId(actionDoneData.playerId); - assert(tmpPlayer); // TODO: throw exception + if (!tmpPlayer) + throw ClientException(ERR_NET_UNKNOWN_PLAYER_ID, 0); if (actionDoneData.gameState == GAME_STATE_PREFLOP_SMALL_BLIND) tmpPlayer->setMyButton(BUTTON_SMALL_BLIND); @@ -609,7 +611,8 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptrToNetPacketPlayersTurn()->GetData(turnData); PlayerInterface *tmpPlayer = curGame->getPlayerByUniqueId(turnData.playerId); - assert(tmpPlayer); // TODO: throw exception + if (!tmpPlayer) + throw ClientException(ERR_NET_UNKNOWN_PLAYER_ID, 0); // Set round. if (curGame->getCurrentHand()->getActualRound() != turnData.gameState) @@ -623,12 +626,13 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptrgetPlayerArray()[i]->setMySetNull(); } + curGame->getCurrentHand()->setActualRound(turnData.gameState); + client.GetGui().refreshPot(); client.GetGui().refreshSet(); client.GetGui().refreshAction(); client.GetGui().refreshCash(); - - curGame->getCurrentHand()->setActualRound(turnData.gameState); + client.GetGui().refreshGameLabels(); } // Next player's turn. @@ -683,7 +687,8 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptrToNetPacketEndOfHandHideCards()->GetData(endHandData); PlayerInterface *tmpPlayer = curGame->getPlayerByUniqueId(endHandData.playerId); - assert(tmpPlayer); // TODO: throw exception + if (!tmpPlayer) + throw ClientException(ERR_NET_UNKNOWN_PLAYER_ID, 0); tmpPlayer->setMyCash(endHandData.playerMoney); // TODO use moneyWon @@ -711,7 +716,8 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptrgetPlayerByUniqueId((*i).playerId); - assert(tmpPlayer); // TODO: throw exception + if (!tmpPlayer) + throw ClientException(ERR_NET_UNKNOWN_PLAYER_ID, 0); int tmpCards[2]; tmpCards[0] = static_cast((*i).cards[0]); diff --git a/src/net/common/clientthread.cpp b/src/net/common/clientthread.cpp index 332a62de..1888ed75 100644 --- a/src/net/common/clientthread.cpp +++ b/src/net/common/clientthread.cpp @@ -53,7 +53,7 @@ private: ClientThread::ClientThread(GuiInterface &gui) -: m_curState(NULL), m_gui(gui), m_curGameId(0), m_guiPlayerNum(0) +: m_curState(NULL), m_gui(gui), m_curGameId(1), m_guiPlayerNum(0) { m_context.reset(new ClientContext); m_senderCallback.reset(new ClientSenderCallback(*this)); @@ -70,7 +70,10 @@ ClientThread::Init( const string &serverAddress, unsigned serverPort, bool ipv6, const string &pwd, const string &playerName) { if (IsRunning()) - return; // TODO: throw exception + { + assert(false); + return; + } ClientContext &context = GetContext(); diff --git a/src/net/socket_msg.h b/src/net/socket_msg.h index bce75293..1def77b9 100644 --- a/src/net/socket_msg.h +++ b/src/net/socket_msg.h @@ -50,6 +50,7 @@ #define ERR_NET_INVALID_PLAYER_NAME 107 #define ERR_NET_INVALID_PLAYER_RESULTS 108 #define ERR_NET_INVALID_CHAT_TEXT 109 +#define ERR_NET_UNKNOWN_PLAYER_ID 110 // This is an internal message which is not reported. #define MSG_SOCK_INTERNAL_PENDING 0