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

View File

@ -523,7 +523,7 @@ struct ServerLSPlayerZoneChange_Struct {
uint32 from; // 0 = world uint32 from; // 0 = world
uint32 to; // 0 = world uint32 to; // 0 = world
}; };
struct ServerLSClientAuth { struct ClientAuth_Struct {
uint32 lsaccount_id; // ID# in login server's db uint32 lsaccount_id; // ID# in login server's db
char name[30]; // username in login server's db char name[30]; // username in login server's db
char key[30]; // the Key the client will present char key[30]; // the Key the client will present

View File

@ -245,7 +245,7 @@ void Client::Handle_Login(const char* data, unsigned int size)
if(result) if(result)
{ {
server.CM->RemoveExistingClient(d_account_id); server.client_manager->RemoveExistingClient(d_account_id);
in_addr in; in_addr in;
in.s_addr = connection->GetRemoteIP(); in.s_addr = connection->GetRemoteIP();
server.db->UpdateLSAccountData(d_account_id, string(inet_ntoa(in))); 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; this->play_server_id = (unsigned int)play->ServerNumber;
play_sequence_id = sequence_in; play_sequence_id = sequence_in;
play_server_id = server_id_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() void Client::SendServerListPacket()
{ {
EQApplicationPacket *outapp = server.SM->CreateServerListPacket(this); EQApplicationPacket *outapp = server.server_manager->CreateServerListPacket(this);
if(server.options.IsDumpOutPacketsOn()) if(server.options.IsDumpOutPacketsOn())
{ {
@ -378,7 +378,7 @@ void Client::GenerateKey()
{ {
key.clear(); key.clear();
int count = 0; int count = 0;
while(count < 10) while (count < 10)
{ {
static const char key_selection[] = static const char key_selection[] =
{ {

View File

@ -61,7 +61,7 @@ DatabaseMySQL::~DatabaseMySQL()
bool DatabaseMySQL::GetLoginDataFromAccountName(string name, string &password, unsigned int &id) bool DatabaseMySQL::GetLoginDataFromAccountName(string name, string &password, unsigned int &id)
{ {
if(!db) if (!db)
{ {
return false; return false;
} }
@ -73,7 +73,7 @@ bool DatabaseMySQL::GetLoginDataFromAccountName(string name, string &password, u
query << name; query << name;
query << "'"; 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()); server_log->Log(log_database, "Mysql query failed: %s", query.str().c_str());
return false; return false;
@ -81,9 +81,9 @@ bool DatabaseMySQL::GetLoginDataFromAccountName(string name, string &password, u
res = mysql_use_result(db); 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]); id = atoi(row[0]);
password = row[1]; 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, 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; return false;
} }
@ -109,7 +109,7 @@ bool DatabaseMySQL::GetWorldRegistration(string long_name, string short_name, un
char escaped_short_name[101]; char escaped_short_name[101];
unsigned long length; 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()); 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); 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 << "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(); 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 << escaped_short_name;
query << "'"; 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()); server_log->Log(log_database, "Mysql query failed: %s", query.str().c_str());
return false; return false;
} }
res = mysql_use_result(db); 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]); id = atoi(row[0]);
desc = row[1]; desc = row[1];
@ -137,22 +137,22 @@ bool DatabaseMySQL::GetWorldRegistration(string long_name, string short_name, un
int db_account_id = atoi(row[5]); int db_account_id = atoi(row[5]);
mysql_free_result(res); mysql_free_result(res);
if(db_account_id > 0) if (db_account_id > 0)
{ {
stringstream query(stringstream::in | stringstream::out); stringstream query(stringstream::in | stringstream::out);
query << "SELECT AccountName, AccountPassword FROM " << server.options.GetWorldAdminRegistrationTable(); query << "SELECT AccountName, AccountPassword FROM " << server.options.GetWorldAdminRegistrationTable();
query << " WHERE ServerAdminID = " << db_account_id; 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()); server_log->Log(log_database, "Mysql query failed: %s", query.str().c_str());
return false; return false;
} }
res = mysql_use_result(db); 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]; account = row[0];
password = row[1]; 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) void DatabaseMySQL::UpdateLSAccountData(unsigned int id, string ip_address)
{ {
if(!db) if (!db)
{ {
return; return;
} }
@ -185,7 +185,7 @@ void DatabaseMySQL::UpdateLSAccountData(unsigned int id, string ip_address)
query << "', LastLoginDate = now() where LoginServerID = "; query << "', LastLoginDate = now() where LoginServerID = ";
query << id; 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()); 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) void DatabaseMySQL::UpdateLSAccountInfo(unsigned int id, string name, string password, string email)
{ {
if(!db) if (!db)
{ {
return; return;
} }
@ -204,7 +204,7 @@ void DatabaseMySQL::UpdateLSAccountInfo(unsigned int id, string name, string pas
query << password << "'), AccountCreateDate = now(), AccountEmail = '" << email; query << password << "'), AccountCreateDate = now(), AccountEmail = '" << email;
query << "', LastIPAddress = '0.0.0.0', LastLoginDate = now()"; 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()); 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) void DatabaseMySQL::UpdateWorldRegistration(unsigned int id, string long_name, string ip_address)
{ {
if(!db) if (!db)
{ {
return; return;
} }
@ -220,7 +220,7 @@ void DatabaseMySQL::UpdateWorldRegistration(unsigned int id, string long_name, s
char escaped_long_name[101]; char escaped_long_name[101];
unsigned long length; 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()); 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); stringstream query(stringstream::in | stringstream::out);
query << "UPDATE " << server.options.GetWorldRegistrationTable() << " SET ServerLastLoginDate = now(), ServerLastIPAddr = '"; query << "UPDATE " << server.options.GetWorldRegistrationTable() << " SET ServerLastLoginDate = now(), ServerLastIPAddr = '";
query << ip_address; query << ip_address;
@ -229,7 +229,7 @@ void DatabaseMySQL::UpdateWorldRegistration(unsigned int id, string long_name, s
query << "' WHERE ServerID = "; query << "' WHERE ServerID = ";
query << id; 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()); 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) bool DatabaseMySQL::CreateWorldRegistration(string long_name, string short_name, unsigned int &id)
{ {
if(!db) if (!db)
{ {
return false; return false;
} }
@ -248,22 +248,22 @@ bool DatabaseMySQL::CreateWorldRegistration(string long_name, string short_name,
char escaped_short_name[101]; char escaped_short_name[101];
unsigned long length; 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()); 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()); 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); stringstream query(stringstream::in | stringstream::out);
query << "SELECT ifnull(max(ServerID),0) FROM " << server.options.GetWorldRegistrationTable(); 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()); server_log->Log(log_database, "Mysql query failed: %s", query.str().c_str());
return false; return false;
} }
res = mysql_use_result(db); 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; id = atoi(row[0]) + 1;
mysql_free_result(res); 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 << ", ServerLongName = '" << escaped_long_name << "', ServerShortName = '" << escaped_short_name;
query << "', ServerListTypeID = 3, ServerAdminID = 0, ServerTrusted = 0, ServerTagDescription = ''"; 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()); server_log->Log(log_database, "Mysql query failed: %s", query.str().c_str());
return false; return false;

View File

@ -40,7 +40,7 @@ public:
* but it's the most trivial way to do this. * but it's the most trivial way to do this.
*/ */
#ifdef WIN32 #ifdef WIN32
LoginServer() : config(nullptr), db(nullptr), eq_crypto(nullptr), SM(nullptr) { } LoginServer() : config(nullptr), db(nullptr), eq_crypto(nullptr), server_manager(nullptr) { }
#else #else
LoginServer() : config(nullptr), db(nullptr) { } LoginServer() : config(nullptr), db(nullptr) { }
#endif #endif
@ -48,8 +48,8 @@ public:
Config *config; Config *config;
Database *db; Database *db;
Options options; Options options;
ServerManager *SM; ServerManager *server_manager;
ClientManager *CM; ClientManager *client_manager;
#ifdef WIN32 #ifdef WIN32
Encryption *eq_crypto; Encryption *eq_crypto;

View File

@ -44,7 +44,7 @@ int main()
RegisterExecutablePlatform(ExePlatformLogin); RegisterExecutablePlatform(ExePlatformLogin);
set_exception_handler(); set_exception_handler();
//Create our error log, is of format login_<number>.log /* Start Loginserver log */
time_t current_time = time(nullptr); time_t current_time = time(nullptr);
std::stringstream log_name(std::stringstream::in | std::stringstream::out); std::stringstream log_name(std::stringstream::in | std::stringstream::out);
#ifdef WIN32 #ifdef WIN32
@ -55,92 +55,55 @@ int main()
server_log = new ErrorLog(log_name.str().c_str()); server_log = new ErrorLog(log_name.str().c_str());
server_log->Log(log_debug, "Logging System Init."); 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.config = new Config();
server_log->Log(log_debug, "Config System Init."); server_log->Log(log_debug, "Config System Init.");
server.config->Parse("login.ini"); 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); 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); 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); 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); 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); server.options.DumpOutPackets(true);
}
//Parse encryption mode option.
std::string mode = server.config->GetVariable("security", "mode"); std::string mode = server.config->GetVariable("security", "mode");
if(mode.size() > 0) if (mode.size() > 0)
{
server.options.EncryptionMode(atoi(mode.c_str())); server.options.EncryptionMode(atoi(mode.c_str()));
}
//Parse local network option. std::string local_network = server.config->GetVariable("options", "local_network");
std::string ln = server.config->GetVariable("options", "local_network"); if (local_network.size() > 0)
if(ln.size() > 0) server.options.LocalNetwork(local_network);
{
server.options.LocalNetwork(ln);
}
//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); server.options.RejectDuplicateServers(true);
}
//Parse account table option. local_network = server.config->GetVariable("schema", "account_table");
ln = server.config->GetVariable("schema", "account_table"); if (local_network.size() > 0)
if(ln.size() > 0) server.options.AccountTable(local_network);
{
server.options.AccountTable(ln);
}
//Parse world account table option. local_network = server.config->GetVariable("schema", "world_registration_table");
ln = server.config->GetVariable("schema", "world_registration_table"); if (local_network.size() > 0)
if(ln.size() > 0) server.options.WorldRegistrationTable(local_network);
{
server.options.WorldRegistrationTable(ln);
}
//Parse admin world account table option. local_network = server.config->GetVariable("schema", "world_admin_registration_table");
ln = server.config->GetVariable("schema", "world_admin_registration_table"); if (local_network.size() > 0)
if(ln.size() > 0) server.options.WorldAdminRegistrationTable(local_network);
{
server.options.WorldAdminRegistrationTable(ln);
}
//Parse world type table option. local_network = server.config->GetVariable("schema", "world_server_type_table");
ln = server.config->GetVariable("schema", "world_server_type_table"); if (local_network.size() > 0)
if(ln.size() > 0) server.options.WorldServerTypeTable(local_network);
{
server.options.WorldServerTypeTable(ln);
}
//Create our DB from options. //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 #ifdef EQEMU_MYSQL_ENABLED
server_log->Log(log_debug, "MySQL Database Init."); server_log->Log(log_debug, "MySQL Database Init.");
server.db = (Database*)new DatabaseMySQL( server.db = (Database*)new DatabaseMySQL(
@ -151,8 +114,7 @@ int main()
server.config->GetVariable("database", "db")); server.config->GetVariable("database", "db"));
#endif #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 #ifdef EQEMU_POSTGRESQL_ENABLED
server_log->Log(log_debug, "PostgreSQL Database Init."); server_log->Log(log_debug, "PostgreSQL Database Init.");
server.db = (Database*)new DatabasePostgreSQL( server.db = (Database*)new DatabasePostgreSQL(
@ -164,9 +126,8 @@ int main()
#endif #endif
} }
//Make sure our database got created okay, otherwise cleanup and exit. /* Make sure our database got created okay, otherwise cleanup and exit. */
if(!server.db) if (!server.db) {
{
server_log->Log(log_error, "Database Initialization Failure."); server_log->Log(log_error, "Database Initialization Failure.");
server_log->Log(log_debug, "Config System Shutdown."); server_log->Log(log_debug, "Config System Shutdown.");
delete server.config; delete server.config;
@ -179,12 +140,10 @@ int main()
//initialize our encryption. //initialize our encryption.
server_log->Log(log_debug, "Encryption Initialize."); server_log->Log(log_debug, "Encryption Initialize.");
server.eq_crypto = new Encryption(); 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."); server_log->Log(log_debug, "Encryption Loaded Successfully.");
} }
else else {
{
//We can't run without encryption, cleanup and exit. //We can't run without encryption, cleanup and exit.
server_log->Log(log_error, "Encryption Failed to Load."); server_log->Log(log_error, "Encryption Failed to Load.");
server_log->Log(log_debug, "Database System Shutdown."); server_log->Log(log_debug, "Database System Shutdown.");
@ -199,15 +158,16 @@ int main()
//create our server manager. //create our server manager.
server_log->Log(log_debug, "Server Manager Initialize."); server_log->Log(log_debug, "Server Manager Initialize.");
server.SM = new ServerManager(); server.server_manager = new ServerManager();
if(!server.SM) if (!server.server_manager) {
{
//We can't run without a server manager, cleanup and exit. //We can't run without a server manager, cleanup and exit.
server_log->Log(log_error, "Server Manager Failed to Start."); server_log->Log(log_error, "Server Manager Failed to Start.");
#ifdef WIN32 #ifdef WIN32
server_log->Log(log_debug, "Encryption System Shutdown."); server_log->Log(log_debug, "Encryption System Shutdown.");
delete server.eq_crypto; delete server.eq_crypto;
#endif #endif
server_log->Log(log_debug, "Database System Shutdown."); server_log->Log(log_debug, "Database System Shutdown.");
delete server.db; delete server.db;
server_log->Log(log_debug, "Config System Shutdown."); server_log->Log(log_debug, "Config System Shutdown.");
@ -219,17 +179,18 @@ int main()
//create our client manager. //create our client manager.
server_log->Log(log_debug, "Client Manager Initialize."); server_log->Log(log_debug, "Client Manager Initialize.");
server.CM = new ClientManager(); server.client_manager = new ClientManager();
if(!server.CM) if (!server.client_manager) {
{
//We can't run without a client manager, cleanup and exit. //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_error, "Client Manager Failed to Start.");
server_log->Log(log_debug, "Server Manager Shutdown."); server_log->Log(log_debug, "Server Manager Shutdown.");
delete server.SM; delete server.server_manager;
#ifdef WIN32 #ifdef WIN32
server_log->Log(log_debug, "Encryption System Shutdown."); server_log->Log(log_debug, "Encryption System Shutdown.");
delete server.eq_crypto; delete server.eq_crypto;
#endif #endif
server_log->Log(log_debug, "Database System Shutdown."); server_log->Log(log_debug, "Database System Shutdown.");
delete server.db; delete server.db;
server_log->Log(log_debug, "Config System Shutdown."); server_log->Log(log_debug, "Config System Shutdown.");
@ -248,23 +209,24 @@ int main()
#endif #endif
server_log->Log(log_debug, "Server Started."); server_log->Log(log_debug, "Server Started.");
while(run_server) while (run_server) {
{
Timer::SetCurrentTime(); Timer::SetCurrentTime();
server.CM->Process(); server.client_manager->Process();
server.SM->Process(); server.server_manager->Process();
Sleep(100); Sleep(100);
} }
server_log->Log(log_debug, "Server Shutdown."); server_log->Log(log_debug, "Server Shutdown.");
server_log->Log(log_debug, "Client Manager Shutdown."); server_log->Log(log_debug, "Client Manager Shutdown.");
delete server.CM; delete server.client_manager;
server_log->Log(log_debug, "Server Manager Shutdown."); server_log->Log(log_debug, "Server Manager Shutdown.");
delete server.SM; delete server.server_manager;
#ifdef WIN32 #ifdef WIN32
server_log->Log(log_debug, "Encryption System Shutdown."); server_log->Log(log_debug, "Encryption System Shutdown.");
delete server.eq_crypto; delete server.eq_crypto;
#endif #endif
server_log->Log(log_debug, "Database System Shutdown."); server_log->Log(log_debug, "Database System Shutdown.");
delete server.db; delete server.db;
server_log->Log(log_debug, "Config System Shutdown."); server_log->Log(log_debug, "Config System Shutdown.");

View File

@ -28,19 +28,18 @@ WorldServer::WorldServer(EmuTCPConnection *c)
connection = c; connection = c;
zones_booted = 0; zones_booted = 0;
players_online = 0; players_online = 0;
status = 0; server_status = 0;
runtime_id = 0; runtime_id = 0;
server_list_id = 0; server_list_id = 0;
server_type = 0; server_type = 0;
authorized = false; is_server_authorized = false;
trusted = false; is_server_trusted = false;
logged_in = false; is_server_logged_in = false;
} }
WorldServer::~WorldServer() WorldServer::~WorldServer()
{ {
if(connection) if(connection) {
{
connection->Free(); connection->Free();
} }
} }
@ -49,12 +48,12 @@ void WorldServer::Reset()
{ {
zones_booted = 0; zones_booted = 0;
players_online = 0; players_online = 0;
status = 0; server_status = 0;
runtime_id; runtime_id;
server_list_id = 0; server_list_id = 0;
server_type = 0; server_type = 0;
authorized = false; is_server_authorized = false;
logged_in = false; is_server_logged_in = false;
} }
bool WorldServer::Process() bool WorldServer::Process()
@ -142,7 +141,7 @@ bool WorldServer::Process()
UsertoWorldResponse_Struct *utwr = (UsertoWorldResponse_Struct*)app->pBuffer; UsertoWorldResponse_Struct *utwr = (UsertoWorldResponse_Struct*)app->pBuffer;
server_log->Log(log_client, "Trying to find client with user id of %u.", utwr->lsaccountid); 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) 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()); 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()); server_log->Log(log_network_trace, "ServerOP_LSAccountUpdate packet received from: %s", short_name.c_str());
ServerLSAccountUpdate_Struct *lsau = (ServerLSAccountUpdate_Struct*)app->pBuffer; 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); server_log->Log(log_network_trace, "ServerOP_LSAccountUpdate update processed for: %s", lsau->useraccount);
string name; string name;
@ -237,7 +236,7 @@ bool WorldServer::Process()
void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i) 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."); server_log->Log(log_network_error, "WorldServer::Handle_NewLSInfo called but the login server was already marked as logged in, aborting.");
return; return;
@ -344,11 +343,11 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
} }
server_type = i->servertype; server_type = i->servertype;
logged_in = true; is_server_logged_in = true;
if(server.options.IsRejectingDuplicateServers()) 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."); server_log->Log(log_world_error, "World tried to login but there already exists a server that has that name.");
return; return;
@ -356,10 +355,10 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
} }
else 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_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.", 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()); long_name.c_str(), short_name.c_str());
authorized = true; is_server_authorized = true;
SetRuntimeID(s_id); SetRuntimeID(s_id);
server_list_id = s_list_type; server_list_id = s_list_type;
desc = s_desc; 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.", server_log->Log(log_world, "Server %s(%s) successfully logged in.",
long_name.c_str(), short_name.c_str()); long_name.c_str(), short_name.c_str());
authorized = true; is_server_authorized = true;
SetRuntimeID(s_id); SetRuntimeID(s_id);
server_list_id = s_list_type; server_list_id = s_list_type;
desc = s_desc; desc = s_desc;
if(s_trusted) if(s_trusted) {
{
server_log->Log(log_network_trace, "ServerOP_LSAccountUpdate sent to world"); server_log->Log(log_network_trace, "ServerOP_LSAccountUpdate sent to world");
trusted = true; is_server_trusted = true;
ServerPacket *outapp = new ServerPacket(ServerOP_LSAccountUpdate, 0); ServerPacket *outapp = new ServerPacket(ServerOP_LSAccountUpdate, 0);
connection->SendPacket(outapp); 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" 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()); " registered servers are allowed.", long_name.c_str(), short_name.c_str());
return; 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.", 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()); long_name.c_str(), short_name.c_str());
return; return;
} }
} }
else else {
{
server_log->Log(log_world, "Server %s(%s) did not attempt to log in but only registered servers are allowed.", 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()); long_name.c_str(), short_name.c_str());
return; return;
} }
} }
else else {
{ unsigned int server_id = 0;
unsigned int s_id = 0; unsigned int server_list_type = 0;
unsigned int s_list_type = 0; unsigned int is_server_trusted = 0;
unsigned int s_trusted = 0; string server_description;
string s_desc; string server_list_description;
string s_list_desc; string server_account_name;
string s_acct_name; string server_account_password;
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))
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(account_name.size() > 0 && account_password.size() > 0) {
if(s_acct_name.compare(account_name) == 0 && s_acct_pass.compare(account_password) == 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.", server_log->Log(log_world, "Server %s(%s) successfully logged in.",
long_name.c_str(), short_name.c_str()); long_name.c_str(), short_name.c_str());
authorized = true; is_server_authorized = true;
SetRuntimeID(s_id); SetRuntimeID(server_id);
server_list_id = s_list_type; server_list_id = server_list_type;
desc = s_desc; desc = server_description;
if(s_trusted)
{ if(is_server_trusted) {
server_log->Log(log_network_trace, "ServerOP_LSAccountUpdate sent to world"); server_log->Log(log_network_trace, "ServerOP_LSAccountUpdate sent to world");
trusted = true; is_server_trusted = true;
ServerPacket *outapp = new ServerPacket(ServerOP_LSAccountUpdate, 0); ServerPacket *outapp = new ServerPacket(ServerOP_LSAccountUpdate, 0);
connection->SendPacket(outapp); connection->SendPacket(outapp);
} }
} }
else else {
{
// this is the first of two cases where we should deny access even if unregistered is allowed // 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.", 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()); long_name.c_str(), short_name.c_str());
} }
} }
else else {
{ if(server_account_name.size() > 0 || server_account_password.size() > 0) {
if(s_acct_name.size() > 0 || s_acct_pass.size() > 0)
{
// this is the second of two cases where we should deny access even if unregistered is allowed // 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.", 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()); 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.", 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()); long_name.c_str(), short_name.c_str());
authorized = true; is_server_authorized = true;
SetRuntimeID(s_id); SetRuntimeID(server_id);
server_list_id = 3; 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.", 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()); long_name.c_str(), short_name.c_str());
if(server.db->CreateWorldRegistration(long_name, short_name, s_id)) if(server.db->CreateWorldRegistration(long_name, short_name, server_id)) {
{ is_server_authorized = true;
authorized = true; SetRuntimeID(server_id);
SetRuntimeID(s_id);
server_list_id = 3; server_list_id = 3;
} }
} }
@ -493,9 +492,9 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
in.s_addr = connection->GetrIP(); in.s_addr = connection->GetrIP();
server.db->UpdateWorldRegistration(GetRuntimeID(), long_name, string(inet_ntoa(in))); 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; players_online = s->num_players;
zones_booted = s->num_zones; 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) void WorldServer::SendClientAuth(unsigned int ip, string account, string key, unsigned int account_id)
{ {
ServerPacket *outapp = new ServerPacket(ServerOP_LSClientAuth, sizeof(ServerLSClientAuth)); ServerPacket *outapp = new ServerPacket(ServerOP_LSClientAuth, sizeof(ClientAuth_Struct));
ServerLSClientAuth* slsca = (ServerLSClientAuth*)outapp->pBuffer; ClientAuth_Struct* client_auth = (ClientAuth_Struct*)outapp->pBuffer;
slsca->lsaccount_id = account_id; client_auth->lsaccount_id = account_id;
strncpy(slsca->name, account.c_str(), account.size() > 30 ? 30 : account.size()); strncpy(client_auth->name, account.c_str(), account.size() > 30 ? 30 : account.size());
strncpy(slsca->key, key.c_str(), 10); strncpy(client_auth->key, key.c_str(), 10);
slsca->lsadmin = 0; client_auth->lsadmin = 0;
slsca->worldadmin = 0; client_auth->worldadmin = 0;
slsca->ip = ip; client_auth->ip = ip;
in_addr in; in_addr in;
in.s_addr = ip;connection->GetrIP(); in.s_addr = ip; connection->GetrIP();
string client_address(inet_ntoa(in)); string client_address(inet_ntoa(in));
in.s_addr = connection->GetrIP(); in.s_addr = connection->GetrIP();
string world_address(inet_ntoa(in)); string world_address(inet_ntoa(in));
if(client_address.compare(world_address) == 0) if (client_address.compare(world_address) == 0) {
{ client_auth->local = 1;
slsca->local = 1;
} }
else if(client_address.find(server.options.GetLocalNetwork()) != string::npos) else if (client_address.find(server.options.GetLocalNetwork()) != string::npos) {
{ client_auth->local = 1;
slsca->local = 1;
} }
else else {
{ client_auth->local = 0;
slsca->local = 0;
} }
connection->SendPacket(outapp); connection->SendPacket(outapp);
if(server.options.IsDumpInPacketsOn()) if (server.options.IsDumpInPacketsOn())
{ {
DumpPacket(outapp); DumpPacket(outapp);
} }

View File

@ -86,7 +86,7 @@ public:
/** /**
* Gets whether the server is authorized to show up on the server list or not. * 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. * Gets the local ip of the server.
@ -106,7 +106,7 @@ public:
/** /**
* Gets the status of the server. * 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. * Gets the number of zones online on the server.
@ -138,7 +138,7 @@ private:
EmuTCPConnection *connection; EmuTCPConnection *connection;
unsigned int zones_booted; unsigned int zones_booted;
unsigned int players_online; unsigned int players_online;
int status; int server_status;
unsigned int runtime_id; unsigned int runtime_id;
unsigned int server_list_id; unsigned int server_list_id;
unsigned int server_type; unsigned int server_type;
@ -151,9 +151,9 @@ private:
std::string local_ip; std::string local_ip;
std::string protocol; std::string protocol;
std::string version; std::string version;
bool authorized; bool is_server_authorized;
bool logged_in; bool is_server_logged_in;
bool trusted; bool is_server_trusted;
}; };
#endif #endif

View File

@ -145,7 +145,7 @@ bool LoginServer::Process() {
break; break;
} }
case ServerOP_LSClientAuth: { case ServerOP_LSClientAuth: {
ServerLSClientAuth* slsca = (ServerLSClientAuth*) pack->pBuffer; ClientAuth_Struct* slsca = (ClientAuth_Struct*) pack->pBuffer;
if (RuleI(World, AccountSessionLimit) >= 0) { if (RuleI(World, AccountSessionLimit) >= 0) {
// Enforce the limit on the number of characters on the same account that can be // Enforce the limit on the number of characters on the same account that can be