diff --git a/server/gameserver/httpproxy.cc b/server/gameserver/httpproxy.cc index 85c58ec7..443071e1 100644 --- a/server/gameserver/httpproxy.cc +++ b/server/gameserver/httpproxy.cc @@ -8,6 +8,16 @@ #include "framework/cpp/httpclientpool.h" +struct HttpProxyRequest +{ + std::string req_id; + a8::XParams param; + f8::AsyncHttpOnOkFunc on_ok; + f8::AsyncHttpOnErrorFunc on_error; + const char* url = nullptr; + a8::XObject url_params; +}; + void HttpProxy::Init() { request_prefix_ = "game2006_" + a8::XValue(a8::GetMilliSecond()).GetString() + "_"; @@ -25,20 +35,20 @@ std::string HttpProxy::HttpGet(a8::XParams param, a8::XObject url_params ) { - std::string request_id = CreateRequestId(); - request_hash_[request_id] = param; + HttpProxyRequest* request = new HttpProxyRequest(); + request->req_id = CreateRequestId(); + request_hash_[request->req_id] = request; + f8::HttpClientPool::Instance()->HttpGet (a8::XParams() - //.SetSender(instance_id) - //.SetParam1(host) - .SetParam2(1), + .SetSender(request), on_ok, on_error, url, url_params, rand() % MAX_SYS_HTTP_NUM ); - return request_id; + return request->req_id; } std::string HttpProxy::CreateRequestId() diff --git a/server/gameserver/httpproxy.h b/server/gameserver/httpproxy.h index 65e750a0..5a64f105 100644 --- a/server/gameserver/httpproxy.h +++ b/server/gameserver/httpproxy.h @@ -2,6 +2,7 @@ #include "framework/cpp/httpclientpool.h" +struct HttpProxyRequest; class HttpProxy : public a8::Singleton { @@ -26,7 +27,7 @@ class HttpProxy : public a8::Singleton std::string CreateRequestId(); private: - std::map request_hash_; + std::map request_hash_; std::string request_prefix_; }; diff --git a/server/gameserver/jsondatamgr.cc b/server/gameserver/jsondatamgr.cc index bbe064c5..917c781a 100644 --- a/server/gameserver/jsondatamgr.cc +++ b/server/gameserver/jsondatamgr.cc @@ -23,6 +23,7 @@ void JsonDataMgr::Init() std::string gameserver_cluster_json_file; std::string setting_json_file; + std::string httpproxy_json_file; gameserver_cluster_json_file = a8::Format("%s/node%d/game%d.gameserver.cluster.json", { @@ -35,8 +36,13 @@ void JsonDataMgr::Init() work_path_, GAME_ID }); + setting_json_file = a8::Format("%s/httpproxy.cluster.json", + { + work_path_, + }); gameserver_cluster_json_.ReadFromFile(gameserver_cluster_json_file); setting_json_.ReadFromFile(setting_json_file); + httpproxy_cluster_json_.ReadFromFile(httpproxy_json_file); if (setting_json_.GetType() == a8::XOT_OBJECT && setting_json_.HasKey("battle_report_url")) { battle_report_url_ = setting_json_.Get("battle_report_url").GetString(); @@ -107,3 +113,11 @@ void JsonDataMgr::GetBattleReportUrl(std::string& url) url = battle_report_url_; } } + +void JsonDataMgr::GetHttpProxyUrl(std::string& url) +{ + if (!httpproxy_cluster_json_.Size() > 0) { + std::shared_ptr conf = httpproxy_cluster_json_.At(0); + url = conf->At("url")->AsXValue().GetString(); + } +} diff --git a/server/gameserver/jsondatamgr.h b/server/gameserver/jsondatamgr.h index 7eb81af8..336fddf5 100644 --- a/server/gameserver/jsondatamgr.h +++ b/server/gameserver/jsondatamgr.h @@ -20,6 +20,7 @@ public: void Reload(); void GetBattleReportUrl(std::string& url); + void GetHttpProxyUrl(std::string& url); private: std::string battle_report_url_; @@ -29,4 +30,5 @@ private: a8::XObject setting_json_; a8::XObject gameserver_cluster_json_; a8::XObject masterserver_cluster_json_; + a8::XObject httpproxy_cluster_json_; };