- tweak: refactor funny

This commit is contained in:
2025-01-05 17:05:23 +03:00
parent 5b24f915a2
commit 8619e248fd
67 changed files with 485 additions and 492 deletions

View File

@@ -0,0 +1,8 @@
namespace Nebula.Shared.Models.Auth;
public sealed record AuthenticateRequest(string? Username, Guid? UserId, string Password, string? TfaCode = null)
{
public AuthenticateRequest(string username, string password) : this(username, null, password)
{
}
}

View File

@@ -0,0 +1,3 @@
namespace Nebula.Shared.Models.Auth;
public sealed record AuthenticateResponse(string Token, string Username, Guid UserId, DateTimeOffset ExpireTime);

View File

@@ -0,0 +1,13 @@
namespace Nebula.Shared.Models.Auth;
public class LoginInfo
{
public Guid UserId { get; set; }
public string Username { get; set; } = default!;
public LoginToken Token { get; set; }
public override string ToString()
{
return $"{Username}/{UserId}";
}
}

View File

@@ -0,0 +1,13 @@
namespace Nebula.Shared.Models.Auth;
public readonly struct LoginToken
{
public readonly string Token;
public readonly DateTimeOffset ExpireTime;
public LoginToken(string token, DateTimeOffset expireTime)
{
Token = token;
ExpireTime = expireTime;
}
}

View File

@@ -0,0 +1,12 @@
namespace Nebula.Shared.Models;
public enum ContentCompressionScheme
{
None = 0,
Deflate = 1,
/// <summary>
/// ZStandard compression. In the future may use SS14 specific dictionary IDs in the frame header.
/// </summary>
ZStd = 2
}

View File

@@ -0,0 +1,13 @@
namespace Nebula.Shared.Models;
[Flags]
public enum DownloadStreamHeaderFlags
{
None = 0,
/// <summary>
/// If this flag is set on the download stream, individual files have been pre-compressed by the server.
/// This means each file has a compression header, and the launcher should not attempt to compress files itself.
/// </summary>
PreCompressed = 1 << 0
}

View File

@@ -0,0 +1,2 @@
namespace Nebula.Shared.Models;
public record ListItemTemplate(Type ModelType, string IconKey, string Label);

View File

@@ -0,0 +1,19 @@
using Robust.LoaderApi;
namespace Nebula.Shared.Models;
public sealed class MainArgs : IMainArgs
{
public MainArgs(string[] args, IFileApi fileApi, IRedialApi? redialApi, IEnumerable<ApiMount>? apiMounts)
{
Args = args;
FileApi = fileApi;
RedialApi = redialApi;
ApiMounts = apiMounts;
}
public string[] Args { get; }
public IFileApi FileApi { get; }
public IRedialApi? RedialApi { get; }
public IEnumerable<ApiMount>? ApiMounts { get; }
}

View File

@@ -0,0 +1,8 @@
namespace Nebula.Shared.Models;
public class RobustBuildInfo
{
public ServerInfo BuildInfo;
public RobustManifestInfo RobustManifestInfo;
public RobustUrl Url;
}

View File

@@ -0,0 +1,3 @@
namespace Nebula.Shared.Models;
public record struct RobustManifestInfo(Uri ManifestUri, Uri DownloadUri, string Hash);

View File

@@ -0,0 +1,3 @@
namespace Nebula.Shared.Models;
public record struct RobustManifestItem(string Hash, string Path, int Id);

View File

@@ -0,0 +1,73 @@
using System.Text.Json.Serialization;
namespace Nebula.Shared.Models;
public sealed record AuthInfo(
[property: JsonPropertyName("mode")] string Mode,
[property: JsonPropertyName("public_key")] string PublicKey);
public sealed record BuildInfo(
[property: JsonPropertyName("engine_version")] string EngineVersion,
[property: JsonPropertyName("fork_id")] string ForkId,
[property: JsonPropertyName("version")] string Version,
[property: JsonPropertyName("download_url")] string DownloadUrl,
[property: JsonPropertyName("manifest_download_url")] string ManifestDownloadUrl,
[property: JsonPropertyName("manifest_url")] string ManifestUrl,
[property: JsonPropertyName("acz")] bool Acz,
[property: JsonPropertyName("hash")] string Hash,
[property: JsonPropertyName("manifest_hash")] string ManifestHash);
public sealed record ServerLink(
[property: JsonPropertyName("name")] string Name,
[property: JsonPropertyName("icon")] string Icon,
[property: JsonPropertyName("url")] string Url);
public sealed record ServerInfo(
[property: JsonPropertyName("connect_address")] string ConnectAddress,
[property: JsonPropertyName("auth")] AuthInfo Auth,
[property: JsonPropertyName("build")] BuildInfo Build,
[property: JsonPropertyName("desc")] string Desc,
[property: JsonPropertyName("links")] List<ServerLink> Links);
public sealed record EngineVersionInfo(
[property: JsonPropertyName("insecure")] bool Insecure,
[property: JsonPropertyName("redirect")] string? RedirectVersion,
[property: JsonPropertyName("platforms")] Dictionary<string, EngineBuildInfo> Platforms);
public sealed class EngineBuildInfo
{
[JsonInclude] [JsonPropertyName("sha256")]
public string Sha256 = default!;
[JsonInclude] [JsonPropertyName("sig")]
public string Signature = default!;
[JsonInclude] [JsonPropertyName("url")]
public string Url = default!;
}
public sealed record ServerHubInfo(
[property: JsonPropertyName("address")] string Address,
[property: JsonPropertyName("statusData")] ServerStatus StatusData,
[property: JsonPropertyName("inferredTags")] List<string> InferredTags);
public sealed record ServerStatus(
[property: JsonPropertyName("map")] string Map,
[property: JsonPropertyName("name")] string Name,
[property: JsonPropertyName("tags")] List<string> Tags,
[property: JsonPropertyName("preset")] string Preset,
[property: JsonPropertyName("players")] int Players,
[property: JsonPropertyName("round_id")] int RoundId,
[property: JsonPropertyName("run_level")] int RunLevel,
[property: JsonPropertyName("panic_bunker")] bool PanicBunker,
[property: JsonPropertyName("round_start_time")] DateTime? RoundStartTime,
[property: JsonPropertyName("soft_max_players")] int SoftMaxPlayers);
public sealed record ModulesInfo(
[property: JsonPropertyName("modules")] Dictionary<string, Module> Modules);
public sealed record Module(
[property: JsonPropertyName("versions")] Dictionary<string, ModuleVersionInfo> Versions);
public sealed record ModuleVersionInfo(
[property: JsonPropertyName("platforms")] Dictionary<string, EngineBuildInfo> Platforms);

View File

@@ -0,0 +1,63 @@
using Nebula.Shared.Utils;
namespace Nebula.Shared.Models;
public class RobustUrl
{
public RobustUrl(string url)
{
if (!UriHelper.TryParseSs14Uri(url, out var uri))
throw new Exception("Invalid scheme");
Uri = uri;
HttpUri = UriHelper.GetServerApiAddress(Uri);
}
public Uri Uri { get; }
public Uri HttpUri { get; }
public RobustPath InfoUri => new(this, "info");
public RobustPath StatusUri => new(this, "status");
public override string ToString()
{
return Uri.ToString();
}
public static implicit operator Uri(RobustUrl url)
{
return url.HttpUri;
}
public static explicit operator RobustUrl(string url)
{
return new RobustUrl(url);
}
public static explicit operator RobustUrl(Uri uri)
{
return new RobustUrl(uri.ToString());
}
}
public class RobustPath
{
public string Path;
public RobustUrl Url;
public RobustPath(RobustUrl url, string path)
{
Url = url;
Path = path;
}
public override string ToString()
{
return ((Uri)this).ToString();
}
public static implicit operator Uri(RobustPath path)
{
return new Uri(path.Url, path.Url.HttpUri.PathAndQuery + path.Path);
}
}