client.h 27 KB

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