-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
stac_stocks.sp
executable file
·1325 lines (1146 loc) · 33.3 KB
/
stac_stocks.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
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
#pragma semicolon 1
/********** StacLog functions **********/
// Open log file for StAC
void OpenStacLog()
{
if (StacLogFile != null)
{
FlushFile(StacLogFile);
return;
}
// current date for log file (gets updated on map change to not spread out maps across files on date changes)
char curDate[32];
// get current date
FormatTime(curDate, sizeof(curDate), "%m%d%y", GetTime());
// init path
char path[128];
// set path
BuildPath(Path_SM, path, sizeof(path), "logs/stac");
// create directory if not extant
if (!DirExists(path, false))
{
LogMessage("[StAC] StAC directory not extant! Creating...");
// chmod perms - rwxrwxr-x . it needs to be octal.
// yes I could use the FPERM flags but pawn doesn't have constexpr and i don't want to make a mess
// with a bunch of ORs and not being able to check it in my IDE
static int perms = 0o775;
if (!CreateDirectory(path, perms, false))
{
LogMessage("[StAC] StAC directory could not be created!");
}
}
// set up the full path here
Format(path, sizeof(path), "%s/stac_%s.log", path, curDate);
// actually create file here
StacLogFile = OpenFile(path, "at", false);
}
// Close log file for StAC
void CloseStacLog()
{
FlushFile(StacLogFile);
delete StacLogFile;
}
/*
log to StAC log file
This strips color strings, e.g.
{color}test{color2}
will become
[StAC] test
*/
void StacLog(const char[] format, any ...)
{
// crutch for reloading the plugin and still printing to our log file
if (StacLogFile == null)
{
stac_log_to_file = FindConVar("stac_log_to_file");
if (stac_log_to_file != null)
{
if (stac_log_to_file.BoolValue)
{
OpenStacLog();
}
}
}
char buffer[254];
VFormat(buffer, sizeof(buffer), format, 2);
// clear color tags
MC_RemoveTags(buffer, sizeof(buffer));
char nowtime[64];
int int_nowtime = GetTime();
FormatTime(nowtime, sizeof(nowtime), "%H:%M:%S", int_nowtime);
char file_buffer[254];
strcopy(file_buffer, sizeof(file_buffer), buffer);
// add newlines
Format(file_buffer, sizeof(file_buffer), "<%s> %s\n", nowtime, file_buffer);
char colored_buffer[254];
strcopy(colored_buffer, sizeof(colored_buffer), buffer);
// strip out any instances of "[StAC] " at the front of the string so we don't get double instances of it later
ReplaceStringEx(colored_buffer, sizeof(colored_buffer), "[StAC] ", "", 7, -1, true);
if (StrEqual(os, "linux"))
{
// add colored tags :D
Format(colored_buffer, sizeof(colored_buffer), ansi_bright_magenta ... "[StAC]" ... ansi_reset ... " %s", colored_buffer);
}
else
{
Format(colored_buffer, sizeof(colored_buffer), "[StAC] %s", colored_buffer);
}
// add the tag to the normal thing
Format(buffer, sizeof(buffer), "[StAC] %s", buffer);
if (StacLogFile != null)
{
WriteFileString(StacLogFile, file_buffer, false);
FlushFile(StacLogFile);
}
// else if (logtofile)
// {
// LogMessage("[StAC] File handle invalid!");
// }
PrintToServer("%s", colored_buffer);
// checking if the convar exists at all before we actually check the value
if (stac_print_to_admin_console && stac_print_to_admin_console.BoolValue)
{
PrintToConsoleAllAdmins("%s", buffer);
}
}
void StacLogDemo()
{
if (GetDemoName())
{
StacLog("Demo file: %s. Demo tick: %i", demoname, demotick);
}
}
void StacLogSteam(int userid)
{
int cl = GetClientOfUserId(userid);
StacLog
("\
\n Player: %L\
\n StAC cached SteamID: %s\
",
cl,
SteamAuthFor[cl]
);
}
void StacLogNetData(int userid)
{
int cl = GetClientOfUserId(userid);
StacLog
(
"\
\nNetwork:\
\n %.2f ms ping\
\n %.2f loss\
\n %.2f inchoke\
\n %.2f outchoke\
\n %.2f totalchoke\
\n %.2f kbps rate\
\n %.2f pps rate\
",
pingFor[cl],
lossFor[cl],
inchokeFor[cl],
outchokeFor[cl],
chokeFor[cl],
rateFor[cl],
ppsFor[cl]
);
StacLog
(
"\
\nMore network:\
\n Approx client cmdrate: ≈%i cmd/sec\
\n Approx server tickrate: ≈%i tick/sec\
\n Failing lag check? %s\
\n SequentialCmdnum? %s\
",
tickspersec[cl],
tickspersec[0],
IsUserLagging(cl) ? "yes" : "no",
isCmdnumSequential(cl) ? "yes" : "no"
);
}
void StacLogMouse(int userid)
{
int cl = GetClientOfUserId(userid);
//if (GetRandomInt(1, 5) == 1)
//{
// QueryClientConVar(Cl, "sensitivity", ConVarCheck);
//}
// init vars for mouse movement - weightedx and weightedy
int wx;
int wy;
// scale mouse movement to sensitivity
if (sensFor[cl] != 0.0)
{
wx = abs(RoundFloat(clmouse[cl][0] * ( 1 / sensFor[cl])));
wy = abs(RoundFloat(clmouse[cl][1] * ( 1 / sensFor[cl])));
}
StacLog
(
"\
\nMouse Movement (sens weighted):\
\n abs(x): %i\
\n abs(y): %i\
\nMouse Movement (unweighted):\
\n x: %i\
\n y: %i\
\nClient Sens:\
\n %f\
",
wx,
wy,
clmouse[cl][0],
clmouse[cl][1],
sensFor[cl]
);
// log buttons whenever we log mouse
StacLogButtons(userid);
}
void StacLogAngles(int userid)
{
int cl = GetClientOfUserId(userid);
StacLog
(
"\
\nAngles:\
\n angles0: x %f y %f\
\n angles1: x %f y %f\
\n angles2: x %f y %f\
\n angles3: x %f y %f\
\n angles4: x %f y %f\
",
clangles[cl][0][0],
clangles[cl][0][1],
clangles[cl][1][0],
clangles[cl][1][1],
clangles[cl][2][0],
clangles[cl][2][1],
clangles[cl][3][0],
clangles[cl][3][1],
clangles[cl][4][0],
clangles[cl][4][1]
);
StacLog
(
"\
\nClient eye positions:\
\n eyepos 0: x %.3f y %.3f z %.3f\
\n eyepos 1: x %.3f y %.3f z %.3f\
",
clpos[cl][0][0],
clpos[cl][0][1],
clpos[cl][0][2],
clpos[cl][1][0],
clpos[cl][1][1],
clpos[cl][1][2]
);
}
void StacLogCmdnums(int userid)
{
int cl = GetClientOfUserId(userid);
StacLog
(
"\
\nPrevious cmdnums:\
\n0 %i\
\n1 %i\
\n2 %i\
\n3 %i\
\n4 %i\
",
clcmdnum[cl][0],
clcmdnum[cl][1],
clcmdnum[cl][2],
clcmdnum[cl][3],
clcmdnum[cl][4]
);
}
void StacLogTickcounts(int userid)
{
int cl = GetClientOfUserId(userid);
StacLog
(
"\
\nPrevious tickcounts:\
\n0 %i\
\n1 %i\
\n2 %i\
\n3 %i\
\n4 %i\
",
cltickcount[cl][0],
cltickcount[cl][1],
cltickcount[cl][2],
cltickcount[cl][3],
cltickcount[cl][4]
);
StacLog
(
"\
\nCurrent server tick:\
\n%i\
",
GetGameTickCount()
);
}
void StacLogButtons(int userid)
{
int cl = GetClientOfUserId(userid);
StacLog
(
"\
\nPrevious buttons - use https://sapphonie.github.io/flags.html to convert to readable input\
\n0 %i\
\n1 %i\
\n2 %i\
\n3 %i\
\n4 %i\
",
clbuttons[cl][0],
clbuttons[cl][1],
clbuttons[cl][2],
clbuttons[cl][3],
clbuttons[cl][4]
);
}
/********** ISVALIDCLIENT STUFF *********/
bool IsValidClient(int cl)
{
if
(
(0 < cl <= MaxClients)
&& IsClientInGame(cl)
&& !IsClientInKickQueue(cl)
&& !userBanQueued[cl]
&& !IsFakeClient(cl)
)
{
return true;
}
return false;
}
bool IsValidClientOrBot(int cl)
{
if
(
(0 < cl <= MaxClients)
&& IsClientInGame(cl)
&& !IsClientInKickQueue(cl)
&& !userBanQueued[cl]
// don't bother sdkhooking stv or replay bots lol
&& !IsClientSourceTV(cl)
&& !IsClientReplay(cl)
)
{
return true;
}
return false;
}
bool IsValidAdmin(int cl)
{
if (IsValidClient(cl))
{
// can this client ban, or are they me, sappho?
if
(
CheckCommandAccess(cl, "sm_ban", ADMFLAG_GENERIC)
//|| Maybe someday, w/ stac_telemetry. Not today. -sappho
//StrEqual(SteamAuthFor[cl], "STEAM_0:1:124178191")
)
{
return true;
}
}
return false;
}
bool IsValidSrcTV(int client)
{
if
(
0 < client <= MaxClients
&& IsClientInGame(client)
&& IsClientSourceTV(client)
)
{
return true;
}
return false;
}
/********** MISC FUNCS **********/
void BanUser(int userid, char reason[128], char pubreason[256])
{
int cl = GetClientOfUserId(userid);
// prevent double bans
if (userBanQueued[cl])
{
KickClient(cl, "Banned from server");
return;
}
StacNotify(userid, reason);
char cleaned_pubreason[256];
if ( stac_generic_ban_msgs.BoolValue )
{
Format(reason, sizeof(reason), "%t", "GenericBanMsg", cl);
Format(cleaned_pubreason, sizeof(cleaned_pubreason), "%t", "GenericBanAllChat", cl);
}
else
{
strcopy(cleaned_pubreason, sizeof(cleaned_pubreason), pubreason);
}
// make sure we dont detect on already banned players
userBanQueued[cl] = true;
// check if client is authed before banning normally
bool isAuthed = IsClientAuthorized(cl);
int banDuration = stac_ban_duration.IntValue;
if (stac_include_demoname_in_banreason.BoolValue && SourceTV_IsRecording() && GetDemoName())
{
char demoname_plus[256];
strcopy(demoname_plus, sizeof(demoname_plus), demoname);
Format(demoname_plus, sizeof(demoname_plus), ". Demo file: %s", demoname_plus);
StrCat(reason, 256, demoname_plus);
StacLog("Reason: %s", reason);
}
if (isAuthed)
{
if (SOURCEBANS)
{
SBPP_BanPlayer(0, cl, banDuration, reason);
// there's no return value for that native, so we have to just assume it worked lol
return;
}
if (MATERIALADMIN)
{
MABanPlayer(0, cl, MA_BAN_STEAM, banDuration, reason);
return;
}
if (GBANS)
{
ServerCommand("gb_ban %i, %i, %s", userid, banDuration, reason);
// There is a native for gbans now but i don't think it can accept the server as an admin
// GB_BanClient(0 /* ? */, userid /* ? */, cheating, banDuration, BSBanned);
return;
}
// stock tf2, no ext ban system. if we somehow fail here, keep going.
if (BanClient(cl, banDuration, BANFLAG_AUTO, reason, reason, _, _))
{
return;
}
}
// if we got here steam is being fussy or the client is not auth'd in some way, or the stock tf2 ban failed somehow.
StacLog("Client %N is not authorized, steam is down, or the ban failed for some other reason. Attempting to ban with cached SteamID...", cl);
// if this returns true, we can still ban the client with their steamid in a roundabout and annoying way.
if (!IsActuallyNullString(SteamAuthFor[cl]))
{
ServerCommand("sm_addban %i \"%s\" %s", banDuration, SteamAuthFor[cl], reason);
KickClient(cl, "%s", reason);
}
// if the above returns false, we can only do ip :/
else
{
char ip[16];
GetClientIP(cl, ip, sizeof(ip));
StacLog("No cached SteamID for %N! Banning with IP %s...", cl, ip);
ServerCommand("sm_banip %s %i %s", ip, banDuration, reason);
// this kick client might not be needed - you get kicked by "being added to ban list"
// KickClient(cl, "%s", reason);
}
MC_PrintToChatAll("%s", cleaned_pubreason);
StacLog("%s", pubreason);
}
bool GetDemoName()
{
demotick = SourceTV_GetRecordingTick();
if (!SourceTV_GetDemoFileName(demoname, sizeof(demoname)))
{
demoname = "N/A";
return false;
}
return true;
}
bool isDefaultTickrate()
{
// Hack! Sometimes tps is set as default when it really isn't
if (tps == 0)
{
DoTPSMath();
}
// 66.66666 -> 67
if (itps == 67)
{
return true;
}
return false;
}
void calcTPSfor(int cl)
{
t[cl]++;
if (GetEngineTime() - 1.0 >= secTime[cl])
{
secTime[cl] = GetEngineTime();
tickspersec[cl] = t[cl];
t[cl] = 0;
}
}
bool IsActuallyNullString(char[] somestring)
{
if (somestring[0] != '\0')
{
return false;
}
return true;
}
bool IsHalloweenCond(TFCond condition)
{
if
(
condition == TFCond_HalloweenKart
|| condition == TFCond_HalloweenKartDash
|| condition == TFCond_HalloweenThriller
|| condition == TFCond_HalloweenBombHead
|| condition == TFCond_HalloweenGiant
|| condition == TFCond_HalloweenTiny
|| condition == TFCond_HalloweenInHell
|| condition == TFCond_HalloweenGhostMode
|| condition == TFCond_HalloweenKartNoTurn
|| condition == TFCond_HalloweenKartCage
|| condition == TFCond_SwimmingCurse
)
{
return true;
}
return false;
}
/********** MISC CLIENT CHECKS **********/
// is client on a team and not dead
bool IsClientPlaying(int client)
{
TFTeam team = TF2_GetClientTeam(client);
if
(
IsPlayerAlive(client)
&&
(
team != TFTeam_Unassigned && team != TFTeam_Spectator
)
)
{
return true;
}
return false;
}
/********** PRINT HELPER FUNCS **********/
// print colored chat to all server/sourcemod admins
void PrintToImportant(const char[] format, any ...)
{
char buffer[254];
// print translations in the servers lang first
SetGlobalTransTarget(LANG_SERVER);
// format it properly
VFormat(buffer, sizeof(buffer), format, 2);
// print detections to staclog as well
if (StrContains(buffer, "detect", false) != -1)
{
// seperate detections with a lotta whitespace for easier readability
StacLog("\n\n----------\n\n%s", buffer);
}
buffer[0] = '\0';
for (int i = 1; i <= MaxClients; i++)
{
// If this cvar is 0 (default), StAC will print detections to admins with sm_ban access and to SourceTV, if extant.
// If this cvar is 1, it will print only to SourceTV.
// If this cvar is 2, StAC never print anything in chat to anyone, ever.
// If this cvar is -1, StAC will print ALL detections to ALL players
if
(
(stac_silent.IntValue == -1 && (IsValidClient(i) || IsValidSrcTV(i)))
||
(stac_silent.IntValue == 0 && (IsValidAdmin(i) || IsValidSrcTV(i)))
||
(stac_silent.IntValue == 1 && IsValidSrcTV(i))
)
{
SetGlobalTransTarget(i);
VFormat(buffer, sizeof(buffer), format, 2);
MC_PrintToChat(i, "%s", buffer);
}
}
}
// print to all server/sourcemod admin's consoles
void PrintToConsoleAllAdmins(const char[] format, any ...)
{
char buffer[254];
for (int i = 1; i <= MaxClients; i++)
{
if (IsValidAdmin(i) || IsValidSrcTV(i))
{
SetGlobalTransTarget(i);
VFormat(buffer, sizeof(buffer), format, 2);
PrintToConsole(i, "%s", buffer);
}
}
}
/********** MATH STUFF **********/
int math_min(int a, int b)
{
return a < b ? a : b;
}
int math_max(int a, int b)
{
return a > b ? a : b;
}
int clamp(int num, int minnum, int maxnum)
{
num = math_max(num, minnum);
return math_min(num, maxnum);
}
any abs(any x)
{
return x > 0 ? x : -x;
}
/*
float RoundToPlace(float input, int decimalPlaces)
{
float poweroften = Pow(10.0, float(decimalPlaces));
return RoundToNearest(input * poweroften) / (poweroften);
}
bool IsZeroVector(const float vec[3])
{
if
(
vec[0] == 0.0
&& vec[1] == 0.0
&& vec[2] == 0.0
)
{
return true;
}
return false;
}
*/
/********** UPDATER **********/
public void OnLibraryAdded(const char[] name)
{
if (StrEqual(name, "updater"))
{
Updater_AddPlugin(UPDATE_URL);
}
}
/********** DETECTIONS & DISCORD **********/
// if our userid is 0, it's a server message without a client
// if our detections are 0, it's a client message without a detection
// otherwise, it's a detection with a number of detections
void StacNotify(int userid, const char[] prefmtedstring, int detections = 0)
{
// This prevents a strange race condition where StAC seems to explode using ban
// systems that don't ban immediately, resulting in a ridiculous amount of discord spam.
// I'm still investigating, so this may not fully fix the issue.
int cl = GetClientOfUserId(userid);
if (userBanQueued[cl])
{
return;
}
StacLogDemo();
if (!DISCORD)
{
return;
}
static char output[8192 * 2];
output[0] = 0x0;
// individual fields
// empty fields for spacing
JSON_Object spacerField = new JSON_Object();
spacerField.EnableOrderedKeys();
spacerField.SetString("name", " ");
spacerField.SetString("value", " ");
spacerField.SetBool ("inline", false);
JSON_Object spacerCpy1;
if (userid)
{
spacerCpy1 = spacerField.DeepCopy();
}
JSON_Object spacerCpy2 = spacerField.DeepCopy();
JSON_Object spacerCpy3 = spacerField.DeepCopy();
JSON_Object spacerCpy4 = spacerField.DeepCopy();
JSON_Object spacerCpy5 = spacerField.DeepCopy();
JSON_Object spacerCpy6;
JSON_Object spacerCpy7;
if (detections)
{
spacerCpy6 = spacerField.DeepCopy();
spacerCpy7 = spacerField.DeepCopy();
}
// this isn't used anywhere we're just using it to copy off of
json_cleanup_and_delete(spacerField);
JSON_Object nameField;
JSON_Object steamIDfield;
if (userid)
{
// playername
char ClName[64];
GetClientName(cl, ClName, sizeof(ClName));
Discord_EscapeString(ClName, sizeof(ClName));
json_escape_string(ClName, sizeof(ClName));
nameField = new JSON_Object();
nameField.EnableOrderedKeys();
nameField.SetString("name", "Player");
nameField.SetString("value", ClName);
nameField.SetBool("inline", true);
// steamid
// we technically store the url in this so it has to be bigger
char steamid[96];
// ok we store these on client connect & auth, this shouldn't be null
if ( SteamAuthFor[cl][0] )
{
// make this a clickable link in discord
Format(steamid, sizeof(steamid), "[%s](https://steamid.io/lookup/%s)", SteamAuthFor[cl], SteamAuthFor[cl]);
}
// if it is, that means we lateloaded and the client was unauth'd.
else
{
steamid = "N/A";
}
steamIDfield = new JSON_Object();
steamIDfield.EnableOrderedKeys();
steamIDfield.SetString("name", "SteamID");
steamIDfield.SetString("value", steamid);
steamIDfield.SetBool ("inline", true);
}
// detection / notify fields
JSON_Object detectOrMsgfield = new JSON_Object();
detectOrMsgfield.EnableOrderedKeys();
if (!userid)
{
detectOrMsgfield.SetString("name", "Message");
}
else if (!detections)
{
detectOrMsgfield.SetString("name", "Notification");
}
else
{
detectOrMsgfield.SetString("name", "Detection");
}
detectOrMsgfield.SetString("value", prefmtedstring);
detectOrMsgfield.SetBool("inline", true);
// number of detections
JSON_Object detectNumfield;
if (detections)
{
detectNumfield = new JSON_Object();
detectNumfield.EnableOrderedKeys();
detectNumfield.SetString("name", "Detection #");
detectNumfield.SetInt("value", detections);
detectNumfield.SetBool("inline", true);
}
// server hostname
char hostname[256];
GetConVarString(FindConVar("hostname"), hostname, sizeof(hostname));
JSON_Object hostname_field = new JSON_Object();
hostname_field.EnableOrderedKeys();
hostname_field.SetString("name", "Hostname");
hostname_field.SetString("value", hostname);
hostname_field.SetBool ("inline", true);
// server IP - steam:///connect ??
JSON_Object serverip_field = new JSON_Object();
serverip_field.EnableOrderedKeys();
serverip_field.SetString("name", "Server IP");
serverip_field.SetString("value", hostipandport);
serverip_field.SetBool ("inline", true);
// STV
GetDemoName();
JSON_Object demoname_field = new JSON_Object();
demoname_field.EnableOrderedKeys();
demoname_field.SetString("name", "Demo name");
demoname_field.SetString("value", demoname);
demoname_field.SetBool ("inline", true);
JSON_Object demotick_field = new JSON_Object();
demotick_field.EnableOrderedKeys();
demotick_field.SetString("name", "Demo tick");
demotick_field.SetInt ("value", demotick);
demotick_field.SetBool ("inline", true);
float tickedTime = GetTickedTime();
char tickedTimeStr[512];
// 1 day
if (tickedTime > 86400)
{
Format
(
tickedTimeStr,
sizeof(tickedTimeStr),
"%.2f minutes(!)\n\n\
Source Engine has memory leaks\n\
and suffers from \n\
[floating point precision loss](https://www.youtube.com/watch?v=RdTJHVG_IdU)\n\
after running for too long.\n\
You should restart your server ASAP,\n\
or it will become choppy,\n\
and StAC may not work correctly!",
tickedTime / 60.0
);
}
else
{
Format
(
tickedTimeStr,
sizeof(tickedTimeStr),
"%.2f minutes",
tickedTime / 60.0
);
}
JSON_Object gametime_field = new JSON_Object();
gametime_field.EnableOrderedKeys();
gametime_field.SetString("name", "Approx server uptime");
gametime_field.SetString("value", tickedTimeStr);
gametime_field.SetBool ("inline", true);
JSON_Object servertick_field = new JSON_Object();
servertick_field.EnableOrderedKeys();
servertick_field.SetString("name", "Server tick");
servertick_field.SetInt ("value", servertick);
servertick_field.SetBool ("inline", true);
int unixTimestamp = GetTime();
char discordTimestamp[512];
Format
(
discordTimestamp,
sizeof(discordTimestamp),
"\
<t:%i:T> on <t:%i:D>\n\
<t:%i:R>\
",
unixTimestamp,
unixTimestamp,
unixTimestamp
);
JSON_Object discordtimestamp_field = new JSON_Object();
discordtimestamp_field.EnableOrderedKeys();
discordtimestamp_field.SetString("name", "Discord Timestamp");
discordtimestamp_field.SetString("value", discordTimestamp);
discordtimestamp_field.SetBool ("inline", true);
JSON_Object unixtimestamp_field = new JSON_Object();
unixtimestamp_field.EnableOrderedKeys();
unixtimestamp_field.SetString("name", "Unix Timestamp");
unixtimestamp_field.SetInt ("value", unixTimestamp);
unixtimestamp_field.SetBool ("inline", true);
JSON_Object viewangle_field;
JSON_Object clpos_field;
JSON_Object tickcount_field;
JSON_Object cmdnum_field;
JSON_Object buttons_field;
JSON_Object netinfo_field;
if (detections)
{
// VIEWANGLES
char viewangleHistoryBuf[1024];
Format
(
viewangleHistoryBuf,
sizeof(viewangleHistoryBuf),
"```\
==----pitch---yaw-----roll-----\n\
0 | %7.2f %7.2f %7.2f\n\
1 | %7.2f %7.2f %7.2f\n\
2 | %7.2f %7.2f %7.2f\n\
3 | %7.2f %7.2f %7.2f\n\
4 | %7.2f %7.2f %7.2f\n\
```",
// angles
clangles[cl][0][0],
clangles[cl][0][1],
clangles[cl][0][2],
clangles[cl][1][0],
clangles[cl][1][1],
clangles[cl][1][2],
clangles[cl][2][0],
clangles[cl][2][1],
clangles[cl][2][2],
clangles[cl][3][0],
clangles[cl][3][1],
clangles[cl][3][2],
clangles[cl][4][0],
clangles[cl][4][1],
clangles[cl][4][2]
);
viewangle_field = new JSON_Object();
viewangle_field.EnableOrderedKeys();
viewangle_field.SetString("name", "viewangle history");
viewangle_field.SetString("value", viewangleHistoryBuf);
viewangle_field.SetBool ("inline", false);
// EYE POSITIONS