Browse Source

LoadAfterRegister

fly 2 years ago
parent
commit
27f6e6789d
3 changed files with 39 additions and 5 deletions
  1. 5 0
      Service/IJsonRpcService.cs
  2. 10 5
      Service/JsonRpcService.cs
  3. 24 0
      Utilities/CryptionHelper.cs

+ 5 - 0
Service/IJsonRpcService.cs

@@ -7,5 +7,10 @@ namespace WingServerCommon.Service
         /// </summary>
         /// <param name="jsonRpcClientPool"></param>
          void Load(JsonRpcClientPool jsonRpcClientPool);
+
+         /// <summary>
+         /// LoadAfterRegister
+         /// </summary>
+         void LoadAfterRegister();
     }
 }

+ 10 - 5
Service/JsonRpcService.cs

@@ -11,9 +11,9 @@ namespace WingServerCommon.Service
         /// Release resource when disposing.
         /// </summary>
         protected virtual void Disposing()
-        {            
+        {
             _jsonRpcClientPool = null;
-        }     
+        }
 
         protected void Dispose(bool disposing)
         {
@@ -35,9 +35,9 @@ namespace WingServerCommon.Service
             _jsonRpcClientPool = jsonRpcClientPool;
         }
 
-        protected void ThrowRpcException(int code, string message, string internalMessage=null)
+        protected void ThrowRpcException(int code, string message, string internalMessage = null)
         {
-             throw new RpcException(code, message, internalMessage??message);
+            throw new RpcException(code, message, internalMessage ?? message);
         }
 
         protected T GetProxy<T>()
@@ -46,7 +46,7 @@ namespace WingServerCommon.Service
             if (client != null)
             {
                 var proxy = client.CreateProxy<T>();
-                if(proxy == null)
+                if (proxy == null)
                 {
                     throw new NotSupportedException($"Can not get proxy with type{typeof(T)} in rpc client");
                 }
@@ -56,5 +56,10 @@ namespace WingServerCommon.Service
 
             throw new NotSupportedException($"Can not get proxy with type{typeof(T)}");
         }
+
+        public virtual void LoadAfterRegister()
+        {
+
+        }
     }
 }

+ 24 - 0
Utilities/CryptionHelper.cs

@@ -157,6 +157,11 @@ namespace WingServerCommon.Utilities
                 }
                 byte[] outbyte = (byte[])outMessage.ToArray(Type.GetType("System.Byte"));
                 var result = Encoding.UTF8.GetString(outbyte);
+                if (!IsNotErrorCode(result))
+                {
+                    Logger.WriteLineWarn($"包含不正确的BASE64编码:" + text);
+                    return "";
+                }
                 return result;
             }
             catch (Exception ex)
@@ -240,6 +245,25 @@ namespace WingServerCommon.Utilities
             return false;
         }
 
+        /// <summary>
+        /// 是否正常字符串不含乱码
+        /// </summary>
+        /// <param name="str"></param>
+        /// <returns></returns>
+        public static bool IsNotErrorCode(string str)
+        {
+            char[] ch = str.ToCharArray();
+            for (int i = 0; i < ch.Length; ++i)
+            {
+                 //乱码
+                 if(ch[i]<7||(ch[i]>13&&ch[i]<26)||(ch[i]>27&&ch[i]<32)||ch[i]>65532)
+                 {
+                    return false;
+                 }
+            }
+            return true;
+        }
+
         /// <summary>
         ///姓名加密
         /// </summary>