mirror of
https://github.com/EQEmu/Server.git
synced 2026-06-17 14:58:21 +00:00
Tons of cleanup / formatting
This commit is contained in:
@@ -1,20 +1,23 @@
|
||||
/* EQEMu: Everquest Server Emulator
|
||||
Copyright (C) 2001-2010 EQEMu Development Team (http://eqemulator.net)
|
||||
/**
|
||||
* EQEmulator: Everquest Server Emulator
|
||||
* Copyright (C) 2001-2019 EQEmulator Development Team (https://github.com/EQEmu/Server)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; version 2 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY except by those people which sell it, which
|
||||
* are required to give you total support for your newly bought product;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; version 2 of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY except by those people which sell it, which
|
||||
are required to give you total support for your newly bought product;
|
||||
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "server_manager.h"
|
||||
#include "login_server.h"
|
||||
#include "login_structures.h"
|
||||
@@ -24,7 +27,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#include "../common/eqemu_logsys_fmt.h"
|
||||
|
||||
extern LoginServer server;
|
||||
extern bool run_server;
|
||||
extern bool run_server;
|
||||
|
||||
ServerManager::ServerManager()
|
||||
{
|
||||
@@ -36,38 +39,52 @@ ServerManager::ServerManager()
|
||||
opts.ipv6 = false;
|
||||
server_connection->Listen(opts);
|
||||
|
||||
server_connection->OnConnectionIdentified("World", [this](std::shared_ptr<EQ::Net::ServertalkServerConnection> c) {
|
||||
LogF(Logs::General, Logs::Login_Server, "New world server connection from {0}:{1}", c->Handle()->RemoteIP(), c->Handle()->RemotePort());
|
||||
server_connection->OnConnectionIdentified(
|
||||
"World", [this](std::shared_ptr<EQ::Net::ServertalkServerConnection> c) {
|
||||
LogF(Logs::General,
|
||||
Logs::Login_Server,
|
||||
"New world server connection from {0}:{1}",
|
||||
c->Handle()->RemoteIP(),
|
||||
c->Handle()->RemotePort());
|
||||
|
||||
auto iter = world_servers.begin();
|
||||
while (iter != world_servers.end()) {
|
||||
if ((*iter)->GetConnection()->Handle()->RemoteIP().compare(c->Handle()->RemoteIP()) == 0 &&
|
||||
(*iter)->GetConnection()->Handle()->RemotePort() == c->Handle()->RemotePort()) {
|
||||
LogF(Logs::General, Logs::Login_Server, "World server already existed for {0}:{1}, removing existing connection.",
|
||||
c->Handle()->RemoteIP(), c->Handle()->RemotePort());
|
||||
auto iter = world_servers.begin();
|
||||
while (iter != world_servers.end()) {
|
||||
if ((*iter)->GetConnection()->Handle()->RemoteIP().compare(c->Handle()->RemoteIP()) == 0 &&
|
||||
(*iter)->GetConnection()->Handle()->RemotePort() == c->Handle()->RemotePort()) {
|
||||
LogF(Logs::General,
|
||||
Logs::Login_Server,
|
||||
"World server already existed for {0}:{1}, removing existing connection.",
|
||||
c->Handle()->RemoteIP(),
|
||||
c->Handle()->RemotePort());
|
||||
|
||||
world_servers.erase(iter);
|
||||
break;
|
||||
world_servers.erase(iter);
|
||||
break;
|
||||
}
|
||||
|
||||
++iter;
|
||||
}
|
||||
|
||||
++iter;
|
||||
world_servers.push_back(std::unique_ptr<WorldServer>(new WorldServer(c)));
|
||||
}
|
||||
);
|
||||
|
||||
world_servers.push_back(std::unique_ptr<WorldServer>(new WorldServer(c)));
|
||||
});
|
||||
server_connection->OnConnectionRemoved(
|
||||
"World", [this](std::shared_ptr<EQ::Net::ServertalkServerConnection> c) {
|
||||
auto iter = world_servers.begin();
|
||||
while (iter != world_servers.end()) {
|
||||
if ((*iter)->GetConnection()->GetUUID() == c->GetUUID()) {
|
||||
LogF(Logs::General,
|
||||
Logs::World_Server,
|
||||
"World server {0} has been disconnected, removing.",
|
||||
(*iter)->GetLongName().c_str());
|
||||
world_servers.erase(iter);
|
||||
return;
|
||||
}
|
||||
|
||||
server_connection->OnConnectionRemoved("World", [this](std::shared_ptr<EQ::Net::ServertalkServerConnection> c) {
|
||||
auto iter = world_servers.begin();
|
||||
while (iter != world_servers.end()) {
|
||||
if ((*iter)->GetConnection()->GetUUID() == c->GetUUID()) {
|
||||
LogF(Logs::General, Logs::World_Server, "World server {0} has been disconnected, removing.", (*iter)->GetLongName().c_str());
|
||||
world_servers.erase(iter);
|
||||
return;
|
||||
++iter;
|
||||
}
|
||||
|
||||
++iter;
|
||||
}
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
ServerManager::~ServerManager()
|
||||
@@ -75,11 +92,12 @@ ServerManager::~ServerManager()
|
||||
|
||||
}
|
||||
|
||||
WorldServer* ServerManager::GetServerByAddress(const std::string &addr, int port)
|
||||
WorldServer *ServerManager::GetServerByAddress(const std::string &addr, int port)
|
||||
{
|
||||
auto iter = world_servers.begin();
|
||||
while (iter != world_servers.end()) {
|
||||
if ((*iter)->GetConnection()->Handle()->RemoteIP() == addr && (*iter)->GetConnection()->Handle()->RemotePort()) {
|
||||
if ((*iter)->GetConnection()->Handle()->RemoteIP() == addr &&
|
||||
(*iter)->GetConnection()->Handle()->RemotePort()) {
|
||||
return (*iter).get();
|
||||
}
|
||||
++iter;
|
||||
@@ -90,9 +108,9 @@ WorldServer* ServerManager::GetServerByAddress(const std::string &addr, int port
|
||||
|
||||
EQApplicationPacket *ServerManager::CreateServerListPacket(Client *c, uint32 seq)
|
||||
{
|
||||
unsigned int packet_size = sizeof(ServerListHeader_Struct);
|
||||
unsigned int packet_size = sizeof(ServerListHeader_Struct);
|
||||
unsigned int server_count = 0;
|
||||
in_addr in;
|
||||
in_addr in;
|
||||
in.s_addr = c->GetConnection()->GetRemoteIP();
|
||||
std::string client_ip = inet_ntoa(in);
|
||||
|
||||
@@ -119,8 +137,8 @@ EQApplicationPacket *ServerManager::CreateServerListPacket(Client *c, uint32 seq
|
||||
++iter;
|
||||
}
|
||||
|
||||
EQApplicationPacket *outapp = new EQApplicationPacket(OP_ServerListResponse, packet_size);
|
||||
ServerListHeader_Struct *server_list = (ServerListHeader_Struct*)outapp->pBuffer;
|
||||
EQApplicationPacket *outapp = new EQApplicationPacket(OP_ServerListResponse, packet_size);
|
||||
ServerListHeader_Struct *server_list = (ServerListHeader_Struct *) outapp->pBuffer;
|
||||
server_list->Unknown1 = seq;
|
||||
server_list->Unknown2 = 0x00000000;
|
||||
server_list->Unknown3 = 0x01650000;
|
||||
@@ -129,7 +147,7 @@ EQApplicationPacket *ServerManager::CreateServerListPacket(Client *c, uint32 seq
|
||||
* Not sure what this is but it should be noted setting it to
|
||||
* 0xFFFFFFFF crashes the client so: don't do that.
|
||||
*/
|
||||
server_list->Unknown4 = 0x00000000;
|
||||
server_list->Unknown4 = 0x00000000;
|
||||
server_list->NumberOfServers = server_count;
|
||||
|
||||
unsigned char *data_pointer = outapp->pBuffer;
|
||||
@@ -157,22 +175,22 @@ EQApplicationPacket *ServerManager::CreateServerListPacket(Client *c, uint32 seq
|
||||
}
|
||||
|
||||
switch ((*iter)->GetServerListID()) {
|
||||
case 1: {
|
||||
*(unsigned int*)data_pointer = 0x00000030;
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
*(unsigned int*)data_pointer = 0x00000009;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
*(unsigned int*)data_pointer = 0x00000001;
|
||||
}
|
||||
case 1: {
|
||||
*(unsigned int *) data_pointer = 0x00000030;
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
*(unsigned int *) data_pointer = 0x00000009;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
*(unsigned int *) data_pointer = 0x00000001;
|
||||
}
|
||||
}
|
||||
|
||||
data_pointer += 4;
|
||||
|
||||
*(unsigned int*)data_pointer = (*iter)->GetRuntimeID();
|
||||
*(unsigned int *) data_pointer = (*iter)->GetRuntimeID();
|
||||
data_pointer += 4;
|
||||
|
||||
memcpy(data_pointer, (*iter)->GetLongName().c_str(), (*iter)->GetLongName().size());
|
||||
@@ -187,18 +205,18 @@ EQApplicationPacket *ServerManager::CreateServerListPacket(Client *c, uint32 seq
|
||||
// 0 = Up, 1 = Down, 2 = Up, 3 = down, 4 = locked, 5 = locked(down)
|
||||
if ((*iter)->GetStatus() < 0) {
|
||||
if ((*iter)->GetZonesBooted() == 0) {
|
||||
*(uint32*)data_pointer = 0x01;
|
||||
*(uint32 *) data_pointer = 0x01;
|
||||
}
|
||||
else {
|
||||
*(uint32*)data_pointer = 0x04;
|
||||
*(uint32 *) data_pointer = 0x04;
|
||||
}
|
||||
}
|
||||
else {
|
||||
*(uint32*)data_pointer = 0x02;
|
||||
*(uint32 *) data_pointer = 0x02;
|
||||
}
|
||||
data_pointer += 4;
|
||||
|
||||
*(uint32*)data_pointer = (*iter)->GetPlayersOnline();
|
||||
*(uint32 *) data_pointer = (*iter)->GetPlayersOnline();
|
||||
data_pointer += 4;
|
||||
|
||||
++iter;
|
||||
@@ -207,16 +225,20 @@ EQApplicationPacket *ServerManager::CreateServerListPacket(Client *c, uint32 seq
|
||||
return outapp;
|
||||
}
|
||||
|
||||
void ServerManager::SendUserToWorldRequest(unsigned int server_id, unsigned int client_account_id, const std::string &client_loginserver)
|
||||
void ServerManager::SendUserToWorldRequest(
|
||||
unsigned int server_id,
|
||||
unsigned int client_account_id,
|
||||
const std::string &client_loginserver
|
||||
)
|
||||
{
|
||||
auto iter = world_servers.begin();
|
||||
auto iter = world_servers.begin();
|
||||
bool found = false;
|
||||
while (iter != world_servers.end()) {
|
||||
if ((*iter)->GetRuntimeID() == server_id) {
|
||||
EQ::Net::DynamicPacket outapp;
|
||||
outapp.Resize(sizeof(UsertoWorldRequest_Struct));
|
||||
UsertoWorldRequest_Struct *utwr = (UsertoWorldRequest_Struct*)outapp.Data();
|
||||
utwr->worldid = server_id;
|
||||
UsertoWorldRequest_Struct *utwr = (UsertoWorldRequest_Struct *) outapp.Data();
|
||||
utwr->worldid = server_id;
|
||||
utwr->lsaccountid = client_account_id;
|
||||
strncpy(utwr->login, &client_loginserver[0], 64);
|
||||
(*iter)->GetConnection()->Send(ServerOP_UsertoWorldReq, outapp);
|
||||
@@ -230,7 +252,10 @@ void ServerManager::SendUserToWorldRequest(unsigned int server_id, unsigned int
|
||||
}
|
||||
|
||||
if (!found && server.options.IsTraceOn()) {
|
||||
Log(Logs::General, Logs::Error, "Client requested a user to world but supplied an invalid id of %u.", server_id);
|
||||
Log(Logs::General,
|
||||
Logs::Error,
|
||||
"Client requested a user to world but supplied an invalid id of %u.",
|
||||
server_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user