-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathratemonitor.sp
More file actions
405 lines (334 loc) · 13.3 KB
/
ratemonitor.sp
File metadata and controls
405 lines (334 loc) · 13.3 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
#define L4D2UTIL_STOCKS_ONLY 1
#include <l4d2util>
#include <colors>
#define STEAMID_SIZE 32
ConVar
hCvarAllowedRateChanges,
hCvarMinRate,
hCvarMinUpd,
hCvarMinCmd,
hCvarProhibitFakePing,
hCvarProhibitedAction,
hCvarPublicNotice;
ArrayList
hClientSettingsArray;
int
iAllowedRateChanges,
iMinRate,
iMinUpd,
iMinCmd,
iActionUponExceed;
bool
IsLateLoad,
bPublic,
bProhibitFakePing,
bIsMatchLive;
enum struct NetsettingsStruct
{
char Client_SteamId[STEAMID_SIZE];
int Client_Rate;
int Client_Cmdrate;
int Client_Updaterate;
int Client_Changes;
}
public Plugin myinfo =
{
name = "RateMonitor",
author = "Visor, Sir, A1m`",
description = "Keep track of players' netsettings",
version = "2.6.1",
url = "https://github.com/A1mDev/L4D2-Competitive-Plugins"
};
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
IsLateLoad = late;
return APLRes_Success;
}
public void OnPluginStart()
{
hCvarAllowedRateChanges = CreateConVar("rm_allowed_rate_changes", "-1", "Allowed number of rate changes during a live round(-1: no limit)");
hCvarPublicNotice = CreateConVar ("rm_public_notice", "0", "Print Rate Changes to the Public? (rm_countermeasure 1 and 3 will still be Public Notice)");
hCvarMinRate = CreateConVar("rm_min_rate", "20000", "Minimum allowed value of rate(-1: none)");
hCvarMinUpd = CreateConVar("rm_min_upd", "20", "Minimum allowed value of cl_updaterate(-1: none)");
hCvarMinCmd = CreateConVar("rm_min_cmd", "20", "Minimum allowed value of cl_cmdrate(-1: none)");
hCvarProhibitFakePing = CreateConVar("rm_no_fake_ping", "0", "Allow or disallow the use of + - . in netsettings, which is commonly used to hide true ping in the scoreboard.");
hCvarProhibitedAction = CreateConVar("rm_countermeasure", "2", "Countermeasure against illegal actions - change overlimit/forbidden netsettings(1:chat notify,2:move to spec,3:kick)", _, true, 1.0, true, 3.0);
iAllowedRateChanges = hCvarAllowedRateChanges.IntValue;
iMinRate = hCvarMinRate.IntValue;
iMinUpd = hCvarMinUpd.IntValue;
iMinCmd = hCvarMinCmd.IntValue;
bProhibitFakePing = hCvarProhibitFakePing.BoolValue;
iActionUponExceed = hCvarProhibitedAction.IntValue;
bPublic = hCvarPublicNotice.BoolValue;
hCvarAllowedRateChanges.AddChangeHook(cvarChanged_AllowedRateChanges);
hCvarMinRate.AddChangeHook(cvarChanged_MinRate);
hCvarMinCmd.AddChangeHook(cvarChanged_MinCmd);
hCvarProhibitFakePing.AddChangeHook(cvarChanged_ProhibitFakePing);
hCvarProhibitedAction.AddChangeHook(cvarChanged_ExceedAction);
hCvarPublicNotice.AddChangeHook(cvarChanged_PublicNotice);
RegConsoleCmd("sm_rates", ListRates, "List netsettings of all players in game");
HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
HookEvent("round_end", Event_RoundEnd, EventHookMode_PostNoCopy);
HookEvent("player_left_start_area", Event_RoundGoesLive, EventHookMode_PostNoCopy);
HookEvent("player_team", OnTeamChange);
hClientSettingsArray = new ArrayList(sizeof(NetsettingsStruct));
if (IsLateLoad) {
for (int i = 1; i <= MaxClients; i++) {
if (IsClientInGame(i) && !IsFakeClient(i)) {
RegisterSettings(i);
}
}
}
}
void Event_RoundStart(Event hEvent, const char[] name, bool dontBroadcast)
{
int iSize = hClientSettingsArray.Length;
NetsettingsStruct player;
for (int i = 0; i < iSize; i++) {
hClientSettingsArray.GetArray(i, player, sizeof(NetsettingsStruct));
player.Client_Changes = 0;
hClientSettingsArray.SetArray(i, player, sizeof(NetsettingsStruct));
}
}
void Event_RoundGoesLive(Event hEvent, const char[] name, bool dontBroadcast)
{
//This event works great with the plugin readyup.smx (does not conflict)
//This event works great in different game modes: versus, coop, scavenge and etc
bIsMatchLive = true;
}
void Event_RoundEnd(Event hEvent, const char[] name, bool dontBroadcast)
{
bIsMatchLive = false;
}
public void OnMapEnd()
{
hClientSettingsArray.Clear();
}
void OnTeamChange(Event hEvent, const char[] name, bool dontBroadcast)
{
if (hEvent.GetInt("team") != L4D2Team_Spectator) {
int userid = hEvent.GetInt("userid");
int client = GetClientOfUserId(userid);
if (client > 0 && !IsFakeClient(client)) {
CreateTimer(0.1, OnTeamChangeDelay, userid, TIMER_FLAG_NO_MAPCHANGE);
}
}
}
Action OnTeamChangeDelay(Handle hTimer, any userid)
{
int client = GetClientOfUserId(userid);
if (client > 0 && IsClientInGame(client) && !IsFakeClient(client)) {
RegisterSettings(client);
}
return Plugin_Stop;
}
public void OnClientSettingsChanged(int client)
{
if (client > 0 && client <= MaxClients && IsClientInGame(client) && !IsFakeClient(client)) {
RegisterSettings(client);
}
}
Action ListRates(int client, int args)
{
ReplyToCommand(client, "\x01[RateMonitor] List of player netsettings(\x03cmd\x01/\x04upd\x01/\x05rate\x01):");
int iSize = hClientSettingsArray.Length;
NetsettingsStruct player;
for (int i = 0; i < iSize; i++) {
hClientSettingsArray.GetArray(i, player, sizeof(NetsettingsStruct));
int iClient = GetClientBySteamId(player.Client_SteamId);
if (iClient > 0 && GetClientTeam(client) > L4D2Team_Spectator) {
ReplyToCommand(client, "\x03%N\x01 : %d/%d/%d", iClient, player.Client_Cmdrate, player.Client_Updaterate, player.Client_Rate);
}
}
return Plugin_Handled;
}
void RegisterSettings(int client)
{
if (client <= 0 || client > MaxClients || !IsClientInGame(client) || IsFakeClient(client)) {
return;
}
if (GetClientTeam(client) < L4D2Team_Survivor) {
return;
}
char
sCmdRate[32],
sUpdateRate[32],
sRate[32],
sSteamId[STEAMID_SIZE],
sCounter[32] = "";
GetClientAuthId(client, AuthId_Steam2, sSteamId, STEAMID_SIZE);
int iIndex = hClientSettingsArray.FindString(sSteamId);
// rate
int iRate = GetClientDataRate(client);
// cl_cmdrate
GetClientInfo(client, "cl_cmdrate", sCmdRate, sizeof(sCmdRate));
int iCmdRate = StringToInt(sCmdRate);
// cl_updaterate
GetClientInfo(client, "cl_updaterate", sUpdateRate, sizeof(sUpdateRate));
int iUpdateRate = StringToInt(sUpdateRate);
// Punish for fake ping or other unallowed symbols in rate settings
if (bProhibitFakePing) {
bool bIsCmdRateClean, bIsUpdateRateClean;
bIsCmdRateClean = IsNatural(sCmdRate);
bIsUpdateRateClean = IsNatural(sUpdateRate);
if (!bIsCmdRateClean || !bIsUpdateRateClean) {
sCounter = "[bad cmd/upd]";
Format(sCmdRate, sizeof(sCmdRate), "%s", sCmdRate);
Format(sUpdateRate, sizeof(sUpdateRate), "%s", sUpdateRate);
Format(sRate, sizeof(sRate), "%d", iRate);
PunishPlayer(client, sCmdRate, sUpdateRate, sRate, sCounter, iIndex);
return;
}
}
// Punish for low rate settings(if we're good on previous check)
if ((iCmdRate < iMinCmd && iMinCmd > -1) || (iRate < iMinRate && iMinRate > -1) || (iUpdateRate < iMinUpd && iMinUpd > -1)) {
sCounter = "[low cmd/update/rate]";
Format(sCmdRate, sizeof(sCmdRate), "%s%d%s", iCmdRate < iMinCmd ? ">" : "", iCmdRate, iCmdRate < iMinCmd ? "<" : "");
Format(sUpdateRate, sizeof(sCmdRate), "%s%d%s", iUpdateRate < iMinUpd ? ">" : "", iUpdateRate, iUpdateRate < iMinUpd ? "<" : "");
Format(sRate, sizeof(sRate), "%s%d%s", iRate < iMinRate ? ">" : "", iRate, iRate < iMinRate ? "<" : "");
PunishPlayer(client, sCmdRate, sUpdateRate, sRate, sCounter, iIndex);
return;
}
NetsettingsStruct player;
if (iIndex > -1) {
hClientSettingsArray.GetArray(iIndex, player, sizeof(NetsettingsStruct));
if (iRate == player.Client_Rate && iCmdRate == player.Client_Cmdrate && iUpdateRate == player.Client_Updaterate) {
return; // No change
}
if (bIsMatchLive && iAllowedRateChanges > -1) {
player.Client_Changes += 1;
Format(sCounter, sizeof(sCounter), "[%d/%d]", player.Client_Changes, iAllowedRateChanges);
// If not punished for bad rate settings yet, punish for overlimit rate change(if any)
if (player.Client_Changes > iAllowedRateChanges) {
Format(sCmdRate, sizeof(sCmdRate), "%s%d", iCmdRate != player.Client_Cmdrate ? "*" : "", iCmdRate);
Format(sUpdateRate, sizeof(sUpdateRate), "%s%d\x01", iUpdateRate != player.Client_Updaterate ? "*" : "", iUpdateRate);
Format(sRate, sizeof(sRate), "%s%d\x01", iRate != player.Client_Rate ? "*" : "", iRate);
PunishPlayer(client, sCmdRate, sUpdateRate, sRate, sCounter, iIndex);
return;
}
}
if (bPublic) {
CPrintToChatAllEx(client, "{default}<{olive}Rates{default}> {teamcolor}%N{default}'s netsettings changed from {teamcolor}%d/%d/%d {default}to {teamcolor}%d/%d/%d {olive}%s", \
client, player.Client_Cmdrate, player.Client_Updaterate, player.Client_Rate, iCmdRate, iUpdateRate, iRate, sCounter);
}
player.Client_Cmdrate = iCmdRate;
player.Client_Updaterate = iUpdateRate;
player.Client_Rate = iRate;
hClientSettingsArray.SetArray(iIndex, player, sizeof(NetsettingsStruct));
} else {
strcopy(player.Client_SteamId, STEAMID_SIZE, sSteamId);
player.Client_Cmdrate = iCmdRate;
player.Client_Updaterate = iUpdateRate;
player.Client_Rate = iRate;
player.Client_Changes = 0;
hClientSettingsArray.PushArray(player, sizeof(NetsettingsStruct));
if (bPublic) {
CPrintToChatAllEx(client, "{default}<{olive}Rates{default}> {teamcolor}%N{default}'s netsettings set to {teamcolor}%d/%d/%d", \
client, player.Client_Cmdrate, player.Client_Updaterate, player.Client_Rate);
}
}
}
void PunishPlayer(int client, const char[] sCmdRate, const char[] sUpdateRate, const char[] sRate, const char[] sCounter, int iIndex)
{
bool bInitialRegister = (iIndex > -1) ? false : true;
switch (iActionUponExceed)
{
case 1: {// Just notify all players(zero punishment)
if (bInitialRegister) {
CPrintToChatAllEx(client, "{default}<{olive}Rates{default}> {teamcolor}%N{default}'s netsettings set to illegal values: {teamcolor}%s/%s/%s {olive}%s", \
client, sCmdRate, sUpdateRate, sRate, sCounter);
} else {
CPrintToChatAllEx(client, "{default}<{olive}Rates{default}> {teamcolor}%N{default}'s illegaly changed netsettings midgame: {teamcolor}%s/%s/%s {olive}%s", \
client, sCmdRate, sUpdateRate, sRate, sCounter);
}
}
case 2: {// Move to spec
ChangeClientTeam(client, L4D2Team_Spectator);
if (bInitialRegister) {
if (bPublic) {
CPrintToChatAllEx(client, "{default}<{olive}Rates{default}> {teamcolor}%N {default}was moved to spectators for illegal netsettings: {teamcolor}%s/%s/%s {olive}%s", \
client, sCmdRate, sUpdateRate, sRate, sCounter);
}
CPrintToChatEx(client, client, "{default}<{olive}Rates{default}> Please adjust your rates to values higher than {olive}%d/%d/%d%s", \
iMinCmd, iMinUpd, iMinRate, bProhibitFakePing ? " and remove any non-digital characters" : "");
} else {
NetsettingsStruct player;
hClientSettingsArray.GetArray(iIndex, player, sizeof(NetsettingsStruct));
if (bPublic) {
CPrintToChatAllEx(client, "{default}<{olive}Rates{default}> {teamcolor}%N {default}was moved to spectators for illegal netsettings: {teamcolor}%s/%s/%s {olive}%s", \
client, sCmdRate, sUpdateRate, sRate, sCounter);
}
CPrintToChatEx(client, client, "{default}<{olive}Rates{default}> Change your netsettings back to: {teamcolor}%d/%d/%d", \
player.Client_Cmdrate, player.Client_Updaterate, player.Client_Rate);
}
}
case 3: {// Kick
if (bInitialRegister) {
KickClient(client, "Please use rates higher than %d/%d/%d%s", \
iMinCmd, iMinUpd, iMinRate, bProhibitFakePing ? " and remove any non-digits" : "");
CPrintToChatAllEx(client, "{default}<{olive}Rates{default}> {teamcolor}%N {default}was kicked for illegal netsettings: {teamcolor}%s/%s/%s {olive}%s", \
client, sCmdRate, sUpdateRate, sRate, sCounter);
} else {
NetsettingsStruct player;
hClientSettingsArray.GetArray(iIndex, player, sizeof(NetsettingsStruct));
KickClient(client, "Change your rates to previous values and remove non-digits: %d/%d/%d", \
player.Client_Cmdrate, player.Client_Updaterate, player.Client_Rate);
CPrintToChatAllEx(client, "{default}<{olive}Rates{default}> {teamcolor}%N {default}was kicked due to illegal netsettings change: {teamcolor}%s/%s/%s {olive}%s", \
client, sCmdRate, sUpdateRate, sRate, sCounter);
}
}
}
}
int GetClientBySteamId(const char[] steamID)
{
char tempSteamID[STEAMID_SIZE];
for (int i = 1; i <= MaxClients; i++) {
if (IsClientInGame(i)) {
GetClientAuthId(i, AuthId_Steam2, tempSteamID, sizeof(tempSteamID));
if (strcmp(steamID, tempSteamID) == 0) {
return i;
}
}
}
return -1;
}
bool IsNatural(const char[] str)
{
int x = 0;
while (str[x] != '\0')
{
if (!IsCharNumeric(str[x])) {
return false;
}
x++;
}
return true;
}
void cvarChanged_AllowedRateChanges(ConVar convar, const char[] oldValue, const char[] newValue)
{
iAllowedRateChanges = hCvarAllowedRateChanges.IntValue;
}
void cvarChanged_MinRate(ConVar convar, const char[] oldValue, const char[] newValue)
{
iMinRate = hCvarMinRate.IntValue;
}
void cvarChanged_MinCmd(ConVar convar, const char[] oldValue, const char[] newValue)
{
iMinCmd = hCvarMinCmd.IntValue;
}
void cvarChanged_ProhibitFakePing(ConVar convar, const char[] oldValue, const char[] newValue)
{
bProhibitFakePing = hCvarProhibitFakePing.BoolValue;
}
void cvarChanged_ExceedAction(ConVar convar, const char[] oldValue, const char[] newValue)
{
iActionUponExceed = hCvarProhibitedAction.IntValue;
}
void cvarChanged_PublicNotice(ConVar convar, const char[] oldValue, const char[] newValue)
{
bPublic = hCvarPublicNotice.BoolValue;
}