Implementing guest login.

This commit is contained in:
lotodore
2009-11-15 08:41:29 +00:00
parent d727a7fd5d
commit b8951a61d3
5 changed files with 67 additions and 27 deletions
+39 -24
View File
@@ -1078,37 +1078,52 @@ ClientStateWaitEnterLogin::TimerLoop(const boost::system::error_code& ec, boost:
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;
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())
context.SetPlayerName(loginData.userName);
// Handle guest login first.
if (loginData.isGuest)
{
MD5Buf tmpMD5;
if (client->GetAvatarManager().GetHashForAvatar(avatarFile, tmpMD5))
context.SetPassword("");
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());
}
// If the player is not a guest, authenticate.
else
{
context.SetPassword(loginData.password);
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())
{
// TODO: use sha1.
authLogin->avatar =
OCTET_STRING_new_fromBuf(
&asn_DEF_OCTET_STRING,
(const char *)tmpMD5.data,
MD5_DATA_SIZE);
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);
}
}
}
+14 -1
View File
@@ -941,11 +941,24 @@ ServerLobbyThread::HandleNetPacketInit(SessionWrapper session, const InitMessage
string playerName;
MD5Buf avatarMD5;
bool noAuth = false;
bool validGuest = false;
if (initMessage.login.present == login_PR_guestLogin)
{
const GuestLogin_t *guestLogin = &initMessage.login.choice.guestLogin;
playerName = STL_STRING_FROM_OCTET_STRING(guestLogin->nickName);
noAuth = true;
// Verify guest player name.
if (playerName.length() > sizeof(SERVER_GUEST_PLAYER_NAME - 1)
&& playerName.substr(0, sizeof(SERVER_GUEST_PLAYER_NAME) - 1) == SERVER_GUEST_PLAYER_NAME)
{
string guestId(playerName.substr(sizeof(SERVER_GUEST_PLAYER_NAME)));
if (count_if(guestId.begin(), guestId.end(), isdigit) == guestId.size())
{
validGuest = true;
noAuth = true;
}
}
if (!validGuest)
SessionError(session, ERR_NET_INVALID_PLAYER_NAME);
}
#ifdef POKERTH_OFFICIAL_SERVER
else if (initMessage.login.present == login_PR_authenticatedLogin)