helpful help + forcing people learn regex
This commit is contained in:
parent
e3acdede67
commit
e8fc578a1b
|
@ -5,6 +5,7 @@ using Config.Net;
|
||||||
using MongoDB.Bson.Serialization;
|
using MongoDB.Bson.Serialization;
|
||||||
using MongoDB.Bson.Serialization.Options;
|
using MongoDB.Bson.Serialization.Options;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using AscNet.Common.Util;
|
||||||
|
|
||||||
namespace AscNet.Common
|
namespace AscNet.Common
|
||||||
{
|
{
|
||||||
|
@ -30,23 +31,22 @@ namespace AscNet.Common
|
||||||
|
|
||||||
public static void DumpTables()
|
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/";
|
string baseSavePath = "/PGR_Data/";
|
||||||
|
|
||||||
|
Console.WriteLine($"Found {tableTypes.Count()} types!");
|
||||||
foreach (Type type in tableTypes)
|
foreach (Type type in tableTypes)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
object? readerInstance = Activator.CreateInstance(type);
|
object? values = typeof(TableReaderV2).GetMethod("Parse")?.MakeGenericMethod(type).Invoke(null, null);
|
||||||
readerInstance?.GetType().GetMethod("Load", BindingFlags.Instance | BindingFlags.Public)?.Invoke(readerInstance, null);
|
|
||||||
object? values = type.GetProperty("All", BindingFlags.Instance | BindingFlags.Public)?.GetValue(readerInstance);
|
|
||||||
if (values is not null)
|
if (values is not null)
|
||||||
{
|
{
|
||||||
// this will create the folder on ur drive root sorry
|
// 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)))
|
if (!Directory.Exists(Path.GetDirectoryName(savePath)))
|
||||||
Directory.CreateDirectory(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);
|
Console.WriteLine(type.FullName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,8 +88,19 @@ namespace AscNet.GameServer.Commands
|
||||||
{
|
{
|
||||||
Command? cmd = CommandFactory.CreateCommand(command, session, args, false);
|
Command? cmd = CommandFactory.CreateCommand(command, session, args, false);
|
||||||
if (cmd is not null)
|
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 })!;
|
return (Command)Activator.CreateInstance(command, new object[] { session, args, validate })!;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class CommandMessageCallbackException : Exception
|
||||||
|
{
|
||||||
|
public CommandMessageCallbackException(string message)
|
||||||
|
: base(message) { }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,6 +170,10 @@ namespace AscNet.GameServer.Handlers
|
||||||
|
|
||||||
cmd?.Execute();
|
cmd?.Execute();
|
||||||
}
|
}
|
||||||
|
catch (CommandMessageCallbackException ex)
|
||||||
|
{
|
||||||
|
notifyWorldChat.ChatMessages.Add(MakeLuciaMessage(ex.Message));
|
||||||
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
notifyWorldChat.ChatMessages.Add(MakeLuciaMessage($"Command {cmdStrings.First().Split('/').Last()} failed to execute!"));
|
notifyWorldChat.ChatMessages.Add(MakeLuciaMessage($"Command {cmdStrings.First().Split('/').Last()} failed to execute!"));
|
||||||
|
|
Loading…
Reference in New Issue