1
This commit is contained in:
parent
4de95e5225
commit
79d4e61bcd
@ -61,15 +61,15 @@ void HttpProxy::UnInit()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string HttpProxy::HttpGet(a8::XParams param,
|
std::string HttpProxy::HttpGet(
|
||||||
f8::AsyncHttpOnOkFunc on_ok,
|
f8::HttpProxyCb cb,
|
||||||
f8::AsyncHttpOnErrorFunc on_error,
|
|
||||||
const char* url,
|
const char* url,
|
||||||
a8::XObject url_params
|
a8::XObject url_params
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
std::shared_ptr<HttpProxyRequest> request = std::make_shared<HttpProxyRequest>();
|
std::shared_ptr<HttpProxyRequest> request = std::make_shared<HttpProxyRequest>();
|
||||||
request->req_id = CreateRequestId();
|
request->req_id = CreateRequestId();
|
||||||
|
#if 0
|
||||||
request->param = param;
|
request->param = param;
|
||||||
request->on_ok = on_ok;
|
request->on_ok = on_ok;
|
||||||
request->on_error = on_error;
|
request->on_error = on_error;
|
||||||
@ -81,6 +81,7 @@ std::string HttpProxy::HttpGet(a8::XParams param,
|
|||||||
}
|
}
|
||||||
request_hash_[request->req_id] = request;
|
request_hash_[request->req_id] = request;
|
||||||
|
|
||||||
|
|
||||||
auto proxy_url_params = a8::MutableXObject::CreateObject();
|
auto proxy_url_params = a8::MutableXObject::CreateObject();
|
||||||
proxy_url_params->SetVal("seq_id", request->req_id);
|
proxy_url_params->SetVal("seq_id", request->req_id);
|
||||||
proxy_url_params->SetVal("target_url", std::string(url));
|
proxy_url_params->SetVal("target_url", std::string(url));
|
||||||
@ -130,6 +131,7 @@ std::string HttpProxy::HttpGet(a8::XParams param,
|
|||||||
*proxy_url_params,
|
*proxy_url_params,
|
||||||
rand() % MAX_SYS_HTTP_NUM
|
rand() % MAX_SYS_HTTP_NUM
|
||||||
);
|
);
|
||||||
|
#endif
|
||||||
return request->req_id;
|
return request->req_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,10 @@
|
|||||||
#include "f8/httpclientpool.h"
|
#include "f8/httpclientpool.h"
|
||||||
|
|
||||||
struct HttpProxyRequest;
|
struct HttpProxyRequest;
|
||||||
typedef std::function<void(a8::XObject&)> HttpProxyCb;
|
namespace f8 {
|
||||||
|
struct HttpContext;
|
||||||
|
typedef std::function<void(bool, a8::XObject*, f8::HttpContext*)> HttpProxyCb;
|
||||||
|
}
|
||||||
class HttpProxy : public a8::Singleton<HttpProxy>
|
class HttpProxy : public a8::Singleton<HttpProxy>
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -18,9 +21,8 @@ class HttpProxy : public a8::Singleton<HttpProxy>
|
|||||||
void Init();
|
void Init();
|
||||||
void UnInit();
|
void UnInit();
|
||||||
|
|
||||||
std::string HttpGet(a8::XParams param,
|
std::string HttpGet(
|
||||||
f8::AsyncHttpOnOkFunc on_ok,
|
f8::HttpProxyCb cb,
|
||||||
f8::AsyncHttpOnErrorFunc on_error,
|
|
||||||
const char* url,
|
const char* url,
|
||||||
a8::XObject url_params
|
a8::XObject url_params
|
||||||
);
|
);
|
||||||
|
@ -2557,36 +2557,6 @@ void Human::SendBattleSettlement()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Player* p = (Player*)this;
|
Player* p = (Player*)this;
|
||||||
auto on_ok =
|
|
||||||
[] (a8::XParams& param, a8::XObject& data)
|
|
||||||
{
|
|
||||||
Room* room = RoomMgr::Instance()->GetRoomByUuid(param.sender);
|
|
||||||
if (!room) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Player* hum = room->GetPlayerByAccountId(param.param1.GetString());
|
|
||||||
if (!hum) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
auto on_error =
|
|
||||||
[] (a8::XParams& param, const std::string& response)
|
|
||||||
{
|
|
||||||
f8::UdpLog::Instance()->Error("reportSettlement error params: %s response: %s",
|
|
||||||
{
|
|
||||||
param.param2,
|
|
||||||
response
|
|
||||||
});
|
|
||||||
Room* room = RoomMgr::Instance()->GetRoomByUuid(param.sender);
|
|
||||||
if (!room) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Player* hum = room->GetPlayerByAccountId(param.param1.GetString());
|
|
||||||
if (!hum) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
std::shared_ptr<a8::MutableXObject> params = a8::MutableXObject::CreateObject();
|
std::shared_ptr<a8::MutableXObject> params = a8::MutableXObject::CreateObject();
|
||||||
{
|
{
|
||||||
params->SetVal("account_id", account_id);
|
params->SetVal("account_id", account_id);
|
||||||
@ -2611,14 +2581,30 @@ void Human::SendBattleSettlement()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
long long room_uuid = room->GetRoomUuid();
|
||||||
|
std::string account_id = account_id;
|
||||||
|
|
||||||
HttpProxy::Instance()->HttpGet
|
HttpProxy::Instance()->HttpGet
|
||||||
(
|
(
|
||||||
a8::XParams()
|
[room_uuid, account_id, data]
|
||||||
.SetSender(room->GetRoomUuid())
|
(bool ok, a8::XObject* rsp_obj, f8::HttpContext* ctx)
|
||||||
.SetParam1(account_id)
|
{
|
||||||
.SetParam2(data),
|
Room* room = RoomMgr::Instance()->GetRoomByUuid(room_uuid);
|
||||||
on_ok,
|
if (!room) {
|
||||||
on_error,
|
return;
|
||||||
|
}
|
||||||
|
Player* hum = room->GetPlayerByAccountId(account_id);
|
||||||
|
if (!hum) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!ok) {
|
||||||
|
f8::UdpLog::Instance()->Error("reportSettlement error params: %s response: %s",
|
||||||
|
{
|
||||||
|
data,
|
||||||
|
""
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
url.c_str(),
|
url.c_str(),
|
||||||
*params.get()
|
*params.get()
|
||||||
);
|
);
|
||||||
@ -2628,41 +2614,6 @@ void Human::SendBattleReport()
|
|||||||
{
|
{
|
||||||
std::shared_ptr<a8::MutableXObject> params = a8::MutableXObject::CreateObject();
|
std::shared_ptr<a8::MutableXObject> params = a8::MutableXObject::CreateObject();
|
||||||
GenBattleReportData(params.get());
|
GenBattleReportData(params.get());
|
||||||
auto on_ok =
|
|
||||||
[] (a8::XParams& param, a8::XObject& data)
|
|
||||||
{
|
|
||||||
Room* room = RoomMgr::Instance()->GetRoomByUuid(param.sender);
|
|
||||||
if (!room) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Player* hum = room->GetPlayerByAccountId(param.param1.GetString());
|
|
||||||
if (!hum) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
hum->sending_battlereport_ = false;
|
|
||||||
hum->already_report_battle_ = true;
|
|
||||||
hum->stats.ParseReward(hum, data);
|
|
||||||
hum->SendGameOver();
|
|
||||||
hum->SendBattleSettlement();
|
|
||||||
};
|
|
||||||
auto on_error =
|
|
||||||
[] (a8::XParams& param, const std::string& response)
|
|
||||||
{
|
|
||||||
f8::UdpLog::Instance()->Error("battleReport http error params: %s response: %s",
|
|
||||||
{
|
|
||||||
param.param2,
|
|
||||||
response
|
|
||||||
});
|
|
||||||
Room* room = RoomMgr::Instance()->GetRoomByUuid(param.sender);
|
|
||||||
if (!room) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Player* hum = room->GetPlayerByAccountId(param.param1.GetString());
|
|
||||||
if (!hum) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
hum->sending_battlereport_ = false;
|
|
||||||
};
|
|
||||||
std::string url;
|
std::string url;
|
||||||
JsonDataMgr::Instance()->GetApiUrl(url);
|
JsonDataMgr::Instance()->GetApiUrl(url);
|
||||||
if (url.find('?') != std::string::npos) {
|
if (url.find('?') != std::string::npos) {
|
||||||
@ -2677,14 +2628,38 @@ void Human::SendBattleReport()
|
|||||||
already_report_battle_ = true;
|
already_report_battle_ = true;
|
||||||
SendGameOver();
|
SendGameOver();
|
||||||
} else {
|
} else {
|
||||||
|
long long room_uuid = room->GetRoomUuid();
|
||||||
|
std::string account_id = account_id;
|
||||||
HttpProxy::Instance()->HttpGet
|
HttpProxy::Instance()->HttpGet
|
||||||
(
|
(
|
||||||
a8::XParams()
|
[room_uuid, account_id, data]
|
||||||
.SetSender(room->GetRoomUuid())
|
(bool ok, a8::XObject* rsp_obj, f8::HttpContext* ctx)
|
||||||
.SetParam1(account_id)
|
{
|
||||||
.SetParam2(data),
|
if (!ok) {
|
||||||
on_ok,
|
f8::UdpLog::Instance()->Error("battleReport http error params: %s response: %s",
|
||||||
on_error,
|
{
|
||||||
|
data,
|
||||||
|
""
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Room* room = RoomMgr::Instance()->GetRoomByUuid(room_uuid);
|
||||||
|
if (!room) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Player* hum = room->GetPlayerByAccountId(account_id);
|
||||||
|
if (!hum) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ok) {
|
||||||
|
hum->sending_battlereport_ = false;
|
||||||
|
hum->already_report_battle_ = true;
|
||||||
|
hum->stats.ParseReward(hum, *rsp_obj);
|
||||||
|
hum->SendGameOver();
|
||||||
|
hum->SendBattleSettlement();
|
||||||
|
} else {
|
||||||
|
hum->sending_battlereport_ = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
url.c_str(),
|
url.c_str(),
|
||||||
*params.get()
|
*params.get()
|
||||||
);
|
);
|
||||||
|
@ -1176,53 +1176,45 @@ void Player::_CMRevive(f8::MsgHdr& hdr, const cs::CMRevive& msg)
|
|||||||
url_params->SetVal("session_id", session_id);
|
url_params->SetVal("session_id", session_id);
|
||||||
url_params->SetVal("target_id", hum->account_id);
|
url_params->SetVal("target_id", hum->account_id);
|
||||||
url_params->SetVal("num", 1);
|
url_params->SetVal("num", 1);
|
||||||
|
|
||||||
|
long long room_uuid = room->GetRoomUuid();
|
||||||
|
std::string account_id = account_id;
|
||||||
|
auto target_uniid = msg.target_uniid();
|
||||||
HttpProxy::Instance()->HttpGet
|
HttpProxy::Instance()->HttpGet
|
||||||
(
|
(
|
||||||
a8::XParams()
|
[room_uuid, account_id, target_uniid]
|
||||||
.SetSender(room->GetRoomUuid())
|
(bool ok, a8::XObject* rsp_obj, f8::HttpContext* ctx)
|
||||||
.SetParam1(account_id)
|
|
||||||
.SetParam2(msg.target_uniid()),
|
|
||||||
[] (a8::XParams& param, a8::XObject& data)
|
|
||||||
{
|
{
|
||||||
Room* room = RoomMgr::Instance()->GetRoomByUuid(param.sender);
|
Room* room = RoomMgr::Instance()->GetRoomByUuid(room_uuid);
|
||||||
if (!room) {
|
if (!room) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Player* hum = room->GetPlayerByAccountId(param.param1.GetString());
|
Player* hum = room->GetPlayerByAccountId(account_id);
|
||||||
if (!hum) {
|
if (!hum) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (room->IsGameOver()) {
|
if (ok) {
|
||||||
return;
|
if (room->IsGameOver()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (rsp_obj->GetType() == a8::XOT_OBJECT &&
|
||||||
|
rsp_obj->Get("errcode").GetInt() == 0) {
|
||||||
|
int revive_coin = rsp_obj->Get("revive_coin");
|
||||||
|
room->xtimer.SetTimeoutEx
|
||||||
|
(
|
||||||
|
NEXT_FRAME_TIMER,
|
||||||
|
[hum, target_uniid, revive_coin] (int event, const a8::Args* args)
|
||||||
|
{
|
||||||
|
if (a8::TIMER_EXEC_EVENT == event) {
|
||||||
|
a8::UnSetBitFlag(hum->status, CS_Reviving);
|
||||||
|
hum->InternalRevive(target_uniid, revive_coin);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
&hum->xtimer_attacher);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
a8::UnSetBitFlag(hum->status, CS_Reviving);
|
||||||
}
|
}
|
||||||
if (data.GetType() == a8::XOT_OBJECT &&
|
|
||||||
data.Get("errcode").GetInt() == 0) {
|
|
||||||
int revive_coin = data.Get("revive_coin");
|
|
||||||
int target_uniid = param.param2.GetInt();
|
|
||||||
room->xtimer.SetTimeoutEx
|
|
||||||
(
|
|
||||||
NEXT_FRAME_TIMER,
|
|
||||||
[hum, target_uniid, revive_coin] (int event, const a8::Args* args)
|
|
||||||
{
|
|
||||||
if (a8::TIMER_EXEC_EVENT == event) {
|
|
||||||
a8::UnSetBitFlag(hum->status, CS_Reviving);
|
|
||||||
hum->InternalRevive(target_uniid, revive_coin);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
&hum->xtimer_attacher);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[] (a8::XParams& param, const std::string& response)
|
|
||||||
{
|
|
||||||
Room* room = RoomMgr::Instance()->GetRoomByUuid(param.sender);
|
|
||||||
if (!room) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Player* hum = room->GetPlayerByAccountId(param.param1.GetString());
|
|
||||||
if (!hum) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
a8::UnSetBitFlag(hum->status, CS_Reviving);
|
|
||||||
},
|
},
|
||||||
url.c_str(),
|
url.c_str(),
|
||||||
*url_params
|
*url_params
|
||||||
|
@ -802,57 +802,41 @@ void RoomMgr::SendGetBattleData(int mode,
|
|||||||
}
|
}
|
||||||
HttpProxy::Instance()->HttpGet
|
HttpProxy::Instance()->HttpGet
|
||||||
(
|
(
|
||||||
a8::XParams()
|
[result, cb]
|
||||||
.SetSender(new std::shared_ptr<std::vector<std::shared_ptr<BattleDataContext>>>(result))
|
(bool ok, a8::XObject* rsp_obj, f8::HttpContext* ctx)
|
||||||
.SetParam1(new std::function<
|
|
||||||
void(std::vector<std::shared_ptr<BattleDataContext>>&)>(cb)),
|
|
||||||
[] (a8::XParams& param, a8::XObject& data)
|
|
||||||
{
|
{
|
||||||
f8::UdpLog::Instance()->Info
|
if (ok) {
|
||||||
("GetBattleData ok %s",
|
f8::UdpLog::Instance()->Info
|
||||||
{
|
("GetBattleData ok %s",
|
||||||
data.ToJsonStr()
|
{
|
||||||
});
|
rsp_obj->ToJsonStr()
|
||||||
auto result = (std::shared_ptr<std::vector<std::shared_ptr<BattleDataContext>>>*)param.sender.GetUserData();
|
});
|
||||||
auto cb = (std::function<
|
|
||||||
void(std::vector<std::shared_ptr<BattleDataContext>>&)>*)param.param1.GetUserData();
|
|
||||||
|
|
||||||
if (data.GetType() == a8::XOT_OBJECT) {
|
if (rsp_obj->GetType() == a8::XOT_OBJECT) {
|
||||||
int match_mode = data.Get("match_mode");
|
int match_mode = rsp_obj->Get("match_mode");
|
||||||
RoomMgr::Instance()->SetMatchMode(match_mode ? 1 : 0);
|
RoomMgr::Instance()->SetMatchMode(match_mode ? 1 : 0);
|
||||||
if (data.HasKey("members")) {
|
if (rsp_obj->HasKey("members")) {
|
||||||
auto members = data.At("members");
|
auto members = rsp_obj->At("members");
|
||||||
if (members->GetType() == a8::XOT_ARRAY && members->Size() == (*result->get()).size()) {
|
if (members->GetType() == a8::XOT_ARRAY && members->Size() == result->size()) {
|
||||||
for (int i = 0; i < members->Size(); ++i) {
|
for (int i = 0; i < members->Size(); ++i) {
|
||||||
auto& ctx = (*result->get()).at(i);
|
auto& ctx = result->at(i);
|
||||||
auto member = members->At(i);
|
auto member = members->At(i);
|
||||||
if (member->GetType() == a8::XOT_OBJECT) {
|
if (member->GetType() == a8::XOT_OBJECT) {
|
||||||
ctx->ParseResult(*member);
|
ctx->ParseResult(*member);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
cb(*result);
|
||||||
|
} else {
|
||||||
|
f8::UdpLog::Instance()->Warning
|
||||||
|
("GetBattleData error %s",
|
||||||
|
{
|
||||||
|
""
|
||||||
|
});
|
||||||
|
cb(*result);
|
||||||
}
|
}
|
||||||
(*cb)(*result->get());
|
|
||||||
|
|
||||||
delete cb;
|
|
||||||
delete result;
|
|
||||||
},
|
|
||||||
[] (a8::XParams& param, const std::string& response)
|
|
||||||
{
|
|
||||||
f8::UdpLog::Instance()->Warning
|
|
||||||
("GetBattleData error %s",
|
|
||||||
{
|
|
||||||
response
|
|
||||||
});
|
|
||||||
auto result = (std::shared_ptr<std::vector<std::shared_ptr<BattleDataContext>>>*)param.sender.GetUserData();
|
|
||||||
auto cb = (std::function<
|
|
||||||
void(std::vector<std::shared_ptr<BattleDataContext>>&)>*)param.param1.GetUserData();
|
|
||||||
(*cb)(*result->get());
|
|
||||||
for (auto& context : *result->get()) {
|
|
||||||
}
|
|
||||||
delete cb;
|
|
||||||
delete result;
|
|
||||||
},
|
},
|
||||||
url.c_str(),
|
url.c_str(),
|
||||||
*url_params
|
*url_params
|
||||||
|
Loading…
x
Reference in New Issue
Block a user