Starting login dialog integration on client side.

This commit is contained in:
lotodore
2009-09-24 20:10:40 +00:00
parent 64613ac9b4
commit 39285263b7
11 changed files with 65 additions and 42 deletions
+2 -2
View File
@@ -30,7 +30,7 @@ ServerDBFactoryGeneric::~ServerDBFactoryGeneric()
} }
boost::shared_ptr<ServerDBInterface> boost::shared_ptr<ServerDBInterface>
ServerDBFactoryGeneric::CreateServerDBObject(ServerDBCallback &/*cb*/, boost::shared_ptr<boost::asio::io_service> /*ioService*/) ServerDBFactoryGeneric::CreateServerDBObject(ServerDBCallback &cb, boost::shared_ptr<boost::asio::io_service> ioService)
{ {
return boost::shared_ptr<ServerDBInterface>(new ServerDBGeneric); return boost::shared_ptr<ServerDBInterface>(new ServerDBGeneric(cb, ioService));
} }
+9 -7
View File
@@ -17,12 +17,14 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#include <boost/bind.hpp>
#include <db/serverdbgeneric.h> #include <db/serverdbgeneric.h>
using namespace std; using namespace std;
ServerDBGeneric::ServerDBGeneric() ServerDBGeneric::ServerDBGeneric(ServerDBCallback &cb, boost::shared_ptr<boost::asio::io_service> ioService)
: m_ioService(ioService), m_callback(cb)
{ {
} }
@@ -36,10 +38,10 @@ ServerDBGeneric::Init(const string &/*host*/, const string &/*user*/, const stri
{ {
} }
async_handle void
ServerDBGeneric::AsyncPlayerLogin(const string &/*playerName*/, const string &/*secretString*/) 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 bool
@@ -48,10 +50,10 @@ ServerDBGeneric::PlayerLogout(db_id /*playerId*/)
return false; return false;
} }
async_handle void
ServerDBGeneric::AsyncCreateGame(const db_list &/*players*/) ServerDBGeneric::AsyncCreateGame(unsigned requestId, const db_list &/*players*/)
{ {
return ASYNC_HANDLE_INVALID; m_ioService->post(boost::bind(&ServerDBCallback::CreateGameFailed, &m_callback, requestId));
} }
bool bool
+4 -6
View File
@@ -24,9 +24,7 @@
#include <string> #include <string>
typedef unsigned db_id; typedef unsigned db_id;
typedef unsigned async_handle;
#define DB_ID_INVALID 0 #define DB_ID_INVALID 0
#define ASYNC_HANDLE_INVALID 0
// Callback operations are posted using the io service, // Callback operations are posted using the io service,
// and will therefore be executed in the io service thread. // and will therefore be executed in the io service thread.
@@ -38,11 +36,11 @@ public:
virtual void ConnectSuccess() = 0; virtual void ConnectSuccess() = 0;
virtual void ConnectFailed(const std::string &error) = 0; virtual void ConnectFailed(const std::string &error) = 0;
virtual void PlayerLoginSuccess(async_handle login, db_id playerId) = 0; virtual void PlayerLoginSuccess(unsigned requestId, db_id playerId) = 0;
virtual void PlayerLoginFailed(async_handle login) = 0; virtual void PlayerLoginFailed(unsigned requestId) = 0;
virtual void CreateGameSuccess(async_handle create, db_id gameId) = 0; virtual void CreateGameSuccess(unsigned requestId, db_id gameId) = 0;
virtual void CreateGameFailed(async_handle create) = 0; virtual void CreateGameFailed(unsigned requestId) = 0;
}; };
#endif #endif
+9 -3
View File
@@ -21,24 +21,30 @@
#ifndef _SERVERDBGENERIC_H_ #ifndef _SERVERDBGENERIC_H_
#define _SERVERDBGENERIC_H_ #define _SERVERDBGENERIC_H_
#include <boost/asio.hpp>
#include <boost/shared_ptr.hpp>
#include <db/serverdbinterface.h> #include <db/serverdbinterface.h>
class ServerDBGeneric : public ServerDBInterface class ServerDBGeneric : public ServerDBInterface
{ {
public: public:
ServerDBGeneric(); ServerDBGeneric(ServerDBCallback &cb, boost::shared_ptr<boost::asio::io_service> ioService);
virtual ~ServerDBGeneric(); virtual ~ServerDBGeneric();
virtual void Init(const std::string &host, const std::string &user, const std::string &pwd, virtual void Init(const std::string &host, const std::string &user, const std::string &pwd,
const std::string &database, const std::string &encryptionKey); 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 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 SetGamePlayerPlace(db_id gameId, db_id playerId, unsigned place);
virtual bool EndGame(db_id gameId); virtual bool EndGame(db_id gameId);
private:
boost::shared_ptr<boost::asio::io_service> m_ioService;
ServerDBCallback &m_callback;
}; };
#endif #endif
+2 -2
View File
@@ -35,10 +35,10 @@ public:
virtual void Init(const std::string &host, const std::string &user, const std::string &pwd, virtual void Init(const std::string &host, const std::string &user, const std::string &pwd,
const std::string &database, const std::string &encryptionKey) = 0; 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 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 SetGamePlayerPlace(db_id gameId, db_id playerId, unsigned place) = 0;
virtual bool EndGame(db_id gameId) = 0; virtual bool EndGame(db_id gameId) = 0;
}; };
+1 -1
View File
@@ -60,8 +60,8 @@ public:
bool ipv6, bool ipv6,
bool sctp, bool sctp,
const std::string &avatarServerAddress, const std::string &avatarServerAddress,
const std::string &pwd,
const std::string &playerName, const std::string &playerName,
const std::string &playerPwd,
const std::string &avatarFile, const std::string &avatarFile,
const std::string &cacheDir); const std::string &cacheDir);
virtual void SignalTermination(); virtual void SignalTermination();
+3 -3
View File
@@ -84,8 +84,8 @@ void
ClientThread::Init( ClientThread::Init(
const string &serverAddress, const string &serverListUrl, const string &serverAddress, const string &serverListUrl,
bool useServerList, unsigned serverPort, bool ipv6, bool sctp, bool useServerList, unsigned serverPort, bool ipv6, bool sctp,
const string &avatarServerAddress, const string &pwd, const string &avatarServerAddress, const string &playerName,
const string &playerName, const string &avatarFile, const string &playerPwd, const string &avatarFile,
const string &cacheDir) const string &cacheDir)
{ {
if (IsRunning()) if (IsRunning())
@@ -103,8 +103,8 @@ ClientThread::Init(
context.SetUseServerList(useServerList); context.SetUseServerList(useServerList);
context.SetServerPort(serverPort); context.SetServerPort(serverPort);
context.SetAvatarServerAddr(avatarServerAddress); context.SetAvatarServerAddr(avatarServerAddress);
context.SetPassword(pwd);
context.SetPlayerName(playerName); context.SetPlayerName(playerName);
context.SetPassword(playerPwd);
context.SetAvatarFile(avatarFile); context.SetAvatarFile(avatarFile);
context.SetCacheDir(cacheDir); context.SetCacheDir(cacheDir);
} }
+24 -12
View File
@@ -28,7 +28,6 @@
#include <net/socket_msg.h> #include <net/socket_msg.h>
#include <net/chatcleanermanager.h> #include <net/chatcleanermanager.h>
#include <db/serverdbinterface.h> #include <db/serverdbinterface.h>
#include <db/serverdbcallback.h>
#ifdef POKERTH_OFFICIAL_SERVER #ifdef POKERTH_OFFICIAL_SERVER
#include <dbclosed/serverdbfactoryinternal.h> #include <dbclosed/serverdbfactoryinternal.h>
#else #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 CreateGameFailed(unsigned requestId)
{
}
virtual void CreateGameSuccess(async_handle create, db_id gameId)
{
}
virtual void CreateGameFailed(async_handle create)
{ {
} }
@@ -1255,7 +1256,18 @@ ServerLobbyThread::EstablishSession(SessionWrapper session)
void void
ServerLobbyThread::AuthenticatePlayer(SessionWrapper session, const std::string &password) 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 void
+5
View File
@@ -27,6 +27,7 @@
#include <net/sessionmanager.h> #include <net/sessionmanager.h>
#include <net/netpacket.h> #include <net/netpacket.h>
#include <db/serverdbcallback.h>
#include <gui/guiinterface.h> #include <gui/guiinterface.h>
#include <gamedata.h> #include <gamedata.h>
@@ -133,6 +134,8 @@ protected:
void InitAfterLogin(SessionWrapper session); void InitAfterLogin(SessionWrapper session);
void EstablishSession(SessionWrapper session); void EstablishSession(SessionWrapper session);
void AuthenticatePlayer(SessionWrapper session, const std::string &password); void AuthenticatePlayer(SessionWrapper session, const std::string &password);
void AuthenticationSuccess(unsigned playerId, db_id dbPlayerId);
void AuthenticationFailure(unsigned playerId);
void RequestPlayerAvatar(SessionWrapper session); void RequestPlayerAvatar(SessionWrapper session);
void TimerRemoveGame(const boost::system::error_code &ec); void TimerRemoveGame(const boost::system::error_code &ec);
void TimerRemovePlayer(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; boost::asio::deadline_timer m_avatarLockTimer;
const boost::posix_time::ptime m_startTime; const boost::posix_time::ptime m_startTime;
friend class InternalServerCallback;
}; };
#endif #endif
+5 -5
View File
@@ -154,7 +154,7 @@ boost::shared_ptr<AvatarManager> Session::getAvatarManager()
return myAvatarManager; return myAvatarManager;
} }
void Session::startInternetClient() void Session::startInternetClient(const std::string &username, const std::string &password)
{ {
if (myNetClient || !myGui) if (myNetClient || !myGui)
{ {
@@ -178,8 +178,8 @@ void Session::startInternetClient()
myConfig->readConfigInt("InternetServerUseIpv6") == 1, myConfig->readConfigInt("InternetServerUseIpv6") == 1,
myConfig->readConfigInt("InternetServerUseSctp") == 1, myConfig->readConfigInt("InternetServerUseSctp") == 1,
useAvatarServer ? myConfig->readConfigString("AvatarServerAddress") : "", useAvatarServer ? myConfig->readConfigString("AvatarServerAddress") : "",
myConfig->readConfigString("InternetServerPassword"), username,
myConfig->readConfigString("MyName"), password,
myConfig->readConfigString("MyAvatar"), myConfig->readConfigString("MyAvatar"),
myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("CacheDir"))); myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("CacheDir")));
myNetClient->Run(); myNetClient->Run();
@@ -203,8 +203,8 @@ void Session::startNetworkClient(const string &serverAddress, unsigned serverPor
ipv6, ipv6,
sctp, sctp,
"", // no avatar server "", // no avatar server
pwd,
myConfig->readConfigString("MyName"), myConfig->readConfigString("MyName"),
pwd,
myConfig->readConfigString("MyAvatar"), myConfig->readConfigString("MyAvatar"),
myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("CacheDir"))); myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("CacheDir")));
myNetClient->Run(); myNetClient->Run();
@@ -231,8 +231,8 @@ void Session::startNetworkClientForLocalServer(const GameData &gameData)
useIpv6, useIpv6,
myConfig->readConfigInt("ServerUseSctp") == 1, myConfig->readConfigInt("ServerUseSctp") == 1,
"", // no avatar server "", // no avatar server
myConfig->readConfigString("ServerPassword"),
myConfig->readConfigString("MyName"), myConfig->readConfigString("MyName"),
myConfig->readConfigString("ServerPassword"),
myConfig->readConfigString("MyAvatar"), myConfig->readConfigString("MyAvatar"),
myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("CacheDir"))); myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("CacheDir")));
myNetClient->Run(); myNetClient->Run();
+1 -1
View File
@@ -62,7 +62,7 @@ public:
boost::shared_ptr<AvatarManager> getAvatarManager(); boost::shared_ptr<AvatarManager> 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 startNetworkClient(const std::string &serverAddress, unsigned serverPort, bool ipv6, bool sctp, const std::string &pwd);
void startNetworkClientForLocalServer(const GameData &gameData); void startNetworkClientForLocalServer(const GameData &gameData);
void terminateNetworkClient(); void terminateNetworkClient();