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)); }
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); }
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)); }
private IRpcMethodInfo[] GetMatchingMethods(RpcRequestSignature requestSignature, IReadOnlyList <IRpcMethodInfo> methods) { IRpcMethodInfo[] methodsWithSameName = ArrayPool <IRpcMethodInfo> .Shared.Rent(methods.Count); try { //Case insenstive check for hybrid approach. Will check for case sensitive if there is ambiguity int methodsWithSameNameCount = 0; for (int i = 0; i < methods.Count; i++) { IRpcMethodInfo methodInfo = methods[i]; if (RpcUtil.NamesMatch(methodInfo.Name.AsSpan(), requestSignature.GetMethodName().Span)) { methodsWithSameName[methodsWithSameNameCount++] = methodInfo; } } if (methodsWithSameNameCount < 1) { return(Array.Empty <IRpcMethodInfo>()); } return(this.FilterBySimilarParams(requestSignature, methodsWithSameName.AsSpan(0, methodsWithSameNameCount))); } finally { ArrayPool <IRpcMethodInfo> .Shared.Return(methodsWithSameName, clearArray : false); } }
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); }); }
public void GetMatchingMethod_ListParam_Match_Snake_Case(string parameterNameCase) { DefaultRequestMatcher matcher = this.GetMatcher(); IEnumerable <KeyValuePair <string, RpcParameterType> > parameters = new[] { new KeyValuePair <string, RpcParameterType>(parameterNameCase, RpcParameterType.String) }; string methodName = nameof(MethodMatcherController.SnakeCaseParams); var requestSignature = RpcRequestSignature.Create(methodName, parameters); RpcMethodInfo methodInfo = matcher.GetMatchingMethod(requestSignature); Assert.NotNull(methodInfo); MethodInfo expectedMethodInfo = typeof(MethodMatcherController).GetMethod(methodName) !; Assert.Equal(expectedMethodInfo, methodInfo.MethodInfo); Assert.Single(methodInfo.Parameters); Assert.False(methodInfo.Parameters[0].IsOptional); Assert.Equal(typeof(string), methodInfo.Parameters[0].RawType); Assert.Equal(RpcParameterType.String, methodInfo.Parameters[0].Type); Assert.True(RpcUtil.NamesMatch(methodInfo.Parameters[0].Name, parameterNameCase)); }
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); }
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); }
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); }
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); }); }
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); }); }
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); }); }
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); }); }
public void ScanAssemblies(Assembly[] asmList) { //扫描一下 foreach (var asm in asmList) { foreach (var t in asm.GetTypes()) { if (RpcUtil.IsHeritedType(t, "Actor")) { RegisterType(t.Name, t); } } } foreach (var asm in asmList) { foreach (var t in asm.GetTypes()) { var refTypeAttrs = t.GetCustomAttributes(typeof(RefTypeAttribute)); if (refTypeAttrs.Count() > 0) { var rta = (RefTypeAttribute)refTypeAttrs.First(); //var rtaType = Global.TypeManager.Get(rta.TypeName); Global.TypeManager.RegisterRefType(t, rta.TypeName); } var msgTypeAttrs = t.GetCustomAttributes(typeof(MessageTypeAttribute)); if (msgTypeAttrs.Count() > 0) { var mta = (MessageTypeAttribute)msgTypeAttrs.First(); Global.TypeManager.RegisterMessageType(mta.ProtoCode, t); } } } }
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); }
private IRpcMethodInfo[] FilterMatchesByCaseSensitiveMethod(RpcRequestSignature requestSignature, Span <IRpcMethodInfo> matches) { //Try to remove ambiguity with case sensitive check IRpcMethodInfo[] caseSensitiveMatches = ArrayPool <IRpcMethodInfo> .Shared.Rent(matches.Length); try { int caseSensitiveCount = 0; for (int i = 0; i < matches.Length; i++) { IRpcMethodInfo m = matches[i]; Memory <char> requestMethodName = requestSignature.GetMethodName(); if (m.Name.Length == requestMethodName.Length) { if (!RpcUtil.NamesMatch(m.Name.AsSpan(), requestMethodName.Span)) { //TODO do we care about the case where 2+ parameters have very similar names and types? continue; } caseSensitiveMatches[caseSensitiveCount++] = m; } } return(caseSensitiveMatches.AsSpan(0, caseSensitiveCount).ToArray()); } finally { ArrayPool <IRpcMethodInfo> .Shared.Return(caseSensitiveMatches, clearArray : false); } }
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); }
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); }
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); }
public virtual void Pack() { Dictionary <string, byte[]> packData = new Dictionary <string, byte[]>(); packData["basic"] = RpcUtil.Serialize(this); foreach (var kv in this.mPersistentDic) { packData[kv.Key.Name] = RpcUtil.Serialize(kv.Value); } }
public static XDR Create(PortmapMapping mapping, bool set) { XDR request = new XDR(); int procedure = set ? RpcProgramPortmap.PmapprocSet : RpcProgramPortmap.PmapprocUnset; RpcCall call = RpcCall.GetInstance(RpcUtil.GetNewXid(RpcProgramPortmap.Program.ToString ()), RpcProgramPortmap.Program, RpcProgramPortmap.Version, procedure, new CredentialsNone (), new VerifierNone()); call.Write(request); return(mapping.Serialize(request)); }
public static void Init(Assembly[] asmList) { RpcUtil.Init(); #if !CLIENT CacheConfig.Init(); #endif Global.TypeManager.ScanAssemblies(asmList); Global.TypeManager.ScanAssemblies(new Assembly[] { typeof(Global).Assembly }); }
public static void Init(RuntimeConfig cfg, Assembly[] asmList) { RpcUtil.Init(); #if !CLIENT && USE_REDIS_IDMANAGER CacheConfig.Init(); #endif _cfg = cfg; Global.TypeManager.ScanAssemblies(asmList); Global.TypeManager.ScanAssemblies(new Assembly[] { typeof(Global).Assembly }); }
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); }
public void MatchMethodNamesCulturallyInvariantTest() { var previousCulture = System.Globalization.CultureInfo.CurrentCulture; // Switch to a locale that would result in lowercasing 'I' to // U+0131, if not done with invariant culture. System.Globalization.CultureInfo.CurrentCulture = new System.Globalization.CultureInfo("az"); var methodInfo = "IsLunchTime"; var requestMethodName = "isLunchtIme"; Assert.True(RpcUtil.NamesMatch(methodInfo, requestMethodName)); System.Globalization.CultureInfo.CurrentCulture = previousCulture; }
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); }
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)); }
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); }
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)); }
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)); }