-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathGameManager.Moderation.cs
105 lines (84 loc) · 2.43 KB
/
GameManager.Moderation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using Sandbox;
using System;
using System.Collections.Generic;
namespace TTT;
public struct BannedClient
{
public long SteamId { get; set; }
public string Reason { get; set; }
public DateTime Duration { get; set; }
}
public partial class GameManager : Sandbox.GameManager
{
public static readonly List<BannedClient> BannedClients = new();
public const string BanFilePath = "bans.json";
public override bool ShouldConnect( long steamId )
{
if ( Karma.SavedPlayerValues.TryGetValue( steamId, out var value ) )
if ( value < Karma.MinValue )
return false;
foreach ( var bannedClient in BannedClients )
{
if ( bannedClient.SteamId != steamId )
continue;
if ( bannedClient.Duration >= DateTime.Now )
return false;
BannedClients.Remove( bannedClient );
}
return true;
}
private static void LoadBannedClients()
{
var clients = FileSystem.Data.ReadJson<List<BannedClient>>( BanFilePath );
if ( !clients.IsNullOrEmpty() )
BannedClients.AddRange( clients );
}
[ConCmd.Admin( Name = "ttt_ban", Help = "Ban the client with the following steam id." )]
public static void BanPlayer( string rawSteamId, int minutes = default, string reason = "" )
{
var steamId = long.Parse( rawSteamId );
foreach ( var client in Game.Clients )
{
if ( client.SteamId != steamId )
continue;
client.Ban( minutes, reason );
return;
}
// Player isn't currently in the server, we should ban anyways.
BannedClients.Add
(
new BannedClient
{
SteamId = steamId,
Duration = minutes == default ? DateTime.MaxValue : DateTime.Now.AddMinutes( minutes ),
Reason = reason
}
);
}
[ConCmd.Admin( Name = "ttt_ban_remove", Help = "Remove the ban on a client using a steam id." )]
public static void RemoveBanWithSteamId( string rawSteamId )
{
var steamId = long.Parse( rawSteamId );
foreach ( var bannedClient in BannedClients )
{
if ( bannedClient.SteamId != steamId )
continue;
BannedClients.Remove( bannedClient );
return;
}
Log.Warning( $"Unable to find player with steam id {rawSteamId}" );
}
[ConCmd.Admin( Name = "ttt_kick", Help = "Kick the client with the following steam id." )]
public static void KickPlayer( string rawSteamId )
{
var steamId = long.Parse( rawSteamId );
foreach ( var client in Game.Clients )
{
if ( client.SteamId == steamId )
continue;
client.Kick();
return;
}
Log.Warning( $"Unable to find player with steam id {rawSteamId}" );
}
}