mirror of
https://github.com/EQEmu/Server.git
synced 2026-08-28 15:57:58 +00:00
45da8cab61
* Fix for GENERIC_9_STRINGS
* Add Bot Heal Message Display
Creates a new rule to display Bot heal messages to the Bot Owner
* 2021-03-25 11L04pm
Spell and Heal Rule added to allow for Bot spell and heal damage to be sent to the Bot Owner's Group. Also added a check to remove duplicate message for #damage on self.
* Update .gitignore
* BOT work
Added BOT logging damage/heals to owner
Added BOT message to owner for harmony fails
Made var Critical global to remove duplicate crit messages
Added a NULL check to Mob:GetCleanname()
* Bot Group Work
Fixed botid=charid spawn on zone issue
Added a group_list update on zone to refresh from database to fix a dangling pointer to a Bot object that was camped but was previously in a group within the zone being entered.
Modified Bot::ProcessBotGroupInvite to use the client of the bot when doing the Bot initialization so that a leader can invite another owner's Bot
* Jan 4
Basic structure in place for Raid::AddBot though not working
* Basement Jan 5
* End of day Jan 5
Working Raid Invite to a Bot.
* Update to Client::QueuePacket to not attempt to send a packet to a BoT. Not clean, but a broad solution.
* Updated Raid::VerifyRaid
* Some Bot Raid working
* Before VS Crash
* Use Case 1, 2, 3,4,7 working.
Need to fix 5, 6, 8
* Work on usecase 5
* A few more use cases working
* New work on Raid invite with a invitor having a group
* Bot Raid inviting working for all use cases
* A few changes
* end of day jan 10
* Jan 11
* end of day Jan 11
* Bot Invite/Accept cleanup
* Start of moving raid bot functions to their own methods
* More bot raid changes
* More raid spell work
* end of day Jan 16
* spawn work
* Spawn on login working
* End of Day Jan 18
* Raid leader and mana/hp updates fixed
* Spell Tracking
* Issue with Bot Death in raid when casted upon. 1741 raid.cpp
* Bot Death fixed and few other crashes
* Working on botgroup removal
* Bot Disbanding Work 90%
* Looks like BOTs are working
* Fixed a bot crash
* bug tracing on entity list mismatch
* safe_delete resoves problem. No to track down leak
* seems to be working
* Memory corruption found - sending packets to BoTs using Client class
* added Raid::IsRaidMemberBot()
* Update p_raid_instance
* g3
* Final - Bot Raid Working
* Fixed IsRaidMemberBot to remove memory leak
Fixed altcombat crash though RaidMainAssist (428) needs fixing
* add RaidMember.IsBot
* Repaired IsBot function to be more preformant. Now works on standard performance machine
* Fixed Bard AE Target Spells
Removed assert for buffs
* updated based on Feb 2022 master updates
* Added bot_db_updates and version increment
* Cleanup of bot raid work and inclusion of bot_raid in cmake
* Delete .gitignore
* Revert "Delete .gitignore"
This reverts commit 8523658d3b.
* Fixed a packet issue
* Merged upstream/master
Merged upstream/master and removed ifdef BOTS as per recent dev approach for BOTS. Functionality is there, compiles and tests ok. A few problems to be resolved though this is a good baseline.
* Added sql update for raid_members to add isbot
* Updated Bot Follow Function
Bot will now follow the Group Leader if IsClient, otherwise follows the Bot Owner
* Updates to Bot Raid System
When camping a client, remove them from the raid. If they are leader, place leadership to the next client.
Update a few crash checks in bot_raid.cpp
* [BOTS] Added RuleB Enabled checks and updated base repo for raid_members
Updated several RuleB(Bots, Enabled) checks
Updated the base repo to be autogenerated.
Raid functionality should work with a non-bots enabled database.
* Few quick updates
* Updates
Corrected a number of comments. Compiled and tested against bot and non-bot database though requires the isbot column in raid_members for both.
Moved the db update out of the bot stream to make bot check code easier.
* Formatting and other small updates
* A few more RuleB(Bots, Enabled) additions
* Fix issue with conflict of bot ID versus character ID.
* Delete CMakeSettings.json
* Comment Updates and other
Several updates including
- fixed comments from PR
- added id to raid_members and unique index on name to avoid botid and charid conflicts
- updated a few raid functions for iterators
- reordered several raid operations to ensure send leader packet to be the last item to ensure proper updating on the client
- update sql to use Replace instead of Insert for botid conflicting with charid
* Exploit fix for Raid Bots
Added item from @Nite to disallow spawning or camping bots if Raid is engaged. Avoids abusive situations.
* Initial Commit
* fix Raid Window after zoning
The raid window was not fully updating for clients not in the zone.
* Cleanup
* Update
Fixed comments
* Resolve crash for MOTD
Fixed a crash situation sending a raid MOTD to BOTS.
* Update ruletypes.h
* Updated to resolve a few recent comments
Fixed some comments within attack.cpp
* fix sql query
* update repository
* prevent duplicate entries in raid after group invite, and cleanup
* fixes for botgroups not following, and add already in raid messages.
* fix messagestring
* fixes
* Cleanup, and resolving issues with disbanding
* refactoring
* more cleanup/fixing.
* fixes for removing from ground in raid
* Refactoring/fixing multiple clients
* fix for compiling
* Bugs from refactoring fixed
* Testing completed, cleaning up unwanted items/duplicate code.
* Cleaned up AICastSpell
* fix typos
* Refactoring
* Adding Raid checks to AI_Process/cleanup
* Fix a typo
Was getting a SQL error on BOT spawn. Fixed typo.
* fix for crash
* Fixed crash when inviting player, more refactoring
* AI_Process Refactoring work
* More Refactoring/fixes for follow
* Finish Refactoring AI_Process
* cleanup
* cleanup
* cleanup
* cleanup
* fix melee attack loop
* fix for leashowner.
* fix for leashowner.
* Bots persist in raid after client death/LD/Camp
* Fix Bot Groups when zoning after death.
* Fix Bots in group following after client death
* remove unnecessary query
* Allow Raid members to invite Bots if owner is in raid. cleanup
* optimization of raid verification
* remove this
* Code Cleanup
* formatting
* formatting
* formatting
* fix for macro
* add return for TryClassAttacks
* fix query
* fix for crash
* restrict camping/spawn in combat.
* Fix other crash issue.
* update learnmembers to use Strings::To, cleanup magic numbers
* fix for merge.
---------
Co-authored-by: Kinglykrab <kinglykrab@gmail.com>
Co-authored-by: Alex King <89047260+Kinglykrab@users.noreply.github.com>
Co-authored-by: Aeadoin <109764533+Aeadoin@users.noreply.github.com>
669 lines
18 KiB
C++
669 lines
18 KiB
C++
/**
|
|
* EQEmulator: Everquest Server Emulator
|
|
* Copyright (C) 2001-2020 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
|
|
*
|
|
*/
|
|
|
|
#define DONT_SHARED_OPCODES
|
|
#define PLATFORM_ZONE 1
|
|
|
|
#include "../common/global_define.h"
|
|
#include "../common/timer.h"
|
|
#include "../common/eq_packet_structs.h"
|
|
#include "../common/mutex.h"
|
|
#include "../common/opcodemgr.h"
|
|
#include "../common/guilds.h"
|
|
#include "../common/eq_stream_ident.h"
|
|
#include "../common/patches/patches.h"
|
|
#include "../common/rulesys.h"
|
|
#include "../common/profanity_manager.h"
|
|
#include "../common/strings.h"
|
|
#include "../common/crash.h"
|
|
#include "../common/memory_mapped_file.h"
|
|
#include "../common/spdat.h"
|
|
#include "../common/eqemu_logsys.h"
|
|
#include "../common/misc.h"
|
|
|
|
#include "api_service.h"
|
|
#include "zone_config.h"
|
|
#include "masterentity.h"
|
|
#include "worldserver.h"
|
|
#include "zone.h"
|
|
#include "queryserv.h"
|
|
#include "command.h"
|
|
#include "bot_command.h"
|
|
#include "zonedb.h"
|
|
#include "../common/zone_store.h"
|
|
#include "titles.h"
|
|
#include "guild_mgr.h"
|
|
#include "task_manager.h"
|
|
#include "quest_parser_collection.h"
|
|
#include "embparser.h"
|
|
#include "lua_parser.h"
|
|
#include "questmgr.h"
|
|
#include "npc_scale_manager.h"
|
|
|
|
#include "../common/net/eqstream.h"
|
|
#include "../common/content/world_content_service.h"
|
|
|
|
#include <stdlib.h>
|
|
#include <signal.h>
|
|
#include <time.h>
|
|
#include <chrono>
|
|
|
|
#ifdef _CRTDBG_MAP_ALLOC
|
|
#undef new
|
|
#define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
|
|
#endif
|
|
|
|
#ifdef _WINDOWS
|
|
#include <conio.h>
|
|
#include <process.h>
|
|
#else
|
|
#include <pthread.h>
|
|
#include "../common/unix.h"
|
|
|
|
#endif
|
|
|
|
volatile bool RunLoops = true;
|
|
#ifdef __FreeBSD__
|
|
#include <pthread_np.h>
|
|
#endif
|
|
|
|
extern volatile bool is_zone_loaded;
|
|
extern bool Critical = false;
|
|
|
|
#include "zone_event_scheduler.h"
|
|
#include "../common/file.h"
|
|
#include "../common/path_manager.h"
|
|
#include "../common/events/player_event_logs.h"
|
|
|
|
EntityList entity_list;
|
|
WorldServer worldserver;
|
|
ZoneStore zone_store;
|
|
uint32 numclients = 0;
|
|
char errorname[32];
|
|
extern Zone *zone;
|
|
|
|
npcDecayTimes_Struct npcCorpseDecayTimes[100];
|
|
TitleManager title_manager;
|
|
QueryServ *QServ = 0;
|
|
TaskManager *task_manager = 0;
|
|
NpcScaleManager *npc_scale_manager;
|
|
QuestParserCollection *parse = 0;
|
|
EQEmuLogSys LogSys;
|
|
ZoneEventScheduler event_scheduler;
|
|
WorldContentService content_service;
|
|
PathManager path;
|
|
PlayerEventLogs player_event_logs;
|
|
|
|
const SPDat_Spell_Struct* spells;
|
|
int32 SPDAT_RECORDS = -1;
|
|
const ZoneConfig *Config;
|
|
double frame_time = 0.0;
|
|
|
|
void Shutdown();
|
|
void UpdateWindowTitle(char* iNewTitle);
|
|
void CatchSignal(int sig_num);
|
|
|
|
extern void MapOpcodes();
|
|
|
|
int main(int argc, char** argv) {
|
|
RegisterExecutablePlatform(ExePlatformZone);
|
|
LogSys.LoadLogSettingsDefaults();
|
|
|
|
set_exception_handler();
|
|
|
|
path.LoadPaths();
|
|
|
|
#ifdef USE_MAP_MMFS
|
|
if (argc == 3 && strcasecmp(argv[1], "convert_map") == 0) {
|
|
if (!ZoneConfig::LoadConfig())
|
|
return 1;
|
|
Config = ZoneConfig::get();
|
|
|
|
std::string mapfile = argv[2];
|
|
std::transform(mapfile.begin(), mapfile.end(), mapfile.begin(), ::tolower);
|
|
std::string filename = Config->MapDir;
|
|
filename += mapfile;
|
|
|
|
auto m = new Map();
|
|
auto success = m->Load(filename, true);
|
|
delete m;
|
|
std::cout << mapfile.c_str() << " conversion " << (success ? "succeeded" : "failed") << std::endl;
|
|
|
|
return 0;
|
|
}
|
|
#endif /*USE_MAP_MMFS*/
|
|
|
|
QServ = new QueryServ;
|
|
|
|
LogInfo("Loading server configuration");
|
|
if (!ZoneConfig::LoadConfig()) {
|
|
LogError("Loading server configuration failed");
|
|
return 1;
|
|
}
|
|
Config = ZoneConfig::get();
|
|
|
|
const char *zone_name;
|
|
uint32 instance_id = 0;
|
|
std::string z_name;
|
|
if (argc == 4) {
|
|
instance_id = Strings::ToInt(argv[3]);
|
|
worldserver.SetLauncherName(argv[2]);
|
|
auto zone_port = Strings::Split(argv[1], ':');
|
|
|
|
if (!zone_port.empty()) {
|
|
z_name = zone_port[0];
|
|
}
|
|
|
|
if (zone_port.size() > 1) {
|
|
std::string p_name = zone_port[1];
|
|
Config->SetZonePort(Strings::ToInt(p_name.c_str()));
|
|
}
|
|
|
|
worldserver.SetLaunchedName(z_name.c_str());
|
|
if (strncmp(z_name.c_str(), "dynamic_", 8) == 0) {
|
|
zone_name = ".";
|
|
}
|
|
else {
|
|
zone_name = z_name.c_str();
|
|
}
|
|
}
|
|
else if (argc == 3) {
|
|
worldserver.SetLauncherName(argv[2]);
|
|
auto zone_port = Strings::Split(argv[1], ':');
|
|
|
|
if (!zone_port.empty()) {
|
|
z_name = zone_port[0];
|
|
}
|
|
|
|
if (zone_port.size() > 1) {
|
|
std::string p_name = zone_port[1];
|
|
Config->SetZonePort(Strings::ToInt(p_name.c_str()));
|
|
}
|
|
|
|
worldserver.SetLaunchedName(z_name.c_str());
|
|
if (strncmp(z_name.c_str(), "dynamic_", 8) == 0) {
|
|
zone_name = ".";
|
|
}
|
|
else {
|
|
zone_name = z_name.c_str();
|
|
}
|
|
}
|
|
else if (argc == 2) {
|
|
worldserver.SetLauncherName("NONE");
|
|
auto zone_port = Strings::Split(argv[1], ':');
|
|
|
|
if (!zone_port.empty()) {
|
|
z_name = zone_port[0];
|
|
}
|
|
|
|
if (zone_port.size() > 1) {
|
|
std::string p_name = zone_port[1];
|
|
Config->SetZonePort(Strings::ToInt(p_name.c_str()));
|
|
}
|
|
|
|
worldserver.SetLaunchedName(z_name.c_str());
|
|
if (strncmp(z_name.c_str(), "dynamic_", 8) == 0) {
|
|
zone_name = ".";
|
|
}
|
|
else {
|
|
zone_name = z_name.c_str();
|
|
}
|
|
}
|
|
else {
|
|
zone_name = ".";
|
|
worldserver.SetLaunchedName(".");
|
|
worldserver.SetLauncherName("NONE");
|
|
}
|
|
|
|
auto mutex = new Mutex;
|
|
|
|
LogInfo("Connecting to MySQL");
|
|
if (!database.Connect(
|
|
Config->DatabaseHost.c_str(),
|
|
Config->DatabaseUsername.c_str(),
|
|
Config->DatabasePassword.c_str(),
|
|
Config->DatabaseDB.c_str(),
|
|
Config->DatabasePort)) {
|
|
LogError("Cannot continue without a database connection");
|
|
return 1;
|
|
}
|
|
|
|
// Multi-tenancy: Content Database
|
|
if (!Config->ContentDbHost.empty()) {
|
|
if (!content_db.Connect(
|
|
Config->ContentDbHost.c_str() ,
|
|
Config->ContentDbUsername.c_str(),
|
|
Config->ContentDbPassword.c_str(),
|
|
Config->ContentDbName.c_str(),
|
|
Config->ContentDbPort,
|
|
"content"
|
|
)) {
|
|
LogError("Cannot continue without a content database connection");
|
|
return 1;
|
|
}
|
|
} else {
|
|
content_db.SetMySQL(database);
|
|
// when database and content_db share the same underlying mysql connection
|
|
// it needs to be protected by a shared mutex otherwise we produce concurrency issues
|
|
// when database actions are occurring in different threads
|
|
database.SetMutex(mutex);
|
|
content_db.SetMutex(mutex);
|
|
}
|
|
|
|
/* Register Log System and Settings */
|
|
LogSys.SetDatabase(&database)
|
|
->SetLogPath(path.GetLogPath())
|
|
->LoadLogDatabaseSettings()
|
|
->SetGMSayHandler(&Zone::GMSayHookCallBackProcess)
|
|
->StartFileLogs();
|
|
|
|
player_event_logs.SetDatabase(&database)->Init();
|
|
|
|
/* Guilds */
|
|
guild_mgr.SetDatabase(&database);
|
|
GuildBanks = nullptr;
|
|
|
|
#ifdef _EQDEBUG
|
|
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
|
|
#endif
|
|
|
|
LogInfo("CURRENT_VERSION [{}]", CURRENT_VERSION);
|
|
|
|
/*
|
|
* Setup nice signal handlers
|
|
*/
|
|
if (signal(SIGINT, CatchSignal) == SIG_ERR) {
|
|
LogError("Could not set signal handler");
|
|
return 1;
|
|
}
|
|
if (signal(SIGTERM, CatchSignal) == SIG_ERR) {
|
|
LogError("Could not set signal handler");
|
|
return 1;
|
|
}
|
|
#ifndef WIN32
|
|
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
|
|
LogError("Could not set signal handler");
|
|
return 1;
|
|
}
|
|
#endif
|
|
|
|
MapOpcodes();
|
|
|
|
database.LoadVariables();
|
|
|
|
std::string hotfix_name;
|
|
if (database.GetVariable("hotfix_name", hotfix_name)) {
|
|
if (!hotfix_name.empty()) {
|
|
LogInfo("Current hotfix in use: [{}]", hotfix_name.c_str());
|
|
}
|
|
}
|
|
|
|
zone_store.LoadZones(content_db);
|
|
|
|
if (zone_store.GetZones().empty()) {
|
|
LogError("Failed to load zones data, check your schema for possible errors");
|
|
return 1;
|
|
}
|
|
|
|
// load these here for now until spells and items can be truly repointed to "content_db"
|
|
database.SetSharedItemsCount(content_db.GetItemsCount());
|
|
database.SetSharedSpellsCount(content_db.GetSpellsCount());
|
|
|
|
if (!database.LoadItems(hotfix_name)) {
|
|
LogError("Loading items failed!");
|
|
LogError("Failed. But ignoring error and going on..");
|
|
}
|
|
|
|
if (!content_db.LoadNPCFactionLists(hotfix_name)) {
|
|
LogError("Loading npcs faction lists failed!");
|
|
return 1;
|
|
}
|
|
if (!content_db.LoadFactionAssociation(hotfix_name)) {
|
|
LogError("Loading faction association hits failed!");
|
|
return 1;
|
|
}
|
|
if (!database.LoadLoot(hotfix_name)) {
|
|
LogError("Loading loot failed!");
|
|
return 1;
|
|
}
|
|
if (!content_db.LoadSkillCaps(std::string(hotfix_name))) {
|
|
LogError("Loading skill caps failed!");
|
|
return 1;
|
|
}
|
|
if (!database.LoadSpells(hotfix_name, &SPDAT_RECORDS, &spells)) {
|
|
LogError("Loading spells failed!");
|
|
return 1;
|
|
}
|
|
|
|
if (!database.LoadBaseData(hotfix_name)) {
|
|
LogError("Loading base data failed!");
|
|
return 1;
|
|
}
|
|
|
|
guild_mgr.LoadGuilds();
|
|
content_db.LoadFactionData();
|
|
title_manager.LoadTitles();
|
|
content_db.LoadTributes();
|
|
|
|
database.GetDecayTimes(npcCorpseDecayTimes);
|
|
|
|
if (!EQ::ProfanityManager::LoadProfanityList(&database)) {
|
|
LogError("Loading profanity list failed!");
|
|
}
|
|
|
|
int retval = command_init();
|
|
if (retval < 0) {
|
|
LogError("Command loading failed");
|
|
}
|
|
else {
|
|
LogInfo("Loaded [{}] commands loaded", Strings::Commify(std::to_string(retval)));
|
|
}
|
|
|
|
//rules:
|
|
{
|
|
std::string tmp;
|
|
if (database.GetVariable("RuleSet", tmp)) {
|
|
LogInfo("Loading rule set [{}]", tmp.c_str());
|
|
if (!RuleManager::Instance()->LoadRules(&database, tmp.c_str(), false)) {
|
|
LogError("Failed to load ruleset [{}], falling back to defaults", tmp.c_str());
|
|
}
|
|
}
|
|
else {
|
|
if (!RuleManager::Instance()->LoadRules(&database, "default", false)) {
|
|
LogInfo("No rule set configured, using default rules");
|
|
}
|
|
}
|
|
|
|
EQ::InitializeDynamicLookups();
|
|
}
|
|
|
|
content_service.SetDatabase(&database)
|
|
->SetExpansionContext()
|
|
->ReloadContentFlags();
|
|
|
|
event_scheduler.SetDatabase(&database)->LoadScheduledEvents();
|
|
|
|
EQ::SayLinkEngine::LoadCachedSaylinks();
|
|
|
|
if (RuleB(Bots, Enabled) && database.DoesTableExist("bot_command_settings")) {
|
|
LogInfo("Loading bot commands");
|
|
int botretval = bot_command_init();
|
|
if (botretval < 0) {
|
|
LogError("Bot command loading failed");
|
|
}
|
|
else {
|
|
LogInfo("[{}] bot commands loaded", botretval);
|
|
}
|
|
|
|
LogInfo("Loading bot spell casting chances");
|
|
if (!database.botdb.LoadBotSpellCastingChances()) {
|
|
LogError("Bot spell casting chances loading failed");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* NPC Scale Manager
|
|
*/
|
|
npc_scale_manager = new NpcScaleManager;
|
|
npc_scale_manager->LoadScaleData();
|
|
|
|
if (RuleB(TaskSystem, EnableTaskSystem)) {
|
|
task_manager = new TaskManager;
|
|
task_manager->LoadTasks();
|
|
}
|
|
|
|
parse = new QuestParserCollection();
|
|
#ifdef LUA_EQEMU
|
|
parse->RegisterQuestInterface(LuaParser::Instance(), "lua");
|
|
#endif
|
|
|
|
#ifdef EMBPERL
|
|
auto perl_parser = new PerlembParser();
|
|
parse->RegisterQuestInterface(perl_parser, "pl");
|
|
|
|
/* Load Perl Event Export Settings */
|
|
parse->LoadPerlEventExportSettings(parse->perl_event_export_settings);
|
|
|
|
#endif
|
|
|
|
//now we have our parser, load the quests
|
|
LogInfo("Loading quests");
|
|
parse->ReloadQuests();
|
|
|
|
worldserver.Connect();
|
|
worldserver.SetScheduler(&event_scheduler);
|
|
|
|
Timer InterserverTimer(INTERSERVER_TIMER); // does MySQL pings and auto-reconnect
|
|
#ifdef EQPROFILE
|
|
#ifdef PROFILE_DUMP_TIME
|
|
Timer profile_dump_timer(PROFILE_DUMP_TIME * 1000);
|
|
profile_dump_timer.Start();
|
|
#endif
|
|
#endif
|
|
if (!strlen(zone_name) || !strcmp(zone_name, ".")) {
|
|
LogInfo("Entering sleep mode");
|
|
}
|
|
else if (!Zone::Bootup(ZoneID(zone_name), instance_id, true)) {
|
|
LogError("Zone Bootup failed :: Zone::Bootup");
|
|
zone = nullptr;
|
|
}
|
|
|
|
//register all the patches we have avaliable with the stream identifier.
|
|
EQStreamIdentifier stream_identifier;
|
|
RegisterAllPatches(stream_identifier);
|
|
|
|
#ifdef __linux__
|
|
LogDebug("Main thread running with thread id [{}]", pthread_self());
|
|
#elif defined(__FreeBSD__)
|
|
LogDebug("Main thread running with thread id [{}]", pthread_getthreadid_np());
|
|
#endif
|
|
|
|
bool worldwasconnected = worldserver.Connected();
|
|
bool eqsf_open = false;
|
|
bool websocker_server_opened = false;
|
|
|
|
Timer quest_timers(100);
|
|
UpdateWindowTitle(nullptr);
|
|
std::shared_ptr<EQStreamInterface> eqss;
|
|
EQStreamInterface *eqsi;
|
|
std::unique_ptr<EQ::Net::EQStreamManager> eqsm;
|
|
std::chrono::time_point<std::chrono::system_clock> frame_prev = std::chrono::system_clock::now();
|
|
std::unique_ptr<EQ::Net::WebsocketServer> ws_server;
|
|
|
|
auto loop_fn = [&](EQ::Timer* t) {
|
|
//Advance the timer to our current point in time
|
|
Timer::SetCurrentTime();
|
|
|
|
/**
|
|
* Calculate frame time
|
|
*/
|
|
std::chrono::time_point<std::chrono::system_clock> frame_now = std::chrono::system_clock::now();
|
|
frame_time = std::chrono::duration_cast<std::chrono::duration<double>>(frame_now - frame_prev).count();
|
|
frame_prev = frame_now;
|
|
|
|
/**
|
|
* Websocket server
|
|
*/
|
|
if (!websocker_server_opened && Config->ZonePort != 0) {
|
|
LogInfo("Websocket Server listener started on address [{}] port [{}]", Config->TelnetIP.c_str(), Config->ZonePort);
|
|
ws_server = std::make_unique<EQ::Net::WebsocketServer>(Config->TelnetIP, Config->ZonePort);
|
|
RegisterApiService(ws_server);
|
|
websocker_server_opened = true;
|
|
}
|
|
|
|
/**
|
|
* EQStreamManager
|
|
*/
|
|
if (!eqsf_open && Config->ZonePort != 0) {
|
|
LogInfo("Starting EQ Network server on port [{}]", Config->ZonePort);
|
|
|
|
EQStreamManagerInterfaceOptions opts(Config->ZonePort, false, RuleB(Network, CompressZoneStream));
|
|
opts.daybreak_options.resend_delay_ms = RuleI(Network, ResendDelayBaseMS);
|
|
opts.daybreak_options.resend_delay_factor = RuleR(Network, ResendDelayFactor);
|
|
opts.daybreak_options.resend_delay_min = RuleI(Network, ResendDelayMinMS);
|
|
opts.daybreak_options.resend_delay_max = RuleI(Network, ResendDelayMaxMS);
|
|
opts.daybreak_options.outgoing_data_rate = RuleR(Network, ClientDataRate);
|
|
eqsm = std::make_unique<EQ::Net::EQStreamManager>(opts);
|
|
eqsf_open = true;
|
|
|
|
eqsm->OnNewConnection(
|
|
[&stream_identifier](std::shared_ptr<EQ::Net::EQStream> stream) {
|
|
stream_identifier.AddStream(stream);
|
|
LogInfo(
|
|
"New connection from address [{}] port [{}]",
|
|
long2ip(stream->GetRemoteIP()),
|
|
ntohs(stream->GetRemotePort())
|
|
);
|
|
}
|
|
);
|
|
}
|
|
|
|
//give the stream identifier a chance to do its work....
|
|
stream_identifier.Process();
|
|
|
|
//check the stream identifier for any now-identified streams
|
|
while ((eqsi = stream_identifier.PopIdentified())) {
|
|
//now that we know what patch they are running, start up their client object
|
|
struct in_addr in;
|
|
in.s_addr = eqsi->GetRemoteIP();
|
|
LogInfo("New client from [{}]:[{}]", inet_ntoa(in), ntohs(eqsi->GetRemotePort()));
|
|
auto client = new Client(eqsi);
|
|
entity_list.AddClient(client);
|
|
}
|
|
|
|
if (worldserver.Connected()) {
|
|
worldwasconnected = true;
|
|
}
|
|
else {
|
|
if (worldwasconnected && is_zone_loaded) {
|
|
entity_list.ChannelMessageFromWorld(0, 0, ChatChannel_Broadcast, 0, 0, 100, "WARNING: World server connection lost");
|
|
worldwasconnected = false;
|
|
}
|
|
}
|
|
|
|
if (is_zone_loaded) {
|
|
{
|
|
entity_list.GroupProcess();
|
|
entity_list.DoorProcess();
|
|
entity_list.ObjectProcess();
|
|
entity_list.CorpseProcess();
|
|
entity_list.TrapProcess();
|
|
entity_list.RaidProcess();
|
|
entity_list.Process();
|
|
entity_list.MobProcess();
|
|
entity_list.BeaconProcess();
|
|
entity_list.EncounterProcess();
|
|
event_scheduler.Process(zone, &content_service);
|
|
|
|
if (zone) {
|
|
if (!zone->Process()) {
|
|
Zone::Shutdown();
|
|
}
|
|
}
|
|
|
|
if (quest_timers.Check()) {
|
|
quest_manager.Process();
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
if (InterserverTimer.Check()) {
|
|
InterserverTimer.Start();
|
|
database.ping();
|
|
content_db.ping();
|
|
entity_list.UpdateWho();
|
|
}
|
|
};
|
|
|
|
EQ::Timer process_timer(loop_fn);
|
|
process_timer.Start(32, true);
|
|
|
|
EQ::EventLoop::Get().Run();
|
|
|
|
entity_list.Clear();
|
|
entity_list.RemoveAllEncounters(); // gotta do it manually or rewrite lots of shit :P
|
|
|
|
parse->ClearInterfaces();
|
|
|
|
#ifdef EMBPERL
|
|
safe_delete(perl_parser);
|
|
#endif
|
|
|
|
safe_delete(Config);
|
|
|
|
if (zone != 0)
|
|
Zone::Shutdown(true);
|
|
//Fix for Linux world server problem.
|
|
safe_delete(task_manager);
|
|
safe_delete(npc_scale_manager);
|
|
command_deinit();
|
|
bot_command_deinit();
|
|
safe_delete(parse);
|
|
LogInfo("Proper zone shutdown complete.");
|
|
LogSys.CloseFileLogs();
|
|
|
|
safe_delete(mutex);
|
|
|
|
return 0;
|
|
}
|
|
|
|
void Shutdown()
|
|
{
|
|
Zone::Shutdown(true);
|
|
LogInfo("Shutting down...");
|
|
LogSys.CloseFileLogs();
|
|
EQ::EventLoop::Get().Shutdown();
|
|
}
|
|
|
|
void CatchSignal(int sig_num) {
|
|
#ifdef _WINDOWS
|
|
LogInfo("Recieved signal: [{}]", sig_num);
|
|
#endif
|
|
Shutdown();
|
|
}
|
|
|
|
/* Update Window Title with relevant information */
|
|
void UpdateWindowTitle(char* iNewTitle) {
|
|
#ifdef _WINDOWS
|
|
char tmp[500];
|
|
if (iNewTitle) {
|
|
snprintf(tmp, sizeof(tmp), "%i: %s", ZoneConfig::get()->ZonePort, iNewTitle);
|
|
}
|
|
else {
|
|
if (zone) {
|
|
#if defined(GOTFRAGS) || defined(_EQDEBUG)
|
|
snprintf(tmp, sizeof(tmp), "%i: %s, %i clients, %i", ZoneConfig::get()->ZonePort, zone->GetShortName(), numclients, getpid());
|
|
#else
|
|
snprintf(tmp, sizeof(tmp), "%s :: clients: %i inst_id: %i inst_ver: %i :: port: %i", zone->GetShortName(), numclients, zone->GetInstanceID(), zone->GetInstanceVersion(), ZoneConfig::get()->ZonePort);
|
|
#endif
|
|
}
|
|
else {
|
|
#if defined(GOTFRAGS) || defined(_EQDEBUG)
|
|
snprintf(tmp, sizeof(tmp), "%i: sleeping, %i", ZoneConfig::get()->ZonePort, getpid());
|
|
#else
|
|
snprintf(tmp, sizeof(tmp), "%i: sleeping", ZoneConfig::get()->ZonePort);
|
|
#endif
|
|
}
|
|
}
|
|
SetConsoleTitle(tmp);
|
|
#endif
|
|
}
|