putting log from local_engine to engine; implementing hand-logging
This commit is contained in:
@@ -42,7 +42,11 @@ LocalEngineFactory::~LocalEngineFactory()
|
||||
}
|
||||
|
||||
|
||||
HandInterface* LocalEngineFactory::createHand(boost::shared_ptr<EngineFactory> 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<EngineFactory> 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; }
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ public:
|
||||
LocalEngineFactory(ConfigFile*);
|
||||
~LocalEngineFactory();
|
||||
|
||||
HandInterface* createHand(boost::shared_ptr<EngineFactory> 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<EngineFactory> 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<PlayerInterface> createPlayer(BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB);
|
||||
std::vector<boost::shared_ptr<BeRoInterface> > createBeRo(HandInterface* hi, int id, unsigned dP, int sB);
|
||||
|
||||
@@ -30,8 +30,8 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
LocalHand::LocalHand(boost::shared_ptr<EngineFactory> 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<EngineFactory> 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<EngineFactory> 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;
|
||||
|
||||
@@ -31,10 +31,11 @@
|
||||
#include <handinterface.h>
|
||||
#include <berointerface.h>
|
||||
|
||||
class Log;
|
||||
|
||||
class LocalHand : public HandInterface{
|
||||
public:
|
||||
LocalHand(boost::shared_ptr<EngineFactory> f, GuiInterface*, BoardInterface*, PlayerList, PlayerList, PlayerList, int, int, unsigned, int, int);
|
||||
LocalHand(boost::shared_ptr<EngineFactory> f, GuiInterface*, BoardInterface*, Log*, PlayerList, PlayerList, PlayerList, int, int, unsigned, int, int);
|
||||
~LocalHand();
|
||||
|
||||
void start();
|
||||
@@ -98,16 +99,19 @@ private:
|
||||
boost::shared_ptr<EngineFactory> 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<boost::shared_ptr<BeRoInterface> > 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;
|
||||
|
||||
@@ -1,214 +0,0 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2006 by FThauer FHammer *
|
||||
* f.thauer@web.de *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#include <sqlite3.h>
|
||||
#include <iostream>
|
||||
#include <dirent.h>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include "configfile.h"
|
||||
#include "game_defs.h"
|
||||
#include "log.h"
|
||||
#include "playerinterface.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
Log::Log(ConfigFile *c) : myConfig(c)
|
||||
{
|
||||
|
||||
if(SQLITE_LOG) {
|
||||
|
||||
// logging activated
|
||||
if(myConfig->readConfigInt("LogOnOff")) {
|
||||
|
||||
DIR *logDir;
|
||||
logDir = opendir(myConfig->readConfigString("LogDir").c_str());
|
||||
|
||||
// check if logging path exist
|
||||
if(myConfig->readConfigString("LogDir") != "" && logDir) {
|
||||
|
||||
int i;
|
||||
string sql;
|
||||
char *errmsg;
|
||||
|
||||
// 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);
|
||||
|
||||
string mySqliteLogFileName = boost::lexical_cast<string>(myConfig->readConfigString("LogDir").c_str());
|
||||
mySqliteLogFileName += "pokerth-log-" + boost::lexical_cast<string>(curDateTime) + ".pdb";
|
||||
|
||||
// open sqlite-db
|
||||
sqlite3_open(mySqliteLogFileName.data(), &mySqliteLogDb);
|
||||
if( mySqliteLogDb != 0 ) {
|
||||
|
||||
// create session table
|
||||
sql = "CREATE TABLE Session (";
|
||||
sql += "PokerTH_Version TEXT NOT NULL";
|
||||
sql += ",Date TEXT NOT NULL";
|
||||
sql += ",Time TEXT NOT NULL";
|
||||
sql += ", PRIMARY KEY(Date,Time))";
|
||||
if(sqlite3_exec(mySqliteLogDb, sql.data(), 0, 0, &errmsg) != SQLITE_OK) {
|
||||
cout << "Error in statement: " << sql.data() << "[" << errmsg << "]." << endl;
|
||||
}
|
||||
|
||||
sql = "INSERT INTO Session (";
|
||||
sql += "PokerTH_Version";
|
||||
sql += ",Date";
|
||||
sql += ",Time";
|
||||
sql += ") VALUES (";
|
||||
sql += "\"" + boost::lexical_cast<string>(POKERTH_BETA_RELEASE_STRING) + "\",";
|
||||
sql += "\"" + boost::lexical_cast<string>(curDate) + "\",";
|
||||
sql += "\"" + boost::lexical_cast<string>(curTime) + "\")";
|
||||
if(sqlite3_exec(mySqliteLogDb, sql.data(), 0, 0, &errmsg) != SQLITE_OK) {
|
||||
cout << "Error in statement: " << sql.data() << "[" << errmsg << "]." << endl;
|
||||
}
|
||||
|
||||
// create game table
|
||||
sql = "CREATE TABLE Game (";
|
||||
sql += "GameID INTEGER NOT NULL PRIMARY KEY";
|
||||
sql += ",Startmoney INTEGER NOT NULL";
|
||||
sql += ",StartSb INTEGER NOT NULL";
|
||||
sql += ",DealerPos INTEGER NOT NULL";
|
||||
for(i=1; i<=MAX_NUMBER_OF_PLAYERS; i++) {
|
||||
sql += ",Seat_" + boost::lexical_cast<std::string>(i) + " TEXT";
|
||||
}
|
||||
sql += ",Winner_Seat INTEGER";
|
||||
sql += ")";
|
||||
if(sqlite3_exec(mySqliteLogDb, sql.data(), 0, 0, &errmsg) != SQLITE_OK) {
|
||||
cout << "Error in statement: " << sql.data() << "[" << errmsg << "]." << endl;
|
||||
}
|
||||
|
||||
// create hand table
|
||||
sql = "CREATE TABLE Hand (";
|
||||
sql += "HandID INTEGER NOT NULL";
|
||||
sql += ",GameID 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<std::string>(i) + "_Cash INTEGER";
|
||||
sql += ",Seat_" + boost::lexical_cast<std::string>(i) + "_Card_1 INTEGER";
|
||||
sql += ",Seat_" + boost::lexical_cast<std::string>(i) + "_Card_2 INTEGER";
|
||||
sql += ",Seat_" + boost::lexical_cast<std::string>(i) + "_Hand_text TEXT";
|
||||
sql += ",Seat_" + boost::lexical_cast<std::string>(i) + "_Hand_int INTEGER";
|
||||
}
|
||||
for(i=1; i<=5; i++) {
|
||||
sql += ",BoardCard_" + boost::lexical_cast<std::string>(i) + " INTEGER";
|
||||
}
|
||||
sql += ",PRIMARY KEY(HandID,GameID))";
|
||||
if(sqlite3_exec(mySqliteLogDb, sql.data(), 0, 0, &errmsg) != SQLITE_OK) {
|
||||
cout << "Error in statement: " << sql.data() << "[" << errmsg << "]." << endl;
|
||||
}
|
||||
|
||||
// create action table
|
||||
sql = "CREATE TABLE Action (";
|
||||
sql += "ActionID INTEGER PRIMARY KEY AUTOINCREMENT";
|
||||
sql += ",HandID INTEGER NOT NULL";
|
||||
sql += ",GameID INTEGER NOT NULL";
|
||||
sql += ",BeRo INTEGER NOT NULL";
|
||||
sql += ",Player INTEGER NOT NULL";
|
||||
sql += ",Action TEXT NOT NULL";
|
||||
sql += ",Amount INTEGER";
|
||||
sql += ")";
|
||||
if(sqlite3_exec(mySqliteLogDb, sql.data(), 0, 0, &errmsg) != SQLITE_OK) {
|
||||
cout << "Error in statement: " << sql.data() << "[" << errmsg << "]." << endl;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Log::~Log()
|
||||
{
|
||||
if(SQLITE_LOG) {
|
||||
sqlite3_close(mySqliteLogDb);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Log::logNewGameMsg(int gameID, int startCash, int startSmallBlind, unsigned dealerPosition, PlayerList seatsList) {
|
||||
|
||||
if(SQLITE_LOG) {
|
||||
|
||||
PlayerListConstIterator it_c;
|
||||
|
||||
if(myConfig->readConfigInt("LogOnOff")) {
|
||||
//if write logfiles is enabled
|
||||
|
||||
string sql;
|
||||
int i;
|
||||
char *errmsg;
|
||||
|
||||
if( mySqliteLogDb != 0 ) {
|
||||
|
||||
sql = "INSERT INTO Game (";
|
||||
sql += "GameID";
|
||||
sql += ",Startmoney";
|
||||
sql += ",StartSb";
|
||||
sql += ",DealerPos";
|
||||
for(i=1; i<=MAX_NUMBER_OF_PLAYERS; i++) {
|
||||
sql += ",Seat_" + boost::lexical_cast<std::string>(i);
|
||||
}
|
||||
sql += ") VALUES (";
|
||||
sql += boost::lexical_cast<string>(gameID);
|
||||
sql += "," + boost::lexical_cast<string>(startCash);
|
||||
sql += "," + boost::lexical_cast<string>(startSmallBlind);
|
||||
sql += "," + boost::lexical_cast<string>(dealerPosition);
|
||||
|
||||
for(it_c = seatsList->begin();it_c!=seatsList->end();it_c++) {
|
||||
if((*it_c)->getMyActiveStatus()) {
|
||||
sql += ",\"" + (*it_c)->getMyName() +"\"";
|
||||
} 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()
|
||||
//{
|
||||
// if(SQLITE_LOG) {
|
||||
// // close sqlite-db
|
||||
// sqlite3_close(mySqliteLogDb);
|
||||
// mySqliteLogDb = NULL;
|
||||
// }
|
||||
|
||||
//}
|
||||
@@ -1,52 +0,0 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2006 by FThauer FHammer *
|
||||
* f.thauer@web.de *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef LOG_H
|
||||
#define LOG_H
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <list>
|
||||
|
||||
struct sqlite3;
|
||||
class ConfigFile;
|
||||
class PlayerInterface;
|
||||
|
||||
typedef boost::shared_ptr<std::list<boost::shared_ptr<PlayerInterface> > > PlayerList;
|
||||
typedef std::list<boost::shared_ptr<PlayerInterface> >::iterator PlayerListIterator;
|
||||
typedef std::list<boost::shared_ptr<PlayerInterface> >::const_iterator PlayerListConstIterator;
|
||||
|
||||
class Log
|
||||
{
|
||||
|
||||
public:
|
||||
Log(ConfigFile *c);
|
||||
|
||||
~Log();
|
||||
|
||||
void logNewGameMsg(int gameID, int startCash, int startSmallBlind, unsigned dealerPosition, PlayerList seatsList);
|
||||
// void closeLogDbAtExit();
|
||||
|
||||
|
||||
private:
|
||||
ConfigFile *myConfig;
|
||||
sqlite3 *mySqliteLogDb;
|
||||
|
||||
};
|
||||
|
||||
#endif // LOG_H
|
||||
Reference in New Issue
Block a user