This commit is contained in:
Akkadius 2019-07-09 02:10:10 -05:00
parent 8c75cf1ff5
commit 8eaeda5ec5
10 changed files with 217 additions and 108 deletions

View File

@ -147,9 +147,6 @@ SET(EQEMU_LOG_LEVEL_DEBUG 3 CACHE STRING "EQEmu logging level for [Debug]:
)
OPTION(EQEMU_LSPX "" OFF)
IF(EQEMU_LSPX)
ADD_DEFINITIONS(-DLSPX=ON)
ENDIF(EQEMU_LSPX)
MARK_AS_ADVANCED(EQEMU_LSPX)
MARK_AS_ADVANCED(EQEMU_LOG_LEVEL_DEBUG)
@ -164,6 +161,10 @@ IF(EQEMU_COMMANDS_LOGGING)
ADD_DEFINITIONS(-DCOMMANDS_LOGGING)
ENDIF(EQEMU_COMMANDS_LOGGING)
IF(EQEMU_LSPX)
ADD_DEFINITIONS(-DLSPX=ON)
ENDIF(EQEMU_LSPX)
IF(EQEMU_ENABLE_BOTS)
ADD_DEFINITIONS(-DBOTS)
ENDIF(EQEMU_ENABLE_BOTS)

View File

@ -472,7 +472,7 @@ struct ServerLSAccountUpdate_Struct { // for updating info on login server
uint32 useraccountid; // player account ID
char useraccount[31]; // player account name
char userpassword[51]; // player account password
char useremail[101]; // player account email address
char user_email[101]; // player account email address
};
struct ServerLSStatus_Struct {

View File

@ -383,11 +383,10 @@ void Client::AttemptLoginAccountCreation(
const std::string &loginserver
)
{
#ifdef LSPX
if (loginserver == "eqemu") {
LogInfo("Attempting login account creation via '{0}'", loginserver);
#ifdef LSPX
if (loginserver == "eqemu") {
if (!server.options.CanAutoLinkAccounts()) {
LogInfo("CanAutoLinkAccounts disabled - sending failed login");
DoFailedLogin();
@ -452,6 +451,7 @@ void Client::AttemptLoginAccountCreation(
#endif
if (server.options.CanAutoCreateAccounts() && loginserver == "local") {
LogInfo("CanAutoCreateAccounts enabled, attempting to creating account [{0}]", user);
CreateLocalAccount(user, pass);
return;
}

View File

@ -503,7 +503,7 @@ std::string Database::CreateLoginserverApiToken(
{
std::string token = EQ::Util::UUID::Generate().ToString();
auto query = fmt::format(
"INSERT INTO loginserver_api_tokens (token, can_write, can_read, created_at) VALUES ('{0}', {1}, {2}, NOW())",
"INSERT INTO login_api_tokens (token, can_write, can_read, created_at) VALUES ('{0}', {1}, {2}, NOW())",
token,
(write_mode ? "1" : "0"),
(read_mode ? "1" : "0")

View File

@ -65,6 +65,15 @@ public:
std::string &password,
unsigned int &id
);
/**
* @param token
* @param ip
* @param db_account_id
* @param db_loginserver
* @param user
* @return
*/
bool GetLoginTokenDataFromToken(
const std::string &token,
const std::string &ip,
@ -72,13 +81,34 @@ public:
std::string &db_loginserver,
std::string &user
);
/**
* @param loginserver
* @return
*/
unsigned int GetFreeID(const std::string &loginserver);
/**
* @param name
* @param password
* @param loginserver
* @param id
* @return
*/
bool CreateLoginData(
const std::string &name,
const std::string &password,
const std::string &loginserver,
unsigned int &id
);
/**
* @param in_account_name
* @param in_account_password
* @param loginserver
* @param id
* @return
*/
bool CreateLoginDataWithID(
const std::string &in_account_name,
const std::string &in_account_password,
@ -86,8 +116,20 @@ public:
unsigned int id
);
/**
* @param name
* @param loginserver
* @param hash
*/
void UpdateLoginHash(const std::string &name, const std::string &loginserver, const std::string &hash);
/**
* @param name
* @param password
* @param loginserver
* @param id
* @return
*/
bool DoesLoginServerAccountExist(
const std::string &name,
const std::string &password,
@ -122,10 +164,38 @@ public:
const std::string& local_ip
);
/**
* @param id
* @param ip_address
*/
void UpdateLSAccountData(unsigned int id, std::string ip_address);
/**
* @param id
* @param name
* @param password
* @param email
*/
void UpdateLSAccountInfo(unsigned int id, std::string name, std::string password, std::string email);
/**
* @param id
* @param long_name
* @param ip_address
*/
void UpdateWorldRegistration(unsigned int id, std::string long_name, std::string ip_address);
/**
* @param long_name
* @param short_name
* @param id
* @return
*/
bool CreateWorldRegistration(std::string long_name, std::string short_name, unsigned int &id);
/**
* @param log_settings
*/
void LoadLogSettings(EQEmuLogSys::LogSettings *log_settings);
/**

View File

@ -63,6 +63,7 @@ int main(int argc, char** argv)
server.options.AutoCreateAccounts(server.config.GetVariableBool("general", "auto_create_accounts", true));
server.options.AutoLinkAccounts(server.config.GetVariableBool("general", "auto_link_accounts", true));
#ifdef LSPX
server.options.EQEmuLoginServerAddress(
server.config.GetVariableString(
"general",
@ -78,6 +79,7 @@ int main(int argc, char** argv)
"local"
)
);
#endif
#ifdef ENABLE_SECURITY
@ -175,6 +177,19 @@ int main(int argc, char** argv)
LoginserverCommandHandler::CommandHandler(argc, argv);
LogInfo("[Config] IsTraceOn [{0}]", server.options.IsTraceOn());
LogInfo("[Config] IsWorldTraceOn [{0}]", server.options.IsWorldTraceOn());
LogInfo("[Config] IsDumpInPacketsOn [{0}]", server.options.IsDumpInPacketsOn());
LogInfo("[Config] IsDumpOutPacketsOn [{0}]", server.options.IsDumpOutPacketsOn());
LogInfo("[Config] IsRejectingDuplicateServers [{0}]", server.options.IsRejectingDuplicateServers());
LogInfo("[Config] CanAutoCreateAccounts [{0}]", server.options.CanAutoCreateAccounts());
LogInfo("[Config] CanAutoLinkAccounts [{0}]", server.options.CanAutoLinkAccounts());
LogInfo("[Config] GetEncryptionMode [{0}]", server.options.GetEncryptionMode());
LogInfo("[Config] IsUnregisteredAllowed [{0}]", server.options.IsUnregisteredAllowed());
LogInfo("[Config] IsTokenLoginAllowed [{0}]", server.options.IsTokenLoginAllowed());
LogInfo("[Config] IsPasswordLoginAllowed [{0}]", server.options.IsPasswordLoginAllowed());
LogInfo("[Config] IsUpdatingInsecurePasswords [{0}]", server.options.IsUpdatingInsecurePasswords());
while (run_server) {
Timer::SetCurrentTime();
server.client_manager->Process();

View File

@ -121,7 +121,7 @@ EQApplicationPacket *ServerManager::CreateServerListPacket(Client *client, uint3
{
unsigned int packet_size = sizeof(ServerListHeader_Struct);
unsigned int server_count = 0;
in_addr in;
in_addr in{};
in.s_addr = client->GetConnection()->GetRemoteIP();
std::string client_ip = inet_ntoa(in);
@ -174,13 +174,13 @@ EQApplicationPacket *ServerManager::CreateServerListPacket(Client *client, uint3
iter = world_servers.begin();
while (iter != world_servers.end()) {
if ((*iter)->IsAuthorized() == false) {
if (!(*iter)->IsAuthorized()) {
++iter;
continue;
}
std::string world_ip = (*iter)->GetConnection()->Handle()->RemoteIP();
if (world_ip.compare(client_ip) == 0) {
if (world_ip == client_ip) {
memcpy(data_pointer, (*iter)->GetLocalIP().c_str(), (*iter)->GetLocalIP().size());
data_pointer += ((*iter)->GetLocalIP().size() + 1);
}

View File

@ -219,13 +219,13 @@ void WorldServer::ProcessUserToWorldResponseLegacy(uint16_t opcode, const EQ::Ne
auto *user_to_world_response = (UsertoWorldResponseLegacy_Struct *) packet.Data();
LogDebug("Trying to find client with user id of [{0}]", user_to_world_response->lsaccountid);
Client *c = server.client_manager->GetClient(user_to_world_response->lsaccountid, "eqemu");
if (c) {
Client *client = server.client_manager->GetClient(user_to_world_response->lsaccountid, "eqemu");
if (client) {
LogDebug(
"Found client with user id of [{0}] and account name of [{1}]",
user_to_world_response->lsaccountid,
c->GetAccountName()
client->GetAccountName()
);
auto *outapp = new EQApplicationPacket(
@ -234,17 +234,17 @@ void WorldServer::ProcessUserToWorldResponseLegacy(uint16_t opcode, const EQ::Ne
);
auto *per = (PlayEverquestResponse_Struct *) outapp->pBuffer;
per->Sequence = c->GetPlaySequence();
per->ServerNumber = c->GetPlayServerID();
per->Sequence = client->GetPlaySequence();
per->ServerNumber = client->GetPlayServerID();
if (user_to_world_response->response > 0) {
per->Allowed = 1;
SendClientAuth(
c->GetConnection()->GetRemoteAddr(),
c->GetAccountName(),
c->GetKey(),
c->GetAccountID(),
c->GetLoginServerName()
client->GetConnection()->GetRemoteAddr(),
client->GetAccountName(),
client->GetKey(),
client->GetAccountID(),
client->GetLoginServerName()
);
}
@ -281,7 +281,7 @@ void WorldServer::ProcessUserToWorldResponseLegacy(uint16_t opcode, const EQ::Ne
DumpPacket(outapp);
}
c->SendPlayResponse(outapp);
client->SendPlayResponse(outapp);
delete outapp;
}
else {
@ -311,10 +311,11 @@ void WorldServer::ProcessUserToWorldResponse(uint16_t opcode, const EQ::Net::Pac
}
if (packet.Length() < sizeof(UsertoWorldResponse_Struct)) {
Log(Logs::General,
Logs::Error,
LogError(
"Received application packet from server that had opcode ServerOP_UsertoWorldResp, "
"but was too small. Discarded to avoid buffer overrun");
"but was too small. Discarded to avoid buffer overrun"
);
return;
}
@ -326,11 +327,13 @@ void WorldServer::ProcessUserToWorldResponse(uint16_t opcode, const EQ::Net::Pac
}
auto user_to_world_response = (UsertoWorldResponse_Struct *) packet.Data();
Log(Logs::General, Logs::Debug, "Trying to find client with user id of %u.", user_to_world_response->lsaccountid);
LogDebug("Trying to find client with user id of [{0}]", user_to_world_response->lsaccountid);
Client *client = server.client_manager->GetClient(
user_to_world_response->lsaccountid,
user_to_world_response->login
);
if (client) {
LogDebug("Found client with user id of {0} and account name of {1}",
user_to_world_response->lsaccountid,
@ -345,9 +348,9 @@ void WorldServer::ProcessUserToWorldResponse(uint16_t opcode, const EQ::Net::Pac
auto *per = (PlayEverquestResponse_Struct *) outapp->pBuffer;
per->Sequence = client->GetPlaySequence();
per->ServerNumber = client->GetPlayServerID();
Log(Logs::General,
Logs::Debug,
"Found sequence and play of %u %u",
LogDebug(
"Found sequence and play of [{0}] [{1}]",
client->GetPlaySequence(),
client->GetPlayServerID()
);
@ -402,8 +405,10 @@ void WorldServer::ProcessUserToWorldResponse(uint16_t opcode, const EQ::Net::Pac
delete outapp;
}
else {
LogError("Received User-To-World Response for {0} but could not find the client referenced!.",
user_to_world_response->lsaccountid);
LogError(
"Received User-To-World Response for {0} but could not find the client referenced!.",
user_to_world_response->lsaccountid
);
}
}
@ -437,22 +442,25 @@ void WorldServer::ProcessLSAccountUpdate(uint16_t opcode, const EQ::Net::Packet
Log(Logs::General, Logs::Netcode, "ServerOP_LSAccountUpdate packet received from: %s", short_name.c_str());
auto *loginserver_update = (ServerLSAccountUpdate_Struct *) packet.Data();
if (is_server_trusted) {
Log(Logs::General,
Logs::Netcode,
"ServerOP_LSAccountUpdate update processed for: %s",
loginserver_update->useraccount);
std::string name = "";
std::string password = "";
std::string email = "";
if (IsServerTrusted()) {
LogDebug("ServerOP_LSAccountUpdate update processed for: [{0}]", loginserver_update->useraccount);
std::string name;
std::string password;
std::string email;
name.assign(loginserver_update->useraccount);
password.assign(loginserver_update->userpassword);
if (loginserver_update->useremail) {
email.assign(loginserver_update->useremail);
if (loginserver_update->user_email) {
email.assign(loginserver_update->user_email);
}
server.db->UpdateLSAccountInfo(loginserver_update->useraccountid, name, password, email);
server.db->UpdateLSAccountInfo(
loginserver_update->useraccountid,
name,
password,
email
);
}
}
@ -473,8 +481,7 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct *new_world_server_info
return;
}
this
->SetAccountPassword(new_world_server_info_packet->account_password)
this->SetAccountPassword(new_world_server_info_packet->account_password)
->SetLongName(new_world_server_info_packet->server_long_name)
->SetShortName(new_world_server_info_packet->server_short_name)
->SetLocalIp(new_world_server_info_packet->local_ip_address)
@ -486,30 +493,40 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct *new_world_server_info
->SetAccountName(new_world_server_info_packet->account_name);
if (server.options.IsRejectingDuplicateServers()) {
if (server.server_manager->ServerExists(long_name, short_name, this)) {
if (server.server_manager->ServerExists(GetServerLongName(), GetServerShortName(), this)) {
LogError("World tried to login but there already exists a server that has that name");
return;
}
}
else {
if (server.server_manager->ServerExists(long_name, short_name, this)) {
LogError("World tried to login but there already exists a server that has that name");
if (server.server_manager->ServerExists(GetServerLongName(), GetServerShortName(), this)) {
LogInfo("World tried to login but there already exists a server that has that name");
server.server_manager->DestroyServerByName(long_name, short_name, this);
}
}
Database::DbWorldRegistration
world_registration = server.db->GetWorldRegistration(short_name, remote_ip_address, local_ip);
world_registration = server.db->GetWorldRegistration(
GetServerShortName(),
GetRemoteIp(),
GetLocalIp()
);
if (!server.options.IsUnregisteredAllowed()) {
if (!this->HandleNewLoginserverRegisteredOnly(world_registration)) {
LogError("WorldServer::HandleNewLoginserverRegisteredOnly checks failed");
LogError(
"WorldServer::HandleNewLoginserverRegisteredOnly checks failed with server [{0}]",
this->GetServerLongName()
);
return;
}
}
else {
if (!this->HandleNewLoginserverInfoUnregisteredAllowed(world_registration)) {
LogError("WorldServer::HandleNewLoginserverInfoUnregisteredAllowed checks failed");
LogError(
"WorldServer::HandleNewLoginserverInfoUnregisteredAllowed checks failed with server [{0}]",
this->GetServerLongName()
);
return;
}
}
@ -526,9 +543,9 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct *new_world_server_info
*/
void WorldServer::Handle_LSStatus(ServerLSStatus_Struct *server_login_status)
{
players_online = server_login_status->num_players;
zones_booted = server_login_status->num_zones;
server_status = server_login_status->status;
SetPlayersOnline(server_login_status->num_players);
SetZonesBooted(server_login_status->num_zones);
SetServerStatus(server_login_status->status);
}
/**
@ -663,7 +680,7 @@ bool WorldServer::HandleNewLoginserverInfoValidation(
if (strlen(new_world_server_info_packet->remote_ip_address) == 0) {
this->SetRemoteIp(GetConnection()->Handle()->RemoteIP());
LogError(
LogWarning(
"Remote address was null, defaulting to stream address {0}",
remote_ip_address
);
@ -675,8 +692,8 @@ bool WorldServer::HandleNewLoginserverInfoValidation(
else {
this->SetRemoteIp(GetConnection()->Handle()->RemoteIP());
LogError(
"Handle_NewLSInfo error, remote address was too long, defaulting to stream address [{0}]",
LogWarning(
"Handle_NewLSInfo remote address was too long, defaulting to stream address [{0}]",
remote_ip_address
);
}
@ -690,7 +707,8 @@ bool WorldServer::HandleNewLoginserverInfoValidation(
*/
bool WorldServer::HandleNewLoginserverRegisteredOnly(
Database::DbWorldRegistration &world_registration
) {
)
{
if (!this->GetAccountName().empty() && !this->GetAccountPassword().empty()) {
if (world_registration.loaded) {
bool does_world_server_not_require_authentication = (
@ -775,7 +793,8 @@ bool WorldServer::HandleNewLoginserverRegisteredOnly(
*/
bool WorldServer::HandleNewLoginserverInfoUnregisteredAllowed(
Database::DbWorldRegistration &world_registration
) {
)
{
if (world_registration.loaded) {
this

View File

@ -36,6 +36,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "clientlist.h"
#include "world_config.h"
extern ZSList zoneserver_list;
extern ClientList client_list;
extern uint32 numzones;
@ -544,24 +545,27 @@ void LoginServer::SendStatus()
pack->size = sizeof(ServerLSStatus_Struct);
pack->pBuffer = new uchar[pack->size];
memset(pack->pBuffer, 0, pack->size);
ServerLSStatus_Struct *lss = (ServerLSStatus_Struct *) pack->pBuffer;
auto loginserver_status = (ServerLSStatus_Struct *) pack->pBuffer;
if (WorldConfig::get()->Locked) {
lss->status = -2;
loginserver_status->status = -2;
}
else if (numzones <= 0) {
lss->status = -2;
loginserver_status->status = -2;
}
else {
lss->status = numplayers;
loginserver_status->status = numplayers;
}
lss->num_zones = numzones;
lss->num_players = numplayers;
loginserver_status->num_zones = numzones;
loginserver_status->num_players = numplayers;
SendPacket(pack);
delete pack;
}
/**
* @param pack
*/
void LoginServer::SendPacket(ServerPacket *pack)
{
if (IsLegacy) {
@ -578,15 +582,15 @@ void LoginServer::SendPacket(ServerPacket *pack)
void LoginServer::SendAccountUpdate(ServerPacket *pack)
{
ServerLSAccountUpdate_Struct *s = (ServerLSAccountUpdate_Struct *) pack->pBuffer;
auto *ls_account_update = (ServerLSAccountUpdate_Struct *) pack->pBuffer;
if (CanUpdate()) {
Log(Logs::Detail,
Logs::World_Server,
"Sending ServerOP_LSAccountUpdate packet to loginserver: %s:%d",
LogInfo(
"Sending ServerOP_LSAccountUpdate packet to loginserver: [{0}]:[{1}]",
LoginServerAddress,
LoginServerPort);
strn0cpy(s->worldaccount, LoginAccount.c_str(), 30);
strn0cpy(s->worldpassword, LoginPassword.c_str(), 30);
LoginServerPort
);
strn0cpy(ls_account_update->worldaccount, LoginAccount.c_str(), 30);
strn0cpy(ls_account_update->worldpassword, LoginPassword.c_str(), 30);
SendPacket(pack);
}
}

View File

@ -2361,7 +2361,7 @@ void command_setlsinfo(Client *c, const Seperator *sep)
ServerLSAccountUpdate_Struct* s = (ServerLSAccountUpdate_Struct *) pack->pBuffer;
s->useraccountid = c->LSAccountID();
strn0cpy(s->useraccount, c->AccountName(), 30);
strn0cpy(s->useremail, sep->arg[1], 100);
strn0cpy(s->user_email, sep->arg[1], 100);
strn0cpy(s->userpassword, sep->arg[2], 50);
worldserver.SendPacket(pack);
c->Message(0, "Login Server update packet sent.");