From 5a63b97341e4858a10e7520701ed4e408a02e3e7 Mon Sep 17 00:00:00 2001
From: milimoe <110188673+milimoe@users.noreply.github.com>
Date: Wed, 28 Jun 2023 00:58:52 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Hashtable=E4=B8=ADJson?=
=?UTF-8?q?=E5=AF=B9=E8=B1=A1=E7=9A=84=E5=8F=8D=E5=BA=8F=E5=88=97=E5=8C=96?=
=?UTF-8?q?=E5=B7=A5=E5=85=B7=E6=96=B9=E6=B3=95=20(#36)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* 添加Hashtable中Json对象的反序列化工具方法
* ErrorType -> ErrorIPAddressType
* 新增房间状态:Matching
---
Api/Utility/General.cs | 37 +++++++++++++++++++++++------------
Library/Constant/StateEnum.cs | 3 ++-
Library/Constant/TypeEnum.cs | 2 +-
3 files changed, 28 insertions(+), 14 deletions(-)
diff --git a/Api/Utility/General.cs b/Api/Utility/General.cs
index 7b7851b..c7e7adc 100644
--- a/Api/Utility/General.cs
+++ b/Api/Utility/General.cs
@@ -1,4 +1,5 @@
-using System.Net.NetworkInformation;
+using System.Collections;
+using System.Net.NetworkInformation;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
using Milimoe.FunGame.Core.Library.Constant;
@@ -56,7 +57,7 @@ namespace Milimoe.FunGame.Core.Api.Utility
///
///
///
- public static ErrorType IsServerAddress(string str)
+ public static ErrorIPAddressType IsServerAddress(string str)
{
string[] strs = str.Split(':');
string ip;
@@ -71,11 +72,11 @@ namespace Milimoe.FunGame.Core.Api.Utility
ip = strs[0];
port = Convert.ToInt32(strs[1]);
}
- else return ErrorType.WrongFormat;
- if (IsIP(ip) && port > 0 && port < 65536) return ErrorType.None;
- else if (!IsIP(ip) && port > 0 && port < 65536) return ErrorType.IsNotIP;
- else if (IsIP(ip) && (port <= 0 || port >= 65536)) return ErrorType.IsNotPort;
- else return ErrorType.WrongFormat;
+ else return ErrorIPAddressType.WrongFormat;
+ if (IsIP(ip) && port > 0 && port < 65536) return ErrorIPAddressType.None;
+ else if (!IsIP(ip) && port > 0 && port < 65536) return ErrorIPAddressType.IsNotIP;
+ else if (IsIP(ip) && (port <= 0 || port >= 65536)) return ErrorIPAddressType.IsNotPort;
+ else return ErrorIPAddressType.WrongFormat;
}
///
@@ -84,12 +85,12 @@ namespace Milimoe.FunGame.Core.Api.Utility
///
///
///
- public static ErrorType IsServerAddress(string ip, int port)
+ public static ErrorIPAddressType IsServerAddress(string ip, int port)
{
- if (IsIP(ip) && port > 0 && port < 65536) return ErrorType.None;
- else if (!IsIP(ip) && port > 0 && port < 65536) return ErrorType.IsNotIP;
- else if (IsIP(ip) && (port <= 0 || port >= 65536)) return ErrorType.IsNotPort;
- else return ErrorType.WrongFormat;
+ if (IsIP(ip) && port > 0 && port < 65536) return ErrorIPAddressType.None;
+ else if (!IsIP(ip) && port > 0 && port < 65536) return ErrorIPAddressType.IsNotIP;
+ else if (IsIP(ip) && (port <= 0 || port >= 65536)) return ErrorIPAddressType.IsNotPort;
+ else return ErrorIPAddressType.WrongFormat;
}
///
@@ -136,6 +137,18 @@ namespace Milimoe.FunGame.Core.Api.Utility
{
return Service.JsonManager.GetObject(json);
}
+
+ ///
+ /// 反序列化Hashtable中的Json对象
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static T? JsonDeserializeFromHashtable(Hashtable hashtable, string key)
+ {
+ return Service.JsonManager.GetObject(hashtable, key);
+ }
}
#endregion
diff --git a/Library/Constant/StateEnum.cs b/Library/Constant/StateEnum.cs
index 347d116..5078d64 100644
--- a/Library/Constant/StateEnum.cs
+++ b/Library/Constant/StateEnum.cs
@@ -11,8 +11,9 @@
public enum RoomState
{
Created,
+ Closed,
+ Matching,
Gaming,
- Close,
Complete
}
diff --git a/Library/Constant/TypeEnum.cs b/Library/Constant/TypeEnum.cs
index 136e86c..4450c5b 100644
--- a/Library/Constant/TypeEnum.cs
+++ b/Library/Constant/TypeEnum.cs
@@ -95,7 +95,7 @@
Server
}
- public enum ErrorType
+ public enum ErrorIPAddressType
{
None,
IsNotIP,