This repository has been archived by the owner on Dec 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
smacbans-block.inc
273 lines (200 loc) · 5.78 KB
/
smacbans-block.inc
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
#if defined _smacbans_block_included
#endinput
#endif
#define _smacbans_block_included
// Taken from smlib, blame them if it's too short :3
#define MAX_STEAMAUTH_LENGTH 21
/**
* Prints a chatmessage to a all admins with a given adminflag or override.
*
* @param admflag Adminflag.
* @param format Formatting rules.
* @param ... Variable number of format parameters.
* @noreturn
*/
stock SmacbansPrintAdminNotice(admflag, const String:format[], any:...)
{
decl String:Message[192];
for(new i; i <= MaxClients; i++)
{
if(SmacbansIsClientValid(i))
{
if(CheckCommandAccess(i, "smacbans_admin", admflag, false))
{
SetGlobalTransTarget(i);
VFormat(Message, sizeof(Message), format, 3);
PrintToChat(i, Message);
}
}
}
}
/**
* Prints an debugmessage to the serverconsole and all ingame players.
*
* @param enabled Bool value to enable/disable this function.
* @param format Formatting rules.
* @param ... Variable number of format parameters.
* @noreturn
*/
stock SmacbansDebug(bool:enabled, const String:format[], any:...)
{
if(enabled)
{
decl String:Message[4096];
VFormat(Message, sizeof(Message), format, 3);
PrintToServer(Message);
PrintToChatAll(Message);
}
}
/**
* Returns if a given clientindex is within the range of being a client.
*
* @param client Client index.
* @return True if client is usable, false otherwise.
*/
stock bool:SmacbansIsClientUsable(client)
{
if(client > 0 && client <= MaxClients)
{
return true;
}
return false;
}
/**
* Returns if a given client is authorized and usable.
*
* @param client Client index.
* @return True if client is authorized and usable, false otherwise.
*/
stock bool:SmacbansIsClientUsableAuth(client)
{
if(client > 0 && client <= MaxClients && IsClientAuthorized(client))
{
return true;
}
return false;
}
/**
* Returns if a given client is valid (ingame).
*
* @param client Client index.
* @return True if client is valid, false otherwise.
*/
stock bool:SmacbansIsClientValid(client)
{
if(client > 0 && client <= MaxClients && IsClientInGame(client))
{
return true;
}
return false;
}
/**
* Finds a client matching the given AuthID.
*
* @param auth AuthID.
* @return Clientindex or -1 on failure.
*/
// Used to find a matching client to an auth
stock SmacbansGetClientFromSteamId(const String:auth[])
{
new String:clientAuth[MAX_STEAMAUTH_LENGTH];
new String:authCopy[MAX_STEAMAUTH_LENGTH];
strcopy(authCopy, sizeof(authCopy), auth);
for(new i; i <= MaxClients; i++)
{
if(SmacbansIsClientUsableAuth(i) && !IsFakeClient(i))
{
GetClientAuthString(i, clientAuth, sizeof(clientAuth));
// Convert new ID's to old format for comparison
if (StrContains(clientAuth, "[U:") == 0)
{
SteamID2ToSteamId(clientAuth, clientAuth, sizeof(clientAuth));
}
if (StrContains(authCopy, "[U:") == 0)
{
SteamID2ToSteamId(authCopy, authCopy, sizeof(authCopy));
}
if(StrEqual(authCopy, clientAuth))
{
return i;
}
}
}
return -1;
}
stock SteamID2ToSteamId(const String:steamID2[], String:dest[], max_len)
{
decl String:sTemp[MAX_STEAMAUTH_LENGTH];
strcopy(sTemp, sizeof(sTemp), steamID2);
sTemp[strlen(sTemp)] = '\0';
new temp = StringToInt(sTemp[5]);
Format(dest, max_len, "STEAM_0:%d%d", temp & 1, temp >> 1);
}
/**
* Formats an long to an dotted IP-string
*
* @param long Long ip.
* @param str String to store the ip into.
* @param maxlen Length of buffer.
* @noreturn
*/
stock SmacbansLongToIp(long, String:str[], maxlen)
{
new pieces[4];
pieces[0] = (long >>> 24 & 255);
pieces[1] = (long >>> 16 & 255);
pieces[2] = (long >>> 8 & 255);
pieces[3] = (long & 255);
Format(str, maxlen, "%d.%d.%d.%d", pieces[0], pieces[1], pieces[2], pieces[3]);
}
// Banstatus
#define BANSTATUS_UNKNOWN 0
#define BANSTATUS_NOT_BANNED 1
#define BANSTATUS_IS_BANNED 2
/**
* Called after the status of an steamid was retrieved.
* Note: It is not gauranteed that the owner of the auth is available at this time.
* [- Use the included stock to find and validate the owner of the auth.
*
* @param auth Authid response.
* @param banstatus Banstatus of the auth.
* @param banreason Banreason if banned.
* @noreturn
*/
forward SmacBans_OnSteamIDStatusRetrieved(const String:auth[], banstatus, const String:banreason[]);
/**
* Called after the status of a banned steamid was retrieved and the owner is about to be kicked.
* Note: Only gets called if kick is enabled.
* [- The client is gauranteed to be authorized at this time.
*
* @param client Client index
* @param auth Authid response.
* @param banreason Banreason if available.
* @noreturn
*/
forward SmacBans_OnSteamIDBlock(client, const String:auth[], const String:banreason[]);
/**
* Called before a clients steamid is about to be checked.
* Note: The client is gauranteed to be authorized at this time.
*
* @param client Client index
* @param auth Authid.
* @return Plugin_Handled to block the further check, Plugin_Continue otherwise.
*/
forward Action:SmacBans_OnSteamIDCheck(client, const String:auth[]);
/* Do not edit below this line */
public SharedPlugin:__pl_sbblock =
{
name = "smacbans-block",
file = "smacbans-block.smx",
#if defined REQUIRE_PLUGIN
required = 1,
#else
required = 0,
#endif
};
#if !defined REQUIRE_PLUGIN
public __pl_sbblock_SetNTVOptional()
{
}
#endif