Ejemplo n.º 1
0
        public void rpc_join_match(String uid, Int32 match_type, Action <ErrCode> callback)
        {
            var toHostId = Global.IdManager.GetHostIdByActorId(this.toActorId, this.isClient);

            if (this.FromHostId == toHostId)
            {
                var protoCode = ProtocolCode.JOIN_MATCH_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[] { uid, match_type, callback, context });
                }
                else
                {
                    Global.Host.GetActor(this.toActorId).CallMethodWithParams(protoCode, new object[] { uid, match_type, callback });
                }
                return;
            }
            var msg = new JoinMatchReq()
            {
                uid        = uid,
                match_type = match_type
            };
            var cb = new Action <byte[]>((cbData) => {
                var cbMsg = cbData == null?new JoinMatchReq.Callback():RpcUtil.Deserialize <JoinMatchReq.Callback>(cbData);
                callback?.Invoke(cbMsg.code);
            });

            this.CallRemoteMethod(ProtocolCode.JOIN_MATCH_REQ, msg, cb);
        }
Ejemplo n.º 2
0
        public async Task <JoinMatchReq.Callback> rpc_join_match_async(global::System.String uid, global::System.Int32 match_type, global::System.Action <global::Shared.Protocol.ErrCode> callback = null)
        {
            var t        = new TaskCompletionSource <JoinMatchReq.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 JoinMatchReq.Callback();
                    cbMsg.code = code;
                    callback?.Invoke(cbMsg.code);
                    t.TrySetResult(cbMsg);
                };
                var protoCode = ProtocolCode.JOIN_MATCH_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[] { uid, match_type, _cb, context });
                }
                else
                {
                    Global.Host.GetActor(this.toActorId).CallMethodWithParams(protoCode, new object[] { uid, match_type, _cb });
                }
            }
            else
            {
                Action <JoinMatchReq.Callback> _cb = (cbMsg) =>
                {
                    callback?.Invoke(cbMsg.code);
                    t.TrySetResult(cbMsg);
                };
                await Task.Run(() => {
                    var msg = new JoinMatchReq()
                    {
                        uid        = uid,
                        match_type = match_type
                    };
                    var cb = new Action <byte[]>((cbData) => {
                        var cbMsg = cbData == null ? new JoinMatchReq.Callback() : RpcUtil.Deserialize <JoinMatchReq.Callback>(cbData);
                        _cb?.Invoke(cbMsg);
                    });
                    this.CallRemoteMethod(ProtocolCode.JOIN_MATCH_REQ, msg, cb);
                });
            }
            return(await t.Task);
        }