diff --git a/docs/net_protocol.txt b/docs/net_protocol.txt index c0fe70e6..87fa85ea 100644 --- a/docs/net_protocol.txt +++ b/docs/net_protocol.txt @@ -111,12 +111,12 @@ Server Notification: Game Start +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Message Type = 5 | Message Length = 8 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Start Dealer Pos | Reserved | + | Start Dealer Player Id | Reserved | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ [ Dealer Pos can be different for each game, therefore it is not transmitted in Join Game ACK. ] -[ It is not necessary to transmit the Dealer Pos, because the server +[ It is not necessary to transmit the Dealer Id, because the server decides which player's turn it is. This is only for fast and simple GUI display. ] diff --git a/src/engine/local_engine/localhand.cpp b/src/engine/local_engine/localhand.cpp index 5108eb04..e3d48ba1 100755 --- a/src/engine/local_engine/localhand.cpp +++ b/src/engine/local_engine/localhand.cpp @@ -49,9 +49,8 @@ LocalHand::LocalHand(boost::shared_ptr f, GuiInterface *g, BoardI } // Karten generieren und Board sowie Player zuweisen - Tools myTool; int *cardsArray = new int[2*actualQuantityPlayers+5]; - myTool.getRandNumber(0, 51, 2*actualQuantityPlayers+5, cardsArray, 1); + Tools::getRandNumber(0, 51, 2*actualQuantityPlayers+5, cardsArray, 1); int tempBoardArray[5]; int tempPlayerArray[2]; int tempPlayerAndBoardArray[7]; @@ -81,7 +80,7 @@ LocalHand::LocalHand(boost::shared_ptr f, GuiInterface *g, BoardI // sBluff für alle aktiver Spieler außer human player setzen if(i) { - myTool.getRandNumber(1,100,1,&sBluff,0); + Tools::getRandNumber(1,100,1,&sBluff,0); playerArray[i]->setSBluff(sBluff); playerArray[i]->setSBluffStatus(0); } diff --git a/src/engine/local_engine/localplayer.cpp b/src/engine/local_engine/localplayer.cpp index e767bda3..b90d13c9 100755 --- a/src/engine/local_engine/localplayer.cpp +++ b/src/engine/local_engine/localplayer.cpp @@ -54,9 +54,8 @@ LocalPlayer::LocalPlayer(ConfigFile *c, BoardInterface *b, int id, unsigned uniq myAggressive[i] = 0; } - Tools myTool; // Dude zuweisen - myTool.getRandNumber(3 , 5, 1, &myDude, 0); + Tools::getRandNumber(3 , 5, 1, &myDude, 0); // cout << "Spieler: " << myID << " Dude: " << myDude << " Cash: " << myCash << " ActiveStatus: " << myActiveStatus << " Button: " << myButton << endl; // Dude4 zuweisen @@ -64,7 +63,7 @@ LocalPlayer::LocalPlayer(ConfigFile *c, BoardInterface *b, int id, unsigned uniq int count = 4; int *tempArray = new int[count]; - myTool.getRandNumber(0, 2*interval, count, tempArray, 0); + Tools::getRandNumber(0, 2*interval, count, tempArray, 0); for(i=0; igetActualQuantityPlayers(); @@ -194,7 +192,7 @@ void LocalPlayer::preflopEngine() { // cout << "Spieler " << myID << ": Dude " << myDude4 << "\t Wert " << myHoleCardsValue << "\t Niveau " << myNiveau[0] << " " << myNiveau[1] << " " << myNiveau[2] << "\t Agg " << aggValue << " " << endl; // Check-Bluff generieren - myTool.getRandNumber(1,100,1,&cBluff,0); + Tools::getRandNumber(1,100,1,&cBluff,0); // aktive oder passivie Situation ? -> im preflop nur passiv @@ -338,7 +336,6 @@ void LocalPlayer::flopEngine() { int i; int cBluff; int pBluff; - Tools myTool; int rand; // übergang solange preflopValue und flopValue noch nicht bereinigt @@ -369,7 +366,7 @@ void LocalPlayer::flopEngine() { } // Check-Bluff generieren - myTool.getRandNumber(1,100,1,&cBluff,0); + Tools::getRandNumber(1,100,1,&cBluff,0); // aktiv oder passiv? if(actualHand->getFlop()->getHighestSet() > 0) { @@ -475,7 +472,7 @@ void LocalPlayer::flopEngine() { // Position if(myButton == 1) { // Position-Bluff generieren - myTool.getRandNumber(1,100,1,&pBluff,0); + Tools::getRandNumber(1,100,1,&pBluff,0); if(pBluff <= 16) { bet = (pBluff/4)*2*actualHand->getSmallBlind(); // bet zu klein @@ -513,7 +510,7 @@ void LocalPlayer::flopEngine() { // Standard-Raise-Routine else { // raise-Betrag ermitteln - myTool.getRandNumber(1,8,1,&rand,0); + Tools::getRandNumber(1,8,1,&rand,0); raise = rand*actualHand->getSmallBlind(); // raise-Betrag zu klein -> mindestens Standard-raise if(raise < actualHand->getFlop()->getHighestSet()) { @@ -537,7 +534,7 @@ void LocalPlayer::flopEngine() { // cout << "sBLUFF!" << endl; - myTool.getRandNumber(1,8,1,&rand,0); + Tools::getRandNumber(1,8,1,&rand,0); bet = rand*actualHand->getSmallBlind(); // bet zu klein if(bet == 0) { @@ -576,7 +573,6 @@ void LocalPlayer::flopEngine() { // // int i; // -// Tools myTools; // // for(i=0; i<2; i++) tempArray[i] = myCards[i]; // actualBoard->getMyCards(boardCards); @@ -601,7 +597,7 @@ void LocalPlayer::flopEngine() { // case 6: {} // case 5: {} // case 4: { -// myTools.getRandNumber(0,100,1,&cBluff,0); +// Tools::getRandNumber(0,100,1,&cBluff,0); // if(cBluff < 35) { // myAction = 2; // } @@ -623,7 +619,7 @@ void LocalPlayer::flopEngine() { // case 3: { // switch(info[3]) { // case 2: { -// myTools.getRandNumber(0,100,1,&cBluff,0); +// Tools::getRandNumber(0,100,1,&cBluff,0); // if(cBluff < 35) { // myAction = 2; // } @@ -643,7 +639,7 @@ void LocalPlayer::flopEngine() { // } // break; // case 1: { -// myTools.getRandNumber(0,100,1,&cBluff,0); +// Tools::getRandNumber(0,100,1,&cBluff,0); // if(cBluff < 40) { // myAction = 2; // } @@ -663,7 +659,7 @@ void LocalPlayer::flopEngine() { // } // break; // default: { -// myTools.getRandNumber(0,100,1,&sBluff,0); +// Tools::getRandNumber(0,100,1,&sBluff,0); // if(info[1] >= 10 && sBluff <= 40) { // bet = (sBluff/10)*2*actualHand->getSmallBlind(); // if(bet < 2*actualHand->getSmallBlind()) bet = 2*actualHand->getSmallBlind(); @@ -679,7 +675,7 @@ void LocalPlayer::flopEngine() { // case 2: { // switch(info[3]) { // case 2: { -// myTools.getRandNumber(0,100,1,&cBluff,0); +// Tools::getRandNumber(0,100,1,&cBluff,0); // if(cBluff > 80) { // myAction = 2; // } @@ -695,7 +691,7 @@ void LocalPlayer::flopEngine() { // } // break; // default: { -// myTools.getRandNumber(0,100,1,&cBluff,0); +// Tools::getRandNumber(0,100,1,&cBluff,0); // if(cBluff > 90) { // myAction = 2; // } @@ -714,7 +710,7 @@ void LocalPlayer::flopEngine() { // break; // case 1: { // if(!info[2]) { -// myTools.getRandNumber(0,100,1,&sBluff,0); +// Tools::getRandNumber(0,100,1,&sBluff,0); // switch(info[3]) { // case 2: {} // case 1: { @@ -833,7 +829,6 @@ void LocalPlayer::turnEngine() { int i; int cBluff; int pBluff; - Tools myTool; int rand; readFile(); @@ -863,7 +858,7 @@ void LocalPlayer::turnEngine() { if(individualHighestSet > myCash) individualHighestSet = myCash; // Check-Bluff generieren - myTool.getRandNumber(1,100,1,&cBluff,0); + Tools::getRandNumber(1,100,1,&cBluff,0); // aktiv oder passiv? if(actualHand->getTurn()->getHighestSet() > 0) { @@ -967,7 +962,7 @@ void LocalPlayer::turnEngine() { // Position if(myButton == 1) { // Position-Bluff generieren - myTool.getRandNumber(1,100,1,&pBluff,0); + Tools::getRandNumber(1,100,1,&pBluff,0); if(pBluff <= 16) { bet = (pBluff/4)*2*actualHand->getSmallBlind(); // bet zu klein @@ -1004,7 +999,7 @@ void LocalPlayer::turnEngine() { // Standard-Raise-Routine else { // raise-Betrag ermitteln - myTool.getRandNumber(1,8,1,&rand,0); + Tools::getRandNumber(1,8,1,&rand,0); raise = rand*actualHand->getSmallBlind(); // raise-Betrag zu klein -> mindestens Standard-raise if(raise < actualHand->getTurn()->getHighestSet()) { @@ -1028,7 +1023,7 @@ void LocalPlayer::turnEngine() { // cout << "sBLUFF!" << endl; - myTool.getRandNumber(1,8,1,&rand,0); + Tools::getRandNumber(1,8,1,&rand,0); bet = rand*actualHand->getSmallBlind(); // bet zu klein if(bet == 0) { @@ -1077,7 +1072,6 @@ void LocalPlayer::riverEngine() { int raise = 0; int bet = 0; int i; - Tools myTool; int rand; int pBluff; @@ -1195,7 +1189,7 @@ void LocalPlayer::riverEngine() { // Position if(myButton == 1) { // Position-Bluff generieren - myTool.getRandNumber(1,100,1,&pBluff,0); + Tools::getRandNumber(1,100,1,&pBluff,0); if(pBluff <= 20) { bet = (pBluff/4)*2*actualHand->getSmallBlind(); // bet zu klein @@ -1232,7 +1226,7 @@ void LocalPlayer::riverEngine() { // Standard-Raise-Routine else { // raise-Betrag ermitteln - myTool.getRandNumber(1,8,1,&rand,0); + Tools::getRandNumber(1,8,1,&rand,0); raise = rand*actualHand->getSmallBlind(); // raise-Betrag zu klein -> mindestens Standard-raise if(raise < actualHand->getRiver()->getHighestSet()) { @@ -1256,7 +1250,7 @@ void LocalPlayer::riverEngine() { // cout << "sBLUFF!" << endl; - myTool.getRandNumber(1,8,1,&rand,0); + Tools::getRandNumber(1,8,1,&rand,0); bet = rand*actualHand->getSmallBlind(); // bet zu klein if(bet == 0) { @@ -2546,16 +2540,15 @@ void LocalPlayer::preflopEngine3() { // cout << "nextID " << actualHand->getPlayerArray()[(myID+1)%5]->getMyID() << endl; - Tools myTool; int raise = 0; // Bauchgefhl (zufᅵlig) int tempRand; - myTool.getRandNumber(1,10,1,&tempRand,0); + Tools::getRandNumber(1,10,1,&tempRand,0); // bluff, checkbluff int bluff; - myTool.getRandNumber(1,100,1,&bluff,0); + Tools::getRandNumber(1,100,1,&bluff,0); // cout << "preflop-bluff " << bluff << endl; @@ -2567,7 +2560,7 @@ void LocalPlayer::preflopEngine3() { // temp fr das Vielfache des Small Blind, sodass HighestSet zu hoch ist int tempFold; // tempFold = (actualHand->getPlayerArray()[0]->getMyAverageSets())/(8*actualHand->getSmallBlind()); - myTool.getRandNumber(2,3,1,&tempFold,0); + Tools::getRandNumber(2,3,1,&tempFold,0); // FOLD --> wenn Potential negativ oder HighestSet zu hoch if( (potential*setToHighest<0 || (setToHighest > tempFold * actualHand->getSmallBlind() && potential<1) || (setToHighest > 2 * tempFold * actualHand->getSmallBlind() && potential<2) || (setToHighest > 4 * tempFold * actualHand->getSmallBlind() && potential<3) || (setToHighest > 10 * tempFold * actualHand->getSmallBlind() && potential<4)) && myCardsValue->holeCardsClass(myCards[0], myCards[1]) < 9 && bluff > 15) { @@ -2780,17 +2773,15 @@ void LocalPlayer::flopEngine3() { double percent = (countMy*1.0)/(countAll*1.0); // cout << "Prozent: " << percent << endl; - Tools myTool; - int raise = 0; // Bauchgefhl (zufᅵlig) int tempRand; - myTool.getRandNumber((int)(percent*10.)-2,(int)(percent*10.)+2,1,&tempRand,0); + Tools::getRandNumber((int)(percent*10.)-2,(int)(percent*10.)+2,1,&tempRand,0); // bluff, checkbluff int bluff; - myTool.getRandNumber(1,100,1,&bluff,0); + Tools::getRandNumber(1,100,1,&bluff,0); // cout << "flop-bluff " << bluff << endl; @@ -2802,7 +2793,7 @@ void LocalPlayer::flopEngine3() { // temp fr das Vielfache des Small Blind, sodass HighestSet zu hoch ist int tempFold; // tempFold = (actualHand->getPlayerArray()[0]->getMyAverageSets())/(8*actualHand->getSmallBlind()); - myTool.getRandNumber(2,3,1,&tempFold,0); + Tools::getRandNumber(2,3,1,&tempFold,0); // FOLD --> wenn potential negativ oder HighestSet zu hoch if(( potential*setToHighest<0 || (setToHighest > tempFold * actualHand->getSmallBlind() && potential<1) || (setToHighest > 3 * tempFold * actualHand->getSmallBlind() && potential<2) || (setToHighest > 9 * tempFold * actualHand->getSmallBlind() && potential<3) || (setToHighest > 20*tempFold * actualHand->getSmallBlind() && potential<4) || (setToHighest > 40 *tempFold * actualHand->getSmallBlind() && potential<5)) && percent < 0.90 && bluff > 18) { @@ -2948,16 +2939,15 @@ void LocalPlayer::turnEngine3() { double percent = (countMy*1.0)/(countAll*1.0); // cout << "Prozent: " << percent << endl; - Tools myTool; int raise; // Bauchgefhl (zufᅵlig) int tempRand; - myTool.getRandNumber((int)(percent*10.)-2,(int)(percent*10.)+2,1,&tempRand,0); + Tools::getRandNumber((int)(percent*10.)-2,(int)(percent*10.)+2,1,&tempRand,0); // bluff, checkbluff int bluff; - myTool.getRandNumber(1,100,1,&bluff,0); + Tools::getRandNumber(1,100,1,&bluff,0); // cout << "turn-bluff " << bluff << endl; @@ -2969,7 +2959,7 @@ void LocalPlayer::turnEngine3() { // temp fr das Vielfache des Small Blind, sodass HighestSet zu hoch ist int tempFold; // tempFold = (actualHand->getPlayerArray()[0]->getMyAverageSets())/(7*actualHand->getSmallBlind()); - myTool.getRandNumber(3,4,1,&tempFold,0); + Tools::getRandNumber(3,4,1,&tempFold,0); // FOLD // --> wenn potential negativ oder HighestSet zu hoch @@ -3111,16 +3101,15 @@ void LocalPlayer::riverEngine3() { double percent = (countMy*1.0)/(countAll*1.0); // cout << "Prozent: " << percent << endl; - Tools myTool; int raise; // Bauchgefhl (zufᅵlig) int tempRand; - myTool.getRandNumber((int)(percent*10.)-2,(int)(percent*10.)+2,1,&tempRand,0); + Tools::getRandNumber((int)(percent*10.)-2,(int)(percent*10.)+2,1,&tempRand,0); // bluff, checkbluff int bluff; - myTool.getRandNumber(1,100,1,&bluff,0); + Tools::getRandNumber(1,100,1,&bluff,0); // cout << "river-bluff " << bluff << endl; @@ -3132,7 +3121,7 @@ void LocalPlayer::riverEngine3() { // temp fr das Vielfache des Small Blind, sodass HighestSet zu hoch ist int tempFold; tempFold = (actualHand->getPlayerArray()[0]->getMyAverageSets())/(6*actualHand->getSmallBlind()); - // myTool.getRandNumber(4,6,1,&tempFold,0); + // Tools::getRandNumber(4,6,1,&tempFold,0); // FOLD // --> wenn potential negativ oder HighestSet zu hoch diff --git a/src/engine/local_engine/tools.cpp b/src/engine/local_engine/tools.cpp index 0a73eeeb..c48a1ed2 100755 --- a/src/engine/local_engine/tools.cpp +++ b/src/engine/local_engine/tools.cpp @@ -22,16 +22,6 @@ using namespace std; -Tools::Tools() -{ -} - - -Tools::~Tools() -{ -} - - void Tools::getRandNumber(int start, int end, int howMany, int* randArray, bool different) { int r = end-start+1; diff --git a/src/engine/local_engine/tools.h b/src/engine/local_engine/tools.h index 898c5c99..2d635c08 100755 --- a/src/engine/local_engine/tools.h +++ b/src/engine/local_engine/tools.h @@ -26,11 +26,7 @@ class Tools{ public: - Tools(); - - ~Tools(); - - void getRandNumber(int, int, int, int*, bool); + static void getRandNumber(int, int, int, int*, bool); }; diff --git a/src/game.cpp b/src/game.cpp index e68118bc..d388c527 100755 --- a/src/game.cpp +++ b/src/game.cpp @@ -35,8 +35,8 @@ Game::Game(GuiInterface* gui, boost::shared_ptr factory, startQuantityPlayers(gameData.numberOfPlayers), startCash(gameData.startCash), startSmallBlind(gameData.smallBlind), startHandsBeforeRaiseSmallBlind(gameData.handsBeforeRaise), - myGameID(gameId), guiPlayerNum(gameData.guiPlayerNum), actualQuantityPlayers(gameData.numberOfPlayers), - actualSmallBlind(gameData.smallBlind), actualHandID(0), dealerPosition(startData.startDealerPos) + myGameID(gameId), actualQuantityPlayers(gameData.numberOfPlayers), + actualSmallBlind(gameData.smallBlind), actualHandID(0), dealerPosition(0) { // cout << "Create Game Object" << "\n"; int i; @@ -47,14 +47,27 @@ Game::Game(GuiInterface* gui, boost::shared_ptr factory, playerArray[i] = 0; } + // Dealer Position bestimmen + PlayerDataList::const_iterator player_i = playerDataList.begin(); + PlayerDataList::const_iterator player_end = playerDataList.end(); + + while (player_i != player_end) + { + if ((*player_i)->GetUniqueId() == startData.startDealerPlayerId) + { + dealerPosition = (*player_i)->GetNumber(); + break; + } + ++player_i; + } // Board erstellen actualBoard = myFactory->createBoard(); // Player erstellen - PlayerDataList::const_iterator player_i = playerDataList.begin(); - PlayerDataList::const_iterator player_end = playerDataList.end(); + player_i = playerDataList.begin(); + player_end = playerDataList.end(); for(i=0; i(tmpDealerPos); //Start Game!!! mySession->startLocalGame(gameData, startData); @@ -1188,7 +1189,7 @@ void mainWindowImpl::dealHoleCards() { currentGame->getPlayerArray()[i]->getMyCards(tempCardsIntArray); for(j=0; j<2; j++) { if(currentGame->getPlayerArray()[i]->getMyActiveStatus()) { - if ((i == currentGame->getGuiPlayerNum()) || debugMode) { + if ((i == 0) || debugMode) { tempCardsPixmapArray[j].load(":/cards/resources/graphics/cards/"+QString::number(tempCardsIntArray[j], 10)+".png"); holeCardsArray[i][j]->setPixmap(tempCardsPixmapArray[j],FALSE); diff --git a/src/net/clientthread.h b/src/net/clientthread.h index 0052a1e0..ee5f9311 100644 --- a/src/net/clientthread.h +++ b/src/net/clientthread.h @@ -73,6 +73,8 @@ protected: void SetGameData(const GameData &gameData); const StartData &GetStartData() const; void SetStartData(const StartData &startData); + int GetGuiPlayerNum() const; + void SetGuiPlayerNum(int guiPlayerNum); boost::shared_ptr GetGame(); @@ -80,7 +82,7 @@ protected: void AddPlayerData(boost::shared_ptr playerData); void RemovePlayerData(unsigned playerId); - const PlayerDataList &GetPlayerDataList() const; + PlayerDataList GetMappedPlayerDataList() const; private: @@ -99,6 +101,7 @@ private: boost::shared_ptr m_game; unsigned m_curGameId; + int m_guiPlayerNum; friend class ClientStateInit; friend class ClientStateStartResolve; diff --git a/src/net/common/clientstate.cpp b/src/net/common/clientstate.cpp index 694e0172..a0ed7680 100644 --- a/src/net/common/clientstate.cpp +++ b/src/net/common/clientstate.cpp @@ -391,10 +391,11 @@ ClientStateWaitSession::Process(ClientThread &client) NetPacketJoinGameAck::Data joinGameAckData; tmpPacket->ToNetPacketJoinGameAck()->GetData(joinGameAckData); client.SetGameData(joinGameAckData.gameData); + client.SetGuiPlayerNum(joinGameAckData.yourPlayerNum); // TODO: Type Human is fixed here. boost::shared_ptr playerData( - new PlayerData(joinGameAckData.gameData.guiPlayerUniqueId, joinGameAckData.gameData.guiPlayerNum, PLAYER_TYPE_HUMAN)); + new PlayerData(joinGameAckData.yourPlayerUniqueId, joinGameAckData.yourPlayerNum, PLAYER_TYPE_HUMAN)); playerData->SetName(context.GetPlayerName()); client.AddPlayerData(playerData); @@ -512,7 +513,9 @@ ClientStateWaitHand::Process(ClientThread &client) int myCards[2]; myCards[0] = (int)tmpData.yourCards[0]; myCards[1] = (int)tmpData.yourCards[1]; - client.GetGame()->getPlayerArray()[client.GetGame()->getGuiPlayerNum()]->setMyCards(myCards); + client.GetGame()->getPlayerArray()[0]->setMyCards(myCards); + client.GetGame()->initHand(); + client.GetGame()->startHand(); client.GetGui().dealHoleCards(); } } diff --git a/src/net/common/clientthread.cpp b/src/net/common/clientthread.cpp index 3f5302c1..7c750e6f 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_curState(NULL), m_gui(gui), m_curGameId(0), m_guiPlayerNum(0) { m_context.reset(new ClientContext); m_senderCallback.reset(new ClientSenderCallback(*this)); @@ -118,7 +118,7 @@ ClientThread::Main() // EngineFactory erstellen boost::shared_ptr factory(new ClientEngineFactory); // LocalEngine erstellen - m_game.reset(new Game(&m_gui, factory, GetPlayerDataList(), GetGameData(), GetStartData(), m_curGameId++)); + m_game.reset(new Game(&m_gui, factory, GetMappedPlayerDataList(), GetGameData(), GetStartData(), m_curGameId++)); GetCallback().SignalNetClientGameStart(m_game); } } @@ -196,6 +196,18 @@ ClientThread::SetStartData(const StartData &startData) m_startData = startData; } +int +ClientThread::GetGuiPlayerNum() const +{ + return m_guiPlayerNum; +} + +void +ClientThread::SetGuiPlayerNum(int guiPlayerNum) +{ + m_guiPlayerNum = guiPlayerNum; +} + boost::shared_ptr ClientThread::GetGame() { @@ -215,9 +227,6 @@ ClientThread::AddPlayerData(boost::shared_ptr playerData) if (playerData.get() && !playerData->GetName().empty()) { m_playerDataList.push_back(playerData); - // Sort the list by player number. - m_playerDataList.sort(*boost::lambda::_1 < *boost::lambda::_2); - GetCallback().SignalNetClientPlayerJoined(playerData->GetName()); } } @@ -244,9 +253,31 @@ ClientThread::RemovePlayerData(unsigned playerId) GetCallback().SignalNetClientPlayerLeft(playerName); } -const PlayerDataList & -ClientThread::GetPlayerDataList() const +PlayerDataList +ClientThread::GetMappedPlayerDataList() const { - return m_playerDataList; + PlayerDataList mappedList; + + PlayerDataList::const_iterator i = m_playerDataList.begin(); + PlayerDataList::const_iterator end = m_playerDataList.end(); + + // Create a copy of the player list so that the GUI player + // is player 0. This is mapped because the GUI depends on it. + while (i != end) + { + boost::shared_ptr tmpData(new PlayerData(*(*i))); + int numberDiff = tmpData->GetNumber() - GetGuiPlayerNum(); + if (numberDiff >= 0) + tmpData->SetNumber(numberDiff); + else + tmpData->SetNumber(GetGameData().numberOfPlayers + numberDiff); + mappedList.push_back(tmpData); + ++i; + } + + // Sort the list by player number. + mappedList.sort(*boost::lambda::_1 < *boost::lambda::_2); + + return mappedList; } diff --git a/src/net/common/netpacket.cpp b/src/net/common/netpacket.cpp index e77c04a0..5b9c1f81 100644 --- a/src/net/common/netpacket.cpp +++ b/src/net/common/netpacket.cpp @@ -115,7 +115,7 @@ struct NetPacketPlayerLeftData struct NetPacketGameStartData { NetPacketHeader head; - u_int16_t startDealerPos; + u_int16_t startDealerPlayerId; u_int16_t reserved; }; @@ -528,13 +528,13 @@ NetPacketJoinGameAck::SetData(const NetPacketJoinGameAck::Data &inData) assert(tmpData); tmpData->sessionId = htonl(inData.sessionId); + tmpData->playerId = htons(inData.yourPlayerUniqueId); + tmpData->playerNumber = htons(inData.yourPlayerNum); tmpData->numberOfPlayers = htons(inData.gameData.numberOfPlayers); tmpData->smallBlind = htons(inData.gameData.smallBlind); tmpData->handsBeforeRaise = htons(inData.gameData.handsBeforeRaise); tmpData->proposedGuiSpeed = htons(inData.gameData.guiSpeed); tmpData->startCash = htonl(inData.gameData.startCash); - tmpData->playerId = htons(inData.gameData.guiPlayerUniqueId); - tmpData->playerNumber = htons(inData.gameData.guiPlayerNum); } void @@ -544,13 +544,13 @@ NetPacketJoinGameAck::GetData(NetPacketJoinGameAck::Data &outData) const assert(tmpData); outData.sessionId = ntohl(tmpData->sessionId); + outData.yourPlayerUniqueId = ntohs(tmpData->playerId); + outData.yourPlayerNum = ntohs(tmpData->playerNumber); outData.gameData.numberOfPlayers = ntohs(tmpData->numberOfPlayers); outData.gameData.smallBlind = ntohs(tmpData->smallBlind); outData.gameData.handsBeforeRaise = ntohs(tmpData->handsBeforeRaise); outData.gameData.guiSpeed = ntohs(tmpData->proposedGuiSpeed); outData.gameData.startCash = ntohl(tmpData->startCash); - outData.gameData.guiPlayerUniqueId = ntohs(tmpData->playerId); - outData.gameData.guiPlayerNum = ntohs(tmpData->playerNumber); } const NetPacketJoinGameAck * @@ -761,7 +761,7 @@ NetPacketGameStart::SetData(const NetPacketGameStart::Data &inData) NetPacketGameStartData *tmpData = (NetPacketGameStartData *)GetRawData(); assert(tmpData); - tmpData->startDealerPos = htons(inData.startData.startDealerPos); + tmpData->startDealerPlayerId = htons(inData.startData.startDealerPlayerId); } void @@ -770,7 +770,7 @@ NetPacketGameStart::GetData(NetPacketGameStart::Data &outData) const NetPacketGameStartData *tmpData = (NetPacketGameStartData *)GetRawData(); assert(tmpData); - outData.startData.startDealerPos = ntohs(tmpData->startDealerPos); + outData.startData.startDealerPlayerId = ntohs(tmpData->startDealerPlayerId); } const NetPacketGameStart * diff --git a/src/net/common/serverrecvstate.cpp b/src/net/common/serverrecvstate.cpp index 197862df..8830ad44 100644 --- a/src/net/common/serverrecvstate.cpp +++ b/src/net/common/serverrecvstate.cpp @@ -154,9 +154,9 @@ ServerRecvStateInit::Process(ServerRecvThread &server) boost::shared_ptr answer(new NetPacketJoinGameAck); NetPacketJoinGameAck::Data joinGameAckData; joinGameAckData.sessionId = session.sessionData->GetId(); // TODO: currently unused. + joinGameAckData.yourPlayerUniqueId = tmpPlayerData->GetUniqueId(); + joinGameAckData.yourPlayerNum = tmpPlayerData->GetNumber(); joinGameAckData.gameData = server.GetGameData(); - joinGameAckData.gameData.guiPlayerUniqueId = tmpPlayerData->GetUniqueId(); - joinGameAckData.gameData.guiPlayerNum = tmpPlayerData->GetNumber(); static_cast(answer.get())->SetData(joinGameAckData); server.GetSender().Send(recvSock, answer); @@ -227,8 +227,9 @@ ServerRecvStateStartGame::Process(ServerRecvThread &server) { // Set dealer pos. StartData startData; - Tools myTool; - myTool.getRandNumber(0, server.GetGameData().numberOfPlayers-1, 1, &startData.startDealerPos, 0); + int tmpDealerPos = 0; + Tools::getRandNumber(0, server.GetGameData().numberOfPlayers-1, 1, &tmpDealerPos, 0); + startData.startDealerPlayerId = static_cast(tmpDealerPos); server.SetStartData(startData); } diff --git a/src/net/netpacket.h b/src/net/netpacket.h index a91c2ecc..23978603 100644 --- a/src/net/netpacket.h +++ b/src/net/netpacket.h @@ -120,6 +120,8 @@ public: struct Data { u_int32_t sessionId; + int16_t yourPlayerNum; + u_int16_t yourPlayerUniqueId; GameData gameData; }; diff --git a/src/net/socket_helper.h b/src/net/socket_helper.h index 1bedd43f..a349d849 100644 --- a/src/net/socket_helper.h +++ b/src/net/socket_helper.h @@ -35,6 +35,8 @@ typedef unsigned __int16 u_int16_t; typedef unsigned __int32 u_int32_t; +typedef __int16 int16_t; +typedef __int32 int32_t; typedef unsigned char u_char; #else diff --git a/src/playerdata.h b/src/playerdata.h index 7b5ca372..0fb9d4aa 100644 --- a/src/playerdata.h +++ b/src/playerdata.h @@ -58,6 +58,8 @@ public: {return m_uniqueId;} int GetNumber() const {return m_number;} + void SetNumber(int number) + {m_number = number;} bool operator<(const PlayerData &other) {return m_number < other.GetNumber();}