From da739b85201347e8cff5223d7dbbdcb7aaa2e074 Mon Sep 17 00:00:00 2001 From: Akkadius Date: Sat, 9 Mar 2019 23:08:38 -0600 Subject: [PATCH 01/11] Initial work --- zone/CMakeLists.txt | 11 +- zone/console.cpp | 122 ++++++ zone/console.h | 25 ++ zone/eqemu_api_zone_data_service.cpp | 370 +++++++++++++++++++ zone/eqemu_api_zone_data_service.h | 32 ++ zone/net.cpp | 36 +- zone/zone.cpp | 27 -- zone/zone.h | 529 ++++++++++++++------------- 8 files changed, 855 insertions(+), 297 deletions(-) create mode 100644 zone/console.cpp create mode 100644 zone/console.h create mode 100644 zone/eqemu_api_zone_data_service.cpp create mode 100644 zone/eqemu_api_zone_data_service.h diff --git a/zone/CMakeLists.txt b/zone/CMakeLists.txt index c92102a2d..8b7bcfd93 100644 --- a/zone/CMakeLists.txt +++ b/zone/CMakeLists.txt @@ -17,6 +17,7 @@ SET(zone_sources client_mods.cpp client_packet.cpp client_process.cpp + console.cpp command.cpp corpse.cpp data_bucket.cpp @@ -28,6 +29,7 @@ SET(zone_sources embxs.cpp encounter.cpp entity.cpp + eqemu_api_zone_data_service.cpp exp.cpp fastmath.cpp fearpath.cpp @@ -140,7 +142,8 @@ SET(zone_sources zone.cpp zone_config.cpp zonedb.cpp - zoning.cpp) + zoning.cpp +) SET(zone_headers aa.h @@ -157,14 +160,16 @@ SET(zone_headers client_packet.h command.h common.h + console.h corpse.h - data_bucket.h + data_bucket.h doors.h embparser.h embperl.h embxs.h encounter.h entity.h + eqemu_api_zone_data_service.h errmsg.h event_codes.h fastmath.h @@ -245,7 +250,7 @@ SET(zone_headers zone.h zone_config.h zonedb.h - zonedump.h) + zonedump.h eqemu_api_zone_data_service.cpp eqemu_api_zone_data_service.h) IF(EQEMU_DEPOP_INVALIDATES_CACHE) ADD_DEFINITIONS(-DDEPOP_INVALIDATES_NPC_TYPES_CACHE) diff --git a/zone/console.cpp b/zone/console.cpp new file mode 100644 index 000000000..0af4adeb5 --- /dev/null +++ b/zone/console.cpp @@ -0,0 +1,122 @@ +/** + * 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 + * + */ + +#include "console.h" +#include "../common/string_util.h" +#include "../common/md5.h" +#include "../common/database.h" +#include "../common/json/json.h" +#include "zone.h" +#include "npc.h" +#include "entity.h" +#include "eqemu_api_zone_data_service.h" + +/** + * @param username + * @param password + * @return + */ +struct EQ::Net::ConsoleLoginStatus CheckLogin(const std::string &username, const std::string &password) +{ + struct EQ::Net::ConsoleLoginStatus ret; + ret.account_id = database.CheckLogin(username.c_str(), password.c_str()); + if (ret.account_id == 0) { + return ret; + } + + char account_name[64]; + database.GetAccountName(static_cast(ret.account_id), account_name); + + ret.account_name = account_name; + ret.status = database.CheckStatus(static_cast(ret.account_id)); + return ret; +} + +/** + * @param connection + * @param command + * @param args + */ +void ConsoleApi( + EQ::Net::ConsoleServerConnection *connection, + const std::string &command, + const std::vector &args +) +{ + Json::Value root; + Json::Value response; + + BenchTimer timer; + timer.reset(); + + EQEmuApiZoneDataService::get(response, args); + + std::string method = args[0]; + + root["execution_time"] = std::to_string(timer.elapsed()); + root["method"] = method; + root["data"] = response; + + std::stringstream payload; + payload << root; + + connection->SendLine(payload.str()); +} + +/** + * + * @param connection + * @param command + * @param args + */ +void ConsoleNull( + EQ::Net::ConsoleServerConnection *connection, + const std::string &command, + const std::vector &args +) +{ +} + +/** + * @param connection + * @param command + * @param args + */ +void ConsoleQuit( + EQ::Net::ConsoleServerConnection *connection, + const std::string &command, + const std::vector &args +) +{ + connection->SendLine("Exiting..."); + connection->Close(); +} + +/** + * @param console + */ +void RegisterConsoleFunctions(std::unique_ptr &console) +{ + console->RegisterLogin(std::bind(CheckLogin, std::placeholders::_1, std::placeholders::_2)); + console->RegisterCall("api", 200, "api", std::bind(ConsoleApi, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); + console->RegisterCall("ping", 50, "ping", std::bind(ConsoleNull, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); + console->RegisterCall("quit", 50, "quit", std::bind(ConsoleQuit, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); + console->RegisterCall("exit", 50, "exit", std::bind(ConsoleQuit, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); +} diff --git a/zone/console.h b/zone/console.h new file mode 100644 index 000000000..05dc29569 --- /dev/null +++ b/zone/console.h @@ -0,0 +1,25 @@ +/** + * EQEmulator: Everquest Server Emulator + * Copyright (C) 2001-2018 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 + * + */ + +#pragma once + +#include "../common/net/console_server.h" + +void RegisterConsoleFunctions(std::unique_ptr &console); diff --git a/zone/eqemu_api_zone_data_service.cpp b/zone/eqemu_api_zone_data_service.cpp new file mode 100644 index 000000000..7ded49b90 --- /dev/null +++ b/zone/eqemu_api_zone_data_service.cpp @@ -0,0 +1,370 @@ +/** + * 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 + * + */ + +#include "eqemu_api_zone_data_service.h" +#include "npc.h" +#include "zone.h" +#include "entity.h" +#include + +extern Zone *zone; + +void callGetNpcListDetail(Json::Value &response) +{ + auto &list = entity_list.GetNPCList(); + + for (auto &iter : list) { + auto npc = iter.second; + Json::Value row; + + /** + * Main + */ + row["id"] = npc->GetID(); + row["clean_name"] = npc->GetCleanName(); + row["x"] = npc->GetX(); + row["y"] = npc->GetY(); + row["z"] = npc->GetZ(); + row["heading"] = npc->GetHeading(); + + /** + * Rest + */ + row["accuracy_rating"] = npc->GetAccuracyRating(); + row["ai_has_spells"] = npc->AI_HasSpells(); + row["ai_has_spells_effects"] = npc->AI_HasSpellsEffects(); + row["ammo_id_file"] = npc->GetAmmoIDfile(); + row["attack_delay"] = npc->GetAttackDelay(); + row["attack_speed"] = npc->GetAttackSpeed(); + row["avoidance_rating"] = npc->GetAvoidanceRating(); + row["base_damage"] = npc->GetBaseDamage(); + row["combat_event"] = npc->GetCombatEvent(); + row["copper"] = npc->GetCopper(); + row["count_loot"] = npc->CountLoot(); + row["drops_global_loot"] = npc->DropsGlobalLoot(); + row["gold"] = npc->GetGold(); + row["grid"] = npc->GetGrid(); + row["has_private_corpse"] = npc->HasPrivateCorpse(); + row["is_animal"] = npc->IsAnimal(); + row["is_guarding"] = npc->IsGuarding(); + row["is_ldon_locked"] = npc->IsLDoNLocked(); + row["is_ldon_trap_detected"] = npc->IsLDoNTrapDetected(); + row["is_ldon_trapped"] = npc->IsLDoNTrapped(); + row["is_merchant_open"] = npc->IsMerchantOpen(); + row["is_not_targetable_with_hotkey"] = npc->IsNotTargetableWithHotkey(); + row["is_proximity_set"] = npc->IsProximitySet(); + row["is_taunting"] = npc->IsTaunting(); + row["ldon_locked_skill"] = npc->GetLDoNLockedSkill(); + row["ldon_trap_spell_id"] = npc->GetLDoNTrapSpellID(); + row["ldon_trap_type"] = npc->GetLDoNTrapType(); + row["loottable_id"] = npc->GetLoottableID(); + row["max_dmg"] = npc->GetMaxDMG(); + row["max_wp"] = npc->GetMaxWp(); + row["min_damage"] = npc->GetMinDamage(); + row["min_dmg"] = npc->GetMinDMG(); + row["npc_spells_effects_id"] = npc->GetNPCSpellsEffectsID(); + row["npc_spells_id"] = npc->GetNPCSpellsID(); + row["npchp_regen"] = npc->GetNPCHPRegen(); + row["num_merc_types"] = npc->GetNumMercTypes(); + row["num_mercs"] = npc->GetNumMercs(); + row["number_of_attacks"] = npc->GetNumberOfAttacks(); + row["pet_spell_id"] = npc->GetPetSpellID(); + row["platinum"] = npc->GetPlatinum(); + row["prim_skill"] = npc->GetPrimSkill(); + + if (npc->IsProximitySet()) { + row["proximity_max_x"] = npc->GetProximityMaxX(); + row["proximity_max_y"] = npc->GetProximityMaxY(); + row["proximity_max_z"] = npc->GetProximityMaxZ(); + row["proximity_min_x"] = npc->GetProximityMinX(); + row["proximity_min_y"] = npc->GetProximityMinY(); + row["proximity_min_z"] = npc->GetProximityMinZ(); + } + + row["ranged_skill"] = npc->GetRangedSkill(); + row["raw_ac"] = npc->GetRawAC(); + row["sec_skill"] = npc->GetSecSkill(); + row["silver"] = npc->GetSilver(); + row["slow_mitigation"] = npc->GetSlowMitigation(); + row["sp2"] = npc->GetSp2(); + row["swarm_owner"] = npc->GetSwarmOwner(); + row["swarm_target"] = npc->GetSwarmTarget(); + row["waypoint_max"] = npc->GetWaypointMax(); + row["will_aggro_npcs"] = npc->WillAggroNPCs(); + + response.append(row); + } +} + +void callGetMobListDetail(Json::Value &response) +{ + auto &list = entity_list.GetMobList(); + + for (auto &iter : list) { + auto mob = iter.second; + + Json::Value row; + + /** + * Main + */ + row["id"] = mob->GetID(); + row["clean_name"] = mob->GetCleanName(); + row["x"] = mob->GetX(); + row["y"] = mob->GetY(); + row["z"] = mob->GetZ(); + row["heading"] = mob->GetHeading(); + + /** + * Rest + */ + row["ac"] = mob->GetAC(); + row["ac_softcap"] = mob->GetACSoftcap(); + row["ac_sum"] = mob->ACSum(); + row["active_light_type"] = mob->GetActiveLightType(); + row["aggro_range"] = mob->GetAggroRange(); + row["allow_beneficial"] = mob->GetAllowBeneficial(); + row["animation"] = mob->GetAnimation(); + row["assist_range"] = mob->GetAssistRange(); + row["aura_slots"] = mob->GetAuraSlots(); + row["base_fear_speed"] = mob->GetBaseFearSpeed(); + row["base_runspeed"] = mob->GetBaseRunspeed(); + row["base_size"] = mob->GetBaseSize(); + row["base_walkspeed"] = mob->GetBaseWalkspeed(); + row["beard"] = mob->GetBeard(); + row["beard_color"] = mob->GetBeardColor(); + row["best_melee_skill"] = mob->GetBestMeleeSkill(); + row["calc_fear_resist_chance"] = mob->CalcFearResistChance(); + row["calc_resist_chance_bonus"] = mob->CalcResistChanceBonus(); + row["can_block_spell"] = mob->CanBlockSpell(); + row["can_facestab"] = mob->CanFacestab(); + row["casted_spell_inv_slot"] = mob->GetCastedSpellInvSlot(); + row["casting_spell_id"] = mob->CastingSpellID(); + row["charmed"] = mob->Charmed(); + row["check_last_los_state"] = mob->CheckLastLosState(); + row["class"] = mob->GetClass(); + row["class_level_factor"] = mob->GetClassLevelFactor(); + row["class_race_ac_bonus"] = mob->GetClassRaceACBonus(); + row["compute_defense"] = mob->compute_defense(); + row["count_dispellable_buffs"] = mob->CountDispellableBuffs(); + row["cripp_blow_chance"] = mob->GetCrippBlowChance(); + row["cur_wp"] = mob->GetCurWp(); + row["cwp"] = mob->GetCWP(); + row["cwpp"] = mob->GetCWPP(); + row["divine_aura"] = mob->DivineAura(); + row["do_casting_checks"] = mob->DoCastingChecks(); + row["dont_buff_me_before"] = mob->DontBuffMeBefore(); + row["dont_cure_me_before"] = mob->DontCureMeBefore(); + row["dont_dot_me_before"] = mob->DontDotMeBefore(); + row["dont_heal_me_before"] = mob->DontHealMeBefore(); + row["dont_root_me_before"] = mob->DontRootMeBefore(); + row["dont_snare_me_before"] = mob->DontSnareMeBefore(); + row["drakkin_details"] = mob->GetDrakkinDetails(); + row["drakkin_heritage"] = mob->GetDrakkinHeritage(); + row["drakkin_tattoo"] = mob->GetDrakkinTattoo(); + row["emote_id"] = mob->GetEmoteID(); + row["equipment_light_type"] = mob->GetEquipmentLightType(); + row["eye_color1"] = mob->GetEyeColor1(); + row["eye_color2"] = mob->GetEyeColor2(); + row["fear_speed"] = mob->GetFearSpeed(); + row["flurry_chance"] = mob->GetFlurryChance(); + row["follow_can_run"] = mob->GetFollowCanRun(); + row["follow_distance"] = mob->GetFollowDistance(); + row["follow_id"] = mob->GetFollowID(); + row["gender"] = mob->GetGender(); + row["hair_color"] = mob->GetHairColor(); + row["hair_style"] = mob->GetHairStyle(); + row["has_active_song"] = mob->HasActiveSong(); + row["has_assist_aggro"] = mob->HasAssistAggro(); + row["has_died"] = mob->HasDied(); + row["has_disc_buff"] = mob->HasDiscBuff(); + row["has_endur_upkeep"] = mob->HasEndurUpkeep(); + row["has_free_aura_slots"] = mob->HasFreeAuraSlots(); + row["has_free_trap_slots"] = mob->HasFreeTrapSlots(); + row["has_mgb"] = mob->HasMGB(); + row["has_numhits"] = mob->HasNumhits(); + row["has_pet"] = mob->HasPet(); + row["has_pet_affinity"] = mob->HasPetAffinity(); + row["has_primary_aggro"] = mob->HasPrimaryAggro(); + row["has_project_illusion"] = mob->HasProjectIllusion(); + row["has_projectile_attack"] = mob->HasProjectileAttack(); + row["has_shield_equiped"] = mob->HasShieldEquiped(); + row["has_special_abilities"] = mob->HasSpecialAbilities(); + row["has_tar_reflection"] = mob->HasTargetReflection(); + row["has_temp_pets_active"] = mob->HasTempPetsActive(); + row["has_two_hand_blunt_equiped"] = mob->HasTwoHandBluntEquiped(); + row["has_two_hander_equipped"] = mob->HasTwoHanderEquipped(); + row["has_virus"] = mob->HasVirus(); + row["hate_summon"] = mob->HateSummon(); + row["helm_texture"] = mob->GetHelmTexture(); + row["hp"] = mob->GetHP(); + row["improved_taunt"] = mob->ImprovedTaunt(); + row["innate_light_type"] = mob->GetInnateLightType(); + row["is_ai_controlled"] = mob->IsAIControlled(); + row["is_amnesiad"] = mob->IsAmnesiad(); + row["is_animation"] = mob->IsAnimation(); + row["is_blind"] = mob->IsBlind(); + row["is_casting"] = mob->IsCasting(); + row["is_charmed"] = mob->IsCharmed(); + row["is_destructible_object"] = mob->IsDestructibleObject(); + row["is_engaged"] = mob->IsEngaged(); + row["is_enraged"] = mob->IsEnraged(); + row["is_familiar"] = mob->IsFamiliar(); + row["is_feared"] = mob->IsFeared(); + row["is_findable"] = mob->IsFindable(); + row["is_focused"] = mob->IsFocused(); + row["is_g_held"] = mob->IsGHeld(); + row["is_grouped"] = mob->IsGrouped(); + row["is_held"] = mob->IsHeld(); + row["is_looting"] = mob->IsLooting(); + row["is_melee_disabled"] = mob->IsMeleeDisabled(); + row["is_mezzed"] = mob->IsMezzed(); + row["is_moved"] = mob->IsMoved(); + row["is_moving"] = mob->IsMoving(); + row["is_no_cast"] = mob->IsNoCast(); + row["is_off_hand_atk"] = mob->IsOffHandAtk(); + row["is_pet_owner_client"] = mob->IsPetOwnerClient(); + row["is_pet_regroup"] = mob->IsPetRegroup(); + row["is_pet_stop"] = mob->IsPetStop(); + row["is_pseudo_rooted"] = mob->IsPseudoRooted(); + row["is_raid_grouped"] = mob->IsRaidGrouped(); + row["is_rare_spawn"] = mob->IsRareSpawn(); + row["is_roamer"] = mob->IsRoamer(); + row["is_rooted"] = mob->IsRooted(); + row["is_running"] = mob->IsRunning(); + row["is_silenced"] = mob->IsSilenced(); + row["is_stunned"] = mob->IsStunned(); + row["is_tar_lock_pet"] = mob->IsTargetLockPet(); + row["is_tarable"] = mob->IsTargetable(); + row["is_tared"] = mob->IsTargeted(); + row["is_temp_pet"] = mob->IsTempPet(); + row["is_trackable"] = mob->IsTrackable(); + row["item_hp_bonuses"] = mob->GetItemHPBonuses(); + row["last_name"] = mob->GetLastName(); + row["level"] = mob->GetLevel(); + row["luclin_face"] = mob->GetLuclinFace(); + row["mana"] = mob->GetMana(); + row["mana_percent"] = mob->GetManaPercent(); + row["mana_ratio"] = mob->GetManaRatio(); + row["max_hp"] = mob->GetMaxHP(); + row["max_mana"] = mob->GetMaxMana(); + row["melee_mitigation"] = mob->GetMeleeMitigation(); + row["mitigation_ac"] = mob->GetMitigationAC(); + row["movespeed"] = mob->GetMovespeed(); + row["name"] = mob->GetName(); + row["next_hp_event"] = mob->GetNextHPEvent(); + row["next_inc_hp_event"] = mob->GetNextIncHPEvent(); + row["npc_assist_cap"] = mob->NPCAssistCap(); + row["npc_type_id"] = mob->GetNPCTypeID(); + row["orig_level"] = mob->GetOrigLevel(); + row["orig_name"] = mob->GetOrigName(); + row["owner_id"] = mob->GetOwnerID(); + row["pet_id"] = mob->GetPetID(); + row["pet_power"] = mob->GetPetPower(); + row["pet_tar_lock_id"] = mob->GetPetTargetLockID(); + row["qglobal"] = mob->GetQglobal(); + row["race"] = mob->GetRace(); + row["run_anim_speed"] = mob->GetRunAnimSpeed(); + row["sanctuary"] = mob->Sanctuary(); + row["see_hide"] = mob->SeeHide(); + row["see_improved_hide"] = mob->SeeImprovedHide(); + row["see_invisible"] = mob->SeeInvisible(); + row["see_invisible_undead"] = mob->SeeInvisibleUndead(); + row["size"] = mob->GetSize(); + row["slow_mitigation"] = mob->GetSlowMitigation(); + row["snared_amount"] = mob->GetSnaredAmount(); + row["spawned"] = mob->Spawned(); + row["spell_hp_bonuses"] = mob->GetSpellHPBonuses(); + row["spell_light_type"] = mob->GetSpellLightType(); + row["spell_power_distance_mod"] = mob->GetSpellPowerDistanceMod(); + row["spell_x"] = mob->GetSpellX(); + row["spell_y"] = mob->GetSpellY(); + row["spell_z"] = mob->GetSpellZ(); + row["tar_ring_x"] = mob->GetTargetRingX(); + row["tar_ring_y"] = mob->GetTargetRingY(); + row["tar_ring_z"] = mob->GetTargetRingZ(); + row["temp_pet_count"] = mob->GetTempPetCount(); + row["texture"] = mob->GetTexture(); + row["trap_slots"] = mob->GetTrapSlots(); + row["try_death_save"] = mob->TryDeathSave(); + row["try_divine_save"] = mob->TryDivineSave(); + row["try_spell_on_death"] = mob->TrySpellOnDeath(); + row["update_active_light"] = mob->UpdateActiveLight(); + row["wander_type"] = mob->GetWanderType(); + + response.append(row); + } +} + +void callGetZoneAttributes(Json::Value &response) +{ + Json::Value row; + + row["aggro_limit_reached"] = zone->AggroLimitReached(); + row["allow_mercs"] = zone->AllowMercs(); + row["buff_timers_suspended"] = zone->BuffTimersSuspended(); + row["can_bind"] = zone->CanBind(); + row["can_cast_outdoor"] = zone->CanCastOutdoor(); + row["can_do_combat"] = zone->CanDoCombat(); + row["can_levitate"] = zone->CanLevitate(); + row["count_auth"] = zone->CountAuth(); + row["count_spawn2"] = zone->CountSpawn2(); + row["file_name"] = zone->GetFileName(); + row["graveyard_id"] = zone->graveyard_id(); + row["graveyard_zoneid"] = zone->graveyard_zoneid(); + row["has_graveyard"] = zone->HasGraveyard(); + row["has_map"] = zone->HasMap(); + row["has_water_map"] = zone->HasWaterMap(); + row["has_weather"] = zone->HasWeather(); + row["instance_id"] = zone->GetInstanceID(); + row["instance_version"] = zone->GetInstanceVersion(); + row["instant_grids"] = zone->InstantGrids(); + row["is_city"] = zone->IsCity(); + row["is_hotzone"] = zone->IsHotzone(); + row["is_instance_persistent"] = zone->IsInstancePersistent(); + row["is_pvp_zone"] = zone->IsPVPZone(); + row["is_static_zone"] = zone->IsStaticZone(); + row["is_ucs_server_available"] = zone->IsUCSServerAvailable(); + row["long_name"] = zone->GetLongName(); + row["max_clients"] = zone->GetMaxClients(); + row["mobs_aggro_count"] = zone->MobsAggroCount(); + row["save_zone_cfg"] = zone->SaveZoneCFG(); + row["short_name"] = zone->GetShortName(); + row["total_blocked_spells"] = zone->GetTotalBlockedSpells(); + row["zone_id"] = zone->GetZoneID(); + row["zone_type"] = zone->GetZoneType(); + + response.append(row); +} + +void EQEmuApiZoneDataService::get(Json::Value &response, const std::vector &args) +{ + std::string method = args[0]; + + if (method == "get_npc_list_detail") { + callGetNpcListDetail(response); + } + if (method == "get_mob_list_detail") { + callGetMobListDetail(response); + } + if (method == "get_zone_attributes") { + callGetZoneAttributes(response); + } +} diff --git a/zone/eqemu_api_zone_data_service.h b/zone/eqemu_api_zone_data_service.h new file mode 100644 index 000000000..b6ed250a9 --- /dev/null +++ b/zone/eqemu_api_zone_data_service.h @@ -0,0 +1,32 @@ +/** + * 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 + * + */ + +#ifndef EQEMU_API_ZONE_DATA_SERVICE_H +#define EQEMU_API_ZONE_DATA_SERVICE_H + +#include "../common/json/json.h" + +class EQEmuApiZoneDataService { +public: + static void get(Json::Value &response, const std::vector &args); +}; + + +#endif //EQEMU_API_ZONE_DATA_SERVICE_H diff --git a/zone/net.cpp b/zone/net.cpp index 6800e078d..44e584091 100644 --- a/zone/net.cpp +++ b/zone/net.cpp @@ -67,6 +67,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "../common/event/event_loop.h" #include "../common/event/timer.h" #include "../common/net/eqstream.h" +#include "../common/net/servertalk_server.h" #include #include @@ -90,6 +91,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #else #include #include "../common/unix.h" +#include "../common/net/console_server.h" +#include "console.h" + #endif volatile bool RunLoops = true; @@ -446,24 +450,50 @@ int main(int argc, char** argv) { Log(Logs::Detail, Logs::None, "Main thread running with thread id %d", pthread_self()); #endif + bool worldwasconnected = worldserver.Connected(); + bool eqsf_open = false; + bool telnet_server_opened = false; + Timer quest_timers(100); UpdateWindowTitle(); - bool worldwasconnected = worldserver.Connected(); std::shared_ptr eqss; EQStreamInterface *eqsi; - bool eqsf_open = false; std::unique_ptr eqsm; std::chrono::time_point frame_prev = std::chrono::system_clock::now(); + std::unique_ptr console; auto loop_fn = [&](EQ::Timer* t) { //Advance the timer to our current point in time Timer::SetCurrentTime(); - //Calculate frame time + /** + * Calculate frame time + */ std::chrono::time_point frame_now = std::chrono::system_clock::now(); frame_time = std::chrono::duration_cast>(frame_now - frame_prev).count(); frame_prev = frame_now; + /** + * Telnet server + */ + if (!telnet_server_opened && Config->ZonePort != 0) { + if (Config->TelnetEnabled) { + Log( + Logs::General, + Logs::Zone_Server, + "Telnet Console (TCP) listener started (%s:%u).", + Config->TelnetIP.c_str(), + Config->ZonePort + ); + console.reset(new EQ::Net::ConsoleServer(Config->TelnetIP, Config->ZonePort)); + RegisterConsoleFunctions(console); + telnet_server_opened = true; + } + } + + /** + * EQStreamManager + */ if (!eqsf_open && Config->ZonePort != 0) { Log(Logs::General, Logs::Zone_Server, "Starting EQ Network server on port %d", Config->ZonePort); diff --git a/zone/zone.cpp b/zone/zone.cpp index 923e37a39..4157683dc 100755 --- a/zone/zone.cpp +++ b/zone/zone.cpp @@ -1834,33 +1834,6 @@ void Zone::ShowSpawnStatusByID(Mob* client, uint32 spawnid) client->Message(0, "No matching spawn id was found in this zone."); } - -bool Zone::RemoveSpawnEntry(uint32 spawnid) -{ - LinkedListIterator iterator(spawn2_list); - - - iterator.Reset(); - while(iterator.MoreElements()) - { - if(iterator.GetData()->GetID() == spawnid) - { - iterator.RemoveCurrent(); - return true; - } - else - iterator.Advance(); - } -return false; -} - -bool Zone::RemoveSpawnGroup(uint32 in_id) { - if(spawn_group_list.RemoveSpawnGroup(in_id)) - return true; - else - return false; -} - bool ZoneDatabase::GetDecayTimes(npcDecayTimes_Struct *npcCorpseDecayTimes) { const std::string query = diff --git a/zone/zone.h b/zone/zone.h index 4eaabfb8a..1ea0c0828 100755 --- a/zone/zone.h +++ b/zone/zone.h @@ -31,32 +31,31 @@ #include "pathfinder_interface.h" #include "global_loot_manager.h" -struct ZonePoint -{ - float x; - float y; - float z; - float heading; +struct ZonePoint { + float x; + float y; + float z; + float heading; uint16 number; - float target_x; - float target_y; - float target_z; - float target_heading; + float target_x; + float target_y; + float target_z; + float target_heading; uint16 target_zone_id; - int32 target_zone_instance; + int32 target_zone_instance; uint32 client_version_mask; }; struct ZoneClientAuth_Struct { - uint32 ip; // client's IP address - uint32 wid; // client's WorldID# - uint32 accid; - int16 admin; - uint32 charid; - bool tellsoff; - char charname[64]; - char lskey[30]; - bool stale; + uint32 ip; // client's IP address + uint32 wid; // client's WorldID# + uint32 accid; + int16 admin; + uint32 charid; + bool tellsoff; + char charname[64]; + char lskey[30]; + bool stale; }; struct ZoneEXPModInfo { @@ -65,11 +64,11 @@ struct ZoneEXPModInfo { }; struct item_tick_struct { - uint32 itemid; - uint32 chance; - uint32 level; - int16 bagslot; - std::string qglobal; + uint32 itemid; + uint32 chance; + uint32 level; + int16 bagslot; + std::string qglobal; }; class Client; @@ -81,290 +80,292 @@ struct NPCType; struct ServerZoneIncomingClient_Struct; class MobMovementManager; -class Zone -{ +class Zone { public: static bool Bootup(uint32 iZoneID, uint32 iInstanceID, bool iStaticZone = false); static void Shutdown(bool quite = false); - Zone(uint32 in_zoneid, uint32 in_instanceid, const char* in_short_name); + Zone(uint32 in_zoneid, uint32 in_instanceid, const char *in_short_name); ~Zone(); - /* When zone has its own version of time */ - bool is_zone_time_localized; - - bool Init(bool iStaticZone); - bool LoadZoneCFG(const char* filename, uint16 instance_id); - bool SaveZoneCFG(); - bool IsLoaded(); - bool IsPVPZone() { return pvpzone; } - inline const char* GetLongName() { return long_name; } - inline const char* GetFileName() { return file_name; } - inline const char* GetShortName() { return short_name; } - inline const uint32 GetZoneID() const { return zoneid; } - inline const uint32 GetInstanceID() const { return instanceid; } - inline const uint16 GetInstanceVersion() const { return instanceversion; } - inline const bool IsInstancePersistent() const { return pers_instance; } - inline const uint8 GetZoneType() const { return zone_type; } - - inline Timer* GetInstanceTimer() { return Instance_Timer; } - Timer spawn2_timer; - - inline glm::vec3 GetSafePoint() { return m_SafePoint; } - inline const uint32& graveyard_zoneid() { return pgraveyard_zoneid; } - inline glm::vec4 GetGraveyardPoint() { return m_Graveyard; } - inline const uint32& graveyard_id() { return pgraveyard_id; } - - inline const uint32& GetMaxClients() { return pMaxClients; } - - //new AA - void LoadAlternateAdvancement(); AA::Ability *GetAlternateAdvancementAbility(int id); AA::Ability *GetAlternateAdvancementAbilityByRank(int rank_id); AA::Rank *GetAlternateAdvancementRank(int rank_id); - std::pair GetAlternateAdvancementAbilityAndRank(int id, int points_spent); - - void LoadZoneDoors(const char* zone, int16 version); - bool LoadZoneObjects(); - bool LoadGroundSpawns(); - void ReloadStaticData(); - - uint32 CountSpawn2(); - ZonePoint* GetClosestZonePoint(const glm::vec3& location, const char* to_name, Client *client, float max_distance = 40000.0f); - ZonePoint* GetClosestZonePoint(const glm::vec3& location, uint32 to, Client *client, float max_distance = 40000.0f); - ZonePoint* GetClosestZonePointWithoutZone(float x, float y, float z, Client *client, float max_distance = 40000.0f); - SpawnGroupList spawn_group_list; - - bool RemoveSpawnEntry(uint32 spawnid); - bool RemoveSpawnGroup(uint32 in_id); - - bool Process(); - void Despawn(uint32 spawngroupID); - - bool Depop(bool StartSpawnTimer = false); - void Repop(uint32 delay = 0); - void RepopClose(const glm::vec4& client_position, uint32 repop_distance); - void ClearNPCTypeCache(int id); - void SpawnStatus(Mob* client); - void ShowEnabledSpawnStatus(Mob* client); - void ShowDisabledSpawnStatus(Mob* client); - void ShowSpawnStatusByID(Mob* client, uint32 spawnid); - void StartShutdownTimer(uint32 set_time = (RuleI(Zone, AutoShutdownDelay))); - void ChangeWeather(); - bool HasWeather(); - void AddAuth(ServerZoneIncomingClient_Struct* szic); - void RemoveAuth(const char* iCharName); - void ResetAuth(); - bool GetAuth(uint32 iIP, const char* iCharName, uint32* oWID = 0, uint32* oAccID = 0, uint32* oCharID = 0, int16* oStatus = 0, char* oLSKey = 0, bool* oTellsOff = 0); - uint32 CountAuth(); - - void AddAggroMob() { aggroedmobs++; } - void DelAggroMob() { aggroedmobs--; } - bool AggroLimitReached() { return (aggroedmobs>10)?true:false; } // change this value, to allow more NPCs to autoaggro - int32 MobsAggroCount() { return aggroedmobs; } - inline bool InstantGrids() { return(!initgrids_timer.Enabled()); } - void SetStaticZone(bool sz) { staticzone = sz; } - inline bool IsStaticZone() { return staticzone; } - inline void SetZoneHasCurrentTime(bool time) { zone_has_current_time = time; } - - void SpawnConditionChanged(const SpawnCondition &c, int16 old_value); - - void GetMerchantDataForZoneLoad(); - void LoadNewMerchantData(uint32 merchantid); - void LoadTempMerchantData(); - uint32 GetTempMerchantQuantity(uint32 NPCID, uint32 Slot); - int SaveTempItem(uint32 merchantid, uint32 npcid, uint32 item, int32 charges, bool sold=false); - void LoadMercTemplates(); - void LoadMercSpells(); - void LoadLevelEXPMods(); - MercTemplate* GetMercTemplate( uint32 template_id ); - - void SetInstanceTimer(uint32 new_duration); - void LoadLDoNTraps(); - void LoadLDoNTrapEntries(); - void LoadAdventureFlavor(); - - std::map npctable; - std::map merctable; - std::map > merchanttable; - std::map > tmpmerchanttable; - std::map adventure_entry_list_flavor; - std::map ldon_trap_list; - std::map > ldon_trap_entry_list; - std::map > merc_stance_list; - std::map merc_templates; - std::map > merc_spells_list; - std::map level_exp_mod; - std::list VeteranRewards; - std::list AlternateCurrencies; - char *adv_data; + bool is_zone_time_localized; + bool AggroLimitReached() { return (aggroedmobs > 10) ? true : false; } + bool AllowMercs() const { return (allow_mercs); } + bool CanBind() const { return (can_bind); } + bool CanCastOutdoor() const { return (can_castoutdoor); } //qadar + bool CanDoCombat() const { return (can_combat); } + bool CanLevitate() const { return (can_levitate); } // Magoth78 + bool Depop(bool StartSpawnTimer = false); bool did_adventure_actions; + bool GetAuth( + uint32 iIP, + const char *iCharName, + uint32 *oWID = 0, + uint32 *oAccID = 0, + uint32 *oCharID = 0, + int16 *oStatus = 0, + char *oLSKey = 0, + bool *oTellsOff = 0 + ); + bool HasGraveyard(); + bool HasWeather(); + bool Init(bool iStaticZone); + bool IsCity() const { return (is_city); } + bool IsHotzone() const { return (is_hotzone); } + bool IsLoaded(); + bool IsPVPZone() { return pvpzone; } + bool IsSpellBlocked(uint32 spell_id, const glm::vec3 &location); + bool IsUCSServerAvailable() { return m_ucss_available; } + bool LoadGroundSpawns(); + bool LoadZoneCFG(const char *filename, uint16 instance_id); + bool LoadZoneObjects(); + bool Process(); + bool SaveZoneCFG(); - //new AA - std::unordered_map> aa_abilities; - std::unordered_map> aa_ranks; + char *adv_data; - void DoAdventureCountIncrease(); - void DoAdventureAssassinationCountIncrease(); - void DoAdventureActions(); - void LoadVeteranRewards(); - void LoadAlternateCurrencies(); - void LoadNPCEmotes(LinkedList* NPCEmoteList); - void ReloadWorld(uint32 Option); - void ReloadMerchants(); + const char *GetSpellBlockedMessage(uint32 spell_id, const glm::vec3 &location); - Map *zonemap; - WaterMap *watermap; - IPathfinder *pathing; - NewZone_Struct newzone_data; + EQEmu::Random random; + EQTime zone_time; - SpawnConditionManager spawn_conditions; + ZonePoint *GetClosestZonePoint(const glm::vec3 &location, const char *to_name, Client *client, float max_distance = 40000.0f); - EQTime zone_time; - void GetTimeSync(); - void SetDate(uint16 year, uint8 month, uint8 day, uint8 hour, uint8 minute); - void SetTime(uint8 hour, uint8 minute, bool update_world = true); - - void weatherSend(Client* client = nullptr); - bool CanBind() const { return(can_bind); } - bool IsCity() const { return(is_city); } - bool CanDoCombat() const { return(can_combat); } - bool CanLevitate() const {return(can_levitate); } // Magoth78 - bool CanCastOutdoor() const {return(can_castoutdoor);} //qadar - bool AllowMercs() const {return(allow_mercs);} - bool IsHotzone() const { return(is_hotzone); } - inline bool BuffTimersSuspended() const { return newzone_data.SuspendBuffs != 0; }; - - time_t weather_timer; - uint8 weather_intensity; - uint8 zone_weather; - - uint8 loglevelvar; - uint8 merchantvar; - uint8 tradevar; - uint8 lootvar; - - bool HasGraveyard(); - void SetGraveyard(uint32 zoneid, const glm::vec4& graveyardPosition); - - void LoadBlockedSpells(uint32 zoneid); - void ClearBlockedSpells(); - bool IsSpellBlocked(uint32 spell_id, const glm::vec3& location); - const char *GetSpellBlockedMessage(uint32 spell_id, const glm::vec3& location); - int GetTotalBlockedSpells() { return totalBS; } + inline bool BuffTimersSuspended() const { return newzone_data.SuspendBuffs != 0; }; inline bool HasMap() { return zonemap != nullptr; } inline bool HasWaterMap() { return watermap != nullptr; } - - QGlobalCache *GetQGlobals() { return qGlobals; } - QGlobalCache *CreateQGlobals() { qGlobals = new QGlobalCache(); return qGlobals; } - void UpdateQGlobal(uint32 qid, QGlobal newGlobal); - void DeleteQGlobal(std::string name, uint32 npcID, uint32 charID, uint32 zoneID); - - LinkedList spawn2_list; - LinkedList zone_point_list; - uint32 numzonepoints; - - LinkedList NPCEmoteList; - - void LoadTickItems(); - uint32 GetSpawnKillCount(uint32 in_spawnid); - void UpdateHotzone(); - std::unordered_map tick_items; - + inline bool InstantGrids() { return (!initgrids_timer.Enabled()); } + inline bool IsStaticZone() { return staticzone; } + inline const bool IsInstancePersistent() const { return pers_instance; } + inline const char *GetFileName() { return file_name; } + inline const char *GetLongName() { return long_name; } + inline const char *GetShortName() { return short_name; } + inline const uint8 GetZoneType() const { return zone_type; } + inline const uint16 GetInstanceVersion() const { return instanceversion; } + inline const uint32 &GetMaxClients() { return pMaxClients; } + inline const uint32 &graveyard_id() { return pgraveyard_id; } + inline const uint32 &graveyard_zoneid() { return pgraveyard_zoneid; } + inline const uint32 GetInstanceID() const { return instanceid; } + inline const uint32 GetZoneID() const { return zoneid; } + inline glm::vec3 GetSafePoint() { return m_SafePoint; } + inline glm::vec4 GetGraveyardPoint() { return m_Graveyard; } inline std::vector GetGlobalLootTables(NPC *mob) const { return m_global_loot.GetGlobalLootTables(mob); } + inline Timer *GetInstanceTimer() { return Instance_Timer; } inline void AddGlobalLootEntry(GlobalLootEntry &in) { return m_global_loot.AddEntry(in); } - inline void ShowZoneGlobalLoot(Client *to) { m_global_loot.ShowZoneGlobalLoot(to); } + inline void SetZoneHasCurrentTime(bool time) { zone_has_current_time = time; } inline void ShowNPCGlobalLoot(Client *to, NPC *who) { m_global_loot.ShowNPCGlobalLoot(to, who); } + inline void ShowZoneGlobalLoot(Client *to) { m_global_loot.ShowZoneGlobalLoot(to); } + int GetTotalBlockedSpells() { return totalBS; } + int SaveTempItem(uint32 merchantid, uint32 npcid, uint32 item, int32 charges, bool sold = false); + int32 MobsAggroCount() { return aggroedmobs; } + IPathfinder *pathing; + LinkedList NPCEmoteList; + LinkedList spawn2_list; + LinkedList zone_point_list; + Map *zonemap; + MercTemplate *GetMercTemplate(uint32 template_id); + NewZone_Struct newzone_data; + QGlobalCache *CreateQGlobals() + { + qGlobals = new QGlobalCache(); + return qGlobals; + } + QGlobalCache *GetQGlobals() { return qGlobals; } + SpawnConditionManager spawn_conditions; + SpawnGroupList spawn_group_list; + + std::list AlternateCurrencies; + std::list VeteranRewards; + std::map ldon_trap_list; + std::map merc_templates; + std::map merctable; + std::map npctable; + std::map > ldon_trap_entry_list; + std::map > merchanttable; + std::map > merc_spells_list; + std::map > merc_stance_list; + std::map > tmpmerchanttable; + std::map adventure_entry_list_flavor; + std::map level_exp_mod; + + std::pair GetAlternateAdvancementAbilityAndRank(int id, int points_spent); + + std::unordered_map tick_items; + std::unordered_map> aa_abilities; + std::unordered_map> aa_ranks; + + time_t weather_timer; + Timer spawn2_timer; + + uint8 weather_intensity; + uint8 zone_weather; + uint8 loglevelvar; + uint8 lootvar; + uint8 merchantvar; + uint8 tradevar; + uint32 numzonepoints; + uint32 CountAuth(); + uint32 CountSpawn2(); + uint32 GetSpawnKillCount(uint32 in_spawnid); + uint32 GetTempMerchantQuantity(uint32 NPCID, uint32 Slot); + + void AddAggroMob() { aggroedmobs++; } + void AddAuth(ServerZoneIncomingClient_Struct *szic); + void ChangeWeather(); + void ClearBlockedSpells(); + void ClearNPCTypeCache(int id); + void DelAggroMob() { aggroedmobs--; } + void DeleteQGlobal(std::string name, uint32 npcID, uint32 charID, uint32 zoneID); + void Despawn(uint32 spawngroupID); + void DoAdventureActions(); + void DoAdventureAssassinationCountIncrease(); + void DoAdventureCountIncrease(); + void GetMerchantDataForZoneLoad(); + void GetTimeSync(); + void LoadAdventureFlavor(); + void LoadAlternateAdvancement(); + void LoadAlternateCurrencies(); + void LoadBlockedSpells(uint32 zoneid); + void LoadLDoNTrapEntries(); + void LoadLDoNTraps(); + void LoadLevelEXPMods(); + void LoadMercSpells(); + void LoadMercTemplates(); + void LoadNewMerchantData(uint32 merchantid); + void LoadNPCEmotes(LinkedList *NPCEmoteList); + void LoadTempMerchantData(); + void LoadTickItems(); + void LoadVeteranRewards(); + void LoadZoneDoors(const char *zone, int16 version); + void ReloadStaticData(); + void ReloadWorld(uint32 Option); + void RemoveAuth(const char *iCharName); + void Repop(uint32 delay = 0); + void RepopClose(const glm::vec4 &client_position, uint32 repop_distance); void RequestUCSServerStatus(); + void ResetAuth(); + void SetDate(uint16 year, uint8 month, uint8 day, uint8 hour, uint8 minute); + void SetGraveyard(uint32 zoneid, const glm::vec4 &graveyardPosition); + void SetInstanceTimer(uint32 new_duration); + void SetStaticZone(bool sz) { staticzone = sz; } + void SetTime(uint8 hour, uint8 minute, bool update_world = true); void SetUCSServerAvailable(bool ucss_available, uint32 update_timestamp); - bool IsUCSServerAvailable() { return m_ucss_available; } + void ShowDisabledSpawnStatus(Mob *client); + void ShowEnabledSpawnStatus(Mob *client); + void ShowSpawnStatusByID(Mob *client, uint32 spawnid); + void SpawnConditionChanged(const SpawnCondition &c, int16 old_value); + void SpawnStatus(Mob *client); + void StartShutdownTimer(uint32 set_time = (RuleI(Zone, AutoShutdownDelay))); + void UpdateHotzone(); + void UpdateQGlobal(uint32 qid, QGlobal newGlobal); + void weatherSend(Client *client = nullptr); - // random object that provides random values for the zone - EQEmu::Random random; + WaterMap *watermap; + ZonePoint *GetClosestZonePoint(const glm::vec3 &location, uint32 to, Client *client, float max_distance = 40000.0f); + ZonePoint *GetClosestZonePointWithoutZone(float x, float y, float z, Client *client, float max_distance = 40000.0f); - static void GMSayHookCallBackProcess(uint16 log_category, std::string message){ - /* Cut messages down to 4000 max to prevent client crash */ - if (!message.empty()) + /** + * GMSay Callback for LogSys + * + * @param log_category + * @param message + */ + static void GMSayHookCallBackProcess(uint16 log_category, std::string message) + { + /** + * Cut messages down to 4000 max to prevent client crash + */ + if (!message.empty()) { message = message.substr(0, 4000); + } - /* Replace Occurrences of % or MessageStatus will crash */ + /** + * Replace Occurrences of % or MessageStatus will crash + */ find_replace(message, std::string("%"), std::string(".")); - if (message.find("\n") != std::string::npos){ + if (message.find("\n") != std::string::npos) { auto message_split = SplitString(message, '\n'); - entity_list.MessageStatus(0, 80, LogSys.GetGMSayColorFromCategory(log_category), "%s", message_split[0].c_str()); + entity_list.MessageStatus( + 0, + 80, + LogSys.GetGMSayColorFromCategory(log_category), + "%s", + message_split[0].c_str() + ); + for (size_t iter = 1; iter < message_split.size(); ++iter) { - entity_list.MessageStatus(0, 80, LogSys.GetGMSayColorFromCategory(log_category), "--- %s", message_split[iter].c_str()); + entity_list.MessageStatus( + 0, + 80, + LogSys.GetGMSayColorFromCategory(log_category), + "--- %s", + message_split[iter].c_str() + ); } } - else{ + else { entity_list.MessageStatus(0, 80, LogSys.GetGMSayColorFromCategory(log_category), "%s", message.c_str()); } } - //MODDING HOOKS + /** + * Modding hooks + */ void mod_init(); void mod_repop(); private: - uint32 zoneid; - uint32 instanceid; - uint16 instanceversion; - bool pers_instance; - char* short_name; - char file_name[16]; - char* long_name; - char* map_name; - bool pvpzone; + bool allow_mercs; + bool can_bind; + bool can_castoutdoor; + bool can_combat; + bool can_levitate; + bool is_city; + bool is_hotzone; + bool pers_instance; + bool pvpzone; + bool m_ucss_available; + bool staticzone; + bool zone_has_current_time; + char *long_name; + char *map_name; + char *short_name; + char file_name[16]; glm::vec3 m_SafePoint; - uint32 pMaxClients; - bool can_bind; - bool is_city; - bool can_combat; - bool can_castoutdoor; - bool can_levitate; - bool is_hotzone; - uint8 zone_type; - bool allow_mercs; - uint32 pgraveyard_id, pgraveyard_zoneid; glm::vec4 m_Graveyard; - int default_ruleset; + int default_ruleset; + int totalBS; + int32 aggroedmobs; + uint8 zone_type; + uint16 instanceversion; + uint32 instanceid; + uint32 pgraveyard_id, pgraveyard_zoneid; + uint32 pMaxClients; + uint32 zoneid; + uint32 m_last_ucss_update; + uint32 pQueuedMerchantsWorkID; + uint32 pQueuedTempMerchantsWorkID; - int totalBS; - ZoneSpellsBlocked *blocked_spells; + GlobalLootManager m_global_loot; + LinkedList client_auth_list; + MobMovementManager *mMovementManager; + QGlobalCache *qGlobals; + Timer *Instance_Shutdown_Timer; + Timer *Instance_Timer; + Timer *Instance_Warning_timer; + Timer *Weather_Timer; + Timer autoshutdown_timer; + Timer clientauth_timer; + Timer hotzone_timer; + Timer initgrids_timer; //delayed loading of initial grids. + Timer qglobal_purge_timer; + ZoneSpellsBlocked *blocked_spells; - /* - Spawn related things - */ - int32 aggroedmobs; - Timer initgrids_timer; //delayed loading of initial grids. - - - bool staticzone; - bool zone_has_current_time; - - uint32 pQueuedMerchantsWorkID; - uint32 pQueuedTempMerchantsWorkID; - - Timer autoshutdown_timer; - Timer clientauth_timer; - Timer qglobal_purge_timer; - Timer* Weather_Timer; - Timer* Instance_Timer; - Timer* Instance_Shutdown_Timer; - Timer* Instance_Warning_timer; - LinkedList client_auth_list; - QGlobalCache *qGlobals; - - Timer hotzone_timer; - - GlobalLootManager m_global_loot; - - bool m_ucss_available; - uint32 m_last_ucss_update; - - MobMovementManager *mMovementManager; }; #endif From 63d0f5ea1deb340c386b50f58e7e2beb7731151a Mon Sep 17 00:00:00 2001 From: Akkadius Date: Sat, 9 Mar 2019 23:10:11 -0600 Subject: [PATCH 02/11] Update CMakeLists.txt --- zone/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zone/CMakeLists.txt b/zone/CMakeLists.txt index 8b7bcfd93..908a1cb02 100644 --- a/zone/CMakeLists.txt +++ b/zone/CMakeLists.txt @@ -250,7 +250,7 @@ SET(zone_headers zone.h zone_config.h zonedb.h - zonedump.h eqemu_api_zone_data_service.cpp eqemu_api_zone_data_service.h) + zonedump.h) IF(EQEMU_DEPOP_INVALIDATES_CACHE) ADD_DEFINITIONS(-DDEPOP_INVALIDATES_NPC_TYPES_CACHE) From 81c6e7d5737900993ff059ff9a59a48156829ffe Mon Sep 17 00:00:00 2001 From: Akkadius Date: Sat, 9 Mar 2019 23:54:32 -0600 Subject: [PATCH 03/11] Add get_door_list_detail --- zone/eqemu_api_zone_data_service.cpp | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/zone/eqemu_api_zone_data_service.cpp b/zone/eqemu_api_zone_data_service.cpp index 7ded49b90..932888518 100644 --- a/zone/eqemu_api_zone_data_service.cpp +++ b/zone/eqemu_api_zone_data_service.cpp @@ -19,6 +19,7 @@ */ #include "eqemu_api_zone_data_service.h" +#include "doors.h" #include "npc.h" #include "zone.h" #include "entity.h" @@ -113,6 +114,43 @@ void callGetNpcListDetail(Json::Value &response) } } +void callGetDoorListDetail(Json::Value &response) +{ + auto &list = entity_list.GetDoorsList(); + + for (auto &iter : list) { + auto door = iter.second; + + Json::Value row; + + row["door_name"] = door->GetDoorName(); + row["client_version_mask"] = door->GetClientVersionMask(); + row["disable_timer"] = door->GetDisableTimer(); + row["door_db_id"] = door->GetDoorDBID(); + row["door_id"] = door->GetDoorID(); + row["door_param"] = door->GetDoorParam(); + row["entity_id"] = door->GetEntityID(); + row["guild_id"] = door->GetGuildID(); + row["incline"] = door->GetIncline(); + row["invert_state"] = door->GetInvertState(); + row["is_door"] = door->IsDoor(); + row["is_door_open"] = door->IsDoorOpen(); + row["is_ldon_door"] = door->IsLDoNDoor(); + row["key_item"] = door->GetKeyItem(); + row["lockpick"] = door->GetLockpick(); + row["no_keyring"] = door->GetNoKeyring(); + row["open_type"] = door->GetOpenType(); + row["size"] = door->GetSize(); + row["trigger_door_id"] = door->GetTriggerDoorID(); + row["trigger_type"] = door->GetTriggerType(); + row["x"] = door->GetX(); + row["y"] = door->GetY(); + row["z"] = door->GetZ(); + + response.append(row); + } +} + void callGetMobListDetail(Json::Value &response) { auto &list = entity_list.GetMobList(); @@ -364,6 +402,9 @@ void EQEmuApiZoneDataService::get(Json::Value &response, const std::vector Date: Sat, 9 Mar 2019 23:56:56 -0600 Subject: [PATCH 04/11] Add call get_object_list_detail --- zone/eqemu_api_zone_data_service.cpp | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/zone/eqemu_api_zone_data_service.cpp b/zone/eqemu_api_zone_data_service.cpp index 932888518..72f33f256 100644 --- a/zone/eqemu_api_zone_data_service.cpp +++ b/zone/eqemu_api_zone_data_service.cpp @@ -21,6 +21,7 @@ #include "eqemu_api_zone_data_service.h" #include "doors.h" #include "npc.h" +#include "object.h" #include "zone.h" #include "entity.h" #include @@ -150,6 +151,34 @@ void callGetDoorListDetail(Json::Value &response) response.append(row); } } +void callGetObjectListDetail(Json::Value &response) +{ + auto &list = entity_list.GetObjectList(); + + for (auto &iter : list) { + auto object = iter.second; + + Json::Value row; + + row["display_name"] = object->GetDisplayName(); + row["dbid"] = object->GetDBID(); + row["heading_data"] = object->GetHeadingData(); + row["icon"] = object->GetIcon(); + row["is_ground_spawn"] = object->IsGroundSpawn(); + row["item_id"] = object->GetItemID(); + row["model_name"] = object->GetModelName(); + row["size"] = object->GetSize(); + row["solid_type"] = object->GetSolidType(); + row["tilt_x"] = object->GetTiltX(); + row["tilt_y"] = object->GetTiltY(); + row["type"] = object->GetType(); + row["x"] = object->GetX(); + row["y"] = object->GetY(); + row["z"] = object->GetZ(); + + response.append(row); + } +} void callGetMobListDetail(Json::Value &response) { @@ -405,6 +434,9 @@ void EQEmuApiZoneDataService::get(Json::Value &response, const std::vector Date: Sun, 10 Mar 2019 00:04:13 -0600 Subject: [PATCH 05/11] Add call get_client_list_detail --- zone/eqemu_api_zone_data_service.cpp | 201 ++++++++++++++++++++++++++- 1 file changed, 199 insertions(+), 2 deletions(-) diff --git a/zone/eqemu_api_zone_data_service.cpp b/zone/eqemu_api_zone_data_service.cpp index 72f33f256..84977cb4f 100644 --- a/zone/eqemu_api_zone_data_service.cpp +++ b/zone/eqemu_api_zone_data_service.cpp @@ -18,12 +18,13 @@ * */ -#include "eqemu_api_zone_data_service.h" +#include "client.h" #include "doors.h" +#include "entity.h" +#include "eqemu_api_zone_data_service.h" #include "npc.h" #include "object.h" #include "zone.h" -#include "entity.h" #include extern Zone *zone; @@ -380,6 +381,199 @@ void callGetMobListDetail(Json::Value &response) } } +void callGetClientListDetail(Json::Value &response) +{ + auto &list = entity_list.GetClientList(); + + for (auto &iter : list) { + auto client = iter.second; + + Json::Value row; + + /** + * Main + */ + row["id"] = client->GetID(); + row["clean_name"] = client->GetCleanName(); + row["x"] = client->GetX(); + row["y"] = client->GetY(); + row["z"] = client->GetZ(); + row["heading"] = client->GetHeading(); + + /** + * Rest + */ + row["aa_percent"] = client->GetAAPercent(); + row["aa_points"] = client->GetAAPoints(); + row["aaxp"] = client->GetAAXP(); + row["account_age"] = client->GetAccountAge(); + row["account_creation"] = client->GetAccountCreation(); + row["account_id"] = client->AccountID(); + row["account_name"] = client->AccountName(); + row["act_agi"] = client->GetActAGI(); + row["act_cha"] = client->GetActCHA(); + row["act_dex"] = client->GetActDEX(); + row["act_int"] = client->GetActINT(); + row["act_sta"] = client->GetActSTA(); + row["act_str"] = client->GetActSTR(); + row["act_wis"] = client->GetActWIS(); + row["active_task_count"] = client->GetActiveTaskCount(); + row["admin"] = client->Admin(); + row["aggro_count"] = client->GetAggroCount(); + row["aggro_meter_available"] = client->AggroMeterAvailable(); + row["all_money"] = client->GetAllMoney(); + row["anon"] = client->GetAnon(); + row["atk_rating"] = client->GetATKRating(); + row["auto_attack_enabled"] = client->AutoAttackEnabled(); + row["auto_fire_enabled"] = client->AutoFireEnabled(); + row["auto_split_enabled"] = client->AutoSplitEnabled(); + row["base_agi"] = client->GetBaseAGI(); + row["base_beard"] = client->GetBaseBeard(); + row["base_beard_color"] = client->GetBaseBeardColor(); + row["base_cha"] = client->GetBaseCHA(); + row["base_class"] = client->GetBaseClass(); + row["base_corrup"] = client->GetBaseCorrup(); + row["base_details"] = client->GetBaseDetails(); + row["base_dex"] = client->GetBaseDEX(); + row["base_eye_color"] = client->GetBaseEyeColor(); + row["base_face"] = client->GetBaseFace(); + row["base_gender"] = client->GetBaseGender(); + row["base_hair_color"] = client->GetBaseHairColor(); + row["base_hair_style"] = client->GetBaseHairStyle(); + row["base_heritage"] = client->GetBaseHeritage(); + row["base_hp"] = client->GetBaseHP(); + row["base_int"] = client->GetBaseINT(); + row["base_ph_r"] = client->GetBasePhR(); + row["base_race"] = client->GetBaseRace(); + row["base_sta"] = client->GetBaseSTA(); + row["base_str"] = client->GetBaseSTR(); + row["base_tattoo"] = client->GetBaseTattoo(); + row["base_wis"] = client->GetBaseWIS(); + row["become_npc_level"] = client->GetBecomeNPCLevel(); + row["boat_id"] = client->GetBoatID(); + row["buyer_welcome_message"] = client->GetBuyerWelcomeMessage(); + row["calc_atk"] = client->CalcATK(); + row["calc_base_mana"] = client->CalcBaseMana(); + row["calc_current_weight"] = client->CalcCurrentWeight(); + row["calc_endurance_regen_cap"] = client->CalcEnduranceRegenCap(); + row["calc_hp_regen_cap"] = client->CalcHPRegenCap(); + row["calc_mana_regen_cap"] = client->CalcManaRegenCap(); + row["calc_max_mana"] = client->CalcMaxMana(); + row["can_fast_regen"] = client->CanFastRegen(); + row["can_fish"] = client->CanFish(); + row["can_med_on_horse"] = client->CanMedOnHorse(); + row["carried_money"] = client->GetCarriedMoney(); + row["char_max_level_from_bucket"] = client->GetCharMaxLevelFromBucket(); + row["char_max_level_from_q_global"] = client->GetCharMaxLevelFromQGlobal(); + row["character_id"] = client->CharacterID(); + row["check_can_unsuspend_merc"] = client->CheckCanUnsuspendMerc(); + row["check_double_attack"] = client->CheckDoubleAttack(); + row["check_double_ranged_attack"] = client->CheckDoubleRangedAttack(); + row["check_dual_wield"] = client->CheckDualWield(); + row["check_trade_non_droppable"] = client->CheckTradeNonDroppable(); + row["check_triple_attack"] = client->CheckTripleAttack(); + row["client_max_level"] = client->GetClientMaxLevel(); + row["client_version_bit"] = client->ClientVersionBit(); + row["connected"] = client->Connected(); + row["copper"] = client->GetCopper(); + row["corpse_count"] = client->GetCorpseCount(); + row["duel_tar"] = client->GetDuelTarget(); + row["ebon_crystals"] = client->GetEbonCrystals(); + row["endurance"] = client->GetEndurance(); + row["endurance_percent"] = client->GetEndurancePercent(); + row["exp"] = client->GetEXP(); + row["face"] = client->GetFace(); + row["feigned"] = client->GetFeigned(); + row["gm"] = client->GetGM(); + row["gm_speed"] = client->GetGMSpeed(); + row["gold"] = client->GetGold(); + row["group_exp"] = client->GetGroupEXP(); + row["group_leadership_aa_health_enhancement"] = client->GroupLeadershipAAHealthEnhancement(); + row["group_leadership_aa_health_regeneration"] = client->GroupLeadershipAAHealthRegeneration(); + row["group_leadership_aa_mana_enhancement"] = client->GroupLeadershipAAManaEnhancement(); + row["group_leadership_aa_offense_enhancement"] = client->GroupLeadershipAAOffenseEnhancement(); + row["group_points"] = client->GetGroupPoints(); + row["guild_id"] = client->GuildID(); + row["guild_rank"] = client->GuildRank(); + row["has_adventure_data"] = client->HasAdventureData(); + row["hide_me"] = client->GetHideMe(); + row["horse_id"] = client->GetHorseId(); + row["hunger"] = client->GetHunger(); + row["hungry"] = client->Hungry(); + row["in_zone"] = client->InZone(); + row["instance_id"] = client->GetInstanceID(); + row["interrogate_inv_state"] = client->GetInterrogateInvState(); + row["ip"] = client->GetIP(); + row["is_become_npc"] = client->IsBecomeNPC(); + row["is_buyer"] = client->IsBuyer(); + row["is_dead"] = client->IsDead(); + row["is_dragging_corpse"] = client->IsDraggingCorpse(); + row["is_dueling"] = client->IsDueling(); + row["is_guild_banker"] = client->IsGuildBanker(); + row["is_hovering_for_respawn"] = client->IsHoveringForRespawn(); + row["is_in_a_guild"] = client->IsInAGuild(); + row["is_ld"] = client->IsLD(); + row["is_leadership_exp_on"] = client->IsLeadershipEXPOn(); + row["is_lfp"] = client->IsLFP(); + row["is_medding"] = client->IsMedding(); + row["is_on_adventure"] = client->IsOnAdventure(); + row["is_rezz_pending"] = client->IsRezzPending(); + row["is_sitting"] = client->IsSitting(); + row["is_starved"] = client->IsStarved(); + row["is_tracking"] = client->IsTracking(); + row["is_trader"] = client->IsTrader(); + row["is_unconscious"] = client->IsUnconscious(); + row["ldon_losses"] = client->GetLDoNLosses(); + row["ldon_wins"] = client->GetLDoNWins(); + row["last_inv_snapshot_time"] = client->GetLastInvSnapshotTime(); + row["last_name"] = client->GetLastName(); + row["level2"] = client->GetLevel2(); + row["level_regen"] = client->LevelRegen(); + row["ls_account_id"] = client->LSAccountID(); + row["max_endurance"] = client->GetMaxEndurance(); + row["max_x_tars"] = client->GetMaxXTargets(); + row["merc_id"] = client->GetMercID(); + row["merc_only_or_no_group"] = client->MercOnlyOrNoGroup(); + row["merc_slot"] = client->GetMercSlot(); + row["next_inv_snapshot_time"] = client->GetNextInvSnapshotTime(); + row["num_mercs"] = client->GetNumMercs(); + row["pending_adventure_create"] = client->GetPendingAdventureCreate(); + row["pending_adventure_door_click"] = client->GetPendingAdventureDoorClick(); + row["pending_adventure_leave"] = client->GetPendingAdventureLeave(); + row["pending_adventure_request"] = client->GetPendingAdventureRequest(); + row["pending_guild_invitation"] = client->GetPendingGuildInvitation(); + row["platinum"] = client->GetPlatinum(); + row["port"] = client->GetPort(); + row["primary_skill_value"] = client->GetPrimarySkillValue(); + row["proximity_x"] = client->ProximityX(); + row["proximity_y"] = client->ProximityY(); + row["proximity_z"] = client->ProximityZ(); + row["pvp_points"] = client->GetPVPPoints(); + row["radiant_crystals"] = client->GetRadiantCrystals(); + row["raid_exp"] = client->GetRaidEXP(); + row["raid_points"] = client->GetRaidPoints(); + row["raw_item_ac"] = client->GetRawItemAC(); + row["required_aa_experience"] = client->GetRequiredAAExperience(); + row["revoked"] = client->GetRevoked(); + row["run_mode"] = client->GetRunMode(); + row["save_currency"] = client->SaveCurrency(); + row["save_task_state"] = client->SaveTaskState(); + row["silver"] = client->GetSilver(); + row["skill_points"] = client->GetSkillPoints(); + row["spent_aa"] = client->GetSpentAA(); + row["tgb"] = client->TGB(); + row["thirst"] = client->GetThirst(); + row["thirsty"] = client->Thirsty(); + row["total_atk"] = client->GetTotalATK(); + row["total_seconds_played"] = client->GetTotalSecondsPlayed(); + row["weight"] = client->GetWeight(); + row["wid"] = client->GetWID(); + row["x_tarting_available"] = client->XTargettingAvailable(); + + response.append(row); + } +} + void callGetZoneAttributes(Json::Value &response) { Json::Value row; @@ -428,6 +622,9 @@ void EQEmuApiZoneDataService::get(Json::Value &response, const std::vector Date: Sun, 10 Mar 2019 00:13:02 -0600 Subject: [PATCH 06/11] Add call get_corpse_list_detail --- zone/eqemu_api_zone_data_service.cpp | 46 +++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/zone/eqemu_api_zone_data_service.cpp b/zone/eqemu_api_zone_data_service.cpp index 84977cb4f..0073678c6 100644 --- a/zone/eqemu_api_zone_data_service.cpp +++ b/zone/eqemu_api_zone_data_service.cpp @@ -19,12 +19,13 @@ */ #include "client.h" -#include "doors.h" #include "entity.h" +#include "corpse.h" #include "eqemu_api_zone_data_service.h" #include "npc.h" #include "object.h" #include "zone.h" +#include "doors.h" #include extern Zone *zone; @@ -118,10 +119,10 @@ void callGetNpcListDetail(Json::Value &response) void callGetDoorListDetail(Json::Value &response) { - auto &list = entity_list.GetDoorsList(); + auto &door_list = entity_list.GetDoorsList(); - for (auto &iter : list) { - auto door = iter.second; + for (auto itr : door_list) { + Doors *door = itr.second; Json::Value row; @@ -152,6 +153,40 @@ void callGetDoorListDetail(Json::Value &response) response.append(row); } } + +void callGetCorpseListDetail(Json::Value &response) +{ + auto &corpse_list = entity_list.GetCorpseList(); + + for (auto itr : corpse_list) { + auto corpse = itr.second; + + Json::Value row; + + row["char_id"] = corpse->GetCharID(); + row["copper"] = corpse->GetCopper(); + row["corpse_dbid"] = corpse->GetCorpseDBID(); + row["count_items"] = corpse->CountItems(); + row["decay_time"] = corpse->GetDecayTime(); + row["gold"] = corpse->GetGold(); + row["is_become_npc_corpse"] = corpse->IsBecomeNPCCorpse(); + row["is_being_looted"] = corpse->IsBeingLooted(); + row["is_corpse"] = corpse->IsCorpse(); + row["is_locked"] = corpse->IsLocked(); + row["is_npc_corpse"] = corpse->IsNPCCorpse(); + row["is_player_corpse"] = corpse->IsPlayerCorpse(); + row["is_rezzed"] = corpse->IsRezzed(); + row["owner_name"] = corpse->GetOwnerName(); + row["platinum"] = corpse->GetPlatinum(); + row["player_kill_item"] = corpse->GetPlayerKillItem(); + row["rez_exp"] = corpse->GetRezExp(); + row["rez_time"] = corpse->GetRezTime(); + row["silver"] = corpse->GetSilver(); + + response.append(row); + } +} + void callGetObjectListDetail(Json::Value &response) { auto &list = entity_list.GetObjectList(); @@ -631,6 +666,9 @@ void EQEmuApiZoneDataService::get(Json::Value &response, const std::vector Date: Sun, 10 Mar 2019 01:09:04 -0600 Subject: [PATCH 07/11] Hook up world to its own api data service --- world/CMakeLists.txt | 2 + world/console.cpp | 656 ++++++++++++++++++++----- world/eqemu_api_world_data_service.cpp | 64 +++ world/eqemu_api_world_data_service.h | 32 ++ world/zonelist.cpp | 5 + world/zonelist.h | 74 +-- zone/eqemu_api_zone_data_service.cpp | 2 +- 7 files changed, 671 insertions(+), 164 deletions(-) create mode 100644 world/eqemu_api_world_data_service.cpp create mode 100644 world/eqemu_api_world_data_service.h diff --git a/world/CMakeLists.txt b/world/CMakeLists.txt index e8b999107..fa4b6ecc6 100644 --- a/world/CMakeLists.txt +++ b/world/CMakeLists.txt @@ -8,6 +8,7 @@ SET(world_sources clientlist.cpp console.cpp eql_config.cpp + eqemu_api_world_data_service.cpp launcher_link.cpp launcher_list.cpp lfplist.cpp @@ -35,6 +36,7 @@ SET(world_headers clientlist.h console.h eql_config.h + eqemu_api_world_data_service.h launcher_link.h launcher_list.h lfplist.h diff --git a/world/console.cpp b/world/console.cpp index 8326737c2..394a21e61 100644 --- a/world/console.cpp +++ b/world/console.cpp @@ -1,3 +1,23 @@ +/** + * 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 + * + */ + #include "console.h" #include "clientlist.h" #include "login_server.h" @@ -9,12 +29,19 @@ #include "zoneserver.h" #include "../common/string_util.h" #include "../common/md5.h" +#include "eqemu_api_world_data_service.h" -extern ClientList client_list; -extern ZSList zoneserver_list; +extern ClientList client_list; +extern ZSList zoneserver_list; extern LoginServerList loginserverlist; -struct EQ::Net::ConsoleLoginStatus CheckLogin(const std::string& username, const std::string& password) { +/** + * @param username + * @param password + * @return + */ +struct EQ::Net::ConsoleLoginStatus CheckLogin(const std::string &username, const std::string &password) +{ struct EQ::Net::ConsoleLoginStatus ret; ret.account_id = database.CheckLogin(username.c_str(), password.c_str()); if (ret.account_id == 0) { @@ -25,31 +52,103 @@ struct EQ::Net::ConsoleLoginStatus CheckLogin(const std::string& username, const database.GetAccountName(ret.account_id, account_name); ret.account_name = account_name; - ret.status = database.CheckStatus(ret.account_id); + ret.status = database.CheckStatus(ret.account_id); return ret; } -void ConsoleNull(EQ::Net::ConsoleServerConnection* connection, const std::string& command, const std::vector& args) { +/** + * @param connection + * @param command + * @param args + */ +void ConsoleNull( + EQ::Net::ConsoleServerConnection *connection, + const std::string &command, + const std::vector &args +) +{ } -void ConsoleWhoami(EQ::Net::ConsoleServerConnection* connection, const std::string& command, const std::vector& args) { + +/** + * @param connection + * @param command + * @param args + */ +void ConsoleApi( + EQ::Net::ConsoleServerConnection *connection, + const std::string &command, + const std::vector &args +) +{ + Json::Value root; + Json::Value response; + + BenchTimer timer; + timer.reset(); + + EQEmuApiWorldDataService::get(response, args); + + std::string method = args[0]; + + root["execution_time"] = std::to_string(timer.elapsed()); + root["method"] = method; + root["data"] = response; + + std::stringstream payload; + payload << root; + + connection->SendLine(payload.str()); +} + +/** + * @param connection + * @param command + * @param args + */ +void ConsoleWhoami( + EQ::Net::ConsoleServerConnection *connection, + const std::string &command, + const std::vector &args +) +{ connection->SendLine(fmt::format("You are logged in as '{0}'", connection->UserName())); connection->SendLine(fmt::format("You are known as '*{0}'", connection->UserName())); connection->SendLine(fmt::format("AccessLevel: '{0}'", connection->Admin())); } -void ConsoleZoneStatus(EQ::Net::ConsoleServerConnection* connection, const std::string& command, const std::vector& args) { +/** + * @param connection + * @param command + * @param args + */ +void ConsoleZoneStatus( + EQ::Net::ConsoleServerConnection *connection, + const std::string &command, + const std::vector &args +) +{ WorldConsoleTCPConnection console_connection(connection); zoneserver_list.SendZoneStatus(0, connection->Admin(), &console_connection); } -void ConsoleWho(EQ::Net::ConsoleServerConnection* connection, const std::string& command, const std::vector& args) { +/** + * @param connection + * @param command + * @param args + */ +void ConsoleWho( + EQ::Net::ConsoleServerConnection *connection, + const std::string &command, + const std::vector &args +) +{ Who_All_Struct whom; memset(&whom, 0, sizeof(whom)); - whom.lvllow = 0xFFFF; - whom.lvlhigh = 0xFFFF; - whom.wclass = 0xFFFF; - whom.wrace = 0xFFFF; + whom.lvllow = 0xFFFF; + whom.lvlhigh = 0xFFFF; + whom.wclass = 0xFFFF; + whom.wrace = 0xFFFF; whom.gmlookup = 0xFFFF; for (auto &arg : args) { @@ -58,13 +157,15 @@ void ConsoleWho(EQ::Net::ConsoleServerConnection* connection, const std::string& } else if (StringIsNumber(arg)) { if (whom.lvllow == 0xFFFF) { - whom.lvllow = atoi(arg.c_str()); + whom.lvllow = atoi(arg.c_str()); whom.lvlhigh = whom.lvllow; } - else if (atoi(arg.c_str()) > int(whom.lvllow)) + else if (atoi(arg.c_str()) > int(whom.lvllow)) { whom.lvlhigh = atoi(arg.c_str()); - else + } + else { whom.lvllow = atoi(arg.c_str()); + } } else { strn0cpy(whom.whom, arg.c_str(), sizeof(whom.whom)); @@ -75,21 +176,33 @@ void ConsoleWho(EQ::Net::ConsoleServerConnection* connection, const std::string& client_list.ConsoleSendWhoAll(0, connection->Admin(), &whom, &console_connection); } -void ConsoleUptime(EQ::Net::ConsoleServerConnection* connection, const std::string& command, const std::vector& args) { +/** + * @param connection + * @param command + * @param args + */ +void ConsoleUptime( + EQ::Net::ConsoleServerConnection *connection, + const std::string &command, + const std::vector &args +) +{ if (args.size() < 1) { return; } if (StringIsNumber(args[0]) && atoi(args[0].c_str()) > 0) { - auto pack = new ServerPacket(ServerOP_Uptime, sizeof(ServerUptime_Struct)); - ServerUptime_Struct* sus = (ServerUptime_Struct*)pack->pBuffer; + auto pack = new ServerPacket(ServerOP_Uptime, sizeof(ServerUptime_Struct)); + ServerUptime_Struct *sus = (ServerUptime_Struct *) pack->pBuffer; snprintf(sus->adminname, sizeof(sus->adminname), "*%s", connection->UserName().c_str()); sus->zoneserverid = atoi(args[0].c_str()); - ZoneServer* zs = zoneserver_list.FindByID(sus->zoneserverid); - if (zs) + ZoneServer *zs = zoneserver_list.FindByID(sus->zoneserverid); + if (zs) { zs->SendPacket(pack); - else + } + else { connection->SendLine("Zoneserver not found."); + } delete pack; } else { @@ -98,78 +211,167 @@ void ConsoleUptime(EQ::Net::ConsoleServerConnection* connection, const std::stri } } -void ConsoleMd5(EQ::Net::ConsoleServerConnection* connection, const std::string& command, const std::vector& args) { +/** + * @param connection + * @param command + * @param args + */ +void ConsoleMd5( + EQ::Net::ConsoleServerConnection *connection, + const std::string &command, + const std::vector &args +) +{ if (args.size() < 1) { return; } - + uint8 md5[16]; - MD5::Generate((const uchar*)args[0].c_str(), strlen(args[0].c_str()), md5); - connection->SendLine(StringFormat("MD5: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", - md5[0], md5[1], md5[2], md5[3], md5[4], md5[5], md5[6], md5[7], md5[8], md5[9], md5[10], md5[11], md5[12], md5[13], md5[14], md5[15])); + MD5::Generate((const uchar *) args[0].c_str(), strlen(args[0].c_str()), md5); + connection->SendLine( + StringFormat( + "MD5: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", + md5[0], + md5[1], + md5[2], + md5[3], + md5[4], + md5[5], + md5[6], + md5[7], + md5[8], + md5[9], + md5[10], + md5[11], + md5[12], + md5[13], + md5[14], + md5[15] + )); } -void ConsoleEmote(EQ::Net::ConsoleServerConnection* connection, const std::string& command, const std::vector& args) { +/** + * @param connection + * @param command + * @param args + */ +void ConsoleEmote( + EQ::Net::ConsoleServerConnection *connection, + const std::string &command, + const std::vector &args +) +{ if (args.size() < 3) { return; } - + auto join_args = args; join_args.erase(join_args.begin(), join_args.begin() + 2); - if (strcasecmp(args[0].c_str(), "world") == 0) + if (strcasecmp(args[0].c_str(), "world") == 0) { zoneserver_list.SendEmoteMessageRaw(0, 0, 0, atoi(args[1].c_str()), JoinString(join_args, " ").c_str()); + } else { - ZoneServer* zs = zoneserver_list.FindByName(args[0].c_str()); - if (zs != 0) + ZoneServer *zs = zoneserver_list.FindByName(args[0].c_str()); + if (zs != 0) { zs->SendEmoteMessageRaw(0, 0, 0, atoi(args[1].c_str()), JoinString(join_args, " ").c_str()); - else - zoneserver_list.SendEmoteMessageRaw(args[0].c_str(), 0, 0, atoi(args[1].c_str()), JoinString(join_args, " ").c_str()); + } + else { + zoneserver_list.SendEmoteMessageRaw( + args[0].c_str(), + 0, + 0, + atoi(args[1].c_str()), + JoinString(join_args, " ").c_str()); + } } } -void ConsoleAcceptMessages(EQ::Net::ConsoleServerConnection* connection, const std::string& command, const std::vector& args) { +/** + * @param connection + * @param command + * @param args + */ +void ConsoleAcceptMessages( + EQ::Net::ConsoleServerConnection *connection, + const std::string &command, + const std::vector &args +) +{ if (args.size() < 1) { connection->SendLine("Usage: acceptmessages [on/off]"); return; } - if (strcasecmp(args[0].c_str(), "on") == 0) + if (strcasecmp(args[0].c_str(), "on") == 0) { connection->SetAcceptMessages(true); - else if (strcasecmp(args[0].c_str(), "off") == 0) + } + else if (strcasecmp(args[0].c_str(), "off") == 0) { connection->SetAcceptMessages(false); - else + } + else { connection->SendLine("Usage: acceptmessages [on/off]"); + } } -void ConsoleTell(EQ::Net::ConsoleServerConnection* connection, const std::string& command, const std::vector& args) { +/** + * @param connection + * @param command + * @param args + */ +void ConsoleTell( + EQ::Net::ConsoleServerConnection *connection, + const std::string &command, + const std::vector &args +) +{ if (args.size() < 2) { return; } - + char tmpname[64]; tmpname[0] = '*'; strcpy(&tmpname[1], connection->UserName().c_str()); std::string to = args[0]; - + auto join_args = args; join_args.erase(join_args.begin(), join_args.begin() + 1); zoneserver_list.SendChannelMessage(tmpname, to.c_str(), 7, 0, JoinString(join_args, " ").c_str()); } -void ConsoleBroadcast(EQ::Net::ConsoleServerConnection* connection, const std::string& command, const std::vector& args) { +/** + * @param connection + * @param command + * @param args + */ +void ConsoleBroadcast( + EQ::Net::ConsoleServerConnection *connection, + const std::string &command, + const std::vector &args +) +{ if (args.size() < 1) { return; } - + char tmpname[64]; tmpname[0] = '*'; strcpy(&tmpname[1], connection->UserName().c_str()); zoneserver_list.SendChannelMessage(tmpname, 0, 6, 0, JoinString(args, " ").c_str()); } -void ConsoleGMSay(EQ::Net::ConsoleServerConnection* connection, const std::string& command, const std::vector& args) { +/** + * @param connection + * @param command + * @param args + */ +void ConsoleGMSay( + EQ::Net::ConsoleServerConnection *connection, + const std::string &command, + const std::vector &args +) +{ if (args.size() < 1) { return; } @@ -180,7 +382,17 @@ void ConsoleGMSay(EQ::Net::ConsoleServerConnection* connection, const std::strin zoneserver_list.SendChannelMessage(tmpname, 0, 11, 0, JoinString(args, " ").c_str()); } -void ConsoleOOC(EQ::Net::ConsoleServerConnection* connection, const std::string& command, const std::vector& args) { +/** + * @param connection + * @param command + * @param args + */ +void ConsoleOOC( + EQ::Net::ConsoleServerConnection *connection, + const std::string &command, + const std::vector &args +) +{ if (args.size() < 1) { return; } @@ -191,7 +403,17 @@ void ConsoleOOC(EQ::Net::ConsoleServerConnection* connection, const std::string& zoneserver_list.SendChannelMessage(tmpname, 0, 5, 0, JoinString(args, " ").c_str()); } -void ConsoleAuction(EQ::Net::ConsoleServerConnection* connection, const std::string& command, const std::vector& args) { +/** + * @param connection + * @param command + * @param args + */ +void ConsoleAuction( + EQ::Net::ConsoleServerConnection *connection, + const std::string &command, + const std::vector &args +) +{ if (args.size() < 1) { return; } @@ -202,19 +424,29 @@ void ConsoleAuction(EQ::Net::ConsoleServerConnection* connection, const std::str zoneserver_list.SendChannelMessage(tmpname, 0, 4, 0, JoinString(args, " ").c_str()); } -void ConsoleKick(EQ::Net::ConsoleServerConnection* connection, const std::string& command, const std::vector& args) { +/** + * @param connection + * @param command + * @param args + */ +void ConsoleKick( + EQ::Net::ConsoleServerConnection *connection, + const std::string &command, + const std::vector &args +) +{ if (args.size() < 1) { return; } - + char tmpname[64]; tmpname[0] = '*'; strcpy(&tmpname[1], connection->UserName().c_str()); auto pack = new ServerPacket; - pack->opcode = ServerOP_KickPlayer; - pack->size = sizeof(ServerKickPlayer_Struct); + pack->opcode = ServerOP_KickPlayer; + pack->size = sizeof(ServerKickPlayer_Struct); pack->pBuffer = new uchar[pack->size]; - ServerKickPlayer_Struct* skp = (ServerKickPlayer_Struct*)pack->pBuffer; + ServerKickPlayer_Struct *skp = (ServerKickPlayer_Struct *) pack->pBuffer; strcpy(skp->adminname, tmpname); strcpy(skp->name, args[0].c_str()); skp->adminrank = connection->Admin(); @@ -222,7 +454,17 @@ void ConsoleKick(EQ::Net::ConsoleServerConnection* connection, const std::string delete pack; } -void ConsoleLock(EQ::Net::ConsoleServerConnection* connection, const std::string& command, const std::vector& args) { +/** + * @param connection + * @param command + * @param args + */ +void ConsoleLock( + EQ::Net::ConsoleServerConnection *connection, + const std::string &command, + const std::vector &args +) +{ WorldConfig::LockWorld(); if (loginserverlist.Connected()) { loginserverlist.SendStatus(); @@ -233,7 +475,17 @@ void ConsoleLock(EQ::Net::ConsoleServerConnection* connection, const std::string } } -void ConsoleUnlock(EQ::Net::ConsoleServerConnection* connection, const std::string& command, const std::vector& args) { +/** + * @param connection + * @param command + * @param args + */ +void ConsoleUnlock( + EQ::Net::ConsoleServerConnection *connection, + const std::string &command, + const std::vector &args +) +{ WorldConfig::UnlockWorld(); if (loginserverlist.Connected()) { loginserverlist.SendStatus(); @@ -244,12 +496,22 @@ void ConsoleUnlock(EQ::Net::ConsoleServerConnection* connection, const std::stri } } -void ConsoleZoneShutdown(EQ::Net::ConsoleServerConnection* connection, const std::string& command, const std::vector& args) { +/** + * @param connection + * @param command + * @param args + */ +void ConsoleZoneShutdown( + EQ::Net::ConsoleServerConnection *connection, + const std::string &command, + const std::vector &args +) +{ if (args.size() < 1) { connection->SendLine("Usage: zoneshutdown zoneshortname"); return; } - + if (args[0].length() == 0) { connection->SendLine("Usage: zoneshutdown zoneshortname"); } @@ -259,35 +521,52 @@ void ConsoleZoneShutdown(EQ::Net::ConsoleServerConnection* connection, const std strcpy(&tmpname[1], connection->UserName().c_str()); auto pack = new ServerPacket; - pack->size = sizeof(ServerZoneStateChange_struct); + pack->size = sizeof(ServerZoneStateChange_struct); pack->pBuffer = new uchar[pack->size]; memset(pack->pBuffer, 0, sizeof(ServerZoneStateChange_struct)); - ServerZoneStateChange_struct* s = (ServerZoneStateChange_struct *)pack->pBuffer; + ServerZoneStateChange_struct *s = (ServerZoneStateChange_struct *) pack->pBuffer; pack->opcode = ServerOP_ZoneShutdown; strcpy(s->adminname, tmpname); - if (StringIsNumber(args[0])) + if (StringIsNumber(args[0])) { s->ZoneServerID = atoi(args[0].c_str()); - else + } + else { s->zoneid = database.GetZoneID(args[0].c_str()); + } - ZoneServer* zs = 0; - if (s->ZoneServerID != 0) + ZoneServer *zs = 0; + if (s->ZoneServerID != 0) { zs = zoneserver_list.FindByID(s->ZoneServerID); - else if (s->zoneid != 0) + } + else if (s->zoneid != 0) { zs = zoneserver_list.FindByName(database.GetZoneName(s->zoneid)); - else + } + else { connection->SendLine("Error: ZoneShutdown: neither ID nor name specified"); + } - if (zs == 0) + if (zs == 0) { connection->SendLine("Error: ZoneShutdown: zoneserver not found"); - else + } + else { zs->SendPacket(pack); + } delete pack; } } -void ConsoleZoneBootup(EQ::Net::ConsoleServerConnection* connection, const std::string& command, const std::vector& args) { +/** + * @param connection + * @param command + * @param args + */ +void ConsoleZoneBootup( + EQ::Net::ConsoleServerConnection *connection, + const std::string &command, + const std::vector &args +) +{ if (args.size() < 2) { return; } @@ -300,10 +579,19 @@ void ConsoleZoneBootup(EQ::Net::ConsoleServerConnection* connection, const std:: tmpname[0] = '*'; strcpy(&tmpname[1], connection->UserName().c_str()); - Log(Logs::Detail, Logs::World_Server, "Console ZoneBootup: %s, %s, %s", tmpname, args[1].c_str(), args[0].c_str()); + Log(Logs::Detail, + Logs::World_Server, + "Console ZoneBootup: %s, %s, %s", + tmpname, + args[1].c_str(), + args[0].c_str()); if (args.size() > 2) { - zoneserver_list.SOPZoneBootup(tmpname, atoi(args[0].c_str()), args[1].c_str(), (bool)(strcasecmp(args[1].c_str(), "static") == 0)); + zoneserver_list.SOPZoneBootup( + tmpname, + atoi(args[0].c_str()), + args[1].c_str(), + (bool) (strcasecmp(args[1].c_str(), "static") == 0)); } else { zoneserver_list.SOPZoneBootup(tmpname, atoi(args[0].c_str()), args[1].c_str(), false); @@ -311,11 +599,21 @@ void ConsoleZoneBootup(EQ::Net::ConsoleServerConnection* connection, const std:: } } -void ConsoleZoneLock(EQ::Net::ConsoleServerConnection* connection, const std::string& command, const std::vector& args) { +/** + * @param connection + * @param command + * @param args + */ +void ConsoleZoneLock( + EQ::Net::ConsoleServerConnection *connection, + const std::string &command, + const std::vector &args +) +{ if (args.size() < 1) { return; } - + if (strcasecmp(args[0].c_str(), "list") == 0) { WorldConsoleTCPConnection console_connection(connection); zoneserver_list.ListLockedZones(0, &console_connection); @@ -327,28 +625,34 @@ void ConsoleZoneLock(EQ::Net::ConsoleServerConnection* connection, const std::st uint16 tmp = database.GetZoneID(args[1].c_str()); if (tmp) { - if (zoneserver_list.SetLockedZone(tmp, true)) + if (zoneserver_list.SetLockedZone(tmp, true)) { zoneserver_list.SendEmoteMessage(0, 0, 80, 15, "Zone locked: %s", database.GetZoneName(tmp)); - else + } + else { connection->SendLine("Failed to change lock"); + } } - else + else { connection->SendLine("Usage: #zonelock lock [zonename]"); + } } else if (strcasecmp(args[0].c_str(), "unlock") == 0 && connection->Admin() >= 101) { if (args.size() < 2) { return; } - + uint16 tmp = database.GetZoneID(args[1].c_str()); if (tmp) { - if (zoneserver_list.SetLockedZone(tmp, false)) + if (zoneserver_list.SetLockedZone(tmp, false)) { zoneserver_list.SendEmoteMessage(0, 0, 80, 15, "Zone unlocked: %s", database.GetZoneName(tmp)); - else + } + else { connection->SendLine("Failed to change lock"); + } } - else + else { connection->SendLine("Usage: #zonelock unlock [zonename]"); + } } else { connection->SendLine("#zonelock sub-commands"); @@ -360,60 +664,108 @@ void ConsoleZoneLock(EQ::Net::ConsoleServerConnection* connection, const std::st } } -void ConsoleFlag(EQ::Net::ConsoleServerConnection* connection, const std::string& command, const std::vector& args) { +/** + * @param connection + * @param command + * @param args + */ +void ConsoleFlag( + EQ::Net::ConsoleServerConnection *connection, + const std::string &command, + const std::vector &args +) +{ if (args.size() < 2) { return; } - - if (args[1].length() == 0 || !StringIsNumber(args[0])) + + if (args[1].length() == 0 || !StringIsNumber(args[0])) { connection->SendLine("Usage: flag [status] [accountname]"); - else - { - if (atoi(args[0].c_str()) > connection->Admin()) + } + else { + if (atoi(args[0].c_str()) > connection->Admin()) { connection->SendLine("You cannot set people's status to higher than your own"); - else if (!database.SetAccountStatus(args[1].c_str(), atoi(args[0].c_str()))) + } + else if (!database.SetAccountStatus(args[1].c_str(), atoi(args[0].c_str()))) { connection->SendLine("Unable to flag account!"); - else + } + else { connection->SendLine("Account Flaged"); + } } } -void ConsoleSetPass(EQ::Net::ConsoleServerConnection* connection, const std::string& command, const std::vector& args) { +/** + * @param connection + * @param command + * @param args + */ +void ConsoleSetPass( + EQ::Net::ConsoleServerConnection *connection, + const std::string &command, + const std::vector &args +) +{ if (args.size() != 2) { connection->SendLine("Format: setpass accountname password"); } else { - int16 tmpstatus = 0; - uint32 tmpid = database.GetAccountIDByName(args[0].c_str(), &tmpstatus); - if (!tmpid) + int16 tmpstatus = 0; + uint32 tmpid = database.GetAccountIDByName(args[0].c_str(), &tmpstatus); + if (!tmpid) { connection->SendLine("Error: Account not found"); - else if (tmpstatus > connection->Admin()) + } + else if (tmpstatus > connection->Admin()) { connection->SendLine("Cannot change password: Account's status is higher than yours"); - else if (database.SetLocalPassword(tmpid, args[1].c_str())) + } + else if (database.SetLocalPassword(tmpid, args[1].c_str())) { connection->SendLine("Password changed."); - else + } + else { connection->SendLine("Error changing password."); + } } } -void ConsoleVersion(EQ::Net::ConsoleServerConnection* connection, const std::string& command, const std::vector& args) { +/** + * @param connection + * @param command + * @param args + */ +void ConsoleVersion( + EQ::Net::ConsoleServerConnection *connection, + const std::string &command, + const std::vector &args +) +{ connection->SendLine(StringFormat("Current version information.")); connection->SendLine(StringFormat(" %s", CURRENT_VERSION)); connection->SendLine(StringFormat(" Compiled on: %s at %s", COMPILE_DATE, COMPILE_TIME)); connection->SendLine(StringFormat(" Last modified on: %s", LAST_MODIFIED)); } -void ConsoleWorldShutdown(EQ::Net::ConsoleServerConnection* connection, const std::string& command, const std::vector& args) { +/** + * @param connection + * @param command + * @param args + */ +void ConsoleWorldShutdown( + EQ::Net::ConsoleServerConnection *connection, + const std::string &command, + const std::vector &args +) +{ if (args.size() == 2) { int32 time, interval; - if (StringIsNumber(args[0]) && StringIsNumber(args[1]) && ((time = atoi(args[0].c_str()))>0) && ((interval = atoi(args[1].c_str()))>0)) { + if (StringIsNumber(args[0]) && StringIsNumber(args[1]) && ((time = atoi(args[0].c_str())) > 0) && + ((interval = atoi(args[1].c_str())) > 0)) { zoneserver_list.WorldShutDown(time, interval); } else { connection->SendLine("Usage: worldshutdown [now] [disable] ([time] [interval])"); } } - else if(args.size() == 1) { + else if (args.size() == 1) { if (strcasecmp(args[0].c_str(), "now") == 0) { zoneserver_list.WorldShutDown(0, 0); } @@ -432,74 +784,120 @@ void ConsoleWorldShutdown(EQ::Net::ConsoleServerConnection* connection, const st } } -void ConsoleIpLookup(EQ::Net::ConsoleServerConnection* connection, const std::string& command, const std::vector& args) { +/** + * @param connection + * @param command + * @param args + */ +void ConsoleIpLookup( + EQ::Net::ConsoleServerConnection *connection, + const std::string &command, + const std::vector &args +) +{ if (args.size() > 0) { WorldConsoleTCPConnection console_connection(connection); client_list.SendCLEList(connection->Admin(), 0, &console_connection, args[0].c_str()); } } -void ConsoleSignalCharByName(EQ::Net::ConsoleServerConnection* connection, const std::string& command, const std::vector& args) { +/** + * @param connection + * @param command + * @param args + */ +void ConsoleSignalCharByName( + EQ::Net::ConsoleServerConnection *connection, + const std::string &command, + const std::vector &args +) +{ if (args.size() < 2) { return; } - - connection->SendLine(StringFormat("Signal Sent to %s with ID %i", (char*) args[0].c_str(), atoi(args[1].c_str()))); - uint32 message_len = strlen((char*) args[0].c_str()) + 1; - auto pack = new ServerPacket(ServerOP_CZSignalClientByName, - sizeof(CZClientSignalByName_Struct) + message_len); - CZClientSignalByName_Struct* CZSC = (CZClientSignalByName_Struct*) pack->pBuffer; - strn0cpy(CZSC->Name, (char*) args[0].c_str(), 64); + + connection->SendLine(StringFormat("Signal Sent to %s with ID %i", (char *) args[0].c_str(), atoi(args[1].c_str()))); + uint32 message_len = strlen((char *) args[0].c_str()) + 1; + auto pack = new ServerPacket( + ServerOP_CZSignalClientByName, + sizeof(CZClientSignalByName_Struct) + message_len + ); + CZClientSignalByName_Struct *CZSC = (CZClientSignalByName_Struct *) pack->pBuffer; + strn0cpy(CZSC->Name, (char *) args[0].c_str(), 64); CZSC->data = atoi(args[1].c_str()); zoneserver_list.SendPacket(pack); safe_delete(pack); } -void ConsoleReloadWorld(EQ::Net::ConsoleServerConnection* connection, const std::string& command, const std::vector& args) { +/** + * @param connection + * @param command + * @param args + */ +void ConsoleReloadWorld( + EQ::Net::ConsoleServerConnection *connection, + const std::string &command, + const std::vector &args +) +{ connection->SendLine("Reloading World..."); - auto pack = new ServerPacket(ServerOP_ReloadWorld, sizeof(ReloadWorld_Struct)); - ReloadWorld_Struct* RW = (ReloadWorld_Struct*)pack->pBuffer; + auto pack = new ServerPacket(ServerOP_ReloadWorld, sizeof(ReloadWorld_Struct)); + ReloadWorld_Struct *RW = (ReloadWorld_Struct *) pack->pBuffer; RW->Option = 1; zoneserver_list.SendPacket(pack); safe_delete(pack); } -void ConsoleQuit(EQ::Net::ConsoleServerConnection* connection, const std::string& command, const std::vector& args) { +/** + * @param connection + * @param command + * @param args + */ +void ConsoleQuit( + EQ::Net::ConsoleServerConnection *connection, + const std::string &command, + const std::vector &args +) +{ connection->SendLine("Exiting..."); connection->Close(); } + +/** + * @param console + */ void RegisterConsoleFunctions(std::unique_ptr& console) { console->RegisterLogin(std::bind(CheckLogin, std::placeholders::_1, std::placeholders::_2)); - console->RegisterCall("whoami", 50, "whoami", std::bind(ConsoleWhoami, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); - console->RegisterCall("who", 50, "who", std::bind(ConsoleWho, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); - console->RegisterCall("zonestatus", 50, "zonestatus", std::bind(ConsoleZoneStatus, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); - console->RegisterCall("uptime", 50, "uptime [zoneID#]", std::bind(ConsoleUptime, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); - console->RegisterCall("md5", 50, "md5", std::bind(ConsoleMd5, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); - console->RegisterCall("emote", 50, "emote [zonename or charname or world] [type] [message]", std::bind(ConsoleEmote, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); - console->RegisterCall("echo", 50, "echo [on/off]", std::bind(ConsoleNull, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); console->RegisterCall("acceptmessages", 50, "acceptmessages [on/off]", std::bind(ConsoleAcceptMessages, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); - console->RegisterCall("tell", 50, "tell [name] [message]", std::bind(ConsoleTell, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); - console->RegisterCall("broadcast", 50, "broadcast [message]", std::bind(ConsoleBroadcast, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); - console->RegisterCall("gmsay", 50, "gmsay [message]", std::bind(ConsoleGMSay, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); - console->RegisterCall("ooc", 50, "ooc [message]", std::bind(ConsoleOOC, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); + console->RegisterCall("api", 200, "api", std::bind(ConsoleApi, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); console->RegisterCall("auction", 50, "auction [message]", std::bind(ConsoleAuction, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); + console->RegisterCall("broadcast", 50, "broadcast [message]", std::bind(ConsoleBroadcast, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); + console->RegisterCall("echo", 50, "echo [on/off]", std::bind(ConsoleNull, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); + console->RegisterCall("emote", 50, "emote [zonename or charname or world] [type] [message]", std::bind(ConsoleEmote, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); + console->RegisterCall("flag", 200, "flag [status] [accountname]", std::bind(ConsoleFlag, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); + console->RegisterCall("gmsay", 50, "gmsay [message]", std::bind(ConsoleGMSay, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); + console->RegisterCall("iplookup", 50, "IPLookup [name]", std::bind(ConsoleIpLookup, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); console->RegisterCall("kick", 150, "kick [charname]", std::bind(ConsoleKick, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); console->RegisterCall("lock", 150, "lock", std::bind(ConsoleLock, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); + console->RegisterCall("lsreconnect", 50, "LSReconnect", std::bind(ConsoleNull, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); + console->RegisterCall("md5", 50, "md5", std::bind(ConsoleMd5, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); + console->RegisterCall("ooc", 50, "ooc [message]", std::bind(ConsoleOOC, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); + console->RegisterCall("reloadworld", 200, "reloadworld", std::bind(ConsoleReloadWorld, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); + console->RegisterCall("setpass", 200, "setpass [accountname] [newpass]", std::bind(ConsoleSetPass, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); + console->RegisterCall("signalcharbyname", 50, "signalcharbyname charname ID", std::bind(ConsoleSignalCharByName, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); + console->RegisterCall("tell", 50, "tell [name] [message]", std::bind(ConsoleTell, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); console->RegisterCall("unlock", 150, "unlock", std::bind(ConsoleUnlock, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); - console->RegisterCall("zoneshutdown", 150, "zoneshutdown [zonename or ZoneServerID]", std::bind(ConsoleZoneShutdown, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); + console->RegisterCall("uptime", 50, "uptime [zoneID#]", std::bind(ConsoleUptime, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); + console->RegisterCall("version", 50, "version", std::bind(ConsoleVersion, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); + console->RegisterCall("who", 50, "who", std::bind(ConsoleWho, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); + console->RegisterCall("whoami", 50, "whoami", std::bind(ConsoleWhoami, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); + console->RegisterCall("worldshutdown", 200, "worldshutdown", std::bind(ConsoleWorldShutdown, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); console->RegisterCall("zonebootup", 150, "zonebootup [ZoneServerID] [zonename]", std::bind(ConsoleZoneBootup, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); console->RegisterCall("zonelock", 150, "zonelock [list|lock|unlock] [zonename]", std::bind(ConsoleZoneLock, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); - console->RegisterCall("flag", 200, "flag [status] [accountname]", std::bind(ConsoleFlag, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); - console->RegisterCall("setpass", 200, "setpass [accountname] [newpass]", std::bind(ConsoleSetPass, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); - console->RegisterCall("version", 50, "version", std::bind(ConsoleVersion, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); - console->RegisterCall("worldshutdown", 200, "worldshutdown", std::bind(ConsoleWorldShutdown, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); - console->RegisterCall("iplookup", 50, "IPLookup [name]", std::bind(ConsoleIpLookup, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); - console->RegisterCall("lsreconnect", 50, "LSReconnect", std::bind(ConsoleNull, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); - console->RegisterCall("signalcharbyname", 50, "signalcharbyname charname ID", std::bind(ConsoleSignalCharByName, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); - console->RegisterCall("reloadworld", 200, "reloadworld", std::bind(ConsoleReloadWorld, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); - console->RegisterCall("ping", 50, "ping", std::bind(ConsoleNull, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); + console->RegisterCall("zoneshutdown", 150, "zoneshutdown [zonename or ZoneServerID]", std::bind(ConsoleZoneShutdown, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); + console->RegisterCall("zonestatus", 50, "zonestatus", std::bind(ConsoleZoneStatus, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));console->RegisterCall("ping", 50, "ping", std::bind(ConsoleNull, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); console->RegisterCall("quit", 50, "quit", std::bind(ConsoleQuit, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); console->RegisterCall("exit", 50, "exit", std::bind(ConsoleQuit, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); } diff --git a/world/eqemu_api_world_data_service.cpp b/world/eqemu_api_world_data_service.cpp new file mode 100644 index 000000000..327bb298b --- /dev/null +++ b/world/eqemu_api_world_data_service.cpp @@ -0,0 +1,64 @@ +/** + * 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 + * + */ + +#include "eqemu_api_world_data_service.h" +#include "zoneserver.h" +#include "zonelist.h" + +extern ZSList zoneserver_list; + +void callGetZoneList(Json::Value &response) +{ + for (auto &zone : zoneserver_list.getZoneServerList()) { + Json::Value row; + + row["booting_up"] = zone->IsBootingUp(); + row["client_address"] = zone->GetCAddress(); + row["client_local_address"] = zone->GetCLocalAddress(); + row["client_port"] = zone->GetCPort(); + row["compile_time"] = zone->GetCompileTime(); + row["id"] = zone->GetID(); + row["instance_id"] = zone->GetInstanceID(); + row["ip"] = zone->GetIP(); + row["is_static_zone"] = zone->IsStaticZone(); + row["launch_name"] = zone->GetLaunchName(); + row["launched_name"] = zone->GetLaunchedName(); + row["number_players"] = zone->NumPlayers(); + row["port"] = zone->GetPort(); + row["previous_zone_id"] = zone->GetPrevZoneID(); + row["uuid"] = zone->GetUUID(); + row["zone_id"] = zone->GetZoneID(); + row["zone_long_name"] = zone->GetZoneLongName(); + row["zone_name"] = zone->GetZoneName(); + row["zone_os_pid"] = zone->GetZoneOSProcessID(); + + response.append(row); + } +} + + +void EQEmuApiWorldDataService::get(Json::Value &response, const std::vector &args) +{ + std::string method = args[0]; + + if (method == "get_zone_list") { + callGetZoneList(response); + } +} diff --git a/world/eqemu_api_world_data_service.h b/world/eqemu_api_world_data_service.h new file mode 100644 index 000000000..522e72a3f --- /dev/null +++ b/world/eqemu_api_world_data_service.h @@ -0,0 +1,32 @@ +/** + * 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 + * + */ + +#ifndef EQEMU_API_WORLD_DATA_SERVICE_H +#define EQEMU_API_WORLD_DATA_SERVICE_H + +#include "../common/json/json.h" + +class EQEmuApiWorldDataService { +public: + static void get(Json::Value &response, const std::vector &args); +}; + + +#endif //EQEMU_API_WORLD_DATA_SERVICE_H diff --git a/world/zonelist.cpp b/world/zonelist.cpp index db831e941..dd174e161 100644 --- a/world/zonelist.cpp +++ b/world/zonelist.cpp @@ -754,3 +754,8 @@ void ZSList::OnKeepAlive(EQ::Timer *t) zone->SendKeepAlive(); } } + +const std::list> &ZSList::getZoneServerList() const +{ + return list; +} diff --git a/world/zonelist.h b/world/zonelist.h index c63e1686b..16fce2172 100644 --- a/world/zonelist.h +++ b/world/zonelist.h @@ -21,57 +21,63 @@ public: ZSList(); ~ZSList(); - ZoneServer* FindByName(const char* zonename); - ZoneServer* FindByID(uint32 ZoneID); - ZoneServer* FindByZoneID(uint32 ZoneID); - ZoneServer* FindByPort(uint16 port); - ZoneServer* FindByInstanceID(uint32 InstanceID); - void SendChannelMessage(const char* from, const char* to, uint8 chan_num, uint8 language, const char* message, ...); - void SendChannelMessageRaw(const char* from, const char* to, uint8 chan_num, uint8 language, const char* message); - void SendEmoteMessage(const char* to, uint32 to_guilddbid, int16 to_minstatus, uint32 type, const char* message, ...); - void SendEmoteMessageRaw(const char* to, uint32 to_guilddbid, int16 to_minstatus, uint32 type, const char* message); + bool IsZoneLocked(uint16 iZoneID); + bool SendPacket(ServerPacket *pack); + bool SendPacket(uint32 zoneid, ServerPacket *pack); + bool SendPacket(uint32 zoneid, uint16 instanceid, ServerPacket *pack); + bool SetLockedZone(uint16 iZoneID, bool iLock); - void SendZoneStatus(const char* to, int16 admin, WorldTCPConnection* connection); - - void SendTimeSync(); - void Add(ZoneServer* zoneserver); - void Remove(const std::string &uuid); - void Process(); - void KillAll(); - bool SendPacket(ServerPacket* pack); - bool SendPacket(uint32 zoneid, ServerPacket* pack); - bool SendPacket(uint32 zoneid, uint16 instanceid, ServerPacket* pack); - inline uint32 GetNextID() { return NextID++; } - void RebootZone(const char* ip1,uint16 port, const char* ip2, uint32 skipid, uint32 zoneid = 0); - uint32 TriggerBootup(uint32 iZoneID, uint32 iInstanceID = 0); - void SOPZoneBootup(const char* adminname, uint32 ZoneServerID, const char* zonename, bool iMakeStatic = false); - EQTime worldclock; - bool SetLockedZone(uint16 iZoneID, bool iLock); - bool IsZoneLocked(uint16 iZoneID); - void ListLockedZones(const char* to, WorldTCPConnection* connection); - Timer* shutdowntimer; - Timer* reminder; - void NextGroupIDs(uint32 &start, uint32 &end); - void SendLSZones(); - uint16 GetAvailableZonePort(); - void UpdateUCSServerAvailable(bool ucss_available = true); + EQTime worldclock; + inline uint32 GetNextID() { return NextID++; } int GetZoneCount(); + + Timer *reminder; + Timer *shutdowntimer; + + uint16 GetAvailableZonePort(); + uint32 TriggerBootup(uint32 iZoneID, uint32 iInstanceID = 0); + + void Add(ZoneServer *zoneserver); void GetZoneIDList(std::vector &zones); + void KillAll(); + void ListLockedZones(const char *to, WorldTCPConnection *connection); + void NextGroupIDs(uint32 &start, uint32 &end); + void Process(); + void RebootZone(const char *ip1, uint16 port, const char *ip2, uint32 skipid, uint32 zoneid = 0); + void Remove(const std::string &uuid); + void SendChannelMessage(const char *from, const char *to, uint8 chan_num, uint8 language, const char *message, ...); + void SendChannelMessageRaw(const char *from, const char *to, uint8 chan_num, uint8 language, const char *message); + void SendEmoteMessage(const char *to, uint32 to_guilddbid, int16 to_minstatus, uint32 type, const char *message, ...); + void SendEmoteMessageRaw(const char *to, uint32 to_guilddbid, int16 to_minstatus, uint32 type, const char *message); + void SendLSZones(); + void SendTimeSync(); + void SendZoneStatus(const char *to, int16 admin, WorldTCPConnection *connection); + void SOPZoneBootup(const char *adminname, uint32 ZoneServerID, const char *zonename, bool iMakeStatic = false); + void UpdateUCSServerAvailable(bool ucss_available = true); void WorldShutDown(uint32 time, uint32 interval); + ZoneServer* FindByPort(uint16 port); + ZoneServer* FindByID(uint32 ZoneID); + ZoneServer* FindByInstanceID(uint32 InstanceID); + ZoneServer* FindByName(const char* zonename); + ZoneServer* FindByZoneID(uint32 ZoneID); + + const std::list> &getZoneServerList() const; + private: void OnTick(EQ::Timer *t); void OnKeepAlive(EQ::Timer *t); uint32 NextID; - std::list> list; uint16 pLockedZones[MaxLockedZones]; uint32 CurGroupID; uint16 LastAllocatedPort; std::unique_ptr m_tick; std::unique_ptr m_keepalive; + + std::list> list; }; #endif /*ZONELIST_H_*/ diff --git a/zone/eqemu_api_zone_data_service.cpp b/zone/eqemu_api_zone_data_service.cpp index 0073678c6..565757c28 100644 --- a/zone/eqemu_api_zone_data_service.cpp +++ b/zone/eqemu_api_zone_data_service.cpp @@ -675,4 +675,4 @@ void EQEmuApiZoneDataService::get(Json::Value &response, const std::vector Date: Sun, 10 Mar 2019 01:10:04 -0600 Subject: [PATCH 08/11] Refactor naming of zone server "list" to zone_server_list --- world/zonelist.cpp | 94 +++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/world/zonelist.cpp b/world/zonelist.cpp index dd174e161..84cd87842 100644 --- a/world/zonelist.cpp +++ b/world/zonelist.cpp @@ -67,16 +67,16 @@ void ZSList::ShowUpTime(WorldTCPConnection* con, const char* adminname) { } void ZSList::Add(ZoneServer* zoneserver) { - list.push_back(std::unique_ptr(zoneserver)); + zone_server_list.push_back(std::unique_ptr(zoneserver)); zoneserver->SendGroupIDs(); } void ZSList::Remove(const std::string &uuid) { - auto iter = list.begin(); - while (iter != list.end()) { + auto iter = zone_server_list.begin(); + while (iter != zone_server_list.end()) { if ((*iter)->GetUUID().compare(uuid) == 0) { - list.erase(iter); + zone_server_list.erase(iter); return; } iter++; @@ -84,10 +84,10 @@ void ZSList::Remove(const std::string &uuid) } void ZSList::KillAll() { - auto iterator = list.begin(); - while (iterator != list.end()) { + auto iterator = zone_server_list.begin(); + while (iterator != zone_server_list.end()) { (*iterator)->Disconnect(); - iterator = list.erase(iterator); + iterator = zone_server_list.erase(iterator); } } @@ -110,8 +110,8 @@ void ZSList::Process() { } bool ZSList::SendPacket(ServerPacket* pack) { - auto iterator = list.begin(); - while (iterator != list.end()) { + auto iterator = zone_server_list.begin(); + while (iterator != zone_server_list.end()) { (*iterator)->SendPacket(pack); iterator++; } @@ -119,8 +119,8 @@ bool ZSList::SendPacket(ServerPacket* pack) { } bool ZSList::SendPacket(uint32 ZoneID, ServerPacket* pack) { - auto iterator = list.begin(); - while (iterator != list.end()) { + auto iterator = zone_server_list.begin(); + while (iterator != zone_server_list.end()) { if ((*iterator)->GetZoneID() == ZoneID) { ZoneServer* tmp = (*iterator).get(); tmp->SendPacket(pack); @@ -134,8 +134,8 @@ bool ZSList::SendPacket(uint32 ZoneID, ServerPacket* pack) { bool ZSList::SendPacket(uint32 ZoneID, uint16 instanceID, ServerPacket* pack) { if (instanceID != 0) { - auto iterator = list.begin(); - while (iterator != list.end()) { + auto iterator = zone_server_list.begin(); + while (iterator != zone_server_list.end()) { if ((*iterator)->GetInstanceID() == instanceID) { ZoneServer* tmp = (*iterator).get(); tmp->SendPacket(pack); @@ -146,8 +146,8 @@ bool ZSList::SendPacket(uint32 ZoneID, uint16 instanceID, ServerPacket* pack) { } else { - auto iterator = list.begin(); - while (iterator != list.end()) { + auto iterator = zone_server_list.begin(); + while (iterator != zone_server_list.end()) { if ((*iterator)->GetZoneID() == ZoneID && (*iterator)->GetInstanceID() == 0) { ZoneServer* tmp = (*iterator).get(); @@ -161,8 +161,8 @@ bool ZSList::SendPacket(uint32 ZoneID, uint16 instanceID, ServerPacket* pack) { } ZoneServer* ZSList::FindByName(const char* zonename) { - auto iterator = list.begin(); - while (iterator != list.end()) { + auto iterator = zone_server_list.begin(); + while (iterator != zone_server_list.end()) { if (strcasecmp((*iterator)->GetZoneName(), zonename) == 0) { ZoneServer* tmp = (*iterator).get(); return tmp; @@ -173,8 +173,8 @@ ZoneServer* ZSList::FindByName(const char* zonename) { } ZoneServer* ZSList::FindByID(uint32 ZoneID) { - auto iterator = list.begin(); - while (iterator != list.end()) { + auto iterator = zone_server_list.begin(); + while (iterator != zone_server_list.end()) { if ((*iterator)->GetID() == ZoneID) { ZoneServer* tmp = (*iterator).get(); return tmp; @@ -185,8 +185,8 @@ ZoneServer* ZSList::FindByID(uint32 ZoneID) { } ZoneServer* ZSList::FindByZoneID(uint32 ZoneID) { - auto iterator = list.begin(); - while (iterator != list.end()) { + auto iterator = zone_server_list.begin(); + while (iterator != zone_server_list.end()) { ZoneServer* tmp = (*iterator).get(); if (tmp->GetZoneID() == ZoneID && tmp->GetInstanceID() == 0) { return tmp; @@ -197,8 +197,8 @@ ZoneServer* ZSList::FindByZoneID(uint32 ZoneID) { } ZoneServer* ZSList::FindByPort(uint16 port) { - auto iterator = list.begin(); - while (iterator != list.end()) { + auto iterator = zone_server_list.begin(); + while (iterator != zone_server_list.end()) { if ((*iterator)->GetCPort() == port) { ZoneServer* tmp = (*iterator).get(); return tmp; @@ -210,8 +210,8 @@ ZoneServer* ZSList::FindByPort(uint16 port) { ZoneServer* ZSList::FindByInstanceID(uint32 InstanceID) { - auto iterator = list.begin(); - while (iterator != list.end()) { + auto iterator = zone_server_list.begin(); + while (iterator != zone_server_list.end()) { if ((*iterator)->GetInstanceID() == InstanceID) { ZoneServer* tmp = (*iterator).get(); return tmp; @@ -289,8 +289,8 @@ void ZSList::SendZoneStatus(const char* to, int16 admin, WorldTCPConnection* con ZoneServer* zone_server_data = 0; - auto iterator = list.begin(); - while (iterator != list.end()) { + auto iterator = zone_server_list.begin(); + while (iterator != zone_server_list.end()) { zone_server_data = (*iterator).get(); auto addr = zone_server_data->GetIP(); @@ -540,8 +540,8 @@ void ZSList::SOPZoneBootup(const char* adminname, uint32 ZoneServerID, const cha void ZSList::RebootZone(const char* ip1, uint16 port, const char* ip2, uint32 skipid, uint32 zoneid) { // get random zone uint32 x = 0; - auto iterator = list.begin(); - while (iterator != list.end()) { + auto iterator = zone_server_list.begin(); + while (iterator != zone_server_list.end()) { x++; iterator++; } @@ -550,8 +550,8 @@ void ZSList::RebootZone(const char* ip1, uint16 port, const char* ip2, uint32 sk auto tmp = new ZoneServer *[x]; uint32 y = 0; - iterator = list.begin(); - while (iterator != list.end()) { + iterator = zone_server_list.begin(); + while (iterator != zone_server_list.end()) { if (!strcmp((*iterator)->GetCAddress(), ip2) && !(*iterator)->IsBootingUp() && (*iterator)->GetID() != skipid) { tmp[y++] = (*iterator).get(); } @@ -605,8 +605,8 @@ uint16 ZSList::GetAvailableZonePort() uint32 ZSList::TriggerBootup(uint32 iZoneID, uint32 iInstanceID) { if (iInstanceID > 0) { - auto iterator = list.begin(); - while (iterator != list.end()) { + auto iterator = zone_server_list.begin(); + while (iterator != zone_server_list.end()) { if ((*iterator)->GetInstanceID() == iInstanceID) { return (*iterator)->GetID(); @@ -614,8 +614,8 @@ uint32 ZSList::TriggerBootup(uint32 iZoneID, uint32 iInstanceID) { iterator++; } - iterator = list.begin(); - while (iterator != list.end()) { + iterator = zone_server_list.begin(); + while (iterator != zone_server_list.end()) { if ((*iterator)->GetZoneID() == 0 && !(*iterator)->IsBootingUp()) { ZoneServer* zone = (*iterator).get(); zone->TriggerBootup(iZoneID, iInstanceID); @@ -627,8 +627,8 @@ uint32 ZSList::TriggerBootup(uint32 iZoneID, uint32 iInstanceID) { } else { - auto iterator = list.begin(); - while (iterator != list.end()) { + auto iterator = zone_server_list.begin(); + while (iterator != zone_server_list.end()) { if ((*iterator)->GetZoneID() == iZoneID && (*iterator)->GetInstanceID() == 0) { return (*iterator)->GetID(); @@ -636,8 +636,8 @@ uint32 ZSList::TriggerBootup(uint32 iZoneID, uint32 iInstanceID) { iterator++; } - iterator = list.begin(); - while (iterator != list.end()) { + iterator = zone_server_list.begin(); + while (iterator != zone_server_list.end()) { if ((*iterator)->GetZoneID() == 0 && !(*iterator)->IsBootingUp()) { ZoneServer* zone = (*iterator).get(); zone->TriggerBootup(iZoneID); @@ -650,8 +650,8 @@ uint32 ZSList::TriggerBootup(uint32 iZoneID, uint32 iInstanceID) { } void ZSList::SendLSZones() { - auto iterator = list.begin(); - while (iterator != list.end()) { + auto iterator = zone_server_list.begin(); + while (iterator != zone_server_list.end()) { ZoneServer* zs = (*iterator).get(); zs->LSBootUpdate(zs->GetZoneID(), true); iterator++; @@ -659,12 +659,12 @@ void ZSList::SendLSZones() { } int ZSList::GetZoneCount() { - return(list.size()); + return(zone_server_list.size()); } void ZSList::GetZoneIDList(std::vector &zones) { - auto iterator = list.begin(); - while (iterator != list.end()) { + auto iterator = zone_server_list.begin(); + while (iterator != zone_server_list.end()) { ZoneServer* zs = (*iterator).get(); zones.push_back(zs->GetID()); iterator++; @@ -718,7 +718,7 @@ void ZSList::OnTick(EQ::Timer *t) out["event"] = "EQW::ZoneUpdate"; out["data"] = Json::Value(); - for (auto &zone : list) + for (auto &zone : zone_server_list) { Json::Value outzone; @@ -750,12 +750,12 @@ void ZSList::OnTick(EQ::Timer *t) void ZSList::OnKeepAlive(EQ::Timer *t) { - for (auto &zone : list) { + for (auto &zone : zone_server_list) { zone->SendKeepAlive(); } } const std::list> &ZSList::getZoneServerList() const { - return list; + return zone_server_list; } From ecd6c362a274719d0704a56d60850cf6fef009c7 Mon Sep 17 00:00:00 2001 From: Akkadius Date: Sun, 10 Mar 2019 01:11:31 -0600 Subject: [PATCH 09/11] Update zonelist.h --- world/zonelist.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/world/zonelist.h b/world/zonelist.h index 16fce2172..947f75a2b 100644 --- a/world/zonelist.h +++ b/world/zonelist.h @@ -77,7 +77,7 @@ private: std::unique_ptr m_tick; std::unique_ptr m_keepalive; - std::list> list; + std::list> zone_server_list; }; #endif /*ZONELIST_H_*/ From 374841cba090943ea343a9fc9106185462d2dbb8 Mon Sep 17 00:00:00 2001 From: Akkadius Date: Sun, 10 Mar 2019 01:43:07 -0600 Subject: [PATCH 10/11] Add call api get_client_list --- world/clientlist.cpp | 79 +++++++++++++++++++++++++- world/clientlist.h | 4 ++ world/eqemu_api_world_data_service.cpp | 12 +++- 3 files changed, 93 insertions(+), 2 deletions(-) diff --git a/world/clientlist.cpp b/world/clientlist.cpp index eb821b22f..8c98adc5c 100644 --- a/world/clientlist.cpp +++ b/world/clientlist.cpp @@ -1489,4 +1489,81 @@ void ClientList::OnTick(EQ::Timer *t) } web_interface.SendEvent(out); -} \ No newline at end of file +} + +/** + * @param response + */ +void ClientList::GetClientList(Json::Value &response) +{ + LinkedListIterator Iterator(clientlist); + + Iterator.Reset(); + + while (Iterator.MoreElements()) { + ClientListEntry *cle = Iterator.GetData(); + + Json::Value row; + + row["online"] = cle->Online(); + row["id"] = cle->GetID(); + row["ip"] = cle->GetIP(); + row["loginserver_id"] = cle->LSID(); + row["loginserver_account_id"] = cle->LSAccountID(); + row["loginserver_name"] = cle->LSName(); + row["world_admin"] = cle->WorldAdmin(); + row["account_id"] = cle->AccountID(); + row["account_name"] = cle->AccountName(); + row["admin"] = cle->Admin(); + + auto server = cle->Server(); + if (server) { + row["server"]["client_address"] = server->GetCAddress(); + row["server"]["client_local_address"] = server->GetCLocalAddress(); + row["server"]["compile_time"] = server->GetCompileTime(); + row["server"]["client_port"] = server->GetCPort(); + row["server"]["id"] = server->GetID(); + row["server"]["instance_id"] = server->GetInstanceID(); + row["server"]["ip"] = server->GetIP(); + row["server"]["launched_name"] = server->GetLaunchedName(); + row["server"]["launch_name"] = server->GetLaunchName(); + row["server"]["port"] = server->GetPort(); + row["server"]["previous_zone_id"] = server->GetPrevZoneID(); + row["server"]["uui"] = server->GetUUID(); + row["server"]["zone_id"] = server->GetZoneID(); + row["server"]["zone_long_name"] = server->GetZoneLongName(); + row["server"]["zone_name"] = server->GetZoneName(); + row["server"]["zone_os_pid"] = server->GetZoneOSProcessID(); + row["server"]["number_players"] = server->NumPlayers(); + row["server"]["is_booting"] = server->IsBootingUp(); + row["server"]["static_zone"] = server->IsStaticZone(); + } + else { + row["server"] = Json::Value(); + } + + row["character_id"] = cle->CharID(); + row["name"] = cle->name(); + row["zone"] = cle->zone(); + row["instance"] = cle->instance(); + row["level"] = cle->level(); + row["class"] = cle->class_(); + row["race"] = cle->race(); + row["anon"] = cle->Anon(); + + row["tells_off"] = cle->TellsOff(); + row["guild_id"] = cle->GuildID(); + row["lfg"] = cle->LFG(); + row["gm"] = cle->GetGM(); + row["is_local_client"] = cle->IsLocalClient(); + row["lfg_from_level"] = cle->GetLFGFromLevel(); + row["lfg_to_level"] = cle->GetLFGToLevel(); + row["lfg_match_filter"] = cle->GetLFGMatchFilter(); + row["lfg_comments"] = cle->GetLFGComments(); + row["client_version"] = cle->GetClientVersion(); + + response.append(row); + + Iterator.Advance(); + } +} diff --git a/world/clientlist.h b/world/clientlist.h index 4cee08a7f..3ca6291c2 100644 --- a/world/clientlist.h +++ b/world/clientlist.h @@ -3,6 +3,7 @@ #include "../common/eq_packet_structs.h" #include "../common/linked_list.h" +#include "../common/json/json.h" #include "../common/timer.h" #include "../common/rulesys.h" #include "../common/servertalk.h" @@ -69,6 +70,8 @@ public: int GetClientCount(); void GetClients(const char *zone_name, std::vector &into); + void GetClientList(Json::Value &response); + private: void OnTick(EQ::Timer *t); inline uint32 GetNextCLEID() { return NextCLEID++; } @@ -81,6 +84,7 @@ private: uint32 NextCLEID; LinkedList clientlist; + std::unique_ptr m_tick; }; diff --git a/world/eqemu_api_world_data_service.cpp b/world/eqemu_api_world_data_service.cpp index 327bb298b..8a5291824 100644 --- a/world/eqemu_api_world_data_service.cpp +++ b/world/eqemu_api_world_data_service.cpp @@ -18,11 +18,14 @@ * */ +#include "clientlist.h" +#include "cliententry.h" #include "eqemu_api_world_data_service.h" #include "zoneserver.h" #include "zonelist.h" -extern ZSList zoneserver_list; +extern ZSList zoneserver_list; +extern ClientList client_list; void callGetZoneList(Json::Value &response) { @@ -53,6 +56,10 @@ void callGetZoneList(Json::Value &response) } } +void callGetClientList(Json::Value &response) +{ + client_list.GetClientList(response); +} void EQEmuApiWorldDataService::get(Json::Value &response, const std::vector &args) { @@ -61,4 +68,7 @@ void EQEmuApiWorldDataService::get(Json::Value &response, const std::vector Date: Sun, 10 Mar 2019 01:44:13 -0600 Subject: [PATCH 11/11] Some sorting on get_client_list --- world/clientlist.cpp | 60 +++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/world/clientlist.cpp b/world/clientlist.cpp index 8c98adc5c..96dd45076 100644 --- a/world/clientlist.cpp +++ b/world/clientlist.cpp @@ -1505,62 +1505,60 @@ void ClientList::GetClientList(Json::Value &response) Json::Value row; - row["online"] = cle->Online(); - row["id"] = cle->GetID(); - row["ip"] = cle->GetIP(); - row["loginserver_id"] = cle->LSID(); - row["loginserver_account_id"] = cle->LSAccountID(); - row["loginserver_name"] = cle->LSName(); - row["world_admin"] = cle->WorldAdmin(); row["account_id"] = cle->AccountID(); row["account_name"] = cle->AccountName(); row["admin"] = cle->Admin(); + row["id"] = cle->GetID(); + row["ip"] = cle->GetIP(); + row["loginserver_account_id"] = cle->LSAccountID(); + row["loginserver_id"] = cle->LSID(); + row["loginserver_name"] = cle->LSName(); + row["online"] = cle->Online(); + row["world_admin"] = cle->WorldAdmin(); auto server = cle->Server(); if (server) { row["server"]["client_address"] = server->GetCAddress(); row["server"]["client_local_address"] = server->GetCLocalAddress(); - row["server"]["compile_time"] = server->GetCompileTime(); row["server"]["client_port"] = server->GetCPort(); + row["server"]["compile_time"] = server->GetCompileTime(); row["server"]["id"] = server->GetID(); row["server"]["instance_id"] = server->GetInstanceID(); row["server"]["ip"] = server->GetIP(); - row["server"]["launched_name"] = server->GetLaunchedName(); + row["server"]["is_booting"] = server->IsBootingUp(); row["server"]["launch_name"] = server->GetLaunchName(); + row["server"]["launched_name"] = server->GetLaunchedName(); + row["server"]["number_players"] = server->NumPlayers(); row["server"]["port"] = server->GetPort(); row["server"]["previous_zone_id"] = server->GetPrevZoneID(); + row["server"]["static_zone"] = server->IsStaticZone(); row["server"]["uui"] = server->GetUUID(); row["server"]["zone_id"] = server->GetZoneID(); row["server"]["zone_long_name"] = server->GetZoneLongName(); row["server"]["zone_name"] = server->GetZoneName(); row["server"]["zone_os_pid"] = server->GetZoneOSProcessID(); - row["server"]["number_players"] = server->NumPlayers(); - row["server"]["is_booting"] = server->IsBootingUp(); - row["server"]["static_zone"] = server->IsStaticZone(); } else { row["server"] = Json::Value(); } - - row["character_id"] = cle->CharID(); - row["name"] = cle->name(); - row["zone"] = cle->zone(); - row["instance"] = cle->instance(); - row["level"] = cle->level(); - row["class"] = cle->class_(); - row["race"] = cle->race(); - row["anon"] = cle->Anon(); - - row["tells_off"] = cle->TellsOff(); - row["guild_id"] = cle->GuildID(); - row["lfg"] = cle->LFG(); - row["gm"] = cle->GetGM(); - row["is_local_client"] = cle->IsLocalClient(); - row["lfg_from_level"] = cle->GetLFGFromLevel(); - row["lfg_to_level"] = cle->GetLFGToLevel(); - row["lfg_match_filter"] = cle->GetLFGMatchFilter(); - row["lfg_comments"] = cle->GetLFGComments(); + row["anon"] = cle->Anon(); + row["character_id"] = cle->CharID(); + row["class"] = cle->class_(); row["client_version"] = cle->GetClientVersion(); + row["gm"] = cle->GetGM(); + row["guild_id"] = cle->GuildID(); + row["instance"] = cle->instance(); + row["is_local_client"] = cle->IsLocalClient(); + row["level"] = cle->level(); + row["lfg"] = cle->LFG(); + row["lfg_comments"] = cle->GetLFGComments(); + row["lfg_from_level"] = cle->GetLFGFromLevel(); + row["lfg_match_filter"] = cle->GetLFGMatchFilter(); + row["lfg_to_level"] = cle->GetLFGToLevel(); + row["name"] = cle->name(); + row["race"] = cle->race(); + row["tells_off"] = cle->TellsOff(); + row["zone"] = cle->zone(); response.append(row);