修改加载项加载顺序

This commit is contained in:
milimoe 2025-01-18 15:56:41 +08:00
parent ccf75528cb
commit f10c24f978
Signed by: milimoe
GPG Key ID: 05D280912DA6C69E
4 changed files with 21 additions and 19 deletions

View File

@ -94,15 +94,15 @@ void StartServer()
// 初始化MailSender // 初始化MailSender
FunGameSystem.InitMailSender(); FunGameSystem.InitMailSender();
// 读取Server插件
FunGameSystem.GetServerPlugins();
// 读取游戏模组 // 读取游戏模组
if (!FunGameSystem.GetGameModuleList()) if (!FunGameSystem.GetGameModuleList())
{ {
ServerHelper.WriteLine("服务器似乎未安装任何游戏模组,请检查是否正确安装它们。"); ServerHelper.WriteLine("服务器似乎未安装任何游戏模组,请检查是否正确安装它们。");
} }
// 读取Server插件
FunGameSystem.GetServerPlugins();
ServerHelper.WriteLine("请输入 help 来获取帮助,按下 Ctrl+C 关闭服务器。"); ServerHelper.WriteLine("请输入 help 来获取帮助,按下 Ctrl+C 关闭服务器。");
ServerHelper.PrintFunGameTitle(); ServerHelper.PrintFunGameTitle();

View File

