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();
|
||||
if(myInternetGameLoginDialog->result() == QDialog::Accepted) {
|
||||
//send login infos
|
||||
// mySession->
|
||||
mySession->setLogin(
|
||||
myInternetGameLoginDialog->lineEdit_username->text().toUtf8().constData(),
|
||||
myInternetGameLoginDialog->lineEdit_password->text().toUtf8().constData(),
|
||||
myInternetGameLoginDialog->checkBox_guest->isChecked());
|
||||
}
|
||||
else {
|
||||
myConnectToServerDialog->reject();
|
||||
|
||||
@@ -83,6 +83,7 @@ public:
|
||||
void HandleRead(const boost::system::error_code& ec, size_t bytesRead);
|
||||
|
||||
void SelectServer(unsigned serverId);
|
||||
void SetLogin(const std::string &userName, const std::string &password, bool isGuest);
|
||||
ServerInfo GetServerInfo(unsigned serverId) const;
|
||||
|
||||
GameInfo GetGameInfo(unsigned gameId) const;
|
||||
@@ -103,6 +104,13 @@ protected:
|
||||
typedef std::map<unsigned, PlayerInfo> PlayerInfoMap;
|
||||
typedef std::map<unsigned, boost::shared_ptr<AvatarFile> > AvatarFileMap;
|
||||
typedef std::map<unsigned, ServerInfo> ServerInfoMap;
|
||||
struct LoginData
|
||||
{
|
||||
LoginData() : isGuest(false) {}
|
||||
std::string userName;
|
||||
std::string password;
|
||||
bool isGuest;
|
||||
};
|
||||
|
||||
// Main function of the thread.
|
||||
virtual void Main();
|
||||
@@ -174,6 +182,8 @@ protected:
|
||||
bool GetSelectedServer(unsigned &serverId) const;
|
||||
void UseServer(unsigned serverId);
|
||||
|
||||
bool GetLoginData(LoginData &loginData) const;
|
||||
|
||||
unsigned GetGameIdByName(const std::string &name) const;
|
||||
void AddGameInfo(unsigned gameId, const GameInfo &info);
|
||||
void UpdateGameInfoMode(unsigned gameId, GameMode mode);
|
||||
@@ -224,6 +234,9 @@ private:
|
||||
unsigned m_selectedServerId;
|
||||
mutable boost::mutex m_selectServerMutex;
|
||||
|
||||
LoginData m_loginData;
|
||||
mutable boost::mutex m_loginDataMutex;
|
||||
|
||||
GameInfoMap m_gameInfoMap;
|
||||
mutable boost::mutex m_gameInfoMapMutex;
|
||||
|
||||
|
||||
@@ -965,6 +965,8 @@ ClientStateStartSession::~ClientStateStartSession()
|
||||
void
|
||||
ClientStateStartSession::Enter(boost::shared_ptr<ClientThread> client)
|
||||
{
|
||||
// Now we finally start receiving data.
|
||||
client->StartAsyncRead();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -999,7 +1001,7 @@ ClientStateStartSession::InternalHandlePacket(boost::shared_ptr<ClientThread> cl
|
||||
client->GetCallback().SignalNetClientLoginShow();
|
||||
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
|
||||
|| netAnnounce->serverType == serverType_serverTypeLAN)
|
||||
{
|
||||
@@ -1008,13 +1010,27 @@ ClientStateStartSession::InternalHandlePacket(boost::shared_ptr<ClientThread> cl
|
||||
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,
|
||||
netInit->login.present = login_PR_unauthenticatedLogin;
|
||||
UnauthenticatedLogin_t *noauthLogin = &netInit->login.choice.unauthenticatedLogin;
|
||||
OCTET_STRING_fromBuf(&noauthLogin->nickName,
|
||||
context.GetPlayerName().c_str(),
|
||||
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->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)
|
||||
{
|
||||
ClientContext &context = client->GetContext();
|
||||
if (!context.GetPassword().empty())
|
||||
ClientThread::LoginData loginData;
|
||||
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));
|
||||
init->GetMsg()->present = PokerTHMessage_PR_initMessage;
|
||||
InitMessage_t *netInit = &init->GetMsg()->choice.initMessage;
|
||||
@@ -1126,8 +1146,6 @@ ClientStateWaitAuthChallenge::~ClientStateWaitAuthChallenge()
|
||||
void
|
||||
ClientStateWaitAuthChallenge::Enter(boost::shared_ptr<ClientThread> client)
|
||||
{
|
||||
// Now we finally start receiving data.
|
||||
client->StartAsyncRead();
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -356,6 +356,15 @@ ClientThread::SelectServer(unsigned 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
|
||||
ClientThread::GetServerInfo(unsigned serverId) const
|
||||
{
|
||||
@@ -1174,6 +1183,19 @@ ClientThread::UseServer(unsigned serverId)
|
||||
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
|
||||
ClientThread::GetGameIdByName(const std::string &name) const
|
||||
{
|
||||
|
||||
@@ -940,13 +940,14 @@ ServerLobbyThread::HandleNetPacketInit(SessionWrapper session, const InitMessage
|
||||
|
||||
string playerName;
|
||||
MD5Buf avatarMD5;
|
||||
bool guestUser = false;
|
||||
bool noAuth = false;
|
||||
if (initMessage.login.present == login_PR_guestLogin)
|
||||
{
|
||||
const GuestLogin_t *guestLogin = &initMessage.login.choice.guestLogin;
|
||||
playerName = STL_STRING_FROM_OCTET_STRING(guestLogin->nickName);
|
||||
guestUser = true;
|
||||
noAuth = true;
|
||||
}
|
||||
#ifdef POKERTH_OFFICIAL_SERVER
|
||||
else if (initMessage.login.present == login_PR_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))
|
||||
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
|
||||
SessionError(session, ERR_NET_INVALID_PASSWORD);
|
||||
|
||||
@@ -1003,7 +1014,7 @@ ServerLobbyThread::HandleNetPacketInit(SessionWrapper session, const InitMessage
|
||||
m_sessionManager.SetSessionPlayerData(session.sessionData->GetId(), tmpPlayerData);
|
||||
session.playerData = tmpPlayerData;
|
||||
|
||||
if (guestUser)
|
||||
if (noAuth)
|
||||
InitAfterLogin(session);
|
||||
else
|
||||
AuthenticatePlayer(session);
|
||||
|
||||
@@ -423,6 +423,14 @@ void Session::selectServer(unsigned 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)
|
||||
{
|
||||
if (!myNetClient)
|
||||
|
||||
@@ -84,6 +84,7 @@ public:
|
||||
void startVoteKickPlayer(unsigned playerId);
|
||||
void voteKick(bool doKick);
|
||||
void selectServer(unsigned serverId);
|
||||
void setLogin(const std::string &userName, const std::string &password, bool isGuest);
|
||||
|
||||
void resetNetworkTimeout();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user