/
meta_api.cpp
executable file
·1922 lines (1592 loc) · 50.8 KB
/
meta_api.cpp
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
// vim: set ts=4 sw=4 tw=99 noet:
//
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
// Copyright (C) The AMX Mod X Development Team.
//
// This software is licensed under the GNU General Public License, version 3 or higher.
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
// https://alliedmods.net/amxmodx-license
#include <time.h>
#include "amxmodx.h"
#include "fakemeta.h"
#include "CMenu.h"
#include "newmenus.h"
#include "natives.h"
#include "binlog.h"
#include "optimizer.h"
#include "libraries.h"
#include "messages.h"
#include "datastructs.h"
#include "CFlagManager.h"
#include <amxmodx_version.h>
#include "trie_natives.h"
#include "CDataPack.h"
#include "textparse.h"
#include "CvarManager.h"
#include "CLibrarySys.h"
#include "CFileSystem.h"
#include "gameconfigs.h"
#include "CGameConfigs.h"
#include <engine_strucs.h>
#include <CDetour/detours.h>
#include "CoreConfig.h"
#include <resdk/mod_rehlds_api.h>
#include <amtl/am-utility.h>
plugin_info_t Plugin_info =
{
META_INTERFACE_VERSION, // ifvers
"AMX Mod X", // name
AMXX_VERSION, // version
__DATE__, // date
"AMX Mod X Dev Team", // author
"http://www.amxmodx.org", // url
"AMXX", // logtag
PT_STARTUP, // (when) loadable
PT_ANYTIME, // (when) unloadable
};
meta_globals_t *gpMetaGlobals;
gamedll_funcs_t *gpGamedllFuncs;
mutil_funcs_t *gpMetaUtilFuncs;
enginefuncs_t g_engfuncs;
globalvars_t *gpGlobals;
funEventCall modMsgsEnd[MAX_REG_MSGS];
funEventCall modMsgs[MAX_REG_MSGS];
void (*function)(void*);
void (*endfunction)(void*);
extern List<AUTHORIZEFUNC> g_auth_funcs;
extern ke::Vector<CAdminData *> DynamicAdmins;
CLog g_log;
CForwardMngr g_forwards;
ke::Vector<ke::AutoPtr<CPlayer *>> g_auth;
ke::Vector<ke::AutoPtr<ForceObject>> g_forcemodels;
ke::Vector<ke::AutoPtr<ForceObject>> g_forcesounds;
ke::Vector<ke::AutoPtr<ForceObject>> g_forcegeneric;
CPlayer g_players[33];
CPlayer* mPlayer;
CPluginMngr g_plugins;
CTaskMngr g_tasksMngr;
CFrameActionMngr g_frameActionMngr;
CmdMngr g_commands;
CFlagManager FlagMan;
EventsMngr g_events;
Grenades g_grenades;
LogEventsMngr g_logevents;
MenuMngr g_menucmds;
CLangMngr g_langMngr;
ke::AString g_log_dir;
ke::AString g_mod_name;
XVars g_xvars;
bool g_bmod_tfc;
bool g_bmod_cstrike;
bool g_bmod_dod;
bool g_bmod_dmc;
bool g_bmod_ricochet;
bool g_bmod_valve;
bool g_bmod_gearbox;
bool g_official_mod;
bool g_dontprecache;
bool g_forcedmodules;
bool g_forcedsounds;
fakecmd_t g_fakecmd;
float g_game_restarting;
float g_game_timeleft;
float g_task_time;
float g_auth_time;
bool g_initialized = false;
bool g_coloredmenus;
bool g_activated = false;
bool g_NewDLL_Available = false;
#ifdef MEMORY_TEST
float g_next_memreport_time;
unsigned int g_memreport_count;
ke::AString g_memreport_dir;
bool g_memreport_enabled;
#define MEMREPORT_INTERVAL 300.0f /* 5 mins */
#endif // MEMORY_TEST
hudtextparms_t g_hudset;
//int g_edict_point;
int g_players_num;
int mPlayerIndex;
int mState;
int g_srvindex;
CDetour *DropClientDetour;
bool g_isDropClientHookEnabled = false;
bool g_isDropClientHookAvailable = false;
void SV_DropClient_RH(IRehldsHook_SV_DropClient *chain, IGameClient *cl, bool crash, const char *format);
cvar_t init_amxmodx_version = {"amxmodx_version", "", FCVAR_SERVER | FCVAR_SPONLY};
cvar_t init_amxmodx_modules = {"amxmodx_modules", "", FCVAR_SPONLY};
cvar_t init_amxmodx_debug = {"amx_debug", "1", FCVAR_SPONLY};
cvar_t init_amxmodx_mldebug = {"amx_mldebug", "", FCVAR_SPONLY};
cvar_t init_amxmodx_language = {"amx_language", "en", FCVAR_SERVER};
cvar_t init_amxmodx_cl_langs = {"amx_client_languages", "1", FCVAR_SERVER};
cvar_t init_amxmodx_perflog = { "amx_perflog_ms", "1.0", FCVAR_SPONLY };
cvar_t* amxmodx_version = NULL;
cvar_t* amxmodx_modules = NULL;
cvar_t* amxmodx_debug = NULL;
cvar_t* amxmodx_language = NULL;
cvar_t* amxmodx_perflog = NULL;
cvar_t* hostname = NULL;
cvar_t* mp_timelimit = NULL;
// main forwards
int FF_ClientCommand = -1;
int FF_ClientConnect = -1;
int FF_ClientDisconnect = -1;
int FF_ClientDisconnected = -1;
int FF_ClientRemove = -1;
int FF_ClientInfoChanged = -1;
int FF_ClientPutInServer = -1;
int FF_PluginInit = -1;
int FF_PluginCfg = -1;
int FF_PluginPrecache = -1;
int FF_PluginLog = -1;
int FF_PluginEnd = -1;
int FF_InconsistentFile = -1;
int FF_ClientAuthorized = -1;
int FF_ChangeLevel = -1;
int FF_ClientConnectEx = -1;
IFileSystem* g_FileSystem;
HLTypeConversion TypeConversion;
bool ColoredMenus(const char *ModName)
{
const char * pModNames[] = { "cstrike", "czero", "dmc", "dod", "tfc", "valve" };
const size_t ModsCount = sizeof(pModNames) / sizeof(const char *);
for (size_t i = 0; i < ModsCount; ++i)
{
if (strcmp(ModName, pModNames[i]) == 0)
return true; // this game modification currently supports colored menus
}
return false; // no colored menus are supported for this game modification
}
void ParseAndOrAdd(CStack<ke::AString *> & files, const char *name)
{
if (strncmp(name, "plugins-", 8) == 0)
{
#if !defined WIN32
size_t len = strlen(name);
if (strcmp(&name[len-4], ".ini") == 0)
{
#endif
ke::AString *pString = new ke::AString(name);
files.push(pString);
#if !defined WIN32
}
#endif
}
}
void BuildPluginFileList(const char *initialdir, CStack<ke::AString *> & files)
{
char path[PLATFORM_MAX_PATH];
#if defined WIN32
build_pathname_r(path, sizeof(path), "%s/*.ini", initialdir);
_finddata_t fd;
intptr_t handle = _findfirst(path, &fd);
if (handle < 0)
{
return;
}
while (!_findnext(handle, &fd))
{
ParseAndOrAdd(files, fd.name);
}
_findclose(handle);
#elif defined(__linux__) || defined(__APPLE__)
build_pathname_r(path, sizeof(path), "%s/", initialdir);
struct dirent *ep;
DIR *dp;
if ((dp = opendir(path)) == NULL)
{
return;
}
while ( (ep=readdir(dp)) != NULL )
{
ParseAndOrAdd(files, ep->d_name);
}
closedir (dp);
#endif
}
//Loads a plugin list into the Plugin Cache and Load Modules cache
void LoadExtraPluginsToPCALM(const char *initialdir)
{
CStack<ke::AString *> files;
BuildPluginFileList(initialdir, files);
char path[255];
while (!files.empty())
{
ke::AString *pString = files.front();
ke::SafeSprintf(path, sizeof(path), "%s/%s",
initialdir,
pString->chars());
g_plugins.CALMFromFile(path);
delete pString;
files.pop();
}
}
void LoadExtraPluginsFromDir(const char *initialdir)
{
CStack<ke::AString *> files;
char path[255];
BuildPluginFileList(initialdir, files);
while (!files.empty())
{
ke::AString *pString = files.front();
ke::SafeSprintf(path, sizeof(path), "%s/%s",
initialdir,
pString->chars());
g_plugins.loadPluginsFromFile(path);
delete pString;
files.pop();
}
}
// Precache stuff from force consistency calls
// or check for pointed files won't be done
int C_PrecacheModel(const char *s)
{
if (!g_forcedmodules)
{
g_forcedmodules = true;
for (auto &model : g_forcemodels)
{
PRECACHE_MODEL(model->getFilename());
ENGINE_FORCE_UNMODIFIED(model->getForceType(), model->getMin(), model->getMax(), model->getFilename());
}
}
RETURN_META_VALUE(MRES_IGNORED, 0);
}
int C_PrecacheSound(const char *s)
{
if (!g_forcedsounds)
{
g_forcedsounds = true;
for (auto &sound : g_forcesounds)
{
PRECACHE_SOUND(sound->getFilename());
ENGINE_FORCE_UNMODIFIED(sound->getForceType(), sound->getMin(), sound->getMax(), sound->getFilename());
}
if (!g_bmod_cstrike)
{
PRECACHE_SOUND("weapons/cbar_hitbod1.wav");
PRECACHE_SOUND("weapons/cbar_hitbod2.wav");
PRECACHE_SOUND("weapons/cbar_hitbod3.wav");
}
}
RETURN_META_VALUE(MRES_IGNORED, 0);
}
// On InconsistentFile call forward function from plugins
int C_InconsistentFile(const edict_t *player, const char *filename, char *disconnect_message)
{
if (FF_InconsistentFile < 0)
RETURN_META_VALUE(MRES_IGNORED, FALSE);
if (MDLL_InconsistentFile(player, filename, disconnect_message))
{
CPlayer *pPlayer = GET_PLAYER_POINTER((edict_t *)player);
if (executeForwards(FF_InconsistentFile, static_cast<cell>(pPlayer->index),
filename, disconnect_message) == 1)
RETURN_META_VALUE(MRES_SUPERCEDE, FALSE);
RETURN_META_VALUE(MRES_SUPERCEDE, TRUE);
}
RETURN_META_VALUE(MRES_IGNORED, FALSE);
}
const char* get_localinfo(const char* name, const char* def)
{
const char* b = LOCALINFO((char*)name);
if (b == 0 || *b == 0)
{
SET_LOCALINFO((char*)name, (char*)(b = def));
}
return b;
}
const char* get_localinfo_r(const char *name, const char *def, char buffer[], size_t maxlength)
{
const char* b = LOCALINFO((char*)name);
if (b == 0 || *b == 0)
{
SET_LOCALINFO((char*)name, (char*)(b = def));
}
ke::SafeSprintf(buffer, maxlength, "%s", b);
return buffer;
}
// Very first point at map load
// Load AMX modules for new native functions
// Initialize AMX stuff and load it's plugins from plugins.ini list
// Call precache forward function from plugins
int C_Spawn(edict_t *pent)
{
if (g_initialized)
{
RETURN_META_VALUE(MRES_IGNORED, 0);
}
g_activated = false;
g_initialized = true;
g_forcedmodules = false;
g_forcedsounds = false;
g_srvindex = IS_DEDICATED_SERVER() ? 0 : 1;
hostname = CVAR_GET_POINTER("hostname");
mp_timelimit = CVAR_GET_POINTER("mp_timelimit");
// Fix for crashing on mods that do not have mp_timelimit
if (mp_timelimit == NULL)
{
static cvar_t timelimit_holder;
timelimit_holder.name = "mp_timelimit";
timelimit_holder.string = "0";
timelimit_holder.flags = 0;
timelimit_holder.value = 0.0;
CVAR_REGISTER(&timelimit_holder);
mp_timelimit = &timelimit_holder;
}
g_forwards.clear();
g_log.MapChange();
// ###### Initialize task manager
g_tasksMngr.registerTimers(&gpGlobals->time, &mp_timelimit->value, &g_game_timeleft);
// ###### Initialize commands prefixes
g_commands.registerPrefix("amx");
g_commands.registerPrefix("amxx");
g_commands.registerPrefix("say");
g_commands.registerPrefix("admin_");
g_commands.registerPrefix("sm_");
g_commands.registerPrefix("cm_");
// make sure localinfos are set
get_localinfo("amxx_basedir", "addons/amxmodx");
get_localinfo("amxx_pluginsdir", "addons/amxmodx/plugins");
get_localinfo("amxx_modulesdir", "addons/amxmodx/modules");
get_localinfo("amxx_configsdir", "addons/amxmodx/configs");
get_localinfo("amxx_customdir", "addons/amxmodx/custom");
// make sure bcompat localinfos are set
get_localinfo("amx_basedir", "addons/amxmodx");
get_localinfo("amx_configdir", "addons/amxmodx/configs");
get_localinfo("amx_langdir", "addons/amxmodx/data/amxmod-lang");
get_localinfo("amx_modulesdir", "addons/amxmodx/modules");
get_localinfo("amx_pluginsdir", "addons/amxmodx/plugins");
get_localinfo("amx_logdir", "addons/amxmodx/logs");
FlagMan.LoadFile();
ArrayHandles.clear();
TrieHandles.clear();
TrieIterHandles.clear();
TrieSnapshotHandles.clear();
DataPackHandles.clear();
TextParsersHandles.clear();
GameConfigHandle.clear();
char map_pluginsfile_path[256];
char prefixed_map_pluginsfile[256];
char configs_dir[256];
// ###### Load modules
loadModules(get_localinfo("amxx_modules", "addons/amxmodx/configs/modules.ini"), PT_ANYTIME);
get_localinfo_r("amxx_configsdir", "addons/amxmodx/configs", configs_dir, sizeof(configs_dir)-1);
g_plugins.CALMFromFile(get_localinfo("amxx_plugins", "addons/amxmodx/configs/plugins.ini"));
LoadExtraPluginsToPCALM(configs_dir);
char temporaryMap[64], *tmap_ptr;
ke::SafeSprintf(temporaryMap, sizeof(temporaryMap), "%s", STRING(gpGlobals->mapname));
prefixed_map_pluginsfile[0] = '\0';
if ((tmap_ptr = strchr(temporaryMap, '_')) != NULL)
{
// this map has a prefix
*tmap_ptr = '\0';
ke::SafeSprintf(prefixed_map_pluginsfile,
sizeof(prefixed_map_pluginsfile),
"%s/maps/plugins-%s.ini",
configs_dir,
temporaryMap);
g_plugins.CALMFromFile(prefixed_map_pluginsfile);
}
ke::SafeSprintf(map_pluginsfile_path,
sizeof(map_pluginsfile_path),
"%s/maps/plugins-%s.ini",
configs_dir,
STRING(gpGlobals->mapname));
g_plugins.CALMFromFile(map_pluginsfile_path);
int loaded = countModules(CountModules_Running); // Call after attachModules so all modules don't have pending stat
// Set some info about amx version and modules
CVAR_SET_STRING(init_amxmodx_version.name, AMXX_VERSION);
char buffer[32];
sprintf(buffer, "%d", loaded);
CVAR_SET_STRING(init_amxmodx_modules.name, buffer);
// ###### Load Vault
char file[PLATFORM_MAX_PATH];
g_vault.setSource(build_pathname_r(file, sizeof(file), "%s", get_localinfo("amxx_vault", "addons/amxmodx/configs/vault.ini")));
g_vault.loadVault();
// ###### Init time and freeze tasks
g_game_timeleft = g_bmod_dod ? 1.0f : 0.0f;
g_task_time = gpGlobals->time + 99999.0f;
g_auth_time = gpGlobals->time + 99999.0f;
#ifdef MEMORY_TEST
g_next_memreport_time = gpGlobals->time + 99999.0f;
#endif
g_players_num = 0;
// Set server flags
memset(g_players[0].flags, -1, sizeof(g_players[0].flags));
g_opt_level = atoi(get_localinfo("optimizer", "7"));
if (!g_opt_level)
g_opt_level = 7;
// ###### Load AMX Mod X plugins
g_plugins.loadPluginsFromFile(get_localinfo("amxx_plugins", "addons/amxmodx/configs/plugins.ini"));
LoadExtraPluginsFromDir(configs_dir);
g_plugins.loadPluginsFromFile(map_pluginsfile_path, false);
if (prefixed_map_pluginsfile[0] != '\0')
{
g_plugins.loadPluginsFromFile(prefixed_map_pluginsfile, false);
}
g_plugins.Finalize();
g_plugins.InvalidateCache();
// Register forwards
FF_PluginInit = registerForward("plugin_init", ET_IGNORE, FP_DONE);
FF_ClientCommand = registerForward("client_command", ET_STOP, FP_CELL, FP_DONE);
FF_ClientConnect = registerForward("client_connect", ET_IGNORE, FP_CELL, FP_DONE);
FF_ClientDisconnect = registerForward("client_disconnect", ET_IGNORE, FP_CELL, FP_DONE);
FF_ClientDisconnected = registerForward("client_disconnected", ET_IGNORE, FP_CELL, FP_CELL, FP_ARRAY, FP_CELL, FP_DONE);
FF_ClientRemove = registerForward("client_remove", ET_IGNORE, FP_CELL, FP_CELL, FP_STRING, FP_DONE);
FF_ClientInfoChanged = registerForward("client_infochanged", ET_IGNORE, FP_CELL, FP_DONE);
FF_ClientPutInServer = registerForward("client_putinserver", ET_IGNORE, FP_CELL, FP_DONE);
FF_PluginCfg = registerForward("plugin_cfg", ET_IGNORE, FP_DONE);
FF_PluginPrecache = registerForward("plugin_precache", ET_IGNORE, FP_DONE);
FF_PluginLog = registerForward("plugin_log", ET_STOP, FP_DONE);
FF_PluginEnd = registerForward("plugin_end", ET_IGNORE, FP_DONE);
FF_InconsistentFile = registerForward("inconsistent_file", ET_STOP, FP_CELL, FP_STRING, FP_STRINGEX, FP_DONE);
FF_ClientAuthorized = registerForward("client_authorized", ET_IGNORE, FP_CELL, FP_STRING, FP_DONE);
FF_ChangeLevel = registerForward("server_changelevel", ET_STOP, FP_STRING, FP_DONE);
FF_ClientConnectEx = registerForward("client_connectex", ET_STOP, FP_CELL, FP_STRING, FP_STRING, FP_ARRAY, FP_DONE);
CoreCfg.OnAmxxInitialized();
#if defined BINLOG_ENABLED
if (!g_BinLog.Open())
{
LOG_ERROR(PLID, "Binary log failed to open.");
}
g_binlog_level = atoi(get_localinfo("bin_logging", "17"));
g_binlog_maxsize = atoi(get_localinfo("max_binlog_size", "20"));
#endif
modules_callPluginsLoaded();
TypeConversion.init();
// ###### Call precache forward function
g_dontprecache = false;
executeForwards(FF_PluginPrecache);
g_dontprecache = true;
for (auto &generic : g_forcegeneric)
{
PRECACHE_GENERIC(generic->getFilename());
ENGINE_FORCE_UNMODIFIED(generic->getForceType(), generic->getMin(), generic->getMax(), generic->getFilename());
}
RETURN_META_VALUE(MRES_IGNORED, 0);
}
struct sUserMsg
{
const char* name;
int* id;
funEventCall func;
bool endmsg;
bool cstrike;
} g_user_msg[] =
{
{"CurWeapon", &gmsgCurWeapon, Client_CurWeapon, false, false},
{"Damage", &gmsgDamage, Client_DamageEnd, true, true},
{"DeathMsg", &gmsgDeathMsg, Client_DeathMsg, false, true},
{"TextMsg", &gmsgTextMsg, Client_TextMsg, false, false},
{"TeamInfo", &gmsgTeamInfo, Client_TeamInfo, false, false},
{"WeaponList", &gmsgWeaponList, Client_WeaponList, false, false},
{"MOTD", &gmsgMOTD, 0, false, false},
{"ServerName", &gmsgServerName, 0, false, false},
{"Health", &gmsgHealth, 0, false, false},
{"Battery", &gmsgBattery, 0, false, false},
{"ShowMenu", &gmsgShowMenu, Client_ShowMenu, false, false},
{"SendAudio", &gmsgSendAudio, 0, false, false},
{"AmmoX", &gmsgAmmoX, Client_AmmoX, false, false},
{"ScoreInfo", &gmsgScoreInfo, Client_ScoreInfo, false, false},
{"VGUIMenu", &gmsgVGUIMenu, Client_VGUIMenu, false, false},
{"AmmoPickup", &gmsgAmmoPickup, Client_AmmoPickup, false, false},
{"WeapPickup", &gmsgWeapPickup, 0, false, false},
{"ResetHUD", &gmsgResetHUD, 0, false, false},
{"RoundTime", &gmsgRoundTime, 0, false, false},
{"SayText", &gmsgSayText, 0, false, false},
{"InitHUD", &gmsgInitHUD, Client_InitHUDEnd, true, false},
{0, 0, 0, false, false}
};
int C_RegUserMsg_Post(const char *pszName, int iSize)
{
for (int i = 0; g_user_msg[i].name; ++i)
{
if (strcmp(g_user_msg[i].name, pszName) == 0)
{
int id = META_RESULT_ORIG_RET(int);
*g_user_msg[i].id = id;
if (!g_user_msg[i].cstrike || g_bmod_cstrike)
{
if (g_user_msg[i].endmsg)
modMsgsEnd[id] = g_user_msg[i].func;
else
modMsgs[id] = g_user_msg[i].func;
}
break;
}
}
RETURN_META_VALUE(MRES_IGNORED, 0);
}
/*
Much more later after precache. All is precached, server
will be flaged as ready to use so call
plugin_init forward function from plugins
*/
void C_ServerActivate(edict_t *pEdictList, int edictCount, int clientMax)
{
int id;
for (int i = 0; g_user_msg[i].name; ++i)
{
if ((*g_user_msg[i].id == 0) && (id = GET_USER_MSG_ID(PLID, g_user_msg[i].name, NULL)) != 0)
{
*g_user_msg[i].id = id;
if (!g_user_msg[i].cstrike || g_bmod_cstrike)
{
if (g_user_msg[i].endmsg)
modMsgsEnd[id] = g_user_msg[i].func;
else
modMsgs[id] = g_user_msg[i].func;
}
}
}
if (g_isDropClientHookAvailable)
{
if (!g_isDropClientHookEnabled)
{
if (RehldsApi)
{
RehldsHookchains->SV_DropClient()->registerHook(SV_DropClient_RH);
}
else
{
DropClientDetour->EnableDetour();
}
g_isDropClientHookEnabled = true;
}
}
RETURN_META(MRES_IGNORED);
}
void C_ServerActivate_Post(edict_t *pEdictList, int edictCount, int clientMax)
{
if (g_activated)
RETURN_META(MRES_IGNORED);
for (int i = 1; i <= gpGlobals->maxClients; ++i)
{
CPlayer *pPlayer = GET_PLAYER_POINTER_I(i);
pPlayer->Init(pEdictList + i, i);
}
CoreCfg.ExecuteMainConfig(); // Execute amxx.cfg
executeForwards(FF_PluginInit);
executeForwards(FF_PluginCfg);
CoreCfg.ExecuteAutoConfigs(); // Execute configs created with AutoExecConfig native.
CoreCfg.SetMapConfigTimer(6.1); // Prepare per-map configs to be executed 6.1 seconds later.
// Original value which was used in admin.sma.
// Correct time in Counter-Strike and other mods (except DOD)
if (!g_bmod_dod)
g_game_timeleft = 0;
g_task_time = gpGlobals->time;
g_auth_time = gpGlobals->time;
#ifdef MEMORY_TEST
g_next_memreport_time = gpGlobals->time + MEMREPORT_INTERVAL;
g_memreport_count = 0;
g_memreport_enabled = true;
#endif
g_activated = true;
RETURN_META(MRES_IGNORED);
}
// Call plugin_end forward function from plugins.
void C_ServerDeactivate()
{
if (!g_activated)
RETURN_META(MRES_IGNORED);
for (int i = 1; i <= gpGlobals->maxClients; ++i)
{
CPlayer *pPlayer = GET_PLAYER_POINTER_I(i);
if (pPlayer->initialized)
{
// deprecated
executeForwards(FF_ClientDisconnect, static_cast<cell>(pPlayer->index));
if (g_isDropClientHookAvailable && !pPlayer->disconnecting)
{
executeForwards(FF_ClientDisconnected, static_cast<cell>(pPlayer->index), FALSE, prepareCharArray(const_cast<char*>(""), 0), 0);
}
}
if (pPlayer->ingame)
{
auto wasDisconnecting = pPlayer->disconnecting;
pPlayer->Disconnect();
--g_players_num;
if (!wasDisconnecting && g_isDropClientHookAvailable)
{
executeForwards(FF_ClientRemove, static_cast<cell>(pPlayer->index), FALSE, const_cast<char*>(""));
}
}
}
if (g_isDropClientHookAvailable)
{
if (g_isDropClientHookEnabled)
{
if (RehldsApi)
{
RehldsHookchains->SV_DropClient()->unregisterHook(SV_DropClient_RH);
}
else
{
DropClientDetour->DisableDetour();
}
g_isDropClientHookEnabled = false;
}
}
g_players_num = 0;
executeForwards(FF_PluginEnd);
RETURN_META(MRES_IGNORED);
}
extern ke::Vector<cell *> g_hudsync;
// After all clear whole AMX configuration
// However leave AMX modules which are loaded only once
void C_ServerDeactivate_Post()
{
if (!g_initialized)
RETURN_META(MRES_IGNORED);
modules_callPluginsUnloading();
CoreCfg.Clear();
g_auth.clear();
g_commands.clear();
g_forcemodels.clear();
g_forcesounds.clear();
g_forcegeneric.clear();
g_grenades.clear();
g_tasksMngr.clear();
g_forwards.clear();
g_logevents.clearLogEvents();
g_events.clearEvents();
g_menucmds.clear();
ClearMenus();
g_vault.clear();
g_xvars.clear();
g_plugins.clear();
g_langMngr.Clear();
ArrayHandles.clear();
TrieHandles.clear();
TrieIterHandles.clear();
TrieSnapshotHandles.clear();
DataPackHandles.clear();
TextParsersHandles.clear();
GameConfigHandle.clear();
g_CvarManager.OnPluginUnloaded();
ClearPluginLibraries();
modules_callPluginsUnloaded();
detachReloadModules();
ClearMessages();
// Flush the dynamic admins list
for (size_t iter=DynamicAdmins.length();iter--; )
{
delete DynamicAdmins[iter];
}
DynamicAdmins.clear();
for (unsigned int i=0; i<g_hudsync.length(); i++)
delete [] g_hudsync[i];
g_hudsync.clear();
FlagMan.WriteCommands();
// last memreport
#ifdef MEMORY_TEST
if (g_memreport_enabled)
{
if (g_memreport_count == 0)
{
// make new directory
time_t td;
time(&td);
tm *curTime = localtime(&td);
int i = 0;
#if defined(__linux__) || defined(__APPLE__)
mkdir(build_pathname("%s/memreports", get_localinfo("amxx_basedir", "addons/amxmodx")), 0700);
#else
mkdir(build_pathname("%s/memreports", get_localinfo("amxx_basedir", "addons/amxmodx")));
#endif
while (true)
{
char buffer[256];
sprintf(buffer, "%s/memreports/D%02d%02d%03d", get_localinfo("amxx_basedir", "addons/amxmodx"), curTime->tm_mon + 1, curTime->tm_mday, i);
#if defined(__linux__) || defined(__APPLE__)
mkdir(build_pathname("%s", g_log_dir.chars()), 0700);
if (mkdir(build_pathname(buffer), 0700) < 0)
#else
mkdir(build_pathname("%s", g_log_dir.chars()));
if (mkdir(build_pathname(buffer)) < 0)
#endif
{
if (errno == EEXIST)
{
// good
++i;
continue;
} else {
// bad
g_memreport_enabled = false;
AMXXLOG_Log("[AMXX] Fatal error: Can't create directory for memreport files (%s)", buffer);
break;
}
}
g_memreport_dir = buffer;
// g_memreport_dir should be valid now
break;
}
}
m_dumpMemoryReport(build_pathname("%s/r%03d.txt", g_memreport_dir.chars(), g_memreport_count));
AMXXLOG_Log("Memreport #%d created (file \"%s/r%03d.txt\") (interval %f)", g_memreport_count + 1, g_memreport_dir.chars(), g_memreport_count, MEMREPORT_INTERVAL);
g_memreport_count++;
}
#endif // MEMORY_TEST
#if defined BINLOG_ENABLED
g_BinLog.Close();
#endif
g_initialized = false;
RETURN_META(MRES_IGNORED);
}
BOOL C_ClientConnect_Post(edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[128])
{
CPlayer* pPlayer = GET_PLAYER_POINTER(pEntity);
if (!pPlayer->IsBot())
{
bool a = pPlayer->Connect(pszName, pszAddress);
executeForwards(FF_ClientConnect, static_cast<cell>(pPlayer->index));
if (a)
{
auto playerToAuth = ke::AutoPtr<CPlayer *>(new CPlayer*(pPlayer));
if (playerToAuth)
g_auth.append(ke::Move(playerToAuth));
} else {
pPlayer->Authorize();
const char* authid = GETPLAYERAUTHID(pEntity);
if (g_auth_funcs.size())
{
List<AUTHORIZEFUNC>::iterator iter, end=g_auth_funcs.end();
AUTHORIZEFUNC fn;
for (iter=g_auth_funcs.begin(); iter!=end; iter++)
{
fn = (*iter);
fn(pPlayer->index, authid);
}
}
executeForwards(FF_ClientAuthorized, static_cast<cell>(pPlayer->index), authid);
}
}
RETURN_META_VALUE(MRES_IGNORED, TRUE);
}
BOOL C_ClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[128])
{
CPlayer* pPlayer = GET_PLAYER_POINTER(pEntity);
if(executeForwards(FF_ClientConnectEx, static_cast<cell>(pPlayer->index), pszName, pszAddress, prepareCharArray(szRejectReason, 128, true)))
RETURN_META_VALUE(MRES_SUPERCEDE, FALSE);
RETURN_META_VALUE(MRES_IGNORED, TRUE);
}
void C_ClientDisconnect(edict_t *pEntity)
{
CPlayer *pPlayer = GET_PLAYER_POINTER(pEntity);
if (pPlayer->initialized)
{
// deprecated
executeForwards(FF_ClientDisconnect, static_cast<cell>(pPlayer->index));
if (g_isDropClientHookAvailable && !pPlayer->disconnecting)
{
executeForwards(FF_ClientDisconnected, static_cast<cell>(pPlayer->index), FALSE, prepareCharArray(const_cast<char*>(""), 0), 0);
}
}
if (pPlayer->ingame)
{
--g_players_num;
}
auto wasDisconnecting = pPlayer->disconnecting;
pPlayer->Disconnect();
if (!wasDisconnecting && g_isDropClientHookAvailable)
{
executeForwards(FF_ClientRemove, static_cast<cell>(pPlayer->index), FALSE, const_cast<char*>(""));
}
RETURN_META(MRES_IGNORED);
}
CPlayer* SV_DropClient_PreHook(edict_s *client, qboolean crash, const char *buffer, size_t buffer_size)
{
auto pPlayer = client ? GET_PLAYER_POINTER(client) : nullptr;
if (pPlayer)
{
if (pPlayer->initialized)
{
pPlayer->disconnecting = true;
executeForwards(FF_ClientDisconnected, pPlayer->index, TRUE, prepareCharArray(const_cast<char*>(buffer), buffer_size, true), buffer_size - 1);
}
}
return pPlayer;
}
void SV_DropClient_PostHook(CPlayer *pPlayer, qboolean crash, const char *buffer)
{
if (pPlayer)
{
pPlayer->Disconnect();
executeForwards(FF_ClientRemove, pPlayer->index, TRUE, buffer);
}
}
// void SV_DropClient(client_t *cl, qboolean crash, const char *fmt, ...);
DETOUR_DECL_STATIC3_VAR(SV_DropClient, void, client_t*, cl, qboolean, crash, const char*, format)
{
char buffer[1024];
va_list ap;
va_start(ap, format);
ke::SafeVsprintf(buffer, sizeof(buffer) - 1, format, ap);
va_end(ap);
auto pPlayer = SV_DropClient_PreHook(cl->edict, crash, buffer, ARRAY_LENGTH(buffer));
DETOUR_STATIC_CALL(SV_DropClient)(cl, crash, "%s", buffer);
SV_DropClient_PostHook(pPlayer, crash, buffer);
}
void SV_DropClient_RH(IRehldsHook_SV_DropClient *chain, IGameClient *cl, bool crash, const char *format)
{
char buffer[1024];
ke::SafeStrcpy(buffer, sizeof(buffer), format);
auto pPlayer = SV_DropClient_PreHook(cl->GetEdict(), crash, buffer, ARRAY_LENGTH(buffer));