Network game, dedicated server without auth backend and dedicated server with auth backend should work now. Guest login still broken.
This commit is contained in:
@@ -333,7 +333,10 @@ void startWindowImpl::callInternetGameLoginDialog() {
|
|||||||
myInternetGameLoginDialog->exec();
|
myInternetGameLoginDialog->exec();
|
||||||
if(myInternetGameLoginDialog->result() == QDialog::Accepted) {
|
if(myInternetGameLoginDialog->result() == QDialog::Accepted) {
|
||||||
//send login infos
|
//send login infos
|
||||||
// mySession->
|
mySession->setLogin(
|
||||||
|
myInternetGameLoginDialog->lineEdit_username->text().toUtf8().constData(),
|
||||||
|
myInternetGameLoginDialog->lineEdit_password->text().toUtf8().constData(),
|
||||||
|
myInternetGameLoginDialog->checkBox_guest->isChecked());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
myConnectToServerDialog->reject();
|
myConnectToServerDialog->reject();
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ public:
|
|||||||
void HandleRead(const boost::system::error_code& ec, size_t bytesRead);
|
void HandleRead(const boost::system::error_code& ec, size_t bytesRead);
|
||||||
|
|
||||||
void SelectServer(unsigned serverId);
|
void SelectServer(unsigned serverId);
|
||||||
|
void SetLogin(const std::string &userName, const std::string &password, bool isGuest);
|
||||||
ServerInfo GetServerInfo(unsigned serverId) const;
|
ServerInfo GetServerInfo(unsigned serverId) const;
|
||||||
|
|
||||||
GameInfo GetGameInfo(unsigned gameId) const;
|
GameInfo GetGameInfo(unsigned gameId) const;
|
||||||
@@ -103,6 +104,13 @@ protected:
|
|||||||
typedef std::map<unsigned, PlayerInfo> PlayerInfoMap;
|
typedef std::map<unsigned, PlayerInfo> PlayerInfoMap;
|
||||||
typedef std::map<unsigned, boost::shared_ptr<AvatarFile> > AvatarFileMap;
|
typedef std::map<unsigned, boost::shared_ptr<AvatarFile> > AvatarFileMap;
|
||||||
typedef std::map<unsigned, ServerInfo> ServerInfoMap;
|
typedef std::map<unsigned, ServerInfo> ServerInfoMap;
|
||||||
|
struct LoginData
|
||||||
|
{
|
||||||
|
LoginData() : isGuest(false) {}
|
||||||
|
std::string userName;
|
||||||
|
std::string password;
|
||||||
|
bool isGuest;
|
||||||
|
};
|
||||||
|
|
||||||
// Main function of the thread.
|
// Main function of the thread.
|
||||||
virtual void Main();
|
virtual void Main();
|
||||||
@@ -174,6 +182,8 @@ protected:
|
|||||||
bool GetSelectedServer(unsigned &serverId) const;
|
bool GetSelectedServer(unsigned &serverId) const;
|
||||||
void UseServer(unsigned serverId);
|
void UseServer(unsigned serverId);
|
||||||
|
|
||||||
|
bool GetLoginData(LoginData &loginData) const;
|
||||||
|
|
||||||
unsigned GetGameIdByName(const std::string &name) const;
|
unsigned GetGameIdByName(const std::string &name) const;
|
||||||
void AddGameInfo(unsigned gameId, const GameInfo &info);
|
void AddGameInfo(unsigned gameId, const GameInfo &info);
|
||||||
void UpdateGameInfoMode(unsigned gameId, GameMode mode);
|
void UpdateGameInfoMode(unsigned gameId, GameMode mode);
|
||||||
@@ -224,6 +234,9 @@ private:
|
|||||||
unsigned m_selectedServerId;
|
unsigned m_selectedServerId;
|
||||||
mutable boost::mutex m_selectServerMutex;
|
mutable boost::mutex m_selectServerMutex;
|
||||||
|
|
||||||
|
LoginData m_loginData;
|
||||||
|
mutable boost::mutex m_loginDataMutex;
|
||||||
|
|
||||||
GameInfoMap m_gameInfoMap;
|
GameInfoMap m_gameInfoMap;
|
||||||
mutable boost::mutex m_gameInfoMapMutex;
|
mutable boost::mutex m_gameInfoMapMutex;
|
||||||
|
|
||||||
|
|||||||
@@ -965,6 +965,8 @@ ClientStateStartSession::~ClientStateStartSession()
|
|||||||
void
|
void
|
||||||
ClientStateStartSession::Enter(boost::shared_ptr<ClientThread> client)
|
ClientStateStartSession::Enter(boost::shared_ptr<ClientThread> client)
|
||||||
{
|
{
|
||||||
|
// Now we finally start receiving data.
|
||||||
|
client->StartAsyncRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -999,7 +1001,7 @@ ClientStateStartSession::InternalHandlePacket(boost::shared_ptr<ClientThread> cl
|
|||||||
client->GetCallback().SignalNetClientLoginShow();
|
client->GetCallback().SignalNetClientLoginShow();
|
||||||
client->SetState(ClientStateWaitEnterLogin::Instance());
|
client->SetState(ClientStateWaitEnterLogin::Instance());
|
||||||
}
|
}
|
||||||
// CASE 2: Unauthenticated login (dedicated server without auth backend).
|
// CASE 2: Unauthenticated login (network game or dedicated server without auth backend).
|
||||||
else if (netAnnounce->serverType == serverType_serverTypeInternetNoAuth
|
else if (netAnnounce->serverType == serverType_serverTypeInternetNoAuth
|
||||||
|| netAnnounce->serverType == serverType_serverTypeLAN)
|
|| netAnnounce->serverType == serverType_serverTypeLAN)
|
||||||
{
|
{
|
||||||
@@ -1008,13 +1010,27 @@ ClientStateStartSession::InternalHandlePacket(boost::shared_ptr<ClientThread> cl
|
|||||||
InitMessage_t *netInit = &init->GetMsg()->choice.initMessage;
|
InitMessage_t *netInit = &init->GetMsg()->choice.initMessage;
|
||||||
netInit->requestedVersion.major = NET_VERSION_MAJOR;
|
netInit->requestedVersion.major = NET_VERSION_MAJOR;
|
||||||
netInit->requestedVersion.minor = NET_VERSION_MINOR;
|
netInit->requestedVersion.minor = NET_VERSION_MINOR;
|
||||||
netInit->login.present = login_PR_guestLogin;
|
netInit->login.present = login_PR_unauthenticatedLogin;
|
||||||
GuestLogin_t *guestLogin = &netInit->login.choice.guestLogin;
|
UnauthenticatedLogin_t *noauthLogin = &netInit->login.choice.unauthenticatedLogin;
|
||||||
OCTET_STRING_fromBuf(&guestLogin->nickName,
|
OCTET_STRING_fromBuf(&noauthLogin->nickName,
|
||||||
context.GetPlayerName().c_str(),
|
context.GetPlayerName().c_str(),
|
||||||
context.GetPlayerName().length());
|
context.GetPlayerName().length());
|
||||||
|
string avatarFile = client->GetQtToolsInterface().stringFromUtf8(context.GetAvatarFile());
|
||||||
|
if (!avatarFile.empty())
|
||||||
|
{
|
||||||
|
MD5Buf tmpMD5;
|
||||||
|
if (client->GetAvatarManager().GetHashForAvatar(avatarFile, tmpMD5))
|
||||||
|
{
|
||||||
|
// TODO: use sha1.
|
||||||
|
noauthLogin->avatar =
|
||||||
|
OCTET_STRING_new_fromBuf(
|
||||||
|
&asn_DEF_OCTET_STRING,
|
||||||
|
(const char *)tmpMD5.data,
|
||||||
|
MD5_DATA_SIZE);
|
||||||
|
}
|
||||||
|
}
|
||||||
client->GetSender().Send(context.GetSessionData(), init);
|
client->GetSender().Send(context.GetSessionData(), init);
|
||||||
client->SetState(ClientStateWaitAuthChallenge::Instance());
|
client->SetState(ClientStateWaitSession::Instance());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1058,9 +1074,13 @@ ClientStateWaitEnterLogin::TimerLoop(const boost::system::error_code& ec, boost:
|
|||||||
{
|
{
|
||||||
if (!ec && &client->GetState() == this)
|
if (!ec && &client->GetState() == this)
|
||||||
{
|
{
|
||||||
ClientContext &context = client->GetContext();
|
ClientThread::LoginData loginData;
|
||||||
if (!context.GetPassword().empty())
|
if (client->GetLoginData(loginData))
|
||||||
{
|
{
|
||||||
|
ClientContext &context = client->GetContext();
|
||||||
|
context.SetPlayerName(loginData.userName);
|
||||||
|
context.SetPassword(loginData.password);
|
||||||
|
// TODO handle guest login.
|
||||||
boost::shared_ptr<NetPacket> init(new NetPacket(NetPacket::Alloc));
|
boost::shared_ptr<NetPacket> init(new NetPacket(NetPacket::Alloc));
|
||||||
init->GetMsg()->present = PokerTHMessage_PR_initMessage;
|
init->GetMsg()->present = PokerTHMessage_PR_initMessage;
|
||||||
InitMessage_t *netInit = &init->GetMsg()->choice.initMessage;
|
InitMessage_t *netInit = &init->GetMsg()->choice.initMessage;
|
||||||
@@ -1126,8 +1146,6 @@ ClientStateWaitAuthChallenge::~ClientStateWaitAuthChallenge()
|
|||||||
void
|
void
|
||||||
ClientStateWaitAuthChallenge::Enter(boost::shared_ptr<ClientThread> client)
|
ClientStateWaitAuthChallenge::Enter(boost::shared_ptr<ClientThread> client)
|
||||||
{
|
{
|
||||||
// Now we finally start receiving data.
|
|
||||||
client->StartAsyncRead();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -356,6 +356,15 @@ ClientThread::SelectServer(unsigned serverId)
|
|||||||
m_selectedServerId = serverId;
|
m_selectedServerId = serverId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ClientThread::SetLogin(const std::string &userName, const std::string &password, bool isGuest)
|
||||||
|
{
|
||||||
|
boost::mutex::scoped_lock lock(m_loginDataMutex);
|
||||||
|
m_loginData.userName = userName;
|
||||||
|
m_loginData.password = password;
|
||||||
|
m_loginData.isGuest = isGuest;
|
||||||
|
}
|
||||||
|
|
||||||
ServerInfo
|
ServerInfo
|
||||||
ClientThread::GetServerInfo(unsigned serverId) const
|
ClientThread::GetServerInfo(unsigned serverId) const
|
||||||
{
|
{
|
||||||
@@ -1174,6 +1183,19 @@ ClientThread::UseServer(unsigned serverId)
|
|||||||
context.SetAvatarServerAddr(useInfo.avatarServerAddr);
|
context.SetAvatarServerAddr(useInfo.avatarServerAddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ClientThread::GetLoginData(LoginData &loginData) const
|
||||||
|
{
|
||||||
|
bool retVal = false;
|
||||||
|
boost::mutex::scoped_lock lock(m_loginDataMutex);
|
||||||
|
if (!m_loginData.userName.empty())
|
||||||
|
{
|
||||||
|
loginData = m_loginData;
|
||||||
|
retVal = true;
|
||||||
|
}
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned
|
unsigned
|
||||||
ClientThread::GetGameIdByName(const std::string &name) const
|
ClientThread::GetGameIdByName(const std::string &name) const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -940,13 +940,14 @@ ServerLobbyThread::HandleNetPacketInit(SessionWrapper session, const InitMessage
|
|||||||
|
|
||||||
string playerName;
|
string playerName;
|
||||||
MD5Buf avatarMD5;
|
MD5Buf avatarMD5;
|
||||||
bool guestUser = false;
|
bool noAuth = false;
|
||||||
if (initMessage.login.present == login_PR_guestLogin)
|
if (initMessage.login.present == login_PR_guestLogin)
|
||||||
{
|
{
|
||||||
const GuestLogin_t *guestLogin = &initMessage.login.choice.guestLogin;
|
const GuestLogin_t *guestLogin = &initMessage.login.choice.guestLogin;
|
||||||
playerName = STL_STRING_FROM_OCTET_STRING(guestLogin->nickName);
|
playerName = STL_STRING_FROM_OCTET_STRING(guestLogin->nickName);
|
||||||
guestUser = true;
|
noAuth = true;
|
||||||
}
|
}
|
||||||
|
#ifdef POKERTH_OFFICIAL_SERVER
|
||||||
else if (initMessage.login.present == login_PR_authenticatedLogin)
|
else if (initMessage.login.present == login_PR_authenticatedLogin)
|
||||||
{
|
{
|
||||||
const AuthenticatedLogin_t *authLogin = &initMessage.login.choice.authenticatedLogin;
|
const AuthenticatedLogin_t *authLogin = &initMessage.login.choice.authenticatedLogin;
|
||||||
@@ -957,6 +958,16 @@ ServerLobbyThread::HandleNetPacketInit(SessionWrapper session, const InitMessage
|
|||||||
if (session.sessionData->AuthStep(1, inAuthData))
|
if (session.sessionData->AuthStep(1, inAuthData))
|
||||||
playerName = session.sessionData->AuthGetUser();
|
playerName = session.sessionData->AuthGetUser();
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
else if (initMessage.login.present == login_PR_unauthenticatedLogin)
|
||||||
|
{
|
||||||
|
const UnauthenticatedLogin_t *noauthLogin = &initMessage.login.choice.unauthenticatedLogin;
|
||||||
|
playerName = STL_STRING_FROM_OCTET_STRING(noauthLogin->nickName);
|
||||||
|
if (noauthLogin->avatar)
|
||||||
|
memcpy(avatarMD5.data, noauthLogin->avatar->buf, MD5_DATA_SIZE);
|
||||||
|
noAuth = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
else
|
else
|
||||||
SessionError(session, ERR_NET_INVALID_PASSWORD);
|
SessionError(session, ERR_NET_INVALID_PASSWORD);
|
||||||
|
|
||||||
@@ -1003,7 +1014,7 @@ ServerLobbyThread::HandleNetPacketInit(SessionWrapper session, const InitMessage
|
|||||||
m_sessionManager.SetSessionPlayerData(session.sessionData->GetId(), tmpPlayerData);
|
m_sessionManager.SetSessionPlayerData(session.sessionData->GetId(), tmpPlayerData);
|
||||||
session.playerData = tmpPlayerData;
|
session.playerData = tmpPlayerData;
|
||||||
|
|
||||||
if (guestUser)
|
if (noAuth)
|
||||||
InitAfterLogin(session);
|
InitAfterLogin(session);
|
||||||
else
|
else
|
||||||
AuthenticatePlayer(session);
|
AuthenticatePlayer(session);
|
||||||
|
|||||||
@@ -423,6 +423,14 @@ void Session::selectServer(unsigned serverId)
|
|||||||
myNetClient->SelectServer(serverId);
|
myNetClient->SelectServer(serverId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Session::setLogin(const std::string &userName, const std::string &password, bool isGuest)
|
||||||
|
{
|
||||||
|
if (!myNetClient)
|
||||||
|
return; // only act if client is running.
|
||||||
|
myNetClient->SetLogin(userName, password, isGuest);
|
||||||
|
}
|
||||||
|
|
||||||
void Session::voteKick(bool doKick)
|
void Session::voteKick(bool doKick)
|
||||||
{
|
{
|
||||||
if (!myNetClient)
|
if (!myNetClient)
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ public:
|
|||||||
void startVoteKickPlayer(unsigned playerId);
|
void startVoteKickPlayer(unsigned playerId);
|
||||||
void voteKick(bool doKick);
|
void voteKick(bool doKick);
|
||||||
void selectServer(unsigned serverId);
|
void selectServer(unsigned serverId);
|
||||||
|
void setLogin(const std::string &userName, const std::string &password, bool isGuest);
|
||||||
|
|
||||||
void resetNetworkTimeout();
|
void resetNetworkTimeout();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user