From 28b6ba9f1359f21408cce1dc53011c79731ddded Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Tue, 18 Oct 2011 01:10:42 +0300 Subject: =?UTF-8?q?=D0=BF=D0=B0=D1=80=D1=81=D0=B5=D1=80=D1=8B=20=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D1=8B=D1=85=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3?= =?UTF-8?q?=D0=BE=D0=B2=20..=20)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/server/config.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++++++- server/server/config.h | 29 ++++++++++++++++++++++ 2 files changed, 92 insertions(+), 1 deletion(-) 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(config)), std::istreambuf_iterator()); @@ -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(config)), std::istreambuf_iterator()); + 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(config)), std::istreambuf_iterator()); + 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_list; + std::list static_proxy_list; }; #endif \ No newline at end of file -- cgit v1.2.3