9
3

LWorld.h 7.2 KB

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