diff --git a/pokerth.pro b/pokerth.pro index 181b1e2d..6fb899a9 100755 --- a/pokerth.pro +++ b/pokerth.pro @@ -1,8 +1,17 @@ # QMake pro-file for PokerTH TEMPLATE = subdirs -SUBDIRS = pokerth_protocol.pro pokerth_db.pro pokerth_lib.pro pokerth_game.pro -!mac:!gui_800x480:!client { +SUBDIRS = pokerth_protocol.pro pokerth_db.pro pokerth_lib.pro +official_server { + SUBDIRS += pokerth_dbofficial.pro +} +qml-client{ + SUBDIRS += pokerth_qml-client.pro +} +!qml-client{ + SUBDIRS += pokerth_game.pro +} +!mac:!gui_800x480:!client:!qml-client { SUBDIRS += pokerth_server.pro chatcleaner.pro } CONFIG += ordered diff --git a/pokerth_dbofficial.pro b/pokerth_dbofficial.pro new file mode 100644 index 00000000..6dd7a128 --- /dev/null +++ b/pokerth_dbofficial.pro @@ -0,0 +1,92 @@ +# QMake pro-file for PokerTH official server DB backend +TEMPLATE = lib +CODECFORSRC = UTF-8 +CONFIG += staticlib \ + thread \ + exceptions \ + rtti \ + stl \ + warn_on +UI_DIR = uics +TARGET = lib/pokerth_dbofficial +MOC_DIR = mocs +OBJECTS_DIR = obj +QT -= core \ + gui + +# PRECOMPILED_HEADER = dbofficial/pch_lib.h +INCLUDEPATH += . \ + ./src +DEPENDPATH += . \ + ./src + +# Input +HEADERS += src/dbofficial/asyncdbauth.h \ + src/dbofficial/asyncdbcreategame.h \ + src/dbofficial/asyncdbgameplace.h \ + src/dbofficial/asyncdbupdatescore.h \ + src/dbofficial/asyncdbquery.h \ + src/dbofficial/serverdbthread.h \ + src/dbofficial/serverdbfactoryinternal.h \ + src/dbofficial/compositeasyncdbquery.h \ + src/dbofficial/singleasyncdbquery.h \ + src/dbofficial/querycontext.h \ + src/dbofficial/asyncdbendgame.h \ + src/dbofficial/db_table_defs.h \ + src/dbofficial/asyncdblogin.h \ + src/dbofficial/asyncdbreportavatar.h \ + src/dbofficial/asyncdbreportgame.h \ + src/dbofficial/asyncdbavatarblacklist.h \ + src/dbofficial/asyncdbadminplayers.h \ + src/dbofficial/asyncdbblockplayer.h \ + src/dbofficial/dbidmanager.h +SOURCES += src/dbofficial/asyncdbauth.cpp \ + src/dbofficial/asyncdbcreategame.cpp \ + src/dbofficial/asyncdbgameplace.cpp \ + src/dbofficial/asyncdbupdatescore.cpp \ + src/dbofficial/asyncdbquery.cpp \ + src/dbofficial/serverdbthread.cpp \ + src/dbofficial/serverdbfactoryinternal.cpp \ + src/dbofficial/singleasyncdbquery.cpp \ + src/dbofficial/compositeasyncdbquery.cpp \ + src/dbofficial/querycontext.cpp \ + src/dbofficial/asyncdbendgame.cpp \ + src/dbofficial/asyncdblogin.cpp \ + src/dbofficial/asyncdbreportavatar.cpp \ + src/dbofficial/asyncdbreportgame.cpp \ + src/dbofficial/asyncdbavatarblacklist.cpp \ + src/dbofficial/asyncdbadminplayers.cpp \ + src/dbofficial/asyncdbblockplayer.cpp \ + src/dbofficial/dbidmanager.cpp +win32 { + DEFINES += _WIN32_WINNT=0x0501 + INCLUDEPATH += ../../../boost/ \ + ../../../GnuTLS/include \ + ../../../curl/include \ + ../../../mysql/include \ + ../../../mysql++/lib \ + ../../../zlib +} +!win32 { + # #### My release static build options + # QMAKE_CXXFLAGS += -ffunction-sections -fdata-sections + INCLUDEPATH += /usr/include \ + /usr/include/mysql \ + /usr/include/mysql++ + INCLUDEPATH += /opt/boost/include +} +mac { + # make it universal + CONFIG += x86 + CONFIG -= ppc + QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.4 + + # for universal-compilation on PPC-Mac uncomment the following line + # on Intel-Mac you have to comment this line out or build will fail. + # QMAKE_MAC_SDK=/Developer/SDKs/MacOSX10.4u.sdk/ + INCLUDEPATH += /Developer/SDKs/MacOSX10.5.sdk/usr/include/ + INCLUDEPATH += /Library/Frameworks/SDL.framework/Headers + INCLUDEPATH += /Library/Frameworks/SDL_mixer.framework/Headers + INCLUDEPATH += /opt/local/include/mysql++ \ + /opt/local/include/mysql5/mysql +} diff --git a/pokerth_game.pro b/pokerth_game.pro index d660452e..1cfb45ca 100644 --- a/pokerth_game.pro +++ b/pokerth_game.pro @@ -601,7 +601,7 @@ mac { OTHER_FILES += docs/infomessage-id-desc.txt official_server { LIBPATH += pkth_stat/daemon_lib/lib - LIBS += -lpokerth_closed \ + LIBS += -lpokerth_dbofficial \ -lmysqlpp DEFINES += POKERTH_OFFICIAL_SERVER } diff --git a/pokerth_server.pro b/pokerth_server.pro index fd54b637..05bca1c4 100644 --- a/pokerth_server.pro +++ b/pokerth_server.pro @@ -322,7 +322,7 @@ mac { official_server { LIBPATH += pkth_stat/daemon_lib/lib - LIBS += -lpokerth_closed -lmysqlpp + LIBS += -lpokerth_dbofficial -lmysqlpp DEFINES += POKERTH_OFFICIAL_SERVER } diff --git a/src/dbofficial/asyncdbadminplayers.cpp b/src/dbofficial/asyncdbadminplayers.cpp new file mode 100644 index 00000000..304b8b25 --- /dev/null +++ b/src/dbofficial/asyncdbadminplayers.cpp @@ -0,0 +1,76 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ + +#include +#include + + +using namespace std; + + +AsyncDBAdminPlayers::AsyncDBAdminPlayers(unsigned queryId, const string &preparedName) + : SingleAsyncDBQuery(queryId, preparedName, list()) +{ +} + +AsyncDBAdminPlayers::~AsyncDBAdminPlayers() +{ +} + +void +AsyncDBAdminPlayers::Init(DBIdManager& /*idManager*/) +{ +} + +void +AsyncDBAdminPlayers::HandleResult(mysqlpp::Query &/*query*/, DBIdManager& /*idManager*/, mysqlpp::StoreQueryResult& result, boost::asio::io_service &service, ServerDBCallback &cb) +{ + list adminPlayers; + for (size_t i = 0; i < result.num_rows(); ++i) { + if (!result[i].empty()) { + adminPlayers.push_back(result[i][0]); + } + } + service.post(boost::bind(&ServerDBCallback::PlayerAdminList, &cb, GetId(), adminPlayers)); +} + +void +AsyncDBAdminPlayers::HandleNoResult(mysqlpp::Query &/*query*/, DBIdManager& /*idManager*/, boost::asio::io_service &service, ServerDBCallback &cb) +{ + // This query should always produce a result. + HandleError(service, cb); +} + +void +AsyncDBAdminPlayers::HandleError(boost::asio::io_service &service, ServerDBCallback &cb) +{ + service.post(boost::bind(&ServerDBCallback::QueryError, &cb, "AsyncDBAdminPlayers: Failure.")); +} diff --git a/src/dbofficial/asyncdbadminplayers.h b/src/dbofficial/asyncdbadminplayers.h new file mode 100644 index 00000000..89cf425d --- /dev/null +++ b/src/dbofficial/asyncdbadminplayers.h @@ -0,0 +1,57 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ +/* Async database query for all admin players. */ + +#ifndef _ASYNCDBADMINPLAYERS_H_ +#define _ASYNCDBADMINPLAYERS_H_ + +#include + + +class AsyncDBAdminPlayers : public SingleAsyncDBQuery +{ +public: + AsyncDBAdminPlayers(unsigned queryId, const std::string &preparedName); + virtual ~AsyncDBAdminPlayers(); + + virtual void Init(DBIdManager& idManager); + + virtual void HandleResult(mysqlpp::Query &query, DBIdManager& idManager, mysqlpp::StoreQueryResult& result, boost::asio::io_service &service, ServerDBCallback &cb); + virtual void HandleNoResult(mysqlpp::Query &query, DBIdManager& idManager, boost::asio::io_service &service, ServerDBCallback &cb); + virtual void HandleError(boost::asio::io_service &service, ServerDBCallback &cb); + + virtual bool RequiresResultSet() const + { + return true; + } +}; + +#endif diff --git a/src/dbofficial/asyncdbauth.cpp b/src/dbofficial/asyncdbauth.cpp new file mode 100644 index 00000000..f5c9c448 --- /dev/null +++ b/src/dbofficial/asyncdbauth.cpp @@ -0,0 +1,84 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ + +#include +#include + + +using namespace std; + + +AsyncDBAuth::AsyncDBAuth(unsigned queryId, const string &preparedName, const list ¶ms) + : SingleAsyncDBQuery(queryId, preparedName, params) +{ +} + +AsyncDBAuth::~AsyncDBAuth() +{ +} + +void +AsyncDBAuth::HandleResult(mysqlpp::Query &/*query*/, DBIdManager& /*idManager*/, mysqlpp::StoreQueryResult& result, boost::asio::io_service &service, ServerDBCallback &cb) +{ + if (result.num_rows() != 1) { + service.post(boost::bind(&ServerDBCallback::PlayerLoginFailed, &cb, GetId())); + } else { + int valid = result[0][2]; + int active = result[0][5]; + if ((valid != 1) || (active != 1)) { + service.post(boost::bind(&ServerDBCallback::PlayerLoginBlocked, &cb, GetId())); + } else { + mysqlpp::String secret(result[0][1]); + mysqlpp::String country(result[0][3]); + mysqlpp::String last_login(result[0][4]); + boost::shared_ptr tmpData(new DBPlayerData); + tmpData->id = result[0][0]; + secret.to_string(tmpData->secret); + if (!country.is_null()) + country.to_string(tmpData->country); + last_login.to_string(tmpData->last_login); + + service.post(boost::bind(&ServerDBCallback::PlayerLoginSuccess, &cb, GetId(), tmpData)); + } + } +} + +void +AsyncDBAuth::HandleNoResult(mysqlpp::Query &/*query*/, DBIdManager& /*idManager*/, boost::asio::io_service &service, ServerDBCallback &cb) +{ + HandleError(service, cb); +} + +void +AsyncDBAuth::HandleError(boost::asio::io_service &service, ServerDBCallback &cb) +{ + service.post(boost::bind(&ServerDBCallback::PlayerLoginFailed, &cb, GetId())); +} diff --git a/src/dbofficial/asyncdbauth.h b/src/dbofficial/asyncdbauth.h new file mode 100644 index 00000000..d775a9d9 --- /dev/null +++ b/src/dbofficial/asyncdbauth.h @@ -0,0 +1,57 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ +/* Async database auth query. */ + +#ifndef _ASYNCDBAUTH_H_ +#define _ASYNCDBAUTH_H_ + +#include + + +class AsyncDBAuth : public SingleAsyncDBQuery +{ +public: + AsyncDBAuth(unsigned queryId, const std::string &preparedName, const std::list ¶ms); + virtual ~AsyncDBAuth(); + + virtual void Init(DBIdManager& /*idManager*/) {} + + virtual void HandleResult(mysqlpp::Query &query, DBIdManager& idManager, mysqlpp::StoreQueryResult& result, boost::asio::io_service &service, ServerDBCallback &cb); + virtual void HandleNoResult(mysqlpp::Query &query, DBIdManager& idManager, boost::asio::io_service &service, ServerDBCallback &cb); + virtual void HandleError(boost::asio::io_service &service, ServerDBCallback &cb); + + virtual bool RequiresResultSet() const + { + return true; + } +}; + +#endif diff --git a/src/dbofficial/asyncdbavatarblacklist.cpp b/src/dbofficial/asyncdbavatarblacklist.cpp new file mode 100644 index 00000000..16800007 --- /dev/null +++ b/src/dbofficial/asyncdbavatarblacklist.cpp @@ -0,0 +1,68 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ + +#include +#include + + +using namespace std; + + +AsyncDBAvatarBlacklist::AsyncDBAvatarBlacklist(unsigned queryId, const string &preparedName, const list ¶ms) + : SingleAsyncDBQuery(queryId, preparedName, params) +{ +} + +AsyncDBAvatarBlacklist::~AsyncDBAvatarBlacklist() +{ +} + +void +AsyncDBAvatarBlacklist::HandleResult(mysqlpp::Query &/*query*/, DBIdManager& /*idManager*/, mysqlpp::StoreQueryResult& result, boost::asio::io_service &service, ServerDBCallback &cb) +{ + if (result.num_rows() == 0) + service.post(boost::bind(&ServerDBCallback::AvatarIsOK, &cb, GetId())); + else + service.post(boost::bind(&ServerDBCallback::AvatarIsBlacklisted, &cb, GetId())); +} + +void +AsyncDBAvatarBlacklist::HandleNoResult(mysqlpp::Query &/*query*/, DBIdManager& /*idManager*/, boost::asio::io_service &service, ServerDBCallback &cb) +{ + HandleError(service, cb); +} + +void +AsyncDBAvatarBlacklist::HandleError(boost::asio::io_service &service, ServerDBCallback &cb) +{ + // If query failed: Avatar is blacklisted. + service.post(boost::bind(&ServerDBCallback::AvatarIsBlacklisted, &cb, GetId())); +} diff --git a/src/dbofficial/asyncdbavatarblacklist.h b/src/dbofficial/asyncdbavatarblacklist.h new file mode 100644 index 00000000..09f75b74 --- /dev/null +++ b/src/dbofficial/asyncdbavatarblacklist.h @@ -0,0 +1,57 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ +/* Async database avatar blacklist query. */ + +#ifndef _ASYNCDBAVATARBLACKLIST_H_ +#define _ASYNCDBAVATARBLACKLIST_H_ + +#include + + +class AsyncDBAvatarBlacklist : public SingleAsyncDBQuery +{ +public: + AsyncDBAvatarBlacklist(unsigned queryId, const std::string &preparedName, const std::list ¶ms); + virtual ~AsyncDBAvatarBlacklist(); + + virtual void Init(DBIdManager& /*idManager*/) {} + + virtual void HandleResult(mysqlpp::Query &query, DBIdManager& /*idManager*/, mysqlpp::StoreQueryResult& result, boost::asio::io_service &service, ServerDBCallback &cb); + virtual void HandleNoResult(mysqlpp::Query &query, DBIdManager& /*idManager*/, boost::asio::io_service &service, ServerDBCallback &cb); + virtual void HandleError(boost::asio::io_service &service, ServerDBCallback &cb); + + virtual bool RequiresResultSet() const + { + return true; + } +}; + +#endif diff --git a/src/dbofficial/asyncdbblockplayer.cpp b/src/dbofficial/asyncdbblockplayer.cpp new file mode 100644 index 00000000..e1caf369 --- /dev/null +++ b/src/dbofficial/asyncdbblockplayer.cpp @@ -0,0 +1,71 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ + +#include +#include +#include + + +using namespace std; + + +AsyncDBBlockPlayer::AsyncDBBlockPlayer(unsigned queryId, unsigned replyId, const string &preparedName, const list ¶ms) + : SingleAsyncDBQuery(queryId, preparedName, params), m_replyId(replyId) +{ +} + +AsyncDBBlockPlayer::~AsyncDBBlockPlayer() +{ +} + +void +AsyncDBBlockPlayer::Init(DBIdManager &/*idManager*/) +{ +} + +void +AsyncDBBlockPlayer::HandleResult(mysqlpp::Query &/*query*/, DBIdManager &/*idManager*/, mysqlpp::StoreQueryResult &/*result*/, boost::asio::io_service &service, ServerDBCallback &cb) +{ + // This query does not produce a result. + HandleError(service, cb); +} + +void +AsyncDBBlockPlayer::HandleNoResult(mysqlpp::Query &/*query*/, DBIdManager &/*idManager*/, boost::asio::io_service &service, ServerDBCallback &cb) +{ + service.post(boost::bind(&ServerDBCallback::BlockPlayerSuccess, &cb, GetId(), m_replyId)); +} + +void +AsyncDBBlockPlayer::HandleError(boost::asio::io_service &service, ServerDBCallback &cb) +{ + service.post(boost::bind(&ServerDBCallback::BlockPlayerFailed, &cb, GetId(), m_replyId)); +} diff --git a/src/dbofficial/asyncdbblockplayer.h b/src/dbofficial/asyncdbblockplayer.h new file mode 100644 index 00000000..4c1bd103 --- /dev/null +++ b/src/dbofficial/asyncdbblockplayer.h @@ -0,0 +1,60 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ +/* Async database update to block a player. */ + +#ifndef _ASYNCDBBLOCKPLAYER_H_ +#define _ASYNCDBBLOCKPLAYER_H_ + +#include + + +class AsyncDBBlockPlayer : public SingleAsyncDBQuery +{ +public: + AsyncDBBlockPlayer(unsigned queryId, unsigned replyId, const std::string &preparedName, const std::list ¶ms); + virtual ~AsyncDBBlockPlayer(); + + virtual void Init(DBIdManager& idManager); + + virtual void HandleResult(mysqlpp::Query &query, DBIdManager& idManager, mysqlpp::StoreQueryResult& result, boost::asio::io_service &service, ServerDBCallback &cb); + virtual void HandleNoResult(mysqlpp::Query &query, DBIdManager& idManager, boost::asio::io_service &service, ServerDBCallback &cb); + virtual void HandleError(boost::asio::io_service &service, ServerDBCallback &cb); + + virtual bool RequiresResultSet() const + { + return false; + } + +private: + unsigned m_replyId; +}; + +#endif diff --git a/src/dbofficial/asyncdbcreategame.cpp b/src/dbofficial/asyncdbcreategame.cpp new file mode 100644 index 00000000..656ca0da --- /dev/null +++ b/src/dbofficial/asyncdbcreategame.cpp @@ -0,0 +1,76 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ + +#include +#include +#include + + +using namespace std; + + +AsyncDBCreateGame::AsyncDBCreateGame(unsigned queryId, const string &preparedName, const list ¶ms) + : SingleAsyncDBQuery(queryId, preparedName, params) +{ +} + +AsyncDBCreateGame::~AsyncDBCreateGame() +{ +} + +void +AsyncDBCreateGame::HandleResult(mysqlpp::Query &/*query*/, DBIdManager& /*idManager*/, mysqlpp::StoreQueryResult& /*result*/, boost::asio::io_service &service, ServerDBCallback &cb) +{ + // This query does not produce a result. + HandleError(service, cb); +} + +void +AsyncDBCreateGame::HandleNoResult(mysqlpp::Query &query, DBIdManager& idManager, boost::asio::io_service &service, ServerDBCallback &cb) +{ + query.reset(); + query + << "SELECT LAST_INSERT_ID()"; + mysqlpp::StoreQueryResult tmpResult = query.store(); + DB_id insertId = tmpResult[0][0]; + if (!tmpResult || tmpResult.num_rows() != 1 || insertId == 0) { + service.post(boost::bind(&ServerDBCallback::CreateGameFailed, &cb, GetId())); + } else { + service.post(boost::bind(&ServerDBCallback::CreateGameSuccess, &cb, GetId())); + idManager.AddGameId(GetId(), insertId); + } +} + +void +AsyncDBCreateGame::HandleError(boost::asio::io_service &service, ServerDBCallback &cb) +{ + service.post(boost::bind(&ServerDBCallback::CreateGameFailed, &cb, GetId())); +} diff --git a/src/dbofficial/asyncdbcreategame.h b/src/dbofficial/asyncdbcreategame.h new file mode 100644 index 00000000..15bd8983 --- /dev/null +++ b/src/dbofficial/asyncdbcreategame.h @@ -0,0 +1,57 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ +/* Async database create game query. */ + +#ifndef _ASYNCDBCREATEGAME_H_ +#define _ASYNCDBCREATEGAME_H_ + +#include + + +class AsyncDBCreateGame : public SingleAsyncDBQuery +{ +public: + AsyncDBCreateGame(unsigned queryId, const std::string &preparedName, const std::list ¶ms); + virtual ~AsyncDBCreateGame(); + + virtual void Init(DBIdManager& /*idManager*/) {} + + virtual void HandleResult(mysqlpp::Query &query, DBIdManager& idManager, mysqlpp::StoreQueryResult& result, boost::asio::io_service &service, ServerDBCallback &cb); + virtual void HandleNoResult(mysqlpp::Query &query, DBIdManager& idManager, boost::asio::io_service &service, ServerDBCallback &cb); + virtual void HandleError(boost::asio::io_service &service, ServerDBCallback &cb); + + virtual bool RequiresResultSet() const + { + return false; + } +}; + +#endif diff --git a/src/dbofficial/asyncdbendgame.cpp b/src/dbofficial/asyncdbendgame.cpp new file mode 100644 index 00000000..44da5d06 --- /dev/null +++ b/src/dbofficial/asyncdbendgame.cpp @@ -0,0 +1,77 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ + +#include +#include + + +using namespace std; + + +AsyncDBEndGame::AsyncDBEndGame(unsigned queryId, const string &preparedName, const std::list ¶ms) + : SingleAsyncDBQuery(queryId, preparedName, params) +{ +} + +AsyncDBEndGame::~AsyncDBEndGame() +{ +} + +void +AsyncDBEndGame::Init(DBIdManager& idManager) +{ + std::list params; + GetParams(params); + ostringstream paramStream; + paramStream << idManager.GetGameDBId(GetId()); + // Add game id as last parameter (where-clause). + params.push_back(paramStream.str()); + SetParams(params); +} + +void +AsyncDBEndGame::HandleResult(mysqlpp::Query &/*query*/, DBIdManager& /*idManager*/, mysqlpp::StoreQueryResult& /*result*/, boost::asio::io_service &service, ServerDBCallback &cb) +{ + // This query does not produce a result. + HandleError(service, cb); +} + +void +AsyncDBEndGame::HandleNoResult(mysqlpp::Query &/*query*/, DBIdManager& /*idManager*/, boost::asio::io_service &/*service*/, ServerDBCallback &/*cb*/) +{ + // Nothing to do. +} + +void +AsyncDBEndGame::HandleError(boost::asio::io_service &/*service*/, ServerDBCallback &/*cb*/) +{ + // Ignore errors for now (as nothing important is done). +} diff --git a/src/dbofficial/asyncdbendgame.h b/src/dbofficial/asyncdbendgame.h new file mode 100644 index 00000000..d14ecd5f --- /dev/null +++ b/src/dbofficial/asyncdbendgame.h @@ -0,0 +1,57 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ +/* Async database end game query. */ + +#ifndef _ASYNCDBENDGAME_H_ +#define _ASYNCDBENDGAME_H_ + +#include + + +class AsyncDBEndGame : public SingleAsyncDBQuery +{ +public: + AsyncDBEndGame(unsigned queryId, const std::string &preparedName, const std::list ¶ms); + virtual ~AsyncDBEndGame(); + + virtual void Init(DBIdManager& idManager); + + virtual void HandleResult(mysqlpp::Query &query, DBIdManager& idManager, mysqlpp::StoreQueryResult& result, boost::asio::io_service &service, ServerDBCallback &cb); + virtual void HandleNoResult(mysqlpp::Query &query, DBIdManager& idManager, boost::asio::io_service &service, ServerDBCallback &cb); + virtual void HandleError(boost::asio::io_service &service, ServerDBCallback &cb); + + virtual bool RequiresResultSet() const + { + return false; + } +}; + +#endif diff --git a/src/dbofficial/asyncdbgameplace.cpp b/src/dbofficial/asyncdbgameplace.cpp new file mode 100644 index 00000000..46e86d50 --- /dev/null +++ b/src/dbofficial/asyncdbgameplace.cpp @@ -0,0 +1,78 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ + +#include +#include +#include + + +using namespace std; + + +AsyncDBGamePlace::AsyncDBGamePlace(unsigned queryId, const string &preparedName, const list ¶ms) + : SingleAsyncDBQuery(queryId, preparedName, params) +{ +} + +AsyncDBGamePlace::~AsyncDBGamePlace() +{ +} + +void +AsyncDBGamePlace::Init(DBIdManager& idManager) +{ + std::list params; + GetParams(params); + ostringstream paramStream; + paramStream << idManager.GetGameDBId(GetId()); + // Add game id as first parameter (according to the order in insert). + params.push_front(paramStream.str()); + SetParams(params); +} + +void +AsyncDBGamePlace::HandleResult(mysqlpp::Query &/*query*/, DBIdManager& /*idManager*/, mysqlpp::StoreQueryResult& /*result*/, boost::asio::io_service &service, ServerDBCallback &cb) +{ + // This query does not produce a result. + HandleError(service, cb); +} + +void +AsyncDBGamePlace::HandleNoResult(mysqlpp::Query &/*query*/, DBIdManager& /*idManager*/, boost::asio::io_service &/*service*/, ServerDBCallback &/*cb*/) +{ + // No action required. +} + +void +AsyncDBGamePlace::HandleError(boost::asio::io_service &service, ServerDBCallback &cb) +{ + service.post(boost::bind(&ServerDBCallback::QueryError, &cb, "AsyncDBGamePlace: Failure.")); +} diff --git a/src/dbofficial/asyncdbgameplace.h b/src/dbofficial/asyncdbgameplace.h new file mode 100644 index 00000000..071623b4 --- /dev/null +++ b/src/dbofficial/asyncdbgameplace.h @@ -0,0 +1,57 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ +/* Async database set place query. */ + +#ifndef _ASYNCDBGAMEPLACE_H_ +#define _ASYNCDBGAMEPLACE_H_ + +#include + + +class AsyncDBGamePlace : public SingleAsyncDBQuery +{ +public: + AsyncDBGamePlace(unsigned queryId, const std::string &preparedName, const std::list ¶ms); + virtual ~AsyncDBGamePlace(); + + virtual void Init(DBIdManager& idManager); + + virtual void HandleResult(mysqlpp::Query &query, DBIdManager& idManager, mysqlpp::StoreQueryResult& result, boost::asio::io_service &service, ServerDBCallback &cb); + virtual void HandleNoResult(mysqlpp::Query &query, DBIdManager& idManager, boost::asio::io_service &service, ServerDBCallback &cb); + virtual void HandleError(boost::asio::io_service &service, ServerDBCallback &cb); + + virtual bool RequiresResultSet() const + { + return false; + } +}; + +#endif diff --git a/src/dbofficial/asyncdblogin.cpp b/src/dbofficial/asyncdblogin.cpp new file mode 100644 index 00000000..ad44cb95 --- /dev/null +++ b/src/dbofficial/asyncdblogin.cpp @@ -0,0 +1,65 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ + +#include +#include + + +using namespace std; + + +AsyncDBLogin::AsyncDBLogin(unsigned queryId, const string &preparedName, const list ¶ms) + : SingleAsyncDBQuery(queryId, preparedName, params) +{ +} + +AsyncDBLogin::~AsyncDBLogin() +{ +} + +void +AsyncDBLogin::HandleResult(mysqlpp::Query &/*query*/, DBIdManager& /*idManager*/, mysqlpp::StoreQueryResult& /*result*/, boost::asio::io_service &service, ServerDBCallback &cb) +{ + // This query does not produce a result. + HandleError(service, cb); +} + +void +AsyncDBLogin::HandleNoResult(mysqlpp::Query &/*query*/, DBIdManager& /*idManager*/, boost::asio::io_service &/*service*/, ServerDBCallback &/*cb*/) +{ + // No action required. +} + +void +AsyncDBLogin::HandleError(boost::asio::io_service &service, ServerDBCallback &cb) +{ + service.post(boost::bind(&ServerDBCallback::QueryError, &cb, "AsyncDBLogin: Failure.")); +} diff --git a/src/dbofficial/asyncdblogin.h b/src/dbofficial/asyncdblogin.h new file mode 100644 index 00000000..3e171415 --- /dev/null +++ b/src/dbofficial/asyncdblogin.h @@ -0,0 +1,57 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ +/* Async database login query. */ + +#ifndef _ASYNCDBLOGIN_H_ +#define _ASYNCDBLOGIN_H_ + +#include + + +class AsyncDBLogin : public SingleAsyncDBQuery +{ +public: + AsyncDBLogin(unsigned queryId, const std::string &preparedName, const std::list ¶ms); + virtual ~AsyncDBLogin(); + + virtual void Init(DBIdManager& /*idManager*/) {} + + virtual void HandleResult(mysqlpp::Query &query, DBIdManager& idManager, mysqlpp::StoreQueryResult& result, boost::asio::io_service &service, ServerDBCallback &cb); + virtual void HandleNoResult(mysqlpp::Query &query, DBIdManager& idManager, boost::asio::io_service &service, ServerDBCallback &cb); + virtual void HandleError(boost::asio::io_service &service, ServerDBCallback &cb); + + virtual bool RequiresResultSet() const + { + return false; + } +}; + +#endif diff --git a/src/dbofficial/asyncdbquery.cpp b/src/dbofficial/asyncdbquery.cpp new file mode 100644 index 00000000..010c3320 --- /dev/null +++ b/src/dbofficial/asyncdbquery.cpp @@ -0,0 +1,40 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ + +#include + + +using namespace std; + + +AsyncDBQuery::~AsyncDBQuery() +{ +} diff --git a/src/dbofficial/asyncdbquery.h b/src/dbofficial/asyncdbquery.h new file mode 100644 index 00000000..373bfa1a --- /dev/null +++ b/src/dbofficial/asyncdbquery.h @@ -0,0 +1,61 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ +/* Async database query. */ + +#ifndef _ASYNCDBQUERY_H_ +#define _ASYNCDBQUERY_H_ + +#include +#include +#include +#include + +class DBIdManager; + +class AsyncDBQuery +{ +public: + virtual ~AsyncDBQuery(); + + virtual void Init(DBIdManager& idManager) = 0; + + virtual std::string GetPreparedName() const = 0; + virtual void GetParams(std::list ¶ms) const = 0; + virtual void SetParams(const std::list ¶ms) = 0; + + virtual void HandleResult(mysqlpp::Query &query, DBIdManager& idManager, mysqlpp::StoreQueryResult& result, boost::asio::io_service &service, ServerDBCallback &cb) = 0; + virtual void HandleNoResult(mysqlpp::Query &query, DBIdManager& idManager, boost::asio::io_service &service, ServerDBCallback &cb) = 0; + virtual void HandleError(boost::asio::io_service &service, ServerDBCallback &cb) = 0; + virtual bool RequiresResultSet() const = 0; + virtual bool Next() = 0; +}; + +#endif diff --git a/src/dbofficial/asyncdbreportavatar.cpp b/src/dbofficial/asyncdbreportavatar.cpp new file mode 100644 index 00000000..4982594e --- /dev/null +++ b/src/dbofficial/asyncdbreportavatar.cpp @@ -0,0 +1,65 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ + +#include +#include + + +using namespace std; + + +AsyncDBReportAvatar::AsyncDBReportAvatar(unsigned queryId, unsigned replyId, const string &preparedName, const list ¶ms) + : SingleAsyncDBQuery(queryId, preparedName, params), m_replyId(replyId) +{ +} + +AsyncDBReportAvatar::~AsyncDBReportAvatar() +{ +} + +void +AsyncDBReportAvatar::HandleResult(mysqlpp::Query &/*query*/, DBIdManager& /*idManager*/, mysqlpp::StoreQueryResult& /*result*/, boost::asio::io_service &service, ServerDBCallback &cb) +{ + // This query does not produce a result. + HandleError(service, cb); +} + +void +AsyncDBReportAvatar::HandleNoResult(mysqlpp::Query &/*query*/, DBIdManager& /*idManager*/, boost::asio::io_service &service, ServerDBCallback &cb) +{ + service.post(boost::bind(&ServerDBCallback::ReportAvatarSuccess, &cb, GetId(), m_replyId)); +} + +void +AsyncDBReportAvatar::HandleError(boost::asio::io_service &service, ServerDBCallback &cb) +{ + service.post(boost::bind(&ServerDBCallback::ReportAvatarFailed, &cb, GetId(), m_replyId)); +} diff --git a/src/dbofficial/asyncdbreportavatar.h b/src/dbofficial/asyncdbreportavatar.h new file mode 100644 index 00000000..be0dd35c --- /dev/null +++ b/src/dbofficial/asyncdbreportavatar.h @@ -0,0 +1,60 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ +/* Async database report inappropriate avatar query. */ + +#ifndef _ASYNCDBREPORTAVATAR_H_ +#define _ASYNCDBREPORTAVATAR_H_ + +#include + + +class AsyncDBReportAvatar : public SingleAsyncDBQuery +{ +public: + AsyncDBReportAvatar(unsigned queryId, unsigned replyId, const std::string &preparedName, const std::list ¶ms); + virtual ~AsyncDBReportAvatar(); + + virtual void Init(DBIdManager& /*idManager*/) {} + + virtual void HandleResult(mysqlpp::Query &query, DBIdManager& idManager, mysqlpp::StoreQueryResult& result, boost::asio::io_service &service, ServerDBCallback &cb); + virtual void HandleNoResult(mysqlpp::Query &query, DBIdManager& idManager, boost::asio::io_service &service, ServerDBCallback &cb); + virtual void HandleError(boost::asio::io_service &service, ServerDBCallback &cb); + + virtual bool RequiresResultSet() const + { + return false; + } + +private: + unsigned m_replyId; +}; + +#endif diff --git a/src/dbofficial/asyncdbreportgame.cpp b/src/dbofficial/asyncdbreportgame.cpp new file mode 100644 index 00000000..2a3387d4 --- /dev/null +++ b/src/dbofficial/asyncdbreportgame.cpp @@ -0,0 +1,83 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ + +#include +#include +#include + + +using namespace std; + + +AsyncDBReportGame::AsyncDBReportGame(unsigned queryId, unsigned replyId, unsigned gameId, const string &preparedName, const list ¶ms) + : SingleAsyncDBQuery(queryId, preparedName, params), m_replyId(replyId), m_gameId(gameId) +{ +} + +AsyncDBReportGame::~AsyncDBReportGame() +{ +} + +void +AsyncDBReportGame::Init(DBIdManager& idManager) +{ + std::list params; + GetParams(params); + ostringstream paramStream; + unsigned tmpGameId = idManager.GetGameDBId(m_gameId); + if (tmpGameId) { + paramStream << idManager.GetGameDBId(m_gameId); + // Add game id as last parameter (where-clause). + params.push_back(paramStream.str()); + } else { + params.push_back("NULL"); + } + SetParams(params); +} + +void +AsyncDBReportGame::HandleResult(mysqlpp::Query &/*query*/, DBIdManager& /*idManager*/, mysqlpp::StoreQueryResult& /*result*/, boost::asio::io_service &service, ServerDBCallback &cb) +{ + // This query does not produce a result. + HandleError(service, cb); +} + +void +AsyncDBReportGame::HandleNoResult(mysqlpp::Query &/*query*/, DBIdManager& /*idManager*/, boost::asio::io_service &service, ServerDBCallback &cb) +{ + service.post(boost::bind(&ServerDBCallback::ReportGameSuccess, &cb, GetId(), m_replyId)); +} + +void +AsyncDBReportGame::HandleError(boost::asio::io_service &service, ServerDBCallback &cb) +{ + service.post(boost::bind(&ServerDBCallback::ReportGameFailed, &cb, GetId(), m_replyId)); +} diff --git a/src/dbofficial/asyncdbreportgame.h b/src/dbofficial/asyncdbreportgame.h new file mode 100644 index 00000000..a6acde1f --- /dev/null +++ b/src/dbofficial/asyncdbreportgame.h @@ -0,0 +1,61 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ +/* Async database report inappropriate avatar query. */ + +#ifndef _ASYNCDBREPORTGAME_H_ +#define _ASYNCDBREPORTGAME_H_ + +#include + + +class AsyncDBReportGame : public SingleAsyncDBQuery +{ +public: + AsyncDBReportGame(unsigned queryId, unsigned replyId, unsigned gameId, const std::string &preparedName, const std::list ¶ms); + virtual ~AsyncDBReportGame(); + + virtual void Init(DBIdManager& idManager); + + virtual void HandleResult(mysqlpp::Query &query, DBIdManager& idManager, mysqlpp::StoreQueryResult& result, boost::asio::io_service &service, ServerDBCallback &cb); + virtual void HandleNoResult(mysqlpp::Query &query, DBIdManager& idManager, boost::asio::io_service &service, ServerDBCallback &cb); + virtual void HandleError(boost::asio::io_service &service, ServerDBCallback &cb); + + virtual bool RequiresResultSet() const + { + return false; + } + +private: + unsigned m_replyId; + unsigned m_gameId; +}; + +#endif diff --git a/src/dbofficial/asyncdbupdatescore.cpp b/src/dbofficial/asyncdbupdatescore.cpp new file mode 100644 index 00000000..5f4b62f4 --- /dev/null +++ b/src/dbofficial/asyncdbupdatescore.cpp @@ -0,0 +1,80 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ + +#include +#include + + +using namespace std; + + +AsyncDBUpdateScore::AsyncDBUpdateScore(unsigned queryId, const string &preparedName, const std::list ¶ms) + : SingleAsyncDBQuery(queryId, preparedName, params) +{ +} + +AsyncDBUpdateScore::~AsyncDBUpdateScore() +{ +} + +void +AsyncDBUpdateScore::Init(DBIdManager& idManager) +{ + std::list params; + GetParams(params); + ostringstream paramStream; + paramStream << idManager.GetGameDBId(GetId()); + // Add game id as first parameter (param for stored procedure). + params.push_front(paramStream.str()); + SetParams(params); + // Ensure that "update score" is only called once for a game. + // This game id cannot be used any more, without re-init. + idManager.RemoveGameId(GetId()); +} + +void +AsyncDBUpdateScore::HandleResult(mysqlpp::Query &/*query*/, DBIdManager& /*idManager*/, mysqlpp::StoreQueryResult& /*result*/, boost::asio::io_service &service, ServerDBCallback &cb) +{ + // This query does not produce a result. + HandleError(service, cb); +} + +void +AsyncDBUpdateScore::HandleNoResult(mysqlpp::Query &/*query*/, DBIdManager& idManager, boost::asio::io_service &/*service*/, ServerDBCallback &/*cb*/) +{ + idManager.RemoveGameId(GetId()); +} + +void +AsyncDBUpdateScore::HandleError(boost::asio::io_service &/*service*/, ServerDBCallback &/*cb*/) +{ + // Ignore errors for now (as nothing important is done). +} diff --git a/src/dbofficial/asyncdbupdatescore.h b/src/dbofficial/asyncdbupdatescore.h new file mode 100644 index 00000000..3dfbf3af --- /dev/null +++ b/src/dbofficial/asyncdbupdatescore.h @@ -0,0 +1,57 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ +/* Async database query to update the score. */ + +#ifndef _ASYNCDBUPDATESCORE_H_ +#define _ASYNCDBUPDATESCORE_H_ + +#include + + +class AsyncDBUpdateScore : public SingleAsyncDBQuery +{ +public: + AsyncDBUpdateScore(unsigned queryId, const std::string &preparedName, const std::list ¶ms); + virtual ~AsyncDBUpdateScore(); + + virtual void Init(DBIdManager& idManager); + + virtual void HandleResult(mysqlpp::Query &query, DBIdManager& idManager, mysqlpp::StoreQueryResult& result, boost::asio::io_service &service, ServerDBCallback &cb); + virtual void HandleNoResult(mysqlpp::Query &query, DBIdManager& idManager, boost::asio::io_service &service, ServerDBCallback &cb); + virtual void HandleError(boost::asio::io_service &service, ServerDBCallback &cb); + + virtual bool RequiresResultSet() const + { + return false; + } +}; + +#endif diff --git a/src/dbofficial/compositeasyncdbquery.cpp b/src/dbofficial/compositeasyncdbquery.cpp new file mode 100644 index 00000000..fbe3dfa7 --- /dev/null +++ b/src/dbofficial/compositeasyncdbquery.cpp @@ -0,0 +1,120 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ + +#include + + +using namespace std; + + +CompositeAsyncDBQuery::CompositeAsyncDBQuery(const AsyncQueryList &queries) + : m_list(queries), m_errorFlag(false), m_lastGameDBId(0) +{ + m_currentQuery = m_list.begin(); +} + +CompositeAsyncDBQuery::~CompositeAsyncDBQuery() +{ +} + +void +CompositeAsyncDBQuery::Init(DBIdManager& idManager) +{ + (*m_currentQuery)->Init(idManager); +} + +std::string +CompositeAsyncDBQuery::GetPreparedName() const +{ + return (*m_currentQuery)->GetPreparedName(); +} + +void +CompositeAsyncDBQuery::GetParams(std::list ¶ms) const +{ + (*m_currentQuery)->GetParams(params); +} + +void +CompositeAsyncDBQuery::SetParams(const std::list ¶ms) +{ + (*m_currentQuery)->SetParams(params); +} + +void +CompositeAsyncDBQuery::HandleResult(mysqlpp::Query &query, DBIdManager& idManager, mysqlpp::StoreQueryResult& result, boost::asio::io_service &service, ServerDBCallback &cb) +{ + (*m_currentQuery)->HandleResult(query, idManager, result, service, cb); +} + +void +CompositeAsyncDBQuery::HandleNoResult(mysqlpp::Query &query, DBIdManager& idManager, boost::asio::io_service &service, ServerDBCallback &cb) +{ + (*m_currentQuery)->HandleNoResult(query, idManager, service, cb); +} + +void +CompositeAsyncDBQuery::HandleError(boost::asio::io_service &service, ServerDBCallback &cb) +{ + (*m_currentQuery)->HandleError(service, cb); + m_errorFlag = true; +} + +bool +CompositeAsyncDBQuery::RequiresResultSet() const +{ + return (*m_currentQuery)->RequiresResultSet(); +} + +bool +CompositeAsyncDBQuery::Next() +{ + bool retVal = false; + AsyncQueryList::iterator pos = m_currentQuery; + ++pos; + if (!m_errorFlag && pos != m_list.end()) { + m_currentQuery = pos; + retVal = true; + } + return retVal; +} + +unsigned +CompositeAsyncDBQuery::GetLastGameDBId() const +{ + return m_lastGameDBId; +} + +void +CompositeAsyncDBQuery::SetLastGameDBId(unsigned id) +{ + m_lastGameDBId = id; +} diff --git a/src/dbofficial/compositeasyncdbquery.h b/src/dbofficial/compositeasyncdbquery.h new file mode 100644 index 00000000..62c4daeb --- /dev/null +++ b/src/dbofficial/compositeasyncdbquery.h @@ -0,0 +1,72 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ +/* Composite async database query. */ + +#ifndef _COMPOSITEASYNCDBQUERY_H_ +#define _COMPOSITEASYNCDBQUERY_H_ + +#include +#include + + +class CompositeAsyncDBQuery : public AsyncDBQuery, public QueryContext +{ +public: + typedef std::list > AsyncQueryList; + // Note: This list must contain at least one query. + CompositeAsyncDBQuery(const AsyncQueryList &queries); + virtual ~CompositeAsyncDBQuery(); + + virtual void Init(DBIdManager& idManager); + + virtual std::string GetPreparedName() const; + virtual void GetParams(std::list ¶ms) const; + virtual void SetParams(const std::list ¶ms); + + virtual void HandleResult(mysqlpp::Query &query, DBIdManager& idManager, mysqlpp::StoreQueryResult& result, boost::asio::io_service &service, ServerDBCallback &cb); + virtual void HandleNoResult(mysqlpp::Query &query, DBIdManager& idManager, boost::asio::io_service &service, ServerDBCallback &cb); + // One error will cancel the rest of the composite query. + virtual void HandleError(boost::asio::io_service &service, ServerDBCallback &cb); + + virtual bool RequiresResultSet() const; + virtual bool Next(); + + virtual unsigned GetLastGameDBId() const; + virtual void SetLastGameDBId(unsigned id); + +private: + AsyncQueryList m_list; + AsyncQueryList::iterator m_currentQuery; + bool m_errorFlag; + unsigned m_lastGameDBId; +}; + +#endif diff --git a/src/dbofficial/db_table_defs.h b/src/dbofficial/db_table_defs.h new file mode 100644 index 00000000..7cc8518b --- /dev/null +++ b/src/dbofficial/db_table_defs.h @@ -0,0 +1,78 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ + +#ifndef _DB_TABLE_DEFS_H_ +#define _DB_TABLE_DEFS_H_ + +#define DB_TABLE_PLAYER "player_login" +#define DB_TABLE_PLAYER_COL_ID "id" +#define DB_TABLE_PLAYER_COL_USERNAME "username" +#define DB_TABLE_PLAYER_COL_PASSWORD "password" +#define DB_TABLE_PLAYER_COL_VALID "valid" +#define DB_TABLE_PLAYER_COL_COUNTRY "country" +#define DB_TABLE_PLAYER_COL_LASTLOGIN "last_login" +#define DB_TABLE_PLAYER_COL_ACTIVE "aktivator" +#define DB_TABLE_PLAYER_COL_AVATARHASH "avatar_hash" +#define DB_TABLE_PLAYER_COL_AVATARTYPE "avatar_type" + +#define DB_TABLE_GAME "game" +#define DB_TABLE_GAME_COL_ID "idgame" +#define DB_TABLE_GAME_COL_NAME "name" +#define DB_TABLE_GAME_COL_STARTTIME "start_time" +#define DB_TABLE_GAME_COL_ENDTIME "end_time" + +#define DB_TABLE_GAMEPLAYER "game_has_player" +#define DB_TABLE_GAMEPLAYER_COL_GAMEID "game_idgame" +#define DB_TABLE_GAMEPLAYER_COL_PLAYERID "player_idplayer" +#define DB_TABLE_GAMEPLAYER_COL_PLACE "place" + +#define DB_TABLE_REP_AVATAR "reported_avatar" +#define DB_TABLE_REP_AVATAR_COL_PLAYERID "idplayer" +#define DB_TABLE_REP_AVATAR_COL_AVATARHASH "avatar_hash" +#define DB_TABLE_REP_AVATAR_COL_AVATARTYPE "avatar_type" +#define DB_TABLE_REP_AVATAR_COL_BY_PLAYERID "by_idplayer" +#define DB_TABLE_REP_AVATAR_COL_TIMESTAMP "timestamp" + +#define DB_TABLE_REP_GAME "reported_gamename" +#define DB_TABLE_REP_GAME_COL_CREATOR "game_creator_idplayer" +#define DB_TABLE_REP_GAME_COL_GAMEID "game_idgame" +#define DB_TABLE_REP_GAME_COL_GAMENAME "game_name" +#define DB_TABLE_REP_GAME_COL_BY_PLAYERID "by_idplayer" +#define DB_TABLE_REP_GAME_COL_TIMESTAMP "timestamp" + +#define DB_TABLE_AVATAR_BLACKLIST "avatar_blacklist" +#define DB_TABLE_AVATAR_BLACKLIST_COL_ID "id" +#define DB_TABLE_AVATAR_BLACKLIST_COL_AVATAR_HASH "avatar_hash" + +#define DB_TABLE_ADMIN_PLAYER "admin_player" +#define DB_TABLE_ADMIN_PLAYER_COL_PLAYERID "admin_idplayer" + +#endif // DB_TABLE_DEFS_H diff --git a/src/dbofficial/dbidmanager.cpp b/src/dbofficial/dbidmanager.cpp new file mode 100644 index 00000000..c6e2a6cb --- /dev/null +++ b/src/dbofficial/dbidmanager.cpp @@ -0,0 +1,61 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ + +#include + + +void +DBIdManager::AddGameId(unsigned gameId, DB_id databaseId) +{ + boost::mutex::scoped_lock lock(m_gameIdMapMutex); + m_gameIdMap[gameId] = databaseId; +} + +void +DBIdManager::RemoveGameId(unsigned gameId) +{ + boost::mutex::scoped_lock lock(m_gameIdMapMutex); + m_gameIdMap.erase(gameId); +} + +DB_id +DBIdManager::GetGameDBId(unsigned gameId) const +{ + DB_id retVal = DB_ID_INVALID; + + boost::mutex::scoped_lock lock(m_gameIdMapMutex); + DBMap::const_iterator pos = m_gameIdMap.find(gameId); + if (pos != m_gameIdMap.end()) { + retVal = pos->second; + } + return retVal; +} + diff --git a/src/dbofficial/dbidmanager.h b/src/dbofficial/dbidmanager.h new file mode 100644 index 00000000..2d13d971 --- /dev/null +++ b/src/dbofficial/dbidmanager.h @@ -0,0 +1,56 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ +/* Manager for database internal ids */ + +#ifndef _DBIDMANAGER_H_ +#define _DBIDMANAGER_H_ + +#include +#include +#include + +class DBIdManager +{ +public: + void AddGameId(unsigned gameId, DB_id databaseId); + void RemoveGameId(unsigned gameId); + + DB_id GetGameDBId(unsigned gameId) const; + +protected: + typedef std::map DBMap; + +private: + DBMap m_gameIdMap; + mutable boost::mutex m_gameIdMapMutex; +}; + +#endif // _DBIDMANAGER_H_ diff --git a/src/dbofficial/querycontext.cpp b/src/dbofficial/querycontext.cpp new file mode 100644 index 00000000..7a872597 --- /dev/null +++ b/src/dbofficial/querycontext.cpp @@ -0,0 +1,36 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ + +#include + +QueryContext::~QueryContext() +{ +} diff --git a/src/dbofficial/querycontext.h b/src/dbofficial/querycontext.h new file mode 100644 index 00000000..7cefeb60 --- /dev/null +++ b/src/dbofficial/querycontext.h @@ -0,0 +1,45 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ +/* Interface for a query context */ + +#ifndef _QUERYCONTEXT_H_ +#define _QUERYCONTEXT_H_ + +class QueryContext +{ +public: + virtual ~QueryContext(); + + virtual unsigned GetLastGameDBId() const = 0; + virtual void SetLastGameDBId(unsigned id) = 0; +}; + +#endif // QUERYCONTEXT_H diff --git a/src/dbofficial/serverdbfactoryinternal.cpp b/src/dbofficial/serverdbfactoryinternal.cpp new file mode 100644 index 00000000..9e85f604 --- /dev/null +++ b/src/dbofficial/serverdbfactoryinternal.cpp @@ -0,0 +1,48 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ + +#include +#include + + +ServerDBFactoryInternal::ServerDBFactoryInternal() +{ +} + +ServerDBFactoryInternal::~ServerDBFactoryInternal() +{ +} + +boost::shared_ptr +ServerDBFactoryInternal::CreateServerDBObject(ServerDBCallback &cb, boost::shared_ptr ioService) +{ + return boost::shared_ptr(new ServerDBThread(cb, ioService)); +} diff --git a/src/dbofficial/serverdbfactoryinternal.h b/src/dbofficial/serverdbfactoryinternal.h new file mode 100644 index 00000000..5e390e6e --- /dev/null +++ b/src/dbofficial/serverdbfactoryinternal.h @@ -0,0 +1,53 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ +/* Server database factory for closed source db objects. */ + +#ifndef _SERVERDBFACTORYINTERNAL_H_ +#define _SERVERDBFACTORYINTERNAL_H_ + +#include +#include +#include +#include + +class ServerDBFactoryInternal +{ +public: + ServerDBFactoryInternal(); + virtual ~ServerDBFactoryInternal(); + + virtual boost::shared_ptr CreateServerDBObject( + ServerDBCallback &cb, boost::shared_ptr ioService); +}; + +typedef ServerDBFactoryInternal DBFactory; + +#endif diff --git a/src/dbofficial/serverdbthread.cpp b/src/dbofficial/serverdbthread.cpp new file mode 100644 index 00000000..e720bfae --- /dev/null +++ b/src/dbofficial/serverdbthread.cpp @@ -0,0 +1,557 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define QUERY_NICK_PREPARE "nick_template" +#define QUERY_LOGIN_PREPARE "login_template" +#define QUERY_AVATAR_BLACKLIST_PREPARE "avatar_blacklist_template" +#define QUERY_CREATE_GAME_PREPARE "create_game_template" +#define QUERY_END_GAME_PREPARE "end_game_template" +#define QUERY_GAME_PLAYER_PREPARE "game_player_template" +#define QUERY_UPDATE_SCORE_PREPARE "update_score_template" +#define QUERY_REPORT_AVATAR_PREPARE "report_avatar_template" +#define QUERY_REPORT_GAME_PREPARE "report_game_template" +#define QUERY_ADMIN_PLAYER_PREPARE "admin_player_template" +#define QUERY_BLOCK_PLAYER_PREPARE "block_player_template" + +using namespace std; + +struct DBConnectionData { + DBConnectionData() : conn(false) {} + string host; + string user; + string pwd; + string database; + string encryptionKey; + mysqlpp::Connection conn; +}; + +ServerDBThread::ServerDBThread(ServerDBCallback &cb, boost::shared_ptr ioService) + : m_ioService(ioService), m_semaphore(0), m_callback(cb), m_isConnected(false), m_permanentError(false), m_previouslyConnected(false) +{ + m_connData.reset(new DBConnectionData); +} + +ServerDBThread::~ServerDBThread() +{ +} + +void +ServerDBThread::SignalTermination() +{ + Thread::SignalTermination(); + m_semaphore.post(); +} + +void +ServerDBThread::Init(const string &host, const string &user, const string &pwd, + const string &database, const string &encryptionKey) +{ + m_connData->host = host; + m_connData->user = user; + m_connData->pwd = pwd; + m_connData->database = database; + m_connData->encryptionKey = encryptionKey; +} + +void +ServerDBThread::Start() +{ + Run(); +} + +void +ServerDBThread::Stop() +{ + SignalTermination(); + this->Join(THREAD_WAIT_INFINITE); +} + +void +ServerDBThread::AsyncPlayerLogin(unsigned requestId, const string &playerName) +{ + if (IsConnected()) { + list params; + params.push_back(m_connData->encryptionKey); + params.push_back(playerName); + boost::shared_ptr asyncQuery( + new AsyncDBAuth( + requestId, + QUERY_NICK_PREPARE, + params)); + + { + boost::mutex::scoped_lock lock(m_asyncQueueMutex); + m_asyncQueue.push(asyncQuery); + } + m_semaphore.post(); + } else { + // If not connected to database, login fails. + m_ioService->post(boost::bind(&ServerDBCallback::PlayerLoginFailed, &m_callback, requestId)); + } +} + +void +ServerDBThread::AsyncCheckAvatarBlacklist(unsigned requestId, const std::string &avatarHash) +{ + if (IsConnected()) { + list params; + params.push_back(avatarHash); + boost::shared_ptr asyncQuery( + new AsyncDBAvatarBlacklist( + requestId, + QUERY_AVATAR_BLACKLIST_PREPARE, + params)); + + { + boost::mutex::scoped_lock lock(m_asyncQueueMutex); + m_asyncQueue.push(asyncQuery); + } + m_semaphore.post(); + } else { + // If not connected to database, all avatars are blacklisted. + m_ioService->post(boost::bind(&ServerDBCallback::AvatarIsBlacklisted, &m_callback, requestId)); + } +} + +void +ServerDBThread::PlayerPostLogin(DB_id playerId, const std::string &avatarHash, const std::string &avatarType) +{ + list params; + params.push_back(mysqlpp::DateTime(time(NULL))); + params.push_back(avatarHash); + params.push_back(avatarType); + ostringstream paramStream; + paramStream << playerId; + params.push_back(paramStream.str()); + boost::shared_ptr asyncQuery( + new AsyncDBLogin( + playerId, + QUERY_LOGIN_PREPARE, + params)); + + { + boost::mutex::scoped_lock lock(m_asyncQueueMutex); + m_asyncQueue.push(asyncQuery); + } + m_semaphore.post(); +} + +void +ServerDBThread::PlayerLogout(DB_id /*playerId*/) +{ +} + +void +ServerDBThread::AsyncCreateGame(unsigned requestId, const string &gameName) +{ + list params; + params.push_back(gameName); + params.push_back(mysqlpp::DateTime(time(NULL))); + boost::shared_ptr asyncQuery( + new AsyncDBCreateGame( + requestId, + QUERY_CREATE_GAME_PREPARE, + params)); + + { + boost::mutex::scoped_lock lock(m_asyncQueueMutex); + m_asyncQueue.push(asyncQuery); + } + m_semaphore.post(); +} + +void +ServerDBThread::SetGamePlayerPlace(unsigned requestId, DB_id playerId, unsigned place) +{ + // The game id param is added later (during init of the async op), because it may be unknown. + list params; + ostringstream paramStream; + paramStream << playerId; + params.push_back(paramStream.str()); + paramStream.str(""); + paramStream << place; + params.push_back(paramStream.str()); + boost::shared_ptr asyncQuery( + new AsyncDBGamePlace( + requestId, + QUERY_GAME_PLAYER_PREPARE, + params)); + + { + boost::mutex::scoped_lock lock(m_asyncQueueMutex); + m_asyncQueue.push(asyncQuery); + } + m_semaphore.post(); +} + +void +ServerDBThread::EndGame(unsigned requestId) +{ + // Set the end time of the game. + { + list params; + params.push_back(mysqlpp::DateTime(time(NULL))); + boost::shared_ptr asyncQuery( + new AsyncDBEndGame( + requestId, + QUERY_END_GAME_PREPARE, + params)); + + { + boost::mutex::scoped_lock lock(m_asyncQueueMutex); + m_asyncQueue.push(asyncQuery); + } + m_semaphore.post(); + } + // Update the player scores. + { + list params; + boost::shared_ptr asyncQuery( + new AsyncDBUpdateScore( + requestId, + QUERY_UPDATE_SCORE_PREPARE, + params)); + + { + boost::mutex::scoped_lock lock(m_asyncQueueMutex); + m_asyncQueue.push(asyncQuery); + } + m_semaphore.post(); + } +} + +void +ServerDBThread::AsyncReportAvatar(unsigned requestId, unsigned replyId, DB_id reportedPlayerId, const std::string &avatarHash, const std::string &avatarType, DB_id *byPlayerId) +{ + list params; + ostringstream paramStream; + paramStream << reportedPlayerId; + params.push_back(paramStream.str()); + params.push_back(avatarHash); + params.push_back(avatarType); + if (byPlayerId) { + paramStream.str(""); + paramStream << *byPlayerId; + params.push_back(paramStream.str()); + } else { + params.push_back("NULL"); + } + params.push_back(mysqlpp::DateTime(time(NULL))); + + boost::shared_ptr asyncQuery( + new AsyncDBReportAvatar( + requestId, + replyId, + QUERY_REPORT_AVATAR_PREPARE, + params)); + + { + boost::mutex::scoped_lock lock(m_asyncQueueMutex); + m_asyncQueue.push(asyncQuery); + } + m_semaphore.post(); +} + +void +ServerDBThread::AsyncReportGame(unsigned requestId, unsigned replyId, DB_id *creatorPlayerId, unsigned gameId, const std::string &gameName, DB_id *byPlayerId) +{ + list params; + ostringstream paramStream; + if (creatorPlayerId) { + paramStream << *creatorPlayerId; + params.push_back(paramStream.str()); + } else { + params.push_back("NULL"); + } + params.push_back(gameName); + if (byPlayerId) { + paramStream.str(""); + paramStream << *byPlayerId; + params.push_back(paramStream.str()); + } else { + params.push_back("NULL"); + } + params.push_back(mysqlpp::DateTime(time(NULL))); + + boost::shared_ptr asyncQuery( + new AsyncDBReportGame( + requestId, + replyId, + gameId, + QUERY_REPORT_GAME_PREPARE, + params)); + + { + boost::mutex::scoped_lock lock(m_asyncQueueMutex); + m_asyncQueue.push(asyncQuery); + } + + m_semaphore.post(); +} + +void +ServerDBThread::AsyncQueryAdminPlayers(unsigned requestId) +{ + boost::shared_ptr asyncQuery( + new AsyncDBAdminPlayers( + requestId, + QUERY_ADMIN_PLAYER_PREPARE)); + { + boost::mutex::scoped_lock lock(m_asyncQueueMutex); + m_asyncQueue.push(asyncQuery); + } + + m_semaphore.post(); +} + +void +ServerDBThread::AsyncBlockPlayer(unsigned requestId, unsigned replyId, DB_id playerId, int valid, int active) +{ + list params; + ostringstream paramStream; + paramStream << valid; + params.push_back(paramStream.str()); + paramStream.str(""); + paramStream << active; + params.push_back(paramStream.str()); + paramStream.str(""); + paramStream << playerId; + params.push_back(paramStream.str()); + boost::shared_ptr asyncQuery( + new AsyncDBBlockPlayer( + requestId, + replyId, + QUERY_BLOCK_PLAYER_PREPARE, + params)); + + { + boost::mutex::scoped_lock lock(m_asyncQueueMutex); + m_asyncQueue.push(asyncQuery); + } + m_semaphore.post(); +} + +bool +ServerDBThread::IsConnected() const +{ + boost::mutex::scoped_lock lock(m_isConnectedMutex); + return m_isConnected; +} + +void +ServerDBThread::Main() +{ + while (!ShouldTerminate() && !HasPermanentError()) { + if (HasDBConnection()) { + SetConnected(true); + m_semaphore.wait(); + HandleNextQuery(); + } else { + SetConnected(false); + EstablishDBConnection(); + } + } + m_connData->conn.disconnect(); +} + +bool +ServerDBThread::HasPermanentError() const +{ + return m_permanentError; +} + +bool +ServerDBThread::HasDBConnection() const +{ + return m_connData->conn.connected(); +} + +void +ServerDBThread::EstablishDBConnection() +{ + m_connData->conn.set_option(new mysqlpp::SetCharsetNameOption("utf8")); + if (!m_connData->conn.connect( + m_connData->database.c_str(), m_connData->host.c_str(), m_connData->user.c_str(), m_connData->pwd.c_str())) { + m_ioService->post(boost::bind(&ServerDBCallback::ConnectFailed, &m_callback, m_connData->conn.error())); + if (!m_previouslyConnected) + m_permanentError = true; + else + Msleep(250); + } else { + mysqlpp::Query prepareNick = m_connData->conn.query(); + prepareNick + << "PREPARE " QUERY_NICK_PREPARE " FROM " << mysqlpp::quote + << "SELECT " DB_TABLE_PLAYER_COL_ID ", AES_DECRYPT(" DB_TABLE_PLAYER_COL_PASSWORD ", ?), " DB_TABLE_PLAYER_COL_VALID ", TRIM(" DB_TABLE_PLAYER_COL_COUNTRY "), " DB_TABLE_PLAYER_COL_LASTLOGIN ", " DB_TABLE_PLAYER_COL_ACTIVE " FROM " DB_TABLE_PLAYER " WHERE BINARY " DB_TABLE_PLAYER_COL_USERNAME " = ?"; + mysqlpp::Query prepareAvatarBlacklist = m_connData->conn.query(); + prepareAvatarBlacklist + << "PREPARE " QUERY_AVATAR_BLACKLIST_PREPARE " FROM " << mysqlpp::quote + << "SELECT " DB_TABLE_AVATAR_BLACKLIST_COL_ID " FROM " DB_TABLE_AVATAR_BLACKLIST " WHERE BINARY " DB_TABLE_AVATAR_BLACKLIST_COL_AVATAR_HASH " = ?"; + mysqlpp::Query prepareLogin = m_connData->conn.query(); + prepareLogin + << "PREPARE " QUERY_LOGIN_PREPARE " FROM " << mysqlpp::quote + << "UPDATE " DB_TABLE_PLAYER " SET " DB_TABLE_PLAYER_COL_LASTLOGIN " = ?, " DB_TABLE_PLAYER_COL_AVATARHASH " = ?, " DB_TABLE_PLAYER_COL_AVATARTYPE " = ? WHERE " DB_TABLE_PLAYER_COL_ID " = ?"; + mysqlpp::Query prepareCreateGame = m_connData->conn.query(); + prepareCreateGame + << "PREPARE " QUERY_CREATE_GAME_PREPARE " FROM " << mysqlpp::quote + << "INSERT INTO " DB_TABLE_GAME " (" DB_TABLE_GAME_COL_NAME ", " DB_TABLE_GAME_COL_STARTTIME ") VALUES (?, ?)"; + mysqlpp::Query prepareEndGame = m_connData->conn.query(); + prepareEndGame + << "PREPARE " QUERY_END_GAME_PREPARE " FROM " << mysqlpp::quote + << "UPDATE " DB_TABLE_GAME " SET "DB_TABLE_GAME_COL_ENDTIME " = ? WHERE " DB_TABLE_GAME_COL_ID " = ?"; + mysqlpp::Query prepareRelation = m_connData->conn.query(); + prepareRelation + << "PREPARE " QUERY_GAME_PLAYER_PREPARE " FROM " << mysqlpp::quote + << "INSERT INTO " DB_TABLE_GAMEPLAYER " (" DB_TABLE_GAMEPLAYER_COL_GAMEID ", " DB_TABLE_GAMEPLAYER_COL_PLAYERID ", " DB_TABLE_GAMEPLAYER_COL_PLACE ") VALUES (?, ?, ?)"; + mysqlpp::Query prepareScore = m_connData->conn.query(); + prepareScore + << "PREPARE " QUERY_UPDATE_SCORE_PREPARE " FROM " << mysqlpp::quote + << "CALL updatePointsForGame(?)"; + mysqlpp::Query prepareReportAvatar = m_connData->conn.query(); + prepareReportAvatar + << "PREPARE " QUERY_REPORT_AVATAR_PREPARE " FROM " << mysqlpp::quote + << "INSERT INTO " DB_TABLE_REP_AVATAR " (" DB_TABLE_REP_AVATAR_COL_PLAYERID ", " DB_TABLE_REP_AVATAR_COL_AVATARHASH ", " DB_TABLE_REP_AVATAR_COL_AVATARTYPE ", " DB_TABLE_REP_AVATAR_COL_BY_PLAYERID ", " DB_TABLE_REP_AVATAR_COL_TIMESTAMP ") VALUES (?, ?, ?, ?, ?)"; + mysqlpp::Query prepareReportGame = m_connData->conn.query(); + prepareReportGame + << "PREPARE " QUERY_REPORT_GAME_PREPARE " FROM " << mysqlpp::quote + << "INSERT INTO " DB_TABLE_REP_GAME " (" DB_TABLE_REP_GAME_COL_CREATOR ", " DB_TABLE_REP_GAME_COL_GAMENAME ", " DB_TABLE_REP_GAME_COL_BY_PLAYERID ", " DB_TABLE_REP_GAME_COL_TIMESTAMP ", " DB_TABLE_REP_GAME_COL_GAMEID ") VALUES (?, ?, ?, ?, ?)"; + mysqlpp::Query prepareAdminPlayer = m_connData->conn.query(); + prepareAdminPlayer + << "PREPARE " QUERY_ADMIN_PLAYER_PREPARE " FROM " << mysqlpp::quote + << "SELECT " DB_TABLE_ADMIN_PLAYER_COL_PLAYERID " FROM " DB_TABLE_ADMIN_PLAYER; + mysqlpp::Query prepareBlockPlayer = m_connData->conn.query(); + prepareBlockPlayer + << "PREPARE " QUERY_BLOCK_PLAYER_PREPARE " FROM " << mysqlpp::quote + << "UPDATE " DB_TABLE_PLAYER " SET " DB_TABLE_PLAYER_COL_VALID " = ?, " DB_TABLE_PLAYER_COL_ACTIVE " = ? WHERE " DB_TABLE_PLAYER_COL_ID " = ?"; + + if (!prepareNick.exec() || !prepareAvatarBlacklist.exec() || !prepareLogin.exec() || !prepareCreateGame.exec() + || !prepareEndGame.exec() || !prepareRelation.exec() || !prepareScore.exec() || !prepareReportAvatar.exec() + || !prepareReportGame.exec() || !prepareAdminPlayer.exec() || !prepareBlockPlayer.exec()) { + m_connData->conn.disconnect(); + m_ioService->post(boost::bind(&ServerDBCallback::ConnectFailed, &m_callback, + string(prepareNick.error()) + prepareAvatarBlacklist.error() + prepareLogin.error() + prepareCreateGame.error() + + prepareEndGame.error() + prepareRelation.error() + prepareScore.error() + prepareReportAvatar.error() + + prepareReportGame.error() + prepareAdminPlayer.error() + prepareBlockPlayer.error())); + m_permanentError = true; + } else { + m_ioService->post(boost::bind(&ServerDBCallback::ConnectSuccess, &m_callback)); + m_previouslyConnected = true; + } + } +} + +void +ServerDBThread::HandleNextQuery() +{ + boost::shared_ptr nextQuery; + { + boost::mutex::scoped_lock lock(m_asyncQueueMutex); + if (!m_asyncQueue.empty()) { + nextQuery = m_asyncQueue.front(); + m_asyncQueue.pop(); + } + } + if (nextQuery) { + do { + nextQuery->Init(m_dbIdManager); + mysqlpp::Query executeQuery = m_connData->conn.query(); + executeQuery << "EXECUTE " << nextQuery->GetPreparedName(); + + list paramList; + nextQuery->GetParams(paramList); + if (!paramList.empty()) { + executeQuery << " using "; + mysqlpp::Query paramQuery = m_connData->conn.query(); + paramQuery << "SET "; + unsigned counter = 1; + list::iterator i = paramList.begin(); + list::iterator end = paramList.end(); + while (i != end) { + if (counter > 1) { + paramQuery << ", "; + executeQuery << ", "; + } + paramQuery << "@param" << counter << " = "; + if (*i == "NULL") { + paramQuery << "NULL"; + } else { + paramQuery << "_utf8" << mysqlpp::quote << *i; + } + executeQuery << "@param" << counter; + ++counter; + ++i; + } + if (!paramQuery.exec()) { + m_connData->conn.disconnect(); + m_ioService->post(boost::bind(&ServerDBCallback::QueryError, &m_callback, paramQuery.error())); + break; + } + } + if (nextQuery->RequiresResultSet()) { + mysqlpp::StoreQueryResult res = executeQuery.store(); + if (res) + nextQuery->HandleResult(executeQuery, m_dbIdManager, res, *m_ioService, m_callback); + else + nextQuery->HandleError(*m_ioService, m_callback); + } else { + if (executeQuery.exec()) + nextQuery->HandleNoResult(executeQuery, m_dbIdManager, *m_ioService, m_callback); + else + nextQuery->HandleError(*m_ioService, m_callback); + } + } while (nextQuery->Next()); // Consider composite queries. + } +} + +void +ServerDBThread::SetConnected(bool isConnected) +{ + boost::mutex::scoped_lock lock(m_isConnectedMutex); + m_isConnected = isConnected; +} + diff --git a/src/dbofficial/serverdbthread.h b/src/dbofficial/serverdbthread.h new file mode 100644 index 00000000..274b247e --- /dev/null +++ b/src/dbofficial/serverdbthread.h @@ -0,0 +1,107 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ +/* Server database thread. */ + +#ifndef _SERVERDBTHREAD_H_ +#define _SERVERDBTHREAD_H_ + +#include +#include +#include +#include +#include +#include +#include +#include + +struct DBConnectionData; +class AsyncDBQuery; + +class ServerDBThread : public ServerDBInterface, public Thread, public boost::enable_shared_from_this +{ +public: + ServerDBThread(ServerDBCallback &cb, boost::shared_ptr ioService); + virtual ~ServerDBThread(); + + virtual void SignalTermination(); + + virtual void Init(const std::string &host, const std::string &user, const std::string &pwd, + const std::string &database, const std::string &encryptionKey); + + virtual void Start(); + virtual void Stop(); + + virtual void AsyncPlayerLogin(unsigned requestId, const std::string &playerName); + virtual void AsyncCheckAvatarBlacklist(unsigned requestId, const std::string &avatarHash); + virtual void PlayerPostLogin(DB_id playerId, const std::string &avatarHash, const std::string &avatarType); + virtual void PlayerLogout(DB_id playerId); + + virtual void AsyncCreateGame(unsigned requestId, const std::string &gameName); + virtual void SetGamePlayerPlace(unsigned requestId, DB_id playerId, unsigned place); + virtual void EndGame(unsigned requestId); + + virtual void AsyncReportAvatar(unsigned requestId, unsigned replyId, DB_id reportedPlayerId, const std::string &avatarHash, const std::string &avatarType, DB_id *byPlayerId); + virtual void AsyncReportGame(unsigned requestId, unsigned replyId, DB_id *creatorPlayerId, unsigned gameId, const std::string &gameName, DB_id *byPlayerId); + + virtual void AsyncQueryAdminPlayers(unsigned requestId); + virtual void AsyncBlockPlayer(unsigned requestId, unsigned replyId, DB_id playerId, int valid, int active); + + bool IsConnected() const; + +protected: + typedef std::queue > AsyncDBQueryQueue; + + // Main function of the thread. + virtual void Main(); + + bool HasPermanentError() const; + bool HasDBConnection() const; + void EstablishDBConnection(); + void HandleNextQuery(); + + void SetConnected(bool isConnected); +private: + + boost::shared_ptr m_ioService; + boost::interprocess::interprocess_semaphore m_semaphore; + ServerDBCallback &m_callback; + boost::shared_ptr m_connData; + mutable boost::mutex m_asyncQueueMutex; + AsyncDBQueryQueue m_asyncQueue; + DBIdManager m_dbIdManager; + + mutable boost::mutex m_isConnectedMutex; + bool m_isConnected; + bool m_permanentError; + bool m_previouslyConnected; +}; + +#endif diff --git a/src/dbofficial/singleasyncdbquery.cpp b/src/dbofficial/singleasyncdbquery.cpp new file mode 100644 index 00000000..ab712b41 --- /dev/null +++ b/src/dbofficial/singleasyncdbquery.cpp @@ -0,0 +1,69 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ + +#include + + +using namespace std; + + +SingleAsyncDBQuery::SingleAsyncDBQuery(unsigned queryId, const string &preparedName, const list ¶ms) + : m_id(queryId), m_preparedName(preparedName), m_params(params) +{ +} + +SingleAsyncDBQuery::~SingleAsyncDBQuery() +{ +} + +unsigned +SingleAsyncDBQuery::GetId() const +{ + return m_id; +} + +std::string +SingleAsyncDBQuery::GetPreparedName() const +{ + return m_preparedName; +} + +void +SingleAsyncDBQuery::GetParams(std::list ¶ms) const +{ + params = m_params; +} + +void +SingleAsyncDBQuery::SetParams(const std::list ¶ms) +{ + m_params = params; +} diff --git a/src/dbofficial/singleasyncdbquery.h b/src/dbofficial/singleasyncdbquery.h new file mode 100644 index 00000000..c27f71e1 --- /dev/null +++ b/src/dbofficial/singleasyncdbquery.h @@ -0,0 +1,61 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2016 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero General Public License as * + * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ +/* Single (non-composite) async database query. */ + +#ifndef _SINGLEASYNCDBQUERY_H_ +#define _SINGLEASYNCDBQUERY_H_ + +#include + +class SingleAsyncDBQuery : public AsyncDBQuery +{ +public: + SingleAsyncDBQuery(unsigned queryId, const std::string &preparedName, const std::list ¶ms); + virtual ~SingleAsyncDBQuery(); + + unsigned GetId() const; + virtual std::string GetPreparedName() const; + virtual void GetParams(std::list ¶ms) const; + virtual void SetParams(const std::list ¶ms); + + virtual bool Next() + { + return false; + } + +private: + + const unsigned m_id; + std::string m_preparedName; + std::list m_params; +}; + +#endif