-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathprotection.inc
848 lines (697 loc) · 22 KB
/
protection.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
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
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
/*
About: cheat protection stuff
Author: ziggi
*/
#if !defined _samp_included
#error "Please include a_samp or a_npc before protection"
#endif
#if !defined foreach
#error "Please include foreach before protection"
#endif
#if defined _protection_included
#endinput
#endif
#define _protection_included
/*
Defines
*/
#if !defined PROTECTION_TIMER_TIME
#define PROTECTION_TIMER_TIME 300
#endif
#if !defined PROTECTION_USE_STREAMER
#if defined Streamer_IncludeFileVersion
#define PROTECTION_USE_STREAMER 1
#else
#define PROTECTION_USE_STREAMER 0
#endif
#endif
#if !defined PROTECTION_CUSTOM_VENDING
#define PROTECTION_CUSTOM_VENDING 1
#endif
#if !defined PROTECTION_MAX_AVAILABLE_IDS
#define PROTECTION_MAX_AVAILABLE_IDS 100
#endif
#define PROTECTION_MAX_STRING 32
#define PROTECTION_MAX_IP 14
/*
Forward
*/
forward Protection_Timer();
forward Float:Protection_GetParamFloat(Protection:protection, ProtectionParams:param);
forward Float:Protection_GetPlayerParamFloat(playerid, Protection:protection, ProtectionPlayerParams:param);
forward Float:Protection_GetPlayerInfoFloat(playerid, ProtectionPlayerInfo:param);
forward OnPlayerGetProtectionWarning(playerid, Protection:protection, bool:warn_reached, message[]);
/*
Enums
*/
enum Protection {
PROTECTION_ALL,
PROTECTION_TELEPORT,
PROTECTION_INTERIOR,
PROTECTION_SPECIALACTION,
PROTECTION_RCON,
PROTECTION_PING,
PROTECTION_HEALTH,
PROTECTION_ARMOUR,
PROTECTION_VEHICLETELEPORT,
PROTECTION_WEAPON,
PROTECTION_MONEY,
PROTECTION_KILLFLOOD,
PROTECTION_WEAPONDAMAGE,
PROTECTION_RAPIDFIRE,
PROTECTION_BADSHOT,
PROTECTION_PICKUPPICK,
PROTECTION_VEHICLECOLOR,
PROTECTION_CAMERA,
PROTECTION_CAMERAMODE,
PROTECTION_FAKEKILL,
PROTECTION_VEHICLETUNING,
}
enum ProtectionParams {
PROTECTION_NAME[PROTECTION_MAX_STRING],
PROTECTION_FUNCTION[PROTECTION_MAX_STRING],
bool:PROTECTION_ENABLED,
PROTECTION_CHECK_DELAY,
PROTECTION_LAST_TICKCOUNT,
PROTECTION_SPAWN_DELAY,
PROTECTION_MAX_WARNINGS,
Float:PROTECTION_MAX_DISTANCE,
Float:PROTECTION_MAX_VEHICLE_DISTANCE,
PROTECTION_MAX_PING,
PROTECTION_AVAILABLE_IDS[PROTECTION_MAX_AVAILABLE_IDS],
PROTECTION_COUNTERACTION,
}
enum ProtectionPlayerParams {
bool:PROTECTION_PLAYER_DISABLED,
bool:PROTECTION_PLAYER_COUNTERACTION,
PROTECTION_PLAYER_WARNING_COUNT,
PROTECTION_PLAYER_BLOCK_UPDATE,
}
enum ProtectionPlayerInfo {
bool:PROTECTION_PLAYER_SPAWNED,
PROTECTION_PLAYER_IP[PROTECTION_MAX_IP + 1],
PROTECTION_PLAYER_PING,
PROTECTION_PLAYER_SPAWN_TICK,
}
/*
Includes
*/
#include "protection/pause"
#include "protection/teleport"
#include "protection/interior"
#include "protection/specialaction"
#include "protection/rcon"
#include "protection/ping"
#include "protection/health"
#include "protection/armour"
#include "protection/vehicleteleport"
#include "protection/weapon"
#include "protection/money"
#include "protection/killflood"
#include "protection/weapondamage"
#include "protection/rapidfire"
#include "protection/badshot"
#include "protection/pickuppick"
#include "protection/vehiclecolor"
#include "protection/camera"
#include "protection/cameramode"
#include "protection/fakekill"
#include "protection/vehicletuning"
#if PROTECTION_CUSTOM_VENDING
#include "protection/vending"
#endif
/*
Vars
*/
static
gParam[Protection][ProtectionParams],
gPlayerParam[MAX_PLAYERS][Protection][ProtectionPlayerParams],
gPlayerInfo[MAX_PLAYERS][ProtectionPlayerInfo];
static const
NULL_gPlayerParam[ProtectionPlayerParams] = {false, true, 0, 0},
NULL_gPlayerInfo[ProtectionPlayerInfo];
/*
OnGameModeInit
*/
public OnGameModeInit()
{
Protection_SetParamInt(PROTECTION_ALL, PROTECTION_CHECK_DELAY, 1000);
Protection_SetParamInt(PROTECTION_ALL, PROTECTION_MAX_WARNINGS, 3);
Protection_SetParamInt(PROTECTION_ALL, PROTECTION_SPAWN_DELAY, 600);
Protection_SetParamInt(PROTECTION_ALL, PROTECTION_COUNTERACTION, 1);
// teleport
Protection_SetParamInt(PROTECTION_TELEPORT, PROTECTION_ENABLED, 1);
Protection_SetParamString(PROTECTION_TELEPORT, PROTECTION_NAME, "Teleport");
Protection_SetParamString(PROTECTION_TELEPORT, PROTECTION_FUNCTION, "Protection_Teleport");
Protection_SetParamFloat(PROTECTION_TELEPORT, PROTECTION_MAX_VEHICLE_DISTANCE, 140.0);
Protection_SetParamFloat(PROTECTION_TELEPORT, PROTECTION_MAX_DISTANCE, 80.0);
// interior (disabled, but is automatically activated when used DisableInteriorEnterExits)
Protection_SetParamInt(PROTECTION_INTERIOR, PROTECTION_ENABLED, 0);
Protection_SetParamString(PROTECTION_INTERIOR, PROTECTION_NAME, "Interior");
// special action
Protection_SetParamInt(PROTECTION_SPECIALACTION, PROTECTION_ENABLED, 1);
Protection_SetParamString(PROTECTION_SPECIALACTION, PROTECTION_NAME, "Special action");
Protection_SetParamString(PROTECTION_SPECIALACTION, PROTECTION_FUNCTION, "Protection_SpecialAction");
// rcon
Protection_SetParamInt(PROTECTION_RCON, PROTECTION_ENABLED, 1);
Protection_SetParamString(PROTECTION_RCON, PROTECTION_NAME, "Rcon");
// ping
Protection_SetParamInt(PROTECTION_PING, PROTECTION_ENABLED, 1);
Protection_SetParamString(PROTECTION_PING, PROTECTION_NAME, "Ping");
Protection_SetParamString(PROTECTION_PING, PROTECTION_FUNCTION, "Protection_Ping");
Protection_SetParamInt(PROTECTION_PING, PROTECTION_MAX_PING, 500);
// health
Protection_SetParamInt(PROTECTION_HEALTH, PROTECTION_ENABLED, 1);
Protection_SetParamString(PROTECTION_HEALTH, PROTECTION_NAME, "Health");
Protection_SetParamString(PROTECTION_HEALTH, PROTECTION_FUNCTION, "Protection_Health");
Protection_SetParamInt(PROTECTION_HEALTH, PROTECTION_SPAWN_DELAY, 2000);
// armour
Protection_SetParamInt(PROTECTION_ARMOUR, PROTECTION_ENABLED, 1);
Protection_SetParamString(PROTECTION_ARMOUR, PROTECTION_NAME, "Armour");
Protection_SetParamString(PROTECTION_ARMOUR, PROTECTION_FUNCTION, "Protection_Armour");
// vehicleteleport
Protection_SetParamInt(PROTECTION_VEHICLETELEPORT, PROTECTION_ENABLED, 1);
Protection_SetParamString(PROTECTION_VEHICLETELEPORT, PROTECTION_NAME, "Vehicle Teleport");
Protection_SetParamFloat(PROTECTION_VEHICLETELEPORT, PROTECTION_MAX_DISTANCE, 20.0);
// weapon
Protection_SetParamInt(PROTECTION_WEAPON, PROTECTION_ENABLED, 1);
Protection_SetParamString(PROTECTION_WEAPON, PROTECTION_NAME, "Weapon");
Protection_SetParamString(PROTECTION_WEAPON, PROTECTION_FUNCTION, "Protection_Weapon");
// money
Protection_SetParamInt(PROTECTION_MONEY, PROTECTION_ENABLED, 1);
Protection_SetParamString(PROTECTION_MONEY, PROTECTION_NAME, "Money");
Protection_SetParamString(PROTECTION_MONEY, PROTECTION_FUNCTION, "Protection_Money");
Protection_SetParamInt(PROTECTION_MONEY, PROTECTION_SPAWN_DELAY, 2000);
// killflood
Protection_SetParamInt(PROTECTION_KILLFLOOD, PROTECTION_ENABLED, 1);
Protection_SetParamString(PROTECTION_KILLFLOOD, PROTECTION_NAME, "Kill Flood");
// weapondamage
Protection_SetParamInt(PROTECTION_WEAPONDAMAGE, PROTECTION_ENABLED, 0);
Protection_SetParamString(PROTECTION_WEAPONDAMAGE, PROTECTION_NAME, "Weapon Damage");
// rapidfire
Protection_SetParamInt(PROTECTION_RAPIDFIRE, PROTECTION_ENABLED, 1);
Protection_SetParamString(PROTECTION_RAPIDFIRE, PROTECTION_NAME, "Rapid Fire");
// badshot
Protection_SetParamInt(PROTECTION_BADSHOT, PROTECTION_ENABLED, 1);
Protection_SetParamString(PROTECTION_BADSHOT, PROTECTION_NAME, "Bad Shot");
// pickuppick
Protection_SetParamInt(PROTECTION_PICKUPPICK, PROTECTION_ENABLED, 1);
Protection_SetParamString(PROTECTION_PICKUPPICK, PROTECTION_NAME, "Range Pickup Pick");
Protection_SetParamFloat(PROTECTION_PICKUPPICK, PROTECTION_MAX_DISTANCE, 10.0);
// vehiclecolor
Protection_SetParamInt(PROTECTION_VEHICLECOLOR, PROTECTION_ENABLED, 1);
Protection_SetParamString(PROTECTION_VEHICLECOLOR, PROTECTION_NAME, "Vehicle Color");
// camera
Protection_SetParamInt(PROTECTION_CAMERA, PROTECTION_ENABLED, 1);
Protection_SetParamString(PROTECTION_CAMERA, PROTECTION_NAME, "Camera");
Protection_SetParamString(PROTECTION_CAMERA, PROTECTION_FUNCTION, "Protection_Camera");
Protection_SetParamFloat(PROTECTION_CAMERA, PROTECTION_MAX_DISTANCE, 80.0);
Protection_SetParamInt(PROTECTION_CAMERA, PROTECTION_SPAWN_DELAY, 2000);
// cameramode
Protection_SetParamInt(PROTECTION_CAMERAMODE, PROTECTION_ENABLED, 1);
Protection_SetParamString(PROTECTION_CAMERAMODE, PROTECTION_NAME, "Camera Mode");
Protection_SetParamString(PROTECTION_CAMERAMODE, PROTECTION_FUNCTION, "Protection_CameraMode");
Protection_SetParamArray(PROTECTION_CAMERAMODE, PROTECTION_AVAILABLE_IDS, {3, 4, 7, 8, 15, 16, 18, 22, 46, 51, 53, 55, 56, 57, 58, 59, 62, 63, 64, -1});
// fakekill
Protection_SetParamInt(PROTECTION_FAKEKILL, PROTECTION_ENABLED, 1);
Protection_SetParamString(PROTECTION_FAKEKILL, PROTECTION_NAME, "Fake Kill");
// vehicletuning
Protection_SetParamInt(PROTECTION_VEHICLETUNING, PROTECTION_ENABLED, 1);
Protection_SetParamString(PROTECTION_VEHICLETUNING, PROTECTION_NAME, "Vehicle Tuning");
// timer
SetTimer("Protection_Timer", PROTECTION_TIMER_TIME, 1);
#if defined Protection_OnGameModeInit
return Protection_OnGameModeInit();
#else
return 1;
#endif
}
#if defined _ALS_OnGameModeInit
#undef OnGameModeInit
#else
#define _ALS_OnGameModeInit
#endif
#define OnGameModeInit Protection_OnGameModeInit
#if defined Protection_OnGameModeInit
forward Protection_OnGameModeInit();
#endif
/*
OnPlayerConnect
*/
public OnPlayerConnect(playerid)
{
// reset arrays data
for (new i = 0; i < sizeof(gParam); i++) {
gPlayerParam[playerid][Protection:i] = NULL_gPlayerParam;
}
gPlayerInfo[playerid] = NULL_gPlayerInfo;
// store connect data
new
player_ip[PROTECTION_MAX_IP + 1];
GetPlayerIp(playerid, player_ip, sizeof(player_ip));
Protection_SetPlayerInfoString(playerid, PROTECTION_PLAYER_IP, player_ip);
#if defined Protection_OnPlayerConnect
return Protection_OnPlayerConnect(playerid);
#else
return 1;
#endif
}
#if defined _ALS_OnPlayerConnect
#undef OnPlayerConnect
#else
#define _ALS_OnPlayerConnect
#endif
#define OnPlayerConnect Protection_OnPlayerConnect
#if defined Protection_OnPlayerConnect
forward Protection_OnPlayerConnect(playerid);
#endif
/*
OnPlayerStateChange
*/
public OnPlayerStateChange(playerid, newstate, oldstate)
{
switch (newstate) {
case PLAYER_STATE_SPAWNED: {
Protection_SetPlayerInfoInt(playerid, PROTECTION_PLAYER_SPAWNED, 1);
Protection_SetPlayerInfoInt(playerid, PROTECTION_PLAYER_SPAWN_TICK, GetTickCount());
}
case PLAYER_STATE_WASTED, PLAYER_STATE_SPECTATING: {
Protection_SetPlayerInfoInt(playerid, PROTECTION_PLAYER_SPAWNED, 0);
}
}
// fix after killflood cheat
if (oldstate == PLAYER_STATE_WASTED) {
switch (newstate) {
case PLAYER_STATE_ONFOOT, PLAYER_STATE_DRIVER, PLAYER_STATE_PASSENGER: {
Protection_SetPlayerInfoInt(playerid, PROTECTION_PLAYER_SPAWNED, 1);
Protection_SetPlayerInfoInt(playerid, PROTECTION_PLAYER_SPAWN_TICK, GetTickCount());
}
}
}
#if defined Protection_OnPlayerStateChange
return Protection_OnPlayerStateChange(playerid, newstate, oldstate);
#else
return 1;
#endif
}
#if defined _ALS_OnPlayerStateChange
#undef OnPlayerStateChange
#else
#define _ALS_OnPlayerStateChange
#endif
#define OnPlayerStateChange Protection_OnPlayerStateChange
#if defined Protection_OnPlayerStateChange
forward Protection_OnPlayerStateChange(playerid, newstate, oldstate);
#endif
/*
OnPlayerUpdate
*/
public OnPlayerUpdate(playerid)
{
static
i,
bool:blocked;
for (i = 1; i < sizeof(gParam); i++) {
blocked = bool:Protection_GetPlayerParamInt(playerid, Protection:i, PROTECTION_PLAYER_BLOCK_UPDATE);
if (blocked) {
return 0;
}
}
#if defined Protection_OnPlayerUpdate
return Protection_OnPlayerUpdate(playerid);
#else
return 1;
#endif
}
#if defined _ALS_OnPlayerUpdate
#undef OnPlayerUpdate
#else
#define _ALS_OnPlayerUpdate
#endif
#define OnPlayerUpdate Protection_OnPlayerUpdate
#if defined Protection_OnPlayerUpdate
forward Protection_OnPlayerUpdate(playerid);
#endif
/*
OnPlayerWeaponShot
*/
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
static
i,
bool:blocked;
for (i = 1; i < sizeof(gParam); i++) {
blocked = bool:Protection_GetPlayerParamInt(playerid, Protection:i, PROTECTION_PLAYER_BLOCK_UPDATE);
if (blocked) {
return 0;
}
}
#if defined Protection_OnPlayerWeaponShot
return Protection_OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, fX, fY, fZ);
#else
return 1;
#endif
}
#if defined _ALS_OnPlayerWeaponShot
#undef OnPlayerWeaponShot
#else
#define _ALS_OnPlayerWeaponShot
#endif
#define OnPlayerWeaponShot Protection_OnPlayerWeaponShot
#if defined Protection_OnPlayerWeaponShot
forward Protection_OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ);
#endif
/*
OnUnoccupiedVehicleUpdate
*/
public OnUnoccupiedVehicleUpdate(vehicleid, playerid, passenger_seat, Float:new_x, Float:new_y, Float:new_z, Float:vel_x, Float:vel_y, Float:vel_z)
{
static
i,
bool:blocked;
for (i = 1; i < sizeof(gParam); i++) {
blocked = bool:Protection_GetPlayerParamInt(playerid, Protection:i, PROTECTION_PLAYER_BLOCK_UPDATE);
if (blocked) {
return 0;
}
}
#if defined Prot_OnUnoccupiedVehicleUpdate
return Prot_OnUnoccupiedVehicleUpdate(vehicleid, playerid, passenger_seat, new_x, new_y, new_z, vel_x, vel_y, vel_z);
#else
return 1;
#endif
}
#if defined _ALS_OnUnoccupiedVehicleUpdate
#undef OnUnoccupiedVehicleUpdate
#else
#define _ALS_OnUnoccupiedVehicleUpdate
#endif
#define OnUnoccupiedVehicleUpdate Prot_OnUnoccupiedVehicleUpdate
#if defined Prot_OnUnoccupiedVehicleUpdate
forward Prot_OnUnoccupiedVehicleUpdate(vehicleid, playerid, passenger_seat, Float:new_x, Float:new_y, Float:new_z, Float:vel_x, Float:vel_y, Float:vel_z);
#endif
/*
OnTrailerUpdate
*/
public OnTrailerUpdate(playerid, vehicleid)
{
static
i,
bool:blocked;
for (i = 1; i < sizeof(gParam); i++) {
blocked = bool:Protection_GetPlayerParamInt(playerid, Protection:i, PROTECTION_PLAYER_BLOCK_UPDATE);
if (blocked) {
return 0;
}
}
#if defined Protection_OnTrailerUpdate
return Protection_OnTrailerUpdate(playerid, vehicleid);
#else
return 1;
#endif
}
#if defined _ALS_OnTrailerUpdate
#undef OnTrailerUpdate
#else
#define _ALS_OnTrailerUpdate
#endif
#define OnTrailerUpdate Protection_OnTrailerUpdate
#if defined Protection_OnTrailerUpdate
forward Protection_OnTrailerUpdate(playerid, vehicleid);
#endif
/*
Timer
*/
public Protection_Timer()
{
static
player_ping,
Protection:current_prot,
spawn_tick,
current_tick,
last_tick,
function[PROTECTION_MAX_STRING];
current_tick = GetTickCount();
foreach (new playerid : Player) {
player_ping = GetPlayerPing(playerid);
Protection_SetPlayerInfoInt(playerid, PROTECTION_PLAYER_PING, player_ping);
spawn_tick = Protection_GetPlayerInfoInt(playerid, PROTECTION_PLAYER_SPAWN_TICK);
// spawned check
if (!Protection_GetPlayerInfoInt(playerid, PROTECTION_PLAYER_SPAWNED)) {
continue;
}
// paused check
if (Protection_IsPlayerPaused(playerid)) {
continue;
}
for (new i = 1; i < sizeof(gParam); i++) {
current_prot = Protection:i;
// spawn delay
if (Protection_GetTickDiff(current_tick, spawn_tick) < player_ping + Protection_GetParamInt(current_prot, PROTECTION_SPAWN_DELAY)) {
continue;
}
// enabled check
if (!Protection_GetParamInt(current_prot, PROTECTION_ENABLED)) {
continue;
}
// player enabled check
if (Protection_GetPlayerParamInt(playerid, current_prot, PROTECTION_PLAYER_DISABLED)) {
continue;
}
// exists check
Protection_GetParamString(current_prot, PROTECTION_FUNCTION, function);
if (funcidx(function) == -1) {
continue;
}
// delay check
last_tick = Protection_GetParamInt(current_prot, PROTECTION_LAST_TICKCOUNT);
if (Protection_GetTickDiff(current_tick, last_tick) < player_ping + Protection_GetParamInt(current_prot, PROTECTION_CHECK_DELAY)) {
continue;
}
Protection_SetParamInt(current_prot, PROTECTION_LAST_TICKCOUNT, current_tick);
// execute
CallRemoteFunction(function, "i", playerid);
}
}
return 1;
}
/*
Protection report
*/
forward _Protection_SysreqFix();
public _Protection_SysreqFix()
{
new temp[2];
format(temp, sizeof(temp), "");
}
stock Protection_GivePlayerWarning(playerid, Protection:protection, const fstring[], {Float, _}:...)
{
static
warn_max,
warn_count;
warn_max = Protection_GetParamInt(protection, PROTECTION_MAX_WARNINGS);
warn_count = Protection_GetPlayerParamInt(playerid, protection, PROTECTION_PLAYER_WARNING_COUNT);
warn_count++;
Protection_SetPlayerParamInt(playerid, protection, PROTECTION_PLAYER_WARNING_COUNT, warn_count);
// format
static const
BYTES_PER_CELL = 4,
STATIC_ARGS = 3;
static
args,
arg_start,
arg_end,
message[144];
#emit LOAD.S.pri 8
#emit STOR.pri args
if (args > STATIC_ARGS * BYTES_PER_CELL) {
#emit ADDR.pri fstring
#emit STOR.pri arg_start
for (arg_end = arg_start + (args - STATIC_ARGS * BYTES_PER_CELL); arg_end > arg_start; arg_end -= BYTES_PER_CELL) {
#emit LREF.pri arg_end
#emit PUSH.pri
}
#emit PUSH.S fstring
#emit PUSH.C 144
#emit PUSH.C message
#emit PUSH.C args
#emit SYSREQ.C format
#emit LCTRL 5
#emit SCTRL 4
CallRemoteFunction("OnPlayerGetProtectionWarning", "iiis", playerid, _:protection, warn_count >= warn_max, message);
} else {
Protection_strcpy(message, fstring);
if (message[0] == '\0') {
message[0] = '\1';
}
CallRemoteFunction("OnPlayerGetProtectionWarning", "iiis", playerid, _:protection, warn_count >= warn_max, fstring);
}
return 1;
}
/*
Integer params
*/
stock Protection_SetParamInt(Protection:protection, ProtectionParams:param, value)
{
if (protection == PROTECTION_ALL) {
for (new i = 0; i < sizeof(gParam); i++) {
gParam[Protection:i][param] = value;
}
} else {
gParam[protection][param] = value;
}
}
stock Protection_GetParamInt(Protection:protection, ProtectionParams:param)
{
return gParam[protection][param];
}
/*
Specific float params
*/
stock Protection_SetParamFloat(Protection:protection, ProtectionParams:param, Float:value)
{
if (protection == PROTECTION_ALL) {
for (new i = 0; i < sizeof(gParam); i++) {
gParam[Protection:i][param] = _:value;
}
} else {
gParam[protection][param] = _:value;
}
}
stock Float:Protection_GetParamFloat(Protection:protection, ProtectionParams:param)
{
return Float:gParam[protection][param];
}
/*
Array params
*/
stock Protection_SetParamArray(Protection:protection, ProtectionParams:param, const values[], const size = sizeof(values))
{
if (protection == PROTECTION_ALL) {
for (new i = 0; i < sizeof(gParam); i++) {
memcpy(gParam[Protection:i][param], values, 0, size * 4, PROTECTION_MAX_AVAILABLE_IDS);
}
} else {
memcpy(gParam[protection][param], values, 0, size * 4, PROTECTION_MAX_AVAILABLE_IDS);
}
}
stock Protection_GetParamArray(Protection:protection, ProtectionParams:param, values[], size = sizeof(values))
{
memcpy(values, gParam[protection][param], 0, PROTECTION_MAX_AVAILABLE_IDS, size * 4);
}
/*
String params
*/
stock Protection_SetParamString(Protection:protection, ProtectionParams:param, const value[])
{
if (protection == PROTECTION_ALL) {
for (new i = 0; i < sizeof(gParam); i++) {
Protection_strcpy(gParam[Protection:i][param], value, PROTECTION_MAX_STRING);
}
} else {
Protection_strcpy(gParam[protection][param], value, PROTECTION_MAX_STRING);
}
}
stock Protection_GetParamString(Protection:protection, ProtectionParams:param, value[], size = sizeof(value))
{
Protection_strcpy(value, gParam[protection][param], size);
}
/*
Player integer params
*/
stock Protection_SetPlayerParamInt(playerid, Protection:protection, ProtectionPlayerParams:param, value)
{
if (protection == PROTECTION_ALL) {
for (new i = 0; i < sizeof(gPlayerParam[]); i++) {
gPlayerParam[playerid][Protection:i][param] = value;
}
} else {
gPlayerParam[playerid][protection][param] = value;
}
}
stock Protection_GetPlayerParamInt(playerid, Protection:protection, ProtectionPlayerParams:param)
{
return gPlayerParam[playerid][protection][param];
}
/*
Player float params
*/
stock Protection_SetPlayerParamFloat(playerid, Protection:protection, ProtectionPlayerParams:param, Float:value)
{
if (protection == PROTECTION_ALL) {
for (new i = 0; i < sizeof(gPlayerParam[]); i++) {
gPlayerParam[playerid][Protection:i][param] = value;
}
} else {
gPlayerParam[playerid][protection][param] = value;
}
}
stock Float:Protection_GetPlayerParamFloat(playerid, Protection:protection, ProtectionPlayerParams:param)
{
return gPlayerParam[playerid][protection][param];
}
/*
Player string params
*/
stock Protection_SetPlayerParamString(playerid, Protection:protection, ProtectionPlayerParams:param, const value[])
{
if (protection == PROTECTION_ALL) {
for (new i = 0; i < sizeof(gPlayerParam[]); i++) {
Protection_strcpy(gPlayerParam[playerid][Protection:i][param], value, PROTECTION_MAX_STRING);
}
} else {
Protection_strcpy(gPlayerParam[playerid][protection][param], value, PROTECTION_MAX_STRING);
}
}
stock Protection_GetPlayerParamString(playerid, Protection:protection, ProtectionPlayerParams:param, value[], size = sizeof(value))
{
Protection_strcpy(value, gPlayerParam[playerid][protection][param], size);
}
/*
Player info integer params
*/
stock Protection_SetPlayerInfoInt(playerid, ProtectionPlayerInfo:param, value)
{
gPlayerInfo[playerid][param] = value;
}
stock Protection_GetPlayerInfoInt(playerid, ProtectionPlayerInfo:param)
{
return gPlayerInfo[playerid][param];
}
/*
Player info float params
*/
stock Protection_SetPlayerInfoFloat(playerid, ProtectionPlayerInfo:param, Float:value)
{
gPlayerInfo[playerid][param] = value;
}
stock Float:Protection_GetPlayerInfoFloat(playerid, ProtectionPlayerInfo:param)
{
return gPlayerInfo[playerid][param];
}
/*
Player info string params
*/
stock Protection_SetPlayerInfoString(playerid, ProtectionPlayerInfo:param, const value[])
{
Protection_strcpy(gPlayerInfo[playerid][param], value, PROTECTION_MAX_STRING);
}
stock Protection_GetPlayerInfoString(playerid, ProtectionPlayerInfo:param, value[], size = sizeof(value))
{
Protection_strcpy(value, gPlayerInfo[playerid][param], size);
}
/*
Tick different
*/
stock Protection_GetTickDiff(newtick, oldtick)
{
return newtick - oldtick;
}
/*
strcpy implementation
*/
stock Protection_strcpy(result[], const source[], const size = sizeof(result))
{
result[0] = 0;
return strcat(result, source, size);
}