@ -113,7 +113,7 @@ namespace Milimoe.FunGame.Server.Others
if (check) if (check)
{ {
if (!module.IsAnonymous) supported.Add(module.Name); if (!module.IsAnonymous) supported.Add(module.Name);
ServerHelper.WriteLine("Loaded: " + module.Name, InvokeMessageType.GameModule); ServerHelper.WriteLine("GameModule Loaded -> " + module.Name, InvokeMessageType.Core);
} }
} }
catch (Exception e) catch (Exception e)
@ -146,7 +146,7 @@ namespace Milimoe.FunGame.Server.Others
Config.ServerPluginLoader = ServerPluginLoader.LoadPlugins(delegates); Config.ServerPluginLoader = ServerPluginLoader.LoadPlugins(delegates);
foreach (ServerPlugin plugin in Config.ServerPluginLoader.Plugins.Values) foreach (ServerPlugin plugin in Config.ServerPluginLoader.Plugins.Values)
{ {
ServerHelper.WriteLine("Loaded: " + plugin.Name, InvokeMessageType.Plugin); ServerHelper.WriteLine("Plugin Loaded -> " + plugin.Name, InvokeMessageType.Core);
} }
} }
catch (Exception e) catch (Exception e)
@ -158,7 +158,7 @@ namespace Milimoe.FunGame.Server.Others
/// <summary> /// <summary>
/// 加载 Web API 插件 /// 加载 Web API 插件
/// </summary> /// </summary>
public static void GetWebAPIPlugins() public static void GetWebAPIPlugins(params object[] otherobjs)
{ {
Dictionary<string, object> delegates = []; Dictionary<string, object> delegates = [];
delegates.Add("WriteLine", new Action<string, string, LogLevel, bool>((name, msg, level, useLevel) => ServerHelper.WriteLine_Addons(name, msg, InvokeMessageType.Plugin, level, useLevel))); delegates.Add("WriteLine", new Action<string, string, LogLevel, bool>((name, msg, level, useLevel) => ServerHelper.WriteLine_Addons(name, msg, InvokeMessageType.Plugin, level, useLevel)));
@ -166,10 +166,10 @@ namespace Milimoe.FunGame.Server.Others
try try
{ {
// 读取plugins目录下的插件 // 读取plugins目录下的插件
Config.WebAPIPluginLoader = WebAPIPluginLoader.LoadPlugins(delegates); Config.WebAPIPluginLoader = WebAPIPluginLoader.LoadPlugins(delegates, otherobjs);
foreach (WebAPIPlugin plugin in Config.WebAPIPluginLoader.Plugins.Values) foreach (WebAPIPlugin plugin in Config.WebAPIPluginLoader.Plugins.Values)
{ {
ServerHelper.WriteLine("Loaded: " + plugin.Name, InvokeMessageType.Plugin); ServerHelper.WriteLine("Plugin Loaded -> " + plugin.Name, InvokeMessageType.Core);
} }
} }
catch (Exception e) catch (Exception e)

View File

@ -55,18 +55,22 @@ try
// 初始化MailSender // 初始化MailSender
FunGameSystem.InitMailSender(); FunGameSystem.InitMailSender();
// 读取Server插件
FunGameSystem.GetServerPlugins();
// Add services to the container.
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
// 读取Web API插件
object[] otherobjs = [builder];
FunGameSystem.GetWebAPIPlugins(otherobjs);
// 读取游戏模组 // 读取游戏模组
if (!FunGameSystem.GetGameModuleList()) if (!FunGameSystem.GetGameModuleList())
{ {
ServerHelper.WriteLine("服务器似乎未安装任何游戏模组,请检查是否正确安装它们。"); ServerHelper.WriteLine("服务器似乎未安装任何游戏模组,请检查是否正确安装它们。");
} }
// 读取Server插件
FunGameSystem.GetServerPlugins();
// 读取Web API插件
FunGameSystem.GetWebAPIPlugins();
// 创建单例 // 创建单例
RESTfulAPIListener apiListener = new(); RESTfulAPIListener apiListener = new();
RESTfulAPIListener.Instance = apiListener; RESTfulAPIListener.Instance = apiListener;
@ -83,9 +87,6 @@ try
ServerHelper.WriteLine("正在启动 Web API 监听 . . ."); ServerHelper.WriteLine("正在启动 Web API 监听 . . .");
Console.WriteLine("\r "); Console.WriteLine("\r ");
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
// Add services to the container.
// 读取扩展控制器 // 读取扩展控制器
if (Config.WebAPIPluginLoader != null) if (Config.WebAPIPluginLoader != null)
{ {
@ -100,6 +101,7 @@ try
} }
} }
} }
// 添加 JSON 转换器 // 添加 JSON 转换器
builder.Services.AddControllers().AddJsonOptions(options => builder.Services.AddControllers().AddJsonOptions(options =>
{ {
@ -173,6 +175,7 @@ try
options.FormatterName = "CustomFormatter"; options.FormatterName = "CustomFormatter";
}); });
builder.Services.AddSingleton<ConsoleFormatter, CustomConsoleFormatter>(); builder.Services.AddSingleton<ConsoleFormatter, CustomConsoleFormatter>();
builder.Services.AddHttpClient();
WebApplication app = builder.Build(); WebApplication app = builder.Build();

View File

@ -27,8 +27,7 @@ namespace Milimoe.FunGame.WebAPI.Services
return logLevel switch return logLevel switch
{ {
LogLevel.Trace => "\x1b[37m", // 灰色 ConsoleColor.Gray LogLevel.Trace => "\x1b[37m", // 灰色 ConsoleColor.Gray
LogLevel.Debug => "\x1b[34m", // 蓝色 ConsoleColor.Blue LogLevel.Debug => "\x1b[32m", // 绿色 ConsoleColor.Green
LogLevel.Information => "\x1b[32m", // 绿色 ConsoleColor.Green
LogLevel.Warning => "\x1b[33m", // 黄色 ConsoleColor.Yellow LogLevel.Warning => "\x1b[33m", // 黄色 ConsoleColor.Yellow
LogLevel.Error => "\x1b[31m", // 红色 ConsoleColor.Red LogLevel.Error => "\x1b[31m", // 红色 ConsoleColor.Red
LogLevel.Critical => "\x1b[31m", // 红色 ConsoleColor.Red LogLevel.Critical => "\x1b[31m", // 红色 ConsoleColor.Red