Esempio n. 1
0
        public void BindClientActor(String actorName, Action <DefaultErrCode> callback)
        {
            var toHostId = Global.IdManager.GetHostIdByActorId(this.toActorId, this.isClient);

            if (this.FromHostId == toHostId)
            {
                var protoCode = OpCode.BIND_CLIENT_ACTOR_REQ;
                if (protoCode < OpCode.CALL_ACTOR_METHOD)
                {
                    var peer    = NetManager.Instance.GetPeerById(this.FromHostId, this.NetType);
                    var context = new RpcContext(null, peer);
                    Global.Host.CallMethodWithParams(protoCode, new object[] { actorName, callback, context });
                }
                else
                {
                    Global.Host.GetActor(this.toActorId).CallMethodWithParams(protoCode, new object[] { actorName, callback });
                }
                return;
            }
            var msg = new BindClientActorReq()
            {
                actorName = actorName
            };
            var cb = new Action <byte[]>((cbData) => {
                var cbMsg = cbData == null?new BindClientActorReq.Callback():RpcUtil.Deserialize <BindClientActorReq.Callback>(cbData);
                callback?.Invoke(cbMsg.code);
            });

            this.CallRemoteMethod(OpCode.BIND_CLIENT_ACTOR_REQ, msg, cb);
        }
Esempio n. 2
0
        public async Task <T> GetAsync <T>(string key)
        {
            try
            {
                string redisKey = FormatKey(key);
                var    t        = typeof(T);
                if (t == typeof(IMessage) || t.IsSubclassOf(typeof(IMessage)))
                {
                    var _value = await this.client.StringGetAsync(redisKey);

                    if (_value.IsNull || !_value.HasValue)
                    {
                        return(default(T));
                    }
                    return((T)(object)RpcUtil.Deserialize(typeof(T), _value));
                }

                var value = await this.client.StringGetAsync(redisKey);

                if (value.IsNull || !value.HasValue)
                {
                    return(default(T));
                }
                return(JsonConvert.DeserializeObject <T>(value));
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
            return(default(T));
        }
Esempio n. 3
0
        public void rpc_change_name(String name, Action <ErrCode> callback)
        {
            var toHostId = Global.IdManager.GetHostIdByActorId(this.toActorId, this.isClient);

            if (this.FromHostId == toHostId)
            {
                var protoCode = ProtocolCode.CHANGE_NAME_REQ;
                if (protoCode < OpCode.CALL_ACTOR_METHOD)
                {
                    var peer    = NetManager.Instance.GetPeerById(this.FromHostId, this.NetType);
                    var context = new RpcContext(null, peer);
                    Global.Host.CallMethodWithParams(protoCode, new object[] { name, callback, context });
                }
                else
                {
                    Global.Host.GetActor(this.toActorId).CallMethodWithParams(protoCode, new object[] { name, callback });
                }
                return;
            }
            var msg = new ChangeNameReq()
            {
                name = name
            };
            var cb = new Action <byte[]>((cbData) => {
                var cbMsg = cbData == null?new ChangeNameReq.Callback():RpcUtil.Deserialize <ChangeNameReq.Callback>(cbData);
                callback?.Invoke(cbMsg.code);
            });

            this.CallRemoteMethod(ProtocolCode.CHANGE_NAME_REQ, msg, cb);
        }
Esempio n. 4
0
        public T Get <T>(string key)
        {
            try
            {
                string redisKey = FormatKey(key);
                var    t        = typeof(T);
                if (t == typeof(IMessage) || t.IsSubclassOf(typeof(IMessage)))
                {
                    var str = this.client.StringGet(redisKey);
                    if (str.IsNull || !str.HasValue)
                    {
                        return(default(T));
                    }
                    return((T)(object)RpcUtil.Deserialize(typeof(T), str));
                }

                string value = this.client.StringGet(redisKey);
                if (value == null)
                {
                    return(default(T));
                }
                return(JsonConvert.DeserializeObject <T>(value));
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }

            return(default(T));
        }
Esempio n. 5
0
        public void rpc_login(String username, String password, Action <ErrCode, String, UInt64, String, String> callback)
        {
            var toHostId = Global.IdManager.GetHostIdByActorId(this.toActorId, this.isClient);

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

            this.CallRemoteMethod(ProtocolCode.LOGIN_REQ, msg, cb);
        }
Esempio n. 6
0
        public void CreateActor(global::System.String typename, global::System.String name, global::System.Action <global::Fenix.Common.DefaultErrCode, global::System.String, global::System.UInt64> callback)
        {
            var toHostId = Global.IdManager.GetHostIdByActorId(this.toActorId, this.isClient);

            if (this.FromHostId == toHostId)
            {
                var protoCode = OpCode.CREATE_ACTOR_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[] { typename, name, callback, context });
                }
                else
                {
                    Global.Host.GetActor(this.toActorId).CallMethodWithParams(protoCode, new object[] { typename, name, callback });
                }
                return;
            }
            Task.Run(() => {
                var msg = new CreateActorReq()
                {
                    typename = typename,
                    name     = name
                };
                var cb = new Action <byte[]>((cbData) => {
                    var cbMsg = cbData == null?new CreateActorReq.Callback():RpcUtil.Deserialize <CreateActorReq.Callback>(cbData);
                    callback?.Invoke(cbMsg.code, cbMsg.arg1, cbMsg.arg2);
                });
                this.CallRemoteMethod(OpCode.CREATE_ACTOR_REQ, msg, cb);
            });
        }
