public void SERVER_API__Fenix__Host__register_client(IMessage msg, Action <IMessage> cb, RpcContext context) { var _msg = (__Fenix__Host__RegisterClientReq)msg; this.RegisterClient(_msg.hostId, _msg.hostName, (code, arg1) => { var cbMsg = new __Fenix__Host__RegisterClientReq.Callback(); cbMsg.code = code; cbMsg.arg1 = arg1; cb.Invoke(cbMsg); }, context); }
public async Task <__Fenix__Host__RegisterClientReq.Callback> RegisterClientAsync(global::System.UInt64 hostId, global::System.String hostName, global::System.Action <global::Fenix.Common.DefaultErrCode, global::Fenix.HostInfo> callback = null) { var t = new TaskCompletionSource <__Fenix__Host__RegisterClientReq.Callback>(); var toHostId = Global.IdManager.GetHostIdByActorId(this.toActorId, this.isClient); if (this.FromHostId == toHostId) { global::System.Action <global::Fenix.Common.DefaultErrCode, global::Fenix.HostInfo> _cb = (code, arg1) => { var cbMsg = new __Fenix__Host__RegisterClientReq.Callback(); cbMsg.code = code; cbMsg.arg1 = arg1; callback?.Invoke(cbMsg.code, cbMsg.arg1); t.TrySetResult(cbMsg); }; var protoCode = OpCode.REGISTER_CLIENT_REQ; if (protoCode < OpCode.CALL_ACTOR_METHOD) { var peer = Global.NetManager.GetPeerById(this.FromHostId, this.NetType); var context = new RpcContext(null, peer); Global.Host.CallMethodWithParams(protoCode, new object[] { hostId, hostName, _cb, context }); } else { Global.Host.GetActor(this.toActorId).CallMethodWithParams(protoCode, new object[] { hostId, hostName, _cb }); } } else { Action <__Fenix__Host__RegisterClientReq.Callback> _cb = (cbMsg) => { callback?.Invoke(cbMsg.code, cbMsg.arg1); t.TrySetResult(cbMsg); }; await Task.Run(() => { var msg = new __Fenix__Host__RegisterClientReq() { hostId = hostId, hostName = hostName }; var cb = new Action <byte[]>((cbData) => { var cbMsg = cbData == null ? new __Fenix__Host__RegisterClientReq.Callback() : global::Fenix.Common.Utils.RpcUtil.Deserialize <__Fenix__Host__RegisterClientReq.Callback>(cbData); _cb?.Invoke(cbMsg); }); this.CallRemoteMethod(OpCode.REGISTER_CLIENT_REQ, msg, cb); }); } return(await t.Task); }