9
3

LWorld.h 7.8 KB

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