net.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 __EQ2_NET__
  17. #define __EQ2_NET__
  18. #ifndef WIN32
  19. #include <sys/socket.h>
  20. #include <netinet/in.h>
  21. #include <arpa/inet.h>
  22. #include <netdb.h>
  23. #include <unistd.h>
  24. #include <errno.h>
  25. #include <fcntl.h>
  26. #else
  27. #include <cerrno>
  28. #include <fcntl.h>
  29. #include <WinSock2.h>
  30. #include <windows.h>
  31. #endif
  32. #include <atomic>
  33. #include <cstring>
  34. #include "../common/linked_list.h"
  35. #include "../common/types.h"
  36. ThreadReturnType EQ2ConsoleListener(void *tmp);
  37. void CatchSignal(int sig_num);
  38. void UpdateWindowTitle(char* iNewTitle);
  39. #define PORT 9000
  40. #define LOGIN_PORT 9100
  41. class NetConnection
  42. {
  43. public:
  44. NetConnection() {
  45. world_locked = false;
  46. for (int i=0; i<4; i++) {
  47. memset(loginaddress[i], 0, sizeof(loginaddress[i]));
  48. loginport[i] = LOGIN_PORT;
  49. }
  50. listening_socket = 0;
  51. memset(worldname, 0, sizeof(worldname));
  52. memset(worldaccount, 0, sizeof(worldaccount));
  53. memset(worldpassword, 0, sizeof(worldpassword));
  54. memset(worldaddress, 0, sizeof(worldaddress));
  55. memset(internalworldaddress, 0, sizeof(internalworldaddress));
  56. worldport = PORT;
  57. DEFAULTSTATUS=0;
  58. LoginServerInfo = 0;//ReadLoginINI();
  59. UpdateStats = false;
  60. web_worldport = 0;
  61. web_peerpriority = 0;
  62. }
  63. ~NetConnection() { }
  64. bool ReadLoginINI(int argc, char** argv);
  65. void WelcomeHeader();
  66. void SetPrimary(bool isprimary = true);
  67. bool LoginServerInfo;
  68. bool UpdateStats;
  69. char* GetLoginInfo(int16* oPort);
  70. inline char* GetLoginAddress(int8 i) { return loginaddress[i]; }
  71. inline int16 GetLoginPort(int8 i) { return loginport[i]; }
  72. inline char* GetWorldName() { return worldname; }
  73. inline char* GetWorldAccount() { return worldaccount; }
  74. inline char* GetWorldPassword() { return worldpassword; }
  75. inline char* GetWorldAddress() { return worldaddress; }
  76. inline char* GetInternalWorldAddress() { return internalworldaddress; }
  77. inline int16 GetWorldPort() { return worldport; }
  78. inline int8 GetDefaultStatus() { return DEFAULTSTATUS; }
  79. std::string GetWebWorldAddress() { return web_worldaddress; }
  80. inline int16 GetWebWorldPort() { return web_worldport; }
  81. std::string GetWebCertFile() { return web_certfile; }
  82. std::string GetWebKeyFile() { return web_keyfile; }
  83. std::string GetWebKeyPassword() { return web_keypassword; }
  84. std::string GetWebHardcodeUser() { return web_hardcodeuser; }
  85. std::string GetWebHardcodePassword() { return web_hardcodepassword; }
  86. std::string GetCmdUser() { return web_cmduser; }
  87. std::string GetCmdPassword() { return web_cmdpassword; }
  88. std::map<std::string, int16> GetWebPeers() { std::map<std::string, int16> copied_map(web_peers); return copied_map; }
  89. int16 GetPeerPriority() { return web_peerpriority; }
  90. bool world_locked;
  91. std::atomic<bool> is_primary;
  92. private:
  93. int listening_socket;
  94. char loginaddress[4][255];
  95. int16 loginport[4];
  96. char worldname[201];
  97. char worldaccount[31];
  98. char worldpassword[31];
  99. char worldaddress[255];
  100. char internalworldaddress[21];
  101. int16 worldport;
  102. int8 DEFAULTSTATUS;
  103. std::string web_worldaddress;
  104. std::string web_certfile;
  105. std::string web_keyfile;
  106. std::string web_keypassword;
  107. std::string web_hardcodeuser;
  108. std::string web_hardcodepassword;
  109. std::string web_cmduser;
  110. std::string web_cmdpassword;
  111. std::map<std::string, int16> web_peers;
  112. int16 web_worldport;
  113. int16 web_peerpriority;
  114. };
  115. class ZoneAuthRequest
  116. {
  117. public:
  118. ZoneAuthRequest(int32 account_id, char* name, int32 access_key);
  119. ~ZoneAuthRequest( );
  120. int32 GetAccountID() { return accountid; }
  121. const char* GetCharacterName() { return character_name.c_str(); }
  122. int32 GetAccessKey() { return accesskey; }
  123. int32 GetTimeStamp() { return timestamp; }
  124. void setFirstLogin(bool value) { firstlogin = value; }
  125. bool isFirstLogin() { return firstlogin; }
  126. private:
  127. int32 accountid;
  128. string character_name;
  129. int32 accesskey;
  130. int32 timestamp;
  131. bool firstlogin;
  132. };
  133. class ZoneAuth
  134. {
  135. public:
  136. void AddAuth(ZoneAuthRequest* zar);
  137. ZoneAuthRequest* GetAuth(int32 account_id, int32 access_key);
  138. void PurgeInactiveAuth();
  139. void RemoveAuth(ZoneAuthRequest* zar);
  140. private:
  141. LinkedList<ZoneAuthRequest*> list;
  142. };
  143. #endif