From 39285263b7b5a13fe7946fa81014797118a15ed0 Mon Sep 17 00:00:00 2001 From: lotodore Date: Thu, 24 Sep 2009 20:10:40 +0000 Subject: [PATCH] Starting login dialog integration on client side. --- src/db/common/serverdbfactorygeneric.cpp | 4 +-- src/db/common/serverdbgeneric.cpp | 16 ++++++----- src/db/serverdbcallback.h | 10 +++---- src/db/serverdbgeneric.h | 12 ++++++-- src/db/serverdbinterface.h | 4 +-- src/net/clientthread.h | 2 +- src/net/common/clientthread.cpp | 6 ++-- src/net/common/serverlobbythread.cpp | 36 ++++++++++++++++-------- src/net/serverlobbythread.h | 5 ++++ src/session.cpp | 10 +++---- src/session.h | 2 +- 11 files changed, 65 insertions(+), 42 deletions(-) diff --git a/src/db/common/serverdbfactorygeneric.cpp b/src/db/common/serverdbfactorygeneric.cpp index 70e0f238..f2daa9f4 100644 --- a/src/db/common/serverdbfactorygeneric.cpp +++ b/src/db/common/serverdbfactorygeneric.cpp @@ -30,7 +30,7 @@ ServerDBFactoryGeneric::~ServerDBFactoryGeneric() } boost::shared_ptr -ServerDBFactoryGeneric::CreateServerDBObject(ServerDBCallback &/*cb*/, boost::shared_ptr /*ioService*/) +ServerDBFactoryGeneric::CreateServerDBObject(ServerDBCallback &cb, boost::shared_ptr ioService) { - return boost::shared_ptr(new ServerDBGeneric); + return boost::shared_ptr(new ServerDBGeneric(cb, ioService)); } diff --git a/src/db/common/serverdbgeneric.cpp b/src/db/common/serverdbgeneric.cpp index 12e6f7d4..1108c119 100644 --- a/src/db/common/serverdbgeneric.cpp +++ b/src/db/common/serverdbgeneric.cpp @@ -17,12 +17,14 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include #include using namespace std; -ServerDBGeneric::ServerDBGeneric() +ServerDBGeneric::ServerDBGeneric(ServerDBCallback &cb, boost::shared_ptr ioService) +: m_ioService(ioService), m_callback(cb) { } @@ -36,10 +38,10 @@ ServerDBGeneric::Init(const string &/*host*/, const string &/*user*/, const stri { } -async_handle -ServerDBGeneric::AsyncPlayerLogin(const string &/*playerName*/, const string &/*secretString*/) +void +ServerDBGeneric::AsyncPlayerLogin(unsigned requestId, const string &/*playerName*/, const string &/*secretString*/) { - return ASYNC_HANDLE_INVALID; + m_ioService->post(boost::bind(&ServerDBCallback::PlayerLoginFailed, &m_callback, requestId)); } bool @@ -48,10 +50,10 @@ ServerDBGeneric::PlayerLogout(db_id /*playerId*/) return false; } -async_handle -ServerDBGeneric::AsyncCreateGame(const db_list &/*players*/) +void +ServerDBGeneric::AsyncCreateGame(unsigned requestId, const db_list &/*players*/) { - return ASYNC_HANDLE_INVALID; + m_ioService->post(boost::bind(&ServerDBCallback::CreateGameFailed, &m_callback, requestId)); } bool diff --git a/src/db/serverdbcallback.h b/src/db/serverdbcallback.h index df9d9c04..b80f0176 100644 --- a/src/db/serverdbcallback.h +++ b/src/db/serverdbcallback.h @@ -24,9 +24,7 @@ #include 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. @@ -38,11 +36,11 @@ public: virtual void ConnectSuccess() = 0; virtual void ConnectFailed(const std::string &error) = 0; - virtual void PlayerLoginSuccess(async_handle login, db_id playerId) = 0; - virtual void PlayerLoginFailed(async_handle login) = 0; + virtual void PlayerLoginSuccess(unsigned requestId, db_id playerId) = 0; + virtual void PlayerLoginFailed(unsigned requestId) = 0; - virtual void CreateGameSuccess(async_handle create, db_id gameId) = 0; - virtual void CreateGameFailed(async_handle create) = 0; + virtual void CreateGameSuccess(unsigned requestId, db_id gameId) = 0; + virtual void CreateGameFailed(unsigned requestId) = 0; }; #endif diff --git a/src/db/serverdbgeneric.h b/src/db/serverdbgeneric.h index b932d656..2c38543e 100644 --- a/src/db/serverdbgeneric.h +++ b/src/db/serverdbgeneric.h @@ -21,24 +21,30 @@ #ifndef _SERVERDBGENERIC_H_ #define _SERVERDBGENERIC_H_ +#include +#include #include class ServerDBGeneric : public ServerDBInterface { public: - ServerDBGeneric(); + ServerDBGeneric(ServerDBCallback &cb, boost::shared_ptr ioService); 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 void AsyncPlayerLogin(unsigned requestId, const std::string &playerName, const std::string &secretString); virtual bool PlayerLogout(db_id playerId); - virtual async_handle AsyncCreateGame(const db_list &players); + virtual void AsyncCreateGame(unsigned requestId, const db_list &players); virtual bool SetGamePlayerPlace(db_id gameId, db_id playerId, unsigned place); virtual bool EndGame(db_id gameId); + +private: + boost::shared_ptr m_ioService; + ServerDBCallback &m_callback; }; #endif diff --git a/src/db/serverdbinterface.h b/src/db/serverdbinterface.h index 10078907..7fc2852c 100644 --- a/src/db/serverdbinterface.h +++ b/src/db/serverdbinterface.h @@ -35,10 +35,10 @@ public: 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 void AsyncPlayerLogin(unsigned requestId, 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 void AsyncCreateGame(unsigned requestId, const db_list &players) = 0; virtual bool SetGamePlayerPlace(db_id gameId, db_id playerId, unsigned place) = 0; virtual bool EndGame(db_id gameId) = 0; }; diff --git a/src/net/clientthread.h b/src/net/clientthread.h index 885badb0..83c33d37 100644 --- a/src/net/clientthread.h +++ b/src/net/clientthread.h @@ -60,8 +60,8 @@ public: bool ipv6, bool sctp, const std::string &avatarServerAddress, - const std::string &pwd, const std::string &playerName, + const std::string &playerPwd, const std::string &avatarFile, const std::string &cacheDir); virtual void SignalTermination(); diff --git a/src/net/common/clientthread.cpp b/src/net/common/clientthread.cpp index 16926066..d8833a6c 100644 --- a/src/net/common/clientthread.cpp +++ b/src/net/common/clientthread.cpp @@ -84,8 +84,8 @@ void ClientThread::Init( const string &serverAddress, const string &serverListUrl, bool useServerList, unsigned serverPort, bool ipv6, bool sctp, - const string &avatarServerAddress, const string &pwd, - const string &playerName, const string &avatarFile, + const string &avatarServerAddress, const string &playerName, + const string &playerPwd, const string &avatarFile, const string &cacheDir) { if (IsRunning()) @@ -103,8 +103,8 @@ ClientThread::Init( context.SetUseServerList(useServerList); context.SetServerPort(serverPort); context.SetAvatarServerAddr(avatarServerAddress); - context.SetPassword(pwd); context.SetPlayerName(playerName); + context.SetPassword(playerPwd); context.SetAvatarFile(avatarFile); context.SetCacheDir(cacheDir); } diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index a4f8c875..a36831c1 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #ifdef POKERTH_OFFICIAL_SERVER #include #else @@ -105,19 +104,21 @@ public: { } - virtual void PlayerLoginSuccess(async_handle login, db_id playerId) + virtual void PlayerLoginSuccess(unsigned requestId, db_id dbPlayerId) + { + m_server.AuthenticationSuccess(requestId, dbPlayerId); + } + + virtual void PlayerLoginFailed(unsigned requestId) + { + m_server.AuthenticationFailure(requestId); + } + + virtual void CreateGameSuccess(unsigned requestId, db_id gameId) { } - virtual void PlayerLoginFailed(async_handle login) - { - } - - virtual void CreateGameSuccess(async_handle create, db_id gameId) - { - } - - virtual void CreateGameFailed(async_handle create) + virtual void CreateGameFailed(unsigned requestId) { } @@ -1255,7 +1256,18 @@ ServerLobbyThread::EstablishSession(SessionWrapper session) void ServerLobbyThread::AuthenticatePlayer(SessionWrapper session, const std::string &password) { - // TODO + assert(session.playerData); + m_database->AsyncPlayerLogin(session.playerData->GetUniqueId(), session.playerData->GetName(), password); +} + +void +ServerLobbyThread::AuthenticationSuccess(unsigned playerId, db_id dbPlayerId) +{ +} + +void +ServerLobbyThread::AuthenticationFailure(unsigned playerId) +{ } void diff --git a/src/net/serverlobbythread.h b/src/net/serverlobbythread.h index d4df2d10..8d560806 100644 --- a/src/net/serverlobbythread.h +++ b/src/net/serverlobbythread.h @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -133,6 +134,8 @@ protected: void InitAfterLogin(SessionWrapper session); void EstablishSession(SessionWrapper session); void AuthenticatePlayer(SessionWrapper session, const std::string &password); + void AuthenticationSuccess(unsigned playerId, db_id dbPlayerId); + void AuthenticationFailure(unsigned playerId); void RequestPlayerAvatar(SessionWrapper session); void TimerRemoveGame(const boost::system::error_code &ec); void TimerRemovePlayer(const boost::system::error_code &ec); @@ -232,6 +235,8 @@ private: boost::asio::deadline_timer m_avatarLockTimer; const boost::posix_time::ptime m_startTime; + +friend class InternalServerCallback; }; #endif diff --git a/src/session.cpp b/src/session.cpp index 5637abce..75a821d7 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -154,7 +154,7 @@ boost::shared_ptr Session::getAvatarManager() return myAvatarManager; } -void Session::startInternetClient() +void Session::startInternetClient(const std::string &username, const std::string &password) { if (myNetClient || !myGui) { @@ -178,8 +178,8 @@ void Session::startInternetClient() myConfig->readConfigInt("InternetServerUseIpv6") == 1, myConfig->readConfigInt("InternetServerUseSctp") == 1, useAvatarServer ? myConfig->readConfigString("AvatarServerAddress") : "", - myConfig->readConfigString("InternetServerPassword"), - myConfig->readConfigString("MyName"), + username, + password, myConfig->readConfigString("MyAvatar"), myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("CacheDir"))); myNetClient->Run(); @@ -203,8 +203,8 @@ void Session::startNetworkClient(const string &serverAddress, unsigned serverPor ipv6, sctp, "", // no avatar server - pwd, myConfig->readConfigString("MyName"), + pwd, myConfig->readConfigString("MyAvatar"), myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("CacheDir"))); myNetClient->Run(); @@ -231,8 +231,8 @@ void Session::startNetworkClientForLocalServer(const GameData &gameData) useIpv6, myConfig->readConfigInt("ServerUseSctp") == 1, "", // no avatar server - myConfig->readConfigString("ServerPassword"), myConfig->readConfigString("MyName"), + myConfig->readConfigString("ServerPassword"), myConfig->readConfigString("MyAvatar"), myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("CacheDir"))); myNetClient->Run(); diff --git a/src/session.h b/src/session.h index f47d662e..f2e72592 100755 --- a/src/session.h +++ b/src/session.h @@ -62,7 +62,7 @@ public: boost::shared_ptr getAvatarManager(); - void startInternetClient(); + void startInternetClient(const std::string &username, const std::string &password); void startNetworkClient(const std::string &serverAddress, unsigned serverPort, bool ipv6, bool sctp, const std::string &pwd); void startNetworkClientForLocalServer(const GameData &gameData); void terminateNetworkClient();