- Add Zone Process ID (OS PID) as information passed back to world, ultimately with the ability to display it in the telnet console under 'zonestatus'

- Refactored some zoneserver/worldserver code for readability
This commit is contained in:
Akkadius
2015-10-31 20:19:57 -05:00
parent ab3e31154c
commit 33917fe2a9
18 changed files with 216 additions and 160 deletions
+44 -36
View File
@@ -49,20 +49,24 @@ extern QueryServConnection QSLink;
void CatchSignal(int sig_num);
ZoneServer::ZoneServer(EmuTCPConnection* itcpc)
: WorldTCPConnection(), tcpc(itcpc), ls_zboot(5000) {
ID = zoneserver_list.GetNextID();
: WorldTCPConnection(), tcpc(itcpc), zone_boot_timer(5000) {
/* Set Process tracking variable defaults */
memset(zone_name, 0, sizeof(zone_name));
memset(compiled, 0, sizeof(compiled));
zoneID = 0;
instanceID = 0;
memset(client_address, 0, sizeof(client_address));
memset(client_local_address, 0, sizeof(client_local_address));
memset(clientaddress, 0, sizeof(clientaddress));
memset(clientlocaladdress, 0, sizeof(clientlocaladdress));
clientport = 0;
BootingUp = false;
authenticated = false;
staticzone = false;
pNumPlayers = 0;
zone_server_id = zoneserver_list.GetNextID();
zone_server_zone_id = 0;
instance_id = 0;
zone_os_process_id = 0;
client_port = 0;
is_booting_up = false;
is_authenticated = false;
is_static_zone = false;
zone_player_count = 0;
}
ZoneServer::~ZoneServer() {
@@ -72,7 +76,7 @@ ZoneServer::~ZoneServer() {
}
bool ZoneServer::SetZone(uint32 iZoneID, uint32 iInstanceID, bool iStaticZone) {
BootingUp = false;
is_booting_up = false;
const char* zn = MakeLowerString(database.GetZoneName(iZoneID));
char* longname;
@@ -81,17 +85,17 @@ bool ZoneServer::SetZone(uint32 iZoneID, uint32 iInstanceID, bool iStaticZone) {
Log.Out(Logs::Detail, Logs::World_Server,"Setting to '%s' (%d:%d)%s",(zn) ? zn : "",iZoneID, iInstanceID,
iStaticZone ? " (Static)" : "");
zoneID = iZoneID;
instanceID = iInstanceID;
zone_server_zone_id = iZoneID;
instance_id = iInstanceID;
if(iZoneID!=0)
oldZoneID = iZoneID;
if (zoneID == 0) {
zone_server_previous_zone_id = iZoneID;
if (zone_server_zone_id == 0) {
client_list.CLERemoveZSRef(this);
pNumPlayers = 0;
zone_player_count = 0;
LSSleepUpdate(GetPrevZoneID());
}
staticzone = iStaticZone;
is_static_zone = iStaticZone;
if (zn)
{
@@ -111,7 +115,7 @@ bool ZoneServer::SetZone(uint32 iZoneID, uint32 iInstanceID, bool iStaticZone) {
}
client_list.ZoneBootup(this);
ls_zboot.Start();
zone_boot_timer.Start();
return true;
}
@@ -172,19 +176,19 @@ void ZoneServer::LSSleepUpdate(uint32 zoneid){
bool ZoneServer::Process() {
if (!tcpc->Connected())
return false;
if(ls_zboot.Check()){
if(zone_boot_timer.Check()){
LSBootUpdate(GetZoneID(), true);
ls_zboot.Disable();
zone_boot_timer.Disable();
}
ServerPacket *pack = 0;
while((pack = tcpc->PopPacket())) {
if (!authenticated) {
if (!is_authenticated) {
if (WorldConfig::get()->SharedKey.length() > 0) {
if (pack->opcode == ServerOP_ZAAuth && pack->size == 16) {
uint8 tmppass[16];
MD5::Generate((const uchar*) WorldConfig::get()->SharedKey.c_str(), WorldConfig::get()->SharedKey.length(), tmppass);
if (memcmp(pack->pBuffer, tmppass, 16) == 0)
authenticated = true;
is_authenticated = true;
else {
struct in_addr in;
in.s_addr = GetIP();
@@ -210,7 +214,7 @@ bool ZoneServer::Process() {
else
{
Log.Out(Logs::Detail, Logs::World_Server,"**WARNING** You have not configured a world shared key in your config file. You should add a <key>STRING</key> element to your <world> element to prevent unauthroized zone access.");
authenticated = true;
is_authenticated = true;
}
}
switch(pack->opcode) {
@@ -582,29 +586,33 @@ bool ZoneServer::Process() {
ServerConnectInfo* sci = (ServerConnectInfo*) pack->pBuffer;
if (!sci->port) {
clientport = zoneserver_list.GetAvailableZonePort();
client_port = zoneserver_list.GetAvailableZonePort();
ServerPacket p(ServerOP_SetConnectInfo, sizeof(ServerConnectInfo));
memset(p.pBuffer,0,sizeof(ServerConnectInfo));
ServerConnectInfo* sci = (ServerConnectInfo*) p.pBuffer;
sci->port = clientport;
sci->port = client_port;
SendPacket(&p);
Log.Out(Logs::Detail, Logs::World_Server,"Auto zone port configuration. Telling zone to use port %d",clientport);
Log.Out(Logs::Detail, Logs::World_Server,"Auto zone port configuration. Telling zone to use port %d",client_port);
} else {
clientport = sci->port;
Log.Out(Logs::Detail, Logs::World_Server,"Zone specified port %d.",clientport);
client_port = sci->port;
Log.Out(Logs::Detail, Logs::World_Server,"Zone specified port %d.",client_port);
}
if(sci->address[0]) {
strn0cpy(clientaddress, sci->address, 250);
strn0cpy(client_address, sci->address, 250);
Log.Out(Logs::Detail, Logs::World_Server, "Zone specified address %s.", sci->address);
}
if(sci->local_address[0]) {
strn0cpy(clientlocaladdress, sci->local_address, 250);
strn0cpy(client_local_address, sci->local_address, 250);
Log.Out(Logs::Detail, Logs::World_Server, "Zone specified local address %s.", sci->address);
}
if (sci->process_id){
zone_os_process_id = sci->process_id;
}
}
case ServerOP_SetLaunchName: {
if(pack->size != sizeof(LaunchName_Struct))
@@ -1411,13 +1419,13 @@ void ZoneServer::ChangeWID(uint32 iCharID, uint32 iWID) {
void ZoneServer::TriggerBootup(uint32 iZoneID, uint32 iInstanceID, const char* adminname, bool iMakeStatic) {
BootingUp = true;
zoneID = iZoneID;
instanceID = iInstanceID;
is_booting_up = true;
zone_server_zone_id = iZoneID;
instance_id = iInstanceID;
auto pack = new ServerPacket(ServerOP_ZoneBootup, sizeof(ServerZoneStateChange_struct));
ServerZoneStateChange_struct* s = (ServerZoneStateChange_struct *) pack->pBuffer;
s->ZoneServerID = ID;
s->ZoneServerID = zone_server_id;
if (adminname != 0)
strcpy(s->adminname, adminname);
@@ -1434,7 +1442,7 @@ void ZoneServer::TriggerBootup(uint32 iZoneID, uint32 iInstanceID, const char* a
}
void ZoneServer::IncomingClient(Client* client) {
BootingUp = true;
is_booting_up = true;
auto pack = new ServerPacket(ServerOP_ZoneIncClient, sizeof(ServerZoneIncomingClient_Struct));
ServerZoneIncomingClient_Struct* s = (ServerZoneIncomingClient_Struct*) pack->pBuffer;
s->zoneid = GetZoneID();