generated from ClaudiuHKS/AdvancedQuakeSounds
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgeoip_chat_connect_announcer.sp
408 lines (305 loc) · 12.8 KB
/
geoip_chat_connect_announcer.sp
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
406
407
408
#include <sourcemod>
#include <GeoResolver>
public Plugin myinfo =
{
name = "GeoResolver: Connect Announcer" , \
author = "Hattrick HKS (claudiuhks)" , \
description = "Prints Players' Geographical Information While Joining" , \
version = __DATE__ , \
url = "https://forums.alliedmods.net/showthread.php?t=267805" ,
};
/**
* PRINTS " \x01Player\x04 HATTRİCK CARAMEL® HACK CS.MONEY\x01 joined."
*
* IF THE GEOGRAPHICAL INFORMATION HAS NOT BEEN DETECTED
*
* UNCOMMENT - '//' IF YES
* COMMENT + '//' IF NO
*/
#define SHOW_EVEN_IF_NOT_DETECTED
#define SHOW_PLAYER_DISCONNECT_CHAT /// Show?
#define SHOW_PLAYER_TEAM_CHAT /// Show?
/**
* PRINTS ONLY A MESSAGE EACH # SECONDS
*/
#define CHAT_SPAM_DELAY 4.000000
static float g_fStamp = 0.000000;
public void OnPluginStart()
{
HookEventEx("player_disconnect", OnPlrDisconnect_Pre, EventHookMode_Pre);
HookEventEx("player_disconnect_client", OnPlrDisconnect_Pre, EventHookMode_Pre);
HookEventEx("player_client_disconnect", OnPlrDisconnect_Pre, EventHookMode_Pre);
HookEventEx("player_connect", OnPlrConnect_Pre, EventHookMode_Pre);
HookEventEx("player_connect_client", OnPlrConnect_Pre, EventHookMode_Pre);
HookEventEx("player_client_connect", OnPlrConnect_Pre, EventHookMode_Pre);
HookEventEx("player_team", OnPlrTeam_Pre, EventHookMode_Pre);
g_fStamp = 0.000000;
}
public void OnMapStart()
{
g_fStamp = 0.000000;
}
public void OnMapEnd()
{
g_fStamp = 0.000000;
}
public void OnClientPutInServer(int nClient)
{
if (nClient >= 1 && nClient <= MaxClients)
{
CreateTimer(GetRandomFloat(2.250000, 4.500000) , \
displayJoinInfo , \
GetClientUserId(nClient) , \
TIMER_FLAG_NO_MAPCHANGE );
}
}
public Action displayJoinInfo(Handle hTimer, any nClientUserId)
{
static int nClient = 0;
static float fEngTime = 0.000000;
static bool bIsp = false, \
bCountry = false, \
bCity = false;
static char szCountry [PLATFORM_MAX_PATH] = "", \
szCity [PLATFORM_MAX_PATH] = "", \
szIsp [PLATFORM_MAX_PATH] = "", \
szIpAddr [PLATFORM_MAX_PATH] = "";
fEngTime = GetEngineTime();
nClient = GetClientOfUserId(nClientUserId);
if (fEngTime > g_fStamp && \
nClient >= 1 && \
nClient <= MaxClients && \
IsClientConnected (nClient) && \
IsClientInGame (nClient) && \
!IsFakeClient (nClient) && \
!IsClientSourceTV (nClient) && \
!IsClientReplay (nClient) && \
!IsClientInKickQueue (nClient) && \
!IsClientTimingOut (nClient) && \
GetClientIP (nClient, szIpAddr, sizeof(szIpAddr), true) )
{
GeoR_Country (szIpAddr, szCountry, sizeof(szCountry));
GeoR_City (szIpAddr, szCity, sizeof(szCity));
GeoR_ISP (szIpAddr, szIsp, sizeof(szIsp));
bIsp = (strcmp(szIsp, "N/ A") == 0) ? false : true;
bCountry = (strcmp(szCountry, "N/ A") == 0) ? false : true;
bCity = (strcmp(szCity, "N/ A") == 0) ? false : true;
if (bCountry && bCity && bIsp)
{
PrintToChatAll(" \x01Player\x04 %N\x01 joined from\x05 %s\x01,\x05 %s\x01.", nClient, szCity, szCountry);
}
else if (bCountry && bCity)
{
PrintToChatAll(" \x01Player\x04 %N\x01 joined from\x05 %s\x01,\x05 %s\x01.", nClient, szCity, szCountry);
}
else if (bCountry && bIsp)
{
PrintToChatAll(" \x01Player\x04 %N\x01 joined from\x05 %s\x01 [\x05 %s\x01 ].", nClient, szCountry, szIsp);
}
else if (bCity && bIsp)
{
PrintToChatAll(" \x01Player\x04 %N\x01 joined from\x05 %s\x01 [\x05 %s\x01 ].", nClient, szCity, szIsp);
}
else if (bCountry)
{
PrintToChatAll(" \x01Player\x04 %N\x01 joined from\x05 %s\x01.", nClient, szCountry);
}
else if (bCity)
{
PrintToChatAll(" \x01Player\x04 %N\x01 joined from\x05 %s\x01.", nClient, szCity);
}
else if (bIsp)
{
PrintToChatAll(" \x01Player\x04 %N\x01 joined [\x05 %s\x01 ].", nClient, szIsp);
}
#if defined SHOW_EVEN_IF_NOT_DETECTED
else
{
PrintToChatAll(" \x01Player\x04 %N\x01 joined.", nClient);
}
#endif
g_fStamp = fEngTime + CHAT_SPAM_DELAY;
}
return Plugin_Continue;
}
public void OnPlrConnect_Pre(Handle hEv, const char[] szEvName, bool bEvNoBC)
{
if (hEv != INVALID_HANDLE)
{
if (bEvNoBC == false)
{
SetEventBroadcast(hEv, true);
}
}
}
public void OnPlrDisconnect_Pre(Handle hEv, const char[] szEvName, bool bEvNoBC)
{
#if defined SHOW_PLAYER_DISCONNECT_CHAT
static Handle hPack = INVALID_HANDLE;
static char szName[PLATFORM_MAX_PATH] = { 0, ... };
static char szReason[PLATFORM_MAX_PATH] = { 0, ... };
static char szRandom[PLATFORM_MAX_PATH] = { 0, ... };
static bool bGenerated = false;
if (bGenerated == false)
{
bGenerated = true;
const int nRandomStringLen = 16;
for (int nIter = 0; nIter < nRandomStringLen; nIter++)
{
switch (GetRandomInt(0, 2))
{
case 0:
{
Format(szRandom, sizeof (szRandom), "%s%c", szRandom, GetRandomInt('a', 'z'));
}
case 1:
{
Format(szRandom, sizeof (szRandom), "%s%c", szRandom, GetRandomInt('A', 'Z'));
}
case 2:
{
Format(szRandom, sizeof (szRandom), "%s%c", szRandom, GetRandomInt('0', '9'));
}
}
}
szRandom[nRandomStringLen] = '\0';
}
#endif
if (hEv != INVALID_HANDLE)
{
if (bEvNoBC == false)
{
SetEventBroadcast(hEv, true);
}
#if defined SHOW_PLAYER_DISCONNECT_CHAT
GetEventString(hEv, "name", szName, sizeof (szName), szRandom);
if (strcmp(szName, szRandom, true))
{
GetEventString(hEv, "reason", szReason, sizeof (szReason), szRandom);
if (strcmp(szReason, szRandom, true))
{
hPack = CreateDataPack();
if (hPack != INVALID_HANDLE)
{
WritePackString(hPack, szName);
WritePackString(hPack, szReason);
CreateTimer(GetRandomFloat(0.100000, 1.500000), Timer_Left, hPack, TIMER_FLAG_NO_MAPCHANGE | TIMER_DATA_HNDL_CLOSE);
}
}
}
#endif
}
}
public void OnPlrTeam_Pre(Handle hEv, const char[] szEvName, bool bEvNoBC)
{
#if defined SHOW_PLAYER_TEAM_CHAT
static Handle hPack = INVALID_HANDLE;
static int nClientUserId = 0;
static int nTeam = 0;
#endif
if (hEv != INVALID_HANDLE)
{
if (bEvNoBC == false)
{
SetEventBroadcast(hEv, true);
}
#if defined SHOW_PLAYER_TEAM_CHAT
nClientUserId = GetEventInt(hEv, "userid", -8192);
if (nClientUserId != -8192)
{
nTeam = GetEventInt(hEv, "team", 0);
if (nTeam > 0)
{
hPack = CreateDataPack();
if (hPack != INVALID_HANDLE)
{
WritePackCell(hPack, nClientUserId);
WritePackCell(hPack, nTeam);
CreateTimer(GetRandomFloat(0.100000, 1.500000), Timer_TeamJoin, hPack, TIMER_FLAG_NO_MAPCHANGE | TIMER_DATA_HNDL_CLOSE);
}
}
}
#endif
}
}
#if defined SHOW_PLAYER_TEAM_CHAT
public Action Timer_TeamJoin(Handle hTimer, any hPack)
{
static int nClientUserId = 0;
static int nClient = 0;
static int nTeam = 0;
static float fEngTime = 0.0;
fEngTime = GetEngineTime();
if (fEngTime > g_fStamp)
{
if (hPack != INVALID_HANDLE)
{
ResetPack(hPack);
nClientUserId = ReadPackCell(hPack);
nClient = GetClientOfUserId(nClientUserId);
if (nClient >= 1 && nClient <= MaxClients)
{
if (IsClientConnected(nClient) && IsClientInGame(nClient))
{
nTeam = ReadPackCell(hPack);
switch (nTeam)
{
case 1:
{
PrintToChatAll(" \x01Player\x05 %N\x01 became a\x08 spectator\x01.", nClient);
g_fStamp = fEngTime + CHAT_SPAM_DELAY;
}
case 2:
{
PrintToChatAll(" \x01Player\x05 %N\x01 became a\x07 terrorist\x01.", nClient);
g_fStamp = fEngTime + CHAT_SPAM_DELAY;
}
case 3:
{
PrintToChatAll(" \x01Player\x05 %N\x01 became a\x0B counter terrorist\x01.", nClient);
g_fStamp = fEngTime + CHAT_SPAM_DELAY;
}
}
}
}
}
}
return Plugin_Continue;
}
#endif
#if defined SHOW_PLAYER_DISCONNECT_CHAT
public Action Timer_Left(Handle hTimer, any hPack)
{
static char szName[PLATFORM_MAX_PATH] = { 0, ... };
static char szReason[PLATFORM_MAX_PATH] = { 0, ... };
static char szNewReason[PLATFORM_MAX_PATH] = { 0, ... };
static float fEngTime = 0.0;
static int nIter = 0;
static int nNewReasonLen = 0;
fEngTime = GetEngineTime();
if (fEngTime > g_fStamp)
{
if (hPack != INVALID_HANDLE)
{
ResetPack(hPack);
ReadPackString(hPack, szName, sizeof (szName));
ReadPackString(hPack, szReason, sizeof (szReason));
nNewReasonLen = 0;
for (nIter = 0; nIter < strlen(szReason); nIter++)
{
if (szReason[nIter] == ' ' || IsCharAlpha(szReason[nIter]) || IsCharNumeric(szReason[nIter]))
{
szNewReason[nNewReasonLen] = CharToLower(szReason[nIter]);
nNewReasonLen++;
}
}
szNewReason[nNewReasonLen] = '\0';
ReplaceString(szNewReason, sizeof (szNewReason), " ", " ", true);
TrimString(szNewReason);
PrintToChatAll(" \x01Player\x05 %s\x01 left,\x09 %s\x01.", szName, szNewReason);
g_fStamp = fEngTime + CHAT_SPAM_DELAY;
}
}
return Plugin_Continue;
}
#endif