diff --git a/FunGame.Core/Interface/Base/ISocket.cs b/FunGame.Core/Interface/Base/ISocket.cs
index 77f2cd6..ff63a2e 100644
--- a/FunGame.Core/Interface/Base/ISocket.cs
+++ b/FunGame.Core/Interface/Base/ISocket.cs
@@ -6,7 +6,7 @@ namespace Milimoe.FunGame.Core.Interface.Base
{
public System.Net.Sockets.Socket Instance { get; }
public int Runtime { get; }
- public string Token { get; }
+ public Guid Token { get; }
public string ServerIP { get; }
public int ServerPort { get; }
public string ServerName { get; }
diff --git a/FunGame.Core/Library/Common/Network/ClientSocket.cs b/FunGame.Core/Library/Common/Network/ClientSocket.cs
index d3d91b0..c5b704d 100644
--- a/FunGame.Core/Library/Common/Network/ClientSocket.cs
+++ b/FunGame.Core/Library/Common/Network/ClientSocket.cs
@@ -8,33 +8,15 @@ namespace Milimoe.FunGame.Core.Library.Common.Network
{
public System.Net.Sockets.Socket Instance { get; }
public int Runtime { get; } = (int)SocketRuntimeType.Server;
- public string Token { get; } = "";
+ public Guid Token { get; } = Guid.Empty;
public string ServerIP { get; } = "";
public int ServerPort { get; } = 0;
public string ServerName { get; } = "";
public string ServerNotice { get; } = "";
public string ClientIP { get; } = "";
- public string ClientName
- {
- get
- {
- return _ClientName;
- }
- }
- public bool Connected
- {
- get
- {
- return Instance != null && Instance.Connected;
- }
- }
- public bool Receiving
- {
- get
- {
- return _Receiving;
- }
- }
+ public string ClientName => _ClientName;
+ public bool Connected => Instance != null && Instance.Connected;
+ public bool Receiving => _Receiving;
private Task? ReceivingTask;
@@ -58,7 +40,7 @@ namespace Milimoe.FunGame.Core.Library.Common.Network
public object[] Receive()
{
object[] result = SocketManager.Receive(Instance);
- if (result.Length != 2) throw new SocketWrongInfoException();
+ if (result.Length != 3) throw new SocketWrongInfoException();
return result;
}
diff --git a/FunGame.Core/Library/Common/Network/JsonObject.cs b/FunGame.Core/Library/Common/Network/JsonObject.cs
index 4eb15a8..d94587c 100644
--- a/FunGame.Core/Library/Common/Network/JsonObject.cs
+++ b/FunGame.Core/Library/Common/Network/JsonObject.cs
@@ -8,12 +8,12 @@ namespace Milimoe.FunGame.Core.Library.Common.Network
public class JsonObject
{
public SocketMessageType MessageType { get; } = SocketMessageType.Unknown;
- public string Token { get; }
+ public Guid Token { get; }
public object[] Parameters { get; }
public string JsonString { get; }
[JsonConstructor]
- public JsonObject(SocketMessageType MessageType, string Token, object[] Parameters)
+ public JsonObject(SocketMessageType MessageType, Guid Token, object[] Parameters)
{
this.MessageType = MessageType;
this.Token = Token;
@@ -21,7 +21,7 @@ namespace Milimoe.FunGame.Core.Library.Common.Network
this.JsonString = JsonSerializer.Serialize(this);
}
- public static string GetString(SocketMessageType MessageType, string Token, object[] Parameters)
+ public static string GetString(SocketMessageType MessageType, Guid Token, object[] Parameters)
{
return new JsonObject(MessageType, Token, Parameters).JsonString;
}
diff --git a/FunGame.Core/Library/Common/Network/ServerSocket.cs b/FunGame.Core/Library/Common/Network/ServerSocket.cs
index 9aa828d..d05f3a7 100644
--- a/FunGame.Core/Library/Common/Network/ServerSocket.cs
+++ b/FunGame.Core/Library/Common/Network/ServerSocket.cs
@@ -9,25 +9,13 @@ namespace Milimoe.FunGame.Core.Library.Common.Network
{
public System.Net.Sockets.Socket Instance { get; }
public int Runtime { get; } = (int)SocketRuntimeType.Server;
- public string Token { get; } = "";
+ public Guid Token { get; } = Guid.Empty;
public string ServerIP { get; } = "";
public int ServerPort { get; } = 0;
public string ServerName { get; } = "";
public string ServerNotice { get; } = "";
- public bool Connected
- {
- get
- {
- return Instance != null && Instance.Connected;
- }
- }
- public bool Receiving
- {
- get
- {
- return _Receiving;
- }
- }
+ public bool Connected => Instance != null && Instance.Connected;
+ public bool Receiving => _Receiving;
private readonly ThreadManager PlayerThreads;
private bool _Receiving = false;
diff --git a/FunGame.Core/Library/Common/Network/Socket.cs b/FunGame.Core/Library/Common/Network/Socket.cs
index f250286..c5acd6c 100644
--- a/FunGame.Core/Library/Common/Network/Socket.cs
+++ b/FunGame.Core/Library/Common/Network/Socket.cs
@@ -8,39 +8,15 @@ namespace Milimoe.FunGame.Core.Library.Common.Network
{
public System.Net.Sockets.Socket Instance { get; }
public int Runtime { get; } = (int)SocketRuntimeType.Client;
- public string Token { get; set; } = "";
+ public Guid Token { get; set; } = Guid.Empty;
public string ServerIP { get; } = "";
public int ServerPort { get; } = 0;
public string ServerName { get; } = "";
public string ServerNotice { get; } = "";
- public int HeartBeatFaileds
- {
- get
- {
- return _HeartBeatFaileds;
- }
- }
- public bool Connected
- {
- get
- {
- return Instance != null && Instance.Connected;
- }
- }
- public bool Receiving
- {
- get
- {
- return _Receiving;
- }
- }
- public bool SendingHeartBeat
- {
- get
- {
- return _SendingHeartBeat;
- }
- }
+ public int HeartBeatFaileds => _HeartBeatFaileds;
+ public bool Connected => Instance != null && Instance.Connected;
+ public bool Receiving => _Receiving;
+ public bool SendingHeartBeat => _SendingHeartBeat;
private Task? SendingHeartBeatTask;
private Task? ReceivingTask;
diff --git a/FunGame.Core/Library/Constant/ConstantSet.cs b/FunGame.Core/Library/Constant/ConstantSet.cs
index 37283f5..aa1da29 100644
--- a/FunGame.Core/Library/Constant/ConstantSet.cs
+++ b/FunGame.Core/Library/Constant/ConstantSet.cs
@@ -32,6 +32,8 @@
public const string Logout = "Logout";
public const string Disconnect = "Disconnect";
public const string HeartBeat = "HeartBeat";
+ public const string IntoRoom = "IntoRoom";
+ public const string Chat = "Chat";
}
public class ReflectionSet
diff --git a/FunGame.Core/Library/Constant/TypeEnum.cs b/FunGame.Core/Library/Constant/TypeEnum.cs
index 27094d8..70d0c57 100644
--- a/FunGame.Core/Library/Constant/TypeEnum.cs
+++ b/FunGame.Core/Library/Constant/TypeEnum.cs
@@ -57,7 +57,9 @@
CheckLogin = 1 << 4,
Logout = 1 << 5,
Disconnect = 1 << 6,
- HeartBeat = 1 << 7
+ HeartBeat = 1 << 7,
+ IntoRoom = 1 << 8,
+ Chat = 1 << 9
}
public enum SocketRuntimeType
diff --git a/FunGame.Core/Library/Exception/Exception.cs b/FunGame.Core/Library/Exception/Exception.cs
index 0ea8df1..a3525c7 100644
--- a/FunGame.Core/Library/Exception/Exception.cs
+++ b/FunGame.Core/Library/Exception/Exception.cs
@@ -109,4 +109,9 @@
{
public override string Message => "执行SQL查询时遇到错误 (#10022)";
}
+
+ public class CanNotIntoRoomException : Exception
+ {
+ public override string Message => "无法加入指定房间 (#10023)";
+ }
}
diff --git a/FunGame.Core/Service/SocketManager.cs b/FunGame.Core/Service/SocketManager.cs
index 4046822..b367099 100644
--- a/FunGame.Core/Service/SocketManager.cs
+++ b/FunGame.Core/Service/SocketManager.cs
@@ -110,7 +110,7 @@ namespace Milimoe.FunGame.Core.Service
/// 通信类型
/// 参数
/// 通信结果
- internal static SocketResult Send(Socket ClientSocket, SocketMessageType type, string token, object[] objs)
+ internal static SocketResult Send(Socket ClientSocket, SocketMessageType type, Guid token, object[] objs)
{
if (ClientSocket != null && objs != null && objs.Length > 0)
{
@@ -129,7 +129,7 @@ namespace Milimoe.FunGame.Core.Service
/// 通信类型
/// 参数
/// 通信结果
- internal static SocketResult Send(SocketMessageType type, string token, object[] objs)
+ internal static SocketResult Send(SocketMessageType type, Guid token, object[] objs)
{
if (objs is null || objs.Length <= 0)
{
@@ -176,7 +176,7 @@ namespace Milimoe.FunGame.Core.Service
/// 用于服务器接收客户端信息
///
/// 客户端Socket
- /// 通信类型[0]和参数[1]
+ /// 通信类型[0]、Token[1]和参数[2]
internal static object[] Receive(Socket ClientSocket)
{
object[] result = Array.Empty