-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathanticheat.patch
1212 lines (1163 loc) · 52.1 KB
/
anticheat.patch
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
diff --git src/anticheat/anticheat.cpp src/anticheat/anticheat.cpp
new file mode 100644
index 0000000..2fe07ee
--- /dev/null
+++ src/anticheat/anticheat.cpp
@@ -0,0 +1,640 @@
+#ifdef ANTICHEAT
+/*
+Integrates Epic's Online Services (EOS) SDK in order to provide protected anti-cheat sessions.
+
+In order to use the Anti-Cheat service, we need to have a Platform handle first. Our main
+use for the platform handle is to time communication between the SDK and Epic's backend.
+(See TickBudgetInMilliseconds and anticheattick().)
+
+Before we can create a Platform instance, we need to initialize the SDK. So when the engine
+calls initializeanticheat(), that calls initializesdk() which in turn calls
+initializeplatform() to set everything up.
+
+Before using the Anti-Cheat service on the client, we need to have a Product User ID, i.e.
+be logged in via the Connect service. triggeranticheatsession() takes care of this for us.
+
+The Anti-Cheat service requires us to provide a mechanism for it to shuttle encrypted messages
+between client and server. To do so, we have to register a "message to server" callback in
+the client and a "message to client" callback in the server, which the SDK will call whenever
+it wants data transmitted. (See *_AddNotify* functions.)
+We then pass the message back to the SDK on the other side (see ReceiveMessageFrom* functions).
+
+On top of that, the server needs to provide callbacks for "client's auth status changed" as
+well as "client action required" (read "player ain't clean").
+
+A server's anti-cheat session starts when it is launched and only ends when the process is
+terminated/killed/whatever. A client's anti-cheat session starts when triggered by a server
+and ends when the server says so or the client disconnects.
+
+Regarding this file's code structure:
+ - All functions in this file starting with "on" are callbacks and only ever called by the SDK.
+ - SDK & Platform setup is the same on client and server and is defined first.
+ - Inside the game namespace, first come Connect related things to log the user in, then anti-
+ cheat callback functions, then all functions exposed via game.h, then the functions exposed
+ via igame.h.
+ - The server namespace is organized similarly, just without the Connect stuff at the top.
+*/
+
+#include "game.h"
+#include "eos_sdk.h"
+#include "eos_logging.h"
+#include "decrypt_credentials.h"
+
+EOS_HPlatform platform = NULL;
+
+void initializeplatform(bool server = false)
+{
+ #include "credentials.cpp"
+
+ static EOS_Platform_ClientCredentials creds;
+ creds.ClientId = server ? serverId : clientId;
+ creds.ClientSecret = server ? serverSecret : clientSecret;
+
+ static EOS_Platform_Options platformoptions = {};
+ platformoptions.ApiVersion = EOS_PLATFORM_OPTIONS_API_LATEST;
+ platformoptions.bIsServer = server ? EOS_TRUE : EOS_FALSE;
+ platformoptions.EncryptionKey = NULL; // todo?
+ platformoptions.Flags = EOS_PF_DISABLE_OVERLAY;
+ platformoptions.CacheDirectory = NULL;
+ platformoptions.ProductId = "36e0587a4c3544e8b635f7f55e7ccbfe";
+ platformoptions.SandboxId = "7743e9c6960a42c7a32772a6d1b8af60";
+ platformoptions.DeploymentId = "011295e7b04049d7978fcaa38d79bf86";
+ platformoptions.TickBudgetInMilliseconds = 5;
+ platformoptions.ClientCredentials = creds;
+ platform = EOS_Platform_Create(&platformoptions);
+}
+
+void releaseplatform()
+{
+ // calling EOS_Platform_Release() makes the client hang for a second
+ // on Linux and even longer on Windows, so we just don't...
+ // if(platform) EOS_Platform_Release(platform);
+}
+
+void logeossdkmessage(const EOS_LogMessage *msg)
+{
+ int level = CON_INFO;
+ string levelname = "[info]";
+ switch(msg->Level)
+ {
+ case EOS_ELogLevel::EOS_LOG_Fatal: level = CON_ERROR; copystring(levelname, "[fatal]"); break;
+ case EOS_ELogLevel::EOS_LOG_Error: level = CON_ERROR; copystring(levelname, "[error]"); break;
+#ifdef DEBUG
+ case EOS_ELogLevel::EOS_LOG_Warning: level = CON_WARN; copystring(levelname, "[warning]"); break;
+ case EOS_ELogLevel::EOS_LOG_Info: break;
+ default: copystring(levelname, "[debug]"); break;
+#else
+ default: return; // discard
+#endif
+ }
+ conoutf(level, "\fs\f8[anti-cheat]\fr SDK: %s: %s: %s", levelname, msg->Category, msg->Message);
+#ifndef STANDALONE
+ static bool warned = false;
+ if(!warned && level > CON_WARN)
+ {
+ conoutf(CON_WARN, "\fs\f8[anti-cheat]\fr \f3something is wrong with your client; it might not get recognized by anti-cheat servers\nplease contact p1x and provide this error log");
+ warned = true;
+ }
+#endif
+}
+
+bool eossdkinitialized = false;
+
+int initializesdk(bool server = false)
+{
+ static EOS_InitializeOptions sdkoptions = {};
+ sdkoptions.ApiVersion = EOS_INITIALIZE_API_LATEST;
+ sdkoptions.ProductName = "p1xbraten anti-cheat";
+ sdkoptions.ProductVersion = "1.0";
+
+ switch (EOS_EResult e = EOS_Initialize(&sdkoptions))
+ {
+ case EOS_EResult::EOS_Success: eossdkinitialized = true; break;
+ case EOS_EResult::EOS_AlreadyConfigured: conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr init: SDK is already configured"); return 1;
+ case EOS_EResult::EOS_InvalidParameters: conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr init: SDK options are invalid"); return 2;
+ default: conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr unexpected return value %d from EOS_Initialize()", (int) e); return 3;
+ }
+#if defined(DEBUG) || defined(STANDALONE)
+ EOS_ELogLevel loglevel = EOS_ELogLevel::EOS_LOG_VeryVerbose;
+#else
+ EOS_ELogLevel loglevel = EOS_ELogLevel::EOS_LOG_Error;
+#endif
+
+ switch (EOS_EResult e = EOS_Logging_SetLogLevel(EOS_ELogCategory::EOS_LC_ALL_CATEGORIES, loglevel))
+ {
+ case EOS_EResult::EOS_Success: break;
+ case EOS_EResult::EOS_NotConfigured: conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr setting log level: SDK not configured"); return 1;
+ default: conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr unexpected return value %d from EOS_Logging_SetLogLevel()", (int) e); return 3;
+ }
+
+ switch (EOS_EResult e = EOS_Logging_SetCallback(logeossdkmessage))
+ {
+ case EOS_EResult::EOS_Success: break;
+ case EOS_EResult::EOS_NotConfigured: conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr setting log callback: SDK not configured"); return 1;
+ default: conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr unexpected return value %d from EOS_Logging_SetCallback()", (int) e); return 3;
+ }
+
+ initializeplatform(server);
+ return 0;
+}
+
+void shutdownsdk()
+{
+ releaseplatform();
+ if(!eossdkinitialized) return;
+ switch (EOS_EResult e = EOS_Shutdown())
+ {
+ case EOS_EResult::EOS_Success: eossdkinitialized = false; break;
+ case EOS_EResult::EOS_NotConfigured: conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr shutdown: SDK not configured"); return;
+ case EOS_EResult::EOS_UnexpectedError: conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr shutdown: SDK already shut down"); return;
+ default: conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr unexpected return value %d from EOS_Shutdown()", (int) e); return;
+ }
+}
+
+void anticheattick()
+{
+ if(platform) EOS_Platform_Tick(platform);
+}
+
+#ifndef STANDALONE
+
+namespace game {
+
+ EOS_ProductUserId eosuserid;
+
+ void startanticheatsession();
+
+ // called when EOS_Connect_CreateUser() completes (after login failed because the user is unknown to Epic)
+ void oneosusercreated(const EOS_Connect_CreateUserCallbackInfo *data)
+ {
+ // conoutf("EOS_Connect_CreateUser() completed with code %d", (int) data->ResultCode);
+ switch(EOS_EResult e = data->ResultCode)
+ {
+ case EOS_EResult::EOS_Success:
+ eosuserid = data->LocalUserId;
+ // conoutf("EOS_Connect_CreateUser() succeeded");
+ startanticheatsession();
+ break;
+ default: conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr EOS_Connect_CreateUser() failed with result code %d", (int) e); break;
+ }
+ }
+
+ EOS_HConnect eosconnect;
+
+ // called when EOS_Connect_Login() completes
+ void oneoslogincompleted(const EOS_Connect_LoginCallbackInfo *data)
+ {
+ // conoutf("EOS_Connect_Login() completed with code %d", (int) data->ResultCode);
+ switch(EOS_EResult e = data->ResultCode)
+ {
+ case EOS_EResult::EOS_Success:
+ eosuserid = data->LocalUserId;
+ // conoutf("EOS_Connect_Login() succeeded");
+ startanticheatsession();
+ break;
+ case EOS_EResult::EOS_InvalidUser: // user is new to Epic, must be created
+ {
+ EOS_Connect_CreateUserOptions connectopts;
+ connectopts.ApiVersion = EOS_CONNECT_CREATEUSER_API_LATEST;
+ connectopts.ContinuanceToken = data->ContinuanceToken;
+ EOS_Connect_CreateUser(eosconnect, &connectopts, NULL, oneosusercreated);
+ break;
+ }
+ default: conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr EOS_Connect_Login() failed with result code %d", (int) e); break;
+ }
+ }
+
+ void eoslogin(char *eosname)
+ {
+ if(eosuserid) return;
+ // conoutf("initializing EOS user");
+ if(!eosconnect) eosconnect = EOS_Platform_GetConnectInterface(platform);
+ if(!eosconnect) { conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr failed to get connect interface handle from SDK"); return; }
+
+ // Epic's anti-cheat framework requires a stable identity to be assigned to each client. I use
+ // the player's name and client number. In order for Epic to accept this "hack", I configured an
+ // OpenID provider as identity provider for this "product" in Epic's dev portal.
+ // Instead of a complete OpenID/OAuth implementation, just the so called "userinfo" endpoint is
+ // required. I just deployed a server that echos back the "token" submitted in the Authorization
+ // header as the user's ID.
+
+ static EOS_Connect_Credentials creds;
+ creds.ApiVersion = EOS_CONNECT_CREDENTIALS_API_LATEST;
+ creds.Type = EOS_EExternalCredentialType::EOS_ECT_OPENID_ACCESS_TOKEN;
+ creds.Token = eosname;
+
+ static EOS_Connect_LoginOptions loginopts;
+ loginopts.ApiVersion = EOS_CONNECT_LOGIN_API_LATEST;
+ loginopts.Credentials = &creds;
+ loginopts.UserLoginInfo = NULL;
+
+ EOS_Connect_Login(eosconnect, &loginopts, NULL, oneoslogincompleted);
+ }
+
+ #include <eos_anticheatclient.h>
+
+ void onmessagetoserver(const EOS_AntiCheatClient_OnMessageToServerCallbackInfo *data)
+ {
+ static uchar buf[1024]; // EOS docs say message is up to 256 bytes, but I saw message sizes up to 512
+ ucharbuf p(buf, sizeof(buf));
+ putint(p, N_P1X_ANTICHEAT_MESSAGE);
+ putuint(p, data->MessageDataSizeBytes);
+ p.put((const uchar *) data->MessageData, data->MessageDataSizeBytes);
+ messages.put(p.getbuf(), p.length());
+ p.empty();
+ }
+
+ void onintegrityviolation(const EOS_AntiCheatClient_OnClientIntegrityViolatedCallbackInfo* data)
+ {
+ // conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr violation detected: %s (%d)", data->ViolationMessage, (int) data->ViolationType);
+ // violation detected, but we won't tell the client that yet
+ addmsg(N_P1X_ANTICHEAT_VIOLATION, "ris", (int) data->ViolationType, data->ViolationMessage);
+ }
+
+ bool anticheatinitialized = false;
+ EOS_HAntiCheatClient acc = NULL;
+ bool anticheatsessionactive = false;
+
+ bool anticheatready() { return eossdkinitialized; }
+
+ void startanticheatsession()
+ {
+ static char useridstring[EOS_PRODUCTUSERID_MAX_LENGTH+1];
+ int32_t useridstringlen = sizeof(useridstring);
+ switch (EOS_EResult e = EOS_ProductUserId_ToString(eosuserid, useridstring, &useridstringlen))
+ {
+ case EOS_EResult::EOS_Success: /* OK */ break;
+ case EOS_EResult::EOS_InvalidParameters: conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr serializing EOS product user ID: input data invalid"); return;
+ case EOS_EResult::EOS_InvalidUser: conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr serializing EOS product user ID: user ID is invalid"); return;
+ case EOS_EResult::EOS_LimitExceeded: conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr serializing EOS product user ID: output buffer too short"); return;
+ default: conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr EOS_ProductUserId_ToString() failed with result code %d", (int) e); return;
+ }
+
+ static EOS_AntiCheatClient_BeginSessionOptions sessionopts;
+ sessionopts.ApiVersion = EOS_ANTICHEATSERVER_BEGINSESSION_API_LATEST;
+ sessionopts.LocalUserId = eosuserid;
+ sessionopts.Mode = EOS_EAntiCheatClientMode::EOS_ACCM_ClientServer;
+ switch (EOS_EResult e = EOS_AntiCheatClient_BeginSession(acc, &sessionopts))
+ {
+ case EOS_EResult::EOS_Success: /* conoutf("\fs\f8[anti-cheat]\fr started session"); */ break;
+ case EOS_EResult::EOS_InvalidParameters: conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr starting session: input data invalid"); return;
+ case EOS_EResult::EOS_AntiCheat_InvalidMode: /* conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr starting session: function not supported in current anti-cheat mode"); */ return;
+ default: conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr EOS_AntiCheatClient_BeginSession() failed with result code %d", (int) e); return;
+ }
+
+ addmsg(N_P1X_ANTICHEAT_BEGINSESSION, "rs", useridstring);
+ anticheatsessionactive = true;
+ }
+
+ void triggeranticheatsession()
+ {
+ // conoutf("\fs\f8[anti-cheat]\fr starting session");
+ if(!anticheatinitialized || !acc)
+ {
+ conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr not initialized\r");
+ conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr make sure you launch the game using the anticheat launcher");
+ return;
+ }
+ if(eosuserid) startanticheatsession();
+ else
+ {
+ // conoutf("\fs\f8[anti-cheat]\fr user not logged in, doing that now");
+ defformatstring(eosname, "%s (%d)", player1->name, player1->clientnum);
+ eoslogin(eosname);
+ }
+ }
+
+ void receiveanticheatmessage(ucharbuf &p)
+ {
+ static EOS_AntiCheatClient_ReceiveMessageFromServerOptions messageopts;
+ messageopts.ApiVersion = EOS_ANTICHEATCLIENT_RECEIVEMESSAGEFROMSERVER_API_LATEST;
+ messageopts.DataLengthBytes = p.remaining();
+ messageopts.Data = p.getbuf();
+
+ if(!anticheatinitialized || !acc) { /*conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr received N_P1X_ANTICHEAT_MESSAGE but anti-cheat not initialized");*/ return; }
+
+ switch (EOS_EResult e = EOS_AntiCheatClient_ReceiveMessageFromServer(acc, &messageopts))
+ {
+ case EOS_EResult::EOS_Success: break;
+ case EOS_EResult::EOS_InvalidParameters: conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr receiving message from server: input data invalid"); return;
+ case EOS_EResult::EOS_AntiCheat_InvalidMode: /* conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr receiving message from server: function not supported in current mode"); */ return;
+ default: conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr EOS_AntiCheatClient_ReceiveMessageFromServer() failed with result code %d", (int) e); return;
+ }
+ }
+
+ bool endanticheatsession()
+ {
+ if(!acc || !anticheatsessionactive) return true;
+
+ static EOS_AntiCheatClient_EndSessionOptions sessionopts;
+ sessionopts.ApiVersion = EOS_ANTICHEATSERVER_ENDSESSION_API_LATEST;
+ switch (EOS_EResult e = EOS_AntiCheatClient_EndSession(acc, &sessionopts))
+ {
+ case EOS_EResult::EOS_Success: break;
+ case EOS_EResult::EOS_InvalidParameters: conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr ending session: input data invalid"); return false;
+ case EOS_EResult::EOS_AntiCheat_InvalidMode: /* conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr ending session: function not supported in current mode"); */ return false;
+ default: conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr EOS_AntiCheatClient_EndSession() failed with result code %d", (int) e); return false;
+ }
+ anticheatsessionactive = false;
+ return true;
+ }
+
+ EOS_NotificationId anticheatmessagetoservercallback;
+ EOS_NotificationId anticheatintegrityviolationcallback;
+
+ void initializeanticheat()
+ {
+ if(anticheatinitialized || (!eossdkinitialized && initializesdk())) return;
+
+ acc = EOS_Platform_GetAntiCheatClientInterface(platform);
+
+ // register c2s function for EOS messages
+ static EOS_AntiCheatClient_AddNotifyMessageToServerOptions messagecallbackopts;
+ messagecallbackopts.ApiVersion = EOS_ANTICHEATCLIENT_ADDNOTIFYMESSAGETOSERVER_API_LATEST;
+ anticheatmessagetoservercallback = EOS_AntiCheatClient_AddNotifyMessageToServer(acc, &messagecallbackopts, NULL, onmessagetoserver);
+ if(anticheatmessagetoservercallback==EOS_INVALID_NOTIFICATIONID)
+ {
+ conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr init: failed to register message-to-server callback");
+ return;
+ }
+
+ // register callback for detected integrity violations
+ static EOS_AntiCheatClient_AddNotifyClientIntegrityViolatedOptions violationcallbackopts;
+ violationcallbackopts.ApiVersion = EOS_ANTICHEATCLIENT_ADDNOTIFYPEERAUTHSTATUSCHANGED_API_LATEST;
+ anticheatintegrityviolationcallback = EOS_AntiCheatClient_AddNotifyClientIntegrityViolated(acc, &violationcallbackopts, NULL, onintegrityviolation);
+ if(anticheatintegrityviolationcallback==EOS_INVALID_NOTIFICATIONID)
+ {
+ conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr init: failed to register integrity violation callback");
+ return;
+ }
+
+ anticheatinitialized = true;
+ conoutf("\fs\f8[anti-cheat]\fr initialized");
+ }
+
+ void shutdownanticheat()
+ {
+ if(!anticheatinitialized) return;
+ // un-register callbacks
+ if(acc)
+ {
+ if(anticheatintegrityviolationcallback!=EOS_INVALID_NOTIFICATIONID) EOS_AntiCheatClient_RemoveNotifyClientIntegrityViolated(acc, anticheatintegrityviolationcallback);
+ if(anticheatmessagetoservercallback!=EOS_INVALID_NOTIFICATIONID) EOS_AntiCheatClient_RemoveNotifyMessageToServer(acc, anticheatmessagetoservercallback);
+ }
+ eosuserid = NULL;
+ if(eossdkinitialized) shutdownsdk();
+ }
+}
+
+#endif
+
+namespace server {
+
+ #include <eos_anticheatserver.h>
+
+ bool anticheatinitialized = false;
+ EOS_HAntiCheatServer acs = NULL;
+
+ void onmessagetoclient(const EOS_AntiCheatCommon_OnMessageToClientCallbackInfo *data)
+ {
+ clientinfo *ci = (clientinfo *) data->ClientHandle;
+ if(!ci) return;
+ packetbuf p(300, ENET_PACKET_FLAG_RELIABLE); // EOS docs say message is up to 256 bytes
+ putint(p, N_P1X_ANTICHEAT_MESSAGE);
+ putuint(p, data->MessageDataSizeBytes);
+ p.put((const uchar *) data->MessageData, data->MessageDataSizeBytes);
+ ENetPacket *packet = p.finalize();
+ sendpacket(ci->clientnum, 1, packet);
+ }
+
+ MOD(VARF, forceanticheatclient, 0, 0, 1, { loopv(clients) if(shouldspectate(clients[i])) forcespectator(clients[i]); });
+
+ void onclientactionrequired(const EOS_AntiCheatCommon_OnClientActionRequiredCallbackInfo *data)
+ {
+ clientinfo *ci = (clientinfo *) data->ClientHandle;
+ if(!ci)
+ {
+ conoutf("\fs\f8[anti-cheat]\fr action required: reason %d (details: %s)", (int) data->ActionReasonCode, data->ActionReasonDetailsString);
+ return;
+ }
+ else conoutf("\fs\f8[anti-cheat]\fr action required: client %s, reason %d (details: %s)", colorname(ci), (int) data->ActionReasonCode, data->ActionReasonDetailsString);
+ if(data->ClientAction==EOS_EAntiCheatCommonClientAction::EOS_ACCCA_RemovePlayer)
+ {
+ string msg;
+ if(data->ActionReasonCode == EOS_EAntiCheatCommonClientActionReason::EOS_ACCCAR_ClientViolation)
+ {
+ formatstring(msg, "\fs\f8[anti-cheat] \f3violation by %s: %s (code: %d)\fr",
+ colorname(ci), data->ActionReasonDetailsString, (int) data->ActionReasonCode
+ );
+ }
+ else
+ {
+ formatstring(msg, "\fs\f8[anti-cheat] \f3%s should be removed from the game: %s (code: %d)\fr",
+ colorname(ci), data->ActionReasonDetailsString, (int) data->ActionReasonCode
+ );
+ }
+ conoutf(CON_WARN, "%s", msg);
+ if(!forceanticheatclient) notifyprivclients(PRIV_AUTH, msg);
+ else
+ {
+ sendf(-1, 1, "ris", N_SERVMSG, msg);
+ forcespectator(ci);
+ formatstring(msg, "\fs\f8[anti-cheat] \f3forced %s to spectator\fr", colorname(ci));
+ }
+ }
+ }
+
+ static const char *authstatusname(int status)
+ {
+ static string asname[3] = {"unverified", "locally verified", "verified by Epic's backend"};
+ return asname[status];
+ }
+
+ void onclientauthstatuschanged(const EOS_AntiCheatCommon_OnClientAuthStatusChangedCallbackInfo *data)
+ {
+ clientinfo *ci = (clientinfo *) data->ClientHandle;
+ if(!ci) return;
+
+ int oldanticheatverified = ci->anticheatverified;
+ ci->anticheatverified = (int) data->ClientAuthStatus; // 0, 1, or 2; see authstatusname()
+
+ if(oldanticheatverified > ci->anticheatverified)
+ {
+ if(forceanticheatclient) forcespectator(ci);
+ defformatstring(msg, "\fs\f8[anti-cheat]\fr \f6%s had their auth status downgraded from %d (%s) to %d (%s)\fr",
+ colorname(ci),
+ oldanticheatverified, authstatusname(oldanticheatverified),
+ ci->anticheatverified, authstatusname(ci->anticheatverified)
+ );
+ conoutf(CON_WARN, "%s", msg);
+ notifyprivclients(PRIV_AUTH, msg);
+ loopv(clients) if(clients[i]->supportsanticheat && clients[i]->privilege >= PRIV_AUTH)
+ sendf(clients[i]->clientnum, 1, "ri3", N_P1X_ANTICHEAT_VERIFIED, ci->clientnum, 0);
+ }
+
+ if(oldanticheatverified < ci->anticheatverified)
+ {
+ defformatstring(msg, "\fs\f8[anti-cheat]\fr %s had their auth status upgraded from %d (%s) to %d (%s)",
+ colorname(ci),
+ oldanticheatverified, authstatusname(oldanticheatverified),
+ ci->anticheatverified, authstatusname(ci->anticheatverified)
+ );
+ conoutf(CON_WARN, "%s", msg);
+ if(ci->anticheatverified==2)
+ {
+ loopv(clients)
+ {
+ if(clients[i]->supportsanticheat) sendf(clients[i]->clientnum, 1, "ri3", N_P1X_ANTICHEAT_VERIFIED, ci->clientnum, 1);
+ if(clients[i]->anticheatverified==2) sendf(ci->clientnum, 1, "ri3", N_P1X_ANTICHEAT_VERIFIED, clients[i]->clientnum, 1);
+ }
+ defformatstring(msg, "\fs\f8[anti-cheat]\fr %s is using the p1xbraten anti-cheat client", colorname(ci));
+ sendf(-1, 1, "ris", N_SERVMSG, msg);
+ if(ci->state.state==CS_SPECTATOR && mastermode<MM_LOCKED) unspectate(ci);
+ }
+ }
+ }
+
+ void probeforanticheatclient(packetbuf &p)
+ {
+ putint(p, N_SERVCMD);
+ sendstring(CAP_PROBE_ANTICHEAT, p);
+ }
+
+ bool registeranticheatclient(clientinfo *ci, const char *useridstring)
+ {
+ conoutf("\fs\f8[anti-cheat]\fr registering %s (%d) with Epic's backend", ci->name, ci->clientnum);
+ EOS_ProductUserId eosuserid = EOS_ProductUserId_FromString(useridstring);
+
+ static EOS_AntiCheatServer_RegisterClientOptions registeropts;
+ registeropts.ApiVersion = EOS_ANTICHEATSERVER_REGISTERCLIENT_API_LATEST;
+ registeropts.ClientHandle = (EOS_AntiCheatCommon_ClientHandle) ci;
+ registeropts.ClientType = EOS_EAntiCheatCommonClientType::EOS_ACCCT_ProtectedClient;
+ registeropts.UserId = eosuserid;
+ registeropts.IpAddress = getclienthostname(ci->clientnum);
+
+ switch (EOS_EResult e = EOS_AntiCheatServer_RegisterClient(acs, ®isteropts))
+ {
+ case EOS_EResult::EOS_Success: return true;
+ case EOS_EResult::EOS_InvalidParameters: conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr registering client: input data invalid"); return false;
+ default: conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr EOS_AntiCheatServer_RegisterClient() failed with result code %d", (int) e); return false;
+ }
+ }
+
+ void receiveanticheatmessage(clientinfo *ci, ucharbuf &p)
+ {
+ static EOS_AntiCheatServer_ReceiveMessageFromClientOptions messageopts;
+ messageopts.ApiVersion = EOS_ANTICHEATSERVER_RECEIVEMESSAGEFROMCLIENT_API_LATEST;
+ messageopts.ClientHandle = (EOS_AntiCheatCommon_ClientHandle) ci;
+ messageopts.DataLengthBytes = p.remaining();
+ messageopts.Data = p.getbuf();
+ if(!anticheatinitialized || !acs) { conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr received N_P1X_ANTICHEAT_MESSAGE but anti-cheat not initialized"); return; }
+ switch (EOS_EResult e = EOS_AntiCheatServer_ReceiveMessageFromClient(acs, &messageopts))
+ {
+ case EOS_EResult::EOS_Success: break;
+ case EOS_EResult::EOS_InvalidParameters: conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr receiving message from client: input data invalid!"); return;
+ default: conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr EOS_AntiCheatServer_ReceiveMessageFromClient() failed with result code %d", (int) e); return;
+ }
+ }
+
+ void handleviolation(clientinfo *ci, int code, const char *details)
+ {
+ defformatstring(msg, "\fs\f3%s self-reported a violation: %s (code: %d)\fr", colorname(ci), details, code);
+ conoutf(CON_WARN, "%s", msg);
+ notifyprivclients(PRIV_AUTH, msg);
+ }
+
+ bool unregisteranticheatclient(clientinfo *ci)
+ {
+ static EOS_AntiCheatServer_UnregisterClientOptions unregisteropts;
+ unregisteropts.ApiVersion = EOS_ANTICHEATSERVER_UNREGISTERCLIENT_API_LATEST;
+ unregisteropts.ClientHandle = (EOS_AntiCheatCommon_ClientHandle) ci;
+
+ switch (EOS_EResult e = EOS_AntiCheatServer_UnregisterClient(acs, &unregisteropts))
+ {
+ case EOS_EResult::EOS_Success: sendf(ci->clientnum, 1, "ri", N_P1X_ANTICHEAT_ENDSESSION); return true;
+ case EOS_EResult::EOS_InvalidParameters: conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr unregistering client: input data invalid"); return false;
+ default: conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr EOS_AntiCheatServer_UnregisterClient() failed with result code %d", (int) e); return false;
+ }
+ }
+
+ EOS_NotificationId anticheatmessagetoclientcallback;
+ EOS_NotificationId anticheatclientactionrequiredcallback;
+ EOS_NotificationId anticheatclientauthstatuschangedcallback;
+
+ void startanticheatsession()
+ {
+ if(!acs) { conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr not initialized"); return; }
+ static EOS_AntiCheatServer_BeginSessionOptions sessionopts;
+ sessionopts.ApiVersion = EOS_ANTICHEATSERVER_BEGINSESSION_API_LATEST;
+ sessionopts.RegisterTimeoutSeconds = 60;
+ string servername;
+ filtertext(servername, serverdesc);
+ sessionopts.ServerName = servername;
+ sessionopts.bEnableGameplayData = EOS_FALSE;
+ sessionopts.LocalUserId = NULL;
+ switch (EOS_EResult e = EOS_AntiCheatServer_BeginSession(acs, &sessionopts))
+ {
+ case EOS_EResult::EOS_Success: break;
+ case EOS_EResult::EOS_InvalidParameters: conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr starting session: input data invalid"); break;
+ default: conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr EOS_AntiCheatServer_BeginSession() failed with result code %d", (int) e); break;
+ }
+ }
+
+ void initializeanticheat()
+ {
+ if(anticheatinitialized || (!eossdkinitialized && initializesdk(true))) return;
+
+ acs = EOS_Platform_GetAntiCheatServerInterface(platform);
+
+ // register s2c function for EOS messages
+ static EOS_AntiCheatServer_AddNotifyMessageToClientOptions messagecallbackopts;
+ messagecallbackopts.ApiVersion = EOS_ANTICHEATSERVER_ADDNOTIFYMESSAGETOCLIENT_API_LATEST;
+ anticheatmessagetoclientcallback = EOS_AntiCheatServer_AddNotifyMessageToClient(acs, &messagecallbackopts, NULL, onmessagetoclient);
+ if(anticheatmessagetoclientcallback==EOS_INVALID_NOTIFICATIONID) conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr init: failed to register onmessagetoclient callback");
+
+ // register callback for required actions
+ static EOS_AntiCheatServer_AddNotifyClientActionRequiredOptions actionrequiredopts;
+ actionrequiredopts.ApiVersion = EOS_ANTICHEATSERVER_ADDNOTIFYCLIENTACTIONREQUIRED_API_LATEST;
+ anticheatclientactionrequiredcallback = EOS_AntiCheatServer_AddNotifyClientActionRequired(acs, &actionrequiredopts, NULL, onclientactionrequired);
+ if(anticheatclientactionrequiredcallback==EOS_INVALID_NOTIFICATIONID) conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr init: failed to register onclientactionrequired callback");
+
+ // register callback for user auth status change
+ static EOS_AntiCheatServer_AddNotifyClientAuthStatusChangedOptions authchangedopts;
+ authchangedopts.ApiVersion = EOS_ANTICHEATSERVER_ADDNOTIFYCLIENTAUTHSTATUSCHANGED_API_LATEST;
+ anticheatclientauthstatuschangedcallback = EOS_AntiCheatServer_AddNotifyClientAuthStatusChanged(acs, &authchangedopts, NULL, onclientauthstatuschanged);
+ if(anticheatclientauthstatuschangedcallback==EOS_INVALID_NOTIFICATIONID) conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr init: failed to register onclientauthstatuschanged callback");
+
+ anticheatinitialized = true;
+ startanticheatsession();
+ }
+
+ bool endanticheatsession()
+ {
+ if(!acs) return true;
+
+ static EOS_AntiCheatServer_EndSessionOptions sessionopts;
+ sessionopts.ApiVersion = EOS_ANTICHEATSERVER_ENDSESSION_API_LATEST;
+ switch (EOS_EResult e = EOS_AntiCheatServer_EndSession(acs, &sessionopts))
+ {
+ case EOS_EResult::EOS_Success: return true;
+ case EOS_EResult::EOS_InvalidParameters: conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr ending session: input data invalid"); return false;
+ default: conoutf(CON_ERROR, "\fs\f8[anti-cheat]\fr EOS_AntiCheatServer_EndSession() failed with result code %d", (int) e); return false;
+ }
+ }
+
+ void shutdownanticheat()
+ {
+ if(!anticheatinitialized) return;
+ endanticheatsession();
+ if(acs)
+ {
+ // unregister callbacks
+ if(anticheatmessagetoclientcallback!=EOS_INVALID_NOTIFICATIONID) EOS_AntiCheatServer_RemoveNotifyMessageToClient(acs, anticheatmessagetoclientcallback);
+ if(anticheatclientactionrequiredcallback!=EOS_INVALID_NOTIFICATIONID) EOS_AntiCheatServer_RemoveNotifyClientActionRequired(acs, anticheatclientactionrequiredcallback);
+ if(anticheatclientauthstatuschangedcallback!=EOS_INVALID_NOTIFICATIONID) EOS_AntiCheatServer_RemoveNotifyClientAuthStatusChanged(acs, anticheatclientauthstatuschangedcallback);
+ }
+ if(eossdkinitialized) shutdownsdk();
+ }
+}
+
+#endif
diff --git src/engine/engine.h src/engine/engine.h
index 01361ed..3f32930 100644
--- src/engine/engine.h
+++ src/engine/engine.h
@@ -4,6 +4,11 @@
#include "cube.h"
#include "world.h"
+#ifdef ANTICHEAT
+// anticheat
+extern void anticheattick();
+#endif
+
#ifndef STANDALONE
#include "octa.h"
diff --git src/engine/main.cpp src/engine/main.cpp
index 53ef550..57654d4 100644
--- src/engine/main.cpp
+++ src/engine/main.cpp
@@ -10,6 +10,9 @@ extern void cleargamma();
void cleanup()
{
+#ifdef ANTICHEAT
+ game::shutdownanticheat();
+#endif
recorder::stop();
cleanupserver();
SDL_ShowCursor(SDL_TRUE);
@@ -1249,6 +1252,9 @@ int main(int argc, char **argv)
break;
}
case 'x': initscript = &argv[i][2]; break;
+#ifdef ANTICHEAT
+ case 'e': anticheatenabled = 1; break;
+#endif
default: if(!serveroption(argv[i])) gameargs.add(argv[i]); break;
}
else gameargs.add(argv[i]);
@@ -1354,6 +1360,14 @@ int main(int argc, char **argv)
migratep1xbraten();
+#ifdef ANTICHEAT
+ if(anticheatenabled)
+ {
+ logoutf("init: anti-cheat");
+ game::initializeanticheat();
+ }
+#endif
+
logoutf("init: mainloop");
if(execfile("once.cfg", false)) remove(findfile("once.cfg", "rb"));
diff --git src/engine/movie.cpp src/engine/movie.cpp
index 25cb491..70c0e2f 100644
--- src/engine/movie.cpp
+++ src/engine/movie.cpp
@@ -8,7 +8,11 @@
// kino - ok
#include "engine.h"
+#ifdef __APPLE__
+ #include <SDL2_mixer/SDL_mixer.h>
+#else
#include "SDL_mixer.h"
+#endif
VAR(dbgmovie, 0, 0, 1);
diff --git src/engine/server.cpp src/engine/server.cpp
index 9aa7a3b..1558215 100644
--- src/engine/server.cpp
+++ src/engine/server.cpp
@@ -170,6 +170,9 @@ void delclient(client *c)
void cleanupserver()
{
+#ifdef ANTICHEAT
+ server::shutdownanticheat();
+#endif
if(serverhost) enet_host_destroy(serverhost);
serverhost = NULL;
@@ -490,6 +493,10 @@ void updatetime()
void serverslice(bool dedicated, uint timeout) // main server update, called from main loop in sp, or from below in dedicated server
{
+#ifdef ANTICHEAT
+ anticheattick();
+#endif
+
if(!serverhost)
{
server::serverupdate();
@@ -959,6 +966,10 @@ bool setuplistenserver(bool dedicated)
return true;
}
+#ifdef ANTICHEAT
+MOD(VAR, anticheatenabled, 1, 0, 0);
+#endif
+
void initserver(bool listen, bool dedicated)
{
if(dedicated)
@@ -976,6 +987,9 @@ void initserver(bool listen, bool dedicated)
if(listen)
{
+#ifdef ANTICHEAT
+ if(anticheatenabled) server::initializeanticheat();
+#endif
dedicatedserver = dedicated;
updatemasterserver();
if(dedicated) rundedicatedserver(); // never returns
@@ -1027,6 +1041,9 @@ bool serveroption(char *opt)
case 'q': logoutf("Using home directory: %s", opt); sethomedir(opt+2); return true;
case 'k': logoutf("Adding package directory: %s", opt); addpackagedir(opt+2); return true;
case 'g': logoutf("Setting log file: %s", opt); setlogfile(opt+2); return true;
+#ifdef ANTICHEAT
+ case 'e': anticheatenabled = 1; return true;
+#endif
#endif
default: return false;
}
diff --git src/engine/sound.cpp src/engine/sound.cpp
index 38ff025..66006a2 100644
--- src/engine/sound.cpp
+++ src/engine/sound.cpp
@@ -1,7 +1,11 @@
// sound.cpp: basic positional sound using sdl_mixer
#include "engine.h"
+#ifdef __APPLE__
+ #include <SDL2_mixer/SDL_mixer.h>
+#else
#include "SDL_mixer.h"
+#endif
bool nosound = true;
diff --git src/engine/texture.cpp src/engine/texture.cpp
index fb662b5..62e90ec 100644
--- src/engine/texture.cpp
+++ src/engine/texture.cpp
@@ -1,8 +1,11 @@
// texture.cpp: texture slot management
#include "engine.h"
+#ifdef __APPLE__
+ #include <SDL2_image/SDL_image.h>
+#else
#include "SDL_image.h"
-
+#endif
#ifndef SDL_IMAGE_VERSION_ATLEAST
#define SDL_IMAGE_VERSION_ATLEAST(X, Y, Z) \
(SDL_VERSIONNUM(SDL_IMAGE_MAJOR_VERSION, SDL_IMAGE_MINOR_VERSION, SDL_IMAGE_PATCHLEVEL) >= SDL_VERSIONNUM(X, Y, Z))
diff --git src/fpsgame/client.cpp src/fpsgame/client.cpp
index c5ae27e..6b87170 100644
--- src/fpsgame/client.cpp
+++ src/fpsgame/client.cpp
@@ -972,6 +972,10 @@ namespace game
void gamedisconnect(bool cleanup)
{
+#ifdef ANTICHEAT
+ endanticheatsession();
+ player1->anticheatverified = false;
+#endif
if(remote) stopfollowing();
ignores.setsize(0);
connected = remote = false;
@@ -2091,7 +2095,32 @@ namespace game
}
else enddemorecord(true);
break;
+#ifdef ANTICHEAT
+ case N_P1X_ANTICHEAT_BEGINSESSION:
+ triggeranticheatsession();
+ break;
+ case N_P1X_ANTICHEAT_MESSAGE:
+ {
+ int len = getuint(p);
+ ucharbuf q = p.subbuf(len);
+ receiveanticheatmessage(q);
+ break;
+ }
+
+ case N_P1X_ANTICHEAT_ENDSESSION:
+ endanticheatsession();
+ break;
+
+ case N_P1X_ANTICHEAT_VERIFIED:
+ {
+ int vn = getint(p), val = getint(p);
+ fpsent *v = getclient(vn);
+ if(!v) return;
+ v->anticheatverified = val>0;
+ break;
+ }
+#endif
default:
neterr("type", cn < 0);
return;
diff --git src/fpsgame/game.h src/fpsgame/game.h
index 0a4c901..4e9fe3a 100644
--- src/fpsgame/game.h
+++ src/fpsgame/game.h
@@ -215,6 +215,7 @@ enum
// protocol extensions
static const char * const CAP_PROBE_CLIENT_DEMO_UPLOAD = "capability_probe_protocol_extension_p1x_client_demo_upload_v2";
+static const char * const CAP_PROBE_ANTICHEAT = "capability_probe_protocol_extension_p1x_anticheat_v3";
// network messages codes, c2s, c2c, s2c
@@ -248,6 +248,9 @@ enum
N_P1X_SETIP = 900, // only from proxy to server (see addtrustedproxyip cmd)
// N_P1X_CLIENT_DEMO_UPLOAD_SUPPORTED = 1000, N_P1X_RECORDDEMO, // legacy
N_P1X_CLIENT_DEMO_UPLOAD_SUPPORTED = 1002, N_P1X_RECORDDEMO, // guarded by CAP_PROBE_CLIENT_DEMO_UPLOAD
+#ifdef ANTICHEAT
+ N_P1X_ANTICHEAT_SUPPORTED = 2000, N_P1X_ANTICHEAT_BEGINSESSION, N_P1X_ANTICHEAT_MESSAGE, N_P1X_ANTICHEAT_VIOLATION, N_P1X_ANTICHEAT_ENDSESSION, N_P1X_ANTICHEAT_VERIFIED, // guarded by CAP_PROBE_ANTICHEAT
+#endif
NUMMSG
};
@@ -279,6 +283,9 @@ static const int msgsizes[] = // size inclusive message token, 0 f
N_DEMOPACKET, 0,
N_P1X_SETIP, 2,
N_P1X_CLIENT_DEMO_UPLOAD_SUPPORTED, 1, N_P1X_RECORDDEMO, 1,
+#ifdef ANTICHEAT
+ N_P1X_ANTICHEAT_SUPPORTED, 1, N_P1X_ANTICHEAT_BEGINSESSION, 0, N_P1X_ANTICHEAT_MESSAGE, 0, N_P1X_ANTICHEAT_VIOLATION, 0, N_P1X_ANTICHEAT_ENDSESSION, 1, N_P1X_ANTICHEAT_VERIFIED, 3,
+#endif
-1
};
@@ -578,10 +578,11 @@ struct fpsent : dynent, fpsstate
ai::aiinfo *ai;
int ownernum, lastnode;
semver p1xbratenversion;
+ bool anticheatverified;
vec muzzle;
- fpsent() : weight(100), clientnum(-1), privilege(PRIV_NONE), lastupdate(0), plag(0), ping(0), lifesequence(0), respawned(-1), suicided(-1), lastpain(0), attacksound(-1), attackchan(-1), idlesound(-1), idlechan(-1), frags(0), flags(0), deaths(0), totaldamage(0), totalshots(0), suicides(0), edit(NULL), smoothmillis(-1), playermodel(-1), ai(NULL), ownernum(-1), p1xbratenversion(0, 0, 0), muzzle(-1, -1, -1)
+ fpsent() : weight(100), clientnum(-1), privilege(PRIV_NONE), lastupdate(0), plag(0), ping(0), lifesequence(0), respawned(-1), suicided(-1), lastpain(0), attacksound(-1), attackchan(-1), idlesound(-1), idlechan(-1), frags(0), flags(0), deaths(0), totaldamage(0), totalshots(0), suicides(0), edit(NULL), smoothmillis(-1), playermodel(-1), ai(NULL), ownernum(-1), p1xbratenversion(0, 0, 0), anticheatverified(false), muzzle(-1, -1, -1)
{
name[0] = team[0] = info[0] = alphanumname[0] = 0;
respawn();
@@ -886,6 +894,14 @@ namespace game
// managed games
extern void handlecapprobe(const char *msg);
extern void sendclientdemo(stream *demo);
+
+#ifdef ANTICHEAT
+ // anticheat
+ extern bool anticheatready();
+ extern void triggeranticheatsession();
+ extern void receiveanticheatmessage(ucharbuf &p);
+ extern bool endanticheatsession();
+#endif
}
#include "fragmessages.h"
@@ -1068,6 +1084,8 @@ namespace server
int authkickvictim;
char *authkickreason;
bool supportsclientdemoupload;
+ bool supportsanticheat;
+ int anticheatverified; // 0 = no anti-cheat, 1 = locally verified, 2 = verified by Epic's backend
clientinfo() : getdemo(NULL), getmap(NULL), clipboard(NULL), authchallenge(NULL), authkickreason(NULL) { reset(); }
~clientinfo() { events.deletecontents(); cleanclipboard(); cleanauth(); }
@@ -1178,6 +1196,8 @@ namespace server
cleanauth();
mapchange();
supportsclientdemoupload = false;
+ supportsanticheat = false;
+ anticheatverified = 0;
}
int geteventmillis(int servmillis, int clientmillis)
@@ -1193,6 +1213,7 @@ namespace server
};
extern vector<clientinfo *> clients;
+ extern char *serverdesc;
extern const char *modename(int n, const char *unknown = "unknown");
extern int mastermode;
extern const char *mastermodename(int n, const char *unknown = "unknown");
@@ -1243,6 +1264,20 @@ namespace server
// proxy support
extern void setip(clientinfo *sender, uint ip);
+
+#ifdef ANTICHEAT
+ // anticheat
+ extern int forceanticheatclient;
+ extern void probeforanticheatclient(packetbuf &p);
+ extern bool registeranticheatclient(clientinfo *ci, const char *useridstring);
+ extern void receiveanticheatmessage(clientinfo *c, ucharbuf &p);
+ extern void handleviolation(clientinfo *ci, int code, const char *details);
+ extern bool unregisteranticheatclient(clientinfo *c);
+ extern bool shouldspectate(clientinfo *ci, clientinfo *requester = NULL);
+ extern void forcespectator(clientinfo *ci);
+ extern void unspectate(clientinfo *ci, clientinfo *requester = NULL);
+ extern void notifyprivclients(int minpriv, char *msg);
+#endif
}
// additional colors
diff --git src/fpsgame/server.cpp src/fpsgame/server.cpp
index e37eb57..76d231f 100644
--- src/fpsgame/server.cpp
+++ src/fpsgame/server.cpp
@@ -1305,7 +1305,11 @@ namespace server
}
uchar operator[](int msg) const { return msg >= 0 && msg < NUMMSG ? msgmask[msg] : 0; }
- } msgfilter(-1, N_CONNECT, N_SERVINFO, N_INITCLIENT, N_WELCOME, N_MAPCHANGE, N_SERVMSG, N_DAMAGE, N_HITPUSH, N_SHOTFX, N_EXPLODEFX, N_DIED, N_SPAWNSTATE, N_FORCEDEATH, N_TEAMINFO, N_ITEMACC, N_ITEMSPAWN, N_TIMEUP, N_CDIS, N_CURRENTMASTER, N_PONG, N_RESUME, N_BASESCORE, N_BASEINFO, N_BASEREGEN, N_ANNOUNCE, N_SENDDEMOLIST, N_SENDDEMO, N_DEMOPLAYBACK, N_SENDMAP, N_DROPFLAG, N_SCOREFLAG, N_RETURNFLAG, N_RESETFLAG, N_INVISFLAG, N_CLIENT, N_AUTHCHAL, N_INITAI, N_EXPIRETOKENS, N_DROPTOKENS, N_STEALTOKENS, N_DEMOPACKET, N_P1X_RECORDDEMO, -2, N_REMIP, N_NEWMAP, N_GETMAP, N_SENDMAP, N_CLIPBOARD, -3, N_EDITENT, N_EDITF, N_EDITT, N_EDITM, N_FLIP, N_COPY, N_PASTE, N_ROTATE, N_REPLACE, N_DELCUBE, N_EDITVAR, N_EDITVSLOT, N_UNDO, N_REDO, -4, N_POS, NUMMSG),
+ } msgfilter(-1, N_CONNECT, N_SERVINFO, N_INITCLIENT, N_WELCOME, N_MAPCHANGE, N_SERVMSG, N_DAMAGE, N_HITPUSH, N_SHOTFX, N_EXPLODEFX, N_DIED, N_SPAWNSTATE, N_FORCEDEATH, N_TEAMINFO, N_ITEMACC, N_ITEMSPAWN, N_TIMEUP, N_CDIS, N_CURRENTMASTER, N_PONG, N_RESUME, N_BASESCORE, N_BASEINFO, N_BASEREGEN, N_ANNOUNCE, N_SENDDEMOLIST, N_SENDDEMO, N_DEMOPLAYBACK, N_SENDMAP, N_DROPFLAG, N_SCOREFLAG, N_RETURNFLAG, N_RESETFLAG, N_INVISFLAG, N_CLIENT, N_AUTHCHAL, N_INITAI, N_EXPIRETOKENS, N_DROPTOKENS, N_STEALTOKENS, N_DEMOPACKET, N_P1X_RECORDDEMO, -2, N_REMIP, N_NEWMAP, N_GETMAP, N_SENDMAP, N_CLIPBOARD, -3, N_EDITENT, N_EDITF, N_EDITT, N_EDITM, N_FLIP, N_COPY, N_PASTE, N_ROTATE, N_REPLACE, N_DELCUBE, N_EDITVAR, N_EDITVSLOT, N_UNDO, N_REDO, -4, N_POS,
+#ifdef ANTICHEAT
+ -1, N_P1X_ANTICHEAT_VERIFIED, N_P1X_ANTICHEAT_ENDSESSION,
+#endif
+ NUMMSG),
connectfilter(-1, N_CONNECT, -2, N_AUTHANS, -3, N_PING, N_P1X_SETIP, NUMMSG);
int checktype(int type, clientinfo *ci)
@@ -1537,6 +1541,9 @@ namespace server
packetbuf p(MAXTRANS, ENET_PACKET_FLAG_RELIABLE);
int chan = welcomepacket(p, ci);
if(!ci->local) probeforclientdemoupload(p);
+#ifdef ANTICHEAT
+ if(!ci->local && anticheatenabled) probeforanticheatclient(p);
+#endif
sendpacket(ci->clientnum, chan, p.finalize());
}
@@ -2338,14 +2345,35 @@ namespace server
}
}
- bool shouldspectate(clientinfo *ci)
+ bool shouldspectate(clientinfo *ci, clientinfo *requester)
+ {
+ if(ci->local) return false;
+ if(ci->warned && modifiedmapspectator && (mcrc || modifiedmapspectator > 1))
+ {
+ if(requester)
+ {