LWorld.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. */
  6. #ifndef LWORLD_H
  7. #define LWORLD_H
  8. #include "../common/Mutex.h"
  9. #define ERROR_BADPASSWORD "Bad password"
  10. #define INVALID_ACCOUNT "Invalid Server Account."
  11. #define ERROR_BADVERSION "Incorrect version"
  12. #define ERROR_UNNAMED "Unnamed servers not allowed to connect to full login servers"
  13. #define ERROR_NOTMASTER "Not a master server"
  14. #define ERROR_NOTMESH "Not a mesh server"
  15. #define ERROR_GHOST "Ghost kick"
  16. #define ERROR_UnknownServerType "Unknown Server Type"
  17. #define ERROR_BADNAME_SERVER "Bad server name, name may not contain the word \"Server\" (case sensitive)"
  18. #define ERROR_BADNAME "Bad server name. Unknown reason."
  19. #define WORLD_NAME_SUFFIX " Server"
  20. #include <boost/algorithm/string.hpp>
  21. #include <boost/property_tree/ptree.hpp>
  22. #include <boost/property_tree/json_parser.hpp>
  23. #include <boost/beast/http.hpp>
  24. #include <sstream>
  25. #include <string>
  26. #include <iostream>
  27. namespace beast = boost::beast; // from <boost/beast.hpp>
  28. namespace http = beast::http; // from <boost/beast/http.hpp>
  29. #include "../common/linked_list.h"
  30. #include "../WorldServer/MutexList.h"
  31. #include "../WorldServer/MutexMap.h"
  32. #include "../common/timer.h"
  33. #include "../common/types.h"
  34. #include "../common/queue.h"
  35. #include "../common/servertalk.h"
  36. #include "../common/TCPConnection.h"
  37. #include "client.h"
  38. #define MAX_UPDATE_COUNT 20
  39. #define MAX_LOGIN_APPEARANCE_COUNT 100
  40. #ifdef WIN32
  41. void ServerUpdateLoop(void* tmp);
  42. #else
  43. void* ServerUpdateLoop(void* tmp);
  44. #endif
  45. enum ConType { UnknownW, World, Chat, Login };
  46. class LWorld
  47. {
  48. public:
  49. LWorld(TCPConnection* in_con, bool OutgoingLoginUplink = false, int32 iIP = 0, int16 iPort = 0, bool iNeverKick = false);
  50. LWorld(int32 in_accountid, char* in_accountname, char* in_worldname, int32 in_admin_id);
  51. LWorld(TCPConnection* in_RemoteLink, int32 in_ip, int32 in_RemoteID, int32 in_accountid, char* in_accountname, char* in_worldname, char* in_address, sint32 in_status, int32 in_adminid, bool in_showdown, int8 in_authlevel, bool in_placeholder, int32 iLinkWorldID);
  52. ~LWorld();
  53. static bool CheckServerName(const char* name);
  54. bool Process();
  55. void SendPacket(ServerPacket* pack);
  56. void Message(const char* to, const char* message, ...);
  57. bool SetupWorld(char* in_worldname, char* in_worldaddress, char* in_account, char* in_password, char* in_version);
  58. void UpdateStatus(sint32 in_status, sint32 in_players, sint32 in_zones, int8 in_level) {
  59. // we don't want the server list to update unless something has changed
  60. if(status != in_status || num_players != in_players || num_zones != in_zones || world_max_level != in_level)
  61. {
  62. status = in_status;
  63. num_players = in_players;
  64. num_zones = in_zones;
  65. world_max_level = in_level;
  66. UpdateWorldList();
  67. }
  68. }
  69. void UpdateWorldList(LWorld* to = 0);
  70. void SetRemoteInfo(int32 in_ip, int32 in_accountid, char* in_account, char* in_name, char* in_address, int32 in_status, int32 in_adminid, sint32 in_players, sint32 in_zones);
  71. inline bool IsPlaceholder() { return pPlaceholder; }
  72. inline int32 GetAccountID() { return accountid; }
  73. inline char* GetAccount() { return account; }
  74. inline char* GetAddress() { return address; }
  75. inline int16 GetClientPort() { return pClientPort; }
  76. inline bool IsAddressIP() { return isaddressip; }
  77. inline char* GetName() { return worldname; }
  78. inline sint32 GetStatus() { return status; }
  79. bool IsLocked() { return status==-2; }
  80. inline int32 GetIP() { return ip; }
  81. inline int16 GetPort() { return port; }
  82. inline int32 GetID() { return ID; }
  83. inline int32 GetAdmin() { return admin_id; }
  84. inline bool ShowDown() { return pshowdown; }
  85. inline bool ShowDownActive(){ return show_down_active; }
  86. void ShowDownActive(bool show){ show_down_active = show; }
  87. void ShowDown(bool show){ pshowdown = show; }
  88. inline bool Connected() { return pConnected; }
  89. int8 GetWorldStatus();
  90. void ChangeToPlaceholder();
  91. void Kick(const char* message = ERROR_GHOST, bool iSetKickedFlag = true);
  92. inline bool IsKicked() { return kicked; }
  93. inline bool IsNeverKick() { return pNeverKick; }
  94. inline ConType GetType() { return ptype; }
  95. inline bool IsOutgoingUplink() { return OutgoingUplink; }
  96. inline TCPConnection* GetLink() { return Link; }
  97. inline int32 GetRemoteID() { return RemoteID; }
  98. inline int32 GetLinkWorldID() { return LinkWorldID; }
  99. inline sint32 GetZoneNum() { return num_zones; }
  100. inline sint32 GetPlayerNum() { return num_players; }
  101. void SetID(int32 new_id) { ID = new_id; }
  102. void SendDeleteCharacter( int32 char_id, int32 account_id );
  103. bool IsDevelServer(){ return devel_server; }
  104. inline int8 GetMaxWorldLevel() { return world_max_level; }
  105. bool IsInit;
  106. protected:
  107. friend class LWorldList;
  108. TCPConnection* Link;
  109. Timer* pReconnectTimer;
  110. Timer* pStatsTimer;
  111. private:
  112. int32 ID;
  113. int32 ip;
  114. char IPAddr[64];
  115. int16 port;
  116. bool kicked;
  117. bool pNeverKick;
  118. bool pPlaceholder;
  119. bool devel_server;
  120. int32 accountid;
  121. char account[30];
  122. char address[250];
  123. bool isAuthenticated;
  124. int16 pClientPort;
  125. bool isaddressip;
  126. char worldname[200];
  127. sint32 status;
  128. int32 admin_id;
  129. bool pshowdown;
  130. bool show_down_active;
  131. ConType ptype;
  132. bool OutgoingUplink;
  133. bool pConnected;
  134. sint32 num_players;
  135. sint32 num_zones;
  136. int32 RemoteID;
  137. int32 LinkWorldID;
  138. int8 world_max_level;
  139. };
  140. class LWorldList
  141. {
  142. public:
  143. LWorldList();
  144. ~LWorldList();
  145. LWorld* FindByID(int32 WorldID);
  146. LWorld* FindByIP(int32 ip);
  147. LWorld* FindByAddress(char* address);
  148. LWorld* FindByLink(TCPConnection* in_link, int32 in_id);
  149. LWorld* FindByAccount(int32 in_accountid, ConType in_type = World);
  150. void Add(LWorld* worldserver);
  151. void AddInitiateWorld ( LWorld* world );
  152. void Process();
  153. void ReceiveData();
  154. void SendPacket(ServerPacket* pack, LWorld* butnotme = 0);
  155. void SendPacketLocal(ServerPacket* pack, LWorld* butnotme = 0);
  156. void SendPacketLogin(ServerPacket* pack, LWorld* butnotme = 0);
  157. void SendWorldChanged(int32 server_id, bool sendtoallclients=false, Client* sendto = 0);
  158. vector<PacketStruct*>* GetServerListUpdate(int16 version);
  159. EQ2Packet* MakeServerListPacket(int8 lsadmin, int16 version);
  160. void UpdateWorldList(LWorld* to = 0);
  161. void UpdateWorldStats();
  162. void KickGhost(ConType in_type, int32 in_accountid = 0, LWorld* ButNotMe = 0);
  163. void KickGhostIP(int32 ip, LWorld* NotMe = 0, int16 iClientPort = 0);
  164. void RemoveByLink(TCPConnection* in_link, int32 in_id = 0, LWorld* ButNotMe = 0);
  165. void RemoveByID(int32 in_id);
  166. void SendWorldStatus(LWorld* chat, char* adminname);
  167. void ConnectUplink();
  168. bool Init();
  169. void InitWorlds();
  170. void Shutdown();
  171. bool WriteXML();
  172. int32 GetCount(ConType type);
  173. void PopulateWorldList(http::response<http::string_body>& res);
  174. void ListWorldsToConsole();
  175. //devn00b temp
  176. void AddServerEquipmentUpdates(LWorld* world, map<int32, LoginEquipmentUpdate> updates);
  177. void ProcessLSEquipUpdates();
  178. void RequestServerEquipUpdates(LWorld* world);
  179. void SetUpdateServerList ( bool var ) { UpdateServerList = var; }
  180. bool ContinueServerUpdates(){ return server_update_thread; }
  181. void ResetServerUpdates(){server_update_thread = true;}
  182. void ProcessServerUpdates();
  183. void RequestServerUpdates(LWorld* world);
  184. void AddServerZoneUpdates(LWorld* world, map<int32, LoginZoneUpdate> updates);
  185. protected:
  186. friend class LWorld;
  187. int32 GetNextID() { return NextID++; }
  188. private:
  189. Mutex MWorldMap;
  190. map<int32, map<int32, bool> > zone_updates_already_used; //used to determine if someone is trying to DOS us
  191. MutexMap<int32, int32> zone_update_timeouts;
  192. MutexMap<int32, int32> awaiting_zone_update;
  193. MutexMap<LWorld*, int32> last_updated;
  194. MutexMap<int32, map<int32, LoginZoneUpdate> > server_zone_updates;
  195. bool server_update_thread;
  196. int32 NextID;
  197. LinkedList<LWorld*> list;
  198. map<int32,LWorld*> worldmap;
  199. TCPServer* tcplistener;
  200. TCPConnection* OutLink;
  201. //devn00b temp
  202. // JohnAdams: login appearances, copied from above
  203. map<int32, map<int32, bool> > equip_updates_already_used;
  204. MutexMap<int32, int32> equip_update_timeouts;
  205. MutexMap<int32, int32> awaiting_equip_update;
  206. MutexMap<LWorld*, int32> last_equip_updated;
  207. MutexMap<int32, map<int32, LoginEquipmentUpdate> > server_equip_updates;
  208. //
  209. ///
  210. // holds the world server list so we don't have to create it for every character
  211. // logging in
  212. map<int32,EQ2Packet*> ServerListData;
  213. bool UpdateServerList;
  214. };
  215. #endif