Refactor zone net class (nothing to do with networking -.-)

This commit is contained in:
KimLS 2019-09-27 14:42:35 -07:00
parent 316d645f33
commit 259bce9509
10 changed files with 52 additions and 156 deletions

View File

@ -42,7 +42,6 @@ SET(world_headers
lfplist.h lfplist.h
login_server.h login_server.h
login_server_list.h login_server_list.h
net.h
queryserv.h queryserv.h
sof_char_create_data.h sof_char_create_data.h
ucs.h ucs.h

View File

@ -79,6 +79,7 @@ SET(zone_sources
horse.cpp horse.cpp
inventory.cpp inventory.cpp
loottables.cpp loottables.cpp
main.cpp
map.cpp map.cpp
merc.cpp merc.cpp
mob.cpp mob.cpp
@ -87,7 +88,6 @@ SET(zone_sources
mob_movement_manager.cpp mob_movement_manager.cpp
mob_info.cpp mob_info.cpp
mod_functions.cpp mod_functions.cpp
net.cpp
npc.cpp npc.cpp
npc_ai.cpp npc_ai.cpp
npc_scale_manager.cpp npc_scale_manager.cpp
@ -210,7 +210,6 @@ SET(zone_headers
merc.h merc.h
mob.h mob.h
mob_movement_manager.h mob_movement_manager.h
net.h
npc.h npc.h
npc_ai.h npc_ai.h
npc_scale_manager.h npc_scale_manager.h

View File

@ -41,7 +41,6 @@ extern volatile bool RunLoops;
#include "../common/profanity_manager.h" #include "../common/profanity_manager.h"
#include "data_bucket.h" #include "data_bucket.h"
#include "position.h" #include "position.h"
#include "net.h"
#include "worldserver.h" #include "worldserver.h"
#include "zonedb.h" #include "zonedb.h"
#include "petitions.h" #include "petitions.h"
@ -67,6 +66,8 @@ extern PetitionList petition_list;
bool commandlogged; bool commandlogged;
char entirecommand[255]; char entirecommand[255];
void UpdateWindowTitle(char* iNewTitle);
Client::Client(EQStreamInterface* ieqs) Client::Client(EQStreamInterface* ieqs)
: Mob("No name", // name : Mob("No name", // name
"", // lastname "", // lastname
@ -244,7 +245,7 @@ Client::Client(EQStreamInterface* ieqs)
PendingRezzSpellID = 0; PendingRezzSpellID = 0;
numclients++; numclients++;
// emuerror; // emuerror;
UpdateWindowTitle(); UpdateWindowTitle(nullptr);
horseId = 0; horseId = 0;
tgb = false; tgb = false;
tribute_master_id = 0xFFFFFFFF; tribute_master_id = 0xFFFFFFFF;
@ -449,7 +450,7 @@ Client::~Client() {
ClearRespawnOptions(); ClearRespawnOptions();
numclients--; numclients--;
UpdateWindowTitle(); UpdateWindowTitle(nullptr);
if(zone) if(zone)
zone->RemoveAuth(GetName(), lskey); zone->RemoveAuth(GetName(), lskey);

View File

@ -33,7 +33,6 @@
#include "../common/guilds.h" #include "../common/guilds.h"
#include "guild_mgr.h" #include "guild_mgr.h"
#include "net.h"
#include "petitions.h" #include "petitions.h"
#include "quest_parser_collection.h" #include "quest_parser_collection.h"
#include "raids.h" #include "raids.h"
@ -56,7 +55,6 @@
extern Zone *zone; extern Zone *zone;
extern volatile bool is_zone_loaded; extern volatile bool is_zone_loaded;
extern WorldServer worldserver; extern WorldServer worldserver;
extern NetConnection net;
extern uint32 numclients; extern uint32 numclients;
extern PetitionList petition_list; extern PetitionList petition_list;
@ -300,6 +298,13 @@ const Bot *Entity::CastToBot() const
#endif #endif
EntityList::EntityList() EntityList::EntityList()
:
object_timer(5000),
door_timer(5000),
corpse_timer(2000),
group_timer(1000),
raid_timer(1000),
trap_timer(1000)
{ {
// set up ids between 1 and 1500 // set up ids between 1 and 1500
// neither client or server performs well if you have // neither client or server performs well if you have
@ -349,7 +354,7 @@ void EntityList::TrapProcess()
return; return;
if (trap_list.empty()) { if (trap_list.empty()) {
net.trap_timer.Disable(); trap_timer.Disable();
return; return;
} }
@ -388,7 +393,7 @@ void EntityList::GroupProcess()
return; return;
if (group_list.empty()) { if (group_list.empty()) {
net.group_timer.Disable(); group_timer.Disable();
return; return;
} }
@ -412,7 +417,7 @@ void EntityList::RaidProcess()
return; return;
if (raid_list.empty()) { if (raid_list.empty()) {
net.raid_timer.Disable(); raid_timer.Disable();
return; return;
} }
@ -427,7 +432,7 @@ void EntityList::DoorProcess()
return; return;
#endif #endif
if (door_list.empty()) { if (door_list.empty()) {
net.door_timer.Disable(); door_timer.Disable();
return; return;
} }
@ -445,7 +450,7 @@ void EntityList::DoorProcess()
void EntityList::ObjectProcess() void EntityList::ObjectProcess()
{ {
if (object_list.empty()) { if (object_list.empty()) {
net.object_timer.Disable(); object_timer.Disable();
return; return;
} }
@ -464,7 +469,7 @@ void EntityList::ObjectProcess()
void EntityList::CorpseProcess() void EntityList::CorpseProcess()
{ {
if (corpse_list.empty()) { if (corpse_list.empty()) {
net.corpse_timer.Disable(); // No corpses in list corpse_timer.Disable(); // No corpses in list
return; return;
} }
@ -606,8 +611,8 @@ void EntityList::AddGroup(Group *group, uint32 gid)
{ {
group->SetID(gid); group->SetID(gid);
group_list.push_back(group); group_list.push_back(group);
if (!net.group_timer.Enabled()) if (!group_timer.Enabled())
net.group_timer.Start(); group_timer.Start();
#if EQDEBUG >= 5 #if EQDEBUG >= 5
CheckGroupList(__FILE__, __LINE__); CheckGroupList(__FILE__, __LINE__);
#endif #endif
@ -631,8 +636,8 @@ void EntityList::AddRaid(Raid *raid, uint32 gid)
{ {
raid->SetID(gid); raid->SetID(gid);
raid_list.push_back(raid); raid_list.push_back(raid);
if (!net.raid_timer.Enabled()) if (!raid_timer.Enabled())
net.raid_timer.Start(); raid_timer.Start();
} }
@ -649,8 +654,8 @@ void EntityList::AddCorpse(Corpse *corpse, uint32 in_id)
corpse->CalcCorpseName(); corpse->CalcCorpseName();
corpse_list.insert(std::pair<uint16, Corpse *>(corpse->GetID(), corpse)); corpse_list.insert(std::pair<uint16, Corpse *>(corpse->GetID(), corpse));
if (!net.corpse_timer.Enabled()) if (!corpse_timer.Enabled())
net.corpse_timer.Start(); corpse_timer.Start();
} }
void EntityList::AddNPC(NPC *npc, bool SendSpawnPacket, bool dontqueue) void EntityList::AddNPC(NPC *npc, bool SendSpawnPacket, bool dontqueue)
@ -752,8 +757,8 @@ void EntityList::AddObject(Object *obj, bool SendSpawnPacket)
object_list.insert(std::pair<uint16, Object *>(obj->GetID(), obj)); object_list.insert(std::pair<uint16, Object *>(obj->GetID(), obj));
if (!net.object_timer.Enabled()) if (!object_timer.Enabled())
net.object_timer.Start(); object_timer.Start();
} }
void EntityList::AddDoor(Doors *door) void EntityList::AddDoor(Doors *door)
@ -761,16 +766,16 @@ void EntityList::AddDoor(Doors *door)
door->SetEntityID(GetFreeID()); door->SetEntityID(GetFreeID());
door_list.insert(std::pair<uint16, Doors *>(door->GetEntityID(), door)); door_list.insert(std::pair<uint16, Doors *>(door->GetEntityID(), door));
if (!net.door_timer.Enabled()) if (!door_timer.Enabled())
net.door_timer.Start(); door_timer.Start();
} }
void EntityList::AddTrap(Trap *trap) void EntityList::AddTrap(Trap *trap)
{ {
trap->SetID(GetFreeID()); trap->SetID(GetFreeID());
trap_list.insert(std::pair<uint16, Trap *>(trap->GetID(), trap)); trap_list.insert(std::pair<uint16, Trap *>(trap->GetID(), trap));
if (!net.trap_timer.Enabled()) if (!trap_timer.Enabled())
net.trap_timer.Start(); trap_timer.Start();
} }
void EntityList::AddBeacon(Beacon *beacon) void EntityList::AddBeacon(Beacon *beacon)

View File

@ -538,6 +538,13 @@ private:
std::list<Area> area_list; std::list<Area> area_list;
std::queue<uint16> free_ids; std::queue<uint16> free_ids;
Timer object_timer;
Timer door_timer;
Timer corpse_timer;
Timer group_timer;
Timer raid_timer;
Timer trap_timer;
// Please Do Not Declare Any EntityList Class Members After This Comment // Please Do Not Declare Any EntityList Class Members After This Comment
#ifdef BOTS #ifdef BOTS
public: public:

View File

@ -47,7 +47,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "zone_config.h" #include "zone_config.h"
#include "masterentity.h" #include "masterentity.h"
#include "worldserver.h" #include "worldserver.h"
#include "net.h"
#include "zone.h" #include "zone.h"
#include "queryserv.h" #include "queryserv.h"
#include "command.h" #include "command.h"
@ -96,7 +95,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
volatile bool RunLoops = true; volatile bool RunLoops = true;
extern volatile bool is_zone_loaded; extern volatile bool is_zone_loaded;
NetConnection net;
EntityList entity_list; EntityList entity_list;
WorldServer worldserver; WorldServer worldserver;
uint32 numclients = 0; uint32 numclients = 0;
@ -115,6 +113,9 @@ const ZoneConfig *Config;
double frame_time = 0.0; double frame_time = 0.0;
void Shutdown(); void Shutdown();
void UpdateWindowTitle(char* iNewTitle);
void CatchSignal(int sig_num);
extern void MapOpcodes(); extern void MapOpcodes();
int main(int argc, char** argv) { int main(int argc, char** argv) {
@ -440,7 +441,7 @@ int main(int argc, char** argv) {
bool websocker_server_opened = false; bool websocker_server_opened = false;
Timer quest_timers(100); Timer quest_timers(100);
UpdateWindowTitle(); UpdateWindowTitle(nullptr);
std::shared_ptr<EQStreamInterface> eqss; std::shared_ptr<EQStreamInterface> eqss;
EQStreamInterface *eqsi; EQStreamInterface *eqsi;
std::unique_ptr<EQ::Net::EQStreamManager> eqsm; std::unique_ptr<EQ::Net::EQStreamManager> eqsm;
@ -514,23 +515,12 @@ int main(int argc, char** argv) {
if (is_zone_loaded) { if (is_zone_loaded) {
{ {
if (net.group_timer.Enabled() && net.group_timer.Check()) entity_list.GroupProcess();
entity_list.GroupProcess(); entity_list.DoorProcess();
entity_list.ObjectProcess();
if (net.door_timer.Enabled() && net.door_timer.Check()) entity_list.CorpseProcess();
entity_list.DoorProcess(); entity_list.TrapProcess();
entity_list.RaidProcess();
if (net.object_timer.Enabled() && net.object_timer.Check())
entity_list.ObjectProcess();
if (net.corpse_timer.Enabled() && net.corpse_timer.Check())
entity_list.CorpseProcess();
if (net.trap_timer.Enabled() && net.trap_timer.Check())
entity_list.TrapProcess();
if (net.raid_timer.Enabled() && net.raid_timer.Check())
entity_list.RaidProcess();
entity_list.Process(); entity_list.Process();
entity_list.MobProcess(); entity_list.MobProcess();
@ -622,60 +612,6 @@ void Shutdown()
LogSys.CloseFileLogs(); LogSys.CloseFileLogs();
} }
uint32 NetConnection::GetIP()
{
char name[255 + 1];
size_t len = 0;
hostent* host = 0;
if (gethostname(name, len) < 0 || len <= 0)
{
return 0;
}
host = (hostent*)gethostbyname(name);
if (host == 0)
{
return 0;
}
return inet_addr(host->h_addr);
}
uint32 NetConnection::GetIP(char* name)
{
hostent* host = 0;
host = (hostent*)gethostbyname(name);
if (host == 0)
{
return 0;
}
return inet_addr(host->h_addr);
}
NetConnection::NetConnection()
:
object_timer(5000),
door_timer(5000),
corpse_timer(2000),
group_timer(1000),
raid_timer(1000),
trap_timer(1000)
{
group_timer.Disable();
raid_timer.Disable();
corpse_timer.Disable();
door_timer.Disable();
object_timer.Disable();
trap_timer.Disable();
}
NetConnection::~NetConnection() {
}
/* Update Window Title with relevant information */ /* Update Window Title with relevant information */
void UpdateWindowTitle(char* iNewTitle) { void UpdateWindowTitle(char* iNewTitle) {
#ifdef _WINDOWS #ifdef _WINDOWS

View File

@ -1,48 +0,0 @@
/* EQEMu: Everquest Server Emulator
Copyright (C) 2001-2002 EQEMu Development Team (http://eqemu.org)
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
*/
#ifdef _WINDOWS
#include <winsock2.h>
#include <windows.h>
#else
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <netdb.h>
#endif
#include "../common/types.h"
#include "../common/timer.h"
void CatchSignal(int);
void UpdateWindowTitle(char* iNewTitle = 0);
class NetConnection
{
public:
~NetConnection();
NetConnection();
uint32 GetIP();
uint32 GetIP(char* name);
Timer object_timer;
Timer door_timer;
Timer corpse_timer;
Timer group_timer;
Timer raid_timer;
Timer trap_timer;
};

View File

@ -21,7 +21,6 @@ Copyright (C) 2001-2014 EQEMu Development Team (http://eqemulator.net)
#include "../common/string_util.h" #include "../common/string_util.h"
#include "queryserv.h" #include "queryserv.h"
#include "worldserver.h" #include "worldserver.h"
#include "net.h"
extern WorldServer worldserver; extern WorldServer worldserver;

View File

@ -44,7 +44,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "quest_parser_collection.h" #include "quest_parser_collection.h"
#include "guild_mgr.h" #include "guild_mgr.h"
#include "mob.h" #include "mob.h"
#include "net.h"
#include "petitions.h" #include "petitions.h"
#include "raids.h" #include "raids.h"
#include "string_ids.h" #include "string_ids.h"
@ -59,7 +58,6 @@ extern Zone* zone;
extern volatile bool is_zone_loaded; extern volatile bool is_zone_loaded;
extern void CatchSignal(int); extern void CatchSignal(int);
extern WorldServer worldserver; extern WorldServer worldserver;
extern NetConnection net;
extern PetitionList petition_list; extern PetitionList petition_list;
extern uint32 numclients; extern uint32 numclients;
extern volatile bool RunLoops; extern volatile bool RunLoops;

View File

@ -39,7 +39,6 @@
#include "guild_mgr.h" #include "guild_mgr.h"
#include "map.h" #include "map.h"
#include "net.h"
#include "npc.h" #include "npc.h"
#include "object.h" #include "object.h"
#include "pathfinder_null.h" #include "pathfinder_null.h"
@ -68,7 +67,6 @@
#endif #endif
extern bool staticzone; extern bool staticzone;
extern NetConnection net;
extern PetitionList petition_list; extern PetitionList petition_list;
extern QuestParserCollection* parse; extern QuestParserCollection* parse;
extern uint32 numclients; extern uint32 numclients;
@ -81,6 +79,8 @@ Mutex MZoneShutdown;
volatile bool is_zone_loaded = false; volatile bool is_zone_loaded = false;
Zone* zone = 0; Zone* zone = 0;
void UpdateWindowTitle(char* iNewTitle);
bool Zone::Bootup(uint32 iZoneID, uint32 iInstanceID, bool iStaticZone) { bool Zone::Bootup(uint32 iZoneID, uint32 iInstanceID, bool iStaticZone) {
const char* zonename = database.GetZoneName(iZoneID); const char* zonename = database.GetZoneName(iZoneID);
@ -147,7 +147,7 @@ bool Zone::Bootup(uint32 iZoneID, uint32 iInstanceID, bool iStaticZone) {
LogInfo("---- Zone server [{}], listening on port:[{}] ----", zonename, ZoneConfig::get()->ZonePort); LogInfo("---- Zone server [{}], listening on port:[{}] ----", zonename, ZoneConfig::get()->ZonePort);
LogInfo("Zone Bootup: [{}] ([{}]: [{}])", zonename, iZoneID, iInstanceID); LogInfo("Zone Bootup: [{}] ([{}]: [{}])", zonename, iZoneID, iInstanceID);
parse->Init(); parse->Init();
UpdateWindowTitle(); UpdateWindowTitle(nullptr);
zone->GetTimeSync(); zone->GetTimeSync();
zone->RequestUCSServerStatus(); zone->RequestUCSServerStatus();
@ -727,7 +727,7 @@ void Zone::Shutdown(bool quiet)
safe_delete(zone); safe_delete(zone);
entity_list.ClearAreas(); entity_list.ClearAreas();
parse->ReloadQuests(true); parse->ReloadQuests(true);
UpdateWindowTitle(); UpdateWindowTitle(nullptr);
LogSys.CloseFileLogs(); LogSys.CloseFileLogs();
@ -2422,4 +2422,4 @@ void Zone::CalculateNpcUpdateDistanceSpread()
update_distance, update_distance,
combined_spread combined_spread
); );
} }