From b232088f4d835038f99760191d1d2b2ba5a5e842 Mon Sep 17 00:00:00 2001 From: rfi Date: Thu, 22 Feb 2024 00:25:19 +0700 Subject: [PATCH] renames --- BLHX.Server.Game/Commands/Command.cs | 12 ++++++------ BLHX.Server.Game/Commands/HelpCommand.cs | 8 ++++---- BLHX.Server.Game/Commands/SaveCommand.cs | 2 +- BLHX.Server.Game/Commands/TestCommand.cs | 2 +- BLHX.Server.Game/Connection.cs | 2 +- BLHX.Server.Game/GameServer.cs | 2 +- BLHX.Server.Game/InputSystem.cs | 2 +- BLHX.Server.Game/Packet.cs | 6 +++--- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/BLHX.Server.Game/Commands/Command.cs b/BLHX.Server.Game/Commands/Command.cs index 366c5d2..b821974 100644 --- a/BLHX.Server.Game/Commands/Command.cs +++ b/BLHX.Server.Game/Commands/Command.cs @@ -4,13 +4,13 @@ using System.Reflection; namespace BLHX.Server.Game.Commands; [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] -public class commandHandler : Attribute +public class CommandHandler : Attribute { public string Name { get; } public string Description { get; } public string Example { get; } - public commandHandler(string commandName, string description, string example) + public CommandHandler(string commandName, string description, string example) { Name = commandName; Description = description; @@ -67,13 +67,13 @@ public abstract class Command } } -public static class CommandHandler +public static class CommandHandlerFactory { public static readonly List Commands = new List(); static readonly Dictionary>> commandFunctions; - static CommandHandler() + static CommandHandlerFactory() { commandFunctions = new Dictionary>>(StringComparer.OrdinalIgnoreCase); @@ -83,11 +83,11 @@ public static class CommandHandler public static void RegisterCommands(Assembly assembly) { var commandTypes = assembly.GetTypes() - .Where(t => Attribute.IsDefined(t, typeof(commandHandler)) && typeof(Command).IsAssignableFrom(t)); + .Where(t => Attribute.IsDefined(t, typeof(CommandHandler)) && typeof(Command).IsAssignableFrom(t)); foreach (var commandType in commandTypes) { - var commandAttribute = (commandHandler?)Attribute.GetCustomAttribute(commandType, typeof(commandHandler)); + var commandAttribute = (CommandHandler?)Attribute.GetCustomAttribute(commandType, typeof(CommandHandler)); if (commandAttribute != null) { var commandInstance = (Command)Activator.CreateInstance(commandType)!; diff --git a/BLHX.Server.Game/Commands/HelpCommand.cs b/BLHX.Server.Game/Commands/HelpCommand.cs index a959248..28cd30d 100644 --- a/BLHX.Server.Game/Commands/HelpCommand.cs +++ b/BLHX.Server.Game/Commands/HelpCommand.cs @@ -3,10 +3,10 @@ using System.Text; namespace BLHX.Server.Game.Commands; -[commandHandler("help", "Print out all commands with their description and example", "help")] +[CommandHandler("help", "Print out all commands with their description and example", "help")] public class HelpCommand : Command { - static readonly Dictionary commandAttributes = new Dictionary(); + static readonly Dictionary commandAttributes = new Dictionary(); public override void Execute(Dictionary args) { @@ -15,11 +15,11 @@ public class HelpCommand : Command StringBuilder sb = new StringBuilder(); sb.AppendLine("Available Commands: "); - foreach (var command in CommandHandler.Commands) + foreach (var command in CommandHandlerFactory.Commands) { if (!commandAttributes.TryGetValue(command.GetType(), out var attr)) { - attr = command.GetType().GetCustomAttribute(typeof(commandHandler)) as commandHandler; + attr = command.GetType().GetCustomAttribute(typeof(CommandHandler)) as CommandHandler; commandAttributes[command.GetType()] = attr; } diff --git a/BLHX.Server.Game/Commands/SaveCommand.cs b/BLHX.Server.Game/Commands/SaveCommand.cs index 7864093..41f7af9 100644 --- a/BLHX.Server.Game/Commands/SaveCommand.cs +++ b/BLHX.Server.Game/Commands/SaveCommand.cs @@ -2,7 +2,7 @@ namespace BLHX.Server.Game.Commands; -[commandHandler("save", "Save the current state", "save")] +[CommandHandler("save", "Save the current state", "save")] public class SaveCommand : Command { public override void Execute(Dictionary args) diff --git a/BLHX.Server.Game/Commands/TestCommand.cs b/BLHX.Server.Game/Commands/TestCommand.cs index 8c1a4a1..f80520f 100644 --- a/BLHX.Server.Game/Commands/TestCommand.cs +++ b/BLHX.Server.Game/Commands/TestCommand.cs @@ -3,7 +3,7 @@ using BLHX.Server.Common.Utils; namespace BLHX.Server.Game.Commands; -[commandHandler("test", "Test command", "test type=gacha")] +[CommandHandler("test", "Test command", "test type=gacha")] public class TestCommand : Command { static readonly string[] RarityStrings = { "Unknown", "Unused", "Normal", "Rare", "Elite", "SSR", "UR" }; diff --git a/BLHX.Server.Game/Connection.cs b/BLHX.Server.Game/Connection.cs index f5dedf1..19ced46 100644 --- a/BLHX.Server.Game/Connection.cs +++ b/BLHX.Server.Game/Connection.cs @@ -68,7 +68,7 @@ namespace BLHX.Server.Game var packet = new Packet(buf[readLen..]); c.Log(packet.command.ToString()); - (PacketHandlerDelegate? handler, PacketHandlerAttribute? attr) = PacketFactory.GetPacketHandler(packet.command); + (PacketHandlerDelegate? handler, PacketHandlerAttribute? attr) = PacketHandlerFactory.GetPacketHandler(packet.command); if (handler is not null && attr is not null) { handler(this, packet); diff --git a/BLHX.Server.Game/GameServer.cs b/BLHX.Server.Game/GameServer.cs index 32d2ac0..a935cc2 100644 --- a/BLHX.Server.Game/GameServer.cs +++ b/BLHX.Server.Game/GameServer.cs @@ -17,7 +17,7 @@ namespace BLHX.Server.Game static GameServer() { // Preload - System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(typeof(PacketFactory).TypeHandle); + System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(typeof(PacketHandlerFactory).TypeHandle); EndPoint = new(IPAddress.Any, (int)Config.Instance.Port); listener = new TcpListener(EndPoint); diff --git a/BLHX.Server.Game/InputSystem.cs b/BLHX.Server.Game/InputSystem.cs index a3dc797..e653e9a 100644 --- a/BLHX.Server.Game/InputSystem.cs +++ b/BLHX.Server.Game/InputSystem.cs @@ -12,7 +12,7 @@ public static class InputSystem if (string.IsNullOrEmpty(command)) continue; - CommandHandler.HandleCommand(command); + CommandHandlerFactory.HandleCommand(command); } } } diff --git a/BLHX.Server.Game/Packet.cs b/BLHX.Server.Game/Packet.cs index 8f349f9..eff0fb4 100644 --- a/BLHX.Server.Game/Packet.cs +++ b/BLHX.Server.Game/Packet.cs @@ -29,12 +29,12 @@ namespace BLHX.Server.Game public readonly T Decode() where T : IExtensible => Serializer.Deserialize(bytes.AsSpan()); } - static class PacketFactory + static class PacketHandlerFactory { - static readonly Logger c = new(nameof(PacketFactory), ConsoleColor.DarkGreen); + static readonly Logger c = new(nameof(PacketHandlerFactory), ConsoleColor.DarkGreen); static readonly Dictionary handlers = []; - static PacketFactory() + static PacketHandlerFactory() { LoadPacketHandlers(); }