This repository was archived by the owner on Sep 28, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathinflux_core.sp
More file actions
3146 lines (2248 loc) · 81.3 KB
/
influx_core.sp
File metadata and controls
3146 lines (2248 loc) · 81.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
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
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <cstrike>
#include <regex>
#include <influx/core>
#include <msharedutil/arrayvec>
#include <msharedutil/ents>
#include <msharedutil/misc>
#undef REQUIRE_PLUGIN
#include <adminmenu>
#include <influx/recordsmenu>
#include <influx/help>
#include <influx/pause>
#include <influx/practise>
#include <influx/zones_freestyle>
#include <influx/hud_draw>
//#include <influx/colorchat>
// Uncomment this to test out SQL performance on map start.
//#define DISABLE_CREATE_SQL_TABLES bool _bUseless = true; if ( _bUseless ) return;
//#define DEBUG
//#define DEBUG_TIMER
//#define DEBUG_WEPSPD
//#define DEBUG_PARSESEARCH
//#define DEBUG_COLORCHAT
//#define DEBUG_DB
//#define DEBUG_DB_VER
//#define DEBUG_DB_CBRECS
//#define DEBUG_DB_MAPID
//#define DEBUG_DB_RUN
//#define TEST_REGEX
//#define TEST_MODESTYLES
#define GAME_CONFIG_FILE "influx.games"
#define INF_UPDATE_CMD "sm_updateinfluxdb"
// Don't change these, change the cvars instead.
#define DEF_CHATPREFIX "{GREY}[{PINK}"...INF_NAME..."{GREY}]"
#define DEF_CHATCLR "{WHITE}"
#define DEF_VALIDMAPNAMES "^(surf\\_|bhop\\_|kz\\_)\\w+"
#define INVALID_MAXSPEED -1.0
// PLAYER STUFF
int g_iRunId[INF_MAXPLAYERS];
int g_iStyleId[INF_MAXPLAYERS];
int g_iModeId[INF_MAXPLAYERS];
int g_iRunStartTick[INF_MAXPLAYERS];
RunState_t g_iRunState[INF_MAXPLAYERS];
int g_iWantedStyleId[INF_MAXPLAYERS];
int g_iWantedModeId[INF_MAXPLAYERS];
float g_flFinishedTime[INF_MAXPLAYERS];
// PLAYER DATABASE RELATED STUFF
int g_iClientId[INF_MAXPLAYERS];
bool g_bCachedTimes[INF_MAXPLAYERS];
// PLAYER CACHE
float g_cache_flPBTime[INF_MAXPLAYERS];
float g_cache_flBestTime[INF_MAXPLAYERS];
char g_cache_szBestName[INF_MAXPLAYERS][MAX_BEST_NAME];
char g_cache_szRunName[INF_MAXPLAYERS][MAX_RUN_NAME];
float g_cache_flMaxSpeed[INF_MAXPLAYERS];
//char g_cache_szModeName[INF_MAXPLAYERS][MAX_NAME_LENGTH];
//char g_cache_szStyleName[INF_MAXPLAYERS][MAX_NAME_LENGTH];
// PLAYER MISC.
float g_flNextStyleGroundCheck[INF_MAXPLAYERS];
float g_flFinishBest[INF_MAXPLAYERS];
float g_flJoinTime[INF_MAXPLAYERS];
float g_flNextMenuTime[INF_MAXPLAYERS];
// ANTI-SPAM
float g_flNextWepSpdPrintTime[INF_MAXPLAYERS];
float g_flLastValidWepSpd[INF_MAXPLAYERS];
// CHAT COLOR
char g_szChatPrefix[128];
char g_szChatClr[64];
ArrayList g_hChatClrs;
int g_nChatClrLen;
ArrayList g_hRuns;
ArrayList g_hModes;
ArrayList g_hStyles;
ArrayList g_hRunResFlags;
// FORWARDS
Handle g_hForward_OnTimerStart;
Handle g_hForward_OnTimerStartPost;
Handle g_hForward_OnTimerFinish;
Handle g_hForward_OnTimerFinishPost;
Handle g_hForward_OnTimerResetPost;
Handle g_hForward_OnPreRunLoad;
Handle g_hForward_OnPostRunLoad;
Handle g_hForward_OnRecordRemoved;
Handle g_hForward_OnClientIdRetrieved;
Handle g_hForward_OnMapIdRetrieved;
Handle g_hForward_OnPostRecordsLoad;
Handle g_hForward_OnRunCreated;
Handle g_hForward_OnRunDeleted;
Handle g_hForward_OnRunLoad;
Handle g_hForward_OnRunSave;
Handle g_hForward_OnClientStatusChanged;
Handle g_hForward_OnClientModeChange;
Handle g_hForward_OnClientModeChangePost;
Handle g_hForward_OnClientStyleChange;
Handle g_hForward_OnClientStyleChangePost;
//Handle g_hForward_OnRequestRuns;
Handle g_hForward_OnRequestModes;
Handle g_hForward_OnRequestStyles;
Handle g_hForward_OnRequestResultFlags;
Handle g_hForward_OnCheckClientStyle;
Handle g_hForward_OnSearchType;
Handle g_hForward_OnSearchTelePos;
// FUNCS
Handle g_hFunc_GetPlayerMaxSpeed;
// CONVARS
ConVar g_ConVar_AirAccelerate;
#if !defined PRE_ORANGEBOX
ConVar g_ConVar_EnableBunnyhopping;
#endif
ConVar g_ConVar_ChatPrefix;
ConVar g_ConVar_ChatClr;
ConVar g_ConVar_ChatMainClr1;
ConVar g_ConVar_SaveRunsOnMapEnd;
ConVar g_ConVar_PreferDb;
ConVar g_ConVar_SuppressMaxSpdWarning;
ConVar g_ConVar_SuppressMaxSpdMsg;
ConVar g_ConVar_DefMode;
ConVar g_ConVar_DefStyle;
ConVar g_ConVar_DefMaxWeaponSpeed;
ConVar g_ConVar_LadderFreestyle;
ConVar g_ConVar_TeleToStart;
ConVar g_ConVar_TeleOnStyleChange;
ConVar g_ConVar_ModeActAsStyle;
ConVar g_ConVar_ValidMapNames;
Regex g_Regex_ValidMapNames;
// LIBRARIES
bool g_bLib_AdminMenu;
bool g_bLib_Pause;
bool g_bLib_Practise;
bool g_bLib_Zones_Fs;
bool g_bLib_Hud_Draw;
// MAP DATA
char g_szCurrentMap[128];
int g_iCurMapId;
bool g_bNewMapId;
//bool g_bRunsLoaded;
bool g_bBestTimesCached;
// Cached id.
int g_iDefMode;
int g_iDefStyle;
//bool g_bHasLoadedAllData;
// MISC
bool g_bIsCSGO;
bool g_bLate;
int g_iCurDBVersion;
// ADMIN MENU
TopMenu g_hTopMenu;
TopMenuObject g_InfluxAdminMenu = INVALID_TOPMENUOBJECT;
#include "influx_core/modestyle_ovrs.sp"
#include "influx_core/cmds.sp"
#include "influx_core/colorchat.sp"
#include "influx_core/db_sql_queries.sp"
#include "influx_core/db.sp"
#include "influx_core/db_cb.sp"
#include "influx_core/events.sp"
#include "influx_core/file.sp"
#include "influx_core/menus.sp"
#include "influx_core/menus_hndlrs.sp"
#include "influx_core/menus_admin.sp"
#include "influx_core/menus_hndlrs_admin.sp"
#include "influx_core/natives.sp"
#include "influx_core/natives_chat.sp"
#include "influx_core/runcmd.sp"
public Plugin myinfo =
{
author = INF_AUTHOR,
url = INF_URL,
name = INF_NAME..." - Core",
description = "Core of "...INF_NAME,
version = INF_VERSION
};
public APLRes AskPluginLoad2( Handle hPlugin, bool late, char[] szError, int error_len )
{
EngineVersion eng = GetEngineVersion();
if ( eng != Engine_CSS && eng != Engine_CSGO )
{
char szFolder[32];
GetGameFolderName( szFolder, sizeof( szFolder ) );
FormatEx( szError, error_len, INF_NAME..." does not support %s!", szFolder );
return APLRes_Failure;
}
g_bLate = late;
// LIBRARIES
RegPluginLibrary( INFLUX_LIB_CORE );
// NATIVES
CreateNative( "Influx_GetDB", Native_GetDB );
CreateNative( "Influx_IsMySQL", Native_IsMySQL );
CreateNative( "Influx_GetPostRunLoadForward", Native_GetPostRunLoadForward );
// In natives_chat.sp
CreateNative( "Influx_PrintToChat", Native_PrintToChat );
CreateNative( "Influx_PrintToChatAll", Native_PrintToChatAll );
CreateNative( "Influx_PrintToChatEx", Native_PrintToChatEx );
CreateNative( "Influx_RemoveChatColors", Native_RemoveChatColors );
CreateNative( "Influx_FormatChatColors", Native_FormatChatColors );
CreateNative( "Influx_StartTimer", Native_StartTimer );
CreateNative( "Influx_FinishTimer", Native_FinishTimer );
CreateNative( "Influx_ResetTimer", Native_ResetTimer );
CreateNative( "Influx_TeleportToStart", Native_TeleportToStart );
CreateNative( "Influx_IsClientCached", Native_IsClientCached );
CreateNative( "Influx_GetClientId", Native_GetClientId );
CreateNative( "Influx_GetCurrentMapId", Native_GetCurrentMapId );
CreateNative( "Influx_InvalidateClientRun", Native_InvalidateClientRun );
CreateNative( "Influx_GetClientRunId", Native_GetClientRunId );
CreateNative( "Influx_SetClientRun", Native_SetClientRun );
CreateNative( "Influx_GetClientMode", Native_GetClientMode );
CreateNative( "Influx_SetClientMode", Native_SetClientMode );
CreateNative( "Influx_GetClientStyle", Native_GetClientStyle );
CreateNative( "Influx_SetClientStyle", Native_SetClientStyle );
CreateNative( "Influx_SetClientStyleEx", Native_SetClientStyleEx );
CreateNative( "Influx_GetClientState", Native_GetClientState );
CreateNative( "Influx_SetClientState", Native_SetClientState );
CreateNative( "Influx_GetClientTime", Native_GetClientTime );
CreateNative( "Influx_GetClientFinishedTime", Native_GetClientFinishedTime );
CreateNative( "Influx_GetClientFinishedBestTime", Native_GetClientFinishedBestTime );
CreateNative( "Influx_GetClientStartTick", Native_GetClientStartTick );
CreateNative( "Influx_SetClientStartTick", Native_SetClientStartTick );
CreateNative( "Influx_GetClientPB", Native_GetClientPB );
CreateNative( "Influx_GetClientCurrentPB", Native_GetClientCurrentPB );
CreateNative( "Influx_GetClientCurrentBestTime", Native_GetClientCurrentBestTime );
CreateNative( "Influx_GetClientCurrentBestName", Native_GetClientCurrentBestName );
CreateNative( "Influx_GetRunBestTime", Native_GetRunBestTime );
CreateNative( "Influx_FindRunById", Native_FindRunById );
CreateNative( "Influx_GetRunsArray", Native_GetRunsArray );
CreateNative( "Influx_GetModesArray", Native_GetModesArray );
CreateNative( "Influx_GetStylesArray", Native_GetStylesArray );
CreateNative( "Influx_GetRunName", Native_GetRunName );
CreateNative( "Influx_GetModeName", Native_GetModeName );
CreateNative( "Influx_GetModeShortName", Native_GetModeShortName );
CreateNative( "Influx_GetModeSafeName", Native_GetModeSafeName );
CreateNative( "Influx_GetStyleName", Native_GetStyleName );
CreateNative( "Influx_GetStyleShortName", Native_GetStyleShortName );
CreateNative( "Influx_GetStyleSafeName", Native_GetStyleSafeName );
CreateNative( "Influx_ShouldModeDisplay", Native_ShouldModeDisplay );
CreateNative( "Influx_ShouldStyleDisplay", Native_ShouldStyleDisplay );
CreateNative( "Influx_AddRun", Native_AddRun );
CreateNative( "Influx_AddStyle", Native_AddStyle );
CreateNative( "Influx_AddMode", Native_AddMode );
CreateNative( "Influx_AddResultFlag", Native_AddResultFlag );
CreateNative( "Influx_RemoveMode", Native_RemoveMode );
CreateNative( "Influx_RemoveStyle", Native_RemoveStyle );
CreateNative( "Influx_SearchType", Native_SearchType );
CreateNative( "Influx_SearchTelePos", Native_SearchTelePos );
CreateNative( "Influx_IsValidMapName", Native_IsValidMapName );
return APLRes_Success;
}
public void OnPluginStart()
{
g_bIsCSGO = ( GetEngineVersion() == Engine_CSGO );
g_hRuns = new ArrayList( RUN_SIZE );
g_hModes = new ArrayList( MODE_SIZE );
g_hStyles = new ArrayList( STYLE_SIZE );
g_hRunResFlags = new ArrayList( RUNRES_SIZE );
g_hChatClrs = new ArrayList( CLR_SIZE );
g_hModeOvers = new ArrayList( MOVR_SIZE );
g_hStyleOvers = new ArrayList( SOVR_SIZE );
ReadGameConfig();
ReadModeOverrides();
ReadStyleOverrides();
// CONVAR CHANGES
if ( (g_ConVar_AirAccelerate = FindConVar( "sv_airaccelerate" )) == null )
{
SetFailState( INF_CON_PRE..."Couldn't find handle for sv_airaccelerate!" );
}
#if !defined PRE_ORANGEBOX
if ( (g_ConVar_EnableBunnyhopping = FindConVar( "sv_enablebunnyhopping" )) == null )
{
SetFailState( INF_CON_PRE..."Couldn't find handle for sv_enablebunnyhopping!" );
}
#endif
// FORWARDS
g_hForward_OnTimerStart = CreateGlobalForward( "Influx_OnTimerStart", ET_Hook, Param_Cell, Param_Cell, Param_String, Param_Cell );
g_hForward_OnTimerStartPost = CreateGlobalForward( "Influx_OnTimerStartPost", ET_Ignore, Param_Cell, Param_Cell );
g_hForward_OnTimerFinish = CreateGlobalForward( "Influx_OnTimerFinish", ET_Hook, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_String, Param_Cell );
g_hForward_OnTimerFinishPost = CreateGlobalForward( "Influx_OnTimerFinishPost", ET_Ignore, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell );
g_hForward_OnTimerResetPost = CreateGlobalForward( "Influx_OnTimerResetPost", ET_Ignore, Param_Cell );
g_hForward_OnRecordRemoved = CreateGlobalForward( "Influx_OnRecordRemoved", ET_Ignore, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell );
g_hForward_OnClientIdRetrieved = CreateGlobalForward( "Influx_OnClientIdRetrieved", ET_Ignore, Param_Cell, Param_Cell, Param_Cell );
g_hForward_OnMapIdRetrieved = CreateGlobalForward( "Influx_OnMapIdRetrieved", ET_Ignore, Param_Cell, Param_Cell );
g_hForward_OnPostRecordsLoad = CreateGlobalForward( "Influx_OnPostRecordsLoad", ET_Ignore );
g_hForward_OnPreRunLoad = CreateGlobalForward( "Influx_OnPreRunLoad", ET_Ignore );
g_hForward_OnPostRunLoad = CreateGlobalForward( "Influx_OnPostRunLoad", ET_Ignore );
g_hForward_OnRunCreated = CreateGlobalForward( "Influx_OnRunCreated", ET_Ignore, Param_Cell );
g_hForward_OnRunDeleted = CreateGlobalForward( "Influx_OnRunDeleted", ET_Ignore, Param_Cell );
g_hForward_OnRunLoad = CreateGlobalForward( "Influx_OnRunLoad", ET_Ignore, Param_Cell, Param_Cell );
g_hForward_OnRunSave = CreateGlobalForward( "Influx_OnRunSave", ET_Ignore, Param_Cell, Param_Cell );
g_hForward_OnClientStatusChanged = CreateGlobalForward( "Influx_OnClientStatusChanged", ET_Ignore, Param_Cell );
g_hForward_OnClientModeChange = CreateGlobalForward( "Influx_OnClientModeChange", ET_Event, Param_Cell, Param_Cell, Param_Cell );
g_hForward_OnClientModeChangePost = CreateGlobalForward( "Influx_OnClientModeChangePost", ET_Ignore, Param_Cell, Param_Cell, Param_Cell );
g_hForward_OnClientStyleChange = CreateGlobalForward( "Influx_OnClientStyleChange", ET_Event, Param_Cell, Param_Cell, Param_Cell );
g_hForward_OnClientStyleChangePost = CreateGlobalForward( "Influx_OnClientStyleChangePost", ET_Ignore, Param_Cell, Param_Cell, Param_Cell );
g_hForward_OnRequestModes = CreateGlobalForward( "Influx_OnRequestModes", ET_Ignore );
g_hForward_OnRequestStyles = CreateGlobalForward( "Influx_OnRequestStyles", ET_Ignore );
g_hForward_OnRequestResultFlags = CreateGlobalForward( "Influx_OnRequestResultFlags", ET_Ignore );
g_hForward_OnCheckClientStyle = CreateGlobalForward( "Influx_OnCheckClientStyle", ET_Hook, Param_Cell, Param_Cell, Param_Array );
g_hForward_OnSearchType = CreateGlobalForward( "Influx_OnSearchType", ET_Hook, Param_String, Param_CellByRef, Param_CellByRef );
g_hForward_OnSearchTelePos = CreateGlobalForward( "Influx_OnSearchTelePos", ET_Hook, Param_Array, Param_CellByRef, Param_Cell, Param_Cell );
// PHRASES
LoadTranslations( INFLUX_PHRASES );
// CONVARS
CreateConVar( "influx_version", INF_VERSION, "Version of Influx. Do not change.", FCVAR_NOTIFY );
g_ConVar_ChatPrefix = CreateConVar( "influx_chatprefix", DEF_CHATPREFIX, "Prefix for chat messages.", FCVAR_NOTIFY );
g_ConVar_ChatPrefix.AddChangeHook( E_ConVarChanged_Prefix );
g_ConVar_ChatClr = CreateConVar( "influx_chatcolor", DEF_CHATCLR, "Default chat color.", FCVAR_NOTIFY );
g_ConVar_ChatClr.AddChangeHook( E_ConVarChanged_ChatClr );
g_ConVar_ChatMainClr1 = CreateConVar( "influx_chatmainclr1", "{SKYBLUE}", "Override main color. This is used to highlight text. Eg Noclip: \"ON\"", FCVAR_NOTIFY );
g_ConVar_ChatMainClr1.AddChangeHook( E_ConVarChanged_ChatMainClr1 );
g_ConVar_SaveRunsOnMapEnd = CreateConVar( "influx_core_saveruns", "1", "Do we automatically save runs on map end?", FCVAR_NOTIFY, true, 0.0, true, 1.0 );
g_ConVar_PreferDb = CreateConVar( "influx_core_preferdb", "1", "Is database preferred method of saving runs?", FCVAR_NOTIFY, true, 0.0, true, 1.0 );
g_ConVar_SuppressMaxSpdMsg = CreateConVar( "influx_core_suppressmaxwepspdmsg", "0", "Suppress player max weapon speed message? (one printed to client)", FCVAR_NOTIFY, true, 0.0, true, 1.0 );
g_ConVar_SuppressMaxSpdWarning = CreateConVar( "influx_core_suppressmaxwepspdwarning", "0", "Suppress player max weapon speed warning? (one printed to console)", FCVAR_NOTIFY, true, 0.0, true, 1.0 );
g_ConVar_DefMode = CreateConVar( "influx_defaultmode", "auto", "Default mode. Recommended to not change.", FCVAR_NOTIFY );
g_ConVar_DefMode.AddChangeHook( E_ConVarChanged_DefMode );
g_iDefMode = MODE_AUTO;
g_ConVar_DefStyle = CreateConVar( "influx_defaultstyle", "normal", "Default style. Recommended to not change.", FCVAR_NOTIFY );
g_ConVar_DefStyle.AddChangeHook( E_ConVarChanged_DefStyle );
g_iDefStyle = STYLE_NORMAL;
g_ConVar_DefMaxWeaponSpeed = CreateConVar( "influx_default_maxwepspd", "250", "Default maximum weapon speed. Max weapon speed is controlled by modes.", FCVAR_NOTIFY, true, 0.0 );
g_ConVar_LadderFreestyle = CreateConVar( "influx_ladderfreestyle", "1", "Whether to allow freestyle on ladders.", FCVAR_NOTIFY, true, 0.0, true, 1.0 );
g_ConVar_TeleToStart = CreateConVar( "influx_teletostartonspawn", "1", "0 = Never teleport when spawning, 1 = Only teleport if no spawnpoints are found, 2 = Always teleport to start.", FCVAR_NOTIFY, true, 0.0, true, 2.0 );
g_ConVar_TeleOnStyleChange = CreateConVar( "influx_teleonstylechange", "1", "Do we teleport player to start on style/mode change?", FCVAR_NOTIFY, true, 0.0, true, 1.0 );
g_ConVar_ModeActAsStyle = CreateConVar( "influx_modeactstyle", "0", "If true, changing your mode/style will set your mode/style to default, effectively making all modes into a style. (working like other timers where you can't have 400vel hsw, etc.)", FCVAR_NOTIFY, true, 0.0, true, 1.0 );
g_ConVar_ValidMapNames = CreateConVar( "influx_core_validmapnames", DEF_VALIDMAPNAMES, "Regular expression of all valid map names. Players can only search for these maps." );
g_ConVar_ValidMapNames.AddChangeHook( E_ConVarChanged_ValidMapNames );
SetMapNameRegex();
AutoExecConfig( true, "core", "influx" );
// PRIVILEGE CMDS
RegAdminCmd( INF_PRIVCOM_REMOVERECORDS, Cmd_Empty, ADMFLAG_ROOT );
RegAdminCmd( INF_PRIVCOM_RUNSETTINGS, Cmd_Empty, ADMFLAG_ROOT );
// MENUS
RegConsoleCmd( "sm_influx", Cmd_Credits );
//RegConsoleCmd( "sm_credits", Cmd_Credits );
RegConsoleCmd( "sm_mode", Cmd_Change_Mode );
RegConsoleCmd( "sm_modes", Cmd_Change_Mode );
RegConsoleCmd( "sm_style", Cmd_Change_Style );
RegConsoleCmd( "sm_styles", Cmd_Change_Style );
// ADMIN MENUS
RegConsoleCmd( "sm_manageruns", Cmd_Admin_RunMenu );
RegConsoleCmd( "sm_runmenu", Cmd_Admin_RunMenu );
RegConsoleCmd( "sm_runsettings", Cmd_Admin_RunSettings );
RegConsoleCmd( "sm_deleterecords", Cmd_Admin_DeleteRecords );
RegConsoleCmd( "sm_deleterunsmenu", Cmd_Admin_DeleteRunMenu );
RegConsoleCmd( "sm_deleterunmenu", Cmd_Admin_DeleteRunMenu );
// ADMIN CMDS
RegAdminCmd( INF_UPDATE_CMD, Cmd_UpdateDB, ADMFLAG_ROOT );
RegAdminCmd( "sm_reloadoverrides", Cmd_ReloadOverrides, ADMFLAG_ROOT );
RegConsoleCmd( "sm_saveruns", Cmd_Admin_SaveRuns );
RegConsoleCmd( "sm_setrunname", Cmd_Admin_SetRunName );
RegConsoleCmd( "sm_settelepos", Cmd_Admin_SetTelePos );
RegConsoleCmd( "sm_deleteruns", Cmd_Admin_DeleteRun );
RegConsoleCmd( "sm_deleterun", Cmd_Admin_DeleteRun );
#if defined TEST_MODESTYLES
RegAdminCmd( "sm_printstyles", Cmd_TestPrintStyles, ADMFLAG_ROOT );
#endif
#if defined TEST_COLORCHAT
RegAdminCmd( "sm_testchat", Cmd_TestColor, ADMFLAG_ROOT );
RegAdminCmd( "sm_testchatremove", Cmd_TestColorRemove, ADMFLAG_ROOT );
#endif
#if defined TEST_REGEX
RegAdminCmd( "sm_testmapname", Cmd_TestMapName, ADMFLAG_ROOT );
#endif
// EVENTS
HookEvent( "player_spawn", E_PlayerSpawn );
// LIBRARIES
g_bLib_AdminMenu = LibraryExists( "adminmenu" );
g_bLib_Pause = LibraryExists( INFLUX_LIB_PAUSE );
g_bLib_Practise = LibraryExists( INFLUX_LIB_PRACTISE );
g_bLib_Zones_Fs = LibraryExists( INFLUX_LIB_ZONES_FS );
g_bLib_Hud_Draw = LibraryExists( INFLUX_LIB_HUD_DRAW );
DB_Init();
if ( g_bLate )
{
for ( int i = 1; i <= MaxClients; i++ )
{
if ( IsClientInGame( i ) )
{
ResetClient( i );
}
}
// Register admin menu late.
TopMenu topmenu;
if ( g_bLib_AdminMenu && (topmenu = GetAdminTopMenu()) != null )
{
OnAdminMenuCreated( topmenu );
OnAdminMenuReady( topmenu );
}
}
}
public void OnPluginEnd()
{
UpdateCvars( true );
if ( g_bLib_AdminMenu && g_hTopMenu != null && g_InfluxAdminMenu != INVALID_TOPMENUOBJECT )
{
g_hTopMenu.Remove( g_InfluxAdminMenu );
}
g_hTopMenu = null;
g_InfluxAdminMenu = INVALID_TOPMENUOBJECT;
}
public void OnLibraryAdded( const char[] lib )
{
if ( StrEqual( lib, "adminmenu" ) ) g_bLib_AdminMenu = true;
if ( StrEqual( lib, INFLUX_LIB_PAUSE ) ) g_bLib_Pause = true;
if ( StrEqual( lib, INFLUX_LIB_PRACTISE ) ) g_bLib_Practise = true;
if ( StrEqual( lib, INFLUX_LIB_ZONES_FS ) ) g_bLib_Zones_Fs = true;
if ( StrEqual( lib, INFLUX_LIB_HUD_DRAW ) ) g_bLib_Hud_Draw = true;
}
public void OnLibraryRemoved( const char[] lib )
{
if ( StrEqual( lib, "adminmenu" ) ) g_bLib_AdminMenu = false;
if ( StrEqual( lib, INFLUX_LIB_PAUSE ) ) g_bLib_Pause = false;
if ( StrEqual( lib, INFLUX_LIB_PRACTISE ) ) g_bLib_Practise = false;
if ( StrEqual( lib, INFLUX_LIB_ZONES_FS ) ) g_bLib_Zones_Fs = false;
if ( StrEqual( lib, INFLUX_LIB_HUD_DRAW ) ) g_bLib_Hud_Draw = false;
}
public void OnAllPluginsLoaded()
{
//g_hModes.Clear();
//g_hStyles.Clear();
g_hRunResFlags.Clear();
AddResultFlag( "Don't save record", RES_TIME_DONTSAVE );
// Request modes and styles.
if ( g_bLate )
{
Call_StartForward( g_hForward_OnRequestModes );
Call_Finish();
Call_StartForward( g_hForward_OnRequestStyles );
Call_Finish();
}
Call_StartForward( g_hForward_OnRequestResultFlags );
Call_Finish();
/*
if ( !g_hStyles.Length )
{
SetFailState( INF_CON_PRE..."No styles were found!" );
}
if ( !g_hModes.Length )
{
g_ConVar_AirAccelerate.Flags |= (FCVAR_NOTIFY | FCVAR_REPLICATED);
g_ConVar_EnableBunnyhopping.Flags |= (FCVAR_NOTIFY | FCVAR_REPLICATED);
AddMode( MODE_SCROLL, "Scroll", "SCRL" );
LogError( INF_CON_PRE..."No modes were found! Assuming scroll as default mode!!! Freeing sv_airaccelerate and sv_enablebunnyhopping." );
}
*/
}
public void OnAdminMenuCreated( Handle hTopMenu )
{
TopMenu topmenu = TopMenu.FromHandle( hTopMenu );
if ( topmenu == g_hTopMenu )
return;
g_InfluxAdminMenu = topmenu.FindCategory( INFLUX_ADMMENU );
if ( g_InfluxAdminMenu == INVALID_TOPMENUOBJECT )
{
g_InfluxAdminMenu = topmenu.AddCategory( INFLUX_ADMMENU, Hndlr_AdminMenu );
}
}
public void Hndlr_AdminMenu(TopMenu topmenu,
TopMenuAction action,
TopMenuObject object_id,
int param,
char[] buffer,
int maxlength)
{
if ( object_id != g_InfluxAdminMenu )
return;
if ( action == TopMenuAction_DisplayTitle )
{
strcopy( buffer, maxlength, "Influx Commands" );
}
else if ( action == TopMenuAction_DisplayOption )
{
strcopy( buffer, maxlength, "Influx Commands" );
}
}
public void OnAdminMenuReady( Handle hTopMenu )
{
TopMenu topmenu = TopMenu.FromHandle( hTopMenu );
if ( topmenu == g_hTopMenu )
return;
TopMenuObject res = topmenu.FindCategory( INFLUX_ADMMENU );
if ( res == INVALID_TOPMENUOBJECT )
{
return;
}
g_hTopMenu = topmenu;
g_InfluxAdminMenu = res;
g_hTopMenu.AddItem( "sm_manageruns", AdmMenu_ManageRuns, res, INF_PRIVCOM_RUNSETTINGS, 0 );
g_hTopMenu.AddItem( "sm_runsettings", AdmMenu_RunSettings, res, INF_PRIVCOM_RUNSETTINGS, 0 );
}
public void AdmMenu_ManageRuns( TopMenu topmenu, TopMenuAction action, TopMenuObject object_id, int client, char[] buffer, int maxlength )
{
if ( action == TopMenuAction_DisplayOption )
{
strcopy( buffer, maxlength, "Manage Runs" );
}
else if ( action == TopMenuAction_SelectOption )
{
FakeClientCommand( client, "sm_manageruns" );
}
}
public void AdmMenu_RunSettings( TopMenu topmenu, TopMenuAction action, TopMenuObject object_id, int client, char[] buffer, int maxlength )
{
if ( action == TopMenuAction_DisplayOption )
{
strcopy( buffer, maxlength, "Run Settings" );
}
else if ( action == TopMenuAction_SelectOption )
{
FakeClientCommand( client, "sm_runsettings" );
}
}
public void Influx_OnClientStatusChanged( int client )
{
UpdateClientCached( client );
}
public void Influx_OnRecordRemoved( int issuer, int uid, int mapid, int runid, int mode, int style )
{
if ( mapid != Influx_GetCurrentMapId() ) return;
int irun = FindRunById( runid );
if ( irun == -1 ) return;
bool bDeletedBest = false;
for ( int client = 1; client <= MaxClients; client++ )
{
if ( !IsClientInGame( client ) ) continue
if ( IsFakeClient( client ) ) continue
if ( uid == -1 || g_iClientId[client] == uid )
{
bool res = RemoveClientTimes( client, irun, mode, style, true );
if ( res )
{
bDeletedBest = true;
}
}
break;
}
if ( bDeletedBest )
{
DB_InitRecords( runid, mode, style );
}
}
public void Influx_OnMapIdRetrieved( int mapid, bool bNew )
{
LoadRuns();
if ( g_bLate )
{
for ( int i = 1; i <= MaxClients; i++ )
{
if ( IsClientInGame( i ) )
{
OnClientPutInServer( i );
if ( IsClientAuthorized( i ) )
{
OnClientPostAdminCheck( i );
}
}
}
}
}
public void Influx_RequestHelpCmds()
{
Influx_AddHelpCommand( "manageruns", "Run menu.", true );
Influx_AddHelpCommand( "saveruns", "Saves all current runs.", true );
Influx_AddHelpCommand( "setrunname <name>", "Set current run's name.", true );
//Influx_AddHelpCommand( "settelepos", "Set current run's tele position and yaw.", true );
Influx_AddHelpCommand( "deleterun <id>", "Delete a run.", true );
Influx_AddHelpCommand( "deleterunmenu", "Run deletion menu.", true );
Influx_AddHelpCommand( "deleterecords", "Delete a specific run's records.", true );
Influx_AddHelpCommand( "wr/records <args>", "Display records.\nValid arguments are maps, players, styles, modes, etc." );
Influx_AddHelpCommand( "myrecords", "Display your records." );
Influx_AddHelpCommand( "wrmaps", "Display map selector for records." );
Influx_AddHelpCommand( "restart/r", "Go back to start or respawn." );
Influx_AddHelpCommand( "run", "Display run selector menu." );
Influx_AddHelpCommand( "style", "Display style selector menu." );
Influx_AddHelpCommand( "mode", "Display mode selector menu." );
}
public void Influx_OnPrintRecordInfo( int client, Handle dbres, ArrayList itemlist, Menu menu, int uid, int mapid, int runid, int mode, int style )
{
// Add item to delete this record.
if ( CanUserRemoveRecords( client ) )
{
// Note: first character will determine the action.
decl String:szInfo[64];
FormatEx( szInfo, sizeof( szInfo ), "d%i_%i_%i_%i_%i", uid, mapid, runid, mode, style );
menu.AddItem( szInfo, "Delete this record" );
}
}
public Action Influx_OnRecordInfoButtonPressed( int client, const char[] szInfo )
{
if ( szInfo[0] == 'd' ) // We want to delete
{
if ( !CanUserRemoveRecords( client ) ) return Plugin_Stop;
// Display confirmation menu.
Menu menu = new Menu( Hndlr_Delete_Confirm );
menu.SetTitle( "Sure you want to delete this record?\n " );
menu.AddItem( szInfo[1], "Yes" );
menu.AddItem( "", "No" );
menu.ExitButton = false;
menu.Display( client, MENU_TIME_FOREVER );
return Plugin_Stop;
}
return Plugin_Continue;
}
public void OnMapStart()
{
g_hRuns.Clear();
if ( g_hFunc_GetPlayerMaxSpeed == null && !g_ConVar_SuppressMaxSpdWarning.BoolValue )
{
Inf_Warning( 3, "Weapon speed check cannot be made! Players are free to cheat with weapon speeds." );
}
GetCurrentMapSafe( g_szCurrentMap, sizeof( g_szCurrentMap ) );
//g_bRunsLoaded = false;
g_bNewMapId = false;
g_bBestTimesCached = false;
g_iCurMapId = 0;
DB_InitMap();
//LoadRuns();
InitColors();
}
public void OnMapEnd()
{
if ( g_ConVar_SaveRunsOnMapEnd.BoolValue )
{
SaveRuns();
}
}
public void OnClientPutInServer( int client )
{
ResetClient( client );
if ( !IsFakeClient( client ) )
{
InitClientModeStyle( client );
// Send status update to other plugins.
g_iRunId[client] = -1; // We didn't have a run before this.
SetClientRun( client, GetDefaultRun(), false, false );
ResetAllClientTimes( client );
UpdateClientCached( client );
Inf_SDKHook( client, SDKHook_PostThinkPost, E_PostThinkPost_Client );
}
}
public void OnClientPostAdminCheck( int client )
{
if ( !IsFakeClient( client ) )
{
DB_InitClient( client );
}
}
public void OnClientDisconnect( int client )
{
g_iClientId[client] = 0;
g_bCachedTimes[client] = false;
if ( !IsFakeClient( client ) )
{
SDKUnhook( client, SDKHook_PostThinkPost, E_PostThinkPost_Client );
DB_UpdateClient( client );
}
}
public void E_PostThinkPost_Client( int client )
{
if ( !IsPlayerAlive( client ) ) return;
// Check for cheating.
if ( g_iRunState[client] == STATE_RUNNING )
{
if ( GetEntityMoveType( client ) == MOVETYPE_NOCLIP && !IS_PAUSED( g_bLib_Pause, client ) && !IS_PRAC( g_bLib_Practise, client ) )
{
InvalidateClientRun( client );
}
CapWeaponSpeed( client );
}
}
stock void CapWeaponSpeed( int client )
{
// Make sure players don't cheat with weapons going over 250-260, depending on their mode.