Skip to content

Commit

Permalink
Join min playtime (#604)
Browse files Browse the repository at this point in the history
  • Loading branch information
Morb0 authored Nov 30, 2022
1 parent 84e9af4 commit 2409fea
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
34 changes: 34 additions & 0 deletions Content.Server/Corvax/JoinPlayTime/JoinPlayTimeManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Threading.Tasks;
using Content.Server.Database;
using Content.Shared.CCVar;
using Content.Shared.Players.PlayTimeTracking;
using Robust.Shared.Configuration;
using Robust.Shared.Network;

namespace Content.Server.Corvax.JoinPlayTime;

public sealed class JoinPlayTimeManager
{
[Dependency] private readonly INetManager _net = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IServerDbManager _db = default!;

private int _minHours = 0;

public void Initialize()
{
_cfg.OnValueChanged(CCVars.JoinPlaytimeHours, (v) => _minHours = v, true);

_net.Connecting += OnConnecting;
}

private async Task OnConnecting(NetConnectingArgs arg)
{
var playTimes = await _db.GetPlayTimes(arg.UserId);
var overallTime = playTimes.Find(p => p.Tracker == PlayTimeTrackingShared.TrackerOverall);
if (overallTime != null && overallTime.TimeSpent.TotalHours < _minHours)
{
arg.Deny(Loc.GetString("join-playtime-deny-reason", ("hours", _minHours)));
}
}
}
2 changes: 2 additions & 0 deletions Content.Server/Entry/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Content.Server.Afk;
using Content.Server.Chat.Managers;
using Content.Server.Connection;
using Content.Server.Corvax.JoinPlayTime;
using Content.Server.Corvax.JoinQueue;
using Content.Server.Corvax.Sponsors;
using Content.Server.Database;
Expand Down Expand Up @@ -100,6 +101,7 @@ public override void Init()
IoCManager.Resolve<GhostKickManager>().Initialize();
IoCManager.Resolve<SponsorsManager>().Initialize(); // Corvax-Sponsors
IoCManager.Resolve<JoinQueueManager>().Initialize(); // Corvax-Queue
IoCManager.Resolve<JoinPlayTimeManager>().Initialize(); // Corvax-JoinPlaytime

_voteManager.Initialize();
_updateManager.Initialize();
Expand Down
2 changes: 2 additions & 0 deletions Content.Server/IoC/ServerContentIoC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Content.Server.Afk;
using Content.Server.Chat.Managers;
using Content.Server.Connection;
using Content.Server.Corvax.JoinPlayTime;
using Content.Server.Corvax.JoinQueue;
using Content.Server.Corvax.Sponsors;
using Content.Server.Database;
Expand Down Expand Up @@ -59,6 +60,7 @@ public static void Register()
IoCManager.Register<UserDbDataManager>();
IoCManager.Register<SponsorsManager>(); // Corvax-Sponsors
IoCManager.Register<JoinQueueManager>(); // Corvax-Queue
IoCManager.Register<JoinPlayTimeManager>(); // Corvax-JoinPlaytime
}
}
}
13 changes: 11 additions & 2 deletions Content.Shared/CCVar/CCVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,7 @@ public static readonly CVarDef<string>
/// </summary>
public static readonly CVarDef<float>
PlayTimeSaveInterval = CVarDef.Create("playtime.save_interval", 900f, CVar.SERVERONLY);

/**
* Corvax | Sponsors
*/
Expand All @@ -1352,7 +1352,6 @@ public static readonly CVarDef<float>
/// </summary>
public static readonly CVarDef<string> SponsorsApiUrl =
CVarDef.Create("sponsor.api_url", "", CVar.SERVERONLY);


/*
* Corvax | Queue
Expand All @@ -1363,5 +1362,15 @@ public static readonly CVarDef<float>
/// </summary>
public static readonly CVarDef<bool>
QueueEnabled = CVarDef.Create("queue.enabled", false, CVar.SERVERONLY);

/*
* Corvax | JoinPlaytime
*/

/// <summary>
/// Minimum required overall play hours to join server
/// </summary>
public static readonly CVarDef<int> JoinPlaytimeHours =
CVarDef.Create("joinplaytime.min_hours", 0, CVar.SERVERONLY);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
join-playtime-deny-reason = Необходимо минимальное отыгранное время для доступа к серверу - { $hours } { $hours ->
[one] час
[few] часа
*[other] часов
}.

0 comments on commit 2409fea

Please sign in to comment.