9
3

World.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef EQ2_WORLD_H
  17. #define EQ2_WORLD_H
  18. #include <string>
  19. #include <vector>
  20. #include <map>
  21. #include <list>
  22. #include <mutex>
  23. #include <shared_mutex>
  24. #include <atomic>
  25. #include "SpawnLists.h"
  26. #include "zoneserver.h"
  27. #include "NPC.h"
  28. #include "Widget.h"
  29. #include "Object.h"
  30. #include "GroundSpawn.h"
  31. #include "Sign.h"
  32. #include "Variables.h"
  33. #include "MutexList.h"
  34. #include "PlayerGroups.h"
  35. #include "../common/Web/WebServer.h"
  36. #include "./Zone/region_map.h"
  37. #include "./Zone/map.h"
  38. #include "./Web/PeerManager.h"
  39. using namespace std;
  40. struct MerchantInfo{
  41. vector<int32> inventory_ids;
  42. /*int32 faction_id;
  43. sint32 faction_min;
  44. sint32 faction_max;
  45. float low_buy_multiplier;
  46. float high_buy_multiplier;
  47. float low_sell_multiplier;
  48. float high_sell_multiplier;*/
  49. };
  50. struct MerchantItemInfo{
  51. int32 item_id;
  52. int16 quantity;
  53. int32 price_item_id;
  54. int32 price_item2_id;
  55. int16 price_item_qty;
  56. int16 price_item2_qty;
  57. int32 price_status;
  58. int64 price_coins;
  59. int32 price_stationcash;
  60. };
  61. struct LootTable{
  62. string name;
  63. int32 mincoin;
  64. int32 maxcoin;
  65. int16 maxlootitems;
  66. float lootdrop_probability;
  67. float coin_probability;
  68. };
  69. struct LootDrop{
  70. int32 item_id;
  71. int16 item_charges;
  72. bool equip_item;
  73. float probability;
  74. int32 no_drop_quest_completed_id;
  75. };
  76. struct GroundSpawnEntry {
  77. int16 min_skill_level;
  78. int16 min_adventure_level;
  79. int8 bonus_table;
  80. float harvest1;
  81. float harvest3;
  82. float harvest5;
  83. float harvest_imbue;
  84. float harvest_rare;
  85. float harvest10;
  86. int32 harvest_coin;
  87. };
  88. struct GroundSpawnEntryItem {
  89. int32 item_id;
  90. int8 is_rare;
  91. int32 grid_id;
  92. };
  93. struct TransportDestination{
  94. int32 unique_id;
  95. int8 type;
  96. string display_name;
  97. string message;
  98. int32 destination_zone_id;
  99. float destination_x;
  100. float destination_y;
  101. float destination_z;
  102. float destination_heading;
  103. int32 cost;
  104. int8 min_level;
  105. int8 max_level;
  106. int32 req_quest;
  107. int16 req_quest_step;
  108. int32 req_quest_complete;
  109. int32 map_x;
  110. int32 map_y;
  111. int32 faction_id;
  112. int32 faction_value;
  113. int32 expansion_flag;
  114. int32 holiday_flag;
  115. int32 min_client_version;
  116. int32 max_client_version;
  117. int32 flight_path_id;
  118. int16 mount_id;
  119. int8 mount_red_color;
  120. int8 mount_green_color;
  121. int8 mount_blue_color;
  122. };
  123. struct LocationTransportDestination{
  124. int32 unique_id;
  125. string message;
  126. int32 destination_zone_id;
  127. float destination_x;
  128. float destination_y;
  129. float destination_z;
  130. float destination_heading;
  131. float trigger_x;
  132. float trigger_y;
  133. float trigger_z;
  134. float trigger_radius;
  135. int32 cost;
  136. int32 faction_id;
  137. int32 faction_value;
  138. };
  139. struct LottoPlayer {
  140. int32 end_time;
  141. int8 num_matches;
  142. bool set;
  143. };
  144. struct HouseZone {
  145. int32 id;
  146. string name;
  147. int64 cost_coin;
  148. int32 cost_status;
  149. int64 upkeep_coin;
  150. int32 upkeep_status;
  151. int8 vault_slots;
  152. int8 alignment;
  153. int8 guild_level;
  154. int32 zone_id;
  155. int32 exit_zone_id;
  156. float exit_x;
  157. float exit_y;
  158. float exit_z;
  159. float exit_heading;
  160. };
  161. struct Deposit {
  162. int32 timestamp;
  163. int64 amount;
  164. int64 last_amount;
  165. int32 status;
  166. int32 last_status;
  167. string name;
  168. };
  169. struct HouseHistory {
  170. HouseHistory()
  171. {
  172. timestamp = 0;
  173. amount = 0;
  174. name = string("");
  175. reason = string("");
  176. status = 0;
  177. pos_flag = 0;
  178. }
  179. HouseHistory(int32 in_timestamp, int64 in_amount, string in_name, string in_reason, int32 in_status, int8 in_pos_flag)
  180. {
  181. timestamp = in_timestamp;
  182. amount = in_amount;
  183. name = in_name;
  184. reason = in_reason;
  185. status = in_status;
  186. pos_flag = in_pos_flag;
  187. }
  188. int32 timestamp;
  189. int64 amount;
  190. string name;
  191. string reason;
  192. int32 status;
  193. int8 pos_flag;
  194. };
  195. struct PlayerHouse {
  196. int32 house_id;
  197. int64 unique_id;
  198. int32 instance_id;
  199. int32 upkeep_due;
  200. int64 escrow_coins;
  201. int32 escrow_status;
  202. string player_name;
  203. list<Deposit> deposits;
  204. map<string, Deposit> depositsMap;
  205. list<HouseHistory> history;
  206. };
  207. // Constants for STATs counters
  208. // Server Utilization
  209. #define STAT_SERVER_OS_TYPE 1 // what OS this server is running on
  210. #define STAT_SERVER_CPU_TYPE 2 // cpu type/speed (ie., Intel P4 3.0GHz)
  211. #define STAT_SERVER_CPU_CURRENT 3 // current CPU usage by EQ2World.exe process
  212. #define STAT_SERVER_CPU_PEAK 4 // highest CPU usage by EQ2World.exe this session
  213. #define STAT_SERVER_PHYSICAL_RAM_TOTAL 5 // total RAM in server
  214. #define STAT_SERVER_PHYSICAL_RAM_CURRENT 6 // current RAM usage by EQ2World.exe
  215. #define STAT_SERVER_PHYSICAL_RAM_PEAK 7 // highest RAM usage by EQ2World.exe this session
  216. #define STAT_SERVER_VIRTUAL_RAM_TOTAL 8 // total vRAM in server
  217. #define STAT_SERVER_VIRTUAL_RAM_CURRENT 9 // current vRAM usage by EQ2World.exe
  218. #define STAT_SERVER_VIRTUAL_RAM_PEAK 10 // highest vRAM usage by EQ2World.exe this session
  219. #define STAT_SERVER_DISK_USAGE 11 // size of /eq2emulator folder and contents
  220. #define STAT_SERVER_THREAD_COUNT 12 // thread count of EQ2World.exe process
  221. #define STAT_SERVER_AVG_LATENCY 13 // network latency between world and loginserver
  222. // Server Stats
  223. #define STAT_SERVER_CREATED 100 // unix_timestamp of date server first came online
  224. #define STAT_SERVER_START_TIME 101 // unix_timestamp of date/time server booted up
  225. #define STAT_SERVER_ACCEPTED_CONNECTION 102 // successful connections since server startup
  226. #define STAT_SERVER_MOST_CONNECTIONS 103 // most players online in history of server
  227. #define STAT_SERVER_NUM_ACCOUNTS 104 // total number of unique accounts
  228. #define STAT_SERVER_NUM_CHARACTERS 105 // total number of player characters
  229. #define STAT_SERVER_AVG_CHAR_LEVEL 106 // average level of player characters
  230. #define STAT_SERVER_NUM_ACTIVE_ZONES 107 // number of currently running/loaded zones
  231. #define STAT_SERVER_NUM_ACTIVE_INSTANCES 108 // number of active zones that are "instances"
  232. // Player PvE counters
  233. #define STAT_PLAYER_TOTAL_NPC_KILLS 1000 // total NPC kills by player
  234. #define STAT_PLAYER_TOTAL_DEATHS 1001 // total non-PvP deaths of player
  235. #define STAT_PLAYER_KVD_RATIO 1002 // kill-versus-death ratio of player
  236. #define STAT_PLAYER_HIGHEST_MELEE_HIT 1003 // players highest melee hit to date
  237. #define STAT_PLAYER_HIGHEST_MAGIC_HIT 1004 // players highest magic hit to date
  238. #define STAT_PLAYER_HIGHEST_HO_HIT 1005 // players highest heroic opportunity hit
  239. #define STAT_PLAYER_TOTAL_STATUS 1006 // player total status
  240. #define STAT_PLAYER_TOTAL_WEALTH 1007 // player total wealth
  241. #define STAT_PLAYER_QUESTS_COMPLETED 1008 // total quests completed
  242. #define STAT_PLAYER_RECIPES_KNOWN 1009 // total recipes player knows
  243. #define STAT_PLAYER_TOTAL_CRAFTED_ITEMS 1010 // total items crafted by player
  244. #define STAT_PLAYER_ITEMS_DISCOVERED 1011 // total items discovered by player
  245. #define STAT_PLAYER_RARES_HARVESTED 1012 // total rare harvests by player
  246. #define STAT_PLAYER_ITEMS_HARVESTED 1013 // total rare harvests by player
  247. #define STAT_PLAYER_MASTER_ABILITIES 1014 // total master abilities player has
  248. #define STAT_PLAYER_HIGHEST_FALLING_HIT 1015 // player's highest damage amount taken from falling
  249. // Player PvP counters
  250. #define STAT_PLAYER_TOTAL_PVP_KILLS 1100 // total PVP kills by player
  251. #define STAT_PLAYER_PVP_KILL_STREAK 1101 // longest PVP kill streak of player
  252. #define STAT_PLAYER_TOTAL_PVP_DEATHS 1102 // total PVP deaths of player
  253. #define STAT_PLAYER_PVP_DEATH_STREAK 1103 // longest PVP death streak of player
  254. #define STAT_PLAYER_PVP_KVD_RATIO 1104 // PVP kill-versus-death ratio of player
  255. #define STAT_PLAYER_TOTAL_ARENA_KILLS 1105 // total Arena kills of player
  256. // MOST stats for players
  257. #define STAT_PLAYER_MOST_NPC_KILLS 1200 // IPvP: Player with most NPC kills
  258. #define STAT_PLAYER_MOST_NPC_DEATHS 1201 // IPvP: Player with most non-PVP deaths
  259. #define STAT_PLAYER_MOST_PVP_KILLS 1202 // IPvP: Player with most PvP kills
  260. #define STAT_PLAYER_MOST_PVP_DEATHS 1203 // IPvP: Player with most PvP deaths
  261. #define STAT_PLAYER_MOST_ARENA_KILLS 1204 // IPvP: Player with most Arena kills
  262. #define STAT_PLAYER_MOST_STATUS 1205 // IPvP: Player with most Status
  263. #define STAT_PLAYER_MOST_WEALTH 1206 // IPvP: Player with most Wealth
  264. // HIGHEST stats for players
  265. #define STAT_PLAYER_HIGHEST_NPC_KVD_RATIO 1300 // IPvP: Player with highest NPC kill-versus-death ratio
  266. #define STAT_PLAYER_HIGHEST_PVP_KILL_STREAK 1301 // IPvP: Player with longest PvP kill streak
  267. #define STAT_PLAYER_HIGHEST_PVP_DEATH_STREAK 1302 // IPvP: Player with longest PvP death streak
  268. #define STAT_PLAYER_HIGHEST_PVP_KVD_RATIO 1303 // IPvP: Player with highest PvP kill-versus-death ratio
  269. #define STAT_PLAYER_HIGHEST_HP 1304 // IPvP: Player with highest HP on server
  270. #define STAT_PLAYER_HIGHEST_POWER 1305 // IPvP: Player with highest Power on server
  271. #define STAT_PLAYER_HIGHEST_RESISTS 1306 // IPvP: Player with highest Resists on server
  272. struct Statistic {
  273. int32 stat_id;
  274. sint32 stat_value;
  275. int32 stat_date;
  276. bool save_needed;
  277. };
  278. // Player EVENT defines
  279. // Some EVENTs are single occurrance (S), while others are cummulative throughout the life of the player (C)
  280. #define PLAYER_EVENT_NEW_ADV_LEVEL 2000 // (C) player achieves a new adventure level
  281. #define PLAYER_EVENT_NEW_TS_LEVEL 2001 // (C) player achieves a new tradeskill level
  282. #define PLAYER_EVENT_NEW_AA 2002 // (C) player earns AA pt
  283. #define PLAYER_EVENT_NEW_ACHIEVEMENT 2003 // (C) player new achievement
  284. #define PLAYER_EVENT_LAST_DEATH 2004 // (S) player was last killed
  285. #define PLAYER_EVENT_LAST_KILL 2005 // (S) player last killed spawn_id
  286. #define PLAYER_EVENT_DISCOVER_POI 2006 // (C) player discovers location_id
  287. // These maybe should be World stat events, since it is about 1 player discovering a new item?
  288. #define PLAYER_EVENT_DISCOVER_ITEM 2007 // (C) player discovers item_id
  289. #define PLAYER_EVENT_DISCOVER_RECIPE 2008 // (C) player discovers recipe_id
  290. struct PlayerHistory {
  291. int32 history_zone;
  292. int32 history_id;
  293. sint32 history_value;
  294. int32 history_date;
  295. bool save_needed;
  296. };
  297. struct GlobalLoot {
  298. int8 minLevel;
  299. int8 maxLevel;
  300. int32 table_id;
  301. int32 loot_tier;
  302. };
  303. #define TRANSPORT_TYPE_LOCATION 0
  304. #define TRANSPORT_TYPE_ZONE 1
  305. #define TRANSPORT_TYPE_GENERIC 2
  306. #define TRANSPORT_TYPE_FLIGHT 3
  307. // structs MUST start with class_id and race_id, in that order as int8's
  308. struct StartingStructHeader
  309. {
  310. int8 class_id;
  311. int8 race_id;
  312. };
  313. struct StartingSkill
  314. {
  315. StartingStructHeader header;
  316. int32 skill_id;
  317. int16 current_val;
  318. int16 max_val;
  319. int32 progress; // what is this for..?
  320. };
  321. struct StartingSpell
  322. {
  323. StartingStructHeader header;
  324. int32 spell_id;
  325. int8 tier;
  326. int32 knowledge_slot;
  327. };
  328. #define MAX_VOICEOVER_TYPE 2
  329. struct VoiceOverStruct{
  330. string mp3_string;
  331. string text_string;
  332. string emote_string;
  333. int32 key1;
  334. int32 key2;
  335. bool is_garbled;
  336. int8 garble_link_id;
  337. };
  338. struct WhoAllPeerPlayer {
  339. std::string name;
  340. std::string subtitle;
  341. std::string zoneName;
  342. int8 adventureClass;
  343. int8 tradeskillClass;
  344. int8 deity;
  345. int8 race;
  346. sint16 status;
  347. int flags;
  348. int flags2;
  349. int16 level;
  350. WhoAllPeerPlayer(std::string inName, std::string inSubtitle, std::string inZoneName, int8 inAdvClass, int8 inTradeskillClass, int8 inDeity, int8 inRace,
  351. sint16 inStatus, int inFlags, int inFlags2, int16 inLevel)
  352. {
  353. name = inName;
  354. subtitle = inSubtitle;
  355. zoneName = inZoneName;
  356. adventureClass = inAdvClass;
  357. tradeskillClass = inTradeskillClass;
  358. deity = inDeity;
  359. race = inRace;
  360. status = inStatus;
  361. flags = inFlags;
  362. flags2 = inFlags2;
  363. level = inLevel;
  364. }
  365. };
  366. class ZoneList {
  367. public:
  368. ZoneList();
  369. ~ZoneList();
  370. void Add(ZoneServer* zone);
  371. void Remove(ZoneServer* zone);
  372. bool GetZone(ZoneChangeDetails* zone_details, int32 opt_zone_id, std::string opt_zone_name = "", bool loadZone = true, bool skip_existing_zones = false, bool increment_zone = true, bool check_peers = true, bool check_instances = false, bool only_always_loaded = false, bool skip_self = false);
  373. bool GetZoneByInstance(ZoneChangeDetails* zone_details, int32 instance_id, int32 zone_id = 0, bool loadZone = true, bool skip_existing_zones = false, bool increment_zone = true, bool check_peers = true);
  374. bool IsClientConnectedPeer(int32 account_id);
  375. //ZoneServer* Get(int32 id, bool loadZone = true, bool skip_existing_zones = false, bool increment_zone = true);
  376. //ZoneServer* Get(const char* zone_name, bool loadZone=true, bool skip_existing_zones = false, bool increment_zone = true);
  377. //ZoneServer* GetByInstanceID(int32 id, int32 zone_id=0, bool skip_existing_zones = false, bool increment_zone = true);
  378. /// <summary>Get the instance for the given zone id with the lowest population</summary>
  379. /// <param name='zone_id'>The id of the zone to look up</param>
  380. /// <returns>ZoneServer* of an active zone with the given id</returns>
  381. ZoneServer* GetByLowestPopulation(int32 zone_id);
  382. int32 GetZonesPlayersCount();
  383. void AddClientToMap(string name, Client* client){
  384. name = ToLower(name);
  385. MClientList.lock();
  386. client_map[name] = client;
  387. MClientList.unlock();
  388. }
  389. void CheckFriendList(Client* client);
  390. void CheckFriendZoned(Client* client);
  391. // move to Chat/Chat.h?
  392. bool HandleGlobalChatMessage(Client* from, char* to, int16 channel, const char* message, const char* channel_name = 0, int32 current_language_id = 0);
  393. void HandleGlobalBroadcast(const char* message);
  394. void HandleGlobalAnnouncement(const char* message);
  395. //
  396. int32 Count();
  397. Client* GetClientByCharName(string name){
  398. name = ToLower(name);
  399. Client* ret = 0;
  400. MClientList.lock();
  401. if(client_map.count(name) > 0)
  402. ret = client_map[name];
  403. MClientList.unlock();
  404. return ret;
  405. }
  406. Client* GetClientByCharID(int32 id) {
  407. Client* ret = 0;
  408. MClientList.lock();
  409. map<string, Client*>::iterator itr;
  410. for (itr = client_map.begin(); itr != client_map.end(); itr++) {
  411. if (itr->second->GetCharacterID() == id) {
  412. ret = itr->second;
  413. break;
  414. }
  415. }
  416. MClientList.unlock();
  417. return ret;
  418. }
  419. Client* GetClientByEQStream(EQStream* eqs) {
  420. Client* ret = 0;
  421. if (eqs) {
  422. MClientList.lock();
  423. map<string, Client*>::iterator itr;
  424. for (itr = client_map.begin(); itr != client_map.end(); itr++) {
  425. if (itr->second->getConnection() == eqs) {
  426. ret = itr->second;
  427. break;
  428. }
  429. }
  430. MClientList.unlock();
  431. }
  432. return ret;
  433. }
  434. void UpdateVitality(float amount);
  435. void RemoveClientFromMap(string name, Client* client){
  436. name = ToLower(name);
  437. MClientList.lock();
  438. if(client_map.count(name) > 0 && client_map[name] == client)
  439. client_map.erase(name);
  440. MClientList.unlock();
  441. }
  442. bool ClientConnected(int32 account_id);
  443. void RemoveClientZoneReference(ZoneServer* zone);
  444. void ReloadClientQuests();
  445. bool DepopFinished();
  446. void Depop();
  447. void Repop();
  448. void DeleteSpellProcess();
  449. void SendZoneWideChannelMessage(std::string fromName, const char* to, int16 channel, const char* message, float distance, const char* channel_name, int32 language);
  450. void LoadSpellProcess();
  451. void ProcessWhoQuery(const char* query, Client* client);
  452. void ProcessWhoQuery(vector<string>* queries, ZoneServer* zone, vector<Entity*>* players, bool isGM);
  453. void SendZoneList(Client* client);
  454. void WritePlayerStatistics();
  455. void ShutDownZones();
  456. void ReloadMail();
  457. void ReloadSpawns();
  458. void WatchdogHeartbeat();
  459. void SendTimeUpdate();
  460. void PopulateClientList(http::response<http::string_body>& res);
  461. void PopulateZoneList(http::response<http::string_body>& res);
  462. private:
  463. Mutex MClientList;
  464. Mutex MZoneList;
  465. map<ZoneServer*, int32> removed_zoneservers;
  466. map<string,Client*> client_map;
  467. list<ZoneServer*> zlist;
  468. };
  469. class World {
  470. public:
  471. World();
  472. ~World();
  473. int8 GetClassID(const char* name);
  474. void Process();
  475. void init(std::string web_ipaddr, int16 web_port, std::string cert_file, std::string key_file, std::string key_password, std::string hardcode_user, std::string hardcode_password);
  476. PacketStruct* GetWorldTime(int16 version);
  477. void WorldTimeTick();
  478. float GetXPRate();
  479. float GetTSXPRate();
  480. void LoadVitalityInformation();
  481. void UpdateVitality();
  482. WorldTime* GetWorldTimeStruct(){
  483. return &world_time;
  484. }
  485. ulong GetCurrentThreadID();
  486. int64 GetThreadUsageCPUTime();
  487. // These 2 functions are never used. What was their purpose? Should they be removed?
  488. void AddNPCAppearance(int32 id, AppearanceData* appearance){ npc_appearance_list[id] = appearance; }
  489. AppearanceData* GetNPCAppearance(int32 id) { return npc_appearance_list[id]; }
  490. void ReloadGuilds();
  491. bool ReportBug(string data, char* player_name, int32 account_id, const char* spawn_name, int32 spawn_id, int32 zone_id);
  492. void AddSpawnScript(int32 id, const char* name);
  493. void AddSpawnEntryScript(int32 id, const char* name);
  494. void AddSpawnLocationScript(int32 id, const char* name);
  495. void AddZoneScript(int32 id, const char* name);
  496. const char* GetSpawnScript(int32 id);
  497. const char* GetSpawnEntryScript(int32 id);
  498. const char* GetSpawnLocationScript(int32 id);
  499. const char* GetZoneScript(int32 id);
  500. void ResetSpawnScripts();
  501. void ResetZoneScripts();
  502. int16 GetMerchantItemQuantity(int32 merchant_id, int32 item_id);
  503. void DecreaseMerchantQuantity(int32 merchant_id, int32 item_id, int16 amount);
  504. int32 GetInventoryID(int32 merchant_id, int32 item_id);
  505. void AddMerchantItem(int32 inventory_id, MerchantItemInfo ItemInfo);
  506. void RemoveMerchantItem(int32 inventory_id, int32 item_id);
  507. vector<MerchantItemInfo>* GetMerchantList(int32 merchant_id);
  508. vector<MerchantItemInfo>* GetMerchantItemList(int32 merchant_id, int8 merchant_type, Player* player);
  509. MerchantInfo* GetMerchantInfo(int32 merchant_id);
  510. map<int32, MerchantInfo*>* GetMerchantInfo();
  511. void AddMerchantInfo(int32 merchant_id, MerchantInfo* multiplier);
  512. void DeleteMerchantsInfo();
  513. void DeleteMerchantItems();
  514. void DeleteSpawns();
  515. vector<Variable*>* GetClientVariables();
  516. void WritePlayerStatistics();
  517. void WriteServerStatistics();
  518. void AddServerStatistic(int32 stat_id, sint32 stat_value, int32 stat_date);
  519. void UpdateServerStatistic(int32 stat_id, sint32 stat_value, bool overwrite = false);
  520. sint32 GetServerStatisticValue(int32 stat_id);
  521. void RemoveServerStatistics();
  522. //PlayerGroup* AddGroup(Client* leader);
  523. //void AddGroupMember(PlayerGroup* group, Client* member);
  524. //void RemoveGroupMember(Client* member, bool immediate = false);
  525. //void DisbandGroup(PlayerGroup* group, bool lock = true);
  526. void SendGroupQuests(PlayerGroup* group, Client* client);
  527. //void UpdateGroupBuffs();
  528. //void RemoveGroupBuffs(PlayerGroup *group, Client *client);
  529. //void SetPendingGroup(char* name, char* leader);
  530. //void GroupMessage(PlayerGroup* group, const char* message, ...);
  531. //void SimpleGroupMessage(PlayerGroup* group, const char* message);
  532. //void GroupChatMessage(PlayerGroup* group, Spawn* from, const char* message);
  533. //const char* GetPendingGroup(string name);
  534. //void GroupReadLock();
  535. //void GroupReadUnLock();
  536. //void CheckRemoveGroupedPlayer();
  537. //void SendGroupUpdate(PlayerGroup* group, Client* exclude = 0);
  538. bool RejoinGroup(Client* client, int32 group_id);
  539. //bool MakeLeader(Client* leader, string new_leader);
  540. void AddBonuses(Item* item, ItemStatsValues* values, int16 type, sint32 value, Entity* entity);
  541. int32 CreateGuild(const char* guild_name, Client* leader = 0, int32 group_id = 0);
  542. void SaveGuilds();
  543. void PickRandomLottoDigits(int32* digits);
  544. void AddLottoPlayer(int32 character_id, int32 end_time);
  545. void RemoveLottoPlayer(int32 character_id);
  546. void SetLottoPlayerNumMatches(int32 character_id, int8 num_matches);
  547. void CheckLottoPlayers();
  548. void PopulateTOVStatMap();
  549. int32 LoadItemBlueStats();
  550. sint16 GetItemStatAOMValue(sint16 subtype);
  551. sint16 GetItemStatTOVValue(sint16 subtype);
  552. sint16 GetItemStatDOVValue(sint16 subtype);
  553. sint16 GetItemStatCOEValue(sint16 subtype);
  554. sint16 GetItemStatKAValue(sint16 subtype);
  555. sint16 GetItemStatTESTValue(sint16 subtype);
  556. int8 TranslateSlotSubTypeToClient(Client* client, int8 stat_type, sint16 sub_type);
  557. vector<string> biography;
  558. volatile bool items_loaded;
  559. volatile bool spells_loaded;
  560. volatile bool achievments_loaded;
  561. std::atomic<bool> world_loaded;
  562. std::atomic<int64> world_uptime;
  563. void AddHouseZone(int32 id, string name, int64 cost_coins, int32 cost_status, int64 upkeep_coins, int32 upkeep_status, int8 vault_slots, int8 alignment, int8 guild_level, int32 zone_id, int32 exit_zone_id, float exit_x, float exit_y, float exit_z, float exit_heading);
  564. HouseZone* GetHouseZone(int32 id);
  565. void AddPlayerHouse(int32 char_id, int32 house_id, int64 unique_id, int32 instance_id, int32 upkeep_due, int64 escrow_coins, int32 escrow_status, string player_name);
  566. PlayerHouse* GetPlayerHouseByHouseID(int32 char_id, int32 house_id);
  567. PlayerHouse* GetPlayerHouseByUniqueID(int64 unique_id);
  568. PlayerHouse* GetPlayerHouseByInstanceID(int32 instance_id);
  569. vector<PlayerHouse*> GetAllPlayerHouses(int32 char_id);
  570. vector<PlayerHouse*> GetAllPlayerHousesByHouseID(int32 house_id);
  571. PlayerHouse* GetPlayerHouse(Client* client, int32 spawn_id, int64 unique_house_id, HouseZone** set_house_zone);
  572. void ReloadHouseData(PlayerHouse* ph);
  573. PlayerGroupManager* GetGroupManager() { return &m_playerGroupManager; }
  574. bool CheckTempBugCRC(char* msg);
  575. void SyncCharacterAbilities(Client* client);
  576. void LoadStartingLists();
  577. void PurgeStartingLists();
  578. multimap<int8, multimap<int8, StartingSkill>*> starting_skills;
  579. multimap<int8, multimap<int8, StartingSpell>*> starting_spells;
  580. Mutex MStartingLists;
  581. void SetReloadingSubsystem(string subsystem);
  582. void RemoveReloadingSubSystem(string subsystem);
  583. bool IsReloadingSubsystems();
  584. int32 GetSuppressedWarningTime() {
  585. return suppressed_warning;
  586. }
  587. void SetSuppressedWarning() { suppressed_warning = Timer::GetCurrentTime2(); }
  588. map<string, int32> GetOldestReloadingSubsystem();
  589. void LoadRegionMaps(std::string zoneFile);
  590. RegionMap* GetRegionMap(std::string zoneFile, int32 client_version);
  591. void LoadMaps(std::string zoneFile);
  592. void RemoveMaps(std::string zoneFile);
  593. Map* GetMap(std::string zoneFile, int32 client_version);
  594. void SendTimeUpdate();
  595. // just in case we roll over a time as to not send bad times to clients (days before hours, hours before minutes as examples)
  596. Mutex MWorldTime;
  597. void LoadVoiceOvers();
  598. void PurgeVoiceOvers();
  599. typedef std::multimap<int16, VoiceOverStruct>::iterator VOMapIterator;
  600. bool FindVoiceOver(int8 type, int32 id, int16 index, VoiceOverStruct* struct_ = nullptr, bool* find_garbled = nullptr, VoiceOverStruct* garble_struct_ = nullptr);
  601. void AddVoiceOver(int8 type, int32 id, int16 index, VoiceOverStruct* struct_);
  602. void CopyVoiceOver(VoiceOverStruct* struct1, VoiceOverStruct* struct2);
  603. /* NPC Spells */
  604. void AddNPCSpell(int32 list_id, int32 spell_id, int8 tier, bool spawn_cast, bool aggro_cast, sint8 req_hp_ratio);
  605. vector<NPCSpell*>* GetNPCSpells(int32 primary_list, int32 secondary_list);
  606. void PurgeNPCSpells();
  607. void ClientAuthApproval(int32 success, std::string charName, int32 account_id, std::string zone_name, int32 zoning_id, int32 instance_id, bool first_login);
  608. static void Web_worldhandle_status(const http::request<http::string_body>& req, http::response<http::string_body>& res);
  609. static void Web_worldhandle_clients(const http::request<http::string_body>& req, http::response<http::string_body>& res);
  610. static void Web_worldhandle_setadminstatus(const http::request<http::string_body>& req, http::response<http::string_body>& res);
  611. static void Web_worldhandle_reloadrules(const http::request<http::string_body>& req, http::response<http::string_body>& res);
  612. static void Web_worldhandle_reloadcommand(const http::request<http::string_body>& req, http::response<http::string_body>& res);
  613. static void Web_worldhandle_addpeer(const http::request<http::string_body>& req, http::response<http::string_body>& res);
  614. static void Web_worldhandle_zones(const http::request<http::string_body>& req, http::response<http::string_body>& res);
  615. static void Web_worldhandle_addcharauth(const http::request<http::string_body>& req, http::response<http::string_body>& res);
  616. static void Web_worldhandle_startzone(const http::request<http::string_body>& req, http::response<http::string_body>& res);
  617. static void Web_worldhandle_sendglobalmessage(const http::request<http::string_body>& req, http::response<http::string_body>& res);
  618. static void Web_worldhandle_newgroup(const http::request<http::string_body>& req, http::response<http::string_body>& res);
  619. static void Web_worldhandle_addgroupmember(const http::request<http::string_body>& req, http::response<http::string_body>& res);
  620. static void Web_worldhandle_removegroupmember(const http::request<http::string_body>& req, http::response<http::string_body>& res);
  621. static void Web_worldhandle_disbandgroup(const http::request<http::string_body>& req, http::response<http::string_body>& res);
  622. static void Web_worldhandle_createguild(const http::request<http::string_body>& req, http::response<http::string_body>& res);
  623. static void Web_worldhandle_addguildmember(const http::request<http::string_body>& req, http::response<http::string_body>& res);
  624. static void Web_worldhandle_removeguildmember(const http::request<http::string_body>& req, http::response<http::string_body>& res);
  625. static void Web_worldhandle_setguildpermission(const http::request<http::string_body>& req, http::response<http::string_body>& res);
  626. static void Web_worldhandle_setguildeventfilter(const http::request<http::string_body>& req, http::response<http::string_body>& res);
  627. Mutex MVoiceOvers;
  628. static sint64 newValue;
  629. private:
  630. multimap<int32, multimap<int16, VoiceOverStruct>*> voiceover_map[3];
  631. int32 suppressed_warning = 0;
  632. map<string, int32> reloading_subsystems;
  633. //void RemovePlayerFromGroup(PlayerGroup* group, GroupMemberInfo* info, bool erase = true);
  634. //void DeleteGroupMember(GroupMemberInfo* info);
  635. Mutex MReloadingSubsystems;
  636. Mutex MMerchantList;
  637. Mutex MSpawnScripts;
  638. Mutex MZoneScripts;
  639. //Mutex MGroups;
  640. mutable std::shared_mutex MNPCSpells;
  641. map<int32, MerchantInfo*> merchant_info;
  642. map<int32, vector<MerchantItemInfo> > merchant_inventory_items;
  643. int32 vitality_frequency;
  644. float vitality_amount;
  645. float xp_rate;
  646. float ts_xp_rate; // JA
  647. WorldTime world_time;
  648. map<int32,AppearanceData*> npc_appearance_list;
  649. map<int32, string> spawn_scripts;
  650. map<int32, string> spawnentry_scripts;
  651. map<int32, string> spawnlocation_scripts;
  652. map<int32, string> zone_scripts;
  653. //vector<PlayerGroup*> player_groups;
  654. //map<GroupMemberInfo*, int32> group_removal_pending;
  655. //map<string, string> pending_groups;
  656. map<int32, Statistic*> server_statistics;
  657. MutexMap<int32, LottoPlayer*> lotto_players;
  658. int32 last_checked_time;
  659. Timer save_time_timer;
  660. Timer time_tick_timer;
  661. Timer vitality_timer;
  662. Timer player_stats_timer;
  663. Timer server_stats_timer;
  664. //Timer remove_grouped_player;
  665. Timer guilds_timer;
  666. Timer lotto_players_timer;
  667. Timer group_buff_updates;
  668. Timer watchdog_timer;
  669. map<int32, HouseZone*> m_houseZones;
  670. // Map <house id, map<char id, player house>>
  671. map<int32, map<int32, PlayerHouse*> > m_playerHouses;
  672. Mutex MHouseZones;
  673. Mutex MPlayerHouses;
  674. map<int16,int16> tov_itemstat_conversion;
  675. map<int16,int16> dov_itemstat_conversion;
  676. map<int16,int16> coe_itemstat_conversion;
  677. map<int16,int16> ka_itemstat_conversion;
  678. PlayerGroupManager m_playerGroupManager;
  679. Mutex MBugReport;
  680. map<sint32, bool> bug_report_crc;
  681. std::map<std::string, RegionMapRange*> region_maps;
  682. std::map<std::string, MapRange*> maps;
  683. Mutex MWorldMaps;
  684. Mutex MWorldRegionMaps;
  685. map<int32, map<int32, NPCSpell*> > npc_spell_list;
  686. WebServer* world_webserver;
  687. };
  688. #endif