forked from PGR/ascnet
1
0
Fork 0

helpful help + forcing people learn regex

This commit is contained in:
rfi 2023-11-27 19:45:34 +07:00
parent e3acdede67
commit e8fc578a1b
3 changed files with 28 additions and 7 deletions

View File

@ -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<Type> tableTypes = Assembly.GetAssembly(typeof(Table.client.activity.ActivityGroupTable))!.GetTypes().Where(t => t.BaseType?.Name == "TableReader`2");
IEnumerable<Type> 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);
}

View File

@ -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<PropertyInfo> 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) { }
}
}

View File

@ -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!"));