From a74ff63d8eb7d85b195e2a39caf06f8b5aeeb06f Mon Sep 17 00:00:00 2001 From: milimoe Date: Sat, 9 Sep 2023 21:24:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BFModelManager=E6=88=90=E4=B8=BA?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=B3=9B=E5=9E=8B=E7=9A=84=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Library/Common/Network/ServerSocket.cs | 6 +++--- Service/ModelManager.cs | 17 ++++++++--------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/Library/Common/Network/ServerSocket.cs b/Library/Common/Network/ServerSocket.cs index d73b70f..f4e5307 100644 --- a/Library/Common/Network/ServerSocket.cs +++ b/Library/Common/Network/ServerSocket.cs @@ -19,16 +19,16 @@ namespace Milimoe.FunGame.Core.Library.Common.Network public int ClientCount => OnlineClients.Count; public int BannedCount => BannedList.Count; - private readonly ModelManager OnlineClients; + private readonly ModelManager OnlineClients; private ServerSocket(System.Net.Sockets.Socket Instance, int ServerPort, int MaxConnection = 0) { this.Instance = Instance; this.ServerPort = ServerPort; if (MaxConnection <= 0) - OnlineClients = new ModelManager(); + OnlineClients = new(); else - OnlineClients = new ModelManager(MaxConnection); + OnlineClients = new(MaxConnection); } public static ServerSocket StartListening(int Port = 22222, int MaxConnection = 0) diff --git a/Service/ModelManager.cs b/Service/ModelManager.cs index bf15083..9656706 100644 --- a/Service/ModelManager.cs +++ b/Service/ModelManager.cs @@ -1,9 +1,8 @@ using System.Collections.Concurrent; -using Milimoe.FunGame.Core.Interface.Base; namespace Milimoe.FunGame.Core.Service { - internal class ModelManager + internal class ModelManager { /// /// 目前的Model数量 @@ -18,7 +17,7 @@ namespace Milimoe.FunGame.Core.Service /// /// 可参与高并发的字典,但添加效率较低 /// - private ConcurrentDictionary Models { get; } = new(); + private ConcurrentDictionary Models { get; } = new(); /// /// Init ModelManager @@ -39,7 +38,7 @@ namespace Milimoe.FunGame.Core.Service /// /// Model的Key /// Model对象 - internal IServerModel this[string name] => Models[name]; + internal T this[string name] => Models[name]; /// /// 向Model管理器中添加Model @@ -47,7 +46,7 @@ namespace Milimoe.FunGame.Core.Service /// Model的Key /// Model对象 /// True:操作成功 - internal bool Add(string name, IServerModel t) + internal bool Add(string name, T t) { if (Models.Count + 1 > MaxModel) return false; return Models.TryAdd(name, t); @@ -69,7 +68,7 @@ namespace Milimoe.FunGame.Core.Service /// Model的Key /// Model对象 /// 被移除的Model - internal bool Remove(string name, ref IServerModel? t) + internal bool Remove(string name, ref T? t) { return Models.TryRemove(name, out t); } @@ -79,9 +78,9 @@ namespace Milimoe.FunGame.Core.Service /// /// Model的Key /// 被移除的Model - internal IServerModel? RemoveAndGet(string name) + internal T? RemoveAndGet(string name) { - Models.TryRemove(name, out IServerModel? result); + Models.TryRemove(name, out T? result); return result; } @@ -102,7 +101,7 @@ namespace Milimoe.FunGame.Core.Service /// /// 获取Model对象的列表 /// - internal List GetList() + internal List GetList() { return Models.Values.ToList(); }