aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Core
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-06-29 17:54:45 -0500
committerGitHub <noreply@github.com>2022-06-29 17:54:45 -0500
commit610582ea53ace5c309b18df5570b12c73a43541a (patch)
tree84248ffd4e3b5c261e2fdbd8f52ddc767e469418 /src/slskd/Core
parent77df3572c381150dc60454be03ca3176a940a628 (diff)
parent6fd167cca6be37e2c88c811cdbcfa64081aeb268 (diff)
downloadslskd-610582ea53ace5c309b18df5570b12c73a43541a.tar.gz
Merge pull request #538 from slskd/privileges
Track user privileges
Diffstat (limited to 'src/slskd/Core')
-rw-r--r--src/slskd/Core/Extensions.cs (renamed from src/slskd/Core/CoreExtensions.cs)17
-rw-r--r--src/slskd/Core/State.cs24
2 files changed, 37 insertions, 4 deletions
diff --git a/src/slskd/Core/CoreExtensions.cs b/src/slskd/Core/Extensions.cs
index aef187b8..d818d387 100644
--- a/src/slskd/Core/CoreExtensions.cs
+++ b/src/slskd/Core/Extensions.cs
@@ -1,4 +1,4 @@
-// <copyright file="CoreExtensions.cs" company="slskd Team">
+// <copyright file="Extensions.cs" company="slskd Team">
// Copyright (c) slskd Team. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
@@ -24,7 +24,7 @@ namespace slskd
/// <summary>
/// Core extensions; extensions for types specific to Soulseek or slskd.
/// </summary>
- public static class CoreExtensions
+ public static class Extensions
{
/// <summary>
/// Redacts this instance of Options, replacing properties marked with <see cref="SecretAttribute"/> with '*****'.
@@ -71,5 +71,18 @@ namespace slskd
inactivityTimeout: inactivityTimeout ?? o.InactivityTimeout,
proxyOptions: proxyOptions ?? o.ProxyOptions,
configureSocket: configureSocketAction ?? o.ConfigureSocket);
+
+ /// <summary>
+ /// Creates a new instance of <see cref="UserStatisticsState"/> from this instance of <see cref="UserStatistics"/>.
+ /// </summary>
+ /// <param name="stats">The UserStatistics instance from which to copy data</param>
+ /// <returns>The new instance.</returns>
+ public static UserStatisticsState ToUserStatisticsState(this UserStatistics stats) => new()
+ {
+ AverageSpeed = stats.AverageSpeed,
+ DirectoryCount = stats.DirectoryCount,
+ FileCount = stats.FileCount,
+ UploadCount = stats.UploadCount,
+ };
}
}
diff --git a/src/slskd/Core/State.cs b/src/slskd/Core/State.cs
index b15ce7fa..e009805a 100644
--- a/src/slskd/Core/State.cs
+++ b/src/slskd/Core/State.cs
@@ -34,6 +34,7 @@ namespace slskd
public bool PendingReconnect { get; init; }
public bool PendingRestart { get; init; }
public ServerState Server { get; init; } = new ServerState();
+ public UserState User { get; init; } = new UserState();
public DistributedNetworkState DistributedNetwork { get; init; } = new DistributedNetworkState();
public ShareState Shares { get; init; } = new ShareState();
public string[] Rooms { get; init; } = Array.Empty<string>();
@@ -57,13 +58,32 @@ namespace slskd
[JsonConverter(typeof(IPEndPointConverter))]
public IPEndPoint IPEndPoint { get; init; }
public SoulseekClientStates State { get; init; }
- public string Username { get; init; }
- public UserStatistics Statistics { get; init; }
public bool IsConnected => State.HasFlag(SoulseekClientStates.Connected);
public bool IsLoggedIn => State.HasFlag(SoulseekClientStates.LoggedIn);
public bool IsTransitioning => State.HasFlag(SoulseekClientStates.Connecting) || State.HasFlag(SoulseekClientStates.Disconnecting) || State.HasFlag(SoulseekClientStates.LoggingIn);
}
+ public record UserState
+ {
+ public string Username { get; init; }
+ public UserPrivilegeState Privileges { get; init; } = new UserPrivilegeState();
+ public UserStatisticsState Statistics { get; init; } = new UserStatisticsState();
+ }
+
+ public record UserPrivilegeState
+ {
+ public bool IsPrivileged { get; init; }
+ public int PrivilegesRemaining { get; init; }
+ }
+
+ public record UserStatisticsState
+ {
+ public int AverageSpeed { get; init; }
+ public int DirectoryCount { get; init; }
+ public int FileCount { get; init; }
+ public long UploadCount { get; init; }
+ }
+
public record DistributedNetworkState
{
public int BranchLevel { get; init; }