Skip to content

Commit

Permalink
zoneserver clean up and formatting.
Browse files Browse the repository at this point in the history
loginserver world_server clean up.
Add some pointer safety checks to underlying data service call
  • Loading branch information
regneq committed Dec 11, 2024
1 parent f828def commit b350a7b
Show file tree
Hide file tree
Showing 9 changed files with 1,143 additions and 1,209 deletions.
78 changes: 50 additions & 28 deletions loginserver/server_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,39 +36,61 @@ ServerManager::ServerManager()
opts.port = listen_port;
opts.ipv6 = false;
m_server_connection->Listen(opts);
m_server_connection->OnConnectionIdentified("World", [this](std::shared_ptr<EQ::Net::ServertalkServerConnection> c) {
LogInfo("New world server connection from {0}:{1}", c->Handle()->RemoteIP(), c->Handle()->RemotePort());

WorldServer* server_entity = GetServerByAddress(c->Handle()->RemoteIP(), c->Handle()->RemotePort());
if (server_entity) {
LogInfo("Loginserver now listening on port [{0}]", listen_port);

LogInfo("World server already existed for {0}:{1}, removing existing connection and updating current.",
c->Handle()->RemoteIP(), c->Handle()->RemotePort());
server_entity->SetConnection(c);
server_entity->Reset();
}
else {
m_world_servers.push_back(std::unique_ptr<WorldServer>(new WorldServer(c)));
}

});
m_server_connection->OnConnectionIdentified(
"World", [this](std::shared_ptr<EQ::Net::ServertalkServerConnection> world_connection) {
LogInfo(
"New World Server connection from {0}:{1}",
world_connection->Handle()->RemoteIP(),
world_connection->Handle()->RemotePort()
);

auto iter = m_world_servers.begin();
while (iter != m_world_servers.end()) {
if ((*iter)->GetConnection()->Handle()->RemoteIP().compare(world_connection->Handle()->RemoteIP()) ==
0 &&
(*iter)->GetConnection()->Handle()->RemotePort() == world_connection->Handle()->RemotePort()) {

LogInfo(
"World server already existed for {0}:{1}, removing existing connection.",
world_connection->Handle()->RemoteIP(),
world_connection->Handle()->RemotePort()
);

m_world_servers.erase(iter);
break;
}

++iter;
}

m_server_connection->OnConnectionRemoved("World", [this](std::shared_ptr<EQ::Net::ServertalkServerConnection> c) {
auto iter = m_world_servers.begin();
while (iter != m_world_servers.end()) {
if ((*iter)->GetConnection()->Handle() == c->Handle()) {
LogInfo("World server {0} has been disconnected, removing.", (*iter)->GetServerLongName().c_str());
m_world_servers.erase(iter);
return;
m_world_servers.push_back(std::make_unique<WorldServer>(world_connection));
}
);

m_server_connection->OnConnectionRemoved(
"World", [this](std::shared_ptr<EQ::Net::ServertalkServerConnection> c) {
auto iter = m_world_servers.begin();
while (iter != m_world_servers.end()) {
if ((*iter)->GetConnection()->GetUUID() == c->GetUUID()) {
LogInfo(
"World server {0} has been disconnected, removing.",
(*iter)->GetServerLongName()
);
m_world_servers.erase(iter);
return;
}

++iter;
}
}
});
);
}

ServerManager::~ServerManager()
{
ServerManager::~ServerManager() = default;

}

WorldServer* ServerManager::GetServerByAddress(const std::string& addr, int port)
{
Expand Down Expand Up @@ -163,11 +185,11 @@ EQApplicationPacket* ServerManager::CreateOldServerListPacket(Client* c)

ServerListServerFlags_Struct* slsf = (ServerListServerFlags_Struct*)data_ptr;
slsf->greenname = 0;
if (server.db->GetWorldPreferredStatus((*iter)->GetRuntimeID())) {
if (server.db->GetWorldPreferredStatus((*iter)->GetServerId())) {
slsf->greenname = 1;
}
slsf->flags = 0x1;
slsf->worldid = (*iter)->GetRuntimeID();
slsf->worldid = (*iter)->GetServerId();
slsf->usercount = (*iter)->GetStatus();
data_ptr += sizeof(ServerListServerFlags_Struct);
++iter;
Expand All @@ -188,7 +210,7 @@ void ServerManager::SendOldUserToWorldRequest(const char* server_id, unsigned in
UsertoWorldRequest_Struct* r = (UsertoWorldRequest_Struct*)outapp.Data();

//utwr->worldid = (*iter)->GetServerListID(); //This pulls preffered status instead of actual ID? That does not seem right.
r->worldid = (*iter)->GetRuntimeID();
r->worldid = (*iter)->GetServerId();

r->lsaccountid = client_account_id;
r->ip = ip;
Expand Down
16 changes: 8 additions & 8 deletions loginserver/world_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ WorldServer::WorldServer(std::shared_ptr<EQ::Net::ServertalkServerConnection> c)
m_zones_booted = 0;
m_players_online = 0;
m_server_status = 0;
m_runtime_id = 0;
m_server_id = 0;
m_server_list_type_id = 0;
m_server_process_type = 0;
m_is_server_authorized = false;
Expand All @@ -53,7 +53,7 @@ void WorldServer::Reset()
m_zones_booted = 0;
m_players_online = 0;
m_server_status = 0;
m_runtime_id;
m_server_id;
m_server_list_type_id = 0;
m_server_process_type = 0;
m_is_server_authorized = false;
Expand Down Expand Up @@ -343,15 +343,15 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
LogInfo("Server [{0}]([{1}]) successfully logged into account that had no user/password requirement.",
m_long_name.c_str(), m_short_name.c_str());
m_is_server_authorized = true;
SetRuntimeID(s_id);
SetServerId(s_id);
m_server_list_type_id = s_list_type;
m_server_description = s_desc;
}
else if(s_acct_name.compare(m_account_name) == 0 && s_acct_pass.compare(m_account_password) == 0) {
LogInfo("Server [{0}]({1}) successfully logged in.",
m_long_name.c_str(), m_short_name.c_str());
m_is_server_authorized = true;
SetRuntimeID(s_id);
SetServerId(s_id);
m_server_list_type_id = s_list_type;
m_server_description = s_desc;
if(s_trusted) {
Expand Down Expand Up @@ -406,7 +406,7 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
if(server_account_name.compare(m_account_name) == 0 && server_account_password.compare(m_account_password) == 0) {
LogInfo("Server [{0}]([{1}]) successfully logged in.", m_long_name.c_str(), m_short_name.c_str());
m_is_server_authorized = true;
SetRuntimeID(server_id);
SetServerId(server_id);
m_server_list_type_id = server_list_type;
m_server_description = server_description;

Expand Down Expand Up @@ -434,7 +434,7 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
LogInfo("Server [{0}]([{1}]) did not attempt to log in but unregistered servers are allowed.",
m_long_name.c_str(), m_short_name.c_str());
m_is_server_authorized = true;
SetRuntimeID(server_id);
SetServerId(server_id);
m_server_list_type_id = 0;
}
}
Expand All @@ -444,13 +444,13 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
m_long_name.c_str(), m_short_name.c_str());
if(server.db->CreateWorldRegistration(m_long_name, m_short_name, server_id)) {
m_is_server_authorized = true;
SetRuntimeID(server_id);
SetServerId(server_id);
m_server_list_type_id = 0;
}
}
}

server.db->UpdateWorldRegistration(GetRuntimeID(), m_long_name, GetConnection()->Handle()->RemoteIP());
server.db->UpdateWorldRegistration(GetServerId(), m_long_name, GetConnection()->Handle()->RemoteIP());

if (m_is_server_authorized)
{
Expand Down
25 changes: 10 additions & 15 deletions loginserver/world_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,15 @@ class WorldServer
void SetConnection(std::shared_ptr<EQ::Net::ServertalkServerConnection> c) { m_connection = c; }

/**
* Gets the runtime id of this server.
*/
unsigned int GetRuntimeID() const { return m_runtime_id; }
* @return
*/
unsigned int GetServerId() const { return m_server_id; }
void SetServerId(unsigned int id) { m_server_id = id; }

/**
* Sets the runtime id of this server.
*/
void SetRuntimeID(unsigned int id) { m_runtime_id = id; }

/**
* Gets the long name of the server.
*/
* @return
*/
std::string GetServerLongName() const { return m_long_name; }

/**
* Gets the short name of the server.
*/
std::string GetServerShortName() const { return m_short_name; }

/**
Expand All @@ -95,6 +87,7 @@ class WorldServer
* Gets what kind of server this server is (legends, preferred, normal)
*/
unsigned int GetServerListID() const { return m_server_list_type_id; }
WorldServer* SetServerListTypeId(unsigned int in_server_list_id);

/**
* Gets the status of the server.
Expand All @@ -121,11 +114,13 @@ class WorldServer
*/
void Handle_LSStatus(ServerLSStatus_Struct *server_login_status);

\
/**
* Informs world that there is a client incoming with the following data.
*/
void SendClientAuth(std::string ip, std::string account, std::string key, unsigned int account_id, uint8 version = 0);


private:
/**
* Packet processing functions:
Expand All @@ -140,7 +135,7 @@ class WorldServer
unsigned int m_zones_booted;
unsigned int m_players_online;
int m_server_status;
unsigned int m_runtime_id;
unsigned int m_server_id;
unsigned int m_server_list_type_id;
unsigned int m_server_process_type;
std::string m_server_description;
Expand Down
21 changes: 6 additions & 15 deletions world/cliententry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,6 @@ void ClientListEntry::SetChar(uint32 iCharID, const char* iCharName)
strn0cpy(pname, iCharName, sizeof(pname));
}

void ClientListEntry::SetOnline(ZoneServer* iZS, CLE_Status iOnline)
{
if (iZS == this->Server()) {
SetOnline(iOnline);
}
}

void ClientListEntry::SetOnline(CLE_Status iOnline)
{
LogClientLogin(
Expand All @@ -135,19 +128,17 @@ void ClientListEntry::SetOnline(CLE_Status iOnline)
else if (iOnline < CLE_Status::Online && pOnline >= CLE_Status::Online) {
numplayers--;
}

if (pOnline >= CLE_Status::Zoning && iOnline < CLE_Status::Zoning) {
if (iOnline != CLE_Status::Online || pOnline < CLE_Status::Online) {
pOnline = iOnline;
Camp();
}

if (iOnline != CLE_Status::Online || pOnline < CLE_Status::Online) {
pOnline = iOnline;
if (iOnline < CLE_Status::Zoning) {
Camp();
}

if (pOnline >= CLE_Status::Online)
if (pOnline >= CLE_Status::Online) {
stale = 0;
}
}

void ClientListEntry::LSUpdate(ZoneServer* iZS)
{
if(WorldConfig::get()->UpdateStats){
Expand Down
1 change: 0 additions & 1 deletion world/cliententry.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class ClientListEntry {
bool CheckAuth(uint32 loginserver_account_id, const char* key_password);
bool CheckAuth(const char* iName, const MD5& iMD5Password);
bool CheckAuth(uint32 id, const char* key, uint32 ip);
void SetOnline(ZoneServer* iZS, CLE_Status iOnline);
void SetOnline(CLE_Status iOnline = CLE_Status::Online);
void SetChar(uint32 iCharID, const char* iCharName);
inline CLE_Status Online() { return pOnline; }
Expand Down
4 changes: 4 additions & 0 deletions world/eqemu_api_world_data_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ void callGetZoneList(Json::Value &response)
for (auto &zone: zoneserver_list.getZoneServerList()) {
Json::Value row;

if (!zone->IsConnected()) {
continue;
}

row["booting_up"] = zone->IsBootingUp();
row["client_address"] = zone->GetCAddress();
row["client_local_address"] = zone->GetCLocalAddress();
Expand Down
Loading

0 comments on commit b350a7b

Please sign in to comment.