diff --git a/server/bin/gameserver/dev_config/zone1/node1/httpproxy.cluster.json b/server/bin/gameserver/dev_config/zone1/node1/httpproxy.cluster.json index f8f55885..d686e809 100644 --- a/server/bin/gameserver/dev_config/zone1/node1/httpproxy.cluster.json +++ b/server/bin/gameserver/dev_config/zone1/node1/httpproxy.cluster.json @@ -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" + } ] diff --git a/server/gameserver/android.cc b/server/gameserver/android.cc index cb1d2e5e..8e066cd4 100644 --- a/server/gameserver/android.cc +++ b/server/gameserver/android.cc @@ -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(); diff --git a/server/gameserver/httpproxy.cc b/server/gameserver/httpproxy.cc index 463193b7..b2920cc5 100644 --- a/server/gameserver/httpproxy.cc +++ b/server/gameserver/httpproxy.cc @@ -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 request = std::make_shared(); + 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(); diff --git a/server/gameserver/httpproxy.h b/server/gameserver/httpproxy.h index 789ed01a..d4855a40 100644 --- a/server/gameserver/httpproxy.h +++ b/server/gameserver/httpproxy.h @@ -22,6 +22,13 @@ class HttpProxy : public a8::Singleton 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 GetRequest(const std::string& req_id); void DestoryRequest(std::shared_ptr request); diff --git a/server/gameserver/jsondatamgr.cc b/server/gameserver/jsondatamgr.cc index a61253f3..6e66988f 100644 --- a/server/gameserver/jsondatamgr.cc +++ b/server/gameserver/jsondatamgr.cc @@ -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 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 conf = httpproxy_cluster_json_.At(0); + url = conf->At("url")->AsXValue().GetString() + "?c=Proxy&a=post"; } } diff --git a/server/gameserver/jsondatamgr.h b/server/gameserver/jsondatamgr.h index 45aede0f..4304e34d 100644 --- a/server/gameserver/jsondatamgr.h +++ b/server/gameserver/jsondatamgr.h @@ -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_; diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 88650d75..e1fb1952 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -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 params = a8::MutableXObject::CreateObject(); std::shared_ptr 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 } diff --git a/server/gameserver/team.cc b/server/gameserver/team.cc index 18bb2b08..8884c837 100644 --- a/server/gameserver/team.cc +++ b/server/gameserver/team.cc @@ -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;