1
This commit is contained in:
parent
12379921ca
commit
434b7a8ed9
@ -1,5 +1,5 @@
|
||||
[
|
||||
{
|
||||
"url": "http://192.168.100.21:8321/webapp/index.php?c=Proxy&a=get"
|
||||
}
|
||||
"url": "http://192.168.100.21:8321/webapp/index.php"
|
||||
}
|
||||
]
|
||||
|
@ -44,7 +44,7 @@ Android::~Android()
|
||||
void Android::Initialize()
|
||||
{
|
||||
Human::Initialize();
|
||||
account_id = a8::Format("2006_0000_%d", {robot_meta->id()});
|
||||
account_id = a8::Format("0000_2006_%d", {robot_meta->id()});
|
||||
RandSkin();
|
||||
GiveEquip();
|
||||
RecalcBaseAttr();
|
||||
|
@ -92,7 +92,7 @@ std::string HttpProxy::HttpGet(
|
||||
JsonDataMgr::Instance()->listen_port
|
||||
}));
|
||||
std::string proxy_url;
|
||||
JsonDataMgr::Instance()->GetHttpProxyUrl(proxy_url);
|
||||
JsonDataMgr::Instance()->GetHttpGetProxyUrl(proxy_url);
|
||||
f8::HttpClientPool::Instance()->HttpGet
|
||||
(
|
||||
[request] (bool ok, a8::XObject* rsp_obj, f8::HttpContext* ctx)
|
||||
@ -126,6 +126,76 @@ std::string HttpProxy::HttpGet(
|
||||
return request->req_id;
|
||||
}
|
||||
|
||||
std::string HttpProxy::HttpPost(
|
||||
f8::HttpProxyCb cb,
|
||||
const char* url,
|
||||
a8::XObject url_params,
|
||||
const std::string& content
|
||||
)
|
||||
{
|
||||
if (f8::App::Instance()->Terminated()) {
|
||||
return "";
|
||||
}
|
||||
std::shared_ptr<HttpProxyRequest> request = std::make_shared<HttpProxyRequest>();
|
||||
request->req_id = CreateRequestId();
|
||||
request->cb = cb;
|
||||
request->url = url;
|
||||
request->url_params = url_params;
|
||||
request->add_tick = a8::XGetTickCount();
|
||||
if (request_hash_.find(request->req_id) != request_hash_.end()) {
|
||||
abort();
|
||||
}
|
||||
request_hash_[request->req_id] = request;
|
||||
|
||||
|
||||
auto proxy_url_params = a8::MutableXObject::CreateObject();
|
||||
proxy_url_params->SetVal("seq_id", request->req_id);
|
||||
proxy_url_params->SetVal("target_url", std::string(url));
|
||||
proxy_url_params->SetVal("params", url_params.ToJsonStr());
|
||||
proxy_url_params->SetVal("cb_url", a8::Format("http://%s:%d/webapp/index.php?c=Proxy&a=callback",
|
||||
{
|
||||
JsonDataMgr::Instance()->ip,
|
||||
JsonDataMgr::Instance()->listen_port
|
||||
}));
|
||||
auto http_headers = a8::MutableXObject::CreateArray();
|
||||
http_headers->Push("Content-Type: application/json");
|
||||
std::string proxy_url;
|
||||
JsonDataMgr::Instance()->GetHttpPostProxyUrl(proxy_url);
|
||||
f8::HttpClientPool::Instance()->HttpPost
|
||||
(
|
||||
[request] (bool ok, a8::XObject* rsp_obj, f8::HttpContext* ctx)
|
||||
{
|
||||
long long cost_time = a8::XGetTickCount() - request->add_tick;
|
||||
if (ok) {
|
||||
#ifdef MYDEBUG
|
||||
f8::UdpLog::Instance()->Debug("ProxyHttpPost ok cost_time:%d url:%s params:%s",
|
||||
{
|
||||
cost_time,
|
||||
request->url,
|
||||
request->url_params.ToJsonStr(),
|
||||
});
|
||||
#endif
|
||||
} else {
|
||||
f8::UdpLog::Instance()->Warning("ProxyHttpPost error cost_time:%d url:%s params:%s response:%s",
|
||||
{
|
||||
cost_time,
|
||||
request->url,
|
||||
request->url_params.ToJsonStr(),
|
||||
ctx->response
|
||||
});
|
||||
request->cb(false, rsp_obj, ctx);
|
||||
HttpProxy::Instance()->DestoryRequest(request);
|
||||
}
|
||||
},
|
||||
proxy_url.c_str(),
|
||||
*proxy_url_params,
|
||||
content,
|
||||
rand() % MAX_SYS_HTTP_NUM,
|
||||
http_headers.get()
|
||||
);
|
||||
return request->req_id;
|
||||
}
|
||||
|
||||
std::string HttpProxy::CreateRequestId()
|
||||
{
|
||||
return request_prefix_ + f8::App::Instance()->NewGlobalUuid();
|
||||
|
@ -22,6 +22,13 @@ class HttpProxy : public a8::Singleton<HttpProxy>
|
||||
const char* url,
|
||||
a8::XObject url_params
|
||||
);
|
||||
std::string HttpPost(
|
||||
f8::HttpProxyCb cb,
|
||||
const char* url,
|
||||
a8::XObject url_params,
|
||||
const std::string& content
|
||||
);
|
||||
|
||||
std::shared_ptr<HttpProxyRequest> GetRequest(const std::string& req_id);
|
||||
void DestoryRequest(std::shared_ptr<HttpProxyRequest> request);
|
||||
|
||||
|
@ -110,10 +110,18 @@ void JsonDataMgr::GetApiUrl(std::string& url)
|
||||
}
|
||||
}
|
||||
|
||||
void JsonDataMgr::GetHttpProxyUrl(std::string& url)
|
||||
void JsonDataMgr::GetHttpGetProxyUrl(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();
|
||||
url = conf->At("url")->AsXValue().GetString() + "?c=Proxy&a=get";
|
||||
}
|
||||
}
|
||||
|
||||
void JsonDataMgr::GetHttpPostProxyUrl(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() + "?c=Proxy&a=post";
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,8 @@ public:
|
||||
std::string server_info;
|
||||
|
||||
void GetApiUrl(std::string& url);
|
||||
void GetHttpProxyUrl(std::string& url);
|
||||
void GetHttpGetProxyUrl(std::string& url);
|
||||
void GetHttpPostProxyUrl(std::string& url);
|
||||
|
||||
private:
|
||||
std::string api_url_;
|
||||
|
@ -2233,6 +2233,9 @@ void Room::OnGameOver()
|
||||
if (all_sent) {
|
||||
TryRoomReport(0);
|
||||
xtimer.DeleteCurrentTimer();
|
||||
} else if (GetFrameNo() - frameno > SERVER_FRAME_RATE * 5) {
|
||||
TryRoomReport(0);
|
||||
xtimer.DeleteCurrentTimer();
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -3965,11 +3968,11 @@ void Room::TryRoomReport(int try_count)
|
||||
}
|
||||
std::shared_ptr<a8::MutableXObject> params = a8::MutableXObject::CreateObject();
|
||||
std::shared_ptr<a8::MutableXObject> post_data = a8::MutableXObject::CreateObject();
|
||||
GenBattleRoomReportData(post_data.get());
|
||||
params->SetVal("account_id", player->account_id);
|
||||
params->SetVal("session_id", player->session_id);
|
||||
params->SetVal("__POST", post_data->ToJsonStr());
|
||||
GenBattleRoomReportData(post_data.get());
|
||||
HttpProxy::Instance()->HttpGet
|
||||
std::string content = post_data->ToJsonStr();
|
||||
HttpProxy::Instance()->HttpPost
|
||||
(
|
||||
[room_uuid = GetRoomUuid()]
|
||||
(bool ok, a8::XObject* rsp_obj, f8::HttpContext* ctx)
|
||||
@ -3982,6 +3985,10 @@ void Room::TryRoomReport(int try_count)
|
||||
}
|
||||
},
|
||||
url.c_str(),
|
||||
*params.get()
|
||||
*params.get(),
|
||||
content
|
||||
);
|
||||
#ifdef MYDEBUG
|
||||
a8::XPrintf("RoomReportLen:%d\n", {params->ToJsonStr().size()});
|
||||
#endif
|
||||
}
|
||||
|
@ -660,6 +660,7 @@ void Team::GenRoomReportData(a8::MutableXObject* params)
|
||||
params->SetVal("pvp_team_kills", 0); //
|
||||
}
|
||||
|
||||
#if 0
|
||||
{
|
||||
auto teams_pb = a8::MutableXObject::CreateArray();
|
||||
room->TraverseTeams
|
||||
@ -684,6 +685,7 @@ void Team::GenRoomReportData(a8::MutableXObject* params)
|
||||
});
|
||||
params->SetVal("team_list", *teams_pb);
|
||||
}
|
||||
#endif
|
||||
|
||||
{
|
||||
int pvp_team_kills = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user