diff --git a/AscNet.Common/Common.cs b/AscNet.Common/Common.cs index c41a572..7c5c8a1 100644 --- a/AscNet.Common/Common.cs +++ b/AscNet.Common/Common.cs @@ -5,6 +5,7 @@ using Config.Net; using MongoDB.Bson.Serialization; using MongoDB.Bson.Serialization.Options; using Newtonsoft.Json; +using AscNet.Common.Util; namespace AscNet.Common { @@ -30,23 +31,22 @@ namespace AscNet.Common public static void DumpTables() { - IEnumerable tableTypes = Assembly.GetAssembly(typeof(Table.client.activity.ActivityGroupTable))!.GetTypes().Where(t => t.BaseType?.Name == "TableReader`2"); + IEnumerable tableTypes = Assembly.GetAssembly(typeof(Table.V2.client.activity.ActivityGroupTable))!.GetTypes().Where(t => typeof(ITable).IsAssignableFrom(t)); string baseSavePath = "/PGR_Data/"; + Console.WriteLine($"Found {tableTypes.Count()} types!"); foreach (Type type in tableTypes) { try { - object? readerInstance = Activator.CreateInstance(type); - readerInstance?.GetType().GetMethod("Load", BindingFlags.Instance | BindingFlags.Public)?.Invoke(readerInstance, null); - object? values = type.GetProperty("All", BindingFlags.Instance | BindingFlags.Public)?.GetValue(readerInstance); + object? values = typeof(TableReaderV2).GetMethod("Parse")?.MakeGenericMethod(type).Invoke(null, null); if (values is not null) { // this will create the folder on ur drive root sorry - string savePath = baseSavePath + string.Join("/", type.FullName!.Split(".").Skip(2)); + string savePath = baseSavePath + string.Join("/", type.FullName!.Split(".").Skip(3)); if (!Directory.Exists(Path.GetDirectoryName(savePath))) Directory.CreateDirectory(Path.GetDirectoryName(savePath)!); - File.WriteAllText(new string(savePath.Take(savePath.Length - 11).ToArray()) + ".json", JsonConvert.SerializeObject(values, Formatting.Indented)); + File.WriteAllText(new string(savePath.Take(savePath.Length - 5).ToArray()) + ".json", JsonConvert.SerializeObject(values, Formatting.Indented)); Console.WriteLine(type.FullName); } diff --git a/AscNet.GameServer/Commands/Command.cs b/AscNet.GameServer/Commands/Command.cs index c736895..b62418d 100644 --- a/AscNet.GameServer/Commands/Command.cs +++ b/AscNet.GameServer/Commands/Command.cs @@ -88,8 +88,19 @@ namespace AscNet.GameServer.Commands { Command? cmd = CommandFactory.CreateCommand(command, session, args, false); if (cmd is not null) - helpText += $"{command}\n\t└─{cmd.Help}\n"; + { + List argsProperties = cmd.GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Where(x => x.GetCustomAttribute(typeof(ArgumentAttribute)) is not null).ToList(); + + helpText += $"{command} {string.Join(" ", argsProperties.Select(x => $"<{x.Name}>"))}\n└─{cmd.Help}\n"; + foreach (var argProp in argsProperties) + { + ArgumentAttribute attr = (ArgumentAttribute)argProp.GetCustomAttribute(typeof(ArgumentAttribute))!; + helpText += string.Format($"└─{argProp.Name} \"{attr.Pattern}\"{{0}}\n", string.IsNullOrEmpty(attr.Description) ? string.Empty : $", {attr.Description}"); + } + } } + + throw new CommandMessageCallbackException(helpText); } } @@ -129,4 +140,10 @@ namespace AscNet.GameServer.Commands return (Command)Activator.CreateInstance(command, new object[] { session, args, validate })!; } } + + public class CommandMessageCallbackException : Exception + { + public CommandMessageCallbackException(string message) + : base(message) { } + } } diff --git a/AscNet.GameServer/Handlers/ChatModule.cs b/AscNet.GameServer/Handlers/ChatModule.cs index d18d730..3aad490 100644 --- a/AscNet.GameServer/Handlers/ChatModule.cs +++ b/AscNet.GameServer/Handlers/ChatModule.cs @@ -170,6 +170,10 @@ namespace AscNet.GameServer.Handlers cmd?.Execute(); } + catch (CommandMessageCallbackException ex) + { + notifyWorldChat.ChatMessages.Add(MakeLuciaMessage(ex.Message)); + } catch (Exception) { notifyWorldChat.ChatMessages.Add(MakeLuciaMessage($"Command {cmdStrings.First().Split('/').Last()} failed to execute!"));