zio fork: @ staff chat while gagged, gag message with time left and reason
Gagged or silenced players can still send @ team chat to online staff. The chat-blocked message now says how long the gag or silence has left, or that it's permanent, and why. Reasons are kept in memory alongside each penalty. Adds release.sh, which ships CS2-SimpleAdmin.dll and lang/en.json.
This commit is contained in:
parent
cf284bd121
commit
6171162ae9
10 changed files with 230 additions and 11 deletions
|
|
@ -8,6 +8,46 @@ public static class PlayerPenaltyManager
|
|||
private static readonly ConcurrentDictionary<int, Dictionary<PenaltyType, List<(DateTime EndDateTime, int Duration, bool Passed)>>> Penalties =
|
||||
new();
|
||||
|
||||
// zio: the reason and online-time bookkeeping for each penalty, kept beside Penalties so the
|
||||
// tuple type the API exposes doesn't change.
|
||||
private static readonly ConcurrentDictionary<(int Slot, PenaltyType Type, DateTime EndDateTime), (string? Reason, DateTime AddedAt, int MinutesLeft)> Details =
|
||||
new();
|
||||
|
||||
/// <summary>
|
||||
/// Adds a penalty and remembers its reason, for telling the player why they're penalized.
|
||||
/// </summary>
|
||||
/// <param name="minutesLeft">Minutes left when added: the duration, less any already served
|
||||
/// online when TimeMode is 0.</param>
|
||||
public static void AddPenalty(int slot, PenaltyType penaltyType, DateTime endDateTime, int durationInMinutes, string? reason, int? minutesLeft = null)
|
||||
{
|
||||
AddPenalty(slot, penaltyType, endDateTime, durationInMinutes);
|
||||
Details[(slot, penaltyType, endDateTime)] = (reason, Time.ActualDateTime(), minutesLeft ?? durationInMinutes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns how long the penalty IsPenalized found has left (null if permanent) and its reason.
|
||||
/// </summary>
|
||||
public static (TimeSpan? Remaining, string? Reason) GetPenaltyDetails(int slot, PenaltyType penaltyType, DateTime endDateTime)
|
||||
{
|
||||
var penalty = GetPlayerPenalties(slot, penaltyType).FirstOrDefault(p => p.EndDateTime == endDateTime);
|
||||
var hasDetails = Details.TryGetValue((slot, penaltyType, endDateTime), out var details);
|
||||
if (penalty.Duration == 0)
|
||||
return (null, details.Reason);
|
||||
|
||||
var now = Time.ActualDateTime();
|
||||
// TimeMode 0 only counts time online, and the player has been online since it was added.
|
||||
var remaining = CS2_SimpleAdmin.Instance.Config.OtherSettings.TimeMode == 0 && hasDetails
|
||||
? TimeSpan.FromMinutes(details.MinutesLeft) - (now - details.AddedAt)
|
||||
: endDateTime - now;
|
||||
return (remaining < TimeSpan.Zero ? TimeSpan.Zero : remaining, details.Reason);
|
||||
}
|
||||
|
||||
private static void RemoveDetails(Func<(int Slot, PenaltyType Type, DateTime EndDateTime), bool> match)
|
||||
{
|
||||
foreach (var key in Details.Keys.Where(match).ToList())
|
||||
Details.TryRemove(key, out _);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a penalty for a specific player slot and penalty type.
|
||||
/// </summary>
|
||||
|
|
@ -162,6 +202,7 @@ public static class PlayerPenaltyManager
|
|||
{
|
||||
Penalties.TryRemove(slot, out _);
|
||||
}
|
||||
RemoveDetails(k => k.Slot == slot);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -170,6 +211,7 @@ public static class PlayerPenaltyManager
|
|||
public static void RemoveAllPenalties()
|
||||
{
|
||||
Penalties.Clear();
|
||||
Details.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -184,6 +226,7 @@ public static class PlayerPenaltyManager
|
|||
{
|
||||
penaltyDict.Remove(penaltyType);
|
||||
}
|
||||
RemoveDetails(k => k.Slot == slot && k.Type == penaltyType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue