Panic bunker min overall playtime & deny reason (#12811)
* Add min overall hours & reason * Disable show reason by default
This commit is contained in:
@@ -5,6 +5,7 @@ using Content.Server.GameTicking;
|
||||
using Content.Server.Preferences.Managers;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.GameTicking;
|
||||
using Content.Shared.Players.PlayTimeTracking;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Network;
|
||||
@@ -103,10 +104,32 @@ namespace Content.Server.Connection
|
||||
|
||||
if (_cfg.GetCVar(CCVars.PanicBunkerEnabled))
|
||||
{
|
||||
var record = await _dbManager.GetPlayerRecordByUserId(userId);
|
||||
var showReason = _cfg.GetCVar(CCVars.PanicBunkerShowReason);
|
||||
|
||||
if ((record is null ||
|
||||
(record.FirstSeenTime.CompareTo(DateTimeOffset.Now - TimeSpan.FromMinutes(_cfg.GetCVar(CCVars.PanicBunkerMinAccountAge))) > 0)))
|
||||
var minMinutesAge = _cfg.GetCVar(CCVars.PanicBunkerMinAccountAge);
|
||||
var record = await _dbManager.GetPlayerRecordByUserId(userId);
|
||||
var validAccountAge = record != null &&
|
||||
record.FirstSeenTime.CompareTo(DateTimeOffset.Now - TimeSpan.FromMinutes(minMinutesAge)) <= 0;
|
||||
|
||||
if (showReason && !validAccountAge)
|
||||
{
|
||||
return (ConnectionDenyReason.Panic,
|
||||
Loc.GetString("panic-bunker-account-denied-reason",
|
||||
("reason", Loc.GetString("panic-bunker-account-reason-account", ("minutes", minMinutesAge)))), null);
|
||||
}
|
||||
|
||||
var minOverallHours = _cfg.GetCVar(CCVars.PanicBunkerMinOverallHours);
|
||||
var overallTime = ( await _db.GetPlayTimes(e.UserId)).Find(p => p.Tracker == PlayTimeTrackingShared.TrackerOverall);
|
||||
var haveMinOverallTime = overallTime != null && overallTime.TimeSpent.TotalHours > minOverallHours;
|
||||
|
||||
if (showReason && !haveMinOverallTime)
|
||||
{
|
||||
return (ConnectionDenyReason.Panic,
|
||||
Loc.GetString("panic-bunker-account-denied-reason",
|
||||
("reason", Loc.GetString("panic-bunker-account-reason-overall", ("hours", minOverallHours)))), null);
|
||||
}
|
||||
|
||||
if (!validAccountAge || !haveMinOverallTime)
|
||||
{
|
||||
return (ConnectionDenyReason.Panic, Loc.GetString("panic-bunker-account-denied"), null);
|
||||
}
|
||||
|
||||
@@ -252,12 +252,24 @@ namespace Content.Shared.CCVar
|
||||
public static readonly CVarDef<bool> PanicBunkerEnabled =
|
||||
CVarDef.Create("game.panic_bunker.enabled", false, CVar.SERVERONLY);
|
||||
|
||||
/// <summary>
|
||||
/// Show reason of disconnect for user or not.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<bool> PanicBunkerShowReason =
|
||||
CVarDef.Create("game.panic_bunker.show_reason", false, CVar.SERVERONLY);
|
||||
|
||||
/// <summary>
|
||||
/// Minimum age of the account (from server's PoV, so from first-seen date) in minutes.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<int> PanicBunkerMinAccountAge =
|
||||
CVarDef.Create("game.panic_bunker.min_account_age", 1440, CVar.SERVERONLY);
|
||||
|
||||
/// <summary>
|
||||
/// Minimal overall played time.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<int> PanicBunkerMinOverallHours =
|
||||
CVarDef.Create("game.panic_bunker.min_overall_hours", 10, CVar.SERVERONLY);
|
||||
|
||||
/// <summary>
|
||||
/// Make people bonk when trying to climb certain objects like tables.
|
||||
/// </summary>
|
||||
|
||||
@@ -23,3 +23,6 @@ ban-banned-2 = The ban reason is: "{$reason}"
|
||||
|
||||
soft-player-cap-full = The server is full!
|
||||
panic-bunker-account-denied = This server is in Panic mode and you were rejected. Contact the server administrator for help.
|
||||
panic-bunker-account-denied-reason = This server is in Panic mode and you were rejected. Reason: "{$reason}"
|
||||
panic-bunker-account-reason-account = Age of account must be more that {$minutes} minutes
|
||||
panic-bunker-account-reason-overall = Minimum required overall playing time {$hours} hours
|
||||
|
||||
Reference in New Issue
Block a user