This commit is contained in:
aozhiwei 2023-12-11 13:17:15 +08:00
commit 9bd92292c6
6 changed files with 41 additions and 22 deletions

View File

@ -319,9 +319,11 @@ void FrameMaker::SerializeShots(cs::SMUpdate* msg, Room* room, Human* hum, Frame
if (idx < room->frame_event_data->shots_.size()) { if (idx < room->frame_event_data->shots_.size()) {
auto& tuple = room->frame_event_data->shots_[idx]; auto& tuple = room->frame_event_data->shots_[idx];
if (std::get<0>(tuple).Get() && hum->CanSee(std::get<0>(tuple).Get())) { if (std::get<0>(tuple).Get() && hum->CanSee(std::get<0>(tuple).Get())) {
#if 0
if (std::get<0>(tuple).Get()->IsPlayer()) { if (std::get<0>(tuple).Get()->IsPlayer()) {
a8::XPrintf("player shot\n", {}); a8::XPrintf("player shot\n", {});
} }
#endif
*msg->add_shots() = std::get<1>(tuple); *msg->add_shots() = std::get<1>(tuple);
} else { } else {
#ifdef MYDEBUG1 #ifdef MYDEBUG1

View File

@ -73,7 +73,9 @@ behaviac::EBTStatus AndroidAgent::CoLogin()
( (
[context] (bool ok, a8::XObject* rsp_obj, f8::HttpContext* ctx) [context] (bool ok, a8::XObject* rsp_obj, f8::HttpContext* ctx)
{ {
#if 0
a8::XPrintf("data:%s\n", {rsp_obj->ToJsonStr()}); a8::XPrintf("data:%s\n", {rsp_obj->ToJsonStr()});
#endif
if (ok) { if (ok) {
std::string account_id = rsp_obj->At("account_id")->AsXValue().GetString(); std::string account_id = rsp_obj->At("account_id")->AsXValue().GetString();
std::string session_id = rsp_obj->At("session_id")->AsXValue().GetString(); std::string session_id = rsp_obj->At("session_id")->AsXValue().GetString();
@ -90,7 +92,9 @@ behaviac::EBTStatus AndroidAgent::CoLogin()
( (
[context] (bool ok, a8::XObject* rsp_obj, f8::HttpContext* ctx) [context] (bool ok, a8::XObject* rsp_obj, f8::HttpContext* ctx)
{ {
#if 0
a8::XPrintf("data:%s\n", {rsp_obj->ToJsonStr()}); a8::XPrintf("data:%s\n", {rsp_obj->ToJsonStr()});
#endif
if (ok) { if (ok) {
context->login_ok = true; context->login_ok = true;
} else { } else {
@ -146,7 +150,7 @@ behaviac::EBTStatus AndroidAgent::CoConnectBattleServer()
owner_->GetWebSocket()->on_connect = owner_->GetWebSocket()->on_connect =
[this, context] (a8::WebSocketClient* ) [this, context] (a8::WebSocketClient* )
{ {
a8::XPrintf("id:%d WebSocketClient on_connect\n", {context->socket_id}); //a8::XPrintf("id:%d WebSocketClient on_connect\n", {context->socket_id});
context->pending = false; context->pending = false;
context->connect_ok = true; context->connect_ok = true;
}; };
@ -191,7 +195,7 @@ behaviac::EBTStatus AndroidAgent::CoJoin()
msg.set_session_id(owner_->GetSessionId()); msg.set_session_id(owner_->GetSessionId());
owner_->SendMsg(msg); owner_->SendMsg(msg);
a8::XPrintf("CoJoin %d\n", {owner_->GetSocketId()}); //a8::XPrintf("CoJoin %d\n", {owner_->GetSocketId()});
auto context = MAKE_BTCONTEXT auto context = MAKE_BTCONTEXT
( (
); );
@ -223,6 +227,8 @@ behaviac::EBTStatus AndroidAgent::CoUpdateGame()
GlmHelper::RotateY(curr_dir_, a8::RandAngle()); GlmHelper::RotateY(curr_dir_, a8::RandAngle());
last_dir_tick_ = a8::XGetTickCount(); last_dir_tick_ = a8::XGetTickCount();
} }
if (a8::XGetTickCount() - last_send_tick_ > 80) {
last_send_tick_ = a8::XGetTickCount();
{ {
cs::CMMove msg; cs::CMMove msg;
ToPb(curr_dir_, msg.mutable_move_dir()); ToPb(curr_dir_, msg.mutable_move_dir());
@ -236,6 +242,9 @@ behaviac::EBTStatus AndroidAgent::CoUpdateGame()
owner_->SendMsg(msg); owner_->SendMsg(msg);
} }
} }
} else {
a8::XPrintf("disconnect\n", {});
}
#endif #endif
return behaviac::BT_SUCCESS; return behaviac::BT_SUCCESS;
} }

View File

@ -41,5 +41,6 @@ private:
std::shared_ptr<Player> owner_; std::shared_ptr<Player> owner_;
glm::vec3 curr_dir_ = glm::vec3(0.0f, 0.0f, 0.0f); glm::vec3 curr_dir_ = glm::vec3(0.0f, 0.0f, 0.0f);
long long last_dir_tick_ = 0; long long last_dir_tick_ = 0;
long long last_send_tick_ = 0;
}; };

View File

@ -65,11 +65,13 @@ protected:
static void _ProxyCallback(std::shared_ptr<f8::JsonHttpRequest> request) static void _ProxyCallback(std::shared_ptr<f8::JsonHttpRequest> request)
{ {
#ifdef MYDEBUG #ifdef MYDEBUG
#if 0
f8::UdpLog::Instance()->Debug("ProxyCallbBack request:%s", f8::UdpLog::Instance()->Debug("ProxyCallbBack request:%s",
{ {
request->GetParams()->ToJsonStr() request->GetParams()->ToJsonStr()
}); });
#endif #endif
#endif
std::string seq_id = request->GetParams()->Get("seq_id"); std::string seq_id = request->GetParams()->Get("seq_id");
std::shared_ptr<HttpProxyRequest> req = HttpProxy::Instance()->GetRequest(seq_id); std::shared_ptr<HttpProxyRequest> req = HttpProxy::Instance()->GetRequest(seq_id);
if (req) { if (req) {
@ -126,12 +128,14 @@ std::string HttpProxy::HttpGet(
proxy_url_params->SetVal("cb_url", proxy_url_params->SetVal("cb_url",
a8::Format("http://%s:%d/webapp/index.php?c=Proxy&a=callback", a8::Format("http://%s:%d/webapp/index.php?c=Proxy&a=callback",
{ {
"192.168.100.39", //"192.168.100.39",
"127.0.0.1",
3333 3333
//JsonDataMgr::Instance()->ip, //JsonDataMgr::Instance()->ip,
//JsonDataMgr::Instance()->listen_port //JsonDataMgr::Instance()->listen_port
})); }));
std::string proxy_url = "http://192.168.100.21:8321/webapp/index.php?c=Proxy&a=get"; //std::string proxy_url = "http://192.168.100.21:8321/webapp/index.php?c=Proxy&a=get";
std::string proxy_url = "http://127.0.0.1:8321/webapp/index.php?c=Proxy&a=get";
//JsonDataMgr::Instance()->GetHttpProxyUrl(proxy_url); //JsonDataMgr::Instance()->GetHttpProxyUrl(proxy_url);
f8::HttpClientPool::Instance()->HttpGet f8::HttpClientPool::Instance()->HttpGet
( (
@ -140,6 +144,7 @@ std::string HttpProxy::HttpGet(
long long cost_time = a8::XGetTickCount() - request->add_tick; long long cost_time = a8::XGetTickCount() - request->add_tick;
if (ok) { if (ok) {
#ifdef MYDEBUG #ifdef MYDEBUG
#if 0
f8::UdpLog::Instance()->Debug("ProxyHttpGet ok cost_time:%d url:%s params:%s", f8::UdpLog::Instance()->Debug("ProxyHttpGet ok cost_time:%d url:%s params:%s",
{ {
cost_time, cost_time,
@ -147,6 +152,7 @@ std::string HttpProxy::HttpGet(
request->url_params.ToJsonStr(), request->url_params.ToJsonStr(),
}); });
#endif #endif
#endif
} else { } else {
f8::UdpLog::Instance()->Warning("ProxyHttpGet error cost_time:%d url:%s params:%s response:%s", f8::UdpLog::Instance()->Warning("ProxyHttpGet error cost_time:%d url:%s params:%s response:%s",
{ {

View File

@ -39,7 +39,8 @@ void Player::Init(int idx, const std::string& account_id)
IoMgr::Instance()->GetIoContext(0), IoMgr::Instance()->GetIoContext(0),
//"192.168.100.45", //"192.168.100.45",
//7601 //7601
"192.144.200.110", //"192.144.200.110",
"127.0.0.1",
7601 7601
); );
web_socket_->on_decode_userpacket = web_socket_->on_decode_userpacket =
@ -135,13 +136,13 @@ void Player::_SMMatchCancel(f8::MsgHdr* hdr, const cs::SMMatchCancel& msg)
void Player::_SMJoinedNotify(f8::MsgHdr* hdr, const cs::SMJoinedNotify& msg) void Player::_SMJoinedNotify(f8::MsgHdr* hdr, const cs::SMJoinedNotify& msg)
{ {
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)}); //f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
join_ok_ = true; join_ok_ = true;
} }
void Player::_SMMapInfo(f8::MsgHdr* hdr, const cs::SMMapInfo& msg) void Player::_SMMapInfo(f8::MsgHdr* hdr, const cs::SMMapInfo& msg)
{ {
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)}); //f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
} }
void Player::_SMUpdate(f8::MsgHdr* hdr, const cs::SMUpdate& msg) void Player::_SMUpdate(f8::MsgHdr* hdr, const cs::SMUpdate& msg)
@ -151,7 +152,7 @@ void Player::_SMUpdate(f8::MsgHdr* hdr, const cs::SMUpdate& msg)
void Player::_SMRollMsg(f8::MsgHdr* hdr, const cs::SMRollMsg& msg) void Player::_SMRollMsg(f8::MsgHdr* hdr, const cs::SMRollMsg& msg)
{ {
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)}); //f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
} }
void Player::_SMVoiceNotify(f8::MsgHdr* hdr, const cs::SMVoiceNotify& msg) void Player::_SMVoiceNotify(f8::MsgHdr* hdr, const cs::SMVoiceNotify& msg)
@ -167,7 +168,7 @@ void Player::_SMDisconnectNotify(f8::MsgHdr* hdr, const cs::SMDisconnectNotify&
void Player::_SMGameOver(f8::MsgHdr* hdr, const cs::SMGameOver& msg) void Player::_SMGameOver(f8::MsgHdr* hdr, const cs::SMGameOver& msg)
{ {
GetWebSocket()->Close(); GetWebSocket()->Close();
f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)}); //f8::UdpLog::Instance()->Info("%s %s", {msg.GetTypeName(), f8::PbToJson(&msg)});
} }
void Player::_SMDebugMsg(f8::MsgHdr* hdr, const cs::SMDebugMsg& msg) void Player::_SMDebugMsg(f8::MsgHdr* hdr, const cs::SMDebugMsg& msg)

View File

@ -31,7 +31,7 @@ void PlayerMgr::Init()
int count = 0; int count = 0;
f8::Timer::Instance()->SetInterval f8::Timer::Instance()->SetInterval
( (
3000, 200,
[this, count] (int et, const a8::Args* args) mutable [this, count] (int et, const a8::Args* args) mutable
{ {
if (et == a8::TIMER_EXEC_EVENT) { if (et == a8::TIMER_EXEC_EVENT) {
@ -42,7 +42,7 @@ void PlayerMgr::Init()
account_id_hash_[hum->GetAccountId()] = hum; account_id_hash_[hum->GetAccountId()] = hum;
socket_id_hash_[hum->GetSocketId()] = hum; socket_id_hash_[hum->GetSocketId()] = hum;
++count; ++count;
if (count >= 200) { if (count >= 2000) {
f8::Timer::Instance()->DeleteCurrentTimer(); f8::Timer::Instance()->DeleteCurrentTimer();
} }
} }