1
This commit is contained in:
parent
c3d8b2e565
commit
37768dc6bf
@ -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()
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include "framework/cpp/httpclientpool.h"
|
||||
|
||||
struct HttpProxyRequest;
|
||||
class HttpProxy : public a8::Singleton<HttpProxy>
|
||||
{
|
||||
|
||||
@ -26,7 +27,7 @@ class HttpProxy : public a8::Singleton<HttpProxy>
|
||||
std::string CreateRequestId();
|
||||
|
||||
private:
|
||||
std::map<std::string, a8::XParams> request_hash_;
|
||||
std::map<std::string, HttpProxyRequest*> request_hash_;
|
||||
std::string request_prefix_;
|
||||
|
||||
};
|
||||
|
@ -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<a8::XObject> conf = httpproxy_cluster_json_.At(0);
|
||||
url = conf->At("url")->AsXValue().GetString();
|
||||
}
|
||||
}
|
||||
|
@ -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_;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user