public void SERVER_API_create_account(IMessage msg, Action <object> cb) { var _msg = (CreateAccountReq)msg; this.CreateAccount(_msg.username, _msg.password, (code) => { var cbMsg = new CreateAccountReq.Callback(); cbMsg.code = code; cb.Invoke(cbMsg); }); }
public async Task <CreateAccountReq.Callback> rpc_create_account_async(global::System.String username, global::System.String password, global::System.Action <global::Shared.Protocol.ErrCode> callback = null) { var t = new TaskCompletionSource <CreateAccountReq.Callback>(); var toHostId = Global.IdManager.GetHostIdByActorId(this.toActorId, this.isClient); if (this.FromHostId == toHostId) { global::System.Action <global::Shared.Protocol.ErrCode> _cb = (code) => { var cbMsg = new CreateAccountReq.Callback(); cbMsg.code = code; callback?.Invoke(cbMsg.code); t.TrySetResult(cbMsg); }; var protoCode = ProtocolCode.CREATE_ACCOUNT_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[] { username, password, _cb, context }); } else { Global.Host.GetActor(this.toActorId).CallMethodWithParams(protoCode, new object[] { username, password, _cb }); } } else { Action <CreateAccountReq.Callback> _cb = (cbMsg) => { callback?.Invoke(cbMsg.code); t.TrySetResult(cbMsg); }; await Task.Run(() => { var msg = new CreateAccountReq() { username = username, password = password }; var cb = new Action <byte[]>((cbData) => { var cbMsg = cbData == null ? new CreateAccountReq.Callback() : RpcUtil.Deserialize <CreateAccountReq.Callback>(cbData); _cb?.Invoke(cbMsg); }); this.CallRemoteMethod(ProtocolCode.CREATE_ACCOUNT_REQ, msg, cb); }); } return(await t.Task); }