client.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783
  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 CLIENT_H
  17. #define CLIENT_H
  18. #include <list>
  19. #include <atomic>
  20. #include <mutex>
  21. #include <shared_mutex>
  22. #include "../common/EQStream.h"
  23. #include "../common/timer.h"
  24. #include "Items/Items.h"
  25. #include "zoneserver.h"
  26. #include "Player.h"
  27. #include "Quests.h"
  28. #include "Web/PeerManager.h"
  29. using namespace std;
  30. #define CLIENT_TIMEOUT 60000
  31. struct TransportDestination;
  32. struct ConversationOption;
  33. struct VoiceOverStruct;
  34. struct GroupOptions;
  35. #define MAIL_SEND_RESULT_SUCCESS 0
  36. #define MAIL_SEND_RESULT_UNKNOWN_PLAYER 1
  37. #define MAIL_SEND_RESULT_CANNOT_SEND_TO_PLAYER 2
  38. #define MAIL_SEND_RESULT_GIFT_WRONG_SERVER 3 /* Cannot send gifts across worlds */
  39. #define MAIL_SEND_RESULT_CANNOT_SEND_TO_SELF 4
  40. #define MAIL_SEND_RESULT_MAILBOX_FULL 5
  41. #define MAIL_SEND_RESULT_NOT_ENOUGH_COIN 6
  42. #define MAIL_SEND_RESULT_ITEM_IN_BAG 7 /* Cannot send non-empty bags as gifts */
  43. #define MAIL_SEND_RESULT_NOT_IN_GUILD 8
  44. #define MAIL_SEND_RESULT_GUILD_ACCESS_DENIED 9
  45. #define MAIL_SEND_RESULT_GIFTS_TO_GUILD 10 /* Cannot send gifts to entire guild */
  46. #define MAIL_SEND_RESULT_EMPTY_TO_LIST 11 /* Empty recipient list */
  47. #define MAIL_SEND_RESULT_TRIAL_PLAYERS 12 /* Cannot send mail to trial players */
  48. #define MAIL_SEND_RESULT_MAIL_WRONG_SERVER 13 /* Cannot send mail across worlds */
  49. #define MAIL_SEND_RESULT_UNKNOWN_ERROR 14
  50. #define MAIL_TYPE_REGULAR 0
  51. #define MAIL_TYPE_SPAM 1
  52. #define MAIL_TYPE_GM 2
  53. struct QueuedQuest{
  54. int32 quest_id;
  55. int32 step;
  56. bool display_quest_helper;
  57. };
  58. struct BuyBackItem{
  59. int32 item_id;
  60. int32 unique_id;
  61. int16 quantity;
  62. int32 price;
  63. bool save_needed;
  64. };
  65. struct MacroData{
  66. string name;
  67. string text;
  68. int16 icon;
  69. };
  70. struct Mail {
  71. int32 mail_id;
  72. int32 player_to_id;
  73. string player_from;
  74. string subject;
  75. string mail_body;
  76. int8 already_read;
  77. int8 mail_type;
  78. int32 coin_copper;
  79. int32 coin_silver;
  80. int32 coin_gold;
  81. int32 coin_plat;
  82. int16 stack;
  83. int32 postage_cost;
  84. int32 attachment_cost;
  85. int32 char_item_id;
  86. int32 time_sent;
  87. int32 expire_time;
  88. int8 save_needed;
  89. };
  90. struct MailWindow {
  91. int32 coin_copper;
  92. int32 coin_silver;
  93. int32 coin_gold;
  94. int32 coin_plat;
  95. Item* item;
  96. int32 char_item_id;
  97. int32 stack;
  98. };
  99. struct PendingGuildInvite {
  100. Guild* guild;
  101. Player* invited_by;
  102. };
  103. struct PendingResurrection {
  104. Spawn* caster;
  105. Timer* expire_timer;
  106. string spell_name;
  107. string heal_name;
  108. bool active;
  109. float hp_perc;
  110. float mp_perc;
  111. float range;
  112. int8 crit_mod;
  113. bool no_calcs;
  114. int32 subspell;
  115. bool crit;
  116. bool should_delete;
  117. int32 spell_visual;
  118. };
  119. #define PAPERDOLL_TYPE_FULL 0
  120. #define PAPERDOLL_TYPE_HEAD 1
  121. struct IncomingPaperdollImage {
  122. uchar* image_bytes;
  123. int32 current_size_bytes;
  124. int8 image_num_packets;
  125. int8 last_received_packet_index;
  126. int8 image_type;
  127. };
  128. struct WaypointInfo {
  129. int32 id;
  130. int8 type;
  131. };
  132. class Client {
  133. public:
  134. Client(EQStream* ieqs);
  135. ~Client();
  136. void RemoveClientFromZone();
  137. bool Process(bool zone_process = false);
  138. void Disconnect(bool send_disconnect = true);
  139. void SetConnected(bool val){ connected = val; }
  140. bool IsConnected(){ return connected; }
  141. bool IsReadyForSpawns(){ return ready_for_spawns; }
  142. bool IsReadyForUpdates() { return ready_for_updates; }
  143. bool IsZoning(){ return client_zoning; }
  144. void SetReadyForUpdates();
  145. void SetReadyForSpawns(bool val);
  146. void QueuePacket(EQ2Packet* app, bool attemptedCombine=false);
  147. void SendLoginInfo();
  148. int8 GetMessageChannelColor(int8 channel_type);
  149. void HandleTellMessage(const char* fromName, const char* message, const char* to, int32 current_language_id);
  150. void SimpleMessage(int8 color, const char* message);
  151. void Message(int8 type, const char* message, ...);
  152. void SendSpellUpdate(Spell* spell, bool add_silently = false, bool add_to_hotbar = true);
  153. void Zone(ZoneChangeDetails* new_zone, ZoneServer* opt_zone = nullptr, bool set_coords = true, bool is_spell = false);
  154. void Zone(const char* new_zone, bool set_coords = true, bool is_spell = false);
  155. void Zone(int32 instanceid, bool set_coords = true, bool byInstanceID=false, bool is_spell = false);
  156. void ApproveZone();
  157. void SendZoneInfo();
  158. void SendZoneSpawns();
  159. void HandleVerbRequest(EQApplicationPacket* app);
  160. void SendControlGhost(int32 send_id=0xFFFFFFFF, int8 unknown2=0);
  161. void SendCharInfo();
  162. void SendLoginDeniedBadVersion();
  163. void SendCharPOVGhost();
  164. void SendPlayerDeathWindow();
  165. float DistanceFrom(Client* client);
  166. void SendDefaultGroupOptions();
  167. bool HandleLootItemByID(Spawn* entity, int32 item_id, Spawn* target);
  168. bool HandleLootItem(Spawn* entity, Item* item, Spawn* target=nullptr, bool overrideLootRestrictions = false);
  169. void HandleLootItemRequestPacket(EQApplicationPacket* app);
  170. void HandleSkillInfoRequest(EQApplicationPacket* app);
  171. void HandleExamineInfoRequest(EQApplicationPacket* app);
  172. void HandleQuickbarUpdateRequest(EQApplicationPacket* app);
  173. void SendPopupMessage(int8 unknown, const char* text, const char* type, float size, int8 red, int8 green, int8 blue);
  174. void PopulateSkillMap();
  175. void ChangeLevel(int16 old_level, int16 new_level);
  176. void ChangeTSLevel(int16 old_level, int16 new_level);
  177. bool Summon(const char* search_name);
  178. std::string IdentifyInstanceLockout(int32 zoneID, bool displayClient = true);
  179. bool IdentifyInstance(ZoneChangeDetails* zone_details, int32 zoneID);
  180. bool TryZoneInstance(int32 zoneID, bool zone_coords_valid=false);
  181. bool GotoSpawn(const char* search_name, bool forceTarget=false);
  182. void DisplayDeadWindow();
  183. void HandlePlayerRevive(int32 point_id);
  184. void Bank(Spawn* banker, bool cancel = false);
  185. void BankWithdrawal(int64 amount);
  186. bool BankWithdrawalNoBanker(int64 amount);
  187. bool BankHasCoin(int64 amount);
  188. void BankDeposit(int64 amount);
  189. Spawn* GetBanker();
  190. void SetBanker(Spawn* in_banker);
  191. bool AddItem(int32 item_id, int16 quantity = 0, AddItemType type = AddItemType::NOT_SET);
  192. bool AddItem(Item* item, bool* item_deleted = 0, AddItemType type = AddItemType::NOT_SET);
  193. bool AddItemToBank(int32 item_id, int16 quantity = 0);
  194. bool AddItemToBank(Item* item);
  195. void UnequipItem(int16 index, sint32 bag_id = -999, int8 to_slot = 255, int8 appearance_equip = 0);
  196. bool RemoveItem(Item *item, int16 quantity, bool force_override_no_delete = false);
  197. void ProcessTeleport(Spawn* spawn, vector<TransportDestination*>* destinations, int32 transport_id = 0, bool is_spell = false);
  198. void ProcessTeleportLocation(EQApplicationPacket* app);
  199. void UpdateCharacterInstances();
  200. void SetLastSavedTimeStamp(int32 unixts) { last_saved_timestamp = unixts; }
  201. int32 GetLastSavedTimeStamp() { return last_saved_timestamp; }
  202. bool CheckZoneAccess(const char* zoneName);
  203. ZoneServer* GetCurrentZone();
  204. int32 GetCurrentZoneID();
  205. void SetCurrentZoneByInstanceID(int32 id, int32 zoneid);
  206. //void SetCurrentZoneByInstanceID(instanceid, zoneid);
  207. void SetCurrentZone(int32 id);
  208. void SetCurrentZone(ZoneServer* zone);
  209. void SetZoningDestination(ZoneServer* zone) {
  210. zoning_destination = zone;
  211. }
  212. ZoneServer* GetZoningDestination() { return zoning_destination; }
  213. Player* GetPlayer(){ return player; }
  214. EQStream* getConnection(){ return eqs; }
  215. void setConnection(EQStream* ieqs){ eqs = ieqs; }
  216. inline int32 GetIP() { return ip; }
  217. inline int16 GetPort() { return port; }
  218. inline int32 WaitingForBootup() { return pwaitingforbootup; }
  219. inline int32 GetCharacterID() { return character_id; }
  220. inline int32 GetAccountID() { return account_id; }
  221. inline const char* GetAccountName() { return account_name; }
  222. inline sint16 GetAdminStatus() { return admin_status; }
  223. inline int16 GetVersion() { return version; }
  224. void SetNameCRC(int32 val){ name_crc = val; }
  225. int32 GetNameCRC(){ return name_crc; }
  226. void SetVersion(int16 new_version){ version = new_version; }
  227. void SetAccountID(int32 in_accountid) { account_id = in_accountid; }
  228. void SetCharacterID(int32 in_characterid) { character_id = in_characterid; }
  229. void SetAdminStatus(sint16 in_status) { admin_status = in_status; }
  230. void DetermineCharacterUpdates ( );
  231. void UpdateTimeStampFlag ( int8 flagType )
  232. {
  233. if(! (timestamp_flag & flagType ) )
  234. timestamp_flag |= flagType;
  235. }
  236. int8 GetTimeStampFlag ( ) { return timestamp_flag; }
  237. bool UpdateQuickbarNeeded();
  238. void Save();
  239. bool remove_from_list;
  240. void CloseLoot(int32 spawn_id);
  241. void SendLootResponsePacket(int32 total_coins, vector<Item*>* items, Spawn* entity, bool ignore_loot_tier = false);
  242. void LootSpawnRequest(Spawn* entity, bool attemptDisarm=true);
  243. bool LootSpawnByMethod(Spawn* entity);
  244. void OpenChest(Spawn* entity, bool attemptDisarm=true);
  245. void CastGroupOrSelf(Entity* source, uint32 spellID, uint32 spellTier=1, float restrictiveRadius=0.0f);
  246. void CheckPlayerQuestsKillUpdate(Spawn* spawn);
  247. void CheckPlayerQuestsChatUpdate(Spawn* spawn);
  248. void CheckPlayerQuestsItemUpdate(Item* item);
  249. void CheckPlayerQuestsSpellUpdate(Spell* spell);
  250. void CheckPlayerQuestsLocationUpdate();
  251. void AddPendingQuest(Quest* quest, bool forced = false);
  252. void AcceptQuest(int32 quest_id);
  253. void RemovePendingQuest(int32 quest_id);
  254. void SetPlayerQuest(Quest* quest, map<int32, int32>* progress);
  255. void AddPlayerQuest(Quest* quest, bool call_accepted = true, bool send_packets = true);
  256. void RemovePlayerQuest(int32 id, bool send_update = true, bool delete_quest = true);
  257. void SendQuestJournal(bool all_quests = false, Client* client = 0, bool updated = true);
  258. void SendQuestUpdate(Quest* quest);
  259. void SendQuestFailure(Quest* quest);
  260. void SendQuestUpdateStep(Quest* quest, int32 step, bool display_quest_helper = true);
  261. void SendQuestUpdateStepImmediately(Quest* quest, int32 step, bool display_quest_helper = true);
  262. void DisplayQuestRewards(Quest* quest, int64 coin, vector<Item*>* rewards=0, vector<Item*>* selectable_rewards=0, map<int32, sint32>* factions=0, const char* header="Quest Reward!", int32 status_points=0, const char* text=0, bool was_displayed = false);
  263. void PopulateQuestRewardItems(vector <Item*>* items, PacketStruct* packet, std::string num_rewards_str = "num_rewards", std::string reward_id_str = "reward_id" , std::string item_str = "item");
  264. void DisplayQuestComplete(Quest* quest, bool tempReward = false, std::string customDescription = string(""), bool was_displayed = false);
  265. void DisplayRandomizeFeatures(int32 features);
  266. void AcceptQuestReward(Quest* quest, int32 item_id);
  267. Quest* GetPendingQuestAcceptance(int32 item_id);
  268. void DisplayConversation(int32 conversation_id, int32 spawn_id, vector<ConversationOption>* conversations, const char* text, const char* mp3, int32 key1, int32 key2, int8 language = 0, int8 can_close = 1);
  269. void DisplayConversation(Item* item, vector<ConversationOption>* conversations, const char* text, int8 type, const char* mp3 = 0, int32 key1 = 0, int32 key2 = 0, int8 language = 0, int8 can_close = 1);
  270. void DisplayConversation(Spawn* src, int8 type, vector<ConversationOption>* conversations, const char* text, const char* mp3 = 0, int32 key1 = 0, int32 key2 = 0, int8 language = 0, int8 can_close = 1);
  271. void CloseDialog(int32 conversation_id);
  272. int32 GetConversationID(Spawn* spawn, Item* item);
  273. void CombineSpawns(float radius, Spawn* spawn);
  274. void AddCombineSpawn(Spawn* spawn);
  275. void RemoveCombineSpawn(Spawn* spawn);
  276. void SaveCombineSpawns(const char* name = 0);
  277. Spawn* GetCombineSpawn();
  278. bool ShouldTarget();
  279. void TargetSpawn(Spawn* spawn);
  280. void ReloadQuests();
  281. int32 GetCurrentQuestID(){ return current_quest_id; }
  282. void SetLuaDebugClient(bool val);
  283. void SetMerchantTransaction(Spawn* spawn);
  284. Spawn* GetMerchantTransaction();
  285. void SetMailTransaction(Spawn* spawn);
  286. Spawn* GetMailTransaction();
  287. void PlaySound(const char* name);
  288. void SendBuyMerchantList(bool sell = false);
  289. void SendSellMerchantList(bool sell = false);
  290. void SendBuyBackList(bool sell = false);
  291. void SendRepairList();
  292. void ShowLottoWindow();
  293. void PlayLotto(int32 price, int32 ticket_item_id);
  294. void SendGuildCreateWindow();
  295. float CalculateBuyMultiplier(int32 merchant_id);
  296. float CalculateSellMultiplier(int32 merchant_id);
  297. void BuyItem(int32 item_id, int16 quantity);
  298. void SellItem(int32 item_id, int16 quantity, int32 unique_id = 0);
  299. void BuyBack(int32 item_id, int16 quantity);
  300. void RepairItem(int32 item_id);
  301. void RepairAllItems();
  302. void AddBuyBack(int32 unique_id, int32 item_id, int16 quantity, int32 price, bool save_needed = true);
  303. deque<BuyBackItem*>* GetBuyBacks();
  304. vector<Item*>* GetRepairableItems();
  305. vector<Item*>* GetItemsByEffectType(ItemEffectType type, ItemEffectType secondary_effect = NO_EFFECT_TYPE);
  306. void SendMailList();
  307. void DisplayMailMessage(int32 mail_id);
  308. void HandleSentMail(EQApplicationPacket* app);
  309. void DeleteMail(int32 mail_id, bool from_database = false);
  310. bool AddMailItem(Item* item);
  311. bool AddMailCoin(int32 copper, int32 silver = 0, int32 gold = 0, int32 plat = 0);
  312. bool RemoveMailCoin(int32 copper, int32 silver = 0, int32 gold = 0, int32 plat = 0);
  313. void TakeMailAttachments(int32 mail_id);
  314. void ResetSendMail(bool cancel = true, bool needslock = true);
  315. bool GateAllowed();
  316. bool BindAllowed();
  317. bool Bind();
  318. bool Gate(bool is_spell = false);
  319. void SendChatRelationship(int8 type, const char* name);
  320. void SendFriendList();
  321. void SendIgnoreList();
  322. void SendNewAdventureSpells();
  323. void SendNewTradeskillSpells();
  324. string GetCoinMessage(int32 total_coins);
  325. void SetItemSearch(vector<Item*>* items);
  326. vector<Item*>* GetSearchItems();
  327. void SearchStore(int32 page);
  328. void SetPlayer(Player* new_player);
  329. void AddPendingQuestAcceptReward(Quest* quest);
  330. void AddPendingQuestReward(Quest* quest, bool update=true, bool is_temporary = false, std::string description = std::string(""));
  331. bool HasQuestRewardQueued(int32 quest_id, bool is_temporary, bool is_collection);
  332. void QueueQuestReward(int32 quest_id, bool is_temporary, bool is_collection, bool has_displayed, int64 tmp_coin, int32 tmp_status, std::string description, bool db_saved=false, int32 index=0);
  333. void RemoveQueuedQuestReward();
  334. void AddPendingQuestUpdate(int32 quest_id, int32 step_id, int32 progress = 0xFFFFFFFF);
  335. void ProcessQuestUpdates();
  336. void AddWaypoint(const char* waypoint_name, int8 waypoint_category, int32 spawn_id);
  337. void BeginWaypoint(const char* waypoint_name, float x, float y, float z);
  338. void InspectPlayer(Player* player_to_inspect);
  339. void SetPendingGuildInvite(Guild* guild, Player* invited_by = 0);
  340. PendingGuildInvite* GetPendingGuildInvite() {return &pending_guild_invite;}
  341. void ShowClaimWindow();
  342. void ShowGuildSearchWindow();
  343. void CheckQuestQueue();
  344. void ShowDressingRoom(Item *item, sint32 crc);
  345. void SendCollectionList();
  346. bool SendCollectionsForItem(Item *item);
  347. void HandleCollectionAddItem(int32 collection_id, Item *item);
  348. void DisplayCollectionComplete(Collection *collection);
  349. void HandInCollections();
  350. void AcceptCollectionRewards(Collection *collection, int32 selectable_item_id = 0);
  351. void SendRecipeList();
  352. void PopulateRecipeData(Recipe* recipe, PacketStruct* packet, int i=0);
  353. int32 GetRecipeCRC(Recipe* recipe);
  354. void SendRecipeDetails(vector<int32>* recipes);
  355. void SendTitleUpdate();
  356. void SendUpdateTitles(sint32 prefix, sint32 suffix);
  357. void SendLanguagesUpdate(int32 id, bool setlang = 1);
  358. void SendAchievementsList();
  359. void SendAchievementUpdate(bool first_login = false);
  360. ///<summary>Send the pet options window to the client</summary>
  361. ///<param name="type">Type of pet, 1 = combat 0 = non combat</param>
  362. void SendPetOptionsWindow(const char* pet_name, int8 type = 1);
  363. void SendBiography();
  364. bool IsCrafting();
  365. void SetRecipeListSent(bool val) {m_recipeListSent = val; }
  366. bool GetRecipeListSent() { return m_recipeListSent; }
  367. void ShowRecipeBook();
  368. PendingResurrection* GetCurrentRez();
  369. void SendResurrectionWindow();
  370. void AcceptResurrection();
  371. Mutex m_resurrect;
  372. Mutex* GetResurrectMutex();
  373. void SetPendingLastName(string last_name);
  374. void RemovePendingLastName();
  375. string* GetPendingLastName();
  376. void SendLastNameConfirmation();
  377. void SetInitialSpawnsSent(bool val) { initial_spawns_sent = val; }
  378. bool GetInitialSpawnsSent() { return initial_spawns_sent; }
  379. void SendQuestJournalUpdate(Quest* quest, bool updated=true);
  380. void AddQuestTimer(int32 quest_id);
  381. void RemoveQuestTimer(int32 quest_id);
  382. void SetPendingFlightPath(int32 val) { pending_flight_path = val; }
  383. int32 GetPendingFlightPath() { return pending_flight_path; }
  384. void EndAutoMount();
  385. bool GetOnAutoMount() { return on_auto_mount; }
  386. bool IsCurrentTransmuteID(int32 trans_id);
  387. void SetTransmuteID(int32 trans_id);
  388. int32 GetTransmuteID();
  389. enum ServerSpawnPlacementMode { DEFAULT, OPEN_HEADING, CLOSE_HEADING };
  390. void SetSpawnPlacementMode(ServerSpawnPlacementMode mode) { spawnPlacementMode = mode; }
  391. ServerSpawnPlacementMode GetSpawnPlacementMode() { return spawnPlacementMode; }
  392. bool HandleNewLogin(int32 account_id, int32 access_code);
  393. void SendSpawnChanges(set<Spawn*>& spawns);
  394. void MakeSpawnChangePacket(map<int32, SpawnData> info_changes, map<int32, SpawnData> pos_changes, map<int32, SpawnData> vis_changes, int32 info_size, int32 pos_size, int32 vis_size);
  395. bool IsZonedIn() { return connected_to_zone; }
  396. void SendHailCommand(Spawn* target);
  397. void SendDefaultCommand(Spawn* spawn, const char* command, float distance);
  398. void SetTempPlacementSpawn(Spawn* tmp);
  399. Spawn* GetTempPlacementSpawn() { return tempPlacementSpawn; }
  400. void SetPlacementUniqueItemID(int32 id) { placement_unique_item_id = id; }
  401. int32 GetPlacementUniqueItemID() { return placement_unique_item_id; }
  402. void SetHasOwnerOrEditAccess(bool val) { hasOwnerOrEditAccess = val; }
  403. bool HasOwnerOrEditAccess() { return hasOwnerOrEditAccess; }
  404. bool HandleHouseEntityCommands(Spawn* spawn, int32 spawnid, string command);
  405. // find an appropriate spawn to use for the house object, save spawn location/entry data to DB
  406. bool PopulateHouseSpawn(PacketStruct* place_object);
  407. // finalize the spawn-in of the object in world, remove the item from player inventory, set the spawned in object item id (for future pickup)
  408. bool PopulateHouseSpawnFinalize();
  409. void SendMoveObjectMode(Spawn* spawn, uint8 placementMode, float unknown2_3=0.0f);
  410. void SendFlightAutoMount(int32 path_id, int16 mount_id = 0, int8 mount_red_color = 0xFF, int8 mount_green_color = 0xFF, int8 mount_blue_color=0xFF);
  411. void SendShowBook(Spawn* sender, string title, int8 language, int8 num_pages, ...);
  412. void SendShowBook(Spawn* sender, string title, int8 language, vector<Item::BookPage*> pages);
  413. void SetTemporaryTransportID(int32 id) { temporary_transport_id = id; }
  414. int32 GetTemporaryTransportID() { return temporary_transport_id; }
  415. void SetRejoinGroupID(int32 id) { rejoin_group_id = id; }
  416. void TempRemoveGroup();
  417. void ReplaceGroupClient(Client* new_client);
  418. void SendWaypoints();
  419. void AddWaypoint(string name, int8 type);
  420. void RemoveWaypoint(string name) {
  421. if (waypoints.count(name) > 0){
  422. waypoints.erase(name);
  423. }
  424. }
  425. void SelectWaypoint(int32 id);
  426. void ClearWaypoint();
  427. bool ShowPathToTarget(float x, float y, float z, float y_offset);
  428. bool ShowPathToTarget(Spawn* spawn);
  429. void SetRegionDebug(bool val) { regionDebugMessaging = val; }
  430. static void CreateMail(int32 charID, std::string fromName, std::string subjectName, std::string mailBody,
  431. int8 mailType, int32 copper, int32 silver, int32 gold, int32 platinum, int32 item_id, int16 stack_size, int32 time_sent, int32 expire_time);
  432. void CreateAndUpdateMail(std::string fromName, std::string subjectName, std::string mailBody,
  433. int8 mailType, int32 copper, int32 silver, int32 gold, int32 platinum, int32 item_id, int16 stack_size, int32 time_sent, int32 expire_time);
  434. void SendEquipOrInvUpdateBySlot(int8 slot);
  435. void SetReloadingZone(bool val) { client_reloading_zone = val; }
  436. bool IsReloadingZone() { return client_reloading_zone; }
  437. void QueueStateCommand(int32 spawn_player_id, int32 state);
  438. void ProcessStateCommands();
  439. void PurgeItem(Item* item);
  440. void ConsumeFoodDrink(Item* item, int32 slot);
  441. void AwardCoins(int64 total_coins, std::string reason = string(""));
  442. void TriggerSpellSave();
  443. void ClearSentItemDetails() {
  444. MItemDetails.writelock(__FUNCTION__, __LINE__);
  445. sent_item_details.clear();
  446. MItemDetails.releasewritelock(__FUNCTION__, __LINE__);
  447. }
  448. bool IsPlayerLoadingComplete() { return player_loading_complete; }
  449. int32 GetRejoinGroupID() { return rejoin_group_id; }
  450. void ClearSentSpellList() {
  451. MSpellDetails.writelock(__FUNCTION__, __LINE__);
  452. sent_spell_details.clear();
  453. MSpellDetails.releasewritelock(__FUNCTION__, __LINE__);
  454. }
  455. void UpdateSentSpellList();
  456. bool CountSentSpell(int32 id, int32 tier) {
  457. bool res = false;
  458. MSpellDetails.readlock(__FUNCTION__, __LINE__);
  459. std::map<int32, int32>::iterator itr = sent_spell_details.find(id);
  460. if(itr != sent_spell_details.end() && itr->second == tier)
  461. res = true;
  462. MSpellDetails.releasereadlock(__FUNCTION__, __LINE__);
  463. return res;
  464. }
  465. void SetSentSpell(int32 id, int32 tier) {
  466. MSpellDetails.writelock(__FUNCTION__, __LINE__);
  467. sent_spell_details[id] = tier;
  468. MSpellDetails.releasewritelock(__FUNCTION__, __LINE__);
  469. }
  470. void DisableSave() { disable_save = true; }
  471. bool IsSaveDisabled() { return disable_save; }
  472. void ResetZoningCoords() {
  473. zoning_x = 0;
  474. zoning_y = 0;
  475. zoning_z = 0;
  476. zoning_h = 0;
  477. }
  478. void SetZoningCoords(float x, float y, float z, float h) {
  479. zoning_x = x;
  480. zoning_y = y;
  481. zoning_z = z;
  482. zoning_h = h;
  483. }
  484. bool UseItem(Item* item, Spawn* target = nullptr);
  485. void SendPlayFlavor(Spawn* spawn, int8 language, VoiceOverStruct* non_garble, VoiceOverStruct* garble, bool success = false, bool garble_success = false);
  486. void SaveQuestRewardData(bool force_refresh = false);
  487. void UpdateCharacterRewardData(QuestRewardData* data);
  488. void SetQuestUpdateState(bool val) { quest_updates = val; }
  489. bool SetPlayerPOVGhost(Spawn* spawn);
  490. int32 GetPlayerPOVGhostSpawnID() { return pov_ghost_spawn_id; }
  491. void HandleDialogSelectMsg(int32 conversation_id, int32 response_index);
  492. bool SetPetName(const char* name);
  493. bool CheckConsumptionAllowed(int16 slot, bool send_message = true);
  494. void StartLinkdeadTimer();
  495. bool IsLinkdeadTimerEnabled();
  496. bool AddRecipeBookToPlayer(int32 recipe_id, Item* item = nullptr);
  497. bool RemoveRecipeFromPlayer(int32 recipe_id);
  498. void SaveSpells();
  499. void GiveQuestReward(Quest* quest, bool has_displayed = false);
  500. void SendReplaceWidget(int32 widget_id, bool delete_widget, float x=0.0f, float y=0.0f, float z=0.0f, int32 grid_id=0);
  501. void ProcessZoneIgnoreWidgets();
  502. void SendHearCast(Spawn* caster, Spawn* target, int32 spell_visual, int16 cast_time);
  503. int32 GetSpellVisualOverride(int32 spell_visual);
  504. sint16 GetClientItemPacketOffset() { sint16 offset = -1; if(GetVersion() <= 373) { offset = -2; } return offset; }
  505. int32 GetZoningID() { return zoning_id; }
  506. int32 GetZoningInstanceID() { return zoning_instance_id; }
  507. void SetZoningDetails(ZoneChangeDetails* details) { zoning_details = ZoneChangeDetails(details); }
  508. void HandleGroupAcceptResponse(int8 result);
  509. void SetGroupOptionsReference(GroupOptions* options);
  510. void SendReceiveOffer(Client* client_target, int8 type, std::string name, int8 unknown2);
  511. private:
  512. void AddRecipeToPlayerPack(Recipe* recipe, PacketStruct* packet, int16* i);
  513. void SavePlayerImages();
  514. void SkillChanged(Skill* skill, int16 previous_value, int16 new_value);
  515. void SetStepComplete(int32 quest_id, int32 step);
  516. void AddStepProgress(int32 quest_id, int32 step, int32 progress);
  517. void SendNewSpells(int8 class_id);
  518. void SendNewTSSpells(int8 class_id);
  519. void AddSendNewSpells(vector<Spell*>* spells);
  520. map<int32, map<int32, int32> > quest_pending_updates;
  521. vector<QueuedQuest*> quest_queue;
  522. vector<QuestRewardData*> quest_pending_reward;
  523. volatile bool quest_updates;
  524. Mutex MQuestPendingUpdates;
  525. Mutex MQuestQueue;
  526. Mutex MDeletePlayer;
  527. vector<Item*>* search_items;
  528. int32 waypoint_id = 0;
  529. map<string, WaypointInfo> waypoints;
  530. Spawn* transport_spawn;
  531. Mutex MBuyBack;
  532. deque<BuyBackItem*> buy_back_items;
  533. Spawn* merchant_transaction;
  534. Spawn* mail_transaction;
  535. mutable std::shared_mutex MPendingQuestAccept;
  536. vector<int32> pending_quest_accept;
  537. bool lua_debug;
  538. bool should_target;
  539. Spawn* combine_spawn;
  540. int8 num_active_failures;
  541. int32 next_conversation_id;
  542. map<int32, int32> conversation_spawns;
  543. map<int32, Item*> conversation_items;
  544. mutable std::shared_mutex MConversation;
  545. map<int32, map<int8, string> > conversation_map;
  546. int32 current_quest_id;
  547. Spawn* banker;
  548. map<int32, int32> sent_spell_details;
  549. map<int32, bool> sent_item_details;
  550. Player* player;
  551. int16 version;
  552. int8 timestamp_flag;
  553. int32 ip;
  554. int16 port;
  555. int32 account_id;
  556. int32 character_id;
  557. sint16 admin_status; // -2 Banned, -1 Suspended, 0 User, etc.
  558. char account_name[64];
  559. char zone_name[64];
  560. int32 zoneID;
  561. int32 instanceID;
  562. Timer* autobootup_timeout;
  563. int32 pwaitingforbootup;
  564. int32 last_update_time;
  565. int32 last_saved_timestamp;
  566. Timer* CLE_keepalive_timer;
  567. Timer* connect;
  568. Timer* camp_timer;
  569. Timer* linkdead_timer;
  570. bool connected;
  571. std::atomic<bool> ready_for_spawns;
  572. std::atomic<bool> ready_for_updates;
  573. bool seencharsel;
  574. bool connected_to_zone;
  575. std::atomic<bool> client_zoning;
  576. std::atomic<bool> client_zoning_details_set;
  577. ZoneChangeDetails zoning_details;
  578. int32 zoning_id;
  579. int32 zoning_instance_id;
  580. ZoneServer* zoning_destination;
  581. float zoning_x;
  582. float zoning_y;
  583. float zoning_z;
  584. float zoning_h;
  585. bool firstlogin;
  586. enum NewLoginState { LOGIN_NONE, LOGIN_DELAYED, LOGIN_ALLOWED, LOGIN_INITIAL_LOAD, LOGIN_SEND };
  587. NewLoginState new_client_login; // 1 = delayed state, 2 = let client in
  588. Timer underworld_cooldown_timer;
  589. Timer pos_update;
  590. Timer quest_pos_timer;
  591. Timer lua_debug_timer;
  592. Timer temp_placement_timer;
  593. Timer spawn_removal_timer;
  594. std::atomic<bool> player_pos_changed;
  595. std::atomic<int8> player_pos_change_count;
  596. int32 player_pos_timer;
  597. bool enabled_player_pos_timer;
  598. bool HandlePacket(EQApplicationPacket *app);
  599. EQStream* eqs;
  600. bool quickbar_changed;
  601. ZoneServer* current_zone;
  602. int32 name_crc;
  603. MailWindow mail_window;
  604. std::mutex MMailWindowMutex;
  605. PendingGuildInvite pending_guild_invite;
  606. PendingResurrection current_rez;
  607. string* pending_last_name;
  608. IncomingPaperdollImage incoming_paperdoll;
  609. int32 transmuteID;
  610. bool GetHouseZoneServer(ZoneChangeDetails* zone_details, int32 spawn_id, int64 house_id);
  611. std::atomic<bool> m_recipeListSent;
  612. bool initial_spawns_sent;
  613. bool should_load_spells;
  614. // int32 = quest id
  615. vector<int32> quest_timers;
  616. Mutex MQuestTimers;
  617. int32 pending_flight_path;
  618. ServerSpawnPlacementMode spawnPlacementMode;
  619. bool on_auto_mount;
  620. bool EntityCommandPrecheck(Spawn* spawn, const char* command);
  621. bool delayedLogin;
  622. int32 delayedAccountID;
  623. int32 delayedAccessKey;
  624. Timer delayTimer;
  625. Spawn* tempPlacementSpawn;
  626. int32 placement_unique_item_id;
  627. bool hasOwnerOrEditAccess;
  628. bool hasSentTempPlacementSpawn;
  629. int32 temporary_transport_id;
  630. int32 rejoin_group_id;
  631. int32 lastRegionRemapTime;
  632. bool regionDebugMessaging;
  633. bool client_reloading_zone;
  634. map<int32, int32> queued_state_commands;
  635. Mutex MQueueStateCmds;
  636. Timer save_spell_state_timer; // will be the 're-trigger' to delay
  637. int32 save_spell_state_time_bucket; // bucket as we collect over time when timer is reset by new spell effects being casted
  638. std::mutex MSaveSpellStateMutex;
  639. bool player_loading_complete;
  640. Mutex MItemDetails;
  641. Mutex MSpellDetails;
  642. bool disable_save;
  643. vector< string > devices;
  644. std::atomic<int32> pov_ghost_spawn_id;
  645. Timer delay_msg_timer;
  646. uchar* recipe_orig_packet;
  647. uchar* recipe_xor_packet;
  648. int recipe_packet_count;
  649. int recipe_orig_packet_size;
  650. };
  651. class ClientList {
  652. public:
  653. ClientList();
  654. ~ClientList();
  655. bool ContainsStream(EQStream* eqs);
  656. void Add(Client* client);
  657. Client* Get(int32 ip, int16 port);
  658. Client* FindByAccountID(int32 account_id);
  659. Client* FindByName(char* charname);
  660. void Remove(Client* client, bool delete_data = false);
  661. void RemoveConnection(EQStream* eqs);
  662. void Process();
  663. int32 Count();
  664. void ReloadQuests();
  665. void CheckPlayersInvisStatus(Client* owner);
  666. void RemovePlayerFromInvisHistory(int32 spawnID);
  667. private:
  668. Mutex MClients;
  669. list<Client*> client_list;
  670. };
  671. #endif