diff options
-rw-r--r-- | server/server/config.cpp | 64 | ||||
-rw-r--r-- | server/server/config.h | 29 |
2 files changed, 92 insertions, 1 deletions
diff --git a/server/server/config.cpp b/server/server/config.cpp index 967d9fe..1917a13 100644 --- a/server/server/config.cpp +++ b/server/server/config.cpp @@ -4,7 +4,7 @@ config::config(const char *pth) { std::ifstream config; if(!pth) - config.open("./server.cfg", std::fstream::out); + config.open("./server.cfg", std::fstream::in); else config.open(pth, std::fstream::in); std::string cfg_str((std::istreambuf_iterator<char>(config)), std::istreambuf_iterator<char>()); @@ -48,6 +48,68 @@ const std::string config::get_string(const std::string& data, const char* var, c } return default_; } + +void config::load_proxy_list(char *pth) +{ + std::ifstream config; + if(!pth) + config.open("./proxy_list.cfg", std::fstream::in); + else + config.open(pth, std::fstream::in); + std::string cfg_str((std::istreambuf_iterator<char>(config)), std::istreambuf_iterator<char>()); + config.close(); + if(!cfg_str.empty()) + { + std::string::size_type p1 = 0, p2 = 0; + p2 = cfg_str.find(';'); + while(p2 != std::string::npos) + { + std::string line = cfg_str.substr(p1, p2-p1); + std::string::size_type lp1 = 0, lp2 = 0; + std::string host, login, password, country, state, city; + int port = 0; + if(line.find('@') != std::string::npos) + { + lp2 = line.find(':'); + login = line.substr(lp1, lp2-lp1); + lp1 = lp2+1; + lp2 = line.find('@'); + password = line.substr(lp1, lp2-lp1); + lp1 = lp2+1; + lp2 = line.find(':'); + host = line.substr(lp1, lp2-lp1); + lp1 = lp2+1; + lp2 = line.find("\x20"); + port = atoi(line.substr(lp1, lp2-lp1).c_str()); + lp1 = lp2+2; + lp2 = line.find('"'); + country = line.substr(lp1, lp2-lp1).c_str(); + lp1 = lp2+3; + lp2 = line.find('"'); + state = line.substr(lp1, lp2-lp1).c_str(); + lp1 = lp2+3; + lp2 = line.find('"'); + city = line.substr(lp1, lp2-lp1).c_str(); + proxy_list.push_back(proxy_entry(login, password, host, port, country, state, city)); + } + else + { + } + } + } +} + +void config::load_static_proxy_list(char *pth) +{ + std::ifstream config; + if(!pth) + config.open("./static_proxy_list.cfg", std::fstream::in); + else + config.open(pth, std::fstream::in); + std::string cfg_str((std::istreambuf_iterator<char>(config)), std::istreambuf_iterator<char>()); + config.close(); +} + const int config::ban_time() { return vars.ban_time; diff --git a/server/server/config.h b/server/server/config.h index 7554857..12ff54b 100644 --- a/server/server/config.h +++ b/server/server/config.h @@ -3,6 +3,31 @@ #include "headers.h" + +struct proxy_entry +{ + std::string host, login, password, country, state, city; + int port; + proxy_entry(): port(0) + {} + proxy_entry (std::string login_, std::string password_, std::string host_, int port_, std::string country_, std::string state_, std::string city_) + { + login = login_; + password = password_; + host = host_; + port = port; + country = country_; + state = state_; + city = city_; + } +}; + +struct static_proxy_entry +{ + int port, position; + std::string host, login, password, label; +}; + class config { public: @@ -33,7 +58,11 @@ private: }; const int get_int(const std::string& data, const char* var, int default_); const std::string get_string(const std::string& data, const char* var, const std::string& default_); + void load_proxy_list(char* pth = NULL); + void load_static_proxy_list(char* pth = NULL); cfg_data vars; + std::list<proxy_entry> proxy_list; + std::list<static_proxy_entry> static_proxy_list; }; #endif
\ No newline at end of file |