Esempio n. 7
0
        public void RegisterClient(UInt64 hostId, String hostName, Action <DefaultErrCode, HostInfo> callback)
        {
            var toHostId = Global.IdManager.GetHostIdByActorId(this.toActorId, this.isClient);

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

            this.CallRemoteMethod(OpCode.REGISTER_CLIENT_REQ, msg, cb);
        }
Esempio n. 8
0
        public void client_on_api_test(String uid, Action <ErrCode> callback)
        {
            var toHostId = Global.IdManager.GetHostIdByActorId(this.toActorId, this.isClient);

            if (this.FromHostId == toHostId)
            {
                var protoCode = ProtocolCode.API_TEST_NTF;
                if (protoCode < OpCode.CALL_ACTOR_METHOD)
                {
                    var peer    = NetManager.Instance.GetPeerById(this.FromHostId, this.NetType);
                    var context = new RpcContext(null, peer);
                    Global.Host.CallMethodWithParams(protoCode, new object[] { uid, callback, context });
                }
                else
                {
                    Global.Host.GetActor(this.toActorId).CallMethodWithParams(protoCode, new object[] { uid, callback });
                }
                return;
            }
            var msg = new ApiTestNtf()
            {
                uid = uid
            };
            var cb = new Action <byte[]>((cbData) => {
                var cbMsg = cbData == null?new ApiTestNtf.Callback():RpcUtil.Deserialize <ApiTestNtf.Callback>(cbData);
                callback?.Invoke(cbMsg.code);
            });

            this.CallRemoteMethod(ProtocolCode.API_TEST_NTF, msg, cb);
        }
Esempio n. 9
0
        public void RemoveClientActor(global::System.UInt64 actorId, global::Fenix.Common.DisconnectReason reason, global::System.Action <global::Fenix.Common.DefaultErrCode> callback)
        {
            var toHostId = Global.IdManager.GetHostIdByActorId(this.toActorId, this.isClient);

            if (this.FromHostId == toHostId)
            {
                var protoCode = OpCode.REMOVE_CLIENT_ACTOR_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[] { actorId, reason, callback, context });
                }
                else
                {
                    Global.Host.GetActor(this.toActorId).CallMethodWithParams(protoCode, new object[] { actorId, reason, callback });
                }
                return;
            }
            Task.Run(() => {
                var msg = new RemoveClientActorReq()
                {
                    actorId = actorId,
                    reason  = reason
                };
                var cb = new Action <byte[]>((cbData) => {
                    var cbMsg = cbData == null?new RemoveClientActorReq.Callback():RpcUtil.Deserialize <RemoveClientActorReq.Callback>(cbData);
                    callback?.Invoke(cbMsg.code);
                });
                this.CallRemoteMethod(OpCode.REMOVE_CLIENT_ACTOR_REQ, msg, cb);
            });
        }
