9fd50ee01e
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
21 lines
969 B
C#
21 lines
969 B
C#
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()));
|
|
} |