9
3

LWorld.h 7.9 KB

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