csharp/0x0ade/CelesteNet/CelesteNet.Server/UserData.cs

UserData.cs
using Celeste.Mod.CelesteNet.DataTypes;
using Mono.Options;
using MonoMod.Utils;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Celeste.Mod.CelesteNet.Server {
    public abstract clast UserData : IDisposable {

        public readonly CelesteNetServer Server;

        public UserData(CelesteNetServer server) {
            Server = server;
        }

        public abstract void Dispose();

        public virtual UserDataBatchContext OpenBatch() => UserDataBatchContext.Nop;

        public abstract string GetUID(string key);
        public abstract string GetKey(string uid);

        public abstract bool TryLoad(string uid, out T value) where T : new();
        public T Load(string uid) where T : new()
            => TryLoad(uid, out T value) ? value : value;
        public abstract Stream? ReadFile(string uid, string name);
        public abstract void Save(string uid, T value) where T : notnull;
        public abstract Stream WriteFile(string uid, string name);
        public abstract void Delete(string uid);
        public abstract void DeleteFile(string uid, string name);
        public abstract void Wipe(string uid);

        public abstract T[] LoadRegistered() where T : new();
        public abstract T[] LoadAll() where T : new();

        public abstract string[] GetRegistered();
        public abstract string[] GetAll();

        public abstract int GetRegisteredCount();
        public abstract int GetAllCount();

        public abstract string Create(string uid);
        public abstract void RevokeKey(string key);

        public abstract void CopyTo(UserData other);
        public abstract void Insert(string uid, string key, string keyFull, bool registered);
        public abstract void InsertData(string uid, string name, Type? type, Stream stream);
        public abstract void InsertFile(string uid, string name, Stream stream);

    }

    public clast UserDataBatchContext : IDisposable {

        public static readonly UserDataBatchContext Nop = new();

        protected UserDataBatchContext() {
        }

        public virtual void Dispose() {
        }

    }

    public clast BasicUserInfo {
        public string Name { get; set; } = "";
        // TODO: Move into separate Discord module!
        public string Discrim { get; set; } = "";
        public HashSet Tags { get; set; } = new();
    }

    public clast BanInfo {
        public string UID { get; set; } = "";
        public string Name { get; set; } = "";
        public string Reason { get; set; } = "";
        public DateTime? From { get; set; } = null;
        public DateTime? To { get; set; } = null;
    }

    public clast KickHistory {
        public List Log { get; set; } = new();
        public clast Entry {
            public string Reason { get; set; } = "";
            public DateTime? From { get; set; } = null;
        }
    }
}