diff --git a/INSTALL b/INSTALL index ff5c6195..db210ced 100644 --- a/INSTALL +++ b/INSTALL @@ -11,7 +11,7 @@ Linux: - libgsasl version >= 1.4 --> http://www.gnu.org/software/gsasl/ - libboost_thread, libboost_filesystem, libboost_datetime, libboost_program_options, libboost_iostreams, libboost_asio, libboost_regex, libboost_random, libboost_uuid - (version >= 1.44, latest always recommended) --> http://www.boost.org/ + (version >= 1.49, latest always recommended) --> http://www.boost.org/ - libSDL_mixer, libSDL --> http://www.libsdl.org/ - libSQLite3 --> http://sqlite.org/ - libtinyxml > 2.0 --> http://www.sourceforge.net/projects/tinyxml diff --git a/pokerth_game.pro b/pokerth_game.pro index d660452e..01ebe39d 100644 --- a/pokerth_game.pro +++ b/pokerth_game.pro @@ -422,6 +422,8 @@ unix:!mac { boost_iostreams-mt BOOST_REGEX = boost_regex \ boost_regex-mt + BOOST_CHRONO = boost_chrono \ + boost_chrono-mt BOOST_SYS = boost_system \ boost_system-mt BOOST_RANDOM = boost_random \ @@ -463,6 +465,14 @@ unix:!mac { message("Found $$lib") BOOST_REGEX = -l$$lib } + for(lib, BOOST_CHRONO):exists($${dir}/lib$${lib}.so*) { + message("Found $$lib") + BOOST_CHRONO = -l$$lib + } + for(lib, BOOST_CHRONO):exists($${dir}/lib$${lib}.a) { + message("Found $$lib") + BOOST_CHRONO = -l$$lib + } !android{ for(lib, BOOST_RANDOM):exists($${dir}/lib$${lib}.so*) { message("Found $$lib") @@ -487,9 +497,10 @@ unix:!mac { $$BOOST_FS \ $$BOOST_IOSTREAMS \ $$BOOST_REGEX \ + $$BOOST_CHRONO \ $$BOOST_RANDOM \ $$BOOST_SYS - !count(BOOST_LIBS, 6):error("Unable to find boost libraries in PREFIX=$${PREFIX}") + !count(BOOST_LIBS, 7):error("Unable to find boost libraries in PREFIX=$${PREFIX}") if($$system(sdl-config --version)):error("sdl-config not found in PATH - libSDL_mixer, libSDL are required!") UNAME = $$system(uname -s) BSD = $$find(UNAME, "BSD") @@ -509,6 +520,7 @@ unix:!mac { $$BOOST_FS \ $$BOOST_IOSTREAMS \ $$BOOST_REGEX \ + $$BOOST_CHRONO \ $$BOOST_SYS !count(BOOST_LIBS, 5):error("Unable to find boost libraries in PREFIX=$${PREFIX}/armv5") LIBS += -ltinyxml @@ -575,6 +587,7 @@ mac { LIBS += /usr/local/lib/libboost_thread.a LIBS += /usr/local/lib/libboost_filesystem.a LIBS += /usr/local/lib/libboost_regex.a + LIBS += /usr/local/lib/libboost_chrono.a LIBS += /usr/local/lib/libboost_random.a LIBS += /usr/local/lib/libboost_system.a LIBS += /usr/local/lib/libboost_iostreams.a diff --git a/pokerth_server.pro b/pokerth_server.pro index 706475f7..f36031c7 100644 --- a/pokerth_server.pro +++ b/pokerth_server.pro @@ -180,6 +180,7 @@ unix : !mac { BOOST_THREAD = boost_thread boost_thread-mt BOOST_PROGRAM_OPTIONS = boost_program_options boost_program_options-mt BOOST_IOSTREAMS = boost_iostreams boost_iostreams-mt + BOOST_CHRONO = boost_chrono boost_chrono-mt BOOST_SYS = boost_system boost_system-mt BOOST_REGEX = boost_regex boost_regex-mt BOOST_RANDOM = boost_random boost_random-mt @@ -231,6 +232,14 @@ unix : !mac { message("Found $$lib") BOOST_REGEX = -l$$lib } + for(lib, BOOST_CHRONO):exists($${dir}/lib$${lib}.so*) { + message("Found $$lib") + BOOST_CHRONO = -l$$lib + } + for(lib, BOOST_CHRONO):exists($${dir}/lib$${lib}.a) { + message("Found $$lib") + BOOST_CHRONO = -l$$lib + } for(lib, BOOST_RANDOM):exists($${dir}/lib$${lib}.so*) { message("Found $$lib") BOOST_RANDOM = -l$$lib @@ -249,8 +258,8 @@ unix : !mac { } } } - BOOST_LIBS = $$BOOST_THREAD $$BOOST_FS $$BOOST_PROGRAM_OPTIONS $$BOOST_IOSTREAMS $$BOOST_REGEX $$BOOST_RANDOM $$BOOST_SYS - !count(BOOST_LIBS, 7){ + BOOST_LIBS = $$BOOST_THREAD $$BOOST_FS $$BOOST_PROGRAM_OPTIONS $$BOOST_IOSTREAMS $$BOOST_REGEX $$BOOST_CHRONO $$BOOST_RANDOM $$BOOST_SYS + !count(BOOST_LIBS, 8){ error("Unable to find boost libraries in PREFIX=$${PREFIX}") } @@ -301,6 +310,7 @@ mac { LIBS += /usr/local/lib/libboost_thread.a LIBS += /usr/local/lib/libboost_filesystem.a LIBS += /usr/local/lib/libboost_regex.a + LIBS += /usr/local/lib/libboost_chrono.a LIBS += /usr/local/lib/libboost_random.a LIBS += /usr/local/lib/libboost_system.a LIBS += /usr/local/lib/libboost_iostreams.a diff --git a/src/engine/game.cpp b/src/engine/game.cpp index 427da138..9ef23841 100755 --- a/src/engine/game.cpp +++ b/src/engine/game.cpp @@ -57,10 +57,10 @@ Game::Game(GuiInterface* gui, boost::shared_ptr factory, dealerPosition = startData.startDealerPlayerId; // debug mode - if(myLog) { - myLog->debugMode_getStartSmallBlind(&startSmallBlind,¤tSmallBlind); - myLog->debugMode_getStartDealerPosition(&dealerPosition); - } + if(myLog) { + myLog->debugMode_getStartSmallBlind(&startSmallBlind,¤tSmallBlind); + myLog->debugMode_getStartDealerPosition(&dealerPosition); + } int i; @@ -110,7 +110,7 @@ Game::Game(GuiInterface* gui, boost::shared_ptr factory, } // debug mode - if(myLog) myLog->debugMode_getPlayerStartCash(&myStartCash, i); + if(myLog) myLog->debugMode_getPlayerStartCash(&myStartCash, i); // create player objects boost::shared_ptr tmpPlayer = myFactory->createPlayer(i, uniqueId, type, myName, myAvatarFile, myStartCash, startQuantityPlayers > i, myStayOnTableStatus, 0); @@ -215,7 +215,6 @@ void Game::startHand() // log new hand myGui->logNewGameHandMsg(myGameID, currentHandID); - myGui->flushLogAtGame(myGameID); currentHand->start(); } diff --git a/src/engine/local_engine/arraydata.cpp b/src/engine/local_engine/arraydata.cpp index ddf575c2..aa241387 100644 --- a/src/engine/local_engine/arraydata.cpp +++ b/src/engine/local_engine/arraydata.cpp @@ -1054,17 +1054,9 @@ vector< vector > ArrayData::getHandChancePreflop(int handCode) int check = -1; - int i; - vector< vector > chance(2); - - chance[0].resize(10); - chance[1].resize(10); - - for(i=0; i<10; i++) { - chance[0][i] = 0; - chance[1][i] = 0; - } + chance[0].assign(10,0); + chance[1].assign(10,0); for (unsigned val = 0; val < NUM_HAND_CHANCE_PREFLOP; val++) { if(handCode == handChancePreflop[val].hand) { diff --git a/src/engine/local_engine/cardsvalue.cpp b/src/engine/local_engine/cardsvalue.cpp index e309d95f..bd921170 100755 --- a/src/engine/local_engine/cardsvalue.cpp +++ b/src/engine/local_engine/cardsvalue.cpp @@ -221,52 +221,304 @@ int CardsValue::holeCardsClass(int one, int two) } -int CardsValue::holeCardsToIntCode(int* cards) +int CardsValue::holeCardsToIntCode(int holeCards[2]) { // Code der HoleCards ermitteln - if(cards[0]%13 == cards[1]%13) { - return ((cards[0]%13)*1000 + (cards[0]%13)*10); + if(holeCards[0]%13 == holeCards[1]%13) { + return ((holeCards[0]%13)*1000 + (holeCards[0]%13)*10); } else { - if(cards[0]%13 < cards[1]%13) { - if(cards[0]/13 == cards[1]/13) { - return ((cards[0]%13)*1000 + (cards[1]%13)*10 + 1); + if(holeCards[0]%13 < holeCards[1]%13) { + if(holeCards[0]/13 == holeCards[1]/13) { + return ((holeCards[0]%13)*1000 + (holeCards[1]%13)*10 + 1); } else { - return ((cards[0]%13)*1000 + (cards[1]%13)*10); + return ((holeCards[0]%13)*1000 + (holeCards[1]%13)*10); } } else { - if(cards[0]/13 == cards[1]/13) { - return ((cards[1]%13)*1000 + (cards[0]%13)*10 + 1); + if(holeCards[0]/13 == holeCards[1]/13) { + return ((holeCards[1]%13)*1000 + (holeCards[0]%13)*10 + 1); } else { - return ((cards[1]%13)*1000 + (cards[0]%13)*10); + return ((holeCards[1]%13)*1000 + (holeCards[0]%13)*10); } } } } -/* DO NOT USE, THIS MAY LEAK MEMORY -int* CardsValue::intCodeToHoleCards(int code) +static const int straight[10] = { 7936, 3968, 1984, 992, 496, 248, 124, 62, 31, 4111 }; + +int CardsValue::cardsValueShort(int cards[4]) { - // one possibility !!! + int color_idx; + int card_idx; - int* cards = new int[2]; - - cards[0] = code/1000; - cards[1] = (code-cards[0]*1000)/10; - - if(cards[0]==cards[1]) { - cards[1] +=13; - } else { - if(code%10 == 0) cards[1] +=13; + // Royal Flush, Straight Flush, Flush + for(color_idx=0; color_idx<4; color_idx++) { // check all colors + if(Tools::bitcount(cards[color_idx])>=5) { // check if at least 5 cards of one color + if((cards[color_idx] & straight[0]) == straight[0]) // check for Royal Flush + return 9; + else { // check for Straight Flush + for(card_idx=1; card_idx<10; card_idx++) { + if((cards[color_idx] & straight[card_idx]) == straight[card_idx]) { + return 8; // Straight Flush + } + } + } + return 5; // Flush + } } - return cards; + int AND = cards[0] & cards[1] & cards[2] & cards[3]; -}*/ + // Four of a Kind + if(AND) { + return 7; + } -int CardsValue::cardsValue(int* cards, int* position) + int OR = cards[0] | cards[1] | cards[2] | cards[3]; + + // Straight + for(card_idx=0; card_idx<10; card_idx++) { + if((OR & straight[card_idx]) == straight[card_idx]) { + return 4; + } + } + + int color_1_idx, color_2_idx, color_3_idx, color_4_idx, color_5_idx; + int temp; + + // Full House, Three of a Kind + for(color_1_idx=0; color_1_idx<2; color_1_idx++) { + for(color_2_idx=color_1_idx+1; color_2_idx<3; color_2_idx++) { + for(color_3_idx=color_2_idx+1; color_3_idx<4; color_3_idx++) { + temp = cards[color_1_idx] & cards[color_2_idx] & cards[color_3_idx]; + if(Tools::bitcount(temp) == 2) { // two times Three of a Kind + return 6; // Full House + } else { + if(temp) { + for(color_4_idx=0; color_4_idx<3; color_4_idx++) { + for(color_5_idx=color_4_idx+1; color_5_idx<4; color_5_idx++) { + if(~temp & cards[color_4_idx] & cards[color_5_idx]) { // search for additional pair + return 6; // Full House + } + } + } + return 3; // Three of a Kind + } + } + } + } + } + + // Two Pairs, Two of a Kind + for(color_1_idx=0; color_1_idx<3; color_1_idx++) { + for(color_2_idx=color_1_idx+1; color_2_idx<4; color_2_idx++) { + temp = cards[color_1_idx] & cards[color_2_idx]; + if(Tools::bitcount(temp) >= 2) { // at least two times Two of a Kind + return 2; // Two Pairs + } else { + if(temp) { // search for second pair + for(color_3_idx=0; color_3_idx<3; color_3_idx++) { + for(color_4_idx=color_3_idx+1; color_4_idx<4; color_4_idx++) { + if(~temp & cards[color_3_idx] & cards[color_4_idx]) { + return 2; // Two Pairs + } + } + } + return 1; // Two of a Kind + } + } + } + } + + return 0; // High Card +} + +int CardsValue::cardsValue(int cards[4], int bestHand[4]) +{ + int color_1_idx; + int card_idx; + KickerValue kickerValue1; + + // Royal Flush, Straight Flush, Flush + for(color_1_idx=0; color_1_idx<4; color_1_idx++) { // check all colors + if(Tools::bitcount(cards[color_1_idx])>=5) { // check if at least 5 cards of one color + if((cards[color_1_idx] & straight[0]) == straight[0]) { // check for Royal Flush + if(bestHand) bestHand[color_1_idx] = straight[0]; + return 900000000; // Royal Flush + } else { + for(card_idx=1; card_idx<10; card_idx++) { + if((cards[color_1_idx] & straight[card_idx]) == straight[card_idx]) { // check for Straight Flush + if(bestHand) bestHand[color_1_idx] = straight[card_idx]; + return (800000000+(12-card_idx)*1000000); // Straight Flush + } + } + } + // Flush + kickerValue1 = determineKickerValue(cards[color_1_idx],0,4); + if(bestHand) bestHand[color_1_idx] = kickerValue1.select; + return 500000000 + kickerValue1.factorValue; + } + } + + int AND = cards[0] & cards[1] & cards[2] & cards[3]; + int OR = cards[0] | cards[1] | cards[2] | cards[3]; + int temp1; + KickerValue kickerValue2; + + // Four of a Kind + if(AND) { + kickerValue1 = determineKickerValue(AND,0,0); + kickerValue2 = determineKickerValue(OR & ~AND,1,1); + if(bestHand) { + temp1 = kickerValue2.select; + for(color_1_idx=3; color_1_idx>=0; color_1_idx--) { + bestHand[color_1_idx] = (cards[color_1_idx] & (kickerValue1.select | temp1)); + if(bestHand[color_1_idx] & temp1) temp1 = 0; + } + } + return 700000000 + kickerValue1.factorValue + kickerValue2.factorValue; + } + + // Straight + for(card_idx=0; card_idx<10; card_idx++) { + if((OR & straight[card_idx]) == straight[card_idx]) { + if(bestHand) { + temp1 = straight[card_idx]; + for(color_1_idx=3; color_1_idx>=0; color_1_idx--) { + bestHand[color_1_idx] += (temp1 & cards[color_1_idx]); + temp1 &= ~bestHand[color_1_idx]; + } + } + return 400000000 + (12-card_idx)*1000000; + } + } + + int color_2_idx, color_3_idx; + int temp2; + + // Full House, Three of a Kind + temp1 = 0; + for(color_1_idx=0; color_1_idx<2; color_1_idx++) { + for(color_2_idx=color_1_idx+1; color_2_idx<3; color_2_idx++) { + for(color_3_idx=color_2_idx+1; color_3_idx<4; color_3_idx++) { + temp1 |= cards[color_1_idx] & cards[color_2_idx] & cards[color_3_idx]; + } + } + } + if(temp1) { + if(Tools::bitcount(temp1) == 2) { + // two times Three of a Kind + if(bestHand) { + kickerValue1 = determineKickerValue(temp1,0,0); + kickerValue2 = determineKickerValue(kickerValue1.remain,1,1); + temp2 = 0; + for(color_1_idx=3; color_1_idx>=0; color_1_idx--) { + if(temp2<2) bestHand[color_1_idx] += (cards[color_1_idx] & (kickerValue1.select | kickerValue2.select)); + else bestHand[color_1_idx] += (cards[color_1_idx] & kickerValue1.select); + if(cards[color_1_idx] & kickerValue2.select) temp2++; + } + } + return 600000000 + determineKickerValue(temp1,0,1).factorValue; + } else { + // one times Three of a Kind + temp2 = temp1; + temp1 = 0; + // check for additional pair + for(color_1_idx=0; color_1_idx<3; color_1_idx++) { + for(color_2_idx=color_1_idx+1; color_2_idx<4; color_2_idx++) { + temp1 |= cards[color_1_idx] & cards[color_2_idx]; + } + } + temp1 &= ~temp2; // remove Three of a Kind from found pairs + if(temp1) { + // with additional pair + kickerValue1 = determineKickerValue(temp2,0,0); + kickerValue2 = determineKickerValue(temp1,1,1); + if(bestHand) { + for(color_1_idx=3; color_1_idx>=0; color_1_idx--) bestHand[color_1_idx] = (cards[color_1_idx] & (kickerValue1.select | kickerValue2.select)); + } + return 600000000 + kickerValue1.factorValue + kickerValue2.factorValue; // Full House + } else { + // without addition pair + kickerValue1 = determineKickerValue(temp2,0,0); + kickerValue2 = determineKickerValue(OR & ~temp2,1,2); + if(bestHand) { + for(color_1_idx=3; color_1_idx>=0; color_1_idx--) bestHand[color_1_idx] = (cards[color_1_idx] & (kickerValue1.select | kickerValue2.select)); + } + return 300000000 + kickerValue1.factorValue + kickerValue2.factorValue; // Three of a Kind + } + } + } + + // Two Pairs, Two of a Kind + temp1 = 0; + for(color_1_idx=0; color_1_idx<3; color_1_idx++) { + for(color_2_idx=color_1_idx+1; color_2_idx<4; color_2_idx++) { + temp1 |= (cards[color_1_idx] & cards[color_2_idx]); + } + } + if(temp1) { + if(Tools::bitcount(temp1) >= 2) { // at least two times Two of a Kind + kickerValue1 = determineKickerValue(temp1,0,1); + kickerValue2 = determineKickerValue(OR & ~kickerValue1.select,2,2); + if(bestHand) { + temp1 = (kickerValue1.select | kickerValue2.select); + for(color_1_idx=3; color_1_idx>=0; color_1_idx--) { + bestHand[color_1_idx] += (cards[color_1_idx] & temp1); + if(bestHand[color_1_idx] & kickerValue2.select) temp1 &= ~kickerValue2.select; + } + } + return 200000000 + kickerValue1.factorValue + kickerValue2.factorValue; // Two Pairs + } else { + kickerValue1 = determineKickerValue(temp1,0,0); + kickerValue2 = determineKickerValue(OR & ~temp1,1,3); + if(bestHand) { + for(color_1_idx=3; color_1_idx>=0; color_1_idx--) { + bestHand[color_1_idx] += (cards[color_1_idx] & (kickerValue1.select | kickerValue2.select)); + } + } + return 100000000 + kickerValue1.factorValue + kickerValue2.factorValue; // Two of a Kind + } + } + + // High Card + kickerValue1 = determineKickerValue(OR,0,4); + if(bestHand) { + for(color_1_idx=3; color_1_idx>=0; color_1_idx--) { + bestHand[color_1_idx] += (cards[color_1_idx] & kickerValue1.select); + } + } + return kickerValue1.factorValue; + +} + +static const int factor_kicker_short[4] = {1000000,10000,100,1}; +static const int factor_kicker_long[5] = {1000000,10000,100,10,1}; + +KickerValue CardsValue::determineKickerValue(int testValue, int factorPointerStart, int factorPointerEnd) +{ + KickerValue kickerValue; + kickerValue.factorValue = 0; + kickerValue.remain = testValue; + kickerValue.select = 0; + int compareValue = 4096; + int factorPointer = factorPointerStart; + for(int card_idx=0; (factorPointer<=factorPointerEnd) & (card_idx<13); card_idx++) { + if(kickerValue.remain >= compareValue) { + if(factorPointerEnd - factorPointerStart==4) kickerValue.factorValue += (12-card_idx)*factor_kicker_long[factorPointer]; + else kickerValue.factorValue += (12-card_idx)*factor_kicker_short[factorPointer]; + kickerValue.remain &= ~compareValue; + factorPointer++; + } + compareValue >>= 1; + } + kickerValue.select = testValue & ~kickerValue.remain; + return kickerValue; +} + +int CardsValue::cardsValueOld(int cards[7], int position[5]) { int array[7][3]; @@ -645,26 +897,18 @@ int CardsValue::cardsValue(int* cards, int* position) } -std::vector< std::vector > CardsValue::calcCardsChance(GameState beRoID, int* playerCards, int* boardCards) +std::vector< std::vector > CardsValue::calcCardsChance(GameState beRoID, int playerCards[2], int boardCards[5]) { - int i,j; + int card_idx_1, card_idx_2; std::vector< std::vector > chance(2); + chance[0].assign(10,0); + chance[1].assign(10,0); - chance[0].resize(10); - chance[1].resize(10); - - for(i=0; i<10; i++) { - chance[0][i] = 0; - chance[1][i] = 0; - } - - int cards[7]; + int cards[4] = { 0,0,0,0 }; int sum = 0; - cards[0] = playerCards[0]; - cards[1] = playerCards[1]; - for(i=0; i<5; i++) cards[i+2] = boardCards[i]; + for(card_idx_1=0; card_idx_1<2; card_idx_1++) cards[playerCards[card_idx_1]/13] |= (1 << (playerCards[card_idx_1]%13)); switch(beRoID) { case GAME_STATE_PREFLOP: { @@ -675,50 +919,60 @@ std::vector< std::vector > CardsValue::calcCardsChance(GameState beRoID, in break; case GAME_STATE_FLOP: { - for(i=0; i<51; i++) { - if(i!=cards[0] && i!=cards[1] && i!=cards[2] && i!=cards[3] && i!=cards[4]) { - for(j=i+1; j<52; j++) { - if(j!=cards[0] && j!=cards[1] && j!=cards[2] && j!=cards[3] && j!=cards[4]) { - cards[5] = i; - cards[6] = j; - (chance[0][cardsValue(cards,0)/100000000])++; + for(card_idx_1=0; card_idx_1<3; card_idx_1++) cards[boardCards[card_idx_1]/13] |= (1 << (boardCards[card_idx_1]%13)); + + for(card_idx_1=0; card_idx_1<51; card_idx_1++) { + if((cards[card_idx_1/13] & (1 << (card_idx_1%13))) == 0) { + cards[card_idx_1/13] |= (1 << (card_idx_1%13)); + for(card_idx_2=card_idx_1+1; card_idx_2<52; card_idx_2++) { + if((cards[card_idx_2/13] & (1 << (card_idx_2%13))) == 0) { + cards[card_idx_2/13] |= (1 << (card_idx_2%13)); + (chance[0][cardsValueShort(cards)])++; sum++; + cards[card_idx_2/13] &= ~(1 << (card_idx_2%13)); } } + cards[card_idx_1/13] &= ~(1 << (card_idx_1%13)); } } - for(i=0; i<10; i++) { - if(chance[0][i] > 0) chance[1][i] = 1; - chance[0][i] = (int)(((double)chance[0][i]/(double)sum)*100.0+0.5); - } } break; case GAME_STATE_TURN: { - for(i=0; i<52; i++) { - if(i!=cards[0] && i!=cards[1] && i!=cards[2] && i!=cards[3] && i!=cards[4] && i!=cards[5]) { - cards[6] = i; - (chance[0][cardsValue(cards,0)/100000000])++; + for(card_idx_1=0; card_idx_1<4; card_idx_1++) cards[boardCards[card_idx_1]/13] |= (1 << (boardCards[card_idx_1]%13)); + + for(card_idx_1=0; card_idx_1<52; card_idx_1++) { + if((cards[card_idx_1/13] & (1 << (card_idx_1%13))) == 0) { + cards[card_idx_1/13] |= (1 << (card_idx_1%13)); + (chance[0][cardsValueShort(cards)])++; sum++; + cards[card_idx_1/13] &= ~(1 << (card_idx_1%13)); } } - for(i=0; i<10; i++) { - if(chance[0][i] > 0) chance[1][i] = 1; - chance[0][i] = (int)(((double)chance[0][i]/(double)sum)*100.0+0.5); - } } break; case GAME_STATE_RIVER: { - chance[0][cardsValue(cards,0)/100000000] = 100; - chance[1][cardsValue(cards,0)/100000000] = 1; + + for(card_idx_1=0; card_idx_1<5; card_idx_1++) cards[boardCards[card_idx_1]/13] |= (1 << (boardCards[card_idx_1]%13)); + + chance[0][cardsValueShort(cards)] = 1; + sum = 1; + } break; default: { } } + if(beRoID>GAME_STATE_PREFLOP) { + for(int hand_idx=0; hand_idx<10; hand_idx++) { + if(chance[0][hand_idx] > 0) chance[1][hand_idx] = 1; + chance[0][hand_idx] = (int)(((double)chance[0][hand_idx]/(double)sum)*100.0+0.5); + } + } + return chance; } diff --git a/src/engine/local_engine/cardsvalue.h b/src/engine/local_engine/cardsvalue.h index ff45baf6..3546d4fa 100755 --- a/src/engine/local_engine/cardsvalue.h +++ b/src/engine/local_engine/cardsvalue.h @@ -38,18 +38,26 @@ #include #include +struct KickerValue { + int factorValue; + int select; + int remain; +}; + class CardsValue { public: static int holeCardsClass(int, int); - static int cardsValue(int*, int*); + static int cardsValueShort(int[4]); + static int cardsValue(int[4], int[4]); + static KickerValue determineKickerValue(int, int, int); + static int cardsValueOld(int[7], int[5]); static std::string determineHandName(int myCardsValueInt, PlayerList activePlayerList); static std::list translateCardsValueCode(int cardsValueCode); - static int holeCardsToIntCode(int*); - static int* intCodeToHoleCards(int); + static int holeCardsToIntCode(int[2]); - static std::vector< std::vector > calcCardsChance(GameState, int*, int*); + static std::vector< std::vector > calcCardsChance(GameState, int[2], int[5]); //static int** showdown(GameState, int**, int); }; diff --git a/src/engine/local_engine/localhand.cpp b/src/engine/local_engine/localhand.cpp index e90146e3..067597ff 100755 --- a/src/engine/local_engine/localhand.cpp +++ b/src/engine/local_engine/localhand.cpp @@ -53,7 +53,7 @@ LocalHand::LocalHand(boost::shared_ptr f, GuiInterface *g, boost: for(it=seatsList->begin(); it!=seatsList->end(); ++it) { (*it)->setHand(this); // set myFlipCards 0 - (*it)->setMyCardsFlip(0, 0); + (*it)->setMyHoleCardsFlip(0, 0); } // generate cards and assign to board and player @@ -77,7 +77,7 @@ LocalHand::LocalHand(boost::shared_ptr f, GuiInterface *g, boost: for(i=0; i<5; i++) tempBoardArray[i] = cardsArray[i]; // debug mode - if(myLog) myLog->debugMode_getBoardCards(tempBoardArray,myID); + if(myLog) myLog->debugMode_getBoardCards(tempBoardArray,myID); // prepare whole player hand for(i=0; i<5; i++) tempPlayerAndBoardArray[i+2] = tempBoardArray[i]; @@ -92,13 +92,13 @@ LocalHand::LocalHand(boost::shared_ptr f, GuiInterface *g, boost: for(j=0; j<2; j++) tempPlayerArray[j] = cardsArray[2*k+j+5]; // debug mode - if(myLog) myLog->debugMode_getPlayerCards(tempPlayerArray,myID,k); + if(myLog) myLog->debugMode_getPlayerCards(tempPlayerArray,myID,k); // complete whole player hand for(j=0; j<2; j++) tempPlayerAndBoardArray[j] = tempPlayerArray[j]; - (*it)->setMyCards(tempPlayerArray); - (*it)->setMyCardsValueInt(CardsValue::cardsValue(tempPlayerAndBoardArray, bestHandPos)); + (*it)->setMyHoleCards(tempPlayerArray); + (*it)->setMyCardsValueInt(CardsValue::cardsValueOld(tempPlayerAndBoardArray, bestHandPos)); (*it)->setMyBestHandPosition(bestHandPos); (*it)->setMyRoundStartCash((*it)->getMyCash()); @@ -144,7 +144,6 @@ void LocalHand::start() } else { LOG_ERROR(__FILE__ << " (" << __LINE__ << "): Log Error: cannot find sBID or bBID"); } - myGui->flushLogAtHand(); // deal cards myGui->dealHoleCards(); diff --git a/src/engine/local_engine/localplayer.cpp b/src/engine/local_engine/localplayer.cpp index 046376b1..8c6d4b31 100755 --- a/src/engine/local_engine/localplayer.cpp +++ b/src/engine/local_engine/localplayer.cpp @@ -861,7 +861,7 @@ static const RoundData FlopValues[] = { LocalPlayer::LocalPlayer(ConfigFile *c, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, bool sotS, int mB) : PlayerInterface(), myConfig(c), currentHand(0), myID(id), myUniqueID(uniqueId), myType(type), myName(name), myAvatar(avatar), myDude(0), myDude4(0), myCardsValueInt(0), myOdds(-1.0), logHoleCardsDone(false), myCash(sC), mySet(0), myLastRelativeSet(0), myAction(PLAYER_ACTION_NONE), - myButton(mB), myActiveStatus(aS), myStayOnTableStatus(sotS), myTurn(0), myCardsFlip(0), myRoundStartCash(0), lastMoneyWon(0), + myButton(mB), myActiveStatus(aS), myStayOnTableStatus(sotS), myTurn(0), myHoleCardsFlip(0), myRoundStartCash(0), lastMoneyWon(0), sBluff(0), sBluffStatus(false), m_actionTimeoutCounter(0), m_isSessionActive(false), m_isKicked(false), m_isMuted(false) { @@ -870,7 +870,7 @@ LocalPlayer::LocalPlayer(ConfigFile *c, int id, unsigned uniqueId, PlayerType ty myNiveau[i] = 0; } for(i=0; i<2; i++) { - myCards[i] = -1; + myHoleCards[i] = -1; } // myBestHandPosition mit -1 initialisieren @@ -905,18 +905,10 @@ LocalPlayer::LocalPlayer(ConfigFile *c, int id, unsigned uniqueId, PlayerType ty } - LocalPlayer::~LocalPlayer() { } - -void LocalPlayer::setHand(HandInterface* br) -{ - currentHand = br; -} - - void LocalPlayer::action() { @@ -1078,7 +1070,7 @@ void LocalPlayer::preflopEngine() myNiveau[2] += (21-myCash/individualHighestSet)/2; } - // cout << myID << ": " << myHoleCardsValue << " - " << myNiveau[0] << " " << myNiveau[2] << " - " << myCards[0] << " " << myCards[1] << endl; + // cout << myID << ": " << myHoleCardsValue << " - " << myNiveau[0] << " " << myNiveau[2] << " - " << myHoleCards[0] << " " << myHoleCards[1] << endl; // count number of active human players size_t countHumanPlayers = 0; @@ -1264,12 +1256,11 @@ void LocalPlayer::preflopEngine() // cout << myID << ": " << myOdds << " - " << myNiveau[0] << " " << myNiveau[2] << " - " << "Bluff: " << sBluffStatus << endl; // debug mode - if(currentHand->getLog()) currentHand->getLog()->debugMode_getPlayerAction(&myAction, &bet, &raise, GAME_STATE_PREFLOP, currentHand->getMyID(), myUniqueID, mySet); + if(currentHand->getLog()) currentHand->getLog()->debugMode_getPlayerAction(&myAction, &bet, &raise, GAME_STATE_PREFLOP, currentHand->getMyID(), myUniqueID, mySet); evaluation(bet, raise); } - void LocalPlayer::flopEngine() { @@ -1526,13 +1517,12 @@ void LocalPlayer::flopEngine() } // debug mode - if(currentHand->getLog()) currentHand->getLog()->debugMode_getPlayerAction(&myAction, &bet, &raise, GAME_STATE_FLOP, currentHand->getMyID(), myUniqueID, mySet); + if(currentHand->getLog()) currentHand->getLog()->debugMode_getPlayerAction(&myAction, &bet, &raise, GAME_STATE_FLOP, currentHand->getMyID(), myUniqueID, mySet); evaluation(bet, raise); } - void LocalPlayer::turnEngine() { @@ -1540,7 +1530,7 @@ void LocalPlayer::turnEngine() // int boardCards[5]; // int i; - // for(i=0; i<2; i++) tempArray[i] = myCards[i]; + // for(i=0; i<2; i++) tempArray[i] = myHoleCards[i]; // currentBoard->getMyCards(boardCards); // for(i=0; i<4; i++) tempArray[2+i] = boardCards[i]; @@ -1801,13 +1791,12 @@ void LocalPlayer::turnEngine() } // debug mode - if(currentHand->getLog()) currentHand->getLog()->debugMode_getPlayerAction(&myAction, &bet, &raise, GAME_STATE_TURN, currentHand->getMyID(), myUniqueID, mySet); + if(currentHand->getLog()) currentHand->getLog()->debugMode_getPlayerAction(&myAction, &bet, &raise, GAME_STATE_TURN, currentHand->getMyID(), myUniqueID, mySet); evaluation(bet, raise); } - void LocalPlayer::riverEngine() { @@ -1815,7 +1804,7 @@ void LocalPlayer::riverEngine() // int boardCards[5]; // int i; - // for(i=0; i<2; i++) tempArray[i] = myCards[i]; + // for(i=0; i<2; i++) tempArray[i] = myHoleCards[i]; // currentBoard->getMyCards(boardCards); // for(i=0; i<4; i++) tempArray[2+i] = boardCards[i]; @@ -2062,13 +2051,12 @@ void LocalPlayer::riverEngine() } // debug mode - if(currentHand->getLog()) currentHand->getLog()->debugMode_getPlayerAction(&myAction, &bet, &raise, GAME_STATE_RIVER, currentHand->getMyID(), myUniqueID, mySet); + if(currentHand->getLog()) currentHand->getLog()->debugMode_getPlayerAction(&myAction, &bet, &raise, GAME_STATE_RIVER, currentHand->getMyID(), myUniqueID, mySet); evaluation(bet, raise); } - void LocalPlayer::evaluation(int bet, int raise) { @@ -2193,7 +2181,6 @@ void LocalPlayer::evaluation(int bet, int raise) } - int LocalPlayer::flopCardsValue(int* cards) { @@ -2827,7 +2814,6 @@ int LocalPlayer::flopCardsValue(int* cards) } - void LocalPlayer::calcMyOdds() { @@ -2835,9 +2821,9 @@ void LocalPlayer::calcMyOdds() switch(currentHand->getCurrentRound()) { - case 0: { + case GAME_STATE_PREFLOP: { - handCode = CardsValue::holeCardsToIntCode(myCards); + handCode = CardsValue::holeCardsToIntCode(myHoleCards); // übergang solange preflopValue und flopValue noch nicht bereinigt int players = currentHand->getActivePlayerList()->size(); @@ -2855,14 +2841,14 @@ void LocalPlayer::calcMyOdds() } break; - case 1: { + case GAME_STATE_FLOP: { int tempArray[5]; int boardCards[5]; int i; - for(i=0; i<2; i++) tempArray[i] = myCards[i]; + for(i=0; i<2; i++) tempArray[i] = myHoleCards[i]; currentHand->getBoard()->getMyCards(boardCards); for(i=0; i<3; i++) tempArray[2+i] = boardCards[i]; @@ -2900,9 +2886,7 @@ void LocalPlayer::calcMyOdds() } break; - case 2: { - - // Prozent ausrechnen + case GAME_STATE_TURN: { int i, j, k; int tempBoardCardsArray[5]; @@ -2910,8 +2894,8 @@ void LocalPlayer::calcMyOdds() int tempOpponentCardsArray[7]; currentHand->getBoard()->getMyCards(tempBoardCardsArray); - tempMyCardsArray[0] = myCards[0]; - tempMyCardsArray[1] = myCards[1]; + tempMyCardsArray[0] = myHoleCards[0]; + tempMyCardsArray[1] = myHoleCards[1]; tempMyCardsArray[2] = tempBoardCardsArray[0]; tempMyCardsArray[3] = tempBoardCardsArray[1]; tempMyCardsArray[4] = tempBoardCardsArray[2]; @@ -2922,6 +2906,12 @@ void LocalPlayer::calcMyOdds() tempOpponentCardsArray[4] = tempBoardCardsArray[2]; tempOpponentCardsArray[5] = tempBoardCardsArray[3]; + + + int myCards[4] = { 0,0,0,0 }; + int opponentCards[4] = { 0,0,0,0 }; + + int tempMyCardsValue; int tempOpponentCardsValue; @@ -2929,11 +2919,11 @@ void LocalPlayer::calcMyOdds() int countMy = 0; for(i=0; i<49; i++) { - if(i != myCards[0] && i != myCards[1] && i != tempBoardCardsArray[0] && i != tempBoardCardsArray[1] && i != tempBoardCardsArray[2]) { + if(i != myHoleCards[0] && i != myHoleCards[1] && i != tempBoardCardsArray[0] && i != tempBoardCardsArray[1] && i != tempBoardCardsArray[2]) { for(j=i+1; j<50; j++) { - if(j != myCards[0] && j != myCards[1] && j != tempBoardCardsArray[0] && j != tempBoardCardsArray[1] && j != tempBoardCardsArray[2]) { + if(j != myHoleCards[0] && j != myHoleCards[1] && j != tempBoardCardsArray[0] && j != tempBoardCardsArray[1] && j != tempBoardCardsArray[2]) { for(k=j+1; k<51; k++) { - if(k != myCards[0] && k != myCards[1] && k != tempBoardCardsArray[0] && k != tempBoardCardsArray[1] && k != tempBoardCardsArray[2]) { + if(k != myHoleCards[0] && k != myHoleCards[1] && k != tempBoardCardsArray[0] && k != tempBoardCardsArray[1] && k != tempBoardCardsArray[2]) { countAll++; @@ -2941,8 +2931,8 @@ void LocalPlayer::calcMyOdds() tempOpponentCardsArray[1] = j; tempOpponentCardsArray[6] = k; tempMyCardsArray[6] = k; - tempMyCardsValue = CardsValue::cardsValue(tempMyCardsArray,0); - tempOpponentCardsValue = CardsValue::cardsValue(tempOpponentCardsArray,0); + tempMyCardsValue = CardsValue::cardsValueOld(tempMyCardsArray,0); + tempOpponentCardsValue = CardsValue::cardsValueOld(tempOpponentCardsArray,0); if(tempMyCardsValue>=tempOpponentCardsValue) countMy++; } @@ -2956,7 +2946,7 @@ void LocalPlayer::calcMyOdds() } break; - case 3: { + case GAME_STATE_RIVER: { // Prozent ausrechnen @@ -2966,8 +2956,8 @@ void LocalPlayer::calcMyOdds() int tempOpponentCardsArray[7]; currentHand->getBoard()->getMyCards(tempBoardCardsArray); - tempMyCardsArray[0] = myCards[0]; - tempMyCardsArray[1] = myCards[1]; + tempMyCardsArray[0] = myHoleCards[0]; + tempMyCardsArray[1] = myHoleCards[1]; tempMyCardsArray[2] = tempBoardCardsArray[0]; tempMyCardsArray[3] = tempBoardCardsArray[1]; tempMyCardsArray[4] = tempBoardCardsArray[2]; @@ -2987,16 +2977,16 @@ void LocalPlayer::calcMyOdds() int countMy = 0; for(i=0; i<49; i++) { - if(i != myCards[0] && i != myCards[1] && i != tempBoardCardsArray[0] && i != tempBoardCardsArray[1] && i != tempBoardCardsArray[2]) { + if(i != myHoleCards[0] && i != myHoleCards[1] && i != tempBoardCardsArray[0] && i != tempBoardCardsArray[1] && i != tempBoardCardsArray[2]) { for(j=i+1; j<50; j++) { - if(j != myCards[0] && j != myCards[1] && j != tempBoardCardsArray[0] && j != tempBoardCardsArray[1] && j != tempBoardCardsArray[2]) { + if(j != myHoleCards[0] && j != myHoleCards[1] && j != tempBoardCardsArray[0] && j != tempBoardCardsArray[1] && j != tempBoardCardsArray[2]) { countAll++; tempOpponentCardsArray[0] = i; tempOpponentCardsArray[1] = j; - tempMyCardsValue = CardsValue::cardsValue(tempMyCardsArray,0); - tempOpponentCardsValue = CardsValue::cardsValue(tempOpponentCardsArray,0); + tempMyCardsValue = CardsValue::cardsValueOld(tempMyCardsArray,0); + tempOpponentCardsValue = CardsValue::cardsValueOld(tempOpponentCardsArray,0); if(tempMyCardsValue>=tempOpponentCardsValue) countMy++; } @@ -3291,7 +3281,7 @@ void LocalPlayer::preflopEngine3() // cout << "preflop-bluff " << bluff << endl; // Potential - int potential = 10*(4*(CardsValue::holeCardsClass(myCards[0], myCards[1]))+1*tempRand)/50-myDude; + int potential = 10*(4*(CardsValue::holeCardsClass(myHoleCards[0], myHoleCards[1]))+1*tempRand)/50-myDude; int setToHighest = currentHand->getCurrentBeRo()->getHighestSet() - mySet; @@ -3301,7 +3291,7 @@ void LocalPlayer::preflopEngine3() Tools::GetRand(2, 3, 1, &tempFold); // FOLD --> wenn Potential negativ oder HighestSet zu hoch - if( (potential*setToHighest<0 || (setToHighest > tempFold * currentHand->getSmallBlind() && potential<1) || (setToHighest > 2 * tempFold * currentHand->getSmallBlind() && potential<2) || (setToHighest > 4 * tempFold * currentHand->getSmallBlind() && potential<3) || (setToHighest > 10 * tempFold * currentHand->getSmallBlind() && potential<4)) && CardsValue::holeCardsClass(myCards[0], myCards[1]) < 9 && bluff > 15) { + if( (potential*setToHighest<0 || (setToHighest > tempFold * currentHand->getSmallBlind() && potential<1) || (setToHighest > 2 * tempFold * currentHand->getSmallBlind() && potential<2) || (setToHighest > 4 * tempFold * currentHand->getSmallBlind() && potential<3) || (setToHighest > 10 * tempFold * currentHand->getSmallBlind() && potential<4)) && CardsValue::holeCardsClass(myHoleCards[0], myHoleCards[1]) < 9 && bluff > 15) { myAction = PLAYER_ACTION_FOLD; } else { // RAISE --> wenn hohes Potential @@ -3457,8 +3447,8 @@ void LocalPlayer::flopEngine3() int tempOpponentCardsArray[7]; currentHand->getBoard()->getMyCards(tempBoardCardsArray); - tempMyCardsArray[0] = myCards[0]; - tempMyCardsArray[1] = myCards[1]; + tempMyCardsArray[0] = myHoleCards[0]; + tempMyCardsArray[1] = myHoleCards[1]; tempMyCardsArray[2] = tempBoardCardsArray[0]; tempMyCardsArray[3] = tempBoardCardsArray[1]; tempMyCardsArray[4] = tempBoardCardsArray[2]; @@ -3474,13 +3464,13 @@ void LocalPlayer::flopEngine3() int countMy = 0; for(i=0; i<49; i++) { - if(i != myCards[0] && i != myCards[1] && i != tempBoardCardsArray[0] && i != tempBoardCardsArray[1] && i != tempBoardCardsArray[2]) { + if(i != myHoleCards[0] && i != myHoleCards[1] && i != tempBoardCardsArray[0] && i != tempBoardCardsArray[1] && i != tempBoardCardsArray[2]) { for(j=i+1; j<50; j++) { - if(j != myCards[0] && j != myCards[1] && j != tempBoardCardsArray[0] && j != tempBoardCardsArray[1] && j != tempBoardCardsArray[2]) { + if(j != myHoleCards[0] && j != myHoleCards[1] && j != tempBoardCardsArray[0] && j != tempBoardCardsArray[1] && j != tempBoardCardsArray[2]) { for(k=j+1; k<51; k++) { - if(k != myCards[0] && k != myCards[1] && k != tempBoardCardsArray[0] && k != tempBoardCardsArray[1] && k != tempBoardCardsArray[2]) { + if(k != myHoleCards[0] && k != myHoleCards[1] && k != tempBoardCardsArray[0] && k != tempBoardCardsArray[1] && k != tempBoardCardsArray[2]) { for(l=k+1; l<52; l++) { - if(l != myCards[0] && l != myCards[1] && l != tempBoardCardsArray[0] && l != tempBoardCardsArray[1] && l != tempBoardCardsArray[2]) { + if(l != myHoleCards[0] && l != myHoleCards[1] && l != tempBoardCardsArray[0] && l != tempBoardCardsArray[1] && l != tempBoardCardsArray[2]) { countAll++; @@ -3490,8 +3480,8 @@ void LocalPlayer::flopEngine3() tempOpponentCardsArray[6] = l; tempMyCardsArray[5] = k; tempMyCardsArray[6] = l; - tempMyCardsValue = CardsValue::cardsValue(tempMyCardsArray,0); - tempOpponentCardsValue = CardsValue::cardsValue(tempOpponentCardsArray,0); + tempMyCardsValue = CardsValue::cardsValueOld(tempMyCardsArray,0); + tempOpponentCardsValue = CardsValue::cardsValueOld(tempOpponentCardsArray,0); if(tempMyCardsValue>=tempOpponentCardsValue) countMy++; @@ -3628,8 +3618,8 @@ void LocalPlayer::turnEngine3() int tempOpponentCardsArray[7]; currentHand->getBoard()->getMyCards(tempBoardCardsArray); - tempMyCardsArray[0] = myCards[0]; - tempMyCardsArray[1] = myCards[1]; + tempMyCardsArray[0] = myHoleCards[0]; + tempMyCardsArray[1] = myHoleCards[1]; tempMyCardsArray[2] = tempBoardCardsArray[0]; tempMyCardsArray[3] = tempBoardCardsArray[1]; tempMyCardsArray[4] = tempBoardCardsArray[2]; @@ -3647,11 +3637,11 @@ void LocalPlayer::turnEngine3() int countMy = 0; for(i=0; i<49; i++) { - if(i != myCards[0] && i != myCards[1] && i != tempBoardCardsArray[0] && i != tempBoardCardsArray[1] && i != tempBoardCardsArray[2]) { + if(i != myHoleCards[0] && i != myHoleCards[1] && i != tempBoardCardsArray[0] && i != tempBoardCardsArray[1] && i != tempBoardCardsArray[2]) { for(j=i+1; j<50; j++) { - if(j != myCards[0] && j != myCards[1] && j != tempBoardCardsArray[0] && j != tempBoardCardsArray[1] && j != tempBoardCardsArray[2]) { + if(j != myHoleCards[0] && j != myHoleCards[1] && j != tempBoardCardsArray[0] && j != tempBoardCardsArray[1] && j != tempBoardCardsArray[2]) { for(k=j+1; k<51; k++) { - if(k != myCards[0] && k != myCards[1] && k != tempBoardCardsArray[0] && k != tempBoardCardsArray[1] && k != tempBoardCardsArray[2]) { + if(k != myHoleCards[0] && k != myHoleCards[1] && k != tempBoardCardsArray[0] && k != tempBoardCardsArray[1] && k != tempBoardCardsArray[2]) { countAll++; @@ -3659,8 +3649,8 @@ void LocalPlayer::turnEngine3() tempOpponentCardsArray[1] = j; tempOpponentCardsArray[6] = k; tempMyCardsArray[6] = k; - tempMyCardsValue = CardsValue::cardsValue(tempMyCardsArray,0); - tempOpponentCardsValue = CardsValue::cardsValue(tempOpponentCardsArray,0); + tempMyCardsValue = CardsValue::cardsValueOld(tempMyCardsArray,0); + tempOpponentCardsValue = CardsValue::cardsValueOld(tempOpponentCardsArray,0); if(tempMyCardsValue>=tempOpponentCardsValue) countMy++; } @@ -3794,8 +3784,8 @@ void LocalPlayer::riverEngine3() int tempOpponentCardsArray[7]; currentHand->getBoard()->getMyCards(tempBoardCardsArray); - tempMyCardsArray[0] = myCards[0]; - tempMyCardsArray[1] = myCards[1]; + tempMyCardsArray[0] = myHoleCards[0]; + tempMyCardsArray[1] = myHoleCards[1]; tempMyCardsArray[2] = tempBoardCardsArray[0]; tempMyCardsArray[3] = tempBoardCardsArray[1]; tempMyCardsArray[4] = tempBoardCardsArray[2]; @@ -3815,16 +3805,16 @@ void LocalPlayer::riverEngine3() int countMy = 0; for(i=0; i<49; i++) { - if(i != myCards[0] && i != myCards[1] && i != tempBoardCardsArray[0] && i != tempBoardCardsArray[1] && i != tempBoardCardsArray[2]) { + if(i != myHoleCards[0] && i != myHoleCards[1] && i != tempBoardCardsArray[0] && i != tempBoardCardsArray[1] && i != tempBoardCardsArray[2]) { for(j=i+1; j<50; j++) { - if(j != myCards[0] && j != myCards[1] && j != tempBoardCardsArray[0] && j != tempBoardCardsArray[1] && j != tempBoardCardsArray[2]) { + if(j != myHoleCards[0] && j != myHoleCards[1] && j != tempBoardCardsArray[0] && j != tempBoardCardsArray[1] && j != tempBoardCardsArray[2]) { countAll++; tempOpponentCardsArray[0] = i; tempOpponentCardsArray[1] = j; - tempMyCardsValue = CardsValue::cardsValue(tempMyCardsArray,0); - tempOpponentCardsValue = CardsValue::cardsValue(tempOpponentCardsArray,0); + tempMyCardsValue = CardsValue::cardsValueOld(tempMyCardsArray,0); + tempOpponentCardsValue = CardsValue::cardsValueOld(tempOpponentCardsArray,0); if(tempMyCardsValue>=tempOpponentCardsValue) countMy++; } diff --git a/src/engine/local_engine/localplayer.h b/src/engine/local_engine/localplayer.h index 58269e9b..eac742e7 100755 --- a/src/engine/local_engine/localplayer.h +++ b/src/engine/local_engine/localplayer.h @@ -48,8 +48,9 @@ public: ~LocalPlayer(); - void setHand(HandInterface *); - + void setHand(HandInterface *theValue) { + currentHand = theValue; + } int getMyID() const { return myID; } @@ -156,13 +157,13 @@ public: return myStayOnTableStatus; } - void setMyCards(int* theValue) { + void setMyHoleCards(int* theValue) { int i; - for(i=0; i<2; i++) myCards[i] = theValue[i]; + for(i=0; i<2; i++) myHoleCards[i] = theValue[i]; } - void getMyCards(int* theValue) const { + void getMyHoleCards(int* theValue) const { int i; - for(i=0; i<2; i++) theValue[i] = myCards[i]; + for(i=0; i<2; i++) theValue[i] = myHoleCards[i]; } void setMyTurn(bool theValue) { @@ -172,27 +173,27 @@ public: return myTurn; } - void setMyCardsFlip(bool theValue, int state) { - myCardsFlip = theValue; + void setMyHoleCardsFlip(bool theValue, int state) { + myHoleCardsFlip = theValue; // log flipping cards - if(myCardsFlip) { + if(myHoleCardsFlip) { switch(state) { case 1: - currentHand->getGuiInterface()->logFlipHoleCardsMsg(myName, myCards[0], myCards[1], myCardsValueInt); + currentHand->getGuiInterface()->logFlipHoleCardsMsg(myName, myHoleCards[0], myHoleCards[1], myCardsValueInt); break; case 2: - currentHand->getGuiInterface()->logFlipHoleCardsMsg(myName, myCards[0], myCards[1]); + currentHand->getGuiInterface()->logFlipHoleCardsMsg(myName, myHoleCards[0], myHoleCards[1]); break; case 3: - currentHand->getGuiInterface()->logFlipHoleCardsMsg(myName, myCards[0], myCards[1], myCardsValueInt, "has"); + currentHand->getGuiInterface()->logFlipHoleCardsMsg(myName, myHoleCards[0], myHoleCards[1], myCardsValueInt, "has"); break; default: ; } } } - bool getMyCardsFlip() const { - return myCardsFlip; + bool getMyHoleCardsFlip() const { + return myHoleCardsFlip; } void setMyCardsValueInt(int theValue) { @@ -328,7 +329,7 @@ private: int myNiveau[3]; bool logHoleCardsDone; - int myCards[2]; + int myHoleCards[2]; int myCash; int mySet; int myLastRelativeSet; @@ -337,7 +338,7 @@ private: bool myActiveStatus; // 0 = inactive, 1 = active bool myStayOnTableStatus; // 0 = left, 1 = stay bool myTurn; // 0 = no, 1 = yes - bool myCardsFlip; // 0 = cards are not fliped, 1 = cards are already flipped, + bool myHoleCardsFlip; // 0 = cards are not fliped, 1 = cards are already flipped, int myRoundStartCash; int lastMoneyWon; diff --git a/src/engine/local_engine/tools.cpp b/src/engine/local_engine/tools.cpp index ebc47a6c..974b0956 100755 --- a/src/engine/local_engine/tools.cpp +++ b/src/engine/local_engine/tools.cpp @@ -83,3 +83,13 @@ void Tools::GetRand(int minValue, int maxValue, unsigned count, int *out) } } +int Tools::bitcount(int in) +{ + int count=0 ; + while (in) { + count++ ; + in &= (in - 1) ; + } + return count ; +} + diff --git a/src/engine/local_engine/tools.h b/src/engine/local_engine/tools.h index 7cd599a4..36fdbdae 100755 --- a/src/engine/local_engine/tools.h +++ b/src/engine/local_engine/tools.h @@ -38,6 +38,7 @@ public: static void ShuffleArrayNonDeterministic(int *inout, unsigned count); static void GetRand(int minValue, int maxValue, unsigned count, int *out); + static int bitcount(int in); }; diff --git a/src/engine/log.cpp b/src/engine/log.cpp index f1625aa0..b13fd6d2 100644 --- a/src/engine/log.cpp +++ b/src/engine/log.cpp @@ -119,115 +119,112 @@ Log::Log(ConfigFile *c) : mySqliteLogDb(0), mySqliteLogFileName(""), myConfig(c) Log::~Log() { - if(SQLITE_LOG) sqlite3_close(mySqliteLogDb); + sqlite3_close(mySqliteLogDb); } void Log::init() { - if(SQLITE_LOG) { + // logging activated + if(myConfig->readConfigInt("LogOnOff")) { - // logging activated - if(myConfig->readConfigInt("LogOnOff")) { + DIR *logDir; + logDir = opendir((myConfig->readConfigString("LogDir")).c_str()); + bool dirExists = logDir != NULL; + closedir(logDir); - DIR *logDir; - logDir = opendir((myConfig->readConfigString("LogDir")).c_str()); - bool dirExists = logDir != NULL; - closedir(logDir); + // check if logging path exist + if(myConfig->readConfigString("LogDir") != "" && dirExists) { - // check if logging path exist - if(myConfig->readConfigString("LogDir") != "" && dirExists) { + // detect current time + char curDateTime[20]; + char curDate[11]; + char curTime[9]; + time_t now = time(NULL); + tm *z = localtime(&now); + strftime(curDateTime,20,"%Y-%m-%d_%H%M%S",z); + strftime(curDate,11,"%Y-%m-%d",z); + strftime(curTime,9,"%H:%M:%S",z); - // detect current time - char curDateTime[20]; - char curDate[11]; - char curTime[9]; - time_t now = time(NULL); - tm *z = localtime(&now); - strftime(curDateTime,20,"%Y-%m-%d_%H%M%S",z); - strftime(curDate,11,"%Y-%m-%d",z); - strftime(curTime,9,"%H:%M:%S",z); + mySqliteLogFileName.clear(); + mySqliteLogFileName /= myConfig->readConfigString("LogDir"); + mySqliteLogFileName /= string("pokerth-log-") + curDateTime + ".pdb"; - mySqliteLogFileName.clear(); - mySqliteLogFileName /= myConfig->readConfigString("LogDir"); - mySqliteLogFileName /= string("pokerth-log-") + curDateTime + ".pdb"; + // open sqlite-db + sqlite3_open(mySqliteLogFileName.directory_string().c_str(), &mySqliteLogDb); + if( mySqliteLogDb != 0 ) { - // open sqlite-db - sqlite3_open(mySqliteLogFileName.directory_string().c_str(), &mySqliteLogDb); - if( mySqliteLogDb != 0 ) { + int i; + // create session table + sql += "CREATE TABLE Session ("; + sql += "PokerTH_Version TEXT NOT NULL"; + sql += ",Date TEXT NOT NULL"; + sql += ",Time TEXT NOT NULL"; + sql += ",LogVersion INTEGER NOT NULL"; + sql += ", PRIMARY KEY(Date,Time));"; - int i; - // create session table - sql += "CREATE TABLE Session ("; - sql += "PokerTH_Version TEXT NOT NULL"; - sql += ",Date TEXT NOT NULL"; - sql += ",Time TEXT NOT NULL"; - sql += ",LogVersion INTEGER NOT NULL"; - sql += ", PRIMARY KEY(Date,Time));"; + sql += "INSERT INTO Session ("; + sql += "PokerTH_Version"; + sql += ",Date"; + sql += ",Time"; + sql += ",LogVersion"; + sql += ") VALUES ("; + sql += "\"" + boost::lexical_cast(POKERTH_BETA_RELEASE_STRING) + "\","; + sql += "\"" + boost::lexical_cast(curDate) + "\","; + sql += "\"" + boost::lexical_cast(curTime) + "\","; + sql += boost::lexical_cast(SQLITE_LOG_VERSION) + ");"; - sql += "INSERT INTO Session ("; - sql += "PokerTH_Version"; - sql += ",Date"; - sql += ",Time"; - sql += ",LogVersion"; - sql += ") VALUES ("; - sql += "\"" + boost::lexical_cast(POKERTH_BETA_RELEASE_STRING) + "\","; - sql += "\"" + boost::lexical_cast(curDate) + "\","; - sql += "\"" + boost::lexical_cast(curTime) + "\","; - sql += boost::lexical_cast(SQLITE_LOG_VERSION) + ");"; + // create game table + sql += "CREATE TABLE Game ("; + sql += "UniqueGameID INTEGER PRIMARY KEY"; + sql += ",GameID INTEGER NOT NULL"; + sql += ",Startmoney INTEGER NOT NULL"; + sql += ",StartSb INTEGER NOT NULL"; + sql += ",DealerPos INTEGER NOT NULL"; + sql += ",Winner_Seat INTEGER"; + sql += ");"; - // create game table - sql += "CREATE TABLE Game ("; - sql += "UniqueGameID INTEGER PRIMARY KEY"; - sql += ",GameID INTEGER NOT NULL"; - sql += ",Startmoney INTEGER NOT NULL"; - sql += ",StartSb INTEGER NOT NULL"; - sql += ",DealerPos INTEGER NOT NULL"; - sql += ",Winner_Seat INTEGER"; - sql += ");"; + // create player table + sql += "CREATE TABLE Player ("; + sql += "UniqueGameID INTEGER NOT NULL"; + sql += ",Seat INTEGER NOT NULL"; + sql += ",Player TEXT NOT NULL"; + sql += ",PRIMARY KEY(UniqueGameID,Seat));"; - // create player table - sql += "CREATE TABLE Player ("; - sql += "UniqueGameID INTEGER NOT NULL"; - sql += ",Seat INTEGER NOT NULL"; - sql += ",Player TEXT NOT NULL"; - sql += ",PRIMARY KEY(UniqueGameID,Seat));"; - - // create hand table - sql += "CREATE TABLE Hand ("; - sql += "HandID INTEGER NOT NULL"; - sql += ",UniqueGameID INTEGER NOT NULL"; - sql += ",Dealer_Seat INTEGER"; - sql += ",Sb_Amount INTEGER NOT NULL"; - sql += ",Sb_Seat INTEGER NOT NULL"; - sql += ",Bb_Amount INTEGER NOT NULL"; - sql += ",Bb_Seat INTEGER NOT NULL"; - for(i=1; i<=MAX_NUMBER_OF_PLAYERS; i++) { - sql += ",Seat_" + boost::lexical_cast(i) + "_Cash INTEGER"; - sql += ",Seat_" + boost::lexical_cast(i) + "_Card_1 INTEGER"; - sql += ",Seat_" + boost::lexical_cast(i) + "_Card_2 INTEGER"; - sql += ",Seat_" + boost::lexical_cast(i) + "_Hand_text TEXT"; - sql += ",Seat_" + boost::lexical_cast(i) + "_Hand_int INTEGER"; - } - for(i=1; i<=5; i++) { - sql += ",BoardCard_" + boost::lexical_cast(i) + " INTEGER"; - } - sql += ",PRIMARY KEY(HandID,UniqueGameID));"; - - // create action table - sql += "CREATE TABLE Action ("; - sql += "ActionID INTEGER PRIMARY KEY AUTOINCREMENT"; - sql += ",HandID INTEGER NOT NULL"; - sql += ",UniqueGameID INTEGER NOT NULL"; - sql += ",BeRo INTEGER NOT NULL"; - sql += ",Player INTEGER NOT NULL"; - sql += ",Action TEXT NOT NULL"; - sql += ",Amount INTEGER"; - sql += ");"; - - exec_transaction(); + // create hand table + sql += "CREATE TABLE Hand ("; + sql += "HandID INTEGER NOT NULL"; + sql += ",UniqueGameID INTEGER NOT NULL"; + sql += ",Dealer_Seat INTEGER"; + sql += ",Sb_Amount INTEGER NOT NULL"; + sql += ",Sb_Seat INTEGER NOT NULL"; + sql += ",Bb_Amount INTEGER NOT NULL"; + sql += ",Bb_Seat INTEGER NOT NULL"; + for(i=1; i<=MAX_NUMBER_OF_PLAYERS; i++) { + sql += ",Seat_" + boost::lexical_cast(i) + "_Cash INTEGER"; + sql += ",Seat_" + boost::lexical_cast(i) + "_Card_1 INTEGER"; + sql += ",Seat_" + boost::lexical_cast(i) + "_Card_2 INTEGER"; + sql += ",Seat_" + boost::lexical_cast(i) + "_Hand_text TEXT"; + sql += ",Seat_" + boost::lexical_cast(i) + "_Hand_int INTEGER"; } + for(i=1; i<=5; i++) { + sql += ",BoardCard_" + boost::lexical_cast(i) + " INTEGER"; + } + sql += ",PRIMARY KEY(HandID,UniqueGameID));"; + + // create action table + sql += "CREATE TABLE Action ("; + sql += "ActionID INTEGER PRIMARY KEY AUTOINCREMENT"; + sql += ",HandID INTEGER NOT NULL"; + sql += ",UniqueGameID INTEGER NOT NULL"; + sql += ",BeRo INTEGER NOT NULL"; + sql += ",Player INTEGER NOT NULL"; + sql += ",Action TEXT NOT NULL"; + sql += ",Amount INTEGER"; + sql += ");"; + + exec_transaction(); } } } @@ -238,49 +235,46 @@ Log::logNewGameMsg(int gameID, int startCash, int startSmallBlind, unsigned deal { uniqueGameID++; - if(SQLITE_LOG) { + if(myConfig->readConfigInt("LogOnOff")) { + //if write logfiles is enabled - if(myConfig->readConfigInt("LogOnOff")) { - //if write logfiles is enabled + PlayerListConstIterator it_c; - PlayerListConstIterator it_c; + if( mySqliteLogDb != 0 ) { + // sqlite-db is open + int i; - if( mySqliteLogDb != 0 ) { - // sqlite-db is open - int i; + sql += "INSERT INTO Game ("; + sql += "UniqueGameID"; + sql += ",GameID"; + sql += ",Startmoney"; + sql += ",StartSb"; + sql += ",DealerPos"; + sql += ") VALUES ("; + sql += boost::lexical_cast(uniqueGameID); + sql += "," + boost::lexical_cast(gameID); + sql += "," + boost::lexical_cast(startCash); + sql += "," + boost::lexical_cast(startSmallBlind); + sql += "," + boost::lexical_cast(dealerPosition); + sql += ");"; - sql += "INSERT INTO Game ("; - sql += "UniqueGameID"; - sql += ",GameID"; - sql += ",Startmoney"; - sql += ",StartSb"; - sql += ",DealerPos"; - sql += ") VALUES ("; - sql += boost::lexical_cast(uniqueGameID); - sql += "," + boost::lexical_cast(gameID); - sql += "," + boost::lexical_cast(startCash); - sql += "," + boost::lexical_cast(startSmallBlind); - sql += "," + boost::lexical_cast(dealerPosition); - sql += ");"; - - i = 1; - for(it_c = seatsList->begin(); it_c!=seatsList->end(); ++it_c) { - if((*it_c)->getMyActiveStatus()) { - sql += "INSERT INTO Player ("; - sql += "UniqueGameID"; - sql += ",Seat"; - sql += ",Player"; - sql += ") VALUES ("; - sql += boost::lexical_cast(uniqueGameID); - sql += "," + boost::lexical_cast(i); - sql += ",\"" + (*it_c)->getMyName() +"\""; - sql += ");"; - } - i++; + i = 1; + for(it_c = seatsList->begin(); it_c!=seatsList->end(); ++it_c) { + if((*it_c)->getMyActiveStatus()) { + sql += "INSERT INTO Player ("; + sql += "UniqueGameID"; + sql += ",Seat"; + sql += ",Player"; + sql += ") VALUES ("; + sql += boost::lexical_cast(uniqueGameID); + sql += "," + boost::lexical_cast(i); + sql += ",\"" + (*it_c)->getMyName() +"\""; + sql += ");"; } - - exec_transaction(); + i++; } + + exec_transaction(); } } } @@ -296,82 +290,79 @@ Log::logNewHandMsg(int handID, unsigned dealerPosition, int smallBlind, unsigned (*it_c)->setLogHoleCardsDone(false); } - if(SQLITE_LOG) { + if(myConfig->readConfigInt("LogOnOff")) { + //if write logfiles is enabled - if(myConfig->readConfigInt("LogOnOff")) { - //if write logfiles is enabled - - if( mySqliteLogDb != 0 ) { - // sqlite-db is open - int i; - - sql += "INSERT INTO Hand ("; - sql += "HandID"; - sql += ",UniqueGameID"; - sql += ",Dealer_Seat"; - sql += ",Sb_Amount"; - sql += ",Sb_Seat"; - sql += ",Bb_Amount"; - sql += ",Bb_Seat"; - for(i=1; i<=MAX_NUMBER_OF_PLAYERS; i++) { - sql += ",Seat_" + boost::lexical_cast(i) + "_Cash"; - } - sql += ") VALUES ("; - sql += boost::lexical_cast(currentHandID); - sql += "," + boost::lexical_cast(uniqueGameID); - sql += "," + boost::lexical_cast(dealerPosition); - sql += "," + boost::lexical_cast(smallBlind); - sql += "," + boost::lexical_cast(smallBlindPosition); - sql += "," + boost::lexical_cast(bigBlind); - sql += "," + boost::lexical_cast(bigBlindPosition); - for(it_c = seatsList->begin(); it_c!=seatsList->end(); ++it_c) { - if((*it_c)->getMyActiveStatus()) { - sql += "," + boost::lexical_cast((*it_c)->getMyRoundStartCash()); - } else { - sql += ",NULL"; - } - } - sql += ");"; - if(myConfig->readConfigInt("LogInterval") == 0) { - exec_transaction(); - } - - // !! TODO !! Hack, weil Button-Regel noch falsch und dealerPosition noch teilweise falsche ID enthält (HeadsUp: dealerPosition=bigBlindPosition <-- falsch) - bool dealerButtonOnTable = false; - int countActivePlayer = 0; - for(it_c = seatsList->begin(); it_c!=seatsList->end(); ++it_c) { - if((*it_c)->getMyActiveStatus()) { - countActivePlayer++; - if((*it_c)->getMyButton()==BUTTON_DEALER && (*it_c)->getMyActiveStatus()) { - dealerButtonOnTable = true; - } - } - } - if(countActivePlayer==2) { - logPlayerAction(smallBlindPosition,LOG_ACTION_DEALER); - } else { - if(dealerButtonOnTable) { - logPlayerAction(dealerPosition,LOG_ACTION_DEALER); - } - } - - // log blinds - for(it_c = seatsList->begin(); it_c!=seatsList->end(); ++it_c) { - if((*it_c)->getMyButton() == BUTTON_SMALL_BLIND && (*it_c)->getMySet()>0) { - logPlayerAction(smallBlindPosition,LOG_ACTION_SMALL_BLIND,(*it_c)->getMySet()); - } - } - for(it_c = seatsList->begin(); it_c!=seatsList->end(); ++it_c) { - if((*it_c)->getMyButton() == BUTTON_BIG_BLIND && (*it_c)->getMySet()>0) { - logPlayerAction(bigBlindPosition,LOG_ACTION_BIG_BLIND,(*it_c)->getMySet()); - } - } - - // (*it_c)->getMySet() ist ein Hack, da es im Internetspiel vorkam, dass ein Spieler zweimal geloggt wurde mit Blind - einmal jedoch mit $0 - - // !! TODO !! Hack + if( mySqliteLogDb != 0 ) { + // sqlite-db is open + int i; + sql += "INSERT INTO Hand ("; + sql += "HandID"; + sql += ",UniqueGameID"; + sql += ",Dealer_Seat"; + sql += ",Sb_Amount"; + sql += ",Sb_Seat"; + sql += ",Bb_Amount"; + sql += ",Bb_Seat"; + for(i=1; i<=MAX_NUMBER_OF_PLAYERS; i++) { + sql += ",Seat_" + boost::lexical_cast(i) + "_Cash"; } + sql += ") VALUES ("; + sql += boost::lexical_cast(currentHandID); + sql += "," + boost::lexical_cast(uniqueGameID); + sql += "," + boost::lexical_cast(dealerPosition); + sql += "," + boost::lexical_cast(smallBlind); + sql += "," + boost::lexical_cast(smallBlindPosition); + sql += "," + boost::lexical_cast(bigBlind); + sql += "," + boost::lexical_cast(bigBlindPosition); + for(it_c = seatsList->begin(); it_c!=seatsList->end(); ++it_c) { + if((*it_c)->getMyActiveStatus()) { + sql += "," + boost::lexical_cast((*it_c)->getMyRoundStartCash()); + } else { + sql += ",NULL"; + } + } + sql += ");"; + if(myConfig->readConfigInt("LogInterval") == 0) { + exec_transaction(); + } + + // !! TODO !! Hack, weil Button-Regel noch falsch und dealerPosition noch teilweise falsche ID enthält (HeadsUp: dealerPosition=bigBlindPosition <-- falsch) + bool dealerButtonOnTable = false; + int countActivePlayer = 0; + for(it_c = seatsList->begin(); it_c!=seatsList->end(); ++it_c) { + if((*it_c)->getMyActiveStatus()) { + countActivePlayer++; + if((*it_c)->getMyButton()==BUTTON_DEALER && (*it_c)->getMyActiveStatus()) { + dealerButtonOnTable = true; + } + } + } + if(countActivePlayer==2) { + logPlayerAction(smallBlindPosition,LOG_ACTION_DEALER); + } else { + if(dealerButtonOnTable) { + logPlayerAction(dealerPosition,LOG_ACTION_DEALER); + } + } + + // log blinds + for(it_c = seatsList->begin(); it_c!=seatsList->end(); ++it_c) { + if((*it_c)->getMyButton() == BUTTON_SMALL_BLIND && (*it_c)->getMySet()>0) { + logPlayerAction(smallBlindPosition,LOG_ACTION_SMALL_BLIND,(*it_c)->getMySet()); + } + } + for(it_c = seatsList->begin(); it_c!=seatsList->end(); ++it_c) { + if((*it_c)->getMyButton() == BUTTON_BIG_BLIND && (*it_c)->getMySet()>0) { + logPlayerAction(bigBlindPosition,LOG_ACTION_BIG_BLIND,(*it_c)->getMySet()); + } + } + + // (*it_c)->getMySet() ist ein Hack, da es im Internetspiel vorkam, dass ein Spieler zweimal geloggt wurde mit Blind - einmal jedoch mit $0 + + // !! TODO !! Hack + } } } @@ -380,35 +371,32 @@ void Log::logPlayerAction(string playerName, PlayerActionLog action, int amount) { - if(SQLITE_LOG) { + if(myConfig->readConfigInt("LogOnOff")) { + //if write logfiles is enabled - if(myConfig->readConfigInt("LogOnOff")) { - //if write logfiles is enabled + if( mySqliteLogDb != 0 ) { + // sqlite-db is open - if( mySqliteLogDb != 0 ) { - // sqlite-db is open + char **result_Player=0; + int nRow_Player=0; + int nCol_Player=0; + char *errmsg = 0; - char **result_Player=0; - int nRow_Player=0; - int nCol_Player=0; - char *errmsg = 0; - - // read seat - string sql_select = "SELECT Seat FROM Player WHERE UniqueGameID=" + boost::lexical_cast(uniqueGameID); - sql_select += " AND "; - sql_select += "Player=\"" + playerName +"\""; - if(sqlite3_get_table(mySqliteLogDb,sql_select.c_str(),&result_Player,&nRow_Player,&nCol_Player,&errmsg) != SQLITE_OK) { - cout << "Error in statement: " << sql_select.c_str() << "[" << errmsg << "]." << endl; + // read seat + string sql_select = "SELECT Seat FROM Player WHERE UniqueGameID=" + boost::lexical_cast(uniqueGameID); + sql_select += " AND "; + sql_select += "Player=\"" + playerName +"\""; + if(sqlite3_get_table(mySqliteLogDb,sql_select.c_str(),&result_Player,&nRow_Player,&nCol_Player,&errmsg) != SQLITE_OK) { + cout << "Error in statement: " << sql_select.c_str() << "[" << errmsg << "]." << endl; + } else { + if(nRow_Player == 1) { + logPlayerAction(boost::lexical_cast(result_Player[1]), action, amount); } else { - if(nRow_Player == 1) { - logPlayerAction(boost::lexical_cast(result_Player[1]), action, amount); - } else { - cout << "Implausible information about player " << playerName << " in log-db!" << endl; - } + cout << "Implausible information about player " << playerName << " in log-db!" << endl; } - - sqlite3_free_table(result_Player); } + + sqlite3_free_table(result_Player); } } } @@ -417,107 +405,104 @@ void Log::logPlayerAction(int seat, PlayerActionLog action, int amount) { - if(SQLITE_LOG) { + if(myConfig->readConfigInt("LogOnOff")) { + //if write logfiles is enabled - if(myConfig->readConfigInt("LogOnOff")) { - //if write logfiles is enabled + if( mySqliteLogDb != 0 ) { + // sqlite-db is open - if( mySqliteLogDb != 0 ) { - // sqlite-db is open - - if(action!=LOG_ACTION_NONE) { - sql += "INSERT INTO Action ("; - sql += "HandID"; - sql += ",UniqueGameID"; - sql += ",BeRo"; - sql += ",Player"; - sql += ",Action"; - sql += ",Amount"; - sql += ") VALUES ("; - sql += boost::lexical_cast(currentHandID); - sql += "," + boost::lexical_cast(uniqueGameID); - sql += "," + boost::lexical_cast(currentRound);; - sql += "," + boost::lexical_cast(seat); - switch(action) { - case LOG_ACTION_DEALER: - sql += ",'starts as dealer'"; - sql += ",NULL"; - break; - case LOG_ACTION_SMALL_BLIND: - sql += ",'posts small blind'"; - sql += "," + boost::lexical_cast(amount); - break; - case LOG_ACTION_BIG_BLIND: - sql += ",'posts big blind'"; - sql += "," + boost::lexical_cast(amount); - break; - case LOG_ACTION_FOLD: - sql += ",'folds'"; - sql += ",NULL"; - break; - case LOG_ACTION_CHECK: - sql += ",'checks'"; - sql += ",NULL"; - break; - case LOG_ACTION_CALL: - sql += ",'calls'"; - sql += "," + boost::lexical_cast(amount); - break; - case LOG_ACTION_BET: - sql += ",'bets'"; - sql += "," + boost::lexical_cast(amount); - break; - case LOG_ACTION_ALL_IN: - sql += ",'is all in with'"; - sql += "," + boost::lexical_cast(amount); - break; - case LOG_ACTION_SHOW: - sql += ",'shows'"; - sql += ",NULL"; - break; - case LOG_ACTION_HAS: - sql += ",'has'"; - sql += ",NULL"; - break; - case LOG_ACTION_WIN: - sql += ",'wins'"; - sql += "," + boost::lexical_cast(amount); - break; - case LOG_ACTION_WIN_SIDE_POT: - sql += ",'wins (side pot)'"; - sql += "," + boost::lexical_cast(amount); - break; - case LOG_ACTION_SIT_OUT: - sql += ",'sits out'"; - sql += ",NULL"; - break; - case LOG_ACTION_WIN_GAME: - sql += ",'wins game'"; - sql += ",NULL"; - break; - case LOG_ACTION_LEFT: - sql += ",'has left the game'"; - sql += ",NULL"; - break; - case LOG_ACTION_KICKED: - sql += ",'was kicked from the game'"; - sql += ",NULL"; - break; - case LOG_ACTION_ADMIN: - sql += ",'is game admin now'"; - sql += ",NULL"; - break; - case LOG_ACTION_JOIN: - sql += ",'has joined the game'"; - sql += ",NULL"; - break; - default: - return; - } - sql += ");"; - if(myConfig->readConfigInt("LogInterval") == 0) { - exec_transaction(); - } + if(action!=LOG_ACTION_NONE) { + sql += "INSERT INTO Action ("; + sql += "HandID"; + sql += ",UniqueGameID"; + sql += ",BeRo"; + sql += ",Player"; + sql += ",Action"; + sql += ",Amount"; + sql += ") VALUES ("; + sql += boost::lexical_cast(currentHandID); + sql += "," + boost::lexical_cast(uniqueGameID); + sql += "," + boost::lexical_cast(currentRound);; + sql += "," + boost::lexical_cast(seat); + switch(action) { + case LOG_ACTION_DEALER: + sql += ",'starts as dealer'"; + sql += ",NULL"; + break; + case LOG_ACTION_SMALL_BLIND: + sql += ",'posts small blind'"; + sql += "," + boost::lexical_cast(amount); + break; + case LOG_ACTION_BIG_BLIND: + sql += ",'posts big blind'"; + sql += "," + boost::lexical_cast(amount); + break; + case LOG_ACTION_FOLD: + sql += ",'folds'"; + sql += ",NULL"; + break; + case LOG_ACTION_CHECK: + sql += ",'checks'"; + sql += ",NULL"; + break; + case LOG_ACTION_CALL: + sql += ",'calls'"; + sql += "," + boost::lexical_cast(amount); + break; + case LOG_ACTION_BET: + sql += ",'bets'"; + sql += "," + boost::lexical_cast(amount); + break; + case LOG_ACTION_ALL_IN: + sql += ",'is all in with'"; + sql += "," + boost::lexical_cast(amount); + break; + case LOG_ACTION_SHOW: + sql += ",'shows'"; + sql += ",NULL"; + break; + case LOG_ACTION_HAS: + sql += ",'has'"; + sql += ",NULL"; + break; + case LOG_ACTION_WIN: + sql += ",'wins'"; + sql += "," + boost::lexical_cast(amount); + break; + case LOG_ACTION_WIN_SIDE_POT: + sql += ",'wins (side pot)'"; + sql += "," + boost::lexical_cast(amount); + break; + case LOG_ACTION_SIT_OUT: + sql += ",'sits out'"; + sql += ",NULL"; + break; + case LOG_ACTION_WIN_GAME: + sql += ",'wins game'"; + sql += ",NULL"; + break; + case LOG_ACTION_LEFT: + sql += ",'has left the game'"; + sql += ",NULL"; + break; + case LOG_ACTION_KICKED: + sql += ",'was kicked from the game'"; + sql += ",NULL"; + break; + case LOG_ACTION_ADMIN: + sql += ",'is game admin now'"; + sql += ",NULL"; + break; + case LOG_ACTION_JOIN: + sql += ",'has joined the game'"; + sql += ",NULL"; + break; + default: + return; + } + sql += ");"; + if(myConfig->readConfigInt("LogInterval") == 0) { + exec_transaction(); } } } @@ -552,42 +537,40 @@ Log::transformPlayerActionLog(PlayerAction action) void Log::logBoardCards(int boardCards[5]) { - if(SQLITE_LOG) { - if(myConfig->readConfigInt("LogOnOff")) { - //if write logfiles is enabled + if(myConfig->readConfigInt("LogOnOff")) { + //if write logfiles is enabled - if( mySqliteLogDb != 0 ) { - // sqlite-db is open + if( mySqliteLogDb != 0 ) { + // sqlite-db is open - switch(currentRound) { - case GAME_STATE_FLOP: { - sql += "UPDATE Hand SET "; - sql += "BoardCard_1=" + boost::lexical_cast(boardCards[0]) + ","; - sql += "BoardCard_2=" + boost::lexical_cast(boardCards[1]) + ","; - sql += "BoardCard_3=" + boost::lexical_cast(boardCards[2]); - } - break; - case GAME_STATE_TURN: { - sql += "UPDATE Hand SET "; - sql += "BoardCard_4=" + boost::lexical_cast(boardCards[3]); - } - break; - case GAME_STATE_RIVER: { - sql += "UPDATE Hand SET "; - sql += "BoardCard_5=" + boost::lexical_cast(boardCards[4]); - } - break; - default: - return; - } - sql += " WHERE "; - sql += "UniqueGameID=" + boost::lexical_cast(uniqueGameID) + " AND "; - sql += "HandID=" + boost::lexical_cast(currentHandID); - sql += ";"; - if(myConfig->readConfigInt("LogInterval") == 0) { - exec_transaction(); - } + switch(currentRound) { + case GAME_STATE_FLOP: { + sql += "UPDATE Hand SET "; + sql += "BoardCard_1=" + boost::lexical_cast(boardCards[0]) + ","; + sql += "BoardCard_2=" + boost::lexical_cast(boardCards[1]) + ","; + sql += "BoardCard_3=" + boost::lexical_cast(boardCards[2]); + } + break; + case GAME_STATE_TURN: { + sql += "UPDATE Hand SET "; + sql += "BoardCard_4=" + boost::lexical_cast(boardCards[3]); + } + break; + case GAME_STATE_RIVER: { + sql += "UPDATE Hand SET "; + sql += "BoardCard_5=" + boost::lexical_cast(boardCards[4]); + } + break; + default: + return; + } + sql += " WHERE "; + sql += "UniqueGameID=" + boost::lexical_cast(uniqueGameID) + " AND "; + sql += "HandID=" + boost::lexical_cast(currentHandID); + sql += ";"; + if(myConfig->readConfigInt("LogInterval") == 0) { + exec_transaction(); } } } @@ -612,44 +595,41 @@ void Log::logHoleCardsHandName(PlayerList activePlayerList, boost::shared_ptr player, bool forceExecLog) { - if(SQLITE_LOG) { + if(myConfig->readConfigInt("LogOnOff")) { + //if write logfiles is enabled - if(myConfig->readConfigInt("LogOnOff")) { - //if write logfiles is enabled - - if( mySqliteLogDb != 0) { - - int myCards[2]; - player->getMyCards(myCards); - sql += "UPDATE Hand SET "; - if(currentRound==GAME_STATE_POST_RIVER && player->getMyCardsValueInt()>0) { - sql += "Seat_" + boost::lexical_cast(player->getMyID()+1) + "_Hand_text=\"" + CardsValue::determineHandName(player->getMyCardsValueInt(),activePlayerList) + "\""; - sql += ",Seat_" + boost::lexical_cast(player->getMyID()+1) + "_Hand_int=" + boost::lexical_cast(player->getMyCardsValueInt()); - } - if(currentRound==GAME_STATE_POST_RIVER && player->getMyCardsValueInt()>0 && !player->getLogHoleCardsDone()) { - sql+= ","; - } - if(!player->getLogHoleCardsDone()) { - sql += "Seat_" + boost::lexical_cast(player->getMyID()+1) + "_Card_1=" + boost::lexical_cast(myCards[0]); - sql += ",Seat_" + boost::lexical_cast(player->getMyID()+1) + "_Card_2=" + boost::lexical_cast(myCards[1]); - } - sql += " WHERE "; - sql += "UniqueGameID=" + boost::lexical_cast(uniqueGameID) + " AND "; - sql += "HandID=" + boost::lexical_cast(currentHandID); - sql += ";"; - if(myConfig->readConfigInt("LogInterval") == 0 || forceExecLog) { - exec_transaction(); - } - - if(!player->getLogHoleCardsDone()) { - logPlayerAction(player->getMyName(),LOG_ACTION_SHOW); - } else { - logPlayerAction(player->getMyName(),LOG_ACTION_HAS); - } - - player->setLogHoleCardsDone(true); + if( mySqliteLogDb != 0) { + int myCards[2]; + player->getMyHoleCards(myCards); + sql += "UPDATE Hand SET "; + if(currentRound==GAME_STATE_POST_RIVER && player->getMyCardsValueInt()>0) { + sql += "Seat_" + boost::lexical_cast(player->getMyID()+1) + "_Hand_text=\"" + CardsValue::determineHandName(player->getMyCardsValueInt(),activePlayerList) + "\""; + sql += ",Seat_" + boost::lexical_cast(player->getMyID()+1) + "_Hand_int=" + boost::lexical_cast(player->getMyCardsValueInt()); } + if(currentRound==GAME_STATE_POST_RIVER && player->getMyCardsValueInt()>0 && !player->getLogHoleCardsDone()) { + sql+= ","; + } + if(!player->getLogHoleCardsDone()) { + sql += "Seat_" + boost::lexical_cast(player->getMyID()+1) + "_Card_1=" + boost::lexical_cast(myCards[0]); + sql += ",Seat_" + boost::lexical_cast(player->getMyID()+1) + "_Card_2=" + boost::lexical_cast(myCards[1]); + } + sql += " WHERE "; + sql += "UniqueGameID=" + boost::lexical_cast(uniqueGameID) + " AND "; + sql += "HandID=" + boost::lexical_cast(currentHandID); + sql += ";"; + if(myConfig->readConfigInt("LogInterval") == 0 || forceExecLog) { + exec_transaction(); + } + + if(!player->getLogHoleCardsDone()) { + logPlayerAction(player->getMyName(),LOG_ACTION_SHOW); + } else { + logPlayerAction(player->getMyName(),LOG_ACTION_HAS); + } + + player->setLogHoleCardsDone(true); + } } } @@ -752,11 +732,9 @@ Log::exec_transaction() //void //Log::closeLogDbAtExit() //{ -// if(SQLITE_LOG) { -// // close sqlite-db -// sqlite3_close(mySqliteLogDb); -// mySqliteLogDb = NULL; -// } +// // close sqlite-db +// sqlite3_close(mySqliteLogDb); +// mySqliteLogDb = NULL; //} void diff --git a/src/engine/network_engine/clienthand.cpp b/src/engine/network_engine/clienthand.cpp index 5672a8df..ac91c51b 100644 --- a/src/engine/network_engine/clienthand.cpp +++ b/src/engine/network_engine/clienthand.cpp @@ -44,7 +44,7 @@ ClientHand::ClientHand(boost::shared_ptr f, GuiInterface *g, boos for(it=seatsList->begin(); it!=seatsList->end(); ++it) { (*it)->setHand(this); // myFlipCards auf 0 setzen - (*it)->setMyCardsFlip(0, 0); + (*it)->setMyHoleCardsFlip(0, 0); } // roundStartCashArray fuellen diff --git a/src/engine/network_engine/clientplayer.cpp b/src/engine/network_engine/clientplayer.cpp index caee7c30..ac4b706f 100644 --- a/src/engine/network_engine/clientplayer.cpp +++ b/src/engine/network_engine/clientplayer.cpp @@ -38,12 +38,12 @@ using namespace std; ClientPlayer::ClientPlayer(ConfigFile *c, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, bool sotS, int mB) : PlayerInterface(), myConfig(c), currentHand(0), myID(id), myUniqueID(uniqueId), myType(type), myName(name), myAvatar(avatar), myDude(0), myDude4(0), myCardsValueInt(0), myOdds(-1.0), logHoleCardsDone(false), myCash(sC), mySet(0), myLastRelativeSet(0), - myAction(PLAYER_ACTION_NONE), myButton(mB), myActiveStatus(aS), myStayOnTableStatus(sotS), myTurn(false), myCardsFlip(false), myRoundStartCash(0), + myAction(PLAYER_ACTION_NONE), myButton(mB), myActiveStatus(aS), myStayOnTableStatus(sotS), myTurn(false), myHoleCardsFlip(false), myRoundStartCash(0), lastMoneyWon(0), sBluff(0), sBluffStatus(false), m_isSessionActive(false), m_isKicked(false), m_isMuted(false) { myBestHandPosition[0] = myBestHandPosition[1] = myBestHandPosition[2] = myBestHandPosition[3] = myBestHandPosition[4] = 0; myNiveau[0] = myNiveau[1] = myNiveau[2] = 0; - myCards[0] = myCards[1] = 0; + myHoleCards[0] = myHoleCards[1] = 0; myAverageSets[0] = myAverageSets[1] = myAverageSets[2] = myAverageSets[3] = 0; myAggressive[0] = myAggressive[1] = myAggressive[2] = myAggressive[3] = myAggressive[4] = myAggressive[5] = myAggressive[6] = false; } @@ -264,19 +264,19 @@ ClientPlayer::getMyStayOnTableStatus() const } void -ClientPlayer::setMyCards(int* theValue) +ClientPlayer::setMyHoleCards(int* theValue) { boost::recursive_mutex::scoped_lock lock(m_syncMutex); for (int i = 0; i < 2; i++) - myCards[i] = theValue[i]; + myHoleCards[i] = theValue[i]; } void -ClientPlayer::getMyCards(int* theValue) const +ClientPlayer::getMyHoleCards(int* theValue) const { boost::recursive_mutex::scoped_lock lock(m_syncMutex); for (int i = 0; i < 2; i++) - theValue[i] = myCards[i]; + theValue[i] = myHoleCards[i]; } void @@ -294,21 +294,21 @@ ClientPlayer::getMyTurn() const } void -ClientPlayer::setMyCardsFlip(bool theValue, int state) +ClientPlayer::setMyHoleCardsFlip(bool theValue, int state) { boost::recursive_mutex::scoped_lock lock(m_syncMutex); - myCardsFlip = theValue; + myHoleCardsFlip = theValue; // log flipping cards - if (myCardsFlip) { + if (myHoleCardsFlip) { switch(state) { case 1: - currentHand->getGuiInterface()->logFlipHoleCardsMsg(myName, myCards[0], myCards[1], myCardsValueInt); + currentHand->getGuiInterface()->logFlipHoleCardsMsg(myName, myHoleCards[0], myHoleCards[1], myCardsValueInt); break; case 2: - currentHand->getGuiInterface()->logFlipHoleCardsMsg(myName, myCards[0], myCards[1]); + currentHand->getGuiInterface()->logFlipHoleCardsMsg(myName, myHoleCards[0], myHoleCards[1]); break; case 3: - currentHand->getGuiInterface()->logFlipHoleCardsMsg(myName, myCards[0], myCards[1], myCardsValueInt, "has"); + currentHand->getGuiInterface()->logFlipHoleCardsMsg(myName, myHoleCards[0], myHoleCards[1], myCardsValueInt, "has"); break; default: ; @@ -317,10 +317,10 @@ ClientPlayer::setMyCardsFlip(bool theValue, int state) } bool -ClientPlayer::getMyCardsFlip() const +ClientPlayer::getMyHoleCardsFlip() const { boost::recursive_mutex::scoped_lock lock(m_syncMutex); - return myCardsFlip; + return myHoleCardsFlip; } void diff --git a/src/engine/network_engine/clientplayer.h b/src/engine/network_engine/clientplayer.h index a4b9c40f..a3535e18 100644 --- a/src/engine/network_engine/clientplayer.h +++ b/src/engine/network_engine/clientplayer.h @@ -89,14 +89,14 @@ public: void setMyStayOnTableStatus(bool theValue); bool getMyStayOnTableStatus() const; - void setMyCards(int* theValue); - void getMyCards(int* theValue) const; + void setMyHoleCards(int* theValue); + void getMyHoleCards(int* theValue) const; void setMyTurn(bool theValue); bool getMyTurn() const; - void setMyCardsFlip(bool theValue, int state); - bool getMyCardsFlip() const; + void setMyHoleCardsFlip(bool theValue, int state); + bool getMyHoleCardsFlip() const; void setMyCardsValueInt(int theValue); int getMyCardsValueInt() const; @@ -184,7 +184,7 @@ private: int myNiveau[3]; bool logHoleCardsDone; - int myCards[2]; + int myHoleCards[2]; int myCash; int mySet; int myLastRelativeSet; @@ -193,7 +193,7 @@ private: bool myActiveStatus; // 0 = inactive, 1 = active bool myStayOnTableStatus; // 0 = left, 1 = stay bool myTurn; // 0 = no, 1 = yes - bool myCardsFlip; // 0 = cards are not fliped, 1 = cards are already flipped, + bool myHoleCardsFlip; // 0 = cards are not fliped, 1 = cards are already flipped, int myRoundStartCash; int lastMoneyWon; diff --git a/src/engine/playerinterface.h b/src/engine/playerinterface.h index 19a7ab93..96291fff 100644 --- a/src/engine/playerinterface.h +++ b/src/engine/playerinterface.h @@ -87,14 +87,14 @@ public: virtual void setMyStayOnTableStatus(bool theValue) =0; virtual bool getMyStayOnTableStatus() const =0; - virtual void setMyCards(int* theValue) =0; - virtual void getMyCards(int* theValue) const =0; + virtual void setMyHoleCards(int* theValue) =0; + virtual void getMyHoleCards(int* theValue) const =0; virtual void setMyTurn(bool theValue) =0; virtual bool getMyTurn() const =0; - virtual void setMyCardsFlip(bool theValue, int state) =0; - virtual bool getMyCardsFlip() const =0; + virtual void setMyHoleCardsFlip(bool theValue, int state) =0; + virtual bool getMyHoleCardsFlip() const =0; virtual void setMyCardsValueInt(int theValue) =0; virtual int getMyCardsValueInt() const =0; diff --git a/src/game_defs.h b/src/game_defs.h index 7d8679f7..157388a1 100644 --- a/src/game_defs.h +++ b/src/game_defs.h @@ -37,9 +37,6 @@ #define MIN_GUI_SPEED 1 #define MAX_GUI_SPEED 11 -#define SQLITE_LOG 1 -#define HTML_LOG 0 - #define POKERTH_VERSION_MAJOR 1 #define POKERTH_VERSION_MINOR 11 #define POKERTH_VERSION ((POKERTH_VERSION_MAJOR << 8) | POKERTH_VERSION_MINOR) diff --git a/src/gui/generic/serverguiwrapper.cpp b/src/gui/generic/serverguiwrapper.cpp index 27813677..e5b2862e 100644 --- a/src/gui/generic/serverguiwrapper.cpp +++ b/src/gui/generic/serverguiwrapper.cpp @@ -105,8 +105,6 @@ void ServerGuiWrapper::logNewBlindsSetsMsg(int /*sbSet*/, int /*bbSet*/, std::st void ServerGuiWrapper::logDealBoardCardsMsg(int /*roundID*/, int /*card1*/, int /*card2*/, int /*card3*/, int /*card4*/, int /*card5*/) {} void ServerGuiWrapper::logFlipHoleCardsMsg(std::string /*playerName*/, int /*card1*/, int /*card2*/, int /*cardsValueInt*/, std::string /*showHas*/) {} void ServerGuiWrapper::logPlayerWinGame(std::string /*playerName*/, int /*gameID*/) {} -void ServerGuiWrapper::flushLogAtGame(int /*gameID*/) {} -void ServerGuiWrapper::flushLogAtHand() {} void ServerGuiWrapper::SignalNetClientServerListAdd(unsigned serverId) { diff --git a/src/gui/generic/serverguiwrapper.h b/src/gui/generic/serverguiwrapper.h index 2986c074..40f7ccea 100644 --- a/src/gui/generic/serverguiwrapper.h +++ b/src/gui/generic/serverguiwrapper.h @@ -118,8 +118,6 @@ public: void logDealBoardCardsMsg(int roundID, int card1, int card2, int card3, int card4 = -1, int card5 = -1) ; void logFlipHoleCardsMsg(std::string playerName, int card1, int card2, int cardsValueInt = -1, std::string showHas = "shows") ; void logPlayerWinGame(std::string playerName, int gameID); - void flushLogAtGame(int gameID); - void flushLogAtHand(); void SignalNetClientConnect(int actionID); void SignalNetClientGameInfo(int actionID); diff --git a/src/gui/guiinterface.h b/src/gui/guiinterface.h index 656e5b48..701ad83b 100644 --- a/src/gui/guiinterface.h +++ b/src/gui/guiinterface.h @@ -119,8 +119,6 @@ public: virtual void logDealBoardCardsMsg(int roundID, int card1, int card2, int card3, int card4 = -1, int card5 = -1) = 0; virtual void logFlipHoleCardsMsg(std::string playerName, int card1, int card2, int cardsValueInt = -1, std::string showHas = "shows") = 0; virtual void logPlayerWinGame(std::string playerName, int gameID) =0; - virtual void flushLogAtGame(int gameID) =0; - virtual void flushLogAtHand() =0; }; diff --git a/src/gui/qt/gametable/gametableimpl.cpp b/src/gui/qt/gametable/gametableimpl.cpp index 3b2c7e56..1d543fe4 100755 --- a/src/gui/qt/gametable/gametableimpl.cpp +++ b/src/gui/qt/gametable/gametableimpl.cpp @@ -834,7 +834,7 @@ void gameTableImpl::applySettings(settingsDialogImpl* mySettingsDialog) QPixmap tempCardsPixmapArray[2]; int tempCardsIntArray[2]; - humanPlayer->getMyCards(tempCardsIntArray); + humanPlayer->getMyHoleCards(tempCardsIntArray); if(myConfig->readConfigInt("AntiPeekMode")) { holeCardsArray[0][0]->setPixmap(flipside, true); tempCardsPixmapArray[0] = QPixmap::fromImage(QImage(myCardDeckStyle->getCurrentDir()+QString::number(tempCardsIntArray[0], 10)+".png")); @@ -1440,7 +1440,7 @@ void gameTableImpl::dealHoleCards() PlayerListConstIterator it_c; PlayerList seatsList = currentGame->getSeatsList(); for (it_c=seatsList->begin(); it_c!=seatsList->end(); ++it_c) { - (*it_c)->getMyCards(tempCardsIntArray); + (*it_c)->getMyHoleCards(tempCardsIntArray); for(j=0; j<2; j++) { if((*it_c)->getMyActiveStatus()) { if (( (*it_c)->getMyID() == 0) || (currentGame->getCurrentHand()->getLog() && currentGame->getCurrentHand()->getLog()->getDebugMode()) ) { @@ -2550,7 +2550,7 @@ void gameTableImpl::postRiverRunAnimation2() for (it_c=activePlayerList->begin(); it_c!=activePlayerList->end(); ++it_c) { if((*it_c)->getMyAction() != PLAYER_ACTION_FOLD) { //set Player value (logging) for all in already shown cards - (*it_c)->setMyCardsFlip(1,3); + (*it_c)->setMyHoleCardsFlip(1,3); } } } @@ -2843,7 +2843,7 @@ void gameTableImpl::showHoleCards(unsigned playerId, bool allIn) if((*it_c)->getMyUniqueID() == playerId) { - (*it_c)->getMyCards(tempCardsIntArray); + (*it_c)->getMyHoleCards(tempCardsIntArray); for(j=0; j<2; j++) { if(showFlipcardAnimation) { // with Eye-Candy @@ -2855,9 +2855,9 @@ void gameTableImpl::showHoleCards(unsigned playerId, bool allIn) } //set Player value (logging) if(currentHand->getCurrentRound() < GAME_STATE_RIVER || allIn) { - (*it_c)->setMyCardsFlip(1,2); //for bero before postriver or allin just log the hole cards + (*it_c)->setMyHoleCardsFlip(1,2); //for bero before postriver or allin just log the hole cards } else { - (*it_c)->setMyCardsFlip(1,1); //for postriver log the value + (*it_c)->setMyHoleCardsFlip(1,1); //for postriver log the value } } } @@ -4013,7 +4013,7 @@ void gameTableImpl::refreshCardsChance(GameState bero) int boardCards[5]; int holeCards[2]; - humanPlayer->getMyCards(holeCards); + humanPlayer->getMyHoleCards(holeCards); myStartWindow->getSession()->getCurrentGame()->getCurrentHand()->getBoard()->getMyCards(boardCards); if(humanPlayer->getMyAction() == PLAYER_ACTION_FOLD) { diff --git a/src/gui/qt/gametable/log/guilog.cpp b/src/gui/qt/gametable/log/guilog.cpp index b76f9a6d..a866bef8 100644 --- a/src/gui/qt/gametable/log/guilog.cpp +++ b/src/gui/qt/gametable/log/guilog.cpp @@ -61,9 +61,6 @@ guiLog::guiLog(gameTableImpl* w, ConfigFile *c) : myW(w), myConfig(c), myLogDir( connect(this, SIGNAL(signalLogSpectatorLeftMsg(QString, int)), this, SLOT(logSpectatorLeftMsg(QString, int))); connect(this, SIGNAL(signalLogSpectatorJoinedMsg(QString)), this, SLOT(logSpectatorJoinedMsg(QString))); connect(this, SIGNAL(signalLogPlayerWinGame(QString, int)), this, SLOT(logPlayerWinGame(QString, int))); - connect(this, SIGNAL(signalFlushLogAtGame(int)), this, SLOT(flushLogAtGame(int))); - connect(this, SIGNAL(signalFlushLogAtHand()), this, SLOT(flushLogAtHand())); - logFileStreamString = ""; lastGameID = 0; @@ -79,40 +76,7 @@ guiLog::guiLog(gameTableImpl* w, ConfigFile *c) : myW(w), myConfig(c), myLogDir( myLogDir = new QDir(QString::fromUtf8(myConfig->readConfigString("LogDir").c_str())); - if(HTML_LOG) { - - QDateTime currentTime = QDateTime::currentDateTime(); - if(SQLITE_LOG) { - myHtmlLogFile_old = new QFile(myLogDir->absolutePath()+"/pokerth-log-"+currentTime.toString("yyyy-MM-dd_hh.mm.ss")+"_old.html"); - } else { - myHtmlLogFile_old = new QFile(myLogDir->absolutePath()+"/pokerth-log-"+currentTime.toString("yyyy-MM-dd_hh.mm.ss")+".html"); - } - - //Logo-Pixmap extrahieren - QPixmap logoChipPixmapFile(":/gfx/logoChip3D.png"); - logoChipPixmapFile.save(myLogDir->absolutePath()+"/logo.png"); - -// myW->textBrowser_Log->append(myHtmlLogFile_old->fileName()); - - // erstelle html-Datei - myHtmlLogFile_old->open( QIODevice::WriteOnly ); - QTextStream stream_old( myHtmlLogFile_old ); - stream_old << "\n"; - stream_old << "\n"; - stream_old << ""; - stream_old << "\n"; -#ifdef GUI_800x480 - stream_old << "\n"; -#else - stream_old << "\n"; -#endif - stream_old << "\n"; - stream_old << QString("

Log-File for PokerTH %1 Session started on ").arg(POKERTH_BETA_RELEASE_STRING)+QDate::currentDate().toString("yyyy-MM-dd")+" at "+QTime::currentTime().toString("hh:mm:ss")+"

\n"; - myHtmlLogFile_old->close(); - - } - - // delete old log files + // delete old log files - TODO: move to Log int daysUntilWaste = myConfig->readConfigInt("LogStoreDuration"); QStringList filters("pokerth-log*"); @@ -191,62 +155,19 @@ void guiLog::logPlayerActionMsg(QString msg, int action, int setValue) myW->textBrowser_Log->append("getChatLogTextColor()+";\">"+msg+""); #endif - - if(HTML_LOG) { - - if(myConfig->readConfigInt("LogOnOff")) { - //if write logfiles is enabled - - logFileStreamString += msg+"
\n"; - - if(myConfig->readConfigInt("LogInterval") == 0) { - writeLogFileStream(logFileStreamString); - logFileStreamString = ""; - } - - } - - } } void guiLog::logNewGameHandMsg(int gameID, int handID) { - - PlayerListConstIterator it_c; - boost::shared_ptr currentHand = myW->getSession()->getCurrentGame()->getCurrentHand(); - - PlayerList activePlayerList = currentHand->getActivePlayerList(); - #ifdef GUI_800x480 myW->tabs.textBrowser_Log->append("getChatLogTextColor()+"; font-size:large; font-weight:bold\">## Game: "+QString::number(gameID,10)+" | Hand: "+QString::number(handID,10)+" ##"); #else myW->textBrowser_Log->append("getChatLogTextColor()+"; font-size:large; font-weight:bold\">## Game: "+QString::number(gameID,10)+" | Hand: "+QString::number(handID,10)+" ##"); #endif - - if(HTML_LOG) { - - if(myConfig->readConfigInt("LogOnOff")) { - //if write logfiles is enabled - - logFileStreamString += "

Game: "+QString::number(gameID,10)+" | Hand: "+QString::number(handID,10)+"
"; - logFileStreamString += "BLIND LEVEL: $"+QString::number(currentHand->getSmallBlind())+" / $"+QString::number(currentHand->getSmallBlind()*2)+"
"; - - //print cash only for active players - for(it_c=activePlayerList->begin(); it_c!=activePlayerList->end(); ++it_c) { - - logFileStreamString += "Seat " + QString::number((*it_c)->getMyID()+1,10) + ": " + QString::fromUtf8((*it_c)->getMyName().c_str()) + " ($" + QString::number((*it_c)->getMyCash()+(*it_c)->getMySet(),10)+")
"; - - } - - } - - } - } void guiLog::logNewBlindsSetsMsg(int sbSet, int bbSet, QString sbName, QString bbName) { - // log blinds #ifdef GUI_800x480 myW->tabs.textBrowser_Log->append("getChatLogTextColor()+";\">"+sbName+" posts small blind ($"+QString::number(sbSet,10)+")"); @@ -255,45 +176,6 @@ void guiLog::logNewBlindsSetsMsg(int sbSet, int bbSet, QString sbName, QString b myW->textBrowser_Log->append("getChatLogTextColor()+";\">"+sbName+" posts small blind ($"+QString::number(sbSet,10)+")"); myW->textBrowser_Log->append("getChatLogTextColor()+";\">"+bbName+" posts big blind ($"+QString::number(bbSet,10)+")"); #endif - - if(HTML_LOG) { - - if(myConfig->readConfigInt("LogOnOff")) { - //if write logfiles is enabled - - logFileStreamString += "BLINDS: "; - - logFileStreamString += sbName+" ($"+QString::number(sbSet,10)+"), "; - logFileStreamString += bbName+" ($"+QString::number(bbSet,10)+")"; - - PlayerListConstIterator it_c; - boost::shared_ptr currentGame = myW->getSession()->getCurrentGame(); - PlayerList activePlayerList = currentGame->getActivePlayerList(); - - for(it_c=activePlayerList->begin(); it_c!=activePlayerList->end(); ++it_c) { - - if(activePlayerList->size() > 2) { - if((*it_c)->getMyButton() == BUTTON_DEALER) { - - logFileStreamString += "
" + QString::fromUtf8((*it_c)->getMyName().c_str()) + " starts as dealer."; - break; - } - } else { - if((*it_c)->getMyButton() == BUTTON_SMALL_BLIND) { - - logFileStreamString += "
" + QString::fromUtf8((*it_c)->getMyName().c_str()) + " starts as dealer."; - break; - } - } - } - - logFileStreamString += "

PREFLOP"; - logFileStreamString += "
\n"; - - } - - } - } void guiLog::logPlayerWinsMsg(QString playerName, int pot, bool main) @@ -312,116 +194,43 @@ void guiLog::logPlayerWinsMsg(QString playerName, int pot, bool main) myW->textBrowser_Log->append("getLogWinnerSidePotColor()+";\">"+playerName+" wins $"+QString::number(pot,10)+" (side pot)"); } #endif - - if(HTML_LOG) { - - if(myConfig->readConfigInt("LogOnOff")) { - //if write logfiles is enabled - - logFileStreamString += "
"+playerName+" wins $"+QString::number(pot,10); - if(!main) { - logFileStreamString += " (side pot)"; - } - logFileStreamString += "\n"; - - if(myConfig->readConfigInt("LogInterval") == 0) { - writeLogFileStream(logFileStreamString); - logFileStreamString = ""; - } - } - - } } void guiLog::logPlayerSitsOut(QString playerName) { - #ifdef GUI_800x480 myW->tabs.textBrowser_Log->append("getLogPlayerSitsOutColor()+";\">"+playerName+" sits out"); #else myW->textBrowser_Log->append("getLogPlayerSitsOutColor()+";\">"+playerName+" sits out"); #endif - - if(HTML_LOG) { - - if(myConfig->readConfigInt("LogOnOff")) { - - logFileStreamString += "
"+playerName+" sits out\n"; - - if(myConfig->readConfigInt("LogInterval") == 0) { - writeLogFileStream(logFileStreamString); - logFileStreamString = ""; - } - } - - } } void guiLog::logDealBoardCardsMsg(int roundID, int card1, int card2, int card3, int card4, int card5) { - - QString round; - switch (roundID) { - case 1: - round = "Flop"; #ifdef GUI_800x480 - myW->tabs.textBrowser_Log->append("getLogPlayerSitsOutColor()+";\">--- "+round+" --- "+"["+translateCardCode(card1).at(0)+translateCardCode(card1).at(1)+","+translateCardCode(card2).at(0)+translateCardCode(card2).at(1)+","+translateCardCode(card3).at(0)+translateCardCode(card3).at(1)+"]"); + myW->tabs.textBrowser_Log->append("getLogPlayerSitsOutColor()+";\">--- Flop --- "+"["+translateCardCode(card1).at(0)+translateCardCode(card1).at(1)+","+translateCardCode(card2).at(0)+translateCardCode(card2).at(1)+","+translateCardCode(card3).at(0)+translateCardCode(card3).at(1)+"]"); #else - myW->textBrowser_Log->append("getLogPlayerSitsOutColor()+";\">--- "+round+" --- "+"["+translateCardCode(card1).at(0)+translateCardCode(card1).at(1)+","+translateCardCode(card2).at(0)+translateCardCode(card2).at(1)+","+translateCardCode(card3).at(0)+translateCardCode(card3).at(1)+"]"); + myW->textBrowser_Log->append("getLogPlayerSitsOutColor()+";\">--- Flop --- "+"["+translateCardCode(card1).at(0)+translateCardCode(card1).at(1)+","+translateCardCode(card2).at(0)+translateCardCode(card2).at(1)+","+translateCardCode(card3).at(0)+translateCardCode(card3).at(1)+"]"); #endif break; case 2: - round = "Turn"; #ifdef GUI_800x480 - myW->tabs.textBrowser_Log->append("getLogPlayerSitsOutColor()+";\">--- "+round+" --- "+"["+translateCardCode(card1).at(0)+translateCardCode(card1).at(1)+","+translateCardCode(card2).at(0)+translateCardCode(card2).at(1)+","+translateCardCode(card3).at(0)+translateCardCode(card3).at(1)+","+translateCardCode(card4).at(0)+translateCardCode(card4).at(1)+"]"); + myW->tabs.textBrowser_Log->append("getLogPlayerSitsOutColor()+";\">--- Turn --- "+"["+translateCardCode(card1).at(0)+translateCardCode(card1).at(1)+","+translateCardCode(card2).at(0)+translateCardCode(card2).at(1)+","+translateCardCode(card3).at(0)+translateCardCode(card3).at(1)+","+translateCardCode(card4).at(0)+translateCardCode(card4).at(1)+"]"); #else - myW->textBrowser_Log->append("getLogPlayerSitsOutColor()+";\">--- "+round+" --- "+"["+translateCardCode(card1).at(0)+translateCardCode(card1).at(1)+","+translateCardCode(card2).at(0)+translateCardCode(card2).at(1)+","+translateCardCode(card3).at(0)+translateCardCode(card3).at(1)+","+translateCardCode(card4).at(0)+translateCardCode(card4).at(1)+"]"); + myW->textBrowser_Log->append("getLogPlayerSitsOutColor()+";\">--- Turn --- "+"["+translateCardCode(card1).at(0)+translateCardCode(card1).at(1)+","+translateCardCode(card2).at(0)+translateCardCode(card2).at(1)+","+translateCardCode(card3).at(0)+translateCardCode(card3).at(1)+","+translateCardCode(card4).at(0)+translateCardCode(card4).at(1)+"]"); #endif break; case 3: - round = "River"; #ifdef GUI_800x480 - myW->tabs.textBrowser_Log->append("getLogPlayerSitsOutColor()+";\">--- "+round+" --- "+"["+translateCardCode(card1).at(0)+translateCardCode(card1).at(1)+","+translateCardCode(card2).at(0)+translateCardCode(card2).at(1)+","+translateCardCode(card3).at(0)+translateCardCode(card3).at(1)+","+translateCardCode(card4).at(0)+translateCardCode(card4).at(1)+","+translateCardCode(card5).at(0)+translateCardCode(card5).at(1)+"]"); + myW->tabs.textBrowser_Log->append("getLogPlayerSitsOutColor()+";\">--- River --- "+"["+translateCardCode(card1).at(0)+translateCardCode(card1).at(1)+","+translateCardCode(card2).at(0)+translateCardCode(card2).at(1)+","+translateCardCode(card3).at(0)+translateCardCode(card3).at(1)+","+translateCardCode(card4).at(0)+translateCardCode(card4).at(1)+","+translateCardCode(card5).at(0)+translateCardCode(card5).at(1)+"]"); #else - myW->textBrowser_Log->append("getLogPlayerSitsOutColor()+";\">--- "+round+" --- "+"["+translateCardCode(card1).at(0)+translateCardCode(card1).at(1)+","+translateCardCode(card2).at(0)+translateCardCode(card2).at(1)+","+translateCardCode(card3).at(0)+translateCardCode(card3).at(1)+","+translateCardCode(card4).at(0)+translateCardCode(card4).at(1)+","+translateCardCode(card5).at(0)+translateCardCode(card5).at(1)+"]"); + myW->textBrowser_Log->append("getLogPlayerSitsOutColor()+";\">--- River --- "+"["+translateCardCode(card1).at(0)+translateCardCode(card1).at(1)+","+translateCardCode(card2).at(0)+translateCardCode(card2).at(1)+","+translateCardCode(card3).at(0)+translateCardCode(card3).at(1)+","+translateCardCode(card4).at(0)+translateCardCode(card4).at(1)+","+translateCardCode(card5).at(0)+translateCardCode(card5).at(1)+"]"); #endif break; default: - round = "ERROR"; - } - - if(HTML_LOG) { - - if(myConfig->readConfigInt("LogOnOff")) { - //if write logfiles is enabled - - switch (roundID) { - - case 1: - round = "Flop"; - logFileStreamString += "
"+round.toUpper()+" [board cards "+translateCardCode(card1).at(0)+""+translateCardCode(card1).at(1)+","+translateCardCode(card2).at(0)+""+translateCardCode(card2).at(1)+","+translateCardCode(card3).at(0)+""+translateCardCode(card3).at(1)+"]"+"
\n"; - break; - case 2: - round = "Turn"; - logFileStreamString += "
"+round.toUpper()+" [board cards "+translateCardCode(card1).at(0)+""+translateCardCode(card1).at(1)+","+translateCardCode(card2).at(0)+""+translateCardCode(card2).at(1)+","+translateCardCode(card3).at(0)+""+translateCardCode(card3).at(1)+","+translateCardCode(card4).at(0)+""+translateCardCode(card4).at(1)+"]"+"
\n"; - break; - case 3: - round = "River"; - logFileStreamString += "
"+round.toUpper()+" [board cards "+translateCardCode(card1).at(0)+""+translateCardCode(card1).at(1)+","+translateCardCode(card2).at(0)+""+translateCardCode(card2).at(1)+","+translateCardCode(card3).at(0)+""+translateCardCode(card3).at(1)+","+translateCardCode(card4).at(0)+""+translateCardCode(card4).at(1)+","+translateCardCode(card5).at(0)+""+translateCardCode(card5).at(1)+"]"+"
\n"; - break; - default: - round = "ERROR"; - } - - if(myConfig->readConfigInt("LogInterval") == 0) { - writeLogFileStream(logFileStreamString); - logFileStreamString = ""; - } - - } - + break; } } @@ -447,40 +256,10 @@ void guiLog::logFlipHoleCardsMsg(QString playerName, int card1, int card2, int c myW->textBrowser_Log->append("getChatLogTextColor()+";\">"+playerName+" "+showHas+" ["+translateCardCode(card1).at(0)+translateCardCode(card1).at(1)+","+translateCardCode(card2).at(0)+translateCardCode(card2).at(1)+"]"); #endif } - - if(HTML_LOG) { - - if(myConfig->readConfigInt("LogOnOff")) { - //if write logfiles is enabled - - if (cardsValueInt != -1) { - - tempHandName.fromStdString(CardsValue::determineHandName(cardsValueInt,myW->getSession()->getCurrentGame()->getActivePlayerList())); - - logFileStreamString += playerName+" "+showHas+" [ "+translateCardCode(card1).at(0)+""+translateCardCode(card1).at(1)+","+translateCardCode(card2).at(0)+""+translateCardCode(card2).at(1)+"] - "+tempHandName+"
\n"; - - if(myConfig->readConfigInt("LogInterval") == 0) { - writeLogFileStream(logFileStreamString); - logFileStreamString = ""; - } - - } else { - - logFileStreamString += playerName+" "+showHas+" ["+translateCardCode(card1).at(0)+""+translateCardCode(card1).at(1)+","+translateCardCode(card2).at(0)+""+translateCardCode(card2).at(1)+"]"+"
\n"; - if(myConfig->readConfigInt("LogInterval") == 0) { - writeLogFileStream(logFileStreamString); - logFileStreamString = ""; - } - } - } - - } - } void guiLog::logPlayerLeftMsg(QString playerName, int wasKicked) { - QString action; if(wasKicked) action = "was kicked from"; else action = "has left"; @@ -490,44 +269,15 @@ void guiLog::logPlayerLeftMsg(QString playerName, int wasKicked) #else myW->textBrowser_Log->append( "getChatLogTextColor()+";\">"+playerName+" "+action+" the game!"); #endif - - if(HTML_LOG) { - - if(myConfig->readConfigInt("LogOnOff")) { - - logFileStreamString += ""+playerName+" "+action+" the game!
\n"; - - if(myConfig->readConfigInt("LogInterval") == 0) { - writeLogFileStream(logFileStreamString); - logFileStreamString = ""; - } - } - - } } void guiLog::logNewGameAdminMsg(QString playerName) { - #ifdef GUI_800x480 myW->tabs.textBrowser_Log->append( "getLogNewGameAdminColor()+";\">"+playerName+" is game admin now!"); #else myW->textBrowser_Log->append( "getLogNewGameAdminColor()+";\">"+playerName+" is game admin now!"); #endif - - if(HTML_LOG) { - - if(myConfig->readConfigInt("LogOnOff")) { - - logFileStreamString += ""+playerName+" is game admin now!
\n"; - - if(myConfig->readConfigInt("LogInterval") == 0) { - writeLogFileStream(logFileStreamString); - logFileStreamString = ""; - } - } - - } } void guiLog::logPlayerJoinedMsg(QString playerName) @@ -551,27 +301,11 @@ void guiLog::logSpectatorJoinedMsg(QString playerName) void guiLog::logPlayerWinGame(QString playerName, int gameID) { - #ifdef GUI_800x480 myW->tabs.textBrowser_Log->append( ""+playerName+" wins game " + QString::number(gameID,10) +"!
"); #else myW->textBrowser_Log->append( ""+playerName+" wins game " + QString::number(gameID,10) +"!
"); #endif - - if(HTML_LOG) { - - if(myConfig->readConfigInt("LogOnOff")) { - - logFileStreamString += "

"+playerName+" wins game " + QString::number(gameID,10) +"!
\n"; - - if(myConfig->readConfigInt("LogInterval") == 0) { - writeLogFileStream(logFileStreamString); - logFileStreamString = ""; - } - } - - } - } QStringList guiLog::translateCardCode(int cardCode) @@ -693,39 +427,6 @@ void guiLog::writeLog(string log_string, int modus) } -void guiLog::flushLogAtHand() -{ - - if(HTML_LOG) { - - if(myConfig->readConfigInt("LogOnOff")) { - if(myConfig->readConfigInt("LogInterval") < 2) { - // write for log after every action and after every hand - writeLogFileStream(logFileStreamString); - logFileStreamString = ""; - } - } - - } -} - -void guiLog::flushLogAtGame(int gameID) -{ - - if(HTML_LOG) { - - if(myConfig->readConfigInt("LogOnOff")) { - // write for log after every game - if(gameID > lastGameID) { - writeLogFileStream(logFileStreamString); - logFileStreamString = ""; - lastGameID = gameID; - } - } - - } -} - void guiLog::exportLogPdbToHtml(QString fileStringPdb, QString exportFileString) { @@ -769,7 +470,7 @@ void guiLog::showLog(QString fileStringPdb, QTextBrowser *tb_tmp, int uniqueGame int guiLog::exportLog(QString fileStringPdb,int modus,int uniqueGameID_req) { - bool neu = false; + bool neu = true; result_struct results; results.result_Session = 0; diff --git a/src/gui/qt/gametable/log/guilog.h b/src/gui/qt/gametable/log/guilog.h index 1202751e..1fa2ea9f 100644 --- a/src/gui/qt/gametable/log/guilog.h +++ b/src/gui/qt/gametable/log/guilog.h @@ -81,8 +81,6 @@ public slots: void logSpectatorLeftMsg(QString playerName, int wasKicked); void logSpectatorJoinedMsg(QString playerName); void logPlayerWinGame(QString playerName, int gameID); - void flushLogAtGame(int gameID); - void flushLogAtHand(); void exportLogPdbToHtml(QString fileStringPdb, QString exportFileString); void exportLogPdbToTxt(QString fileStringPdb, QString exportFileString); void showLog(QString fileStringPdb, QTextBrowser *tb, int uniqueGameID = 0); @@ -115,8 +113,6 @@ signals: void signalLogSpectatorJoinedMsg(QString playerName); void signalLogNewGameAdminMsg(QString playerName); void signalLogPlayerWinGame(QString playerName, int gameID); - void signalFlushLogAtGame(int gameID); - void signalFlushLogAtHand(); private: diff --git a/src/gui/qt/guiwrapper.cpp b/src/gui/qt/guiwrapper.cpp index cd0a1f74..aa12deec 100644 --- a/src/gui/qt/guiwrapper.cpp +++ b/src/gui/qt/guiwrapper.cpp @@ -287,14 +287,6 @@ void GuiWrapper::logPlayerWinGame(std::string playerName, int gameID) { myGuiLog->signalLogPlayerWinGame(QString::fromUtf8(playerName.c_str()), gameID); } -void GuiWrapper::flushLogAtGame(int gameID) -{ - myGuiLog->signalFlushLogAtGame(gameID); -} -void GuiWrapper::flushLogAtHand() -{ - myGuiLog->signalFlushLogAtHand(); -} void GuiWrapper::SignalNetClientConnect(int actionID) diff --git a/src/gui/qt/guiwrapper.h b/src/gui/qt/guiwrapper.h index a3548f39..702ebcb2 100644 --- a/src/gui/qt/guiwrapper.h +++ b/src/gui/qt/guiwrapper.h @@ -124,8 +124,6 @@ public: void logDealBoardCardsMsg(int roundID, int card1, int card2, int card3, int card4 = -1, int card5 = -1); void logFlipHoleCardsMsg(std::string playerName, int card1, int card2, int cardsValueInt = -1, std::string showHas = "shows"); void logPlayerWinGame(std::string playerName, int gameID); - void flushLogAtGame(int gameID); - void flushLogAtHand(); void SignalNetClientConnect(int actionID); void SignalNetClientServerListAdd(unsigned serverId); diff --git a/src/gui/qt/startwindow/startwindowimpl.cpp b/src/gui/qt/startwindow/startwindowimpl.cpp index 0a7fba58..a0de40db 100644 --- a/src/gui/qt/startwindow/startwindowimpl.cpp +++ b/src/gui/qt/startwindow/startwindowimpl.cpp @@ -771,12 +771,24 @@ void startWindowImpl::networkError(int errorID, int /*osErrorID*/) QMessageBox::Close); } break; + case ERR_SOCK_CONNECT_IPV6_FAILED: { + MyMessageBox::warning(this, tr("Network Error"), + tr("Could not connect to the server.\n\nPlease note: IPv6 is enabled in the settings. The connection fails if your provider does not support IPv6.\nThis may be fixed by unchecking the \"Use IPv6\" checkbox in the settings."), + QMessageBox::Close); + } + break; case ERR_SOCK_CONNECT_TIMEOUT: { MyMessageBox::warning(this, tr("Network Error"), tr("Connection timed out.\nPlease check the server address.\n\nIf the server is behind a NAT-Router, make sure port forwarding has been set up on server side."), QMessageBox::Close); } break; + case ERR_SOCK_CONNECT_IPV6_TIMEOUT: { + MyMessageBox::warning(this, tr("Network Error"), + tr("Connection timed out.\nPlease check the server address.\n\nPlease note: IPv6 is enabled in the settings. The connection fails if your provider does not support IPv6.\nThis may be fixed by unchecking the \"Use IPv6\" checkbox in the settings."), + QMessageBox::Close); + } + break; case ERR_SOCK_SELECT_FAILED: { MyMessageBox::warning(this, tr("Network Error"), tr("Internal network error: \"select\" failed."), diff --git a/src/net/clientthread.h b/src/net/clientthread.h index 03f5fd96..55ec12a9 100644 --- a/src/net/clientthread.h +++ b/src/net/clientthread.h @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -218,7 +219,7 @@ protected: ClientState &GetState(); void SetState(ClientState &newState); - boost::asio::deadline_timer &GetStateTimer(); + boost::asio::steady_timer &GetStateTimer(); SenderHelper &GetSender(); @@ -341,8 +342,8 @@ private: mutable boost::mutex m_pingDataMutex; PingData m_pingData; - boost::asio::deadline_timer m_stateTimer; - boost::asio::deadline_timer m_avatarTimer; + boost::asio::steady_timer m_stateTimer; + boost::asio::steady_timer m_avatarTimer; friend class AbstractClientStateReceiving; friend class ClientStateInit; diff --git a/src/net/common/clientstate.cpp b/src/net/common/clientstate.cpp index 84921ced..6114ca63 100644 --- a/src/net/common/clientstate.cpp +++ b/src/net/common/clientstate.cpp @@ -60,6 +60,12 @@ using namespace std; using namespace boost::filesystem; +#ifdef BOOST_ASIO_HAS_STD_CHRONO +using namespace std::chrono; +#else +using namespace boost::chrono; +#endif + #define CLIENT_WAIT_TIMEOUT_MSEC 50 #define CLIENT_CONNECT_TIMEOUT_SEC 10 @@ -238,7 +244,7 @@ void ClientStateDownloadingServerList::Enter(boost::shared_ptr client) { client->GetStateTimer().expires_from_now( - boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC)); + milliseconds(CLIENT_WAIT_TIMEOUT_MSEC)); client->GetStateTimer().async_wait( boost::bind( &ClientStateDownloadingServerList::TimerLoop, this, boost::asio::placeholders::error, client)); @@ -265,7 +271,7 @@ ClientStateDownloadingServerList::TimerLoop(const boost::system::error_code& ec, client->SetState(ClientStateReadingServerList::Instance()); } else { client->GetStateTimer().expires_from_now( - boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC)); + milliseconds(CLIENT_WAIT_TIMEOUT_MSEC)); client->GetStateTimer().async_wait( boost::bind( &ClientStateDownloadingServerList::TimerLoop, this, boost::asio::placeholders::error, client)); @@ -409,7 +415,7 @@ void ClientStateWaitChooseServer::Enter(boost::shared_ptr client) { client->GetStateTimer().expires_from_now( - boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC)); + milliseconds(CLIENT_WAIT_TIMEOUT_MSEC)); client->GetStateTimer().async_wait( boost::bind( &ClientStateWaitChooseServer::TimerLoop, this, boost::asio::placeholders::error, client)); @@ -432,7 +438,7 @@ ClientStateWaitChooseServer::TimerLoop(const boost::system::error_code& ec, boos client->SetState(ClientStateStartResolve::Instance()); } else { client->GetStateTimer().expires_from_now( - boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC)); + milliseconds(CLIENT_WAIT_TIMEOUT_MSEC)); client->GetStateTimer().async_wait( boost::bind( &ClientStateWaitChooseServer::TimerLoop, this, boost::asio::placeholders::error, client)); @@ -461,7 +467,7 @@ void ClientStateStartConnect::Enter(boost::shared_ptr client) { client->GetStateTimer().expires_from_now( - boost::posix_time::seconds(CLIENT_CONNECT_TIMEOUT_SEC)); + seconds(CLIENT_CONNECT_TIMEOUT_SEC)); client->GetStateTimer().async_wait( boost::bind( &ClientStateStartConnect::TimerTimeout, this, boost::asio::placeholders::error, client)); @@ -511,7 +517,11 @@ ClientStateStartConnect::HandleConnect(const boost::system::error_code& ec, boos client)); } else { if (ec != boost::asio::error::operation_aborted) { - throw ClientException(__FILE__, __LINE__, ERR_SOCK_CONNECT_FAILED, ec.value()); + if (client->GetContext().GetAddrFamily() == AF_INET6) { + throw ClientException(__FILE__, __LINE__, ERR_SOCK_CONNECT_IPV6_FAILED, ec.value()); + } else { + throw ClientException(__FILE__, __LINE__, ERR_SOCK_CONNECT_FAILED, ec.value()); + } } } } @@ -523,7 +533,11 @@ ClientStateStartConnect::TimerTimeout(const boost::system::error_code& ec, boost if (!ec && &client->GetState() == this) { boost::system::error_code ec; client->GetContext().GetSessionData()->GetAsioSocket()->close(ec); - throw ClientException(__FILE__, __LINE__, ERR_SOCK_CONNECT_TIMEOUT, 0); + if (client->GetContext().GetAddrFamily() == AF_INET6) { + throw ClientException(__FILE__, __LINE__, ERR_SOCK_CONNECT_IPV6_TIMEOUT, 0); + } else { + throw ClientException(__FILE__, __LINE__, ERR_SOCK_CONNECT_TIMEOUT, 0); + } } } @@ -986,7 +1000,7 @@ void ClientStateWaitEnterLogin::Enter(boost::shared_ptr client) { client->GetStateTimer().expires_from_now( - boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC)); + milliseconds(CLIENT_WAIT_TIMEOUT_MSEC)); client->GetStateTimer().async_wait( boost::bind( &ClientStateWaitEnterLogin::TimerLoop, this, boost::asio::placeholders::error, client)); @@ -1065,7 +1079,7 @@ ClientStateWaitEnterLogin::TimerLoop(const boost::system::error_code& ec, boost: } } else { client->GetStateTimer().expires_from_now( - boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC)); + milliseconds(CLIENT_WAIT_TIMEOUT_MSEC)); client->GetStateTimer().async_wait( boost::bind( &ClientStateWaitEnterLogin::TimerLoop, this, boost::asio::placeholders::error, client)); @@ -1399,7 +1413,7 @@ void ClientStateSynchronizeStart::Enter(boost::shared_ptr client) { client->GetStateTimer().expires_from_now( - boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC)); + milliseconds(CLIENT_WAIT_TIMEOUT_MSEC)); client->GetStateTimer().async_wait( boost::bind( &ClientStateSynchronizeStart::TimerLoop, this, boost::asio::placeholders::error, client)); @@ -1429,7 +1443,7 @@ ClientStateSynchronizeStart::TimerLoop(const boost::system::error_code& ec, boos client->SetState(ClientStateWaitStart::Instance()); } else { client->GetStateTimer().expires_from_now( - boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC)); + milliseconds(CLIENT_WAIT_TIMEOUT_MSEC)); client->GetStateTimer().async_wait( boost::bind( &ClientStateSynchronizeStart::TimerLoop, this, boost::asio::placeholders::error, client)); @@ -1637,7 +1651,7 @@ ClientStateWaitHand::InternalHandlePacket(boost::shared_ptr client // Basic synchronisation before a new hand is started. client->GetGui().waitForGuiUpdateDone(); // Start new hand. - client->GetGame()->getSeatsList()->front()->setMyCards(myCards); + client->GetGame()->getSeatsList()->front()->setMyHoleCards(myCards); client->GetGame()->initHand(); client->GetGame()->getCurrentHand()->setSmallBlind(netHandStart.smallblind()); client->GetGame()->getCurrentHand()->getCurrentBeRo()->setMinimumRaise(2 * netHandStart.smallblind()); @@ -1677,7 +1691,7 @@ ClientStateWaitHand::InternalHandlePacket(boost::shared_ptr client int bestHandPos[5]; tmpCards[0] = static_cast(r.resultcard1()); tmpCards[1] = static_cast(r.resultcard2()); - tmpPlayer->setMyCards(tmpCards); + tmpPlayer->setMyHoleCards(tmpCards); for (int num = 0; num < 5; num++) { bestHandPos[num] = r.besthandposition(num); } @@ -1794,7 +1808,6 @@ ClientStateRunHand::InternalHandlePacket(boost::shared_ptr client, curGame->getPlayerByUniqueId(curGame->getCurrentHand()->getCurrentBeRo()->getBigBlindPositionId())->getMySet(), curGame->getPlayerByUniqueId(curGame->getCurrentHand()->getCurrentBeRo()->getSmallBlindPositionId())->getMyName(), curGame->getPlayerByUniqueId(curGame->getCurrentHand()->getCurrentBeRo()->getBigBlindPositionId())->getMyName()); - client->GetGui().flushLogAtHand(); client->GetClientLog()->logNewHandMsg( curGame->getCurrentHandID(), curGame->getPlayerByUniqueId(curGame->getCurrentHand()->getDealerPosition())->getMyID()+1, @@ -1926,7 +1939,7 @@ ClientStateRunHand::InternalHandlePacket(boost::shared_ptr client, int tmpCards[2]; tmpCards[0] = static_cast(p.allincard1()); tmpCards[1] = static_cast(p.allincard2()); - tmpPlayer->setMyCards(tmpCards); + tmpPlayer->setMyHoleCards(tmpCards); } client->GetGui().flipHolecardsAllIn(); if(curGame->getCurrentHand()->getCurrentRound() client, int bestHandPos[5]; tmpCards[0] = static_cast(r.resultcard1()); tmpCards[1] = static_cast(r.resultcard2()); - tmpPlayer->setMyCards(tmpCards); + tmpPlayer->setMyHoleCards(tmpCards); for (int num = 0; num < 5; num++) { bestHandPos[num] = r.besthandposition(num); } diff --git a/src/net/common/clientthread.cpp b/src/net/common/clientthread.cpp index c36e94af..2a338483 100644 --- a/src/net/common/clientthread.cpp +++ b/src/net/common/clientthread.cpp @@ -66,6 +66,12 @@ using namespace std; using namespace boost::filesystem; using boost::asio::ip::tcp; +#ifdef BOOST_ASIO_HAS_STD_CHRONO +using namespace std::chrono; +#else +using namespace boost::chrono; +#endif + ClientThread::ClientThread(GuiInterface &gui, AvatarManager &avatarManager, Log *myLog) : m_ioService(new boost::asio::io_service), m_clientLog(myLog), m_curState(NULL), m_gui(gui), m_avatarManager(avatarManager), m_isServerSelected(false), @@ -586,7 +592,7 @@ void ClientThread::RegisterTimers() { m_avatarTimer.expires_from_now( - boost::posix_time::milliseconds(CLIENT_AVATAR_LOOP_MSEC)); + milliseconds(CLIENT_AVATAR_LOOP_MSEC)); m_avatarTimer.async_wait( boost::bind( &ClientThread::TimerCheckAvatarDownloads, shared_from_this(), boost::asio::placeholders::error)); @@ -910,7 +916,7 @@ ClientThread::TimerCheckAvatarDownloads(const boost::system::error_code& ec) PassAvatarFileToManager(playerId, tmpAvatar); } m_avatarTimer.expires_from_now( - boost::posix_time::milliseconds(CLIENT_AVATAR_LOOP_MSEC)); + milliseconds(CLIENT_AVATAR_LOOP_MSEC)); m_avatarTimer.async_wait( boost::bind( &ClientThread::TimerCheckAvatarDownloads, shared_from_this(), boost::asio::placeholders::error)); @@ -1022,7 +1028,7 @@ ClientThread::SetState(ClientState &newState) m_curState->Enter(shared_from_this()); } -boost::asio::deadline_timer & +boost::asio::steady_timer & ClientThread::GetStateTimer() { return m_stateTimer; diff --git a/src/net/common/serveradminbot.cpp b/src/net/common/serveradminbot.cpp index a200cc97..36c3a1dc 100644 --- a/src/net/common/serveradminbot.cpp +++ b/src/net/common/serveradminbot.cpp @@ -49,6 +49,12 @@ using namespace std; using namespace boost::filesystem; +#ifdef BOOST_ASIO_HAS_STD_CHRONO +using namespace std::chrono; +#else +using namespace boost::chrono; +#endif + ServerAdminBot::ServerAdminBot(boost::shared_ptr ioService) : m_notifyTimeoutMinutes(0), m_notifyIntervalMinutes(0), m_notifyCounter(0), m_notifyTimer(boost::posix_time::time_duration(0, 0, 0), boost::timers::portable::second_timer::manual_start), @@ -272,17 +278,17 @@ ServerAdminBot::Run() if (m_ircAdminThread) { // Initialise the timers. m_reconnectTimer.expires_from_now( - boost::posix_time::seconds(SERVER_RESTART_IRC_BOT_INTERVAL_SEC)); + seconds(SERVER_RESTART_IRC_BOT_INTERVAL_SEC)); m_reconnectTimer.async_wait( boost::bind( &ServerAdminBot::ReconnectHandler, shared_from_this(), boost::asio::placeholders::error)); m_notifyLoopTimer.expires_from_now( - boost::posix_time::seconds(SERVER_NOTIFY_IRC_BOT_INTERVAL_SEC)); + seconds(SERVER_NOTIFY_IRC_BOT_INTERVAL_SEC)); m_notifyLoopTimer.async_wait( boost::bind( &ServerAdminBot::NotifyLoop, shared_from_this(), boost::asio::placeholders::error)); m_checkFileTimer.expires_from_now( - boost::posix_time::seconds(SERVER_CHECK_IRC_BOT_INTERVAL_SEC)); + seconds(SERVER_CHECK_IRC_BOT_INTERVAL_SEC)); m_checkFileTimer.async_wait( boost::bind( &ServerAdminBot::CheckFileHandler, shared_from_this(), boost::asio::placeholders::error)); @@ -298,7 +304,7 @@ ServerAdminBot::ReconnectHandler(const boost::system::error_code& ec) Reconnect(); m_reconnectTimer.expires_from_now( - boost::posix_time::seconds(SERVER_RESTART_IRC_BOT_INTERVAL_SEC)); + seconds(SERVER_RESTART_IRC_BOT_INTERVAL_SEC)); m_reconnectTimer.async_wait( boost::bind( &ServerAdminBot::ReconnectHandler, shared_from_this(), boost::asio::placeholders::error)); @@ -330,7 +336,7 @@ ServerAdminBot::CheckFileHandler(const boost::system::error_code& ec) Reconnect(); } m_checkFileTimer.expires_from_now( - boost::posix_time::seconds(SERVER_CHECK_IRC_BOT_INTERVAL_SEC)); + seconds(SERVER_CHECK_IRC_BOT_INTERVAL_SEC)); m_checkFileTimer.async_wait( boost::bind( &ServerAdminBot::CheckFileHandler, shared_from_this(), boost::asio::placeholders::error)); @@ -386,7 +392,7 @@ ServerAdminBot::NotifyLoop(const boost::system::error_code& ec) } } m_notifyLoopTimer.expires_from_now( - boost::posix_time::seconds(SERVER_NOTIFY_IRC_BOT_INTERVAL_SEC)); + seconds(SERVER_NOTIFY_IRC_BOT_INTERVAL_SEC)); m_notifyLoopTimer.async_wait( boost::bind( &ServerAdminBot::NotifyLoop, shared_from_this(), boost::asio::placeholders::error)); diff --git a/src/net/common/serverbanmanager.cpp b/src/net/common/serverbanmanager.cpp index 99951f21..62a94997 100644 --- a/src/net/common/serverbanmanager.cpp +++ b/src/net/common/serverbanmanager.cpp @@ -34,6 +34,11 @@ using namespace std; +#ifdef BOOST_ASIO_HAS_STD_CHRONO +using namespace std::chrono; +#else +using namespace boost::chrono; +#endif ServerBanManager::ServerBanManager(boost::shared_ptr ioService) : m_ioService(ioService), m_curBanId(0) @@ -126,7 +131,7 @@ ServerBanManager::GetBanList(list &list) const banText << (*i_nick).first << ": (nickStr) - " << (*i_nick).second.nameStr; if ((*i_nick).second.timer) - banText << " duration: " << (*i_nick).second.timer->expires_from_now().hours() << "h"; + banText << " duration: " << duration_cast((*i_nick).second.timer->expires_from_now()).count() << "h"; list.push_back(banText.str()); ++i_nick; } @@ -136,7 +141,7 @@ ServerBanManager::GetBanList(list &list) const ostringstream banText; banText << (*i_ip).first << ": (IP) - " << (*i_ip).second.ipAddress; if ((*i_ip).second.timer) - banText << " duration: " << (*i_ip).second.timer->expires_from_now().hours() << "h"; + banText << " duration: " << duration_cast((*i_ip).second.timer->expires_from_now()).count() << "h"; list.push_back(banText.str()); ++i_ip; } @@ -235,14 +240,14 @@ ServerBanManager::IsBadGameName(const std::string &name) const return retVal; } -boost::shared_ptr +boost::shared_ptr ServerBanManager::InternalRegisterTimedBan(unsigned timerId, unsigned durationHours) { - boost::shared_ptr tmpTimer; + boost::shared_ptr tmpTimer; if (durationHours) { - tmpTimer.reset(new boost::asio::deadline_timer(*m_ioService)); + tmpTimer.reset(new boost::asio::steady_timer(*m_ioService)); tmpTimer->expires_from_now( - boost::posix_time::hours(durationHours)); + hours(durationHours)); tmpTimer->async_wait( boost::bind( &ServerBanManager::TimerRemoveBan, shared_from_this(), boost::asio::placeholders::error, timerId, tmpTimer)); @@ -251,7 +256,7 @@ ServerBanManager::InternalRegisterTimedBan(unsigned timerId, unsigned durationHo } void -ServerBanManager::TimerRemoveBan(const boost::system::error_code &ec, unsigned banId, boost::shared_ptr timer) +ServerBanManager::TimerRemoveBan(const boost::system::error_code &ec, unsigned banId, boost::shared_ptr timer) { if (!ec && timer) UnBan(banId); diff --git a/src/net/common/servergame.cpp b/src/net/common/servergame.cpp index bf7102b0..4deb7940 100644 --- a/src/net/common/servergame.cpp +++ b/src/net/common/servergame.cpp @@ -53,6 +53,12 @@ using namespace std; +#ifdef BOOST_ASIO_HAS_STD_CHRONO +using namespace std::chrono; +#else +using namespace boost::chrono; +#endif + static bool LessThanPlayerHandStartMoney(const boost::shared_ptr p1, const boost::shared_ptr p2) { return p1->getMyRoundStartCash() < p2->getMyRoundStartCash(); @@ -276,7 +282,7 @@ ServerGame::TimerVoteKick(const boost::system::error_code &ec) m_voteKickData.reset(); } m_voteKickTimer.expires_from_now( - boost::posix_time::milliseconds(SERVER_CHECK_VOTE_KICK_INTERVAL_MSEC)); + milliseconds(SERVER_CHECK_VOTE_KICK_INTERVAL_MSEC)); m_voteKickTimer.async_wait( boost::bind( &ServerGame::TimerVoteKick, shared_from_this(), boost::asio::placeholders::error)); @@ -514,7 +520,7 @@ ServerGame::InternalAskVoteKick(boost::shared_ptr byWhom, unsigned SendToAllPlayers(packet, SessionData::Game); m_voteKickTimer.expires_from_now( - boost::posix_time::milliseconds(SERVER_CHECK_VOTE_KICK_INTERVAL_MSEC)); + milliseconds(SERVER_CHECK_VOTE_KICK_INTERVAL_MSEC)); m_voteKickTimer.async_wait( boost::bind( &ServerGame::TimerVoteKick, shared_from_this(), boost::asio::placeholders::error)); @@ -1072,13 +1078,13 @@ ServerGame::SetState(ServerGameState &newState) m_curState->Enter(shared_from_this()); } -boost::asio::deadline_timer & +boost::asio::steady_timer & ServerGame::GetStateTimer1() { return m_stateTimer1; } -boost::asio::deadline_timer & +boost::asio::steady_timer & ServerGame::GetStateTimer2() { return m_stateTimer2; diff --git a/src/net/common/servergamestate.cpp b/src/net/common/servergamestate.cpp index 372e5165..e214cd86 100644 --- a/src/net/common/servergamestate.cpp +++ b/src/net/common/servergamestate.cpp @@ -52,6 +52,12 @@ using namespace std; +#ifdef BOOST_ASIO_HAS_STD_CHRONO +using namespace std::chrono; +#else +using namespace boost::chrono; +#endif + //#define POKERTH_SERVER_TEST #ifdef POKERTH_SERVER_TEST @@ -204,7 +210,7 @@ SetPlayerResult(PlayerResult &playerResult, boost::shared_ptr t playerResult.set_playerid(tmpPlayer->getMyUniqueID()); int tmpCards[2]; int bestHandPos[5]; - tmpPlayer->getMyCards(tmpCards); + tmpPlayer->getMyHoleCards(tmpCards); playerResult.set_resultcard1(tmpCards[0]); playerResult.set_resultcard2(tmpCards[1]); tmpPlayer->getMyBestHandPosition(bestHandPos); @@ -570,7 +576,7 @@ ServerGameStateInit::RegisterAdminTimer(boost::shared_ptr server) // No admin timeout in LAN or ranking games. if (server->GetLobbyThread().GetServerMode() != SERVER_MODE_LAN && server->GetGameData().gameType != GAME_TYPE_RANKING) { server->GetStateTimer1().expires_from_now( - boost::posix_time::seconds(SERVER_GAME_ADMIN_TIMEOUT_SEC - SERVER_GAME_ADMIN_WARNING_REMAINING_SEC)); + seconds(SERVER_GAME_ADMIN_TIMEOUT_SEC - SERVER_GAME_ADMIN_WARNING_REMAINING_SEC)); server->GetStateTimer1().async_wait( boost::bind( &ServerGameStateInit::TimerAdminWarning, this, boost::asio::placeholders::error, server)); @@ -589,7 +595,7 @@ ServerGameStateInit::RegisterAutoStartTimer(boost::shared_ptr server // No autostart in LAN games. if (server->GetLobbyThread().GetServerMode() != SERVER_MODE_LAN) { server->GetStateTimer2().expires_from_now( - boost::posix_time::seconds(SERVER_AUTOSTART_GAME_DELAY_SEC)); + seconds(SERVER_AUTOSTART_GAME_DELAY_SEC)); server->GetStateTimer2().async_wait( boost::bind( &ServerGameStateInit::TimerAutoStart, this, boost::asio::placeholders::error, server)); @@ -627,7 +633,7 @@ ServerGameStateInit::TimerAdminWarning(const boost::system::error_code &ec, boos } // Start timeout timer. server->GetStateTimer1().expires_from_now( - boost::posix_time::seconds(SERVER_GAME_ADMIN_WARNING_REMAINING_SEC)); + seconds(SERVER_GAME_ADMIN_WARNING_REMAINING_SEC)); server->GetStateTimer1().async_wait( boost::bind( &ServerGameStateInit::TimerAdminTimeout, this, boost::asio::placeholders::error, server)); @@ -762,7 +768,7 @@ void ServerGameStateStartGame::Enter(boost::shared_ptr server) { server->GetStateTimer1().expires_from_now( - boost::posix_time::seconds(SERVER_START_GAME_TIMEOUT_SEC)); + seconds(SERVER_START_GAME_TIMEOUT_SEC)); server->GetStateTimer1().async_wait( boost::bind( &ServerGameStateStartGame::TimerTimeout, this, boost::asio::placeholders::error, server)); @@ -925,7 +931,7 @@ void ServerGameStateHand::Enter(boost::shared_ptr server) { server->GetStateTimer1().expires_from_now( - boost::posix_time::milliseconds(SERVER_LOOP_DELAY_MSEC)); + milliseconds(SERVER_LOOP_DELAY_MSEC)); server->GetStateTimer1().async_wait( boost::bind( &ServerGameStateHand::TimerLoop, this, boost::asio::placeholders::error, server)); @@ -993,7 +999,7 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr server) AllInShowCardsMessage::PlayerAllIn *playerAllIn = netAllInShow->add_playersallin(); playerAllIn->set_playerid((*i)->getMyUniqueID()); int tmpCards[2]; - (*i)->getMyCards(tmpCards); + (*i)->getMyHoleCards(tmpCards); playerAllIn->set_allincard1(tmpCards[0]); playerAllIn->set_allincard2(tmpCards[1]); ++i; @@ -1002,7 +1008,7 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr server) curGame.getCurrentHand()->setCardsShown(true); server->GetStateTimer1().expires_from_now( - boost::posix_time::seconds(SERVER_SHOW_CARDS_DELAY_SEC)); + seconds(SERVER_SHOW_CARDS_DELAY_SEC)); server->GetStateTimer1().async_wait( boost::bind( &ServerGameStateHand::TimerShowCards, this, boost::asio::placeholders::error, server)); @@ -1010,7 +1016,7 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr server) SendNewRoundCards(*server, curGame, newRound); server->GetStateTimer1().expires_from_now( - boost::posix_time::seconds(GetDealCardsDelaySec(*server))); + seconds(GetDealCardsDelaySec(*server))); server->GetStateTimer1().async_wait( boost::bind( &ServerGameStateHand::TimerLoop, this, boost::asio::placeholders::error, server)); @@ -1038,7 +1044,7 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr server) // If the player is computer controlled, let the engine act. if (curPlayer->getMyType() == PLAYER_TYPE_COMPUTER) { server->GetStateTimer1().expires_from_now( - boost::posix_time::seconds(SERVER_COMPUTER_ACTION_DELAY_SEC)); + seconds(SERVER_COMPUTER_ACTION_DELAY_SEC)); server->GetStateTimer1().async_wait( boost::bind( &ServerGameStateHand::TimerComputerAction, this, boost::asio::placeholders::error, server)); @@ -1049,7 +1055,7 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr server) PerformPlayerAction(*server, curPlayer, PLAYER_ACTION_FOLD, 0); server->GetStateTimer1().expires_from_now( - boost::posix_time::milliseconds(SERVER_LOOP_DELAY_MSEC)); + milliseconds(SERVER_LOOP_DELAY_MSEC)); server->GetStateTimer1().async_wait( boost::bind( &ServerGameStateHand::TimerLoop, this, boost::asio::placeholders::error, server)); @@ -1117,7 +1123,7 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr server) // View a dialog for a new game - delayed. server->GetStateTimer1().expires_from_now( - boost::posix_time::seconds(SERVER_DELAY_NEXT_GAME_SEC)); + seconds(SERVER_DELAY_NEXT_GAME_SEC)); server->GetStateTimer1().async_wait( boost::bind( &ServerGameStateHand::TimerNextGame, this, boost::asio::placeholders::error, server, winnerPlayer->getMyUniqueID())); @@ -1136,7 +1142,7 @@ ServerGameStateHand::TimerShowCards(const boost::system::error_code &ec, boost:: SendNewRoundCards(*server, curGame, curGame.getCurrentHand()->getCurrentRound()); server->GetStateTimer1().expires_from_now( - boost::posix_time::seconds(GetDealCardsDelaySec(*server))); + seconds(GetDealCardsDelaySec(*server))); server->GetStateTimer1().async_wait( boost::bind( &ServerGameStateHand::TimerLoop, this, boost::asio::placeholders::error, server)); @@ -1251,7 +1257,7 @@ ServerGameStateHand::StartNewHand(boost::shared_ptr server) if (tmpSession) { int cards[2]; bool errorFlag = false; - tmpPlayer->getMyCards(cards); + tmpPlayer->getMyHoleCards(cards); boost::shared_ptr notifyCards = CreateNetPacketHandStart(*server); HandStartMessage *netHandStart = notifyCards->GetMsg()->mutable_handstartmessage(); @@ -1507,7 +1513,7 @@ ServerGameStateWaitPlayerAction::Enter(boost::shared_ptr server) int timeoutSec = server->GetGameData().playerActionTimeoutSec + SERVER_PLAYER_TIMEOUT_ADD_DELAY_SEC; #endif - server->GetStateTimer1().expires_from_now(boost::posix_time::seconds(timeoutSec)); + server->GetStateTimer1().expires_from_now(seconds(timeoutSec)); server->GetStateTimer1().async_wait( boost::bind( &ServerGameStateWaitPlayerAction::TimerTimeout, this, boost::asio::placeholders::error, server)); @@ -1641,7 +1647,7 @@ ServerGameStateWaitNextHand::Enter(boost::shared_ptr server) #endif server->GetStateTimer1().expires_from_now( - boost::posix_time::seconds(timeoutSec)); + seconds(timeoutSec)); server->GetStateTimer1().async_wait( boost::bind( diff --git a/src/net/common/serverlobbybot.cpp b/src/net/common/serverlobbybot.cpp index 31d3325b..c3fd6afd 100644 --- a/src/net/common/serverlobbybot.cpp +++ b/src/net/common/serverlobbybot.cpp @@ -45,6 +45,12 @@ using namespace std; +#ifdef BOOST_ASIO_HAS_STD_CHRONO +using namespace std::chrono; +#else +using namespace boost::chrono; +#endif + ServerLobbyBot::ServerLobbyBot(boost::shared_ptr ioService) : m_reconnectTimer(*ioService) { @@ -110,7 +116,7 @@ ServerLobbyBot::Run() if (m_ircLobbyThread) { // Initialise the reconnect timer. m_reconnectTimer.expires_from_now( - boost::posix_time::seconds(SERVER_RESTART_IRC_BOT_INTERVAL_SEC)); + seconds(SERVER_RESTART_IRC_BOT_INTERVAL_SEC)); m_reconnectTimer.async_wait( boost::bind( &ServerLobbyBot::Reconnect, shared_from_this(), boost::asio::placeholders::error)); @@ -132,7 +138,7 @@ ServerLobbyBot::Reconnect(const boost::system::error_code& ec) } } m_reconnectTimer.expires_from_now( - boost::posix_time::seconds(SERVER_RESTART_IRC_BOT_INTERVAL_SEC)); + seconds(SERVER_RESTART_IRC_BOT_INTERVAL_SEC)); m_reconnectTimer.async_wait( boost::bind( &ServerLobbyBot::Reconnect, shared_from_this(), boost::asio::placeholders::error)); diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index 4e63dc5e..0c920afa 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -95,6 +95,11 @@ using namespace std; using boost::asio::ip::tcp; +#ifdef BOOST_ASIO_HAS_STD_CHRONO +using namespace std::chrono; +#else +using namespace boost::chrono; +#endif class InternalServerCallback : public SessionDataCallback, public ChatCleanerCallback, public ServerDBCallback { @@ -859,19 +864,19 @@ ServerLobbyThread::RegisterTimers() { // Remove closed games. m_removeGameTimer.expires_from_now( - boost::posix_time::milliseconds(SERVER_REMOVE_GAME_INTERVAL_MSEC)); + milliseconds(SERVER_REMOVE_GAME_INTERVAL_MSEC)); m_removeGameTimer.async_wait( boost::bind( &ServerLobbyThread::TimerRemoveGame, shared_from_this(), boost::asio::placeholders::error)); // Update the statistics file. m_saveStatisticsTimer.expires_from_now( - boost::posix_time::seconds(SERVER_SAVE_STATISTICS_INTERVAL_SEC)); + seconds(SERVER_SAVE_STATISTICS_INTERVAL_SEC)); m_saveStatisticsTimer.async_wait( boost::bind( &ServerLobbyThread::TimerSaveStatisticsFile, shared_from_this(), boost::asio::placeholders::error)); // Update the avatar upload locks. m_loginLockTimer.expires_from_now( - boost::posix_time::milliseconds(SERVER_UPDATE_LOGIN_LOCK_INTERVAL_MSEC)); + milliseconds(SERVER_UPDATE_LOGIN_LOCK_INTERVAL_MSEC)); m_loginLockTimer.async_wait( boost::bind( &ServerLobbyThread::TimerUpdateClientLoginLock, shared_from_this(), boost::asio::placeholders::error)); @@ -1859,7 +1864,7 @@ ServerLobbyThread::TimerRemoveGame(const boost::system::error_code &ec) } // Restart timer m_removeGameTimer.expires_from_now( - boost::posix_time::milliseconds(SERVER_REMOVE_GAME_INTERVAL_MSEC)); + milliseconds(SERVER_REMOVE_GAME_INTERVAL_MSEC)); m_removeGameTimer.async_wait( boost::bind( &ServerLobbyThread::TimerRemoveGame, shared_from_this(), boost::asio::placeholders::error)); @@ -1884,7 +1889,7 @@ ServerLobbyThread::TimerUpdateClientLoginLock(const boost::system::error_code &e } // Restart timer m_loginLockTimer.expires_from_now( - boost::posix_time::milliseconds(SERVER_UPDATE_LOGIN_LOCK_INTERVAL_MSEC)); + milliseconds(SERVER_UPDATE_LOGIN_LOCK_INTERVAL_MSEC)); m_loginLockTimer.async_wait( boost::bind( &ServerLobbyThread::TimerUpdateClientLoginLock, shared_from_this(), boost::asio::placeholders::error)); @@ -2231,7 +2236,7 @@ ServerLobbyThread::TimerSaveStatisticsFile(const boost::system::error_code &ec) } // Restart timer m_saveStatisticsTimer.expires_from_now( - boost::posix_time::seconds(SERVER_SAVE_STATISTICS_INTERVAL_SEC)); + seconds(SERVER_SAVE_STATISTICS_INTERVAL_SEC)); m_saveStatisticsTimer.async_wait( boost::bind( &ServerLobbyThread::TimerSaveStatisticsFile, shared_from_this(), boost::asio::placeholders::error)); diff --git a/src/net/common/sessiondata.cpp b/src/net/common/sessiondata.cpp index fd30cc44..f9cd30b9 100644 --- a/src/net/common/sessiondata.cpp +++ b/src/net/common/sessiondata.cpp @@ -41,6 +41,12 @@ using namespace std; using boost::asio::ip::tcp; +#ifdef BOOST_ASIO_HAS_STD_CHRONO +using namespace std::chrono; +#else +using namespace boost::chrono; +#endif + SessionData::SessionData(boost::shared_ptr sock, SessionId id, SessionDataCallback &cb, boost::asio::io_service &ioService) : m_socket(sock), m_id(id), m_state(SessionData::Init), m_readyFlag(false), m_wantsLobbyMsg(true), m_activityTimeoutSec(0), m_activityWarningRemainingSec(0), m_initTimeoutTimer(ioService), m_globalTimeoutTimer(ioService), @@ -236,7 +242,7 @@ SessionData::TimerActivityWarning(const boost::system::error_code &ec) m_callback.SessionTimeoutWarning(shared_from_this(), m_activityWarningRemainingSec); m_activityTimeoutTimer.expires_from_now( - boost::posix_time::seconds(m_activityWarningRemainingSec)); + seconds(m_activityWarningRemainingSec)); m_activityTimeoutTimer.async_wait( boost::bind( &SessionData::TimerSessionTimeout, shared_from_this(), boost::asio::placeholders::error)); @@ -322,7 +328,7 @@ SessionData::ResetActivityTimer() { boost::mutex::scoped_lock lock(m_dataMutex); m_activityTimeoutTimer.expires_from_now( - boost::posix_time::seconds(m_activityTimeoutSec - m_activityWarningRemainingSec)); + seconds(m_activityTimeoutSec - m_activityWarningRemainingSec)); m_activityTimeoutTimer.async_wait( boost::bind( &SessionData::TimerActivityWarning, shared_from_this(), boost::asio::placeholders::error)); @@ -333,7 +339,7 @@ SessionData::StartTimerInitTimeout(unsigned timeoutSec) { boost::mutex::scoped_lock lock(m_dataMutex); m_initTimeoutTimer.expires_from_now( - boost::posix_time::seconds(timeoutSec)); + seconds(timeoutSec)); m_initTimeoutTimer.async_wait( boost::bind( &SessionData::TimerInitTimeout, shared_from_this(), boost::asio::placeholders::error)); @@ -344,7 +350,7 @@ SessionData::StartTimerGlobalTimeout(unsigned timeoutSec) { boost::mutex::scoped_lock lock(m_dataMutex); m_globalTimeoutTimer.expires_from_now( - boost::posix_time::seconds(timeoutSec)); + seconds(timeoutSec)); m_globalTimeoutTimer.async_wait( boost::bind( &SessionData::TimerSessionTimeout, shared_from_this(), boost::asio::placeholders::error)); @@ -358,7 +364,7 @@ SessionData::StartTimerActivityTimeout(unsigned timeoutSec, unsigned warningRema m_activityWarningRemainingSec = warningRemainingSec; m_activityTimeoutTimer.expires_from_now( - boost::posix_time::seconds(timeoutSec - warningRemainingSec)); + seconds(timeoutSec - warningRemainingSec)); m_activityTimeoutTimer.async_wait( boost::bind( &SessionData::TimerActivityWarning, shared_from_this(), boost::asio::placeholders::error)); diff --git a/src/net/serveradminbot.h b/src/net/serveradminbot.h index dea02915..3f0f5df2 100644 --- a/src/net/serveradminbot.h +++ b/src/net/serveradminbot.h @@ -34,6 +34,7 @@ #define _SERVERADMINBOT_H_ #include +#include #include #include #include @@ -96,9 +97,9 @@ private: boost::shared_ptr m_ircAdminThread; boost::timers::portable::second_timer m_notifyTimer; - boost::asio::deadline_timer m_reconnectTimer; - boost::asio::deadline_timer m_notifyLoopTimer; - boost::asio::deadline_timer m_checkFileTimer; + boost::asio::steady_timer m_reconnectTimer; + boost::asio::steady_timer m_notifyLoopTimer; + boost::asio::steady_timer m_checkFileTimer; }; #endif diff --git a/src/net/serverbanmanager.h b/src/net/serverbanmanager.h index 22336adb..50ca465a 100644 --- a/src/net/serverbanmanager.h +++ b/src/net/serverbanmanager.h @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -67,12 +68,12 @@ public: protected: struct TimedPlayerBan { - boost::shared_ptr timer; + boost::shared_ptr timer; std::string nameStr; boost::regex nameRegex; }; struct TimedIPBan { - boost::shared_ptr timer; + boost::shared_ptr timer; std::string ipAddress; }; @@ -81,8 +82,8 @@ protected: typedef std::list RegexList; typedef std::vector DBPlayerIdList; - boost::shared_ptr InternalRegisterTimedBan(unsigned timerId, unsigned durationHours); - void TimerRemoveBan(const boost::system::error_code &ec, unsigned banId, boost::shared_ptr timer); + boost::shared_ptr InternalRegisterTimedBan(unsigned timerId, unsigned durationHours); + void TimerRemoveBan(const boost::system::error_code &ec, unsigned banId, boost::shared_ptr timer); boost::shared_ptr m_ioService; diff --git a/src/net/servergame.h b/src/net/servergame.h index 560c54aa..146bbd59 100644 --- a/src/net/servergame.h +++ b/src/net/servergame.h @@ -34,6 +34,7 @@ #define _SERVERGAME_H_ #include +#include #include #include @@ -177,8 +178,8 @@ protected: ServerGameState &GetState(); void SetState(ServerGameState &newState); - boost::asio::deadline_timer &GetStateTimer1(); - boost::asio::deadline_timer &GetStateTimer2(); + boost::asio::steady_timer &GetStateTimer1(); + boost::asio::steady_timer &GetStateTimer2(); const StartData &GetStartData() const; void SetStartData(const StartData &startData); @@ -237,9 +238,9 @@ private: ConfigFile &m_playerConfig; unsigned m_gameNum; unsigned m_curPetitionId; - boost::asio::deadline_timer m_voteKickTimer; - boost::asio::deadline_timer m_stateTimer1; - boost::asio::deadline_timer m_stateTimer2; + boost::asio::steady_timer m_voteKickTimer; + boost::asio::steady_timer m_stateTimer1; + boost::asio::steady_timer m_stateTimer2; bool m_isNameReported; friend class ServerLobbyThread; diff --git a/src/net/serverlobbybot.h b/src/net/serverlobbybot.h index 2a6b8746..8ada9ad5 100644 --- a/src/net/serverlobbybot.h +++ b/src/net/serverlobbybot.h @@ -34,6 +34,7 @@ #define _SERVERLOBBYBOT_H_ #include +#include #include #include #include @@ -86,7 +87,7 @@ private: boost::shared_ptr m_lobbyThread; boost::shared_ptr m_ircLobbyThread; - boost::asio::deadline_timer m_reconnectTimer; + boost::asio::steady_timer m_reconnectTimer; }; #endif diff --git a/src/net/serverlobbythread.h b/src/net/serverlobbythread.h index c26486b7..7886d398 100644 --- a/src/net/serverlobbythread.h +++ b/src/net/serverlobbythread.h @@ -34,6 +34,7 @@ #define _SERVERLOBBYTHREAD_H_ #include +#include #include #include @@ -268,9 +269,9 @@ private: boost::shared_ptr m_chatCleanerManager; boost::shared_ptr m_database; - boost::asio::deadline_timer m_removeGameTimer; - boost::asio::deadline_timer m_saveStatisticsTimer; - boost::asio::deadline_timer m_loginLockTimer; + boost::asio::steady_timer m_removeGameTimer; + boost::asio::steady_timer m_saveStatisticsTimer; + boost::asio::steady_timer m_loginLockTimer; boost::uuids::random_generator m_sessionIdGenerator; diff --git a/src/net/sessiondata.h b/src/net/sessiondata.h index 48d94d9b..d9b502ac 100644 --- a/src/net/sessiondata.h +++ b/src/net/sessiondata.h @@ -36,6 +36,7 @@ typedef unsigned SessionId; #include +#include #include #include #include @@ -144,9 +145,9 @@ private: bool m_wantsLobbyMsg; unsigned m_activityTimeoutSec; unsigned m_activityWarningRemainingSec; - boost::asio::deadline_timer m_initTimeoutTimer; - boost::asio::deadline_timer m_globalTimeoutTimer; - boost::asio::deadline_timer m_activityTimeoutTimer; + boost::asio::steady_timer m_initTimeoutTimer; + boost::asio::steady_timer m_globalTimeoutTimer; + boost::asio::steady_timer m_activityTimeoutTimer; SessionDataCallback &m_callback; Gsasl_session *m_authSession; int m_curAuthStep; diff --git a/src/net/socket_msg.h b/src/net/socket_msg.h index d65fe604..0dcf9e7b 100644 --- a/src/net/socket_msg.h +++ b/src/net/socket_msg.h @@ -61,6 +61,8 @@ #define ERR_SOCK_TRANSFER_INVALID_URL 26 #define ERR_SOCK_TRANSFER_SELECT_FAILED 27 #define ERR_SOCK_TRANSFER_FAILED 28 +#define ERR_SOCK_CONNECT_IPV6_FAILED 29 +#define ERR_SOCK_CONNECT_IPV6_TIMEOUT 30 // The following errors are game errors. #define ERR_NET_VERSION_NOT_SUPPORTED 101 #define ERR_NET_SERVER_MAINTENANCE 102