From 6ecec7e2623192376a9491223df62f4ac597910b Mon Sep 17 00:00:00 2001 From: lotodore Date: Fri, 4 Sep 2009 22:53:24 +0000 Subject: [PATCH] Adding database interface and generic implementation for database stuff. The generic implementation acts just as placeholder and does nothing. --- pokerth_lib.pro | 10 ++++ src/db/common/serverdbcallback.cpp | 26 +++++++++ src/db/common/serverdbfactory.cpp | 26 +++++++++ src/db/common/serverdbfactorygeneric.cpp | 36 +++++++++++++ src/db/common/serverdbgeneric.cpp | 67 ++++++++++++++++++++++++ src/db/common/serverdbinterface.cpp | 26 +++++++++ src/db/serverdbcallback.h | 43 +++++++++++++++ src/db/serverdbfactory.h | 38 ++++++++++++++ src/db/serverdbfactorygeneric.h | 39 ++++++++++++++ src/db/serverdbgeneric.h | 44 ++++++++++++++++ src/db/serverdbinterface.h | 46 ++++++++++++++++ 11 files changed, 401 insertions(+) create mode 100644 src/db/common/serverdbcallback.cpp create mode 100644 src/db/common/serverdbfactory.cpp create mode 100644 src/db/common/serverdbfactorygeneric.cpp create mode 100644 src/db/common/serverdbgeneric.cpp create mode 100644 src/db/common/serverdbinterface.cpp create mode 100644 src/db/serverdbcallback.h create mode 100644 src/db/serverdbfactory.h create mode 100644 src/db/serverdbfactorygeneric.h create mode 100644 src/db/serverdbgeneric.h create mode 100644 src/db/serverdbinterface.h diff --git a/pokerth_lib.pro b/pokerth_lib.pro index 123f0fd0..7a17ac23 100644 --- a/pokerth_lib.pro +++ b/pokerth_lib.pro @@ -126,6 +126,11 @@ HEADERS += \ src/engine/network_engine/clienthand.h \ src/engine/network_engine/clientplayer.h \ src/engine/network_engine/clientbero.h \ + src/db/serverdbcallback.h \ + src/db/serverdbfactory.h \ + src/db/serverdbinterface.h \ + src/db/serverdbgeneric.h \ + src/db/serverdbfactorygeneric.h \ src/gui/qttoolsinterface.h \ src/gui/generic/serverguiwrapper.h @@ -205,6 +210,11 @@ SOURCES += \ src/net/common/uploadhelper.cpp \ src/net/common/encodedpacket.cpp \ src/net/common/internalchatcleanerpacket.cpp \ + src/db/common/serverdbcallback.cpp \ + src/db/common/serverdbfactory.cpp \ + src/db/common/serverdbinterface.cpp \ + src/db/common/serverdbgeneric.cpp \ + src/db/common/serverdbfactorygeneric.cpp \ src/gui/generic/serverguiwrapper.cpp \ src/gui/qttoolsinterface.cpp diff --git a/src/db/common/serverdbcallback.cpp b/src/db/common/serverdbcallback.cpp new file mode 100644 index 00000000..ae778ff5 --- /dev/null +++ b/src/db/common/serverdbcallback.cpp @@ -0,0 +1,26 @@ +/*************************************************************************** + * Copyright (C) 2009 by Lothar May * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include + + +ServerDBCallback::~ServerDBCallback() +{ +} + diff --git a/src/db/common/serverdbfactory.cpp b/src/db/common/serverdbfactory.cpp new file mode 100644 index 00000000..b621f6d1 --- /dev/null +++ b/src/db/common/serverdbfactory.cpp @@ -0,0 +1,26 @@ +/*************************************************************************** + * Copyright (C) 2009 by Lothar May * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include + + +ServerDBFactory::~ServerDBFactory() +{ +} + diff --git a/src/db/common/serverdbfactorygeneric.cpp b/src/db/common/serverdbfactorygeneric.cpp new file mode 100644 index 00000000..70e0f238 --- /dev/null +++ b/src/db/common/serverdbfactorygeneric.cpp @@ -0,0 +1,36 @@ +/*************************************************************************** + * Copyright (C) 2009 by Lothar May * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include +#include + + +ServerDBFactoryGeneric::ServerDBFactoryGeneric() +{ +} + +ServerDBFactoryGeneric::~ServerDBFactoryGeneric() +{ +} + +boost::shared_ptr +ServerDBFactoryGeneric::CreateServerDBObject(ServerDBCallback &/*cb*/, boost::shared_ptr /*ioService*/) +{ + return boost::shared_ptr(new ServerDBGeneric); +} diff --git a/src/db/common/serverdbgeneric.cpp b/src/db/common/serverdbgeneric.cpp new file mode 100644 index 00000000..12e6f7d4 --- /dev/null +++ b/src/db/common/serverdbgeneric.cpp @@ -0,0 +1,67 @@ +/*************************************************************************** + * Copyright (C) 2009 by Lothar May * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include + +using namespace std; + + +ServerDBGeneric::ServerDBGeneric() +{ +} + +ServerDBGeneric::~ServerDBGeneric() +{ +} + +void +ServerDBGeneric::Init(const string &/*host*/, const string &/*user*/, const string &/*pwd*/, + const string &/*database*/, const string &/*encryptionKey*/) +{ +} + +async_handle +ServerDBGeneric::AsyncPlayerLogin(const string &/*playerName*/, const string &/*secretString*/) +{ + return ASYNC_HANDLE_INVALID; +} + +bool +ServerDBGeneric::PlayerLogout(db_id /*playerId*/) +{ + return false; +} + +async_handle +ServerDBGeneric::AsyncCreateGame(const db_list &/*players*/) +{ + return ASYNC_HANDLE_INVALID; +} + +bool +ServerDBGeneric::SetGamePlayerPlace(db_id /*gameId*/, db_id /*playerId*/, unsigned /*place*/) +{ + return false; +} + +bool +ServerDBGeneric::EndGame(db_id /*gameId*/) +{ + return false; +} diff --git a/src/db/common/serverdbinterface.cpp b/src/db/common/serverdbinterface.cpp new file mode 100644 index 00000000..c04e3074 --- /dev/null +++ b/src/db/common/serverdbinterface.cpp @@ -0,0 +1,26 @@ +/*************************************************************************** + * Copyright (C) 2009 by Lothar May * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include + + +ServerDBInterface::~ServerDBInterface() +{ +} + diff --git a/src/db/serverdbcallback.h b/src/db/serverdbcallback.h new file mode 100644 index 00000000..42a3f0cf --- /dev/null +++ b/src/db/serverdbcallback.h @@ -0,0 +1,43 @@ +/*************************************************************************** + * Copyright (C) 2009 by Lothar May * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +/* Server database callback for async database operations. */ + +#ifndef _SERVERDBCALLBACK_H_ +#define _SERVERDBCALLBACK_H_ + +typedef unsigned db_id; +typedef unsigned async_handle; +#define DB_ID_INVALID 0 +#define ASYNC_HANDLE_INVALID 0 + +// Callback operations are posted using the io service, +// and will therefore be executed in the io service thread. +class ServerDBCallback +{ +public: + virtual ~ServerDBCallback(); + + virtual void PlayerLoginSuccess(async_handle login, db_id playerId) = 0; + virtual void PlayerLoginFailed(async_handle login) = 0; + + virtual void CreateGameSuccess(async_handle create, db_id gameId) = 0; + virtual void CreateGameFailed(async_handle create) = 0; +}; + +#endif diff --git a/src/db/serverdbfactory.h b/src/db/serverdbfactory.h new file mode 100644 index 00000000..5c7deab7 --- /dev/null +++ b/src/db/serverdbfactory.h @@ -0,0 +1,38 @@ +/*************************************************************************** + * Copyright (C) 2009 by Lothar May * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +/* Server database factory. */ + +#ifndef _SERVERDBFACTORY_H_ +#define _SERVERDBFACTORY_H_ + +#include +#include +#include +#include + +class ServerDBFactory +{ +public: + virtual ~ServerDBFactory(); + + virtual boost::shared_ptr CreateServerDBObject( + ServerDBCallback &cb, boost::shared_ptr ioService) = 0; +}; + +#endif diff --git a/src/db/serverdbfactorygeneric.h b/src/db/serverdbfactorygeneric.h new file mode 100644 index 00000000..c1a11405 --- /dev/null +++ b/src/db/serverdbfactorygeneric.h @@ -0,0 +1,39 @@ +/*************************************************************************** + * Copyright (C) 2009 by Lothar May * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +/* Server database factory for generic objects. */ + +#ifndef _SERVERDBFACTORYGENERIC_H_ +#define _SERVERDBFACTORYGENERIC_H_ + +#include +#include +#include +#include + +class ServerDBFactoryGeneric +{ +public: + ServerDBFactoryGeneric(); + virtual ~ServerDBFactoryGeneric(); + + virtual boost::shared_ptr CreateServerDBObject( + ServerDBCallback &cb, boost::shared_ptr ioService); +}; + +#endif diff --git a/src/db/serverdbgeneric.h b/src/db/serverdbgeneric.h new file mode 100644 index 00000000..b932d656 --- /dev/null +++ b/src/db/serverdbgeneric.h @@ -0,0 +1,44 @@ +/*************************************************************************** + * Copyright (C) 2009 by Lothar May * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +/* Generic server database implementation. Basically does nothing. */ + +#ifndef _SERVERDBGENERIC_H_ +#define _SERVERDBGENERIC_H_ + +#include + + +class ServerDBGeneric : public ServerDBInterface +{ +public: + ServerDBGeneric(); + virtual ~ServerDBGeneric(); + + virtual void Init(const std::string &host, const std::string &user, const std::string &pwd, + const std::string &database, const std::string &encryptionKey); + + virtual async_handle AsyncPlayerLogin(const std::string &playerName, const std::string &secretString); + virtual bool PlayerLogout(db_id playerId); + + virtual async_handle AsyncCreateGame(const db_list &players); + virtual bool SetGamePlayerPlace(db_id gameId, db_id playerId, unsigned place); + virtual bool EndGame(db_id gameId); +}; + +#endif diff --git a/src/db/serverdbinterface.h b/src/db/serverdbinterface.h new file mode 100644 index 00000000..10078907 --- /dev/null +++ b/src/db/serverdbinterface.h @@ -0,0 +1,46 @@ +/*************************************************************************** + * Copyright (C) 2009 by Lothar May * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +/* Server database interface. */ + +#ifndef _SERVERDBINTERFACE_H_ +#define _SERVERDBINTERFACE_H_ + +#include +#include +#include + +typedef std::list db_list; + +class ServerDBInterface +{ +public: + virtual ~ServerDBInterface(); + + virtual void Init(const std::string &host, const std::string &user, const std::string &pwd, + const std::string &database, const std::string &encryptionKey) = 0; + + virtual async_handle AsyncPlayerLogin(const std::string &playerName, const std::string &secretString) = 0; + virtual bool PlayerLogout(db_id playerId) = 0; + + virtual async_handle AsyncCreateGame(const db_list &players) = 0; + virtual bool SetGamePlayerPlace(db_id gameId, db_id playerId, unsigned place) = 0; + virtual bool EndGame(db_id gameId) = 0; +}; + +#endif