mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-12 17:51:28 +00:00
Some more loginserver refactoring to make things more sane to read
This commit is contained in:
parent
2fbf047853
commit
a936796b45
@ -33,15 +33,15 @@ DatabaseMySQL::DatabaseMySQL(string user, string pass, string host, string port,
|
||||
this->host = host;
|
||||
this->name = name;
|
||||
|
||||
db = mysql_init(nullptr);
|
||||
if(db)
|
||||
database = mysql_init(nullptr);
|
||||
if(database)
|
||||
{
|
||||
my_bool r = 1;
|
||||
mysql_options(db, MYSQL_OPT_RECONNECT, &r);
|
||||
if(!mysql_real_connect(db, host.c_str(), user.c_str(), pass.c_str(), name.c_str(), atoi(port.c_str()), nullptr, 0))
|
||||
mysql_options(database, MYSQL_OPT_RECONNECT, &r);
|
||||
if(!mysql_real_connect(database, host.c_str(), user.c_str(), pass.c_str(), name.c_str(), atoi(port.c_str()), nullptr, 0))
|
||||
{
|
||||
mysql_close(db);
|
||||
server_log->Log(log_database, "Failed to connect to MySQL database. Error: %s", mysql_error(db));
|
||||
mysql_close(database);
|
||||
server_log->Log(log_database, "Failed to connect to MySQL database. Error: %s", mysql_error(database));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
@ -53,15 +53,15 @@ DatabaseMySQL::DatabaseMySQL(string user, string pass, string host, string port,
|
||||
|
||||
DatabaseMySQL::~DatabaseMySQL()
|
||||
{
|
||||
if(db)
|
||||
if(database)
|
||||
{
|
||||
mysql_close(db);
|
||||
mysql_close(database);
|
||||
}
|
||||
}
|
||||
|
||||
bool DatabaseMySQL::GetLoginDataFromAccountName(string name, string &password, unsigned int &id)
|
||||
{
|
||||
if (!db)
|
||||
if (!database)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -73,13 +73,13 @@ bool DatabaseMySQL::GetLoginDataFromAccountName(string name, string &password, u
|
||||
query << name;
|
||||
query << "'";
|
||||
|
||||
if (mysql_query(db, query.str().c_str()) != 0)
|
||||
if (mysql_query(database, 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);
|
||||
res = mysql_use_result(database);
|
||||
|
||||
if (res)
|
||||
{
|
||||
@ -99,7 +99,7 @@ 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)
|
||||
{
|
||||
if (!db)
|
||||
if (!database)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -108,7 +108,7 @@ bool DatabaseMySQL::GetWorldRegistration(string long_name, string short_name, un
|
||||
MYSQL_ROW row;
|
||||
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());
|
||||
length = mysql_real_escape_string(database, escaped_short_name, short_name.substr(0, 100).c_str(), short_name.substr(0, 100).length());
|
||||
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, ";
|
||||
@ -118,13 +118,13 @@ 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(database, 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);
|
||||
res = mysql_use_result(database);
|
||||
if (res)
|
||||
{
|
||||
if ((row = mysql_fetch_row(res)) != nullptr)
|
||||
@ -143,13 +143,13 @@ bool DatabaseMySQL::GetWorldRegistration(string long_name, string short_name, un
|
||||
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(database, 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);
|
||||
res = mysql_use_result(database);
|
||||
if (res)
|
||||
{
|
||||
if ((row = mysql_fetch_row(res)) != nullptr)
|
||||
@ -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 (!database)
|
||||
{
|
||||
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(database, 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 (!database)
|
||||
{
|
||||
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(database, query.str().c_str()) != 0)
|
||||
{
|
||||
server_log->Log(log_database, "Mysql query failed: %s", query.str().c_str());
|
||||
}
|
||||
@ -212,14 +212,14 @@ 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 (!database)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
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());
|
||||
length = mysql_real_escape_string(database, escaped_long_name, long_name.substr(0, 100).c_str(), long_name.substr(0, 100).length());
|
||||
escaped_long_name[length + 1] = 0;
|
||||
stringstream query(stringstream::in | stringstream::out);
|
||||
query << "UPDATE " << server.options.GetWorldRegistrationTable() << " SET ServerLastLoginDate = now(), ServerLastIPAddr = '";
|
||||
@ -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(database, 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 (!database)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -247,20 +247,20 @@ bool DatabaseMySQL::CreateWorldRegistration(string long_name, string short_name,
|
||||
char escaped_long_name[201];
|
||||
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());
|
||||
length = mysql_real_escape_string(database, escaped_long_name, long_name.substr(0, 100).c_str(), long_name.substr(0, 100).length());
|
||||
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(database, escaped_short_name, short_name.substr(0, 100).c_str(), short_name.substr(0, 100).length());
|
||||
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(database, 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);
|
||||
res = mysql_use_result(database);
|
||||
if (res)
|
||||
{
|
||||
if ((row = mysql_fetch_row(res)) != nullptr)
|
||||
@ -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(database, query.str().c_str()) != 0)
|
||||
{
|
||||
server_log->Log(log_database, "Mysql query failed: %s", query.str().c_str());
|
||||
return false;
|
||||
|
||||
@ -35,7 +35,7 @@ public:
|
||||
/**
|
||||
* Constructor, sets our database to null.
|
||||
*/
|
||||
DatabaseMySQL() { db = nullptr; }
|
||||
DatabaseMySQL() { database = nullptr; }
|
||||
|
||||
/**
|
||||
* Constructor, tries to set our database to connect to the supplied options.
|
||||
@ -50,7 +50,7 @@ public:
|
||||
/**
|
||||
* @return Returns true if the database successfully connected.
|
||||
*/
|
||||
virtual bool IsConnected() { return (db != nullptr); }
|
||||
virtual bool IsConnected() { return (database != nullptr); }
|
||||
|
||||
/**
|
||||
* Retrieves the login data (password hash and account id) from the account name provided
|
||||
@ -88,7 +88,7 @@ public:
|
||||
virtual bool CreateWorldRegistration(std::string long_name, std::string short_name, unsigned int &id);
|
||||
protected:
|
||||
std::string user, pass, host, port, name;
|
||||
MYSQL *db;
|
||||
MYSQL *database;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -41,7 +41,7 @@ ErrorLog::ErrorLog(const char* file_name)
|
||||
ErrorLog::~ErrorLog()
|
||||
{
|
||||
log_mutex->lock();
|
||||
if(error_log)
|
||||
if (error_log)
|
||||
{
|
||||
fclose(error_log);
|
||||
}
|
||||
@ -51,7 +51,7 @@ ErrorLog::~ErrorLog()
|
||||
|
||||
void ErrorLog::Log(eqLogType type, const char *message, ...)
|
||||
{
|
||||
if(type >= _log_largest_type)
|
||||
if (type >= _log_largest_type)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -70,21 +70,21 @@ void ErrorLog::Log(eqLogType type, const char *message, ...)
|
||||
log_mutex->lock();
|
||||
printf("[%s] [%02d.%02d.%02d - %02d:%02d:%02d] %s\n",
|
||||
eqLogTypes[type],
|
||||
m_time->tm_mon+1,
|
||||
m_time->tm_mon + 1,
|
||||
m_time->tm_mday,
|
||||
m_time->tm_year%100,
|
||||
m_time->tm_year % 100,
|
||||
m_time->tm_hour,
|
||||
m_time->tm_min,
|
||||
m_time->tm_sec,
|
||||
buffer);
|
||||
|
||||
if(error_log)
|
||||
if (error_log)
|
||||
{
|
||||
fprintf(error_log, "[%s] [%02d.%02d.%02d - %02d:%02d:%02d] %s\n",
|
||||
eqLogTypes[type],
|
||||
m_time->tm_mon+1,
|
||||
m_time->tm_mon + 1,
|
||||
m_time->tm_mday,
|
||||
m_time->tm_year%100,
|
||||
m_time->tm_year % 100,
|
||||
m_time->tm_hour,
|
||||
m_time->tm_min,
|
||||
m_time->tm_sec,
|
||||
@ -98,7 +98,7 @@ void ErrorLog::Log(eqLogType type, const char *message, ...)
|
||||
|
||||
void ErrorLog::LogPacket(eqLogType type, const char *data, size_t size)
|
||||
{
|
||||
if(type >= _log_largest_type)
|
||||
if (type >= _log_largest_type)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -112,21 +112,21 @@ void ErrorLog::LogPacket(eqLogType type, const char *data, size_t size)
|
||||
log_mutex->lock();
|
||||
printf("[%s] [%02d.%02d.%02d - %02d:%02d:%02d] dumping packet of size %u:\n",
|
||||
eqLogTypes[type],
|
||||
m_time->tm_mon+1,
|
||||
m_time->tm_mon + 1,
|
||||
m_time->tm_mday,
|
||||
m_time->tm_year%100,
|
||||
m_time->tm_year % 100,
|
||||
m_time->tm_hour,
|
||||
m_time->tm_min,
|
||||
m_time->tm_sec,
|
||||
(unsigned int)size);
|
||||
|
||||
if(error_log)
|
||||
if (error_log)
|
||||
{
|
||||
fprintf(error_log, "[%s] [%02d.%02d.%02d - %02d:%02d:%02d] dumping packet of size %u\n",
|
||||
eqLogTypes[type],
|
||||
m_time->tm_mon+1,
|
||||
m_time->tm_mon + 1,
|
||||
m_time->tm_mday,
|
||||
m_time->tm_year%100,
|
||||
m_time->tm_year % 100,
|
||||
m_time->tm_hour,
|
||||
m_time->tm_min,
|
||||
m_time->tm_sec,
|
||||
@ -138,14 +138,14 @@ void ErrorLog::LogPacket(eqLogType type, const char *data, size_t size)
|
||||
|
||||
size_t j = 0;
|
||||
size_t i = 0;
|
||||
for(; i < size; ++i)
|
||||
for (; i < size; ++i)
|
||||
{
|
||||
if(i % 16 == 0)
|
||||
if (i % 16 == 0)
|
||||
{
|
||||
if(i != 0)
|
||||
if (i != 0)
|
||||
{
|
||||
printf(" | %s\n", ascii);
|
||||
if(error_log)
|
||||
if (error_log)
|
||||
{
|
||||
fprintf(error_log, " | %s\n", ascii);
|
||||
}
|
||||
@ -154,22 +154,22 @@ void ErrorLog::LogPacket(eqLogType type, const char *data, size_t size)
|
||||
memset(ascii, 0, 17);
|
||||
j = 0;
|
||||
}
|
||||
else if(i % 8 == 0)
|
||||
else if (i % 8 == 0)
|
||||
{
|
||||
printf("- ");
|
||||
if(error_log)
|
||||
if (error_log)
|
||||
{
|
||||
fprintf(error_log, "- ");
|
||||
}
|
||||
}
|
||||
|
||||
printf("%02X ", (unsigned int)data[i]);
|
||||
if(error_log)
|
||||
if (error_log)
|
||||
{
|
||||
fprintf(error_log, "%02X ", (unsigned int)data[i]);
|
||||
}
|
||||
|
||||
if(data[i] >= 32 && data[i] < 127)
|
||||
if (data[i] >= 32 && data[i] < 127)
|
||||
{
|
||||
ascii[j++] = data[i];
|
||||
}
|
||||
@ -180,26 +180,26 @@ void ErrorLog::LogPacket(eqLogType type, const char *data, size_t size)
|
||||
}
|
||||
|
||||
size_t k = (i - 1) % 16;
|
||||
if(k < 8)
|
||||
if (k < 8)
|
||||
{
|
||||
printf(" ");
|
||||
if(error_log)
|
||||
if (error_log)
|
||||
{
|
||||
fprintf(error_log, " ");
|
||||
}
|
||||
}
|
||||
|
||||
for(size_t h = k + 1; h < 16; ++h)
|
||||
for (size_t h = k + 1; h < 16; ++h)
|
||||
{
|
||||
printf(" ");
|
||||
if(error_log)
|
||||
if (error_log)
|
||||
{
|
||||
fprintf(error_log, " ");
|
||||
}
|
||||
}
|
||||
|
||||
printf(" | %s\n", ascii);
|
||||
if(error_log)
|
||||
if (error_log)
|
||||
{
|
||||
fprintf(error_log, " | %s\n", ascii);
|
||||
fflush(error_log);
|
||||
@ -207,4 +207,3 @@ void ErrorLog::LogPacket(eqLogType type, const char *data, size_t size)
|
||||
|
||||
log_mutex->unlock();
|
||||
}
|
||||
|
||||
|
||||
@ -102,7 +102,7 @@ int main()
|
||||
if (local_network.size() > 0)
|
||||
server.options.WorldServerTypeTable(local_network);
|
||||
|
||||
//Create our DB from options.
|
||||
/* Create database connection */
|
||||
if (server.config->GetVariable("database", "subsystem").compare("MySQL") == 0) {
|
||||
#ifdef EQEMU_MYSQL_ENABLED
|
||||
server_log->Log(log_debug, "MySQL Database Init.");
|
||||
|
||||
@ -31,12 +31,10 @@ ServerManager::ServerManager()
|
||||
|
||||
int listen_port = atoi(server.config->GetVariable("options", "listen_port").c_str());
|
||||
tcps = new EmuTCPServer(listen_port, true);
|
||||
if(tcps->Open(listen_port, error_buffer))
|
||||
{
|
||||
if(tcps->Open(listen_port, error_buffer)) {
|
||||
server_log->Log(log_network, "ServerManager listening on port %u", listen_port);
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
server_log->Log(log_error, "ServerManager fatal error opening port on %u: %s", listen_port, error_buffer);
|
||||
run_server = false;
|
||||
}
|
||||
@ -44,8 +42,7 @@ ServerManager::ServerManager()
|
||||
|
||||
ServerManager::~ServerManager()
|
||||
{
|
||||
if(tcps)
|
||||
{
|
||||
if (tcps) {
|
||||
tcps->Close();
|
||||
delete tcps;
|
||||
}
|
||||
@ -55,38 +52,32 @@ void ServerManager::Process()
|
||||
{
|
||||
ProcessDisconnect();
|
||||
EmuTCPConnection *tcp_c = nullptr;
|
||||
while(tcp_c = tcps->NewQueuePop())
|
||||
{
|
||||
while (tcp_c = tcps->NewQueuePop()) {
|
||||
in_addr tmp;
|
||||
tmp.s_addr = tcp_c->GetrIP();
|
||||
server_log->Log(log_network, "New world server connection from %s:%d", inet_ntoa(tmp), tcp_c->GetrPort());
|
||||
|
||||
WorldServer *cur = GetServerByAddress(tcp_c->GetrIP());
|
||||
if(cur)
|
||||
{
|
||||
WorldServer *server_entity = GetServerByAddress(tcp_c->GetrIP());
|
||||
if (server_entity) {
|
||||
server_log->Log(log_network, "World server already existed for %s, removing existing connection and updating current.", inet_ntoa(tmp));
|
||||
cur->GetConnection()->Free();
|
||||
cur->SetConnection(tcp_c);
|
||||
cur->Reset();
|
||||
server_entity->GetConnection()->Free();
|
||||
server_entity->SetConnection(tcp_c);
|
||||
server_entity->Reset();
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
WorldServer *w = new WorldServer(tcp_c);
|
||||
world_servers.push_back(w);
|
||||
}
|
||||
}
|
||||
|
||||
list<WorldServer*>::iterator iter = world_servers.begin();
|
||||
while(iter != world_servers.end())
|
||||
{
|
||||
if((*iter)->Process() == false)
|
||||
{
|
||||
while (iter != world_servers.end()) {
|
||||
if ((*iter)->Process() == false) {
|
||||
server_log->Log(log_world, "World server %s had a fatal error and had to be removed from the login.", (*iter)->GetLongName().c_str());
|
||||
delete (*iter);
|
||||
iter = world_servers.erase(iter);
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
@ -95,20 +86,17 @@ void ServerManager::Process()
|
||||
void ServerManager::ProcessDisconnect()
|
||||
{
|
||||
list<WorldServer*>::iterator iter = world_servers.begin();
|
||||
while(iter != world_servers.end())
|
||||
{
|
||||
EmuTCPConnection *c = (*iter)->GetConnection();
|
||||
if(!c->Connected())
|
||||
{
|
||||
while (iter != world_servers.end()) {
|
||||
EmuTCPConnection *connection = (*iter)->GetConnection();
|
||||
if (!connection->Connected()) {
|
||||
in_addr tmp;
|
||||
tmp.s_addr = c->GetrIP();
|
||||
tmp.s_addr = connection->GetrIP();
|
||||
server_log->Log(log_network, "World server disconnected from the server, removing server and freeing connection.");
|
||||
c->Free();
|
||||
connection->Free();
|
||||
delete (*iter);
|
||||
iter = world_servers.erase(iter);
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
@ -117,10 +105,8 @@ void ServerManager::ProcessDisconnect()
|
||||
WorldServer* ServerManager::GetServerByAddress(unsigned int address)
|
||||
{
|
||||
list<WorldServer*>::iterator iter = world_servers.begin();
|
||||
while(iter != world_servers.end())
|
||||
{
|
||||
if((*iter)->GetConnection()->GetrIP() == address)
|
||||
{
|
||||
while (iter != world_servers.end()) {
|
||||
if ((*iter)->GetConnection()->GetrIP() == address) {
|
||||
return (*iter);
|
||||
}
|
||||
++iter;
|
||||
@ -138,10 +124,8 @@ EQApplicationPacket *ServerManager::CreateServerListPacket(Client *c)
|
||||
string client_ip = inet_ntoa(in);
|
||||
|
||||
list<WorldServer*>::iterator iter = world_servers.begin();
|
||||
while(iter != world_servers.end())
|
||||
{
|
||||
if((*iter)->IsAuthorized() == false)
|
||||
{
|
||||
while (iter != world_servers.end()) {
|
||||
if ((*iter)->IsAuthorized() == false) {
|
||||
++iter;
|
||||
continue;
|
||||
}
|
||||
@ -149,16 +133,13 @@ EQApplicationPacket *ServerManager::CreateServerListPacket(Client *c)
|
||||
in.s_addr = (*iter)->GetConnection()->GetrIP();
|
||||
string world_ip = inet_ntoa(in);
|
||||
|
||||
if(world_ip.compare(client_ip) == 0)
|
||||
{
|
||||
if (world_ip.compare(client_ip) == 0) {
|
||||
packet_size += (*iter)->GetLongName().size() + (*iter)->GetLocalIP().size() + 24;
|
||||
}
|
||||
else if(client_ip.find(server.options.GetLocalNetwork()) != string::npos)
|
||||
{
|
||||
else if (client_ip.find(server.options.GetLocalNetwork()) != string::npos) {
|
||||
packet_size += (*iter)->GetLongName().size() + (*iter)->GetLocalIP().size() + 24;
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
packet_size += (*iter)->GetLongName().size() + (*iter)->GetRemoteIP().size() + 24;
|
||||
}
|
||||
|
||||
@ -167,98 +148,87 @@ EQApplicationPacket *ServerManager::CreateServerListPacket(Client *c)
|
||||
}
|
||||
|
||||
EQApplicationPacket *outapp = new EQApplicationPacket(OP_ServerListResponse, packet_size);
|
||||
ServerListHeader_Struct *sl = (ServerListHeader_Struct*)outapp->pBuffer;
|
||||
sl->Unknown1 = 0x00000004;
|
||||
sl->Unknown2 = 0x00000000;
|
||||
sl->Unknown3 = 0x01650000;
|
||||
ServerListHeader_Struct *server_list = (ServerListHeader_Struct*)outapp->pBuffer;
|
||||
server_list->Unknown1 = 0x00000004;
|
||||
server_list->Unknown2 = 0x00000000;
|
||||
server_list->Unknown3 = 0x01650000;
|
||||
|
||||
/**
|
||||
* Not sure what this is but it should be noted setting it to
|
||||
* 0xFFFFFFFF crashes the client so: don't do that.
|
||||
*/
|
||||
sl->Unknown4 = 0x00000000;
|
||||
sl->NumberOfServers = server_count;
|
||||
server_list->Unknown4 = 0x00000000;
|
||||
server_list->NumberOfServers = server_count;
|
||||
|
||||
unsigned char *data_ptr = outapp->pBuffer;
|
||||
data_ptr += sizeof(ServerListHeader_Struct);
|
||||
unsigned char *data_pointer = outapp->pBuffer;
|
||||
data_pointer += sizeof(ServerListHeader_Struct);
|
||||
|
||||
iter = world_servers.begin();
|
||||
while(iter != world_servers.end())
|
||||
{
|
||||
if((*iter)->IsAuthorized() == false)
|
||||
{
|
||||
while (iter != world_servers.end()) {
|
||||
if ((*iter)->IsAuthorized() == false) {
|
||||
++iter;
|
||||
continue;
|
||||
}
|
||||
|
||||
in.s_addr = (*iter)->GetConnection()->GetrIP();
|
||||
string world_ip = inet_ntoa(in);
|
||||
if(world_ip.compare(client_ip) == 0)
|
||||
{
|
||||
memcpy(data_ptr, (*iter)->GetLocalIP().c_str(), (*iter)->GetLocalIP().size());
|
||||
data_ptr += ((*iter)->GetLocalIP().size() + 1);
|
||||
if (world_ip.compare(client_ip) == 0) {
|
||||
memcpy(data_pointer, (*iter)->GetLocalIP().c_str(), (*iter)->GetLocalIP().size());
|
||||
data_pointer += ((*iter)->GetLocalIP().size() + 1);
|
||||
}
|
||||
else if(client_ip.find(server.options.GetLocalNetwork()) != string::npos)
|
||||
{
|
||||
memcpy(data_ptr, (*iter)->GetLocalIP().c_str(), (*iter)->GetLocalIP().size());
|
||||
data_ptr += ((*iter)->GetLocalIP().size() + 1);
|
||||
else if (client_ip.find(server.options.GetLocalNetwork()) != string::npos) {
|
||||
memcpy(data_pointer, (*iter)->GetLocalIP().c_str(), (*iter)->GetLocalIP().size());
|
||||
data_pointer += ((*iter)->GetLocalIP().size() + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(data_ptr, (*iter)->GetRemoteIP().c_str(), (*iter)->GetRemoteIP().size());
|
||||
data_ptr += ((*iter)->GetRemoteIP().size() + 1);
|
||||
else {
|
||||
memcpy(data_pointer, (*iter)->GetRemoteIP().c_str(), (*iter)->GetRemoteIP().size());
|
||||
data_pointer += ((*iter)->GetRemoteIP().size() + 1);
|
||||
}
|
||||
|
||||
switch((*iter)->GetServerListID())
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
*(unsigned int*)data_ptr = 0x00000030;
|
||||
switch ((*iter)->GetServerListID()) {
|
||||
case 1: {
|
||||
*(unsigned int*)data_pointer = 0x00000030;
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
*(unsigned int*)data_ptr = 0x00000009;
|
||||
case 2: {
|
||||
*(unsigned int*)data_pointer = 0x00000009;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
*(unsigned int*)data_ptr = 0x00000001;
|
||||
default: {
|
||||
*(unsigned int*)data_pointer = 0x00000001;
|
||||
}
|
||||
}
|
||||
data_ptr += 4;
|
||||
|
||||
*(unsigned int*)data_ptr = (*iter)->GetRuntimeID();
|
||||
data_ptr += 4;
|
||||
data_pointer += 4;
|
||||
|
||||
memcpy(data_ptr, (*iter)->GetLongName().c_str(), (*iter)->GetLongName().size());
|
||||
data_ptr += ((*iter)->GetLongName().size() + 1);
|
||||
*(unsigned int*)data_pointer = (*iter)->GetRuntimeID();
|
||||
data_pointer += 4;
|
||||
|
||||
memcpy(data_ptr, "EN", 2);
|
||||
data_ptr += 3;
|
||||
memcpy(data_pointer, (*iter)->GetLongName().c_str(), (*iter)->GetLongName().size());
|
||||
data_pointer += ((*iter)->GetLongName().size() + 1);
|
||||
|
||||
memcpy(data_ptr, "US", 2);
|
||||
data_ptr += 3;
|
||||
memcpy(data_pointer, "EN", 2);
|
||||
data_pointer += 3;
|
||||
|
||||
memcpy(data_pointer, "US", 2);
|
||||
data_pointer += 3;
|
||||
|
||||
// 0 = Up, 1 = Down, 2 = Up, 3 = down, 4 = locked, 5 = locked(down)
|
||||
if((*iter)->GetStatus() < 0)
|
||||
{
|
||||
if((*iter)->GetZonesBooted() == 0)
|
||||
{
|
||||
*(uint32*)data_ptr = 0x01;
|
||||
if ((*iter)->GetStatus() < 0) {
|
||||
if ((*iter)->GetZonesBooted() == 0) {
|
||||
*(uint32*)data_pointer = 0x01;
|
||||
}
|
||||
else
|
||||
{
|
||||
*(uint32*)data_ptr = 0x04;
|
||||
else {
|
||||
*(uint32*)data_pointer = 0x04;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
*(uint32*)data_ptr = 0x02;
|
||||
else {
|
||||
*(uint32*)data_pointer = 0x02;
|
||||
}
|
||||
data_ptr += 4;
|
||||
data_pointer += 4;
|
||||
|
||||
*(uint32*)data_ptr = (*iter)->GetPlayersOnline();
|
||||
data_ptr += 4;
|
||||
*(uint32*)data_pointer = (*iter)->GetPlayersOnline();
|
||||
data_pointer += 4;
|
||||
|
||||
++iter;
|
||||
}
|
||||
@ -270,10 +240,8 @@ void ServerManager::SendUserToWorldRequest(unsigned int server_id, unsigned int
|
||||
{
|
||||
list<WorldServer*>::iterator iter = world_servers.begin();
|
||||
bool found = false;
|
||||
while(iter != world_servers.end())
|
||||
{
|
||||
if((*iter)->GetRuntimeID() == server_id)
|
||||
{
|
||||
while (iter != world_servers.end()) {
|
||||
if ((*iter)->GetRuntimeID() == server_id) {
|
||||
ServerPacket *outapp = new ServerPacket(ServerOP_UsertoWorldReq, sizeof(UsertoWorldRequest_Struct));
|
||||
UsertoWorldRequest_Struct *utwr = (UsertoWorldRequest_Struct*)outapp->pBuffer;
|
||||
utwr->worldid = server_id;
|
||||
@ -281,8 +249,7 @@ void ServerManager::SendUserToWorldRequest(unsigned int server_id, unsigned int
|
||||
(*iter)->GetConnection()->SendPacket(outapp);
|
||||
found = true;
|
||||
|
||||
if(server.options.IsDumpInPacketsOn())
|
||||
{
|
||||
if (server.options.IsDumpInPacketsOn()) {
|
||||
DumpPacket(outapp);
|
||||
}
|
||||
delete outapp;
|
||||
@ -290,8 +257,7 @@ void ServerManager::SendUserToWorldRequest(unsigned int server_id, unsigned int
|
||||
++iter;
|
||||
}
|
||||
|
||||
if(!found && server.options.IsTraceOn())
|
||||
{
|
||||
if (!found && server.options.IsTraceOn()) {
|
||||
server_log->Log(log_client_error, "Client requested a user to world but supplied an invalid id of %u.", server_id);
|
||||
}
|
||||
}
|
||||
@ -299,16 +265,13 @@ void ServerManager::SendUserToWorldRequest(unsigned int server_id, unsigned int
|
||||
bool ServerManager::ServerExists(string l_name, string s_name, WorldServer *ignore)
|
||||
{
|
||||
list<WorldServer*>::iterator iter = world_servers.begin();
|
||||
while(iter != world_servers.end())
|
||||
{
|
||||
if((*iter) == ignore)
|
||||
{
|
||||
while (iter != world_servers.end()) {
|
||||
if ((*iter) == ignore) {
|
||||
++iter;
|
||||
continue;
|
||||
}
|
||||
|
||||
if((*iter)->GetLongName().compare(l_name) == 0 && (*iter)->GetShortName().compare(s_name) == 0)
|
||||
{
|
||||
if ((*iter)->GetLongName().compare(l_name) == 0 && (*iter)->GetShortName().compare(s_name) == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -320,18 +283,14 @@ bool ServerManager::ServerExists(string l_name, string s_name, WorldServer *igno
|
||||
void ServerManager::DestroyServerByName(string l_name, string s_name, WorldServer *ignore)
|
||||
{
|
||||
list<WorldServer*>::iterator iter = world_servers.begin();
|
||||
while(iter != world_servers.end())
|
||||
{
|
||||
if((*iter) == ignore)
|
||||
{
|
||||
while (iter != world_servers.end()) {
|
||||
if ((*iter) == ignore) {
|
||||
++iter;
|
||||
}
|
||||
|
||||
if((*iter)->GetLongName().compare(l_name) == 0 && (*iter)->GetShortName().compare(s_name) == 0)
|
||||
{
|
||||
if ((*iter)->GetLongName().compare(l_name) == 0 && (*iter)->GetShortName().compare(s_name) == 0) {
|
||||
EmuTCPConnection *c = (*iter)->GetConnection();
|
||||
if(c->Connected())
|
||||
{
|
||||
if (c->Connected()) {
|
||||
c->Disconnect();
|
||||
}
|
||||
c->Free();
|
||||
@ -342,4 +301,3 @@ void ServerManager::DestroyServerByName(string l_name, string s_name, WorldServe
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user