diff --git a/Content.Server/Connection/ConnectionManager.cs b/Content.Server/Connection/ConnectionManager.cs index 1bf9b67a34..4938dd9610 100644 --- a/Content.Server/Connection/ConnectionManager.cs +++ b/Content.Server/Connection/ConnectionManager.cs @@ -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); } diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index 7000124fa8..4f68a22be8 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -252,12 +252,24 @@ namespace Content.Shared.CCVar public static readonly CVarDef PanicBunkerEnabled = CVarDef.Create("game.panic_bunker.enabled", false, CVar.SERVERONLY); + /// + /// Show reason of disconnect for user or not. + /// + public static readonly CVarDef PanicBunkerShowReason = + CVarDef.Create("game.panic_bunker.show_reason", false, CVar.SERVERONLY); + /// /// Minimum age of the account (from server's PoV, so from first-seen date) in minutes. /// public static readonly CVarDef PanicBunkerMinAccountAge = CVarDef.Create("game.panic_bunker.min_account_age", 1440, CVar.SERVERONLY); + /// + /// Minimal overall played time. + /// + public static readonly CVarDef PanicBunkerMinOverallHours = + CVarDef.Create("game.panic_bunker.min_overall_hours", 10, CVar.SERVERONLY); + /// /// Make people bonk when trying to climb certain objects like tables. /// diff --git a/Resources/Locale/en-US/connection-messages.ftl b/Resources/Locale/en-US/connection-messages.ftl index 0c8740b6c9..2c66ce358b 100644 --- a/Resources/Locale/en-US/connection-messages.ftl +++ b/Resources/Locale/en-US/connection-messages.ftl @@ -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