net.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. #ifdef WIN32
  7. #define WIN32_LEAN_AND_MEAN
  8. #include <windows.h>
  9. #include <winsock.h>
  10. #else
  11. #include <sys/socket.h>
  12. #include <netinet/in.h>
  13. #include <arpa/inet.h>
  14. #include <unistd.h>
  15. #endif
  16. //#include <netdb.h>
  17. #include <errno.h>
  18. #include <fcntl.h>
  19. #include <atomic>
  20. #include "../common/types.h"
  21. #include "../common/Web/WebServer.h"
  22. #include "../common/MiscFunctions.h"
  23. void CatchSignal(int sig_num);
  24. enum eServerMode { Standalone, Master, Slave, Mesh };
  25. class NetConnection
  26. {
  27. public:
  28. NetConnection() {
  29. port = 5999;
  30. listening_socket = 0;
  31. memset(masteraddress, 0, sizeof(masteraddress));
  32. uplinkport = 0;
  33. memset(uplinkaccount, 0, sizeof(uplinkaccount));
  34. memset(uplinkpassword, 0, sizeof(uplinkpassword));
  35. LoginMode = Standalone;
  36. Uplink_WrongVersion = false;
  37. numclients = 0;
  38. numservers = 0;
  39. allowAccountCreation = true;
  40. // full support = 0x7CFF
  41. // 1 << 12 (-4096) = missing echoes of faydwer, disables Fae and Arasai (black portraits) and kelethin as starting city
  42. // 1 << 13 (-8192) = disables sarnak (black portraits) and gorowyn as starting city
  43. expansionFlag = 0x7CFF; // 0x4CF5
  44. /* dword_1ECBA18 operand for race flag packs (sublevel 0,1,2?) -- (sublevel -1) controls starting zones omission 0xEE vs 0xCF (CF misses halas)
  45. 1 = city of qeynos
  46. 2 = city of freeport
  47. 4 = city of kelethin
  48. 8 = city of neriak
  49. 16 = gorowyn
  50. 32 = new halas
  51. 64 = queens colony
  52. 128 = outpost overlord
  53. */
  54. citiesFlag = 0xFF;
  55. // sub_level 0xFFFFFFFF = blacks out all portraits for class alignments, considered non membership
  56. // sub_level > 0 = class alignments still required, but portraits are viewable and race selectable
  57. // sub_level = 2 membership, you can 'create characters on time locked servers' vs standard
  58. // sub_level = 0 forces popup on close to web browser
  59. defaultSubscriptionLevel = 0xFFFFFFFF;
  60. // disable extra races FAE(16) ARASAI (17) SARNAK (18) -- with 4096/8192 flags, no visibility of portraits
  61. enabledRaces = 0xFFFF; // 0xCFFF
  62. web_loginport = 0;
  63. login_webserver = nullptr;
  64. login_running = false;
  65. login_uptime = getCurrentTimestamp();
  66. }
  67. ~NetConnection() {
  68. safe_delete(login_webserver);
  69. }
  70. void UpdateWindowTitle(char* iNewTitle = 0);
  71. bool Init();
  72. void ListenNewClients();
  73. void HitKey(int keyhit);
  74. char address[1024];
  75. int32 numclients;
  76. int32 numservers;
  77. int16 GetPort() { return port; }
  78. void SetPort(int16 in_port) { port = in_port; }
  79. eServerMode GetLoginMode() { return LoginMode; }
  80. bool ReadLoginConfig();
  81. char* GetMasterAddress() { return masteraddress; }
  82. int16 GetUplinkPort() { if (uplinkport != 0) return uplinkport; else return port; }
  83. char* GetUplinkAccount() { return uplinkaccount; }
  84. char* GetUplinkPassword() { return uplinkpassword; }
  85. bool IsAllowingAccountCreation() { return allowAccountCreation; }
  86. int32 GetExpansionFlag() { return expansionFlag; }
  87. int8 GetCitiesFlag() { return citiesFlag; }
  88. int32 GetDefaultSubscriptionLevel() { return defaultSubscriptionLevel; }
  89. int32 GetEnabledRaces() { return enabledRaces; }
  90. std::string GetWebLoginAddress() { return web_loginaddress; }
  91. inline int16 GetWebLoginPort() { return web_loginport; }
  92. std::string GetWebCertFile() { return web_certfile; }
  93. std::string GetWebKeyFile() { return web_keyfile; }
  94. std::string GetWebKeyPassword() { return web_keypassword; }
  95. std::string GetWebHardcodeUser() { return web_hardcodeuser; }
  96. std::string GetWebHardcodePassword() { return web_hardcodepassword; }
  97. void WelcomeHeader();
  98. void InitWebServer(std::string web_ipaddr, int16 web_port, std::string cert_file, std::string key_file, std::string key_password, std::string hardcode_user, std::string hardcode_password);
  99. static void Web_loginhandle_status(const http::request<http::string_body>& req, http::response<http::string_body>& res);
  100. static void Web_loginhandle_worlds(const http::request<http::string_body>& req, http::response<http::string_body>& res);
  101. bool login_running;
  102. std::atomic<int64> login_uptime;
  103. protected:
  104. friend class LWorld;
  105. bool Uplink_WrongVersion;
  106. private:
  107. int16 port;
  108. int listening_socket;
  109. char masteraddress[300];
  110. int16 uplinkport;
  111. char uplinkaccount[300];
  112. char uplinkpassword[300];
  113. eServerMode LoginMode;
  114. bool allowAccountCreation;
  115. int32 expansionFlag;
  116. int8 citiesFlag;
  117. int32 defaultSubscriptionLevel;
  118. int32 enabledRaces;
  119. std::string web_loginaddress;
  120. std::string web_certfile;
  121. std::string web_keyfile;
  122. std::string web_keypassword;
  123. std::string web_hardcodeuser;
  124. std::string web_hardcodepassword;
  125. int16 web_loginport;
  126. WebServer* login_webserver;
  127. };