9
3

net.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. void WelcomeHeader();
  38. #define PORT 9000
  39. #define LOGIN_PORT 9100
  40. class NetConnection
  41. {
  42. public:
  43. NetConnection() {
  44. world_locked = false;
  45. for (int i=0; i<3; i++) {
  46. memset(loginaddress[i], 0, sizeof(loginaddress[i]));
  47. loginport[i] = LOGIN_PORT;
  48. }
  49. listening_socket = 0;
  50. updateport = 0;
  51. memset(worldname, 0, sizeof(worldname));
  52. memset(updateaddress, 0, sizeof(updateaddress));
  53. memset(worldaccount, 0, sizeof(worldaccount));
  54. memset(worldpassword, 0, sizeof(worldpassword));
  55. memset(worldaddress, 0, sizeof(worldaddress));
  56. memset(internalworldaddress, 0, sizeof(internalworldaddress));
  57. worldport = PORT;
  58. DEFAULTSTATUS=0;
  59. LoginServerInfo = 0;//ReadLoginINI();
  60. UpdateStats = false;
  61. }
  62. ~NetConnection() { }
  63. bool ReadLoginINI();
  64. bool LoginServerInfo;
  65. bool UpdateStats;
  66. char* GetLoginInfo(int16* oPort);
  67. char* GetUpdateServerInfo(int16* oPort);
  68. inline char* GetLoginAddress(int8 i) { return loginaddress[i]; }
  69. inline int16 GetLoginPort(int8 i) { return loginport[i]; }
  70. inline char* GetWorldName() { return worldname; }
  71. inline char* GetWorldAccount() { return worldaccount; }
  72. inline char* GetWorldPassword() { return worldpassword; }
  73. inline char* GetWorldAddress() { return worldaddress; }
  74. inline char* GetInternalWorldAddress() { return internalworldaddress; }
  75. inline int16 GetWorldPort() { return worldport; }
  76. inline int8 GetDefaultStatus() { return DEFAULTSTATUS; }
  77. bool world_locked;
  78. private:
  79. int listening_socket;
  80. char loginaddress[3][255];
  81. char updateaddress[255];
  82. int16 loginport[3];
  83. int16 updateport;
  84. char worldname[201];
  85. char worldaccount[31];
  86. char worldpassword[31];
  87. char worldaddress[255];
  88. char internalworldaddress[21];
  89. int16 worldport;
  90. int8 DEFAULTSTATUS;
  91. };
  92. class ZoneAuthRequest
  93. {
  94. public:
  95. ZoneAuthRequest(int32 account_id, char* name, int32 access_key);
  96. ~ZoneAuthRequest( );
  97. int32 GetAccountID() { return accountid; }
  98. const char* GetCharacterName() { return character_name.c_str(); }
  99. int32 GetAccessKey() { return accesskey; }
  100. int32 GetTimeStamp() { return timestamp; }
  101. void setFirstLogin(bool value) { firstlogin = value; }
  102. bool isFirstLogin() { return firstlogin; }
  103. private:
  104. int32 accountid;
  105. string character_name;
  106. int32 accesskey;
  107. int32 timestamp;
  108. bool firstlogin;
  109. };
  110. class ZoneAuth
  111. {
  112. public:
  113. void AddAuth(ZoneAuthRequest* zar);
  114. ZoneAuthRequest* GetAuth(int32 account_id, int32 access_key);
  115. void PurgeInactiveAuth();
  116. void RemoveAuth(ZoneAuthRequest* zar);
  117. private:
  118. LinkedList<ZoneAuthRequest*> list;
  119. };
  120. #endif