Esempio n. 10
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);
        }
Esempio n. 11
0
        public async Task <object> GetAsync(Type type, string key)
        {
            try
            {
                string redisKey = FormatKey(key);
                if (type == typeof(IMessage) || type.IsSubclassOf(typeof(IMessage)))
                {
                    var _value = await this.client.StringGetAsync(redisKey);

                    if (_value.IsNull || !_value.HasValue)
                    {
                        return(null);
                    }
                    return(RpcUtil.Deserialize(type, _value));
                }

                var value = await this.client.StringGetAsync(redisKey);

                if (value.IsNull || !value.HasValue)
                {
                    return(null);
                }
                return(JsonConvert.DeserializeObject(value, type));
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }

            return(null);
        }
Esempio n. 12
0
        public void rpc_create_account(global::System.String username, global::System.String password, global::System.Action <global::Shared.Protocol.ErrCode> callback)
        {
            var toHostId = Global.IdManager.GetHostIdByActorId(this.toActorId, this.isClient);

            if (this.FromHostId == toHostId)
            {
                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, callback, context });
                }
                else
                {
                    Global.Host.GetActor(this.toActorId).CallMethodWithParams(protoCode, new object[] { username, password, callback });
                }
                return;
            }
            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);
                    callback?.Invoke(cbMsg.code);
                });
                this.CallRemoteMethod(ProtocolCode.CREATE_ACCOUNT_REQ, msg, cb);
            });
        }
Esempio n. 13
0
        public void rpc_find_match(global::System.String uid, global::System.Action <global::Shared.Protocol.ErrCode, global::Server.DataModel.Account> callback)
        {
            var toHostId = Global.IdManager.GetHostIdByActorId(this.toActorId, this.isClient);

            if (this.FromHostId == toHostId)
            {
                var protoCode = ProtocolCode.FIND_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, callback, context });
                }
                else
                {
                    Global.Host.GetActor(this.toActorId).CallMethodWithParams(protoCode, new object[] { uid, callback });
                }
                return;
            }
            Task.Run(() => {
                var msg = new FindMatchReq()
                {
                    uid = uid
                };
                var cb = new Action <byte[]>((cbData) => {
                    var cbMsg = cbData == null?new FindMatchReq.Callback():RpcUtil.Deserialize <FindMatchReq.Callback>(cbData);
                    callback?.Invoke(cbMsg.code, cbMsg.user);
                });
                this.CallRemoteMethod(ProtocolCode.FIND_MATCH_REQ, msg, cb);
            });
        }
Esempio n. 14
0
        public void OnBeforeDisconnect(global::Fenix.Common.DisconnectReason reason, global::System.Action callback)
        {
            var toHostId = Global.IdManager.GetHostIdByActorId(this.toActorId, this.isClient);

            if (this.FromHostId == toHostId)
            {
                var protoCode = OpCode.ON_BEFORE_DISCONNECT_NTF;
                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[] { reason, callback, context });
                }
                else
                {
                    Global.Host.GetActor(this.toActorId).CallMethodWithParams(protoCode, new object[] { reason, callback });
                }
                return;
            }
            Task.Run(() => {
                var msg = new OnBeforeDisconnectNtf()
                {
                    reason = reason
                };
                var cb = new Action <byte[]>((cbData) => {
                    var cbMsg = cbData == null?new OnBeforeDisconnectNtf.Callback():RpcUtil.Deserialize <OnBeforeDisconnectNtf.Callback>(cbData);
                    callback?.Invoke();
                });
                this.CallRemoteMethod(OpCode.ON_BEFORE_DISCONNECT_NTF, msg, cb);
            });
        }
Esempio n. 15
0
        protected Actor CreateActorLocally(string typename, byte[] data)
        {
            var type = Global.TypeManager.Get(typename);
            var a    = (Actor)RpcUtil.Deserialize(type, data);

            this.ActivateActor(a);
            return(a);
        }
