[Loginserver] Add some resiliency to LS requests (#1663)

This commit is contained in:
Chris Miles 2021-11-02 00:19:13 -05:00 committed by GitHub
parent 9af7122b1d
commit 05782433b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 60 deletions

View File

@ -280,6 +280,8 @@ bool AccountManagement::UpdateLoginserverWorldAdminAccountPasswordById(
return updated_account;
}
constexpr int REQUEST_TIMEOUT_MS = 1500;
/**
* @param in_account_username
* @param in_account_password
@ -386,8 +388,16 @@ uint32 AccountManagement::CheckExternalLoginserverUserCredentials(
}
);
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
auto &loop = EQ::EventLoop::Get();
while (running) {
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
if (std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count() > REQUEST_TIMEOUT_MS) {
LogInfo("[CheckExternalLoginserverUserCredentials] Deadline exceeded [{}]", REQUEST_TIMEOUT_MS);
running = false;
}
loop.Process();
}

View File

@ -4,6 +4,7 @@
#include "../common/eqemu_logsys.h"
#include "../common/string_util.h"
#include "encryption.h"
#include "account_management.h"
extern LoginServer server;
@ -13,10 +14,10 @@ extern LoginServer server;
*/
Client::Client(std::shared_ptr<EQStreamInterface> c, LSClientVersion v)
{
m_connection = c;
m_client_version = v;
m_client_status = cs_not_sent_session_ready;
m_account_id = 0;
m_connection = c;
m_client_version = v;
m_client_status = cs_not_sent_session_ready;
m_account_id = 0;
m_play_server_id = 0;
m_play_sequence_id = 0;
}
@ -303,7 +304,7 @@ void Client::Handle_Play(const char *data)
);
}
m_play_server_id = (unsigned int) play->ServerNumber;
m_play_server_id = (unsigned int) play->ServerNumber;
m_play_sequence_id = sequence_in;
m_play_server_id = server_id_in;
server.server_manager->SendUserToWorldRequest(server_id_in, m_account_id, m_loginserver_name);
@ -375,59 +376,18 @@ void Client::AttemptLoginAccountCreation(
return;
}
if (server.options.GetEQEmuLoginServerAddress().length() == 0) {
DoFailedLogin();
return;
}
auto addr_components = SplitString(server.options.GetEQEmuLoginServerAddress(), ':');
if (addr_components.size() != 2) {
DoFailedLogin();
return;
}
m_stored_user = user;
m_stored_pass = pass;
auto address = addr_components[0];
auto port = std::stoi(addr_components[1]);
EQ::Net::DNSLookup(
address, port, false, [=](const std::string &addr) {
if (addr.empty()) {
DoFailedLogin();
return;
}
m_login_connection_manager.reset(new EQ::Net::DaybreakConnectionManager());
m_login_connection_manager->OnNewConnection(
std::bind(
&Client::LoginOnNewConnection,
this,
std::placeholders::_1
)
);
m_login_connection_manager->OnConnectionStateChange(
std::bind(
&Client::LoginOnStatusChange,
this,
std::placeholders::_1,
std::placeholders::_2,
std::placeholders::_3
)
);
m_login_connection_manager->OnPacketRecv(
std::bind(
&Client::LoginOnPacketRecv,
this,
std::placeholders::_1,
std::placeholders::_2
)
);
m_login_connection_manager->Connect(addr, port);
}
uint32 account_id = AccountManagement::CheckExternalLoginserverUserCredentials(
user,
pass
);
if (account_id > 0) {
LogInfo("[AttemptLoginAccountCreation] Found and creating eqemu account [{}]", account_id);
CreateEQEmuAccount(user, pass, account_id);
return;
}
DoFailedLogin();
return;
}
#endif
@ -569,7 +529,7 @@ void Client::DoSuccessfulLogin(
server.db->UpdateLSAccountData(db_account_id, std::string(inet_ntoa(in)));
GenerateKey();
m_account_id = db_account_id;
m_account_id = db_account_id;
m_account_name = in_account_name;
m_loginserver_name = db_loginserver;
@ -795,9 +755,9 @@ void Client::LoginProcessLoginResponse(const EQ::Net::Packet &p)
}
else {
LogDebug(
"response [{0}] login succeeded user [{1}]",
response_error,
m_stored_user
"response [{0}] login succeeded user [{1}]",
response_error,
m_stored_user
);
auto m_dbid = sp.GetUInt32(8);