Preparing to fix login for network game and dedicated server without login backend. Currently broken.

This commit is contained in:
lotodore
2009-11-14 12:39:25 +00:00
parent 9e7792fd8e
commit 059da0232a
10 changed files with 214 additions and 124 deletions
+2
View File
@@ -122,6 +122,8 @@ void ServerGuiWrapper::SignalNetClientServerListAdd(unsigned serverId) { if (myC
void ServerGuiWrapper::SignalNetClientServerListClear() { if (myClientcb) myClientcb->SignalNetClientServerListClear(); }
void ServerGuiWrapper::SignalNetClientServerListShow() { if (myClientcb) myClientcb->SignalNetClientServerListShow(); }
void ServerGuiWrapper::SignalNetClientLoginShow() { if (myClientcb) myClientcb->SignalNetClientLoginShow(); }
void ServerGuiWrapper::SignalNetClientConnect(int actionID) { if (myClientcb) myClientcb->SignalNetClientConnect(actionID); }
void ServerGuiWrapper::SignalNetClientGameInfo(int actionID) { if (myClientcb) myClientcb->SignalNetClientGameInfo(actionID); }
void ServerGuiWrapper::SignalNetClientError(int errorID, int osErrorID) { if (myClientcb) myClientcb->SignalNetClientError(errorID, osErrorID); }
+2
View File
@@ -132,6 +132,8 @@ public:
void SignalNetClientServerListClear();
void SignalNetClientServerListShow();
void SignalNetClientLoginShow();
void SignalNetServerSuccess(int actionID);
void SignalNetServerError(int errorID, int osErrorID);
+1 -2
View File
@@ -446,8 +446,7 @@ void startWindowImpl::callJoinNetworkGameDialog() {
myJoinNetworkGameDialog->lineEdit_ipAddress->text().toUtf8().constData(),
myJoinNetworkGameDialog->spinBox_port->value(),
myJoinNetworkGameDialog->checkBox_ipv6->isChecked(),
myJoinNetworkGameDialog->checkBox_sctp->isChecked(),
myJoinNetworkGameDialog->lineEdit_password->text().toUtf8().constData());
myJoinNetworkGameDialog->checkBox_sctp->isChecked());
//Dialog mit Statusbalken
myConnectToServerDialog->exec();
+5 -3
View File
@@ -62,9 +62,11 @@ public:
virtual void SignalNetClientMsgBox(const std::string &msg) = 0;
virtual void SignalNetClientWaitDialog() = 0;
virtual void SignalNetClientServerListAdd(unsigned serverId) =0;
virtual void SignalNetClientServerListClear() =0;
virtual void SignalNetClientServerListShow() =0;
virtual void SignalNetClientServerListAdd(unsigned serverId) = 0;
virtual void SignalNetClientServerListClear() = 0;
virtual void SignalNetClientServerListShow() = 0;
virtual void SignalNetClientLoginShow() = 0;
virtual void SignalLobbyPlayerJoined(unsigned playerId, const std::string &nickName) = 0;
virtual void SignalLobbyPlayerKicked(const std::string &nickName, const std::string &byWhom, const std::string &reason) = 0;
+38 -18
View File
@@ -234,24 +234,6 @@ private:
boost::asio::ip::tcp::resolver::iterator m_remoteEndpointIterator;
};
// State: Session init.
class ClientStateStartSession : public ClientState
{
public:
// Access the state singleton.
static ClientStateStartSession &Instance();
virtual ~ClientStateStartSession();
virtual void Enter(boost::shared_ptr<ClientThread> client);
virtual void Exit(boost::shared_ptr<ClientThread> client);
virtual void HandlePacket(boost::shared_ptr<ClientThread> /*client*/, boost::shared_ptr<NetPacket> /*tmpPacket*/) {}
protected:
// Protected constructor - this is a singleton.
ClientStateStartSession();
};
// Abstract State: Receiving
class AbstractClientStateReceiving : public ClientState
{
@@ -266,6 +248,44 @@ protected:
virtual void InternalHandlePacket(boost::shared_ptr<ClientThread> client, boost::shared_ptr<NetPacket> tmpPacket) = 0;
};
// State: Session init.
class ClientStateStartSession : public AbstractClientStateReceiving
{
public:
// Access the state singleton.
static ClientStateStartSession &Instance();
virtual ~ClientStateStartSession();
virtual void Enter(boost::shared_ptr<ClientThread> client);
virtual void Exit(boost::shared_ptr<ClientThread> client);
protected:
// Protected constructor - this is a singleton.
ClientStateStartSession();
virtual void InternalHandlePacket(boost::shared_ptr<ClientThread> client, boost::shared_ptr<NetPacket> tmpPacket);
};
// State: Waiting for the user to enter login data.
class ClientStateWaitEnterLogin : public ClientState
{
public:
static ClientStateWaitEnterLogin &Instance();
virtual ~ClientStateWaitEnterLogin();
virtual void Enter(boost::shared_ptr<ClientThread> client);
virtual void Exit(boost::shared_ptr<ClientThread> client);
virtual void HandlePacket(boost::shared_ptr<ClientThread> /*client*/, boost::shared_ptr<NetPacket> /*tmpPacket*/) {}
protected:
// Protected constructor - this is a singleton.
ClientStateWaitEnterLogin();
void TimerLoop(const boost::system::error_code& ec, boost::shared_ptr<ClientThread> client);
};
// State: Wait for Authentication Challenge.
class ClientStateWaitAuthChallenge : public AbstractClientStateReceiving
{
+1 -1
View File
@@ -62,7 +62,6 @@ public:
bool sctp,
const std::string &avatarServerAddress,
const std::string &playerName,
const std::string &playerPwd,
const std::string &avatarFile,
const std::string &cacheDir);
virtual void SignalTermination();
@@ -267,6 +266,7 @@ friend class ClientStateWaitChooseServer;
friend class ClientStateStartConnect;
friend class ClientStateConnecting;
friend class ClientStateStartSession;
friend class ClientStateWaitEnterLogin;
friend class ClientStateWaitAuthChallenge;
friend class ClientStateWaitAuthVerify;
friend class ClientStateWaitSession;
+162 -92
View File
@@ -649,82 +649,6 @@ ClientStateStartConnect::TimerTimeout(const boost::system::error_code& ec, boost
//-----------------------------------------------------------------------------
ClientStateStartSession &
ClientStateStartSession::Instance()
{
static ClientStateStartSession state;
return state;
}
ClientStateStartSession::ClientStateStartSession()
{
}
ClientStateStartSession::~ClientStateStartSession()
{
}
void
ClientStateStartSession::Enter(boost::shared_ptr<ClientThread> client)
{
ClientContext &context = client->GetContext();
boost::shared_ptr<NetPacket> init(new NetPacket(NetPacket::Alloc));
init->GetMsg()->present = PokerTHMessage_PR_initMessage;
InitMessage_t *netInit = &init->GetMsg()->choice.initMessage;
netInit->requestedVersion.major = NET_VERSION_MAJOR;
netInit->requestedVersion.minor = NET_VERSION_MINOR;
// CASE 1: Authenticated login (username, challenge/response for password).
if (!context.GetPassword().empty())
{
netInit->login.present = login_PR_authenticatedLogin;
AuthenticatedLogin_t *authLogin = &netInit->login.choice.authenticatedLogin;
// Send authentication user data for challenge/response in init.
boost::shared_ptr<SessionData> tmpSession = context.GetSessionData();
tmpSession->CreateClientAuthSession(client->GetAuthContext(), context.GetPlayerName(), context.GetPassword());
if (!tmpSession->AuthStep(1, ""))
throw ClientException(__FILE__, __LINE__, ERR_NET_INVALID_PASSWORD, 0);
string outUserData(tmpSession->AuthGetNextOutMsg());
OCTET_STRING_fromBuf(&authLogin->clientUserData,
outUserData.c_str(),
outUserData.length());
string avatarFile = client->GetQtToolsInterface().stringFromUtf8(context.GetAvatarFile());
if (!avatarFile.empty())
{
MD5Buf tmpMD5;
if (client->GetAvatarManager().GetHashForAvatar(avatarFile, tmpMD5))
{
// TODO: use sha1.
authLogin->avatar =
OCTET_STRING_new_fromBuf(
&asn_DEF_OCTET_STRING,
(const char *)tmpMD5.data,
MD5_DATA_SIZE);
}
}
}
// CASE 2: Guest login (no password, but restrictions may apply).
else
{
netInit->login.present = login_PR_guestLogin;
GuestLogin_t *guestLogin = &netInit->login.choice.guestLogin;
OCTET_STRING_fromBuf(&guestLogin->nickName,
context.GetPlayerName().c_str(),
context.GetPlayerName().length());
}
client->GetSender().Send(context.GetSessionData(), init);
client->SetState(ClientStateWaitAuthChallenge::Instance());
}
void
ClientStateStartSession::Exit(boost::shared_ptr<ClientThread> /*client*/)
{
}
//-----------------------------------------------------------------------------
AbstractClientStateReceiving::AbstractClientStateReceiving()
{
}
@@ -1023,6 +947,167 @@ AbstractClientStateReceiving::HandlePacket(boost::shared_ptr<ClientThread> clien
//-----------------------------------------------------------------------------
ClientStateStartSession &
ClientStateStartSession::Instance()
{
static ClientStateStartSession state;
return state;
}
ClientStateStartSession::ClientStateStartSession()
{
}
ClientStateStartSession::~ClientStateStartSession()
{
}
void
ClientStateStartSession::Enter(boost::shared_ptr<ClientThread> client)
{
}
void
ClientStateStartSession::Exit(boost::shared_ptr<ClientThread> /*client*/)
{
}
void
ClientStateStartSession::InternalHandlePacket(boost::shared_ptr<ClientThread> client, boost::shared_ptr<NetPacket> tmpPacket)
{
if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_announceMessage)
{
// Server has send announcement - check data.
AnnounceMessage_t *netAnnounce = &tmpPacket->GetMsg()->choice.announceMessage;
// Check current game version.
if (netAnnounce->latestGameVersion.major != POKERTH_VERSION_MAJOR
|| netAnnounce->latestGameVersion.minor != POKERTH_VERSION_MINOR)
{
client->GetCallback().SignalNetClientNotification(NTF_NET_NEW_RELEASE_AVAILABLE);
}
else if (POKERTH_BETA_REVISION && netAnnounce->latestBetaRevision != POKERTH_BETA_REVISION)
{
client->GetCallback().SignalNetClientNotification(NTF_NET_OUTDATED_BETA);
}
else
{
ClientContext &context = client->GetContext();
// CASE 1: Authenticated login (username, challenge/response for password).
if (netAnnounce->serverType == serverType_serverTypeInternetAuth)
{
client->GetCallback().SignalNetClientLoginShow();
client->SetState(ClientStateWaitEnterLogin::Instance());
}
// CASE 2: Unauthenticated login (dedicated server without auth backend).
else if (netAnnounce->serverType == serverType_serverTypeInternetNoAuth
|| netAnnounce->serverType == serverType_serverTypeLAN)
{
boost::shared_ptr<NetPacket> init(new NetPacket(NetPacket::Alloc));
init->GetMsg()->present = PokerTHMessage_PR_initMessage;
InitMessage_t *netInit = &init->GetMsg()->choice.initMessage;
netInit->requestedVersion.major = NET_VERSION_MAJOR;
netInit->requestedVersion.minor = NET_VERSION_MINOR;
netInit->login.present = login_PR_guestLogin;
GuestLogin_t *guestLogin = &netInit->login.choice.guestLogin;
OCTET_STRING_fromBuf(&guestLogin->nickName,
context.GetPlayerName().c_str(),
context.GetPlayerName().length());
client->GetSender().Send(context.GetSessionData(), init);
client->SetState(ClientStateWaitAuthChallenge::Instance());
}
}
}
}
//-----------------------------------------------------------------------------
ClientStateWaitEnterLogin &
ClientStateWaitEnterLogin::Instance()
{
static ClientStateWaitEnterLogin state;
return state;
}
ClientStateWaitEnterLogin::ClientStateWaitEnterLogin()
{
}
ClientStateWaitEnterLogin::~ClientStateWaitEnterLogin()
{
}
void
ClientStateWaitEnterLogin::Enter(boost::shared_ptr<ClientThread> client)
{
client->GetStateTimer().expires_from_now(
boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
client->GetStateTimer().async_wait(
boost::bind(
&ClientStateWaitEnterLogin::TimerLoop, this, boost::asio::placeholders::error, client));
}
void
ClientStateWaitEnterLogin::Exit(boost::shared_ptr<ClientThread> client)
{
client->GetStateTimer().cancel();
}
void
ClientStateWaitEnterLogin::TimerLoop(const boost::system::error_code& ec, boost::shared_ptr<ClientThread> client)
{
if (!ec && &client->GetState() == this)
{
ClientContext &context = client->GetContext();
if (!context.GetPassword().empty())
{
boost::shared_ptr<NetPacket> init(new NetPacket(NetPacket::Alloc));
init->GetMsg()->present = PokerTHMessage_PR_initMessage;
InitMessage_t *netInit = &init->GetMsg()->choice.initMessage;
netInit->requestedVersion.major = NET_VERSION_MAJOR;
netInit->requestedVersion.minor = NET_VERSION_MINOR;
netInit->login.present = login_PR_authenticatedLogin;
AuthenticatedLogin_t *authLogin = &netInit->login.choice.authenticatedLogin;
// Send authentication user data for challenge/response in init.
boost::shared_ptr<SessionData> tmpSession = context.GetSessionData();
tmpSession->CreateClientAuthSession(client->GetAuthContext(), context.GetPlayerName(), context.GetPassword());
if (!tmpSession->AuthStep(1, ""))
throw ClientException(__FILE__, __LINE__, ERR_NET_INVALID_PASSWORD, 0);
string outUserData(tmpSession->AuthGetNextOutMsg());
OCTET_STRING_fromBuf(&authLogin->clientUserData,
outUserData.c_str(),
outUserData.length());
string avatarFile = client->GetQtToolsInterface().stringFromUtf8(context.GetAvatarFile());
if (!avatarFile.empty())
{
MD5Buf tmpMD5;
if (client->GetAvatarManager().GetHashForAvatar(avatarFile, tmpMD5))
{
// TODO: use sha1.
authLogin->avatar =
OCTET_STRING_new_fromBuf(
&asn_DEF_OCTET_STRING,
(const char *)tmpMD5.data,
MD5_DATA_SIZE);
}
}
client->GetSender().Send(context.GetSessionData(), init);
client->SetState(ClientStateWaitAuthChallenge::Instance());
}
else
{
client->GetStateTimer().expires_from_now(
boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
client->GetStateTimer().async_wait(
boost::bind(
&ClientStateWaitEnterLogin::TimerLoop, this, boost::asio::placeholders::error, client));
}
}
}
//-----------------------------------------------------------------------------
ClientStateWaitAuthChallenge &
ClientStateWaitAuthChallenge::Instance()
{
@@ -1053,22 +1138,7 @@ ClientStateWaitAuthChallenge::Exit(boost::shared_ptr<ClientThread> /*client*/)
void
ClientStateWaitAuthChallenge::InternalHandlePacket(boost::shared_ptr<ClientThread> client, boost::shared_ptr<NetPacket> tmpPacket)
{
if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_announceMessage)
{
// Server has send announcement - check data.
AnnounceMessage_t *netAnnounce = &tmpPacket->GetMsg()->choice.announceMessage;
// Check current game version.
if (netAnnounce->latestGameVersion.major != POKERTH_VERSION_MAJOR
|| netAnnounce->latestGameVersion.minor != POKERTH_VERSION_MINOR)
{
client->GetCallback().SignalNetClientNotification(NTF_NET_NEW_RELEASE_AVAILABLE);
}
else if (POKERTH_BETA_REVISION && netAnnounce->latestBetaRevision != POKERTH_BETA_REVISION)
{
client->GetCallback().SignalNetClientNotification(NTF_NET_OUTDATED_BETA);
}
}
else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_authMessage)
if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_authMessage)
{
// Check subtype.
AuthMessage_t *netAuth = &tmpPacket->GetMsg()->choice.authMessage;
+1 -3
View File
@@ -86,8 +86,7 @@ ClientThread::Init(
const string &serverAddress, const string &serverListUrl,
bool useServerList, unsigned serverPort, bool ipv6, bool sctp,
const string &avatarServerAddress, const string &playerName,
const string &playerPwd, const string &avatarFile,
const string &cacheDir)
const string &avatarFile, const string &cacheDir)
{
if (IsRunning())
{
@@ -105,7 +104,6 @@ ClientThread::Init(
context.SetServerPort(serverPort);
context.SetAvatarServerAddr(avatarServerAddress);
context.SetPlayerName(playerName);
context.SetPassword(playerPwd);
context.SetAvatarFile(avatarFile);
context.SetCacheDir(cacheDir);
}
+1 -4
View File
@@ -179,13 +179,12 @@ void Session::startInternetClient()
myConfig->readConfigInt("InternetServerUseSctp") == 1,
useAvatarServer ? myConfig->readConfigString("AvatarServerAddress") : "",
myConfig->readConfigString("MyName"),
"testpw",
myConfig->readConfigString("MyAvatar"),
myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("CacheDir")));
myNetClient->Run();
}
void Session::startNetworkClient(const string &serverAddress, unsigned serverPort, bool ipv6, bool sctp, const string &pwd)
void Session::startNetworkClient(const string &serverAddress, unsigned serverPort, bool ipv6, bool sctp)
{
if (myNetClient || !myGui)
{
@@ -204,7 +203,6 @@ void Session::startNetworkClient(const string &serverAddress, unsigned serverPor
sctp,
"", // no avatar server
myConfig->readConfigString("MyName"),
pwd,
myConfig->readConfigString("MyAvatar"),
myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("CacheDir")));
myNetClient->Run();
@@ -232,7 +230,6 @@ void Session::startNetworkClientForLocalServer(const GameData &gameData)
myConfig->readConfigInt("ServerUseSctp") == 1,
"", // no avatar server
myConfig->readConfigString("MyName"),
myConfig->readConfigString("ServerPassword"),
myConfig->readConfigString("MyAvatar"),
myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("CacheDir")));
myNetClient->Run();
+1 -1
View File
@@ -63,7 +63,7 @@ public:
boost::shared_ptr<AvatarManager> getAvatarManager();
void startInternetClient();
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);
void startNetworkClientForLocalServer(const GameData &gameData);
void terminateNetworkClient();
void clientCreateGame(const GameData &gameData, const std::string &name, const std::string &password);