Esempio n. 16
0
        public async Task <LoginReq.Callback> rpc_login_async(global::System.String username, global::System.String password, global::System.Action <global::Shared.Protocol.ErrCode, global::System.String, global::System.UInt64, global::System.String, global::System.String> callback = null)
        {
            var t        = new TaskCompletionSource <LoginReq.Callback>();
            var toHostId = Global.IdManager.GetHostIdByActorId(this.toActorId, this.isClient);

            if (this.FromHostId == toHostId)
            {
                global::System.Action <global::Shared.Protocol.ErrCode, global::System.String, global::System.UInt64, global::System.String, global::System.String> _cb = (code, arg1, arg2, arg3, arg4) =>
                {
                    var cbMsg = new LoginReq.Callback();
                    cbMsg.code = code;
                    cbMsg.arg1 = arg1;
                    cbMsg.arg2 = arg2;
                    cbMsg.arg3 = arg3;
                    cbMsg.arg4 = arg4;
                    callback?.Invoke(cbMsg.code, cbMsg.arg1, cbMsg.arg2, cbMsg.arg3, cbMsg.arg4);
                    t.TrySetResult(cbMsg);
                };
                var protoCode = ProtocolCode.LOGIN_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 <LoginReq.Callback> _cb = (cbMsg) =>
                {
                    callback?.Invoke(cbMsg.code, cbMsg.arg1, cbMsg.arg2, cbMsg.arg3, cbMsg.arg4);
                    t.TrySetResult(cbMsg);
                };
                await Task.Run(() => {
                    var msg = new LoginReq()
                    {
                        username = username,
                        password = password
                    };
                    var cb = new Action <byte[]>((cbData) => {
                        var cbMsg = cbData == null ? new LoginReq.Callback() : RpcUtil.Deserialize <LoginReq.Callback>(cbData);
                        _cb?.Invoke(cbMsg);
                    });
                    this.CallRemoteMethod(ProtocolCode.LOGIN_REQ, msg, cb);
                });
            }
            return(await t.Task);
        }
Esempio n. 17
0
        public async Task <CreateActorReq.Callback> CreateActorAsync(global::System.String typename, global::System.String name, global::System.Action <global::Fenix.Common.DefaultErrCode, global::System.String, global::System.UInt64> callback = null)
        {
            var t        = new TaskCompletionSource <CreateActorReq.Callback>();
            var toHostId = Global.IdManager.GetHostIdByActorId(this.toActorId, this.isClient);

            if (this.FromHostId == toHostId)
            {
                global::System.Action <global::Fenix.Common.DefaultErrCode, global::System.String, global::System.UInt64> _cb = (code, arg1, arg2) =>
                {
                    var cbMsg = new CreateActorReq.Callback();
                    cbMsg.code = code;
                    cbMsg.arg1 = arg1;
                    cbMsg.arg2 = arg2;
                    callback?.Invoke(cbMsg.code, cbMsg.arg1, cbMsg.arg2);
                    t.TrySetResult(cbMsg);
                };
                var protoCode = OpCode.CREATE_ACTOR_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[] { typename, name, _cb, context });
                }
                else
                {
                    Global.Host.GetActor(this.toActorId).CallMethodWithParams(protoCode, new object[] { typename, name, _cb });
                }
            }
            else
            {
                Action <CreateActorReq.Callback> _cb = (cbMsg) =>
                {
                    callback?.Invoke(cbMsg.code, cbMsg.arg1, cbMsg.arg2);
                    t.TrySetResult(cbMsg);
                };
                await Task.Run(() => {
                    var msg = new CreateActorReq()
                    {
                        typename = typename,
                        name     = name
                    };
                    var cb = new Action <byte[]>((cbData) => {
                        var cbMsg = cbData == null ? new CreateActorReq.Callback() : RpcUtil.Deserialize <CreateActorReq.Callback>(cbData);
                        _cb?.Invoke(cbMsg);
                    });
                    this.CallRemoteMethod(OpCode.CREATE_ACTOR_REQ, msg, cb);
                });
            }
            return(await t.Task);
        }
