From c66b25c21db7f71016543900a1d80507e38004d1 Mon Sep 17 00:00:00 2001 From: yeziuku <53083103+yeziuku@users.noreply.github.com> Date: Sat, 9 Dec 2023 17:03:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E7=9A=84AddonController=E6=9E=84?= =?UTF-8?q?=E9=80=A0=E6=96=B9=E6=B3=95=20(#32)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FunGame.Server/Main.cs | 10 ++++++++-- FunGame.Server/Models/ServerModel.cs | 2 +- FunGame.Server/Utilities/General.cs | 6 +++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/FunGame.Server/Main.cs b/FunGame.Server/Main.cs index c72fdc9..f0e20cb 100644 --- a/FunGame.Server/Main.cs +++ b/FunGame.Server/Main.cs @@ -1,4 +1,5 @@ -using Milimoe.FunGame; +using System.Collections; +using Milimoe.FunGame; using Milimoe.FunGame.Core.Api.Utility; using Milimoe.FunGame.Core.Library.Common.Addon; using Milimoe.FunGame.Core.Library.Common.Network; @@ -156,7 +157,12 @@ bool GetGameModeList() { // 同时读取Implement预设的模组和gamemods目录下的模组,最后合成一个总的列表 List supported = []; - Config.GameModeLoader = GameModeLoader.LoadGameModes(Config.FunGameType, [new Action(msg => ServerHelper.WriteLine(msg, InvokeMessageType.GameMode))]); + // 构建AddonController + Hashtable delegates = []; + delegates.Add("WriteLine", new Action(msg => ServerHelper.WriteLine(msg, InvokeMessageType.GameMode))); + delegates.Add("Error", new Action(ServerHelper.Error)); + // 开始读取 + Config.GameModeLoader = GameModeLoader.LoadGameModes(Config.FunGameType, delegates); string[] mods = (string[]?)Implement.GetFunGameImplValue(InterfaceType.IServer, InterfaceMethod.GameModeList, false) ?? []; if (mods.Length > 0) { diff --git a/FunGame.Server/Models/ServerModel.cs b/FunGame.Server/Models/ServerModel.cs index 89086c9..d1feeb1 100644 --- a/FunGame.Server/Models/ServerModel.cs +++ b/FunGame.Server/Models/ServerModel.cs @@ -387,7 +387,7 @@ namespace Milimoe.FunGame.Server.Model { NowGamingServer = Config.GameModeLoader.GetServerMode(room.GameMode); Dictionary others = Server.UserList.Cast().Where(model => usernames.Contains(model.User.Username) && model.User.Username != UserName).ToDictionary(k => k.User.Username, v => v); - if (NowGamingServer.StartServer(room.GameMode, room, users, this, others, new Action(msg => ServerHelper.WriteLine(msg)))) + if (NowGamingServer.StartServer(room.GameMode, room, users, this, others)) { foreach (ServerModel serverTask in Server.UserList.Cast().Where(model => usernames.Contains(model.User.Username))) { diff --git a/FunGame.Server/Utilities/General.cs b/FunGame.Server/Utilities/General.cs index f417584..4807d85 100644 --- a/FunGame.Server/Utilities/General.cs +++ b/FunGame.Server/Utilities/General.cs @@ -11,11 +11,11 @@ namespace Milimoe.FunGame.Server.Utility { public static string GetPrefix(InvokeMessageType type) { - string prefix = ""; + string prefix; switch (type) { case InvokeMessageType.Core: - Console.ForegroundColor = ConsoleColor.Yellow; + Console.ForegroundColor = ConsoleColor.Cyan; prefix = "[Core] "; break; case InvokeMessageType.Error: @@ -31,7 +31,7 @@ namespace Milimoe.FunGame.Server.Utility prefix = "[Interface] "; break; case InvokeMessageType.DataRequest: - Console.ForegroundColor = ConsoleColor.Cyan; + Console.ForegroundColor = ConsoleColor.Green; prefix = "[DataRequest] "; break; case InvokeMessageType.Plugin: