net.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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<3; 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. }
  59. ~NetConnection() { }
  60. bool ReadLoginINI();
  61. void WelcomeHeader();
  62. bool LoginServerInfo;
  63. bool UpdateStats;
  64. char* GetLoginInfo(int16* oPort);
  65. inline char* GetLoginAddress(int8 i) { return loginaddress[i]; }
  66. inline int16 GetLoginPort(int8 i) { return loginport[i]; }
  67. inline char* GetWorldName() { return worldname; }
  68. inline char* GetWorldAccount() { return worldaccount; }
  69. inline char* GetWorldPassword() { return worldpassword; }
  70. inline char* GetWorldAddress() { return worldaddress; }
  71. inline char* GetInternalWorldAddress() { return internalworldaddress; }
  72. inline int16 GetWorldPort() { return worldport; }
  73. inline int8 GetDefaultStatus() { return DEFAULTSTATUS; }
  74. bool world_locked;
  75. private:
  76. int listening_socket;
  77. char loginaddress[3][255];
  78. int16 loginport[3];
  79. char worldname[201];
  80. char worldaccount[31];
  81. char worldpassword[31];
  82. char worldaddress[255];
  83. char internalworldaddress[21];
  84. int16 worldport;
  85. int8 DEFAULTSTATUS;
  86. };
  87. class ZoneAuthRequest
  88. {
  89. public:
  90. ZoneAuthRequest(int32 account_id, char* name, int32 access_key);
  91. ~ZoneAuthRequest( );
  92. int32 GetAccountID() { return accountid; }
  93. const char* GetCharacterName() { return character_name.c_str(); }
  94. int32 GetAccessKey() { return accesskey; }
  95. int32 GetTimeStamp() { return timestamp; }
  96. void setFirstLogin(bool value) { firstlogin = value; }
  97. bool isFirstLogin() { return firstlogin; }
  98. private:
  99. int32 accountid;
  100. string character_name;
  101. int32 accesskey;
  102. int32 timestamp;
  103. bool firstlogin;
  104. };
  105. class ZoneAuth
  106. {
  107. public:
  108. void AddAuth(ZoneAuthRequest* zar);
  109. ZoneAuthRequest* GetAuth(int32 account_id, int32 access_key);
  110. void PurgeInactiveAuth();
  111. void RemoveAuth(ZoneAuthRequest* zar);
  112. private:
  113. LinkedList<ZoneAuthRequest*> list;
  114. };
  115. #endif