Esempio n. 18
0
        public async Task <object> GetAsync(Type type, string key)
        {
            if (type == typeof(IMessage) || type.IsSubclassOf(typeof(IMessage)))
            {
                var bytes = await this.client.GetBytesAsync(key);

                if (bytes == null)
                {
                    return(null);
                }
                return(RpcUtil.Deserialize(type, bytes));
            }

            return(await this.client.GetAsync(key));
        }
Esempio n. 19
0
        public async Task <FindMatchReq.Callback> rpc_find_match_async(global::System.String uid, global::System.Action <global::Shared.Protocol.ErrCode, global::Server.DataModel.Account> callback = null)
        {
            var t        = new TaskCompletionSource <FindMatchReq.Callback>();
            var toHostId = Global.IdManager.GetHostIdByActorId(this.toActorId, this.isClient);

            if (this.FromHostId == toHostId)
            {
                global::System.Action <global::Shared.Protocol.ErrCode, global::Server.DataModel.Account> _cb = (code, user) =>
                {
                    var cbMsg = new FindMatchReq.Callback();
                    cbMsg.code = code;
                    cbMsg.user = user;
                    callback?.Invoke(cbMsg.code, cbMsg.user);
                    t.TrySetResult(cbMsg);
                };
                var protoCode = ProtocolCode.FIND_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, _cb, context });
                }
                else
                {
                    Global.Host.GetActor(this.toActorId).CallMethodWithParams(protoCode, new object[] { uid, _cb });
                }
            }
            else
            {
                Action <FindMatchReq.Callback> _cb = (cbMsg) =>
                {
                    callback?.Invoke(cbMsg.code, cbMsg.user);
                    t.TrySetResult(cbMsg);
                };
                await Task.Run(() => {
                    var msg = new FindMatchReq()
                    {
                        uid = uid
                    };
                    var cb = new Action <byte[]>((cbData) => {
                        var cbMsg = cbData == null ? new FindMatchReq.Callback() : RpcUtil.Deserialize <FindMatchReq.Callback>(cbData);
                        _cb?.Invoke(cbMsg);
                    });
                    this.CallRemoteMethod(ProtocolCode.FIND_MATCH_REQ, msg, cb);
                });
            }
            return(await t.Task);
        }
Esempio n. 20
0
        public T Get <T>(string key)
        {
            var t = typeof(T);

            if (t == typeof(IMessage) || t.IsSubclassOf(typeof(IMessage)))
            {
                var bytes = this.client.GetBytes(key);
                if (bytes == null)
                {
                    return(default(T));
                }
                return((T)(object)RpcUtil.Deserialize(typeof(T), bytes));
            }

            return(this.client.Get <T>(key));
        }
Esempio n. 21
0
        public T Get <T>(string key) where T : IMessage
        {
            var t = typeof(T);

            if (t == typeof(IMessage) || t.IsSubclassOf(typeof(IMessage)))
            {
                var bytes = this.client.GetBytes(key);
                if (bytes == null)
                {
                    return(null);
                }
                return(RpcUtil.Deserialize <T>(bytes));
            }

            return(this.client.Get <T>(key));
        }
Esempio n. 22
0
        public async Task <ApiTestNtf.Callback> client_on_api_test_async(global::System.String uid, global::System.Action <global::Shared.Protocol.ErrCode> callback = null)
        {
            var t        = new TaskCompletionSource <ApiTestNtf.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 ApiTestNtf.Callback();
                    cbMsg.code = code;
                    callback?.Invoke(cbMsg.code);
                    t.TrySetResult(cbMsg);
                };
                var protoCode = ProtocolCode.API_TEST_NTF;
                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, _cb, context });
                }
                else
                {
                    Global.Host.GetActor(this.toActorId).CallMethodWithParams(protoCode, new object[] { uid, _cb });
                }
            }
            else
            {
                Action <ApiTestNtf.Callback> _cb = (cbMsg) =>
                {
                    callback?.Invoke(cbMsg.code);
                    t.TrySetResult(cbMsg);
                };
                await Task.Run(() => {
                    var msg = new ApiTestNtf()
                    {
                        uid = uid
                    };
                    var cb = new Action <byte[]>((cbData) => {
                        var cbMsg = cbData == null ? new ApiTestNtf.Callback() : RpcUtil.Deserialize <ApiTestNtf.Callback>(cbData);
                        _cb?.Invoke(cbMsg);
                    });
                    this.CallRemoteMethod(ProtocolCode.API_TEST_NTF, msg, cb);
                });
            }
            return(await t.Task);
        }
