From 10f56871e6c1dff7beee610e80a5b2bd71fbedbb Mon Sep 17 00:00:00 2001 From: kervala Date: Tue, 23 Feb 2016 17:03:40 +0100 Subject: [PATCH] Fixed: Implement alternate login system with LoginCustomParameters --- code/ryzom/client/src/far_tp.cpp | 47 +++++++++-- code/ryzom/client/src/far_tp.h | 5 ++ code/ryzom/client/src/login.cpp | 135 ++++++++++++++++++++++--------- 3 files changed, 144 insertions(+), 43 deletions(-) diff --git a/code/ryzom/client/src/far_tp.cpp b/code/ryzom/client/src/far_tp.cpp index a7a41c628..bd313b830 100644 --- a/code/ryzom/client/src/far_tp.cpp +++ b/code/ryzom/client/src/far_tp.cpp @@ -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: diff --git a/code/ryzom/client/src/far_tp.h b/code/ryzom/client/src/far_tp.h index cec696ba3..a4c8f77b4 100644 --- a/code/ryzom/client/src/far_tp.h +++ b/code/ryzom/client/src/far_tp.h @@ -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(); diff --git a/code/ryzom/client/src/login.cpp b/code/ryzom/client/src/login.cpp index 80e184efe..109f9417e 100644 --- a/code/ryzom/client/src/login.cpp +++ b/code/ryzom/client/src/login.cpp @@ -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");