diff --git a/server/gameserver/netdata.cc b/server/gameserver/netdata.cc index 9e0e2d27..e90c2c94 100644 --- a/server/gameserver/netdata.cc +++ b/server/gameserver/netdata.cc @@ -2,6 +2,8 @@ #include +#include + #include "netdata.h" #include "human.h" @@ -17,6 +19,9 @@ #include "android.h" #include "skill.h" #include "trigger.h" +#include "jsondatamgr.h" +#include "player.h" +#include "httpproxy.h" #include "buff/distance_dmg_addition.h" @@ -1420,5 +1425,78 @@ void BattleDataContext::UseItem(int item_id) std::get<2>(tuple) += 1; } } + auto hum = owner_.Get()->AsPlayer(); + { + std::string url; + JsonDataMgr::Instance()->GetApiUrl(url); + auto url_params = a8::MutableXObject::CreateObject(); + url_params->SetVal("c", "Battle"); + url_params->SetVal("a", "getNormalBattleData"); + url_params->SetVal("account_id", hum->account_id); + url_params->SetVal("session_id", hum->session_id); + std::string post_data; + { + //a8::XObject post_obj; + //post_obj.ReadFromJsonString(join_msg->payload_data()); + //post_data = post_obj.ToJsonStr(); + } + HttpProxy::Instance()->HttpGet + ( + [] + (bool ok, a8::XObject* rsp_obj, f8::HttpContext* ctx) + { + #if 0 + if (ok) { + f8::UdpLog::Instance()->Info + ("GetBattleData ok %s", + { + rsp_obj->ToJsonStr() + }); + if (rsp_obj->GetType() != a8::XOT_OBJECT || + !rsp_obj->HasKey("errcode")) { + cb(1, "", nullptr); + return; + } + int errcode = rsp_obj->Get("errcode", "").GetInt(); + std::string errmsg = rsp_obj->Get("errmsg", "").GetString(); + if (errcode) { + cb(1, "", nullptr); + return; + } + std::string room_uuid = rsp_obj->Get("room_uuid", "").GetString(); + if (room_uuid.empty()) { + cb(1, "custom battle data error", nullptr); + return; + } + auto cur_room = RoomMgr::Instance()->GetCustomRoom(room_uuid); + if (cur_room) { + cb(0, "", cur_room); + return; + } + + auto custom_battle = std::make_shared(); + custom_battle->Init(); + custom_battle->SetCustomRoomType(custom_room_type); + custom_battle->ParseResult(*rsp_obj); + if (custom_battle->GetParseOk()) { + cb(0, "", custom_battle); + RoomMgr::Instance()->custom_room_hash_[custom_battle->GetMatchRoomUuid()] = custom_battle; + } else { + cb(1, "", custom_battle); + } + } else { + f8::UdpLog::Instance()->Warning + ("GetCustomBattleData error %s", + { + "" + }); + cb(1, "custom battle data error", nullptr); + } + #endif + }, + url, + url_params + ); + } } }