2
2
// This file is part of SourceBans++.
3
3
//
4
4
// Copyright (C) 2014-2016 Sarabveer Singh <me@sarabveer.me>
5
- //
5
+ //
6
6
// SourceBans++ is free software: you can redistribute it and/or modify
7
7
// it under the terms of the GNU General Public License as published by
8
8
// the Free Software Foundation, per version 3 of the License.
9
- //
9
+ //
10
10
// SourceBans++ is distributed in the hope that it will be useful,
11
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
13
// GNU General Public License for more details.
14
- //
14
+ //
15
15
// You should have received a copy of the GNU General Public License
16
16
// along with SourceBans++. If not, see <http://www.gnu.org/licenses/>.
17
17
//
18
- // This file is based off work covered by the following copyright(s):
18
+ // This file is based off work covered by the following copyright(s):
19
19
//
20
20
// SourceSleuth 1.3 fix
21
21
// Copyright (C) 2013-2015 ecca
@@ -53,36 +53,36 @@ ConVar g_cVar_bypass;
53
53
//- Bools -//
54
54
new bool :CanUseSourcebans = false ;
55
55
56
- public Plugin :myinfo =
56
+ public Plugin :myinfo =
57
57
{
58
- name = " SourceSleuth" ,
59
- author = " ecca, Sarabveer(VEER™)" ,
60
- description = " Useful for TF2 servers. Plugin will check for banned ips and ban the player." ,
61
- version = PLUGIN_VERSION ,
58
+ name = " SourceSleuth" ,
59
+ author = " ecca, Sarabveer(VEER™)" ,
60
+ description = " Useful for TF2 servers. Plugin will check for banned ips and ban the player." ,
61
+ version = PLUGIN_VERSION ,
62
62
url = " https://sarabveer.github.io/SourceBans-Fork/"
63
63
};
64
64
65
65
public OnPluginStart ()
66
66
{
67
67
LoadTranslations (" sourcesleuth.phrases" );
68
-
68
+
69
69
CreateConVar (" sm_sourcesleuth_version" , PLUGIN_VERSION , " SourceSleuth plugin version" , FCVAR_PLUGIN | FCVAR_SPONLY | FCVAR_REPLICATED | FCVAR_NOTIFY | FCVAR_DONTRECORD );
70
-
70
+
71
71
g_cVar_actions = CreateConVar (" sm_sleuth_actions" , " 3" , " Sleuth Ban Type: 1 - Original Length, 2 - Custom Length, 3 - Double Length, 4 - Notify Admins Only" , FCVAR_PLUGIN , true , 1.0 , true , 4.0 );
72
72
g_cVar_banduration = CreateConVar (" sm_sleuth_duration" , " 0" , " Required: sm_sleuth_actions 1: Bantime to ban player if we got a match (0 = permanent (defined in minutes) )" , FCVAR_PLUGIN );
73
73
g_cVar_sbprefix = CreateConVar (" sm_sleuth_prefix" , " sb" , " Prexfix for sourcebans tables: Default sb" , FCVAR_PLUGIN );
74
74
g_cVar_bansAllowed = CreateConVar (" sm_sleuth_bansallowed" , " 0" , " How many active bans are allowed before we act" , FCVAR_PLUGIN );
75
75
g_cVar_bantype = CreateConVar (" sm_sleuth_bantype" , " 0" , " 0 - ban all type of lengths, 1 - ban only permanent bans" , FCVAR_PLUGIN , true , 0.0 , true , 1.0 );
76
76
g_cVar_bypass = CreateConVar (" sm_sleuth_adminbypass" , " 0" , " 0 - Inactivated, 1 - Allow all admins with ban flag to pass the check" , FCVAR_PLUGIN , true , 0.0 , true , 1.0 );
77
-
77
+
78
78
g_hAllowedArray = CreateArray (256 );
79
-
79
+
80
80
AutoExecConfig (true , " Sm_SourceSleuth" );
81
-
81
+
82
82
SQL_TConnect (SQL_OnConnect , " sourcebans" );
83
-
83
+
84
84
RegAdminCmd (" sm_sleuth_reloadlist" , ReloadListCallBack , ADMFLAG_ROOT );
85
-
85
+
86
86
LoadWhiteList ();
87
87
}
88
88
@@ -122,16 +122,16 @@ public SQL_OnConnect(Handle:owner, Handle:hndl, const String:error[], any:data)
122
122
public Action :ReloadListCallBack (client , args )
123
123
{
124
124
ClearArray (g_hAllowedArray );
125
-
125
+
126
126
LoadWhiteList ();
127
-
127
+
128
128
LogMessage (" %L reloaded the whitelist" , client );
129
-
129
+
130
130
if (client != 0 )
131
131
{
132
132
PrintToChat (client , " [SourceSleuth] WhiteList has been reloaded!" );
133
133
}
134
-
134
+
135
135
return Plugin_Continue ;
136
136
}
137
137
@@ -141,30 +141,30 @@ public OnClientPostAdminCheck(client)
141
141
{
142
142
new String :steamid [32 ];
143
143
GetClientAuthId (client , AuthId_Steam2 , steamid , sizeof (steamid ));
144
-
144
+
145
145
if (g_cVar_bypass .BoolValue && CheckCommandAccess (client , " sleuth_admin" , ADMFLAG_BAN , false ))
146
146
{
147
147
return ;
148
148
}
149
-
149
+
150
150
if (FindStringInArray (g_hAllowedArray , steamid ) == - 1 )
151
151
{
152
152
new String :IP [32 ], String :Prefix [64 ];
153
153
GetClientIP (client , IP , sizeof (IP ));
154
-
154
+
155
155
g_cVar_sbprefix .GetString (Prefix , sizeof (Prefix ));
156
-
156
+
157
157
new String :query [1024 ];
158
-
158
+
159
159
FormatEx (query , sizeof (query ), " SELECT * FROM %s _bans WHERE ip='%s ' AND RemoveType IS NULL AND ends > %d " , Prefix , IP , g_cVar_bantype .IntValue == 0 ? GetTime () : 0 );
160
-
160
+
161
161
new Handle :datapack = CreateDataPack ();
162
-
162
+
163
163
WritePackCell (datapack , GetClientUserId (client ));
164
164
WritePackString (datapack , steamid );
165
165
WritePackString (datapack , IP );
166
166
ResetPack (datapack );
167
-
167
+
168
168
SQL_TQuery (hDatabase , SQL_CheckHim , query , datapack );
169
169
}
170
170
}
@@ -174,25 +174,25 @@ public SQL_CheckHim(Handle:owner, Handle:hndl, const String:error[], any:datapac
174
174
{
175
175
new client ;
176
176
decl String :steamid [32 ], String :IP [32 ];
177
-
177
+
178
178
if (datapack != INVALID_HANDLE )
179
179
{
180
180
client = GetClientOfUserId (ReadPackCell (datapack ));
181
181
ReadPackString (datapack , steamid , sizeof (steamid ));
182
182
ReadPackString (datapack , IP , sizeof (IP ));
183
183
CloseHandle (datapack );
184
184
}
185
-
185
+
186
186
if (hndl == INVALID_HANDLE )
187
187
{
188
188
LogError (" SourceSleuth: Database query error: %s " , error );
189
189
return ;
190
190
}
191
-
191
+
192
192
if (SQL_FetchRow (hndl ))
193
193
{
194
194
new TotalBans = SQL_GetRowCount (hndl );
195
-
195
+
196
196
if (TotalBans > g_cVar_bansAllowed .IntValue )
197
197
{
198
198
switch (g_cVar_actions .IntValue )
@@ -201,7 +201,7 @@ public SQL_CheckHim(Handle:owner, Handle:hndl, const String:error[], any:datapac
201
201
{
202
202
new length = SQL_FetchInt (hndl , 6 );
203
203
new time = length * 60 ;
204
-
204
+
205
205
BanPlayer (client , time );
206
206
}
207
207
case LENGTH_CUSTOM :
@@ -212,8 +212,14 @@ public SQL_CheckHim(Handle:owner, Handle:hndl, const String:error[], any:datapac
212
212
case LENGTH_DOUBLE :
213
213
{
214
214
new length = SQL_FetchInt (hndl , 6 );
215
- new time = length / 60 * 2 ;
216
-
215
+
216
+ new time = 0 ;
217
+
218
+ if (length != 0 )
219
+ {
220
+ time = length / 60 * 2 ;
221
+ }
222
+
217
223
BanPlayer (client , time );
218
224
}
219
225
case LENGTH_NOTIFY :
@@ -236,13 +242,13 @@ stock BanPlayer(client, time)
236
242
PrintToAdmins (const String :format [], any : ...)
237
243
{
238
244
new String :g_Buffer [256 ];
239
-
245
+
240
246
for (new i = 1 ; i <= MaxClients ; i ++ )
241
247
{
242
248
if (CheckCommandAccess (i , " sm_sourcesleuth_printtoadmins" , ADMFLAG_BAN ) && IsClientInGame (i ))
243
249
{
244
250
VFormat (g_Buffer , sizeof (g_Buffer ), format , 2 );
245
-
251
+
246
252
PrintToChat (i , " %s " , g_Buffer );
247
253
}
248
254
}
@@ -251,17 +257,17 @@ PrintToAdmins(const String:format[], any:...)
251
257
public LoadWhiteList ()
252
258
{
253
259
decl String :path [PLATFORM_MAX_PATH ], String :line [256 ];
254
-
260
+
255
261
BuildPath (Path_SM , path , PLATFORM_MAX_PATH , " configs/sourcesleuth_whitelist.cfg" );
256
-
262
+
257
263
new Handle :fileHandle = OpenFile (path , " r" );
258
-
264
+
259
265
while (! IsEndOfFile (fileHandle ) && ReadFileLine (fileHandle , line , sizeof (line )))
260
266
{
261
267
ReplaceString (line , sizeof (line ), " \n " , " " , false );
262
-
268
+
263
269
PushArrayString (g_hAllowedArray , line );
264
270
}
265
-
271
+
266
272
CloseHandle (fileHandle );
267
273
}
0 commit comments