优化服务器端指令头分类操作

This commit is contained in:
dathlin
2017-06-17 10:44:34 +08:00
parent ed8dc29129
commit a8aad0b3dc
2 changed files with 38 additions and 4 deletions

View File

@@ -10,6 +10,14 @@ namespace CommonLibrary
/// </summary> /// </summary>
public class CommonHeadCode public class CommonHeadCode
{ {
/************************************************************************************************
*
* 注意您在准备二次开发时应该重新生成一个自己的GUID码
*
**************************************************************************************************/
/// <summary> /// <summary>
/// 用于同步和异步的网络的身份令牌,提升安全性 /// 用于同步和异步的网络的身份令牌,提升安全性
/// </summary> /// </summary>
@@ -23,6 +31,15 @@ namespace CommonLibrary
[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Auto)] [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Auto)]
public class SimplifyHeadCode public class SimplifyHeadCode
{ {
/// <summary>
/// 判断指令否是系统指令
/// </summary>
/// <param name="customer">指令</param>
/// <returns>是否符合</returns>
public static bool IsCustomerGroupSystem(int customer)
{
return (customer >= 10000 && customer < 11000);
}
public static int { get; } = 10000;//10000开始的表明是系统相关的 public static int { get; } = 10000;//10000开始的表明是系统相关的
public static int { get; } = 10001; public static int { get; } = 10001;
public static int { get; } = 10002; public static int { get; } = 10002;
@@ -38,7 +55,15 @@ namespace CommonLibrary
/// <summary>
/// 判断指令否是日志相关指令
/// </summary>
/// <param name="customer">指令</param>
/// <returns>是否符合</returns>
public static bool IsCustomerGroupLogging(int customer)
{
return (customer >= 11000 && customer < 12000);
}
public static int { get; } = 11000;//11000开头的是日志请求和清空 public static int { get; } = 11000;//11000开头的是日志请求和清空
public static int { get; } = 11001; public static int { get; } = 11001;
public static int { get; } = 11002; public static int { get; } = 11002;
@@ -66,6 +91,15 @@ namespace CommonLibrary
/// </summary> /// </summary>
public class MultiNetHeadCode public class MultiNetHeadCode
{ {
/// <summary>
///
/// </summary>
/// <param name="customer">指令</param>
/// <returns>是否符合</returns>
public static bool IsCustomerGroupSystem(int customer)
{
return (customer >= 50000 && customer < 51000);
}
public static int 线 { get; } = 50000; public static int 线 { get; } = 50000;
public static int { get; } = 50001; public static int { get; } = 50001;
public static int { get; } = 50002; public static int { get; } = 50002;

View File

@@ -335,11 +335,11 @@ namespace 软件系统服务端模版
private void Net_simplify_server_ReceiveStringEvent(AsyncStateOne state, int customer, string data) private void Net_simplify_server_ReceiveStringEvent(AsyncStateOne state, int customer, string data)
{ {
//必须返回结果调用SendMessage(object1,[实际数据]); //必须返回结果调用SendMessage(object1,[实际数据]);
if (customer < 11000) if (CommonHeadCode.SimplifyHeadCode.IsCustomerGroupSystem(customer))
{ {
DataProcessingWithStartA(state, customer, data); DataProcessingWithStartA(state, customer, data);
} }
else if (customer < 12000) else if (CommonHeadCode.SimplifyHeadCode.IsCustomerGroupLogging(customer))
{ {
DataProcessingWithStartB(state, customer, data); DataProcessingWithStartB(state, customer, data);
} }
@@ -604,7 +604,7 @@ namespace 软件系统服务端模版
private void Net_socket_server_AcceptString(AsyncStateOne object1, int customer, string data) private void Net_socket_server_AcceptString(AsyncStateOne object1, int customer, string data)
{ {
//如果此处充斥大量if语句影响观感则考虑进行指令头分类操作客户端异步发送的字符串都会到此处处理 //如果此处充斥大量if语句影响观感则考虑进行指令头分类操作客户端异步发送的字符串都会到此处处理
if (50000 <= customer && customer < 51000) if (CommonHeadCode.MultiNetHeadCode.IsCustomerGroupSystem(customer))
{ {
//H类系统指令 //H类系统指令
DataProcessingWithStartH(object1, customer, data); DataProcessingWithStartH(object1, customer, data);