Skip to content

Commit

Permalink
client side: --auto-login
Browse files Browse the repository at this point in the history
  • Loading branch information
etorth committed Aug 13, 2023
1 parent a9784a1 commit ec5f767
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
6 changes: 3 additions & 3 deletions client/src/clientargparser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ struct ClientArgParser
if(const auto autoLoginStr = cmdParser("auto-login").str(); !autoLoginStr.empty()){
const auto pos = autoLoginStr.find(':');

fflassert(pos != std::string::npos);
fflassert(pos != 0);
fflassert(pos != autoLoginStr.size() - 1);
if(pos == std::string::npos ||
pos == 0 ||
pos == autoLoginStr.size() - 1) throw fflerror("usage: --auto-login=id:password");

return std::make_pair(autoLoginStr.substr(0, pos), autoLoginStr.substr(pos + 1));
}
Expand Down
23 changes: 17 additions & 6 deletions client/src/processlogin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
#include "buildconfig.hpp"
#include "notifyboard.hpp"
#include "processlogin.hpp"
#include "clientargparser.hpp"

extern Log *g_log;
extern Client *g_client;
extern PNGTexDB *g_progUseDB;
extern SDLDevice *g_sdlDevice;
extern BGMusicDB *g_bgmDB;
extern ClientArgParser *g_clientArgParser;

ProcessLogin::ProcessLogin()
: Process()
Expand Down Expand Up @@ -108,6 +110,10 @@ ProcessLogin::ProcessLogin()
{
m_buildSignature.setText(u8"编译版本号:%s", getBuildSignature());
g_sdlDevice->playBGM(g_bgmDB->retrieve(0X00040007));

if(g_clientArgParser->autoLogin.has_value()){
sendLogin(g_clientArgParser->autoLogin.value().first, g_clientArgParser->autoLogin.value().second);
}
}

void ProcessLogin::update(double fUpdateTime)
Expand Down Expand Up @@ -197,12 +203,7 @@ void ProcessLogin::doLogin()
// this allows some test account like: (test, 123456)
// but when creating account, changing password we need to be extremely careful

CMLogin cmL;
std::memset(&cmL, 0, sizeof(cmL));

cmL.id.assign(idStr);
cmL.password.assign(pwdStr);
g_client->send(CM_LOGIN, cmL);
sendLogin(idStr, pwdStr);
}
}

Expand All @@ -220,3 +221,13 @@ void ProcessLogin::doExit()
{
std::exit(0);
}

void ProcessLogin::sendLogin(const std::string &id, const std::string &password)
{
CMLogin cmL;
std::memset(&cmL, 0, sizeof(cmL));

cmL.id.assign(id);
cmL.password.assign(password);
g_client->send(CM_LOGIN, cmL);
}
3 changes: 3 additions & 0 deletions client/src/processlogin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class ProcessLogin: public Process
void doCreateAccount();
void doChangePassword();

private:
void sendLogin(const std::string &, const std::string &);

public:
void net_LOGINOK (const uint8_t *, size_t);
void net_LOGINERROR(const uint8_t *, size_t);
Expand Down
7 changes: 7 additions & 0 deletions client/src/processselectcharnet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
#include "dbcomid.hpp"
#include "client.hpp"
#include "fflerror.hpp"
#include "clientargparser.hpp"
#include "processselectchar.hpp"

extern Client *g_client;
extern ClientArgParser *g_clientArgParser;

void ProcessSelectChar::net_QUERYCHAROK(const uint8_t *buf, size_t)
{
m_smChar = ServerMsg::conv<SMQueryCharOK>(buf);
Expand All @@ -14,6 +17,10 @@ void ProcessSelectChar::net_QUERYCHAROK(const uint8_t *buf, size_t)
if(m_smChar.value().name.empty()){
m_notifyBoard.addLog(u8"请先创建游戏角色");
}
else if(g_clientArgParser->autoLogin){
onStart();
}

updateGUIActive();
}

Expand Down

0 comments on commit ec5f767

Please sign in to comment.