diff --git a/common/servertalk.h b/common/servertalk.h index e7ce947c5..e476d023d 100644 --- a/common/servertalk.h +++ b/common/servertalk.h @@ -523,7 +523,7 @@ struct ServerLSPlayerZoneChange_Struct { uint32 from; // 0 = world uint32 to; // 0 = world }; -struct ServerLSClientAuth { +struct ClientAuth_Struct { uint32 lsaccount_id; // ID# in login server's db char name[30]; // username in login server's db char key[30]; // the Key the client will present diff --git a/loginserver/client.cpp b/loginserver/client.cpp index fe43e6675..28836f915 100644 --- a/loginserver/client.cpp +++ b/loginserver/client.cpp @@ -245,7 +245,7 @@ void Client::Handle_Login(const char* data, unsigned int size) if(result) { - server.CM->RemoveExistingClient(d_account_id); + server.client_manager->RemoveExistingClient(d_account_id); in_addr in; in.s_addr = connection->GetRemoteIP(); server.db->UpdateLSAccountData(d_account_id, string(inet_ntoa(in))); @@ -347,12 +347,12 @@ void Client::Handle_Play(const char* data) this->play_server_id = (unsigned int)play->ServerNumber; play_sequence_id = sequence_in; play_server_id = server_id_in; - server.SM->SendUserToWorldRequest(server_id_in, account_id); + server.server_manager->SendUserToWorldRequest(server_id_in, account_id); } void Client::SendServerListPacket() { - EQApplicationPacket *outapp = server.SM->CreateServerListPacket(this); + EQApplicationPacket *outapp = server.server_manager->CreateServerListPacket(this); if(server.options.IsDumpOutPacketsOn()) { @@ -378,7 +378,7 @@ void Client::GenerateKey() { key.clear(); int count = 0; - while(count < 10) + while (count < 10) { static const char key_selection[] = { diff --git a/loginserver/database_mysql.cpp b/loginserver/database_mysql.cpp index 2e69dfca3..0f309d7b4 100644 --- a/loginserver/database_mysql.cpp +++ b/loginserver/database_mysql.cpp @@ -61,7 +61,7 @@ DatabaseMySQL::~DatabaseMySQL() bool DatabaseMySQL::GetLoginDataFromAccountName(string name, string &password, unsigned int &id) { - if(!db) + if (!db) { return false; } @@ -73,7 +73,7 @@ bool DatabaseMySQL::GetLoginDataFromAccountName(string name, string &password, u query << name; query << "'"; - if(mysql_query(db, query.str().c_str()) != 0) + if (mysql_query(db, query.str().c_str()) != 0) { server_log->Log(log_database, "Mysql query failed: %s", query.str().c_str()); return false; @@ -81,9 +81,9 @@ bool DatabaseMySQL::GetLoginDataFromAccountName(string name, string &password, u res = mysql_use_result(db); - if(res) + if (res) { - while((row = mysql_fetch_row(res)) != nullptr) + while ((row = mysql_fetch_row(res)) != nullptr) { id = atoi(row[0]); password = row[1]; @@ -97,9 +97,9 @@ bool DatabaseMySQL::GetLoginDataFromAccountName(string name, string &password, u } bool DatabaseMySQL::GetWorldRegistration(string long_name, string short_name, unsigned int &id, string &desc, unsigned int &list_id, - unsigned int &trusted, string &list_desc, string &account, string &password) + unsigned int &trusted, string &list_desc, string &account, string &password) { - if(!db) + if (!db) { return false; } @@ -109,7 +109,7 @@ bool DatabaseMySQL::GetWorldRegistration(string long_name, string short_name, un char escaped_short_name[101]; unsigned long length; length = mysql_real_escape_string(db, escaped_short_name, short_name.substr(0, 100).c_str(), short_name.substr(0, 100).length()); - escaped_short_name[length+1] = 0; + escaped_short_name[length + 1] = 0; stringstream query(stringstream::in | stringstream::out); query << "SELECT ifnull(WSR.ServerID,999999) AS ServerID, WSR.ServerTagDescription, ifnull(WSR.ServerTrusted,0) AS ServerTrusted, ifnull(SLT.ServerListTypeID,3) AS ServerListTypeID, "; query << "SLT.ServerListTypeDescription, ifnull(WSR.ServerAdminID,0) AS ServerAdminID FROM " << server.options.GetWorldRegistrationTable(); @@ -118,16 +118,16 @@ bool DatabaseMySQL::GetWorldRegistration(string long_name, string short_name, un query << escaped_short_name; query << "'"; - if(mysql_query(db, query.str().c_str()) != 0) + if (mysql_query(db, query.str().c_str()) != 0) { server_log->Log(log_database, "Mysql query failed: %s", query.str().c_str()); return false; } res = mysql_use_result(db); - if(res) + if (res) { - if((row = mysql_fetch_row(res)) != nullptr) + if ((row = mysql_fetch_row(res)) != nullptr) { id = atoi(row[0]); desc = row[1]; @@ -137,22 +137,22 @@ bool DatabaseMySQL::GetWorldRegistration(string long_name, string short_name, un int db_account_id = atoi(row[5]); mysql_free_result(res); - if(db_account_id > 0) + if (db_account_id > 0) { stringstream query(stringstream::in | stringstream::out); query << "SELECT AccountName, AccountPassword FROM " << server.options.GetWorldAdminRegistrationTable(); query << " WHERE ServerAdminID = " << db_account_id; - if(mysql_query(db, query.str().c_str()) != 0) + if (mysql_query(db, query.str().c_str()) != 0) { server_log->Log(log_database, "Mysql query failed: %s", query.str().c_str()); return false; } res = mysql_use_result(db); - if(res) + if (res) { - if((row = mysql_fetch_row(res)) != nullptr) + if ((row = mysql_fetch_row(res)) != nullptr) { account = row[0]; password = row[1]; @@ -174,7 +174,7 @@ bool DatabaseMySQL::GetWorldRegistration(string long_name, string short_name, un void DatabaseMySQL::UpdateLSAccountData(unsigned int id, string ip_address) { - if(!db) + if (!db) { return; } @@ -185,7 +185,7 @@ void DatabaseMySQL::UpdateLSAccountData(unsigned int id, string ip_address) query << "', LastLoginDate = now() where LoginServerID = "; query << id; - if(mysql_query(db, query.str().c_str()) != 0) + if (mysql_query(db, query.str().c_str()) != 0) { server_log->Log(log_database, "Mysql query failed: %s", query.str().c_str()); } @@ -193,7 +193,7 @@ void DatabaseMySQL::UpdateLSAccountData(unsigned int id, string ip_address) void DatabaseMySQL::UpdateLSAccountInfo(unsigned int id, string name, string password, string email) { - if(!db) + if (!db) { return; } @@ -204,7 +204,7 @@ void DatabaseMySQL::UpdateLSAccountInfo(unsigned int id, string name, string pas query << password << "'), AccountCreateDate = now(), AccountEmail = '" << email; query << "', LastIPAddress = '0.0.0.0', LastLoginDate = now()"; - if(mysql_query(db, query.str().c_str()) != 0) + if (mysql_query(db, query.str().c_str()) != 0) { server_log->Log(log_database, "Mysql query failed: %s", query.str().c_str()); } @@ -212,7 +212,7 @@ void DatabaseMySQL::UpdateLSAccountInfo(unsigned int id, string name, string pas void DatabaseMySQL::UpdateWorldRegistration(unsigned int id, string long_name, string ip_address) { - if(!db) + if (!db) { return; } @@ -220,7 +220,7 @@ void DatabaseMySQL::UpdateWorldRegistration(unsigned int id, string long_name, s char escaped_long_name[101]; unsigned long length; length = mysql_real_escape_string(db, escaped_long_name, long_name.substr(0, 100).c_str(), long_name.substr(0, 100).length()); - escaped_long_name[length+1] = 0; + escaped_long_name[length + 1] = 0; stringstream query(stringstream::in | stringstream::out); query << "UPDATE " << server.options.GetWorldRegistrationTable() << " SET ServerLastLoginDate = now(), ServerLastIPAddr = '"; query << ip_address; @@ -229,7 +229,7 @@ void DatabaseMySQL::UpdateWorldRegistration(unsigned int id, string long_name, s query << "' WHERE ServerID = "; query << id; - if(mysql_query(db, query.str().c_str()) != 0) + if (mysql_query(db, query.str().c_str()) != 0) { server_log->Log(log_database, "Mysql query failed: %s", query.str().c_str()); } @@ -237,7 +237,7 @@ void DatabaseMySQL::UpdateWorldRegistration(unsigned int id, string long_name, s bool DatabaseMySQL::CreateWorldRegistration(string long_name, string short_name, unsigned int &id) { - if(!db) + if (!db) { return false; } @@ -248,22 +248,22 @@ bool DatabaseMySQL::CreateWorldRegistration(string long_name, string short_name, char escaped_short_name[101]; unsigned long length; length = mysql_real_escape_string(db, escaped_long_name, long_name.substr(0, 100).c_str(), long_name.substr(0, 100).length()); - escaped_long_name[length+1] = 0; + escaped_long_name[length + 1] = 0; length = mysql_real_escape_string(db, escaped_short_name, short_name.substr(0, 100).c_str(), short_name.substr(0, 100).length()); - escaped_short_name[length+1] = 0; + escaped_short_name[length + 1] = 0; stringstream query(stringstream::in | stringstream::out); query << "SELECT ifnull(max(ServerID),0) FROM " << server.options.GetWorldRegistrationTable(); - if(mysql_query(db, query.str().c_str()) != 0) + if (mysql_query(db, query.str().c_str()) != 0) { server_log->Log(log_database, "Mysql query failed: %s", query.str().c_str()); return false; } res = mysql_use_result(db); - if(res) + if (res) { - if((row = mysql_fetch_row(res)) != nullptr) + if ((row = mysql_fetch_row(res)) != nullptr) { id = atoi(row[0]) + 1; mysql_free_result(res); @@ -273,7 +273,7 @@ bool DatabaseMySQL::CreateWorldRegistration(string long_name, string short_name, query << ", ServerLongName = '" << escaped_long_name << "', ServerShortName = '" << escaped_short_name; query << "', ServerListTypeID = 3, ServerAdminID = 0, ServerTrusted = 0, ServerTagDescription = ''"; - if(mysql_query(db, query.str().c_str()) != 0) + if (mysql_query(db, query.str().c_str()) != 0) { server_log->Log(log_database, "Mysql query failed: %s", query.str().c_str()); return false; diff --git a/loginserver/login_server.h b/loginserver/login_server.h index f83154b8f..bae3079b7 100644 --- a/loginserver/login_server.h +++ b/loginserver/login_server.h @@ -40,7 +40,7 @@ public: * but it's the most trivial way to do this. */ #ifdef WIN32 - LoginServer() : config(nullptr), db(nullptr), eq_crypto(nullptr), SM(nullptr) { } + LoginServer() : config(nullptr), db(nullptr), eq_crypto(nullptr), server_manager(nullptr) { } #else LoginServer() : config(nullptr), db(nullptr) { } #endif @@ -48,8 +48,8 @@ public: Config *config; Database *db; Options options; - ServerManager *SM; - ClientManager *CM; + ServerManager *server_manager; + ClientManager *client_manager; #ifdef WIN32 Encryption *eq_crypto; diff --git a/loginserver/main.cpp b/loginserver/main.cpp index 0d51a69ff..a6e4cdf82 100644 --- a/loginserver/main.cpp +++ b/loginserver/main.cpp @@ -44,7 +44,7 @@ int main() RegisterExecutablePlatform(ExePlatformLogin); set_exception_handler(); - //Create our error log, is of format login_.log + /* Start Loginserver log */ time_t current_time = time(nullptr); std::stringstream log_name(std::stringstream::in | std::stringstream::out); #ifdef WIN32 @@ -55,92 +55,55 @@ int main() server_log = new ErrorLog(log_name.str().c_str()); server_log->Log(log_debug, "Logging System Init."); - //Create our subsystem and parse the ini file. + /* Parse out login.ini */ server.config = new Config(); server_log->Log(log_debug, "Config System Init."); server.config->Parse("login.ini"); - //Parse unregistered allowed option. - if(server.config->GetVariable("options", "unregistered_allowed").compare("FALSE") == 0) - { + if (server.config->GetVariable("options", "unregistered_allowed").compare("FALSE") == 0) server.options.AllowUnregistered(false); - } - //Parse trace option. - if(server.config->GetVariable("options", "trace").compare("TRUE") == 0) - { + if (server.config->GetVariable("options", "trace").compare("TRUE") == 0) server.options.Trace(true); - } - //Parse trace option. - if(server.config->GetVariable("options", "world_trace").compare("TRUE") == 0) - { + if (server.config->GetVariable("options", "world_trace").compare("TRUE") == 0) server.options.WorldTrace(true); - } - //Parse packet inc dump option. - if(server.config->GetVariable("options", "dump_packets_in").compare("TRUE") == 0) - { + if (server.config->GetVariable("options", "dump_packets_in").compare("TRUE") == 0) server.options.DumpInPackets(true); - } - //Parse packet out dump option. - if(server.config->GetVariable("options", "dump_packets_out").compare("TRUE") == 0) - { + if (server.config->GetVariable("options", "dump_packets_out").compare("TRUE") == 0) server.options.DumpOutPackets(true); - } - //Parse encryption mode option. std::string mode = server.config->GetVariable("security", "mode"); - if(mode.size() > 0) - { + if (mode.size() > 0) server.options.EncryptionMode(atoi(mode.c_str())); - } - //Parse local network option. - std::string ln = server.config->GetVariable("options", "local_network"); - if(ln.size() > 0) - { - server.options.LocalNetwork(ln); - } + std::string local_network = server.config->GetVariable("options", "local_network"); + if (local_network.size() > 0) + server.options.LocalNetwork(local_network); - //Parse reject duplicate servers option. - if(server.config->GetVariable("options", "reject_duplicate_servers").compare("TRUE") == 0) - { + if (server.config->GetVariable("options", "reject_duplicate_servers").compare("TRUE") == 0) server.options.RejectDuplicateServers(true); - } - //Parse account table option. - ln = server.config->GetVariable("schema", "account_table"); - if(ln.size() > 0) - { - server.options.AccountTable(ln); - } + local_network = server.config->GetVariable("schema", "account_table"); + if (local_network.size() > 0) + server.options.AccountTable(local_network); - //Parse world account table option. - ln = server.config->GetVariable("schema", "world_registration_table"); - if(ln.size() > 0) - { - server.options.WorldRegistrationTable(ln); - } + local_network = server.config->GetVariable("schema", "world_registration_table"); + if (local_network.size() > 0) + server.options.WorldRegistrationTable(local_network); - //Parse admin world account table option. - ln = server.config->GetVariable("schema", "world_admin_registration_table"); - if(ln.size() > 0) - { - server.options.WorldAdminRegistrationTable(ln); - } + local_network = server.config->GetVariable("schema", "world_admin_registration_table"); + if (local_network.size() > 0) + server.options.WorldAdminRegistrationTable(local_network); - //Parse world type table option. - ln = server.config->GetVariable("schema", "world_server_type_table"); - if(ln.size() > 0) - { - server.options.WorldServerTypeTable(ln); - } + local_network = server.config->GetVariable("schema", "world_server_type_table"); + if (local_network.size() > 0) + server.options.WorldServerTypeTable(local_network); //Create our DB from options. - if(server.config->GetVariable("database", "subsystem").compare("MySQL") == 0) - { + if (server.config->GetVariable("database", "subsystem").compare("MySQL") == 0) { #ifdef EQEMU_MYSQL_ENABLED server_log->Log(log_debug, "MySQL Database Init."); server.db = (Database*)new DatabaseMySQL( @@ -151,8 +114,7 @@ int main() server.config->GetVariable("database", "db")); #endif } - else if(server.config->GetVariable("database", "subsystem").compare("PostgreSQL") == 0) - { + else if (server.config->GetVariable("database", "subsystem").compare("PostgreSQL") == 0) { #ifdef EQEMU_POSTGRESQL_ENABLED server_log->Log(log_debug, "PostgreSQL Database Init."); server.db = (Database*)new DatabasePostgreSQL( @@ -164,9 +126,8 @@ int main() #endif } - //Make sure our database got created okay, otherwise cleanup and exit. - if(!server.db) - { + /* Make sure our database got created okay, otherwise cleanup and exit. */ + if (!server.db) { server_log->Log(log_error, "Database Initialization Failure."); server_log->Log(log_debug, "Config System Shutdown."); delete server.config; @@ -179,12 +140,10 @@ int main() //initialize our encryption. server_log->Log(log_debug, "Encryption Initialize."); server.eq_crypto = new Encryption(); - if(server.eq_crypto->LoadCrypto(server.config->GetVariable("security", "plugin"))) - { + if (server.eq_crypto->LoadCrypto(server.config->GetVariable("security", "plugin"))) { server_log->Log(log_debug, "Encryption Loaded Successfully."); } - else - { + else { //We can't run without encryption, cleanup and exit. server_log->Log(log_error, "Encryption Failed to Load."); server_log->Log(log_debug, "Database System Shutdown."); @@ -199,15 +158,16 @@ int main() //create our server manager. server_log->Log(log_debug, "Server Manager Initialize."); - server.SM = new ServerManager(); - if(!server.SM) - { + server.server_manager = new ServerManager(); + if (!server.server_manager) { //We can't run without a server manager, cleanup and exit. server_log->Log(log_error, "Server Manager Failed to Start."); + #ifdef WIN32 server_log->Log(log_debug, "Encryption System Shutdown."); delete server.eq_crypto; #endif + server_log->Log(log_debug, "Database System Shutdown."); delete server.db; server_log->Log(log_debug, "Config System Shutdown."); @@ -219,17 +179,18 @@ int main() //create our client manager. server_log->Log(log_debug, "Client Manager Initialize."); - server.CM = new ClientManager(); - if(!server.CM) - { + server.client_manager = new ClientManager(); + if (!server.client_manager) { //We can't run without a client manager, cleanup and exit. server_log->Log(log_error, "Client Manager Failed to Start."); server_log->Log(log_debug, "Server Manager Shutdown."); - delete server.SM; + delete server.server_manager; + #ifdef WIN32 server_log->Log(log_debug, "Encryption System Shutdown."); delete server.eq_crypto; #endif + server_log->Log(log_debug, "Database System Shutdown."); delete server.db; server_log->Log(log_debug, "Config System Shutdown."); @@ -248,23 +209,24 @@ int main() #endif server_log->Log(log_debug, "Server Started."); - while(run_server) - { + while (run_server) { Timer::SetCurrentTime(); - server.CM->Process(); - server.SM->Process(); + server.client_manager->Process(); + server.server_manager->Process(); Sleep(100); } server_log->Log(log_debug, "Server Shutdown."); server_log->Log(log_debug, "Client Manager Shutdown."); - delete server.CM; + delete server.client_manager; server_log->Log(log_debug, "Server Manager Shutdown."); - delete server.SM; + delete server.server_manager; + #ifdef WIN32 server_log->Log(log_debug, "Encryption System Shutdown."); delete server.eq_crypto; #endif + server_log->Log(log_debug, "Database System Shutdown."); delete server.db; server_log->Log(log_debug, "Config System Shutdown."); diff --git a/loginserver/world_server.cpp b/loginserver/world_server.cpp index c91f1b702..64f7de02c 100644 --- a/loginserver/world_server.cpp +++ b/loginserver/world_server.cpp @@ -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); } diff --git a/loginserver/world_server.h b/loginserver/world_server.h index 0d8ed4251..b9a64ffe5 100644 --- a/loginserver/world_server.h +++ b/loginserver/world_server.h @@ -86,7 +86,7 @@ public: /** * Gets whether the server is authorized to show up on the server list or not. */ - bool IsAuthorized() const { return authorized; } + bool IsAuthorized() const { return is_server_authorized; } /** * Gets the local ip of the server. @@ -106,7 +106,7 @@ public: /** * Gets the status of the server. */ - int GetStatus() const { return status; } + int GetStatus() const { return server_status; } /** * Gets the number of zones online on the server. @@ -138,7 +138,7 @@ private: EmuTCPConnection *connection; unsigned int zones_booted; unsigned int players_online; - int status; + int server_status; unsigned int runtime_id; unsigned int server_list_id; unsigned int server_type; @@ -151,9 +151,9 @@ private: std::string local_ip; std::string protocol; std::string version; - bool authorized; - bool logged_in; - bool trusted; + bool is_server_authorized; + bool is_server_logged_in; + bool is_server_trusted; }; #endif diff --git a/world/login_server.cpp b/world/login_server.cpp index 450ecb0a3..a6b46a6ea 100644 --- a/world/login_server.cpp +++ b/world/login_server.cpp @@ -145,7 +145,7 @@ bool LoginServer::Process() { break; } case ServerOP_LSClientAuth: { - ServerLSClientAuth* slsca = (ServerLSClientAuth*) pack->pBuffer; + ClientAuth_Struct* slsca = (ClientAuth_Struct*) pack->pBuffer; if (RuleI(World, AccountSessionLimit) >= 0) { // Enforce the limit on the number of characters on the same account that can be