net.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 "../common/linked_list.h"
  33. #include "../common/types.h"
  34. ThreadReturnType EQ2ConsoleListener(void *tmp);
  35. void CatchSignal(int sig_num);
  36. void UpdateWindowTitle(char* iNewTitle);
  37. #define PORT 9000
  38. #define LOGIN_PORT 9100
  39. class NetConnection
  40. {
  41. public:
  42. NetConnection() {
  43. world_locked = false;
  44. for (int i=0; i<4; i++) {
  45. memset(loginaddress[i], 0, sizeof(loginaddress[i]));
  46. loginport[i] = LOGIN_PORT;
  47. }
  48. listening_socket = 0;
  49. memset(worldname, 0, sizeof(worldname));
  50. memset(worldaccount, 0, sizeof(worldaccount));
  51. memset(worldpassword, 0, sizeof(worldpassword));
  52. memset(worldaddress, 0, sizeof(worldaddress));
  53. memset(internalworldaddress, 0, sizeof(internalworldaddress));
  54. worldport = PORT;
  55. DEFAULTSTATUS=0;
  56. LoginServerInfo = 0;//ReadLoginINI();
  57. UpdateStats = false;
  58. web_worldport = 0;
  59. }
  60. ~NetConnection() { }
  61. bool ReadLoginINI();
  62. void WelcomeHeader();
  63. bool LoginServerInfo;
  64. bool UpdateStats;
  65. char* GetLoginInfo(int16* oPort);
  66. inline char* GetLoginAddress(int8 i) { return loginaddress[i]; }
  67. inline int16 GetLoginPort(int8 i) { return loginport[i]; }
  68. inline char* GetWorldName() { return worldname; }
  69. inline char* GetWorldAccount() { return worldaccount; }
  70. inline char* GetWorldPassword() { return worldpassword; }
  71. inline char* GetWorldAddress() { return worldaddress; }
  72. inline char* GetInternalWorldAddress() { return internalworldaddress; }
  73. inline int16 GetWorldPort() { return worldport; }
  74. inline int8 GetDefaultStatus() { return DEFAULTSTATUS; }
  75. std::string GetWebWorldAddress() { return web_worldaddress; }
  76. inline int16 GetWebWorldPort() { return web_worldport; }
  77. std::string GetWebCertFile() { return web_certfile; }
  78. std::string GetWebKeyFile() { return web_keyfile; }
  79. std::string GetWebKeyPassword() { return web_keypassword; }
  80. std::string GetWebHardcodeUser() { return web_hardcodeuser; }
  81. std::string GetWebHardcodePassword() { return web_hardcodepassword; }
  82. bool world_locked;
  83. private:
  84. int listening_socket;
  85. char loginaddress[4][255];
  86. int16 loginport[4];
  87. char worldname[201];
  88. char worldaccount[31];
  89. char worldpassword[31];
  90. char worldaddress[255];
  91. char internalworldaddress[21];
  92. int16 worldport;
  93. int8 DEFAULTSTATUS;
  94. std::string web_worldaddress;
  95. std::string web_certfile;
  96. std::string web_keyfile;
  97. std::string web_keypassword;
  98. std::string web_hardcodeuser;
  99. std::string web_hardcodepassword;
  100. int16 web_worldport;
  101. };
  102. class ZoneAuthRequest
  103. {
  104. public:
  105. ZoneAuthRequest(int32 account_id, char* name, int32 access_key);
  106. ~ZoneAuthRequest( );
  107. int32 GetAccountID() { return accountid; }
  108. const char* GetCharacterName() { return character_name.c_str(); }
  109. int32 GetAccessKey() { return accesskey; }
  110. int32 GetTimeStamp() { return timestamp; }
  111. void setFirstLogin(bool value) { firstlogin = value; }
  112. bool isFirstLogin() { return firstlogin; }
  113. private:
  114. int32 accountid;
  115. string character_name;
  116. int32 accesskey;
  117. int32 timestamp;
  118. bool firstlogin;
  119. };
  120. class ZoneAuth
  121. {
  122. public:
  123. void AddAuth(ZoneAuthRequest* zar);
  124. ZoneAuthRequest* GetAuth(int32 account_id, int32 access_key);
  125. void PurgeInactiveAuth();
  126. void RemoveAuth(ZoneAuthRequest* zar);
  127. private:
  128. LinkedList<ZoneAuthRequest*> list;
  129. };
  130. #endif