예제 #1
0
        public void SERVER_API_join_match(IMessage msg, Action <object> cb)
        {
            var _msg = (JoinMatchReq)msg;

            this.JoinMatch(_msg.uid, _msg.match_type, (code) =>
            {
                var cbMsg  = new JoinMatchReq.Callback();
                cbMsg.code = code;
                cb.Invoke(cbMsg);
            });
        }
예제 #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);
        }