1
This commit is contained in:
commit
bc57b6ea56
@ -70,11 +70,14 @@ behaviac::EBTStatus AndroidAgent::CoLogin()
|
||||
{
|
||||
auto url_params = a8::MutableXObject::CreateObject();
|
||||
url_params->SetVal("c", "Login");
|
||||
url_params->SetVal("a", "auth");
|
||||
url_params->SetVal("gameid", 2006);
|
||||
url_params->SetVal("channel", 6513);
|
||||
url_params->SetVal("openid", owner_->GetIdx());
|
||||
HttpProxy::Instance()->HttpGet
|
||||
url_params->SetVal("a", "auth2");
|
||||
//url_params->SetVal("gameid", 2006);
|
||||
//url_params->SetVal("channel", 6513);
|
||||
//url_params->SetVal("openid", owner_->GetIdx());
|
||||
auto post_body = a8::MutableXObject::CreateObject();
|
||||
post_body->SetVal("channel", 2);
|
||||
post_body->SetVal("data", owner_->GetIdx());
|
||||
HttpProxy::Instance()->HttpPost
|
||||
(
|
||||
[context] (bool ok, a8::XObject* rsp_obj, f8::HttpContext* ctx)
|
||||
{
|
||||
@ -110,7 +113,7 @@ behaviac::EBTStatus AndroidAgent::CoLogin()
|
||||
}
|
||||
},
|
||||
"https://game2006api-test.kingsome.cn/webapp/index.php",
|
||||
*url_params
|
||||
url_params
|
||||
);
|
||||
} else {
|
||||
context->login_ok = false;
|
||||
@ -118,7 +121,8 @@ behaviac::EBTStatus AndroidAgent::CoLogin()
|
||||
}
|
||||
},
|
||||
"https://login-test.kingsome.cn/webapp/index.php",
|
||||
*url_params
|
||||
url_params,
|
||||
post_body->ToJsonStr()
|
||||
);
|
||||
}
|
||||
co->runing_cb =
|
||||
@ -198,13 +202,7 @@ behaviac::EBTStatus AndroidAgent::CoJoin()
|
||||
msg.set_server_id(6);
|
||||
msg.set_team_uuid("");
|
||||
msg.set_account_id(owner_->GetAccountId());
|
||||
msg.set_team_mode(2);
|
||||
msg.set_proto_version(cs::ProtoVersion);
|
||||
msg.set_auto_fill(1);
|
||||
msg.set_name("");
|
||||
msg.set_avatar_url("");
|
||||
msg.set_mapid(2001);
|
||||
msg.set_hero_id(30800);
|
||||
//weapons
|
||||
msg.set_session_id(owner_->GetSessionId());
|
||||
owner_->SendMsg(msg);
|
||||
|
@ -58,7 +58,6 @@ void HandlerMgr::RegisterNetMsgHandlers()
|
||||
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMReconnect);
|
||||
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMWatchWar);
|
||||
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMLeave);
|
||||
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMMatchCancel);
|
||||
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMJoinedNotify);
|
||||
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMMapInfo);
|
||||
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMUpdate);
|
||||
@ -72,9 +71,7 @@ void HandlerMgr::RegisterNetMsgHandlers()
|
||||
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMSysPiaoMsg);
|
||||
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMShowCountdown);
|
||||
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMShowTeamUI);
|
||||
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMUpdateMatchInfo);
|
||||
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMGetItemNotify);
|
||||
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMMatchMemberMsgNotify);
|
||||
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMPvePassWave);
|
||||
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMTeamMarkTargetPosList);
|
||||
RegisterNetMsgHandler(&gsmsghandler, &Player::_SMDebugCmd);
|
||||
|
@ -1,200 +0,0 @@
|
||||
#include "precompile.h"
|
||||
|
||||
#include <a8/sysutils.h>
|
||||
#include <a8/mutable_xobject.h>
|
||||
#include <a8/awaiter.h>
|
||||
#include <a8/promise.h>
|
||||
|
||||
#include <f8/udplog.h>
|
||||
#include <f8/jsonhttprequest.h>
|
||||
#include <f8/utils.h>
|
||||
|
||||
#include "httpproxy.h"
|
||||
#include "app.h"
|
||||
#include "handlermgr.h"
|
||||
|
||||
#include "f8/httpclientpool.h"
|
||||
|
||||
struct HttpProxyRequest
|
||||
{
|
||||
std::string req_id;
|
||||
f8::HttpProxyCb cb;
|
||||
std::string url;
|
||||
a8::XObject url_params;
|
||||
long long add_tick = 0;
|
||||
};
|
||||
|
||||
class HttpProxyPromise : public a8::Promise
|
||||
{
|
||||
public:
|
||||
HttpProxyPromise(const char* url, a8::XObject url_params, bool* ret, std::shared_ptr<a8::XObject>* rsp)
|
||||
{
|
||||
url_ = url;
|
||||
url_params_ = url_params;
|
||||
ret_ = ret;
|
||||
rsp_ = rsp;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
virtual void DoAwait() override
|
||||
{
|
||||
f8::HttpClientPool::Instance()->HttpGet
|
||||
(
|
||||
[this, _self = shared_from_this()]
|
||||
(bool ok, a8::XObject* rsp_obj, f8::HttpContext* ctx)
|
||||
{
|
||||
*ret_ = ok;
|
||||
if (ok) {
|
||||
**rsp_ = *rsp_obj;
|
||||
}
|
||||
DoDone();
|
||||
},
|
||||
url_.c_str(),
|
||||
url_params_,
|
||||
rand() % MAX_SYS_HTTP_NUM
|
||||
);
|
||||
}
|
||||
|
||||
private:
|
||||
std::string url_;
|
||||
a8::XObject url_params_;
|
||||
bool* ret_ = nullptr;
|
||||
std::shared_ptr<a8::XObject>* rsp_ = nullptr;
|
||||
};
|
||||
|
||||
static void _ProxyCallback(std::shared_ptr<f8::JsonHttpRequest> request)
|
||||
{
|
||||
#ifdef MYDEBUG
|
||||
#if 0
|
||||
f8::UdpLog::Instance()->Debug("ProxyCallbBack request:%s",
|
||||
{
|
||||
request->GetParams()->ToJsonStr()
|
||||
});
|
||||
#endif
|
||||
#endif
|
||||
std::string seq_id = request->GetParams()->Get("seq_id");
|
||||
std::shared_ptr<HttpProxyRequest> req = HttpProxy::Instance()->GetRequest(seq_id);
|
||||
if (req) {
|
||||
a8::XObject data;
|
||||
|
||||
data.ReadFromJsonString(request->GetParams()->Get("data").GetString());
|
||||
if (data.GetType() == a8::XOT_SIMPLE) {
|
||||
data.ReadFromJsonString("{}");
|
||||
}
|
||||
f8::HttpContext ctx;
|
||||
if (request->GetParams()->HasKey("errcode") &&
|
||||
request->GetParams()->Get("errcode").GetInt() == 0) {
|
||||
req->cb(true, &data, &ctx);
|
||||
} else {
|
||||
req->cb(false, request->GetParams().get(), &ctx);
|
||||
}
|
||||
HttpProxy::Instance()->DestoryRequest(req);
|
||||
}
|
||||
}
|
||||
|
||||
void HttpProxy::Init()
|
||||
{
|
||||
request_prefix_ = "robot2006_" + a8::XValue(a8::GetMilliSecond()).GetString() + "_";
|
||||
HandlerMgr::Instance()->RegisterGMMsgHandler("Proxy@callback", _ProxyCallback);
|
||||
}
|
||||
|
||||
void HttpProxy::UnInit()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::string HttpProxy::HttpGet(
|
||||
f8::HttpProxyCb cb,
|
||||
const char* url,
|
||||
a8::XObject url_params
|
||||
)
|
||||
{
|
||||
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;
|
||||
|
||||
std::string local_ip;
|
||||
a8::GetLocalIp(local_ip);
|
||||
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",
|
||||
{
|
||||
local_ip,
|
||||
3333
|
||||
}));
|
||||
std::string proxy_url = "http://192.168.100.21:8321/webapp/index.php?c=Proxy&a=get";
|
||||
if (f8::IsTestEnv()) {
|
||||
proxy_url = "http://127.0.0.1:8321/webapp/index.php?c=Proxy&a=get";
|
||||
}
|
||||
f8::HttpClientPool::Instance()->HttpGet
|
||||
(
|
||||
[request] (bool ok, a8::XObject* rsp_obj, f8::HttpContext* ctx)
|
||||
{
|
||||
long long cost_time = a8::XGetTickCount() - request->add_tick;
|
||||
if (ok) {
|
||||
#ifdef MYDEBUG
|
||||
#if 0
|
||||
f8::UdpLog::Instance()->Debug("ProxyHttpGet ok cost_time:%d url:%s params:%s",
|
||||
{
|
||||
cost_time,
|
||||
request->url,
|
||||
request->url_params.ToJsonStr(),
|
||||
});
|
||||
#endif
|
||||
#endif
|
||||
} else {
|
||||
f8::UdpLog::Instance()->Warning("ProxyHttpGet 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,
|
||||
rand() % MAX_SYS_HTTP_NUM
|
||||
);
|
||||
return request->req_id;
|
||||
}
|
||||
|
||||
std::string HttpProxy::CreateRequestId()
|
||||
{
|
||||
return request_prefix_ + f8::App::Instance()->NewGlobalUuid();
|
||||
}
|
||||
|
||||
std::shared_ptr<HttpProxyRequest> HttpProxy::GetRequest(const std::string& req_id)
|
||||
{
|
||||
auto itr = request_hash_.find(req_id);
|
||||
return itr != request_hash_.end() ? itr->second : nullptr;
|
||||
}
|
||||
|
||||
void HttpProxy::DestoryRequest(std::shared_ptr<HttpProxyRequest> request)
|
||||
{
|
||||
request_hash_.erase(request->req_id);
|
||||
}
|
||||
|
||||
std::shared_ptr<a8::Awaiter> HttpProxy::CoHttpGet(const char* url,
|
||||
a8::XObject url_params,
|
||||
bool* ret,
|
||||
std::shared_ptr<a8::XObject>* rsp)
|
||||
{
|
||||
*ret = false;
|
||||
*rsp = std::make_shared<a8::XObject>();
|
||||
return std::make_shared<HttpProxyPromise>(url, url_params, ret, rsp);
|
||||
}
|
1
server/robotserver/httpproxy.cc
Symbolic link
1
server/robotserver/httpproxy.cc
Symbolic link
@ -0,0 +1 @@
|
||||
../gameserver/httpproxy.cc
|
@ -1,46 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <a8/singleton.h>
|
||||
|
||||
#include "f8/httpclientpool.h"
|
||||
|
||||
namespace a8
|
||||
{
|
||||
class Awaiter;
|
||||
}
|
||||
|
||||
struct HttpProxyRequest;
|
||||
class HttpProxy : public a8::Singleton<HttpProxy>
|
||||
{
|
||||
|
||||
private:
|
||||
HttpProxy() {};
|
||||
friend class a8::Singleton<HttpProxy>;
|
||||
|
||||
public:
|
||||
|
||||
void Init();
|
||||
void UnInit();
|
||||
|
||||
std::string HttpGet(
|
||||
f8::HttpProxyCb cb,
|
||||
const char* url,
|
||||
a8::XObject url_params
|
||||
);
|
||||
std::shared_ptr<HttpProxyRequest> GetRequest(const std::string& req_id);
|
||||
void DestoryRequest(std::shared_ptr<HttpProxyRequest> request);
|
||||
|
||||
std::shared_ptr<a8::Awaiter> CoHttpGet(const char* url,
|
||||
a8::XObject url_params,
|
||||
bool* ret,
|
||||
std::shared_ptr<a8::XObject>* rsp);
|
||||
|
||||
private:
|
||||
|
||||
std::string CreateRequestId();
|
||||
|
||||
private:
|
||||
std::map<std::string, std::shared_ptr<HttpProxyRequest>> request_hash_;
|
||||
std::string request_prefix_;
|
||||
|
||||
};
|
1
server/robotserver/httpproxy.h
Symbolic link
1
server/robotserver/httpproxy.h
Symbolic link
@ -0,0 +1 @@
|
||||
../gameserver/httpproxy.h
|
1
server/robotserver/jsondatamgr.cc
Symbolic link
1
server/robotserver/jsondatamgr.cc
Symbolic link
@ -0,0 +1 @@
|
||||
../gameserver/jsondatamgr.cc
|
1
server/robotserver/jsondatamgr.h
Symbolic link
1
server/robotserver/jsondatamgr.h
Symbolic link
@ -0,0 +1 @@
|
||||
../gameserver/jsondatamgr.h
|
@ -134,11 +134,6 @@ void Player::_SMLeave(f8::MsgHdr* hdr, const cs::SMLeave& msg)
|
||||
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
||||
}
|
||||
|
||||
void Player::_SMMatchCancel(f8::MsgHdr* hdr, const cs::SMMatchCancel& msg)
|
||||
{
|
||||
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
||||
}
|
||||
|
||||
void Player::_SMJoinedNotify(f8::MsgHdr* hdr, const cs::SMJoinedNotify& msg)
|
||||
{
|
||||
//f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
||||
@ -206,21 +201,11 @@ void Player::_SMShowTeamUI(f8::MsgHdr* hdr, const cs::SMShowTeamUI& msg)
|
||||
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
||||
}
|
||||
|
||||
void Player::_SMUpdateMatchInfo(f8::MsgHdr* hdr, const cs::SMUpdateMatchInfo& msg)
|
||||
{
|
||||
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
||||
}
|
||||
|
||||
void Player::_SMGetItemNotify(f8::MsgHdr* hdr, const cs::SMGetItemNotify& msg)
|
||||
{
|
||||
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
||||
}
|
||||
|
||||
void Player::_SMMatchMemberMsgNotify(f8::MsgHdr* hdr, const cs::SMMatchMemberMsgNotify& msg)
|
||||
{
|
||||
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
||||
}
|
||||
|
||||
void Player::_SMPvePassWave(f8::MsgHdr* hdr, const cs::SMPvePassWave& msg)
|
||||
{
|
||||
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
|
||||
|
@ -45,7 +45,6 @@ public:
|
||||
void _SMReconnect(f8::MsgHdr* hdr, const cs::SMReconnect& msg);
|
||||
void _SMWatchWar(f8::MsgHdr* hdr, const cs::SMWatchWar& msg);
|
||||
void _SMLeave(f8::MsgHdr* hdr, const cs::SMLeave& msg);
|
||||
void _SMMatchCancel(f8::MsgHdr* hdr, const cs::SMMatchCancel& msg);
|
||||
void _SMJoinedNotify(f8::MsgHdr* hdr, const cs::SMJoinedNotify& msg);
|
||||
void _SMMapInfo(f8::MsgHdr* hdr, const cs::SMMapInfo& msg);
|
||||
void _SMUpdate(f8::MsgHdr* hdr, const cs::SMUpdate& msg);
|
||||
@ -59,9 +58,7 @@ public:
|
||||
void _SMSysPiaoMsg(f8::MsgHdr* hdr, const cs::SMSysPiaoMsg& msg);
|
||||
void _SMShowCountdown(f8::MsgHdr* hdr, const cs::SMShowCountdown& msg);
|
||||
void _SMShowTeamUI(f8::MsgHdr* hdr, const cs::SMShowTeamUI& msg);
|
||||
void _SMUpdateMatchInfo(f8::MsgHdr* hdr, const cs::SMUpdateMatchInfo& msg);
|
||||
void _SMGetItemNotify(f8::MsgHdr* hdr, const cs::SMGetItemNotify& msg);
|
||||
void _SMMatchMemberMsgNotify(f8::MsgHdr* hdr, const cs::SMMatchMemberMsgNotify& msg);
|
||||
void _SMPvePassWave(f8::MsgHdr* hdr, const cs::SMPvePassWave& msg);
|
||||
void _SMTeamMarkTargetPosList(f8::MsgHdr* hdr, const cs::SMTeamMarkTargetPosList& msg);
|
||||
void _SMDebugCmd(f8::MsgHdr* hdr, const cs::SMDebugCmd& msg);
|
||||
|
@ -21,7 +21,7 @@ void PlayerMgr::Init()
|
||||
int count = 0;
|
||||
f8::Timer::Instance()->SetInterval
|
||||
(
|
||||
200,
|
||||
1,
|
||||
[this, count] (int et, const a8::Args* args) mutable
|
||||
{
|
||||
if (et == a8::TIMER_EXEC_EVENT) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user