diff --git a/pokerth_game.pro b/pokerth_game.pro index 646af685..a1e3d263 100644 --- a/pokerth_game.pro +++ b/pokerth_game.pro @@ -199,8 +199,7 @@ HEADERS += src/game.h \ src/gui/qt/internetgamelogindialog/internetgamelogindialogimpl.h \ src/engine/local_engine/replay.h \ src/gui/qt/gamelobbydialog/mynicklistsortfilterproxymodel.h \ - src/gui/qt/gametable/myslider.h \ - src/engine/local_engine/log.h + src/gui/qt/gametable/myslider.h FORMS += src/gui/qt/gametable.ui \ src/gui/qt/aboutpokerth.ui \ src/gui/qt/connecttoserverdialog.ui \ @@ -268,8 +267,7 @@ SOURCES += src/pokerth.cpp \ src/gui/qt/gamelobbydialog/mygamelistsortfilterproxymodel.cpp \ src/gui/qt/internetgamelogindialog/internetgamelogindialogimpl.cpp \ src/engine/local_engine/replay.cpp \ - src/gui/qt/gamelobbydialog/mynicklistsortfilterproxymodel.cpp \ - src/engine/local_engine/log.cpp + src/gui/qt/gamelobbydialog/mynicklistsortfilterproxymodel.cpp TRANSLATIONS = ts/pokerth_af.ts \ ts/pokerth_bg.ts \ ts/pokerth_zhcn.ts \ diff --git a/pokerth_lib.pro b/pokerth_lib.pro index 0e9adf66..74d9f1d2 100644 --- a/pokerth_lib.pro +++ b/pokerth_lib.pro @@ -126,7 +126,7 @@ HEADERS += \ src/engine/local_engine/localbero.h \ src/engine/local_engine/localexception.h \ src/engine/local_engine/arraydata.h \ - src/engine/local_engine/log.h \ + src/engine/log.h \ src/engine/network_engine/clientboard.h \ src/engine/network_engine/clientenginefactory.h \ src/engine/network_engine/clienthand.h \ @@ -174,7 +174,7 @@ SOURCES += \ src/engine/local_engine/localbero.cpp \ src/engine/local_engine/localexception.cpp \ src/engine/local_engine/arraydata.cpp \ - src/engine/local_engine/log.cpp \ + src/engine/log.cpp \ src/engine/network_engine/clientboard.cpp \ src/engine/network_engine/clientenginefactory.cpp \ src/engine/network_engine/clienthand.cpp \ diff --git a/src/engine/enginefactory.h b/src/engine/enginefactory.h index 3b844d84..3e1736db 100644 --- a/src/engine/enginefactory.h +++ b/src/engine/enginefactory.h @@ -24,14 +24,14 @@ #include "handinterface.h" #include "playerinterface.h" #include "berointerface.h" - +#include "log.h" class EngineFactory{ public: virtual ~EngineFactory(); - virtual HandInterface* createHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC) =0; + virtual HandInterface* createHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, Log *l, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC) =0; virtual BoardInterface* createBoard() =0; virtual boost::shared_ptr createPlayer(BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB) =0; virtual std::vector > createBeRo(HandInterface* hi, int id, unsigned dP, int sB) =0; diff --git a/src/engine/local_engine/localenginefactory.cpp b/src/engine/local_engine/localenginefactory.cpp index 425b3aaa..5f229fae 100644 --- a/src/engine/local_engine/localenginefactory.cpp +++ b/src/engine/local_engine/localenginefactory.cpp @@ -42,7 +42,11 @@ LocalEngineFactory::~LocalEngineFactory() } -HandInterface* LocalEngineFactory::createHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC) { return new LocalHand(f, g, b, sl, apl, rpl, id, sP, dP, sB, sC); } +HandInterface* +LocalEngineFactory::createHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, Log *l, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC) +{ + return new LocalHand(f, g, b, l, sl, apl, rpl, id, sP, dP, sB, sC); +} BoardInterface* LocalEngineFactory::createBoard() { return new LocalBoard; } diff --git a/src/engine/local_engine/localenginefactory.h b/src/engine/local_engine/localenginefactory.h index 903ad10f..765b3899 100644 --- a/src/engine/local_engine/localenginefactory.h +++ b/src/engine/local_engine/localenginefactory.h @@ -37,7 +37,7 @@ public: LocalEngineFactory(ConfigFile*); ~LocalEngineFactory(); - HandInterface* createHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC); + HandInterface* createHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, Log *l, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC); BoardInterface* createBoard(); boost::shared_ptr createPlayer(BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB); std::vector > createBeRo(HandInterface* hi, int id, unsigned dP, int sB); diff --git a/src/engine/local_engine/localhand.cpp b/src/engine/local_engine/localhand.cpp index 515674eb..e27a0d76 100755 --- a/src/engine/local_engine/localhand.cpp +++ b/src/engine/local_engine/localhand.cpp @@ -30,8 +30,8 @@ using namespace std; -LocalHand::LocalHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, unsigned dP, int sB,int sC) -: myFactory(f), myGui(g), myBoard(b), seatsList(sl), activePlayerList(apl), runningPlayerList(rpl), myBeRo(0), myID(id), startQuantityPlayers(sP), dealerPosition(dP), currentRound(0), smallBlind(sB), startCash(sC), lastPlayersTurn(-1), lastActionPlayer(0), allInCondition(false), +LocalHand::LocalHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, Log *l, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, unsigned dP, int sB,int sC) +: myFactory(f), myGui(g), myBoard(b), myLog(l), seatsList(sl), activePlayerList(apl), runningPlayerList(rpl), myBeRo(0), myID(id), startQuantityPlayers(sP), dealerPosition(dP), smallBlindPosition(dP), bigBlindPosition(dP), currentRound(0), smallBlind(sB), startCash(sC), lastPlayersTurn(-1), lastActionPlayer(0), allInCondition(false), cardsShown(false), bettingRoundsPlayed(0) { @@ -358,6 +358,8 @@ LocalHand::LocalHand(boost::shared_ptr f, GuiInterface *g, BoardI // determine dealer, SB, BB assignButtons(); + myLog->logNewHandMsg(myID, dealerPosition, smallBlind, smallBlindPosition, 2*smallBlind, bigBlindPosition, seatsList); + myBeRo = myFactory->createBeRo(this, myID, dealerPosition, smallBlind); } @@ -426,10 +428,12 @@ void LocalHand::assignButtons() { nextActivePlayerFound = true; if(activePlayerList->size() > 2) { //small blind normal - (*it)->setMyButton(2); + (*it)->setMyButton(2); + smallBlindPosition = (*it)->getMyUniqueID(); } else { //big blind in heads up (*it)->setMyButton(3); + bigBlindPosition = (*it)->getMyUniqueID(); // lastPlayerAction for showing cards } @@ -442,9 +446,11 @@ void LocalHand::assignButtons() { if(activePlayerList->size() > 2) { //big blind normal (*it)->setMyButton(3); + bigBlindPosition = (*it)->getMyUniqueID(); } else { //small blind in heads up (*it)->setMyButton(2); + smallBlindPosition = (*it)->getMyUniqueID(); } break; diff --git a/src/engine/local_engine/localhand.h b/src/engine/local_engine/localhand.h index ff7c5aa5..2d5d628f 100755 --- a/src/engine/local_engine/localhand.h +++ b/src/engine/local_engine/localhand.h @@ -31,10 +31,11 @@ #include #include +class Log; class LocalHand : public HandInterface{ public: - LocalHand(boost::shared_ptr f, GuiInterface*, BoardInterface*, PlayerList, PlayerList, PlayerList, int, int, unsigned, int, int); + LocalHand(boost::shared_ptr f, GuiInterface*, BoardInterface*, Log*, PlayerList, PlayerList, PlayerList, int, int, unsigned, int, int); ~LocalHand(); void start(); @@ -98,16 +99,19 @@ private: boost::shared_ptr myFactory; GuiInterface *myGui; BoardInterface *myBoard; + Log *myLog; - PlayerList seatsList; // all player - PlayerList activePlayerList; // all player who are not out - PlayerList runningPlayerList; // all player who are not folded, not all in and not out + PlayerList seatsList; // all player + PlayerList activePlayerList; // all player who are not out + PlayerList runningPlayerList; // all player who are not folded, not all in and not out std::vector > myBeRo; int myID; int startQuantityPlayers; unsigned dealerPosition; + unsigned smallBlindPosition; + unsigned bigBlindPosition; int currentRound; //0 = preflop, 1 = flop, 2 = turn, 3 = river int smallBlind; int startCash; diff --git a/src/engine/local_engine/log.cpp b/src/engine/log.cpp similarity index 79% rename from src/engine/local_engine/log.cpp rename to src/engine/log.cpp index 6fd6e80b..8f19015a 100644 --- a/src/engine/local_engine/log.cpp +++ b/src/engine/log.cpp @@ -29,7 +29,7 @@ using namespace std; -Log::Log(ConfigFile *c) : myConfig(c) +Log::Log(ConfigFile *c) : myConfig(c), curGameID(0) { if(SQLITE_LOG) { @@ -159,18 +159,20 @@ Log::~Log() void Log::logNewGameMsg(int gameID, int startCash, int startSmallBlind, unsigned dealerPosition, PlayerList seatsList) { - if(SQLITE_LOG) { + curGameID = gameID; - PlayerListConstIterator it_c; + if(SQLITE_LOG) { if(myConfig->readConfigInt("LogOnOff")) { //if write logfiles is enabled + PlayerListConstIterator it_c; string sql; int i; char *errmsg; if( mySqliteLogDb != 0 ) { + // sqlite-db is open sql = "INSERT INTO Game ("; sql += "GameID"; @@ -181,11 +183,10 @@ Log::logNewGameMsg(int gameID, int startCash, int startSmallBlind, unsigned deal sql += ",Seat_" + boost::lexical_cast(i); } sql += ") VALUES ("; - sql += boost::lexical_cast(gameID); + sql += boost::lexical_cast(curGameID); sql += "," + boost::lexical_cast(startCash); sql += "," + boost::lexical_cast(startSmallBlind); sql += "," + boost::lexical_cast(dealerPosition); - for(it_c = seatsList->begin();it_c!=seatsList->end();it_c++) { if((*it_c)->getMyActiveStatus()) { sql += ",\"" + (*it_c)->getMyName() +"\""; @@ -202,6 +203,60 @@ Log::logNewGameMsg(int gameID, int startCash, int startSmallBlind, unsigned deal } } +void +Log::logNewHandMsg(int handID, unsigned dealerPosition, int smallBlind, unsigned smallBlindPosition, int bigBlind, unsigned bigBlindPosition, PlayerList seatsList) { + + if(SQLITE_LOG) { + + if(myConfig->readConfigInt("LogOnOff")) { + //if write logfiles is enabled + + PlayerListConstIterator it_c; + string sql; + int i; + char *errmsg; + + if( mySqliteLogDb != 0 ) { + // sqlite-db is open + + sql = "INSERT INTO Hand ("; + sql += "HandID"; + sql += ",GameID"; + 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(handID); + sql += "," + boost::lexical_cast(curGameID); + sql += "," + boost::lexical_cast(dealerPosition+1); + sql += "," + boost::lexical_cast(smallBlind); + sql += "," + boost::lexical_cast(smallBlindPosition+1); + sql += "," + boost::lexical_cast(bigBlind); + sql += "," + boost::lexical_cast(bigBlindPosition+1); + for(it_c = seatsList->begin();it_c!=seatsList->end();it_c++) { + if((*it_c)->getMyActiveStatus()) { + sql += "," + boost::lexical_cast((*it_c)->getMyCash()); + } else { + sql += ",NULL"; + } + } + sql += ")"; + if(sqlite3_exec(mySqliteLogDb, sql.data(), 0, 0, &errmsg) != SQLITE_OK) { + cout << "Error in statement: " << sql.data() << "[" << errmsg << "]." << endl; + } + + } + + } + + } +} + //void //Log::closeLogDbAtExit() //{ diff --git a/src/engine/local_engine/log.h b/src/engine/log.h similarity index 91% rename from src/engine/local_engine/log.h rename to src/engine/log.h index 1eea1771..b62e70d6 100644 --- a/src/engine/local_engine/log.h +++ b/src/engine/log.h @@ -40,12 +40,14 @@ public: ~Log(); void logNewGameMsg(int gameID, int startCash, int startSmallBlind, unsigned dealerPosition, PlayerList seatsList); + void logNewHandMsg(int handID, unsigned dealerPosition, int smallBlind, unsigned smallBlindPosition, int bigBlind, unsigned bigBlindPosition, PlayerList seatsList); // void closeLogDbAtExit(); private: ConfigFile *myConfig; sqlite3 *mySqliteLogDb; + int curGameID; }; diff --git a/src/engine/network_engine/clientenginefactory.cpp b/src/engine/network_engine/clientenginefactory.cpp index 43c0442d..e1374cec 100644 --- a/src/engine/network_engine/clientenginefactory.cpp +++ b/src/engine/network_engine/clientenginefactory.cpp @@ -35,9 +35,9 @@ ClientEngineFactory::~ClientEngineFactory() } -HandInterface* ClientEngineFactory::createHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC) +HandInterface* ClientEngineFactory::createHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, Log *l, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC) { - return new ClientHand(f, g, b, sl, apl, rpl, id, sP, dP, sB, sC); + return new ClientHand(f, g, b, l, sl, apl, rpl, id, sP, dP, sB, sC); } BoardInterface* ClientEngineFactory::createBoard() diff --git a/src/engine/network_engine/clientenginefactory.h b/src/engine/network_engine/clientenginefactory.h index 9243702d..b5e85d1d 100644 --- a/src/engine/network_engine/clientenginefactory.h +++ b/src/engine/network_engine/clientenginefactory.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -37,7 +38,7 @@ public: ClientEngineFactory(); ~ClientEngineFactory(); - HandInterface* createHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC); + HandInterface* createHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, Log *l, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC); BoardInterface* createBoard(); boost::shared_ptr createPlayer(BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB); std::vector > createBeRo(HandInterface* hi, int id, unsigned dP, int sB); diff --git a/src/engine/network_engine/clienthand.cpp b/src/engine/network_engine/clienthand.cpp index 5612d24d..5f36f497 100644 --- a/src/engine/network_engine/clienthand.cpp +++ b/src/engine/network_engine/clienthand.cpp @@ -21,8 +21,8 @@ using namespace std; -ClientHand::ClientHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC) -: myFactory(f), myGui(g), myBoard(b), seatsList(sl), activePlayerList(apl), runningPlayerList(rpl), myID(id), startQuantityPlayers(sP), dealerPosition(dP), currentRound(0), +ClientHand::ClientHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, Log *l, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC) +: myFactory(f), myGui(g), myBoard(b), myLog(l), seatsList(sl), activePlayerList(apl), runningPlayerList(rpl), myID(id), startQuantityPlayers(sP), dealerPosition(dP), currentRound(0), smallBlind(sB), startCash(sC), lastPlayersTurn(-1), allInCondition(0), cardsShown(false), bettingRoundsPlayed(0) { diff --git a/src/engine/network_engine/clienthand.h b/src/engine/network_engine/clienthand.h index ee3b97c6..aeab1db5 100644 --- a/src/engine/network_engine/clienthand.h +++ b/src/engine/network_engine/clienthand.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -32,7 +33,7 @@ class ClientHand : public HandInterface { public: - ClientHand ( boost::shared_ptr f, GuiInterface*, BoardInterface*, PlayerList, PlayerList, PlayerList , int, int, int, int, int ); + ClientHand ( boost::shared_ptr f, GuiInterface*, BoardInterface*, Log*, PlayerList, PlayerList, PlayerList , int, int, int, int, int ); ~ClientHand(); void start(); @@ -98,6 +99,7 @@ class ClientHand : public HandInterface boost::shared_ptr myFactory; GuiInterface *myGui; BoardInterface *myBoard; + Log *myLog; PlayerList seatsList; PlayerList activePlayerList; diff --git a/src/game.cpp b/src/game.cpp index d8325284..06b96056 100755 --- a/src/game.cpp +++ b/src/game.cpp @@ -174,7 +174,7 @@ void Game::initHand() (*runningPlayerList) = (*activePlayerList); // create Hand - currentHand = myFactory->createHand(myFactory, myGui, currentBoard, seatsList, activePlayerList, runningPlayerList, currentHandID, startQuantityPlayers, dealerPosition, currentSmallBlind, startCash); + currentHand = myFactory->createHand(myFactory, myGui, currentBoard, myLog, seatsList, activePlayerList, runningPlayerList, currentHandID, startQuantityPlayers, dealerPosition, currentSmallBlind, startCash); // shifting dealer button -> TODO exception-rule !!! bool nextDealerFound = false;