Some loginserver refactoring

This commit is contained in:
Akkadius
2015-12-02 13:14:26 -06:00
parent a483d37c26
commit af18377505
8 changed files with 169 additions and 211 deletions
+80 -84
View File
@@ -28,19 +28,18 @@ WorldServer::WorldServer(EmuTCPConnection *c)
connection = c;
zones_booted = 0;
players_online = 0;
status = 0;
server_status = 0;
runtime_id = 0;
server_list_id = 0;
server_type = 0;
authorized = false;
trusted = false;
logged_in = false;
is_server_authorized = false;
is_server_trusted = false;
is_server_logged_in = false;
}
WorldServer::~WorldServer()
{
if(connection)
{
if(connection) {
connection->Free();
}
}
@@ -49,12 +48,12 @@ void WorldServer::Reset()
{
zones_booted = 0;
players_online = 0;
status = 0;
server_status = 0;
runtime_id;
server_list_id = 0;
server_type = 0;
authorized = false;
logged_in = false;
is_server_authorized = false;
is_server_logged_in = false;
}
bool WorldServer::Process()
@@ -142,7 +141,7 @@ bool WorldServer::Process()
UsertoWorldResponse_Struct *utwr = (UsertoWorldResponse_Struct*)app->pBuffer;
server_log->Log(log_client, "Trying to find client with user id of %u.", utwr->lsaccountid);
Client *c = server.CM->GetClient(utwr->lsaccountid);
Client *c = server.client_manager->GetClient(utwr->lsaccountid);
if(c)
{
server_log->Log(log_client, "Found client with user id of %u and account name of %s.", utwr->lsaccountid, c->GetAccountName().c_str());
@@ -210,7 +209,7 @@ bool WorldServer::Process()
server_log->Log(log_network_trace, "ServerOP_LSAccountUpdate packet received from: %s", short_name.c_str());
ServerLSAccountUpdate_Struct *lsau = (ServerLSAccountUpdate_Struct*)app->pBuffer;
if(trusted)
if(is_server_trusted)
{
server_log->Log(log_network_trace, "ServerOP_LSAccountUpdate update processed for: %s", lsau->useraccount);
string name;
@@ -237,7 +236,7 @@ bool WorldServer::Process()
void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
{
if(logged_in)
if(is_server_logged_in)
{
server_log->Log(log_network_error, "WorldServer::Handle_NewLSInfo called but the login server was already marked as logged in, aborting.");
return;
@@ -344,11 +343,11 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
}
server_type = i->servertype;
logged_in = true;
is_server_logged_in = true;
if(server.options.IsRejectingDuplicateServers())
{
if(server.SM->ServerExists(long_name, short_name, this))
if(server.server_manager->ServerExists(long_name, short_name, this))
{
server_log->Log(log_world_error, "World tried to login but there already exists a server that has that name.");
return;
@@ -356,10 +355,10 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
}
else
{
if(server.SM->ServerExists(long_name, short_name, this))
if(server.server_manager->ServerExists(long_name, short_name, this))
{
server_log->Log(log_world_error, "World tried to login but there already exists a server that has that name.");
server.SM->DestroyServerByName(long_name, short_name, this);
server.server_manager->DestroyServerByName(long_name, short_name, this);
}
}
@@ -380,7 +379,7 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
{
server_log->Log(log_world, "Server %s(%s) successfully logged into account that had no user/password requirement.",
long_name.c_str(), short_name.c_str());
authorized = true;
is_server_authorized = true;
SetRuntimeID(s_id);
server_list_id = s_list_type;
desc = s_desc;
@@ -389,89 +388,90 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
{
server_log->Log(log_world, "Server %s(%s) successfully logged in.",
long_name.c_str(), short_name.c_str());
authorized = true;
is_server_authorized = true;
SetRuntimeID(s_id);
server_list_id = s_list_type;
desc = s_desc;
if(s_trusted)
{
if(s_trusted) {
server_log->Log(log_network_trace, "ServerOP_LSAccountUpdate sent to world");
trusted = true;
is_server_trusted = true;
ServerPacket *outapp = new ServerPacket(ServerOP_LSAccountUpdate, 0);
connection->SendPacket(outapp);
}
}
else
{
else {
server_log->Log(log_world, "Server %s(%s) attempted to log in but account and password did not match the entry in the database, and only"
" registered servers are allowed.", long_name.c_str(), short_name.c_str());
return;
}
}
else
{
else {
server_log->Log(log_world, "Server %s(%s) attempted to log in but database couldn't find an entry and only registered servers are allowed.",
long_name.c_str(), short_name.c_str());
return;
}
}
else
{
else {
server_log->Log(log_world, "Server %s(%s) did not attempt to log in but only registered servers are allowed.",
long_name.c_str(), short_name.c_str());
return;
}
}
else
{
unsigned int s_id = 0;
unsigned int s_list_type = 0;
unsigned int s_trusted = 0;
string s_desc;
string s_list_desc;
string s_acct_name;
string s_acct_pass;
if(server.db->GetWorldRegistration(long_name, short_name, s_id, s_desc, s_list_type, s_trusted, s_list_desc, s_acct_name, s_acct_pass))
else {
unsigned int server_id = 0;
unsigned int server_list_type = 0;
unsigned int is_server_trusted = 0;
string server_description;
string server_list_description;
string server_account_name;
string server_account_password;
if(server.db->GetWorldRegistration(
long_name,
short_name,
server_id,
server_description,
server_list_type,
is_server_trusted,
server_list_description,
server_account_name,
server_account_password))
{
if(account_name.size() > 0 && account_password.size() > 0)
{
if(s_acct_name.compare(account_name) == 0 && s_acct_pass.compare(account_password) == 0)
{
if(account_name.size() > 0 && account_password.size() > 0) {
if(server_account_name.compare(account_name) == 0 && server_account_password.compare(account_password) == 0) {
server_log->Log(log_world, "Server %s(%s) successfully logged in.",
long_name.c_str(), short_name.c_str());
authorized = true;
SetRuntimeID(s_id);
server_list_id = s_list_type;
desc = s_desc;
if(s_trusted)
{
is_server_authorized = true;
SetRuntimeID(server_id);
server_list_id = server_list_type;
desc = server_description;
if(is_server_trusted) {
server_log->Log(log_network_trace, "ServerOP_LSAccountUpdate sent to world");
trusted = true;
is_server_trusted = true;
ServerPacket *outapp = new ServerPacket(ServerOP_LSAccountUpdate, 0);
connection->SendPacket(outapp);
}
}
else
{
else {
// this is the first of two cases where we should deny access even if unregistered is allowed
server_log->Log(log_world, "Server %s(%s) attempted to log in but account and password did not match the entry in the database.",
long_name.c_str(), short_name.c_str());
}
}
else
{
if(s_acct_name.size() > 0 || s_acct_pass.size() > 0)
{
else {
if(server_account_name.size() > 0 || server_account_password.size() > 0) {
// this is the second of two cases where we should deny access even if unregistered is allowed
server_log->Log(log_world, "Server %s(%s) did not attempt to log in but this server requires a password.",
long_name.c_str(), short_name.c_str());
}
else
{
else {
server_log->Log(log_world, "Server %s(%s) did not attempt to log in but unregistered servers are allowed.",
long_name.c_str(), short_name.c_str());
authorized = true;
SetRuntimeID(s_id);
is_server_authorized = true;
SetRuntimeID(server_id);
server_list_id = 3;
}
}
@@ -480,10 +480,9 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
{
server_log->Log(log_world, "Server %s(%s) attempted to log in but database couldn't find an entry but unregistered servers are allowed.",
long_name.c_str(), short_name.c_str());
if(server.db->CreateWorldRegistration(long_name, short_name, s_id))
{
authorized = true;
SetRuntimeID(s_id);
if(server.db->CreateWorldRegistration(long_name, short_name, server_id)) {
is_server_authorized = true;
SetRuntimeID(server_id);
server_list_id = 3;
}
}
@@ -493,9 +492,9 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
in.s_addr = connection->GetrIP();
server.db->UpdateWorldRegistration(GetRuntimeID(), long_name, string(inet_ntoa(in)));
if(authorized)
if(is_server_authorized)
{
server.CM->UpdateServerList();
server.client_manager->UpdateServerList();
}
}
@@ -503,43 +502,40 @@ void WorldServer::Handle_LSStatus(ServerLSStatus_Struct *s)
{
players_online = s->num_players;
zones_booted = s->num_zones;
status = s->status;
server_status = s->status;
}
void WorldServer::SendClientAuth(unsigned int ip, string account, string key, unsigned int account_id)
{
ServerPacket *outapp = new ServerPacket(ServerOP_LSClientAuth, sizeof(ServerLSClientAuth));
ServerLSClientAuth* slsca = (ServerLSClientAuth*)outapp->pBuffer;
ServerPacket *outapp = new ServerPacket(ServerOP_LSClientAuth, sizeof(ClientAuth_Struct));
ClientAuth_Struct* client_auth = (ClientAuth_Struct*)outapp->pBuffer;
slsca->lsaccount_id = account_id;
strncpy(slsca->name, account.c_str(), account.size() > 30 ? 30 : account.size());
strncpy(slsca->key, key.c_str(), 10);
slsca->lsadmin = 0;
slsca->worldadmin = 0;
slsca->ip = ip;
client_auth->lsaccount_id = account_id;
strncpy(client_auth->name, account.c_str(), account.size() > 30 ? 30 : account.size());
strncpy(client_auth->key, key.c_str(), 10);
client_auth->lsadmin = 0;
client_auth->worldadmin = 0;
client_auth->ip = ip;
in_addr in;
in.s_addr = ip;connection->GetrIP();
in.s_addr = ip; connection->GetrIP();
string client_address(inet_ntoa(in));
in.s_addr = connection->GetrIP();
string world_address(inet_ntoa(in));
if(client_address.compare(world_address) == 0)
{
slsca->local = 1;
if (client_address.compare(world_address) == 0) {
client_auth->local = 1;
}
else if(client_address.find(server.options.GetLocalNetwork()) != string::npos)
{
slsca->local = 1;
else if (client_address.find(server.options.GetLocalNetwork()) != string::npos) {
client_auth->local = 1;
}
else
{
slsca->local = 0;
else {
client_auth->local = 0;
}
connection->SendPacket(outapp);
if(server.options.IsDumpInPacketsOn())
if (server.options.IsDumpInPacketsOn())
{
DumpPacket(outapp);
}