1
This commit is contained in:
parent
13ce94f65e
commit
2764aac6c1
@ -126,31 +126,33 @@ behaviac::EBTStatus AndroidAgent::CoConnectBattleServer()
|
|||||||
(
|
(
|
||||||
std::function<void (a8::WebSocketClient*, int)> old_on_error;
|
std::function<void (a8::WebSocketClient*, int)> old_on_error;
|
||||||
std::function<void (a8::WebSocketClient*)> old_on_connect;
|
std::function<void (a8::WebSocketClient*)> old_on_connect;
|
||||||
std::function<void (a8::WebSocketClient*)> old_on_disconnect;
|
std::function<void (a8::WebSocketClient*, int)> old_on_disconnect;
|
||||||
bool pending = true;
|
bool pending = true;
|
||||||
bool connect_ok = false;
|
bool connect_ok = false;
|
||||||
|
int socket_id = 0;
|
||||||
);
|
);
|
||||||
context->old_on_error = owner_->GetWebSocket()->on_error;
|
context->old_on_error = owner_->GetWebSocket()->on_error;
|
||||||
context->old_on_connect = owner_->GetWebSocket()->on_connect;
|
context->old_on_connect = owner_->GetWebSocket()->on_connect;
|
||||||
context->old_on_disconnect = owner_->GetWebSocket()->on_disconnect;
|
context->old_on_disconnect = owner_->GetWebSocket()->on_disconnect;
|
||||||
|
context->socket_id = owner_->GetSocketId();
|
||||||
owner_->GetWebSocket()->on_error =
|
owner_->GetWebSocket()->on_error =
|
||||||
[this, context] (a8::WebSocketClient*, int err_code)
|
[this, context] (a8::WebSocketClient*, int err_code)
|
||||||
{
|
{
|
||||||
a8::XPrintf("WebSocketClient on_error:%d\n", {err_code});
|
a8::XPrintf("id:%d WebSocketClient on_error:%d\n", {context->socket_id, err_code});
|
||||||
context->pending = false;
|
context->pending = false;
|
||||||
context->connect_ok = false;
|
context->connect_ok = false;
|
||||||
};
|
};
|
||||||
owner_->GetWebSocket()->on_connect =
|
owner_->GetWebSocket()->on_connect =
|
||||||
[this, context] (a8::WebSocketClient* )
|
[this, context] (a8::WebSocketClient* )
|
||||||
{
|
{
|
||||||
a8::XPrintf("WebSocketClient on_connect\n", {});
|
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;
|
||||||
};
|
};
|
||||||
owner_->GetWebSocket()->on_disconnect =
|
owner_->GetWebSocket()->on_disconnect =
|
||||||
[this, context] (a8::WebSocketClient* )
|
[this, context] (a8::WebSocketClient*, int err_code)
|
||||||
{
|
{
|
||||||
a8::XPrintf("WebSocketClient on_disconnect\n", {});
|
a8::XPrintf("id:%d WebSocketClient on_disconnect:%d\n", {context->socket_id, err_code});
|
||||||
context->pending = false;
|
context->pending = false;
|
||||||
context->connect_ok = false;
|
context->connect_ok = false;
|
||||||
};
|
};
|
||||||
@ -172,6 +174,7 @@ behaviac::EBTStatus AndroidAgent::CoConnectBattleServer()
|
|||||||
|
|
||||||
behaviac::EBTStatus AndroidAgent::CoJoin()
|
behaviac::EBTStatus AndroidAgent::CoJoin()
|
||||||
{
|
{
|
||||||
|
PRE_ENTER_COROUTINE();
|
||||||
cs::CMJoin msg;
|
cs::CMJoin msg;
|
||||||
msg.set_server_id(6);
|
msg.set_server_id(6);
|
||||||
msg.set_team_uuid("");
|
msg.set_team_uuid("");
|
||||||
@ -187,14 +190,36 @@ 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\n", {});
|
a8::XPrintf("CoJoin %d\n", {owner_->GetSocketId()});
|
||||||
|
auto context = MAKE_BTCONTEXT
|
||||||
|
(
|
||||||
|
);
|
||||||
|
auto co = std::make_shared<BtCoroutine>(context, co_id, "CoJoin");
|
||||||
|
co->runing_cb =
|
||||||
|
[this, context] (BtCoroutine* co)
|
||||||
|
{
|
||||||
|
if (!owner_->IsJoinOk()) {
|
||||||
|
return behaviac::BT_RUNNING;
|
||||||
|
}
|
||||||
return behaviac::BT_SUCCESS;
|
return behaviac::BT_SUCCESS;
|
||||||
|
};
|
||||||
|
return StartCoroutine(co);
|
||||||
}
|
}
|
||||||
|
|
||||||
behaviac::EBTStatus AndroidAgent::CoUpdateGame()
|
behaviac::EBTStatus AndroidAgent::CoUpdateGame()
|
||||||
|
{
|
||||||
|
#if 1
|
||||||
|
if (owner_->GetWebSocket()->Connected()) {
|
||||||
{
|
{
|
||||||
cs::CMMove msg;
|
cs::CMMove msg;
|
||||||
owner_->SendMsg(msg);
|
owner_->SendMsg(msg);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
cs::CMPing msg;
|
||||||
|
owner_->SendMsg(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
return behaviac::BT_SUCCESS;
|
return behaviac::BT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ void IoMgr::Init()
|
|||||||
auto w = std::make_shared<asio::io_context::work>(*c);
|
auto w = std::make_shared<asio::io_context::work>(*c);
|
||||||
works.push_back(w);
|
works.push_back(w);
|
||||||
contexts.push_back(c);
|
contexts.push_back(c);
|
||||||
new std::thread(&IoMgr::WorkerThreadProc, this, contexts.at(0));
|
//new std::thread(&IoMgr::WorkerThreadProc, this, contexts.at(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ void Player::_SMKcpHandshake(f8::MsgHdr* hdr, const cs::SMKcpHandshake& msg)
|
|||||||
|
|
||||||
void Player::_SMPing(f8::MsgHdr* hdr, const cs::SMPing& msg)
|
void Player::_SMPing(f8::MsgHdr* hdr, const cs::SMPing& 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::_SMRpcError(f8::MsgHdr* hdr, const cs::SMRpcError& msg)
|
void Player::_SMRpcError(f8::MsgHdr* hdr, const cs::SMRpcError& msg)
|
||||||
|
@ -37,6 +37,7 @@ public:
|
|||||||
void SetLoginSucess();
|
void SetLoginSucess();
|
||||||
void SetLoginFail();
|
void SetLoginFail();
|
||||||
bool IsLoginSucess() { return is_login_success_; };
|
bool IsLoginSucess() { return is_login_success_; };
|
||||||
|
bool IsJoinOk() { return join_ok_; }
|
||||||
|
|
||||||
void _SMKcpHandshake(f8::MsgHdr* hdr, const cs::SMKcpHandshake& msg);
|
void _SMKcpHandshake(f8::MsgHdr* hdr, const cs::SMKcpHandshake& msg);
|
||||||
void _SMPing(f8::MsgHdr* hdr, const cs::SMPing& msg);
|
void _SMPing(f8::MsgHdr* hdr, const cs::SMPing& msg);
|
||||||
|
@ -28,10 +28,11 @@ void PlayerMgr::Init()
|
|||||||
socket_id_hash_[hum->GetSocketId()] = hum;
|
socket_id_hash_[hum->GetSocketId()] = hum;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
int count = 0;
|
||||||
f8::Timer::Instance()->SetInterval
|
f8::Timer::Instance()->SetInterval
|
||||||
(
|
(
|
||||||
3000,
|
3000,
|
||||||
[this] (int et, const a8::Args* args)
|
[this, count] (int et, const a8::Args* args) mutable
|
||||||
{
|
{
|
||||||
if (et == a8::TIMER_EXEC_EVENT) {
|
if (et == a8::TIMER_EXEC_EVENT) {
|
||||||
int idx = account_id_hash_.size() + 1;
|
int idx = account_id_hash_.size() + 1;
|
||||||
@ -40,6 +41,10 @@ void PlayerMgr::Init()
|
|||||||
hum->Init(idx, account_id);
|
hum->Init(idx, account_id);
|
||||||
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;
|
||||||
|
if (count >= 200) {
|
||||||
|
f8::Timer::Instance()->DeleteCurrentTimer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
2
third_party/a8
vendored
2
third_party/a8
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 380074e2f78043a71b134c420af20b00127b1967
|
Subproject commit af7a9093a0d6a9c7427e08c5ee042d692c94c70b
|
Loading…
x
Reference in New Issue
Block a user