This commit is contained in:
aozhiwei 2023-12-05 21:32:06 +08:00
parent 32bf17fd17
commit 85b6c88a6d

View File

@ -122,7 +122,8 @@ behaviac::EBTStatus AndroidAgent::CoConnectBattleServer()
std::function<void (a8::WebSocketClient*, int)> old_on_error;
std::function<void (a8::WebSocketClient*)> old_on_connect;
std::function<void (a8::WebSocketClient*)> old_on_disconnect;
bool pending = false;
bool pending = true;
bool connect_ok = false;
);
context->old_on_error = owner_->GetWebSocket()->on_error;
context->old_on_connect = owner_->GetWebSocket()->on_connect;
@ -130,20 +131,38 @@ behaviac::EBTStatus AndroidAgent::CoConnectBattleServer()
owner_->GetWebSocket()->on_error =
[this, context] (a8::WebSocketClient*, int err_code)
{
a8::XPrintf("WebSocketClient on_error:%d\n", {err_code});
context->pending = false;
context->connect_ok = true;
};
owner_->GetWebSocket()->on_connect =
[this, context] (a8::WebSocketClient* )
{
a8::XPrintf("WebSocketClient on_connect\n", {});
context->pending = false;
context->connect_ok = false;
};
owner_->GetWebSocket()->on_disconnect =
[this, context] (a8::WebSocketClient* )
{
a8::XPrintf("WebSocketClient on_disconnect\n", {});
context->pending = false;
context->connect_ok = false;
};
if (owner_->GetWebSocket()->IsActive()) {
owner_->GetWebSocket()->Close();
}
owner_->GetWebSocket()->Open();
return behaviac::BT_SUCCESS;
auto co = std::make_shared<BtCoroutine>(context, co_id, "CoConnectBattleServer");
co->runing_cb =
[this, context] (BtCoroutine* co)
{
if (context->pending) {
return behaviac::BT_RUNNING;
}
return context->connect_ok ? behaviac::BT_SUCCESS : behaviac::BT_FAILURE;
};
return StartCoroutine(co);
}
behaviac::EBTStatus AndroidAgent::CoJoin()