diff --git a/FunGame.Core/Interface/Base/ISocket.cs b/FunGame.Core/Interface/Base/ISocket.cs
index 7f4c775..93f93df 100644
--- a/FunGame.Core/Interface/Base/ISocket.cs
+++ b/FunGame.Core/Interface/Base/ISocket.cs
@@ -12,11 +12,11 @@ namespace Milimoe.FunGame.Core.Interface.Base
{
public System.Net.Sockets.Socket Instance { get; }
public int Runtime { get; }
+ public string Token { get; }
public string ServerIP { get; }
public int ServerPort { get; }
public string ServerName { get; }
public string ServerNotice { get; }
- public int HeartBeatFaileds { get; }
public bool Connected
{
get
@@ -25,7 +25,6 @@ namespace Milimoe.FunGame.Core.Interface.Base
}
}
public bool Receiving { get; }
- public bool SendingHeartBeat { get; }
public SocketResult Send(SocketMessageType type, params object[] objs);
public object[] Receive();
public void Close();
diff --git a/FunGame.Core/Interface/Base/ISocketHeartBeat.cs b/FunGame.Core/Interface/Base/ISocketHeartBeat.cs
new file mode 100644
index 0000000..67cb35f
--- /dev/null
+++ b/FunGame.Core/Interface/Base/ISocketHeartBeat.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Milimoe.FunGame.Core.Interface.Base
+{
+ public interface ISocketHeartBeat
+ {
+ public int HeartBeatFaileds { get; }
+ public bool SendingHeartBeat { get; }
+ }
+}
diff --git a/FunGame.Core/Library/Common/Network/ClientSocket.cs b/FunGame.Core/Library/Common/Network/ClientSocket.cs
index b617695..f0cbe44 100644
--- a/FunGame.Core/Library/Common/Network/ClientSocket.cs
+++ b/FunGame.Core/Library/Common/Network/ClientSocket.cs
@@ -13,13 +13,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 string ServerIP { get; } = "";
public int ServerPort { get; } = 0;
public string ServerName { get; } = "";
public string ServerNotice { get; } = "";
public string ClientIP { get; } = "";
public string ClientName { get; private set; } = "";
- public int HeartBeatFaileds { get; private set; } = 0;
public bool Connected
{
get
@@ -28,7 +28,6 @@ namespace Milimoe.FunGame.Core.Library.Common.Network
}
}
public bool Receiving { get; private set; } = false;
- public bool SendingHeartBeat { get; private set; } = false;
private Task? ReceivingTask;
@@ -57,7 +56,7 @@ namespace Milimoe.FunGame.Core.Library.Common.Network
{
if (Instance != null)
{
- if (SocketManager.Send(Instance, type, objs) == SocketResult.Success)
+ if (SocketManager.Send(Instance, type, Token, objs) == SocketResult.Success)
{
return SocketResult.Success;
}
diff --git a/FunGame.Core/Library/Common/Network/JsonObject.cs b/FunGame.Core/Library/Common/Network/JsonObject.cs
index 1c8ce9b..0a3b43a 100644
--- a/FunGame.Core/Library/Common/Network/JsonObject.cs
+++ b/FunGame.Core/Library/Common/Network/JsonObject.cs
@@ -12,19 +12,21 @@ namespace Milimoe.FunGame.Core.Library.Common.Network
internal class JsonObject
{
internal SocketMessageType MessageType { get; } = SocketMessageType.Unknown;
+ internal string Token { get; }
internal object[] Parameters { get; }
internal string JsonString { get; }
- internal JsonObject(SocketMessageType MessageType, object[] Parameters)
+ internal JsonObject(SocketMessageType MessageType, string Token, object[] Parameters)
{
this.MessageType = MessageType;
+ this.Token = Token;
this.Parameters = Parameters;
this.JsonString = JsonSerializer.Serialize(this);
}
- internal static string GetString(SocketMessageType MessageType, object[] Parameters)
+ internal static string GetString(SocketMessageType MessageType, string Token, object[] Parameters)
{
- return new JsonObject(MessageType, Parameters).JsonString;
+ return new JsonObject(MessageType, Token, Parameters).JsonString;
}
internal static JsonObject? GetObject(string JsonString)
diff --git a/FunGame.Core/Library/Common/Network/ServerSocket.cs b/FunGame.Core/Library/Common/Network/ServerSocket.cs
index e0df93e..ae1a158 100644
--- a/FunGame.Core/Library/Common/Network/ServerSocket.cs
+++ b/FunGame.Core/Library/Common/Network/ServerSocket.cs
@@ -14,11 +14,11 @@ 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 string ServerIP { get; } = "";
public int ServerPort { get; } = 0;
public string ServerName { get; } = "";
public string ServerNotice { get; } = "";
- public int HeartBeatFaileds { get; private set; } = 0;
public bool Connected
{
get
@@ -27,7 +27,6 @@ namespace Milimoe.FunGame.Core.Library.Common.Network
}
}
public bool Receiving { get; private set; } = false;
- public bool SendingHeartBeat { get; private set; } = false;
private readonly ThreadManager PlayerThreads;
diff --git a/FunGame.Core/Library/Common/Network/Socket.cs b/FunGame.Core/Library/Common/Network/Socket.cs
index a160f15..67854ab 100644
--- a/FunGame.Core/Library/Common/Network/Socket.cs
+++ b/FunGame.Core/Library/Common/Network/Socket.cs
@@ -5,6 +5,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Net.Sockets;
using System.Net;
+using System.Security.Cryptography;
using Milimoe.FunGame.Core.Interface;
using Milimoe.FunGame.Core.Service;
using Milimoe.FunGame.Core.Library.Constant;
@@ -12,10 +13,11 @@ using Milimoe.FunGame.Core.Interface.Base;
namespace Milimoe.FunGame.Core.Library.Common.Network
{
- public class Socket : ISocket
+ public class Socket : ISocket, ISocketHeartBeat
{
public System.Net.Sockets.Socket Instance { get; }
public int Runtime { get; } = (int)SocketRuntimeType.Client;
+ public string Token { get; set; } = "";
public string ServerIP { get; } = "";
public int ServerPort { get; } = 0;
public string ServerName { get; } = "";
@@ -54,11 +56,11 @@ namespace Milimoe.FunGame.Core.Library.Common.Network
{
if (Instance != null)
{
- if (SocketManager.Send(type, objs) == SocketResult.Success)
+ if (SocketManager.Send(type, Token, objs) == SocketResult.Success)
{
return SocketResult.Success;
}
- else return SocketResult.Fail;
+ return SocketResult.Fail;
}
return SocketResult.NotSent;
}
diff --git a/FunGame.Core/Service/SocketManager.cs b/FunGame.Core/Service/SocketManager.cs
index c53a798..cbe734f 100644
--- a/FunGame.Core/Service/SocketManager.cs
+++ b/FunGame.Core/Service/SocketManager.cs
@@ -115,11 +115,11 @@ namespace Milimoe.FunGame.Core.Service
/// 通信类型
/// 参数
/// 通信结果
- internal static SocketResult Send(Socket ClientSocket, SocketMessageType type, object[] objs)
+ internal static SocketResult Send(Socket ClientSocket, SocketMessageType type, string token, object[] objs)
{
if (ClientSocket != null && objs != null && objs.Length > 0)
{
- if (ClientSocket.Send(General.DEFAULT_ENCODING.GetBytes(Library.Common.Network.JsonObject.GetString(type, objs))) > 0)
+ if (ClientSocket.Send(General.DEFAULT_ENCODING.GetBytes(Library.Common.Network.JsonObject.GetString(type, token, objs))) > 0)
{
return SocketResult.Success;
}
@@ -134,7 +134,7 @@ namespace Milimoe.FunGame.Core.Service
/// 通信类型
/// 参数
/// 通信结果
- internal static SocketResult Send(SocketMessageType type, object[] objs)
+ internal static SocketResult Send(SocketMessageType type, string token, object[] objs)
{
if (objs is null || objs.Length <= 0)
{
@@ -142,7 +142,7 @@ namespace Milimoe.FunGame.Core.Service
}
if (Socket != null)
{
- if (Socket.Send(General.DEFAULT_ENCODING.GetBytes(Library.Common.Network.JsonObject.GetString(type, objs))) > 0)
+ if (Socket.Send(General.DEFAULT_ENCODING.GetBytes(Library.Common.Network.JsonObject.GetString(type, token, objs))) > 0)
{
return SocketResult.Success;
}
diff --git a/FunGame.Desktop/Model/MainModel.cs b/FunGame.Desktop/Model/MainModel.cs
index 3e9330d..b9ab94c 100644
--- a/FunGame.Desktop/Model/MainModel.cs
+++ b/FunGame.Desktop/Model/MainModel.cs
@@ -279,6 +279,8 @@ namespace Milimoe.FunGame.Desktop.Model
string ServerNotice = strings[1];
Config.FunGame_ServerName = ServerName;
Config.FunGame_Notice = ServerNotice;
+ if (objs.Length > 1) msg = (string)objs[1];
+ Socket!!.Token = msg;
Main?.GetMessage($"已连接服务器:{ServerName}。\n\n********** 服务器公告 **********\n\n{ServerNotice}\n\n");
// 设置等待登录的黄灯
Main?.UpdateUI(MainControllerSet.WaitLoginAndSetYellow);