Fixed cli help texts
Added administrator options for critical methods
Added result state for client and server specific errors
Redirect root to help text
Fixed fingerprint error, fingerprint must be case sensitive
Re-Added online messages
Added typing trigger for discord bot messages
client:
fixed chunkString for empty results preemtive
wrap error objects for server messages
both:
added raw lua RS Bridge command entry
This commit is contained in:
Michael Chen
2022-01-17 15:24:04 +01:00
parent 4a98d4cb50
commit 9fd50ee01e
13 changed files with 160 additions and 55 deletions

View File

@ -0,0 +1,21 @@
using Newtonsoft.Json;
namespace MinecraftDiscordBot.Models;
public class LuaPackedArray {
public ref object? this[int i] => ref _items[i];
private readonly object?[] _items;
public LuaPackedArray(IDictionary<string, object> packedTable) {
if (packedTable["n"] is not long n) throw new ArgumentException("No length in packed array!");
_items = new object?[n];
for (var i = 0; i < _items.Length; i++)
_items[i] = packedTable.TryGetValue((i + 1).ToString(), out var val) ? val : null;
}
public static LuaPackedArray Deserialize(string value) {
var dict = JsonConvert.DeserializeObject<Dictionary<string, object>>(value);
return new LuaPackedArray(dict ?? throw new Exception("Not a packed table (empty object)!"));
}
public override string ToString() => _items is { Length: 0 }
? "Empty Array"
: string.Join(", ", _items.Select(i => i is null ? "nil" : i.ToString()));
}

View File

@ -1,5 +1,6 @@
using Newtonsoft.Json;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
namespace MinecraftDiscordBot.Models;
@ -19,7 +20,7 @@ public class Md5Hash : IEquatable<Md5Hash?> {
hashCode.AddBytes(_hash);
return hashCode.ToHashCode();
}
public override string ToString() => Convert.ToHexString(_hash);
public override string ToString() => Convert.ToHexString(_hash).ToLower();
public class Md5JsonConverter : JsonConverter<Md5Hash> {
public override Md5Hash? ReadJson(JsonReader reader, Type objectType, Md5Hash? existingValue, bool hasExistingValue, JsonSerializer serializer)
@ -31,4 +32,14 @@ public class Md5Hash : IEquatable<Md5Hash?> {
else writer.WriteValue(value.ToString());
}
}
public static bool TryParse(string itemid, [NotNullWhen(true)] out Md5Hash? fingerprint) {
try {
fingerprint = new Md5Hash(itemid);
return true;
} catch (Exception) {
fingerprint = null;
return false;
}
}
}

View File

@ -40,11 +40,8 @@ public class ReplyMessage : Message {
public int Chunk { get; set; } = 1;
[JsonProperty("total", Required = Required.DisallowNull)]
public int Total { get; set; } = 1;
/// <summary>
/// If at least one packet was received where
/// </summary>
[JsonProperty("success", Required = Required.DisallowNull)]
public bool Success { get; set; } = true;
public ResultState State { get; set; } = ResultState.Successful;
public override string Type => "reply";
}
@ -62,4 +59,10 @@ public class RequestMessage : Message {
[JsonProperty("params")]
public Dictionary<string, object> Parameters { get; }
public override string Type => "request";
}
public enum ResultState {
Successful,
Unsuccessful,
Fatal
}