Esempio n. 23
0
        public async Task <T> GetAsync <T>(string key)
        {
            var t = typeof(T);

            if (t == typeof(IMessage) || t.IsSubclassOf(typeof(IMessage)))
            {
                var bytes = await this.client.GetBytesAsync(key);

                if (bytes == null)
                {
                    return(default(T));
                }
                return((T)(object)RpcUtil.Deserialize(typeof(T), bytes));
            }

            return(await this.client.GetAsync <T>(key));
        }
Esempio n. 24
0
        public void ReconnectServerActor(global::System.UInt64 hostId, global::System.String hostName, global::System.String hostIP, global::System.Int32 hostPort, global::System.UInt64 actorId, global::System.String actorName, global::System.String aTypeName, global::System.Action <global::Fenix.Common.DefaultErrCode> callback)
        {
            var toHostId = Global.IdManager.GetHostIdByActorId(this.toActorId, this.isClient);

            if (this.FromHostId == toHostId)
            {
                var protoCode = OpCode.RECONNECT_SERVER_ACTOR_NTF;
                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, hostIP, hostPort, actorId, actorName, aTypeName, callback, context });
                }
                else
                {
                    Global.Host.GetActor(this.toActorId).CallMethodWithParams(protoCode, new object[] { hostId, hostName, hostIP, hostPort, actorId, actorName, aTypeName, callback });
                }
                return;
            }
            Task.Run(() => {
                var msg = new ReconnectServerActorNtf()
                {
                    hostId    = hostId,
                    hostName  = hostName,
                    hostIP    = hostIP,
                    hostPort  = hostPort,
                    actorId   = actorId,
                    actorName = actorName,
                    aTypeName = aTypeName
                };
                var cb = new Action <byte[]>((cbData) => {
                    var cbMsg = cbData == null?new ReconnectServerActorNtf.Callback():RpcUtil.Deserialize <ReconnectServerActorNtf.Callback>(cbData);
                    callback?.Invoke(cbMsg.code);
                });
                this.CallRemoteMethod(OpCode.RECONNECT_SERVER_ACTOR_NTF, msg, cb);
            });
        }
Esempio n. 25
0
        public async Task <OnBeforeDisconnectNtf.Callback> OnBeforeDisconnectAsync(global::Fenix.Common.DisconnectReason reason, global::System.Action callback = null)
        {
            var t        = new TaskCompletionSource <OnBeforeDisconnectNtf.Callback>();
            var toHostId = Global.IdManager.GetHostIdByActorId(this.toActorId, this.isClient);

            if (this.FromHostId == toHostId)
            {
                global::System.Action _cb = () =>
                {
                    var cbMsg = new OnBeforeDisconnectNtf.Callback();

                    callback?.Invoke();
                    t.TrySetResult(cbMsg);
                };
                var protoCode = OpCode.ON_BEFORE_DISCONNECT_NTF;
                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[] { reason, _cb, context });
                }
                else
                {
                    Global.Host.GetActor(this.toActorId).CallMethodWithParams(protoCode, new object[] { reason, _cb });
                }
            }
            else
            {
                Action <OnBeforeDisconnectNtf.Callback> _cb = (cbMsg) =>
                {
                    callback?.Invoke();
                    t.TrySetResult(cbMsg);
                };
                await Task.Run(() => {
                    var msg = new OnBeforeDisconnectNtf()
                    {
                        reason = reason
                    };
                    var cb = new Action <byte[]>((cbData) => {
                        var cbMsg = cbData == null ? new OnBeforeDisconnectNtf.Callback() : RpcUtil.Deserialize <OnBeforeDisconnectNtf.Callback>(cbData);
                        _cb?.Invoke(cbMsg);
                    });
                    this.CallRemoteMethod(OpCode.ON_BEFORE_DISCONNECT_NTF, msg, cb);
                });
            }
            return(await t.Task);
        }