mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-22 23:06:18 +00:00
Fixed: Implement alternate login system with LoginCustomParameters
This commit is contained in:
parent
840f5b7c61
commit
10f56871e6
3 changed files with 144 additions and 43 deletions
|
@ -189,7 +189,7 @@ const std::string& CLoginStateMachine::toString(CLoginStateMachine::TEvent event
|
|||
break; \
|
||||
} \
|
||||
|
||||
extern std::string LoginLogin, LoginPassword;
|
||||
extern std::string LoginLogin, LoginPassword, LoginCustomParameters;
|
||||
extern bool noUserChar;
|
||||
extern bool userChar;
|
||||
extern bool serverReceivedReady;
|
||||
|
@ -248,12 +248,24 @@ void CLoginStateMachine::run()
|
|||
{
|
||||
if (LoginLogin.empty())
|
||||
{
|
||||
// standard procedure
|
||||
SM_BEGIN_EVENT_TABLE
|
||||
SM_EVENT(ev_init_done, st_login);
|
||||
SM_EVENT(ev_skip_all_login, st_ingame);
|
||||
SM_EVENT(ev_quit, st_end);
|
||||
SM_END_EVENT_TABLE
|
||||
if (LoginCustomParameters.empty())
|
||||
{
|
||||
// standard procedure
|
||||
SM_BEGIN_EVENT_TABLE
|
||||
SM_EVENT(ev_init_done, st_login);
|
||||
SM_EVENT(ev_skip_all_login, st_ingame);
|
||||
SM_EVENT(ev_quit, st_end);
|
||||
SM_END_EVENT_TABLE
|
||||
}
|
||||
else
|
||||
{
|
||||
// alternate login procedure
|
||||
SM_BEGIN_EVENT_TABLE
|
||||
SM_EVENT(ev_init_done, st_alt_login);
|
||||
SM_EVENT(ev_skip_all_login, st_ingame);
|
||||
SM_EVENT(ev_quit, st_end);
|
||||
SM_END_EVENT_TABLE
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -325,6 +337,27 @@ void CLoginStateMachine::run()
|
|||
// SM_EVENT(ev_login_ok, st_check_patch);
|
||||
// SM_EVENT(ev_quit, st_end);
|
||||
// SM_END_EVENT_TABLE
|
||||
// }
|
||||
break;
|
||||
case st_alt_login:
|
||||
initAltLogin();
|
||||
|
||||
// if (ClientCfg.R2Mode)
|
||||
{
|
||||
// r2 mode
|
||||
SM_BEGIN_EVENT_TABLE
|
||||
SM_EVENT(ev_login_not_alt, st_login);
|
||||
SM_EVENT(ev_login_ok, st_check_patch);
|
||||
SM_EVENT(ev_quit, st_end);
|
||||
SM_END_EVENT_TABLE
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// // legacy mode
|
||||
// SM_BEGIN_EVENT_TABLE
|
||||
// SM_EVENT(ev_login_ok, st_check_patch);
|
||||
// SM_EVENT(ev_quit, st_end);
|
||||
// SM_END_EVENT_TABLE
|
||||
// }
|
||||
break;
|
||||
case st_shard_list:
|
||||
|
|
|
@ -81,6 +81,8 @@ public:
|
|||
st_rate_session,
|
||||
/// create account
|
||||
st_create_account,
|
||||
/// try to login with alternate login system
|
||||
st_alt_login,
|
||||
/// pseudo state to leave the state machine
|
||||
st_end,
|
||||
///
|
||||
|
@ -156,6 +158,8 @@ public:
|
|||
ev_create_account,
|
||||
/// the client push the 'create account' button
|
||||
ev_close_create_account,
|
||||
/// the client want to use alternate login system
|
||||
ev_login_not_alt,
|
||||
///
|
||||
ev_unknown
|
||||
};
|
||||
|
@ -203,6 +207,7 @@ void initEula();
|
|||
void initPatchCheck();
|
||||
void initCatDisplay();
|
||||
void initAutoLogin();
|
||||
void initAltLogin();
|
||||
void initPatch();
|
||||
//void initWebBrowser();
|
||||
void initReboot();
|
||||
|
|
|
@ -842,6 +842,55 @@ void initAutoLogin()
|
|||
}
|
||||
}
|
||||
|
||||
void initAltLogin()
|
||||
{
|
||||
// Check the alt param
|
||||
if (!LoginCustomParameters.empty())
|
||||
{
|
||||
// don't use login and password for alternate login
|
||||
string res = checkLogin("", "", ClientApp, LoginCustomParameters);
|
||||
if (res.empty())
|
||||
{
|
||||
if (ClientCfg.R2Mode)
|
||||
{
|
||||
LoginSM.pushEvent(CLoginStateMachine::ev_login_ok);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Select good shard
|
||||
ShardSelected = -1;
|
||||
for (uint32 i = 0; i < Shards.size(); ++i)
|
||||
{
|
||||
if (Shards[i].ShardId == LoginShardId)
|
||||
{
|
||||
ShardSelected = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ShardSelected == -1)
|
||||
{
|
||||
CInterfaceManager *pIM = CInterfaceManager::getInstance();
|
||||
pIM->messageBoxWithHelp(CI18N::get("uiErrServerLost"), "ui:login");
|
||||
LoginSM.pushEvent(CLoginStateMachine::ev_quit);
|
||||
}
|
||||
else
|
||||
{
|
||||
LoginSM.pushEvent(CLoginStateMachine::ev_login_ok);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// close the socket in case of error
|
||||
HttpClient.disconnect();
|
||||
|
||||
// ignore error
|
||||
LoginSM.pushEvent(CLoginStateMachine::ev_login_not_alt);
|
||||
}
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
// Called from client.cpp
|
||||
|
@ -2732,49 +2781,63 @@ string checkLogin(const string &login, const string &password, const string &cli
|
|||
|
||||
string res;
|
||||
|
||||
// ask server for salt
|
||||
if(!HttpClient.sendGet(ClientCfg.ConfigFile.getVar("StartupPage").asString()+"?cmd=ask&login="+login+"&lg="+ClientCfg.LanguageCode, "", pPM->isVerboseLog()))
|
||||
return "Can't send (error code 60)";
|
||||
|
||||
if(pPM->isVerboseLog()) nlinfo("Sent request for password salt");
|
||||
|
||||
if(!HttpClient.receive(res, pPM->isVerboseLog()))
|
||||
return "Can't receive (error code 61)";
|
||||
|
||||
if(pPM->isVerboseLog()) nlinfo("Received request login check");
|
||||
|
||||
if(res.empty())
|
||||
return "Empty answer from server (error code 62)";
|
||||
|
||||
if(res[0] == '0')
|
||||
// don't use login with alt method
|
||||
if (!login.empty())
|
||||
{
|
||||
// server returns an error
|
||||
nlwarning("server error: %s", res.substr(2).c_str());
|
||||
return res.substr(2);
|
||||
}
|
||||
else if(res[0] == '1')
|
||||
{
|
||||
Salt = res.substr(2);
|
||||
}
|
||||
else
|
||||
{
|
||||
// server returns ???
|
||||
nlwarning("%s", res.c_str());
|
||||
return res;
|
||||
}
|
||||
// ask server for salt
|
||||
if(!HttpClient.sendGet(ClientCfg.ConfigFile.getVar("StartupPage").asString()+"?cmd=ask&login="+login+"&lg="+ClientCfg.LanguageCode, "", pPM->isVerboseLog()))
|
||||
return "Can't send (error code 60)";
|
||||
|
||||
// send login + crypted password + client app and cp=1 (as crypted password)
|
||||
if(!HttpClient.connectToLogin())
|
||||
return "Can't connect (error code 63)";
|
||||
if(pPM->isVerboseLog()) nlinfo("Sent request for password salt");
|
||||
|
||||
if(pPM->isVerboseLog()) nlinfo("Connected");
|
||||
if(!HttpClient.receive(res, pPM->isVerboseLog()))
|
||||
return "Can't receive (error code 61)";
|
||||
|
||||
if(pPM->isVerboseLog()) nlinfo("Received request login check");
|
||||
|
||||
if(res.empty())
|
||||
return "Empty answer from server (error code 62)";
|
||||
|
||||
if(res[0] == '0')
|
||||
{
|
||||
// server returns an error
|
||||
nlwarning("server error: %s", res.substr(2).c_str());
|
||||
return res.substr(2);
|
||||
}
|
||||
else if(res[0] == '1')
|
||||
{
|
||||
Salt = res.substr(2);
|
||||
}
|
||||
else
|
||||
{
|
||||
// server returns ???
|
||||
nlwarning("%s", res.c_str());
|
||||
return res;
|
||||
}
|
||||
|
||||
// send login + crypted password + client app and cp=1 (as crypted password)
|
||||
if(!HttpClient.connectToLogin())
|
||||
return "Can't connect (error code 63)";
|
||||
|
||||
if(pPM->isVerboseLog()) nlinfo("Connected");
|
||||
}
|
||||
|
||||
if (ClientCfg.R2Mode)
|
||||
{
|
||||
// R2 login sequence
|
||||
std::string cryptedPassword = CCrypt::crypt(password, Salt);
|
||||
if(!HttpClient.sendGet(ClientCfg.ConfigFile.getVar("StartupPage").asString()+"?cmd=login&login="+login+"&password="+cryptedPassword+"&clientApplication="+clientApp+"&cp=1"+"&lg="+ClientCfg.LanguageCode+customParameters))
|
||||
return "Can't send (error code 2)";
|
||||
|
||||
if (!login.empty())
|
||||
{
|
||||
std::string cryptedPassword = CCrypt::crypt(password, Salt);
|
||||
if(!HttpClient.sendGet(ClientCfg.ConfigFile.getVar("StartupPage").asString()+"?cmd=login&login="+login+"&password="+cryptedPassword+"&clientApplication="+clientApp+"&cp=1"+"&lg="+ClientCfg.LanguageCode+customParameters))
|
||||
return "Can't send (error code 2)";
|
||||
}
|
||||
else
|
||||
{
|
||||
// don't send login and password if empty
|
||||
if(!HttpClient.sendGet(ClientCfg.ConfigFile.getVar("StartupPage").asString()+"?cmd=login&clientApplication="+clientApp+"&cp=1"+"&lg="+ClientCfg.LanguageCode+customParameters))
|
||||
return "Can't send (error code 2)";
|
||||
}
|
||||
|
||||
// the response should contains the result code and the cookie value
|
||||
if(pPM->isVerboseLog()) nlinfo("Sent request login check");
|
||||
|
|
Loading…
Reference in a new issue