forked from AdKats/AdKats-LRT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdKatsLRT.cs
5064 lines (4770 loc) · 312 KB
/
AdKatsLRT.cs
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
/*
* AdKatsLRT - On-Spawn Loadout Enforcer
*
* AdKats and respective extensions are inspired by the gaming community A Different Kind (ADK).
* Visit http://www.ADKGamers.com/ for more information.
*
* The AdKats Frostbite Plugin is open source, and under public domain, but certain extensions are not.
* The AdKatsLRT extension is not open for free distribution, copyright Daniel J. Gradinjan, with all rights reserved.
*
* Development by Daniel J. Gradinjan (ColColonCleaner)
*
* AdKatsLRT.cs
* Version 2.0.9.0
* 25-MAR-2018
*
* Automatic Update Information
* <version_code>2.0.9.0</version_code>
*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Threading;
using PRoCon.Core;
using PRoCon.Core.Players;
using PRoCon.Core.Plugin;
namespace PRoConEvents {
public class AdKatsLRT : PRoConPluginAPI, IPRoConPluginInterface {
//Current Plugin Version
private const String PluginVersion = "2.0.9.1";
public readonly Logger Log;
public enum GameVersion {
BF3,
BF4,
BFHL
};
//Constants
private const String SettingsInstancePrefix = "0. Instance Settings|";
private const String SettingsDisplayPrefix = "1. Display Settings|";
private const String SettingsPresetPrefix = "2. Preset Settings|";
private const String SettingsMapModePrefix = "3. Map/Mode Settings";
private const String SettingsWeaponPrefix = "4. Weapons - ";
private const String SettingsAccessoryPrefix = "5. Weapon Accessories - ";
private const String SettingsGadgetPrefix = "6. Gadgets - ";
private const String SettingsVehiclePrefix = "7. Vehicle Weapons/Unlocks";
private const String SettingsDeniedItemMessagePrefix = "8A. Denied Item Kill Messages|";
private const String SettingsDeniedItemAccMessagePrefix = "8B. Denied Item Accessory Kill Messages|";
private const String SettingsDeniedVehicleItemMessagePrefix = "8C. Denied Vehicle Item Kill Messages|";
//State
private GameVersion _gameVersion = GameVersion.BF3;
private volatile Boolean _pluginEnabled;
private DateTime _pluginStartTime = DateTime.UtcNow;
private WarsawLibrary _warsawLibrary = new WarsawLibrary();
private Boolean _warsawLibraryLoaded;
private readonly HashSet<String> _adminList = new HashSet<string>();
private readonly Dictionary<String, AdKatsSubscribedPlayer> _playerDictionary = new Dictionary<String, AdKatsSubscribedPlayer>();
private Boolean _firstPlayerListComplete;
private Boolean _isTestingAuthorized;
private readonly Dictionary<String, AdKatsSubscribedPlayer> _playerLeftDictionary = new Dictionary<String, AdKatsSubscribedPlayer>();
private readonly Queue<ProcessObject> _loadoutProcessingQueue = new Queue<ProcessObject>();
private readonly Queue<AdKatsSubscribedPlayer> _battlelogFetchQueue = new Queue<AdKatsSubscribedPlayer>();
private readonly Dictionary<String, String> _warsawInvalidLoadoutIDMessages = new Dictionary<String, String>();
private readonly Dictionary<String, String> _warsawInvalidVehicleLoadoutIDMessages = new Dictionary<String, String>();
private readonly HashSet<String> _warsawSpawnDeniedIDs = new HashSet<String>();
private Int32 _countKilled;
private Int32 _countFixed;
private Int32 _countQuit;
private readonly AdKatsServer _serverInfo;
private Boolean _displayLoadoutDebug;
//Settings
private Boolean _highRequestVolume;
private Boolean _useProxy = false;
private String _proxyURL = "";
private Boolean _enableAdKatsIntegration;
private Boolean _spawnEnforcementOnly;
private Boolean _spawnEnforcementActOnAdmins;
private Boolean _spawnEnforcementActOnReputablePlayers;
private Boolean _displayWeaponPopularity;
private Int32 _weaponPopularityDisplayMinutes = 6;
private Boolean _useWeaponCatchingBackup = true;
private Int32 _triggerEnforcementMinimumInfractionPoints = 6;
private Boolean _spawnEnforceAllVehicles;
private String[] _Whitelist = { };
private String[] _ItemFilter = { };
//Display
private Boolean _displayMapsModes;
private Boolean _displayWeapons;
private Boolean _displayWeaponAccessories;
private Boolean _displayGadgets;
private Boolean _displayVehicles;
//Maps Modes
private Boolean _restrictSpecificMapModes;
private List<MapMode> _availableMapModes = new List<MapMode>();
private readonly Dictionary<String, MapMode> _restrictedMapModes = new Dictionary<String, MapMode>();
//Timing
private readonly DateTime _proconStartTime = DateTime.UtcNow - TimeSpan.FromSeconds(5);
private readonly TimeSpan _battlelogWaitDuration = TimeSpan.FromSeconds(3);
private DateTime _startTime = DateTime.UtcNow - TimeSpan.FromSeconds(5);
private DateTime _lastVersionTrackingUpdate = DateTime.UtcNow - TimeSpan.FromHours(1);
private Object _battlelogLocker = new Object();
private DateTime _lastBattlelogAction = DateTime.UtcNow - TimeSpan.FromSeconds(5);
private DateTime _lastBattlelogFrequencyMessage = DateTime.UtcNow - TimeSpan.FromSeconds(5);
private Queue<DateTime> _BattlelogActionTimes = new Queue<DateTime>();
private DateTime _lastCategoryListing = DateTime.UtcNow;
//Threads
private readonly Dictionary<Int32, Thread> _aliveThreads = new Dictionary<Int32, Thread>();
private volatile Boolean _threadsReady;
private EventWaitHandle _threadMasterWaitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
private EventWaitHandle _loadoutProcessingWaitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
private EventWaitHandle _playerProcessingWaitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
private EventWaitHandle _battlelogCommWaitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
private Thread _activator;
private Thread _finalizer;
private Thread _spawnProcessingThread;
private Thread _battlelogCommThread;
//AutoAdmin
private Boolean _UseBackupAutoadmin;
private Boolean _UseAdKatsPunishments;
private Dictionary<String, List<String>> _WarsawRCONMappings = new Dictionary<String, List<String>>();
private Dictionary<String, List<String>> _RCONWarsawMappings = new Dictionary<String, List<String>>();
//Settings
private const Int32 YellDuration = 7;
//Debug
private Boolean _slowmo;
public AdKatsLRT() {
Log = new Logger(this);
//Create the server reference
_serverInfo = new AdKatsServer(this);
//Populate maps/modes
PopulateMapModes();
//Populate AutoAdmin Weapon Mappings
PopulateWarsawRCONCodes();
//Set defaults for webclient
ServicePointManager.Expect100Continue = false;
//By default plugin is not enabled or ready
_pluginEnabled = false;
_threadsReady = false;
//Debug level is 0 by default
Log.DebugLevel = 0;
//Prepare the status monitor
SetupStatusMonitor();
}
public String GetPluginName() {
return "AdKatsLRT - Loadout Enforcer";
}
public String GetPluginVersion() {
return PluginVersion;
}
public String GetPluginAuthor() {
return "[ADK]ColColonCleaner";
}
public String GetPluginWebsite() {
return "https://github.com/AdKats/";
}
public String GetPluginDescription() {
return "";
}
public List<CPluginVariable> GetDisplayPluginVariables() {
var lstReturn = new List<CPluginVariable>();
try {
const string separator = " | ";
lstReturn.Add(new CPluginVariable(SettingsInstancePrefix + "Enable High Request Volume", typeof(Boolean), _highRequestVolume));
lstReturn.Add(new CPluginVariable(SettingsInstancePrefix + "Use Proxy for Battlelog", typeof(Boolean), _useProxy));
if (_useProxy) {
lstReturn.Add(new CPluginVariable(SettingsInstancePrefix + "Proxy URL", typeof(String), _proxyURL));
}
lstReturn.Add(new CPluginVariable(SettingsInstancePrefix + "Integrate with AdKats", typeof(Boolean), _enableAdKatsIntegration));
if (_enableAdKatsIntegration) {
lstReturn.Add(new CPluginVariable(SettingsInstancePrefix + "Spawn Enforcement Only", typeof(Boolean), _spawnEnforcementOnly));
lstReturn.Add(new CPluginVariable(SettingsInstancePrefix + "Spawn Enforce Admins", typeof(Boolean), _spawnEnforcementActOnAdmins));
lstReturn.Add(new CPluginVariable(SettingsInstancePrefix + "Spawn Enforce Reputable Players", typeof(Boolean), _spawnEnforcementActOnReputablePlayers));
lstReturn.Add(new CPluginVariable(SettingsInstancePrefix + "Action Whitelist", typeof(String[]), _Whitelist));
lstReturn.Add(new CPluginVariable(SettingsInstancePrefix + "Trigger Enforce Minimum Infraction Points", typeof(Int32), _triggerEnforcementMinimumInfractionPoints));
}
lstReturn.Add(new CPluginVariable(SettingsInstancePrefix + "Display Weapon Popularity Periodically", typeof(Boolean), _displayWeaponPopularity));
if (_displayWeaponPopularity) {
lstReturn.Add(new CPluginVariable(SettingsInstancePrefix + "Weapon Popularity Display Frequency Minutes", typeof(Int32), _weaponPopularityDisplayMinutes));
}
lstReturn.Add(new CPluginVariable(SettingsInstancePrefix + "Use Backup AutoAdmin", typeof(Boolean), _UseBackupAutoadmin));
if (_enableAdKatsIntegration && _UseBackupAutoadmin) {
lstReturn.Add(new CPluginVariable(SettingsInstancePrefix + "Backup AutoAdmin Use AdKats Punishments", typeof(Boolean), _UseAdKatsPunishments));
}
lstReturn.Add(new CPluginVariable(SettingsInstancePrefix + "Global Item Filter", typeof(String[]), _ItemFilter));
if (!_warsawLibraryLoaded) {
lstReturn.Add(new CPluginVariable("The WARSAW library must be loaded to view settings.", typeof(String), "Enable the plugin to fetch the library."));
return lstReturn;
}
lstReturn.Add(new CPluginVariable(SettingsDisplayPrefix + "Display Map/Mode Settings", typeof(Boolean), _displayMapsModes));
lstReturn.Add(new CPluginVariable(SettingsDisplayPrefix + "Display Weapon Settings", typeof(Boolean), _displayWeapons));
lstReturn.Add(new CPluginVariable(SettingsDisplayPrefix + "Display Weapon Accessory Settings", typeof(Boolean), _displayWeaponAccessories));
lstReturn.Add(new CPluginVariable(SettingsDisplayPrefix + "Display Gadget Settings", typeof(Boolean), _displayGadgets));
lstReturn.Add(new CPluginVariable(SettingsDisplayPrefix + "Display Vehicle Settings", typeof(Boolean), _displayVehicles));
if (_displayMapsModes) {
lstReturn.Add(new CPluginVariable(SettingsMapModePrefix + separator.Trim() + "Enforce on Specific Maps/Modes Only", typeof(Boolean), _restrictSpecificMapModes));
if (_restrictSpecificMapModes) {
lstReturn.AddRange(_availableMapModes.OrderBy(mm => mm.ModeName).ThenBy(mm => mm.MapName).Select(mapMode => new CPluginVariable(SettingsMapModePrefix + " - " + mapMode.ModeName + separator.Trim() + "RMM" + mapMode.MapModeID.ToString(CultureInfo.InvariantCulture).PadLeft(3, '0') + separator + mapMode.MapName + separator + "Enforce?", "enum.EnforceMapEnum(Enforce|Ignore)", _restrictedMapModes.ContainsKey(mapMode.ModeKey + "|" + mapMode.MapKey) ? ("Enforce") : ("Ignore"))));
}
}
//Run removals
_warsawSpawnDeniedIDs.RemoveWhere(spawnID => !_warsawInvalidLoadoutIDMessages.ContainsKey(spawnID) && !_warsawInvalidVehicleLoadoutIDMessages.ContainsKey(spawnID));
if (_displayWeapons) {
if (_warsawLibrary.Items.Any()) {
foreach (WarsawItem weapon in _warsawLibrary.Items.Values.Where(weapon => weapon.CategoryReadable != "GADGET").OrderBy(weapon => weapon.CategoryReadable).ThenBy(weapon => weapon.Slug)) {
if (_ItemFilter.Any() && !_ItemFilter.Any(item => weapon.Slug.ToLower().Contains(item.ToLower()))) {
continue;
}
if (_enableAdKatsIntegration && !_spawnEnforcementOnly) {
lstReturn.Add(new CPluginVariable(SettingsWeaponPrefix + weapon.CategoryTypeReadable + "|ALWT" + weapon.WarsawID + separator + weapon.Slug + separator + "Allow on trigger?", "enum.AllowItemEnum(Allow|Deny)", _warsawInvalidLoadoutIDMessages.ContainsKey(weapon.WarsawID) ? ("Deny") : ("Allow")));
if (_warsawInvalidLoadoutIDMessages.ContainsKey(weapon.WarsawID)) {
lstReturn.Add(new CPluginVariable(SettingsWeaponPrefix + weapon.CategoryTypeReadable + "|ALWS" + weapon.WarsawID + separator + weapon.Slug + separator + "Allow on spawn?", "enum.AllowItemEnum(Allow|Deny)", _warsawSpawnDeniedIDs.Contains(weapon.WarsawID) ? ("Deny") : ("Allow")));
}
} else {
lstReturn.Add(new CPluginVariable(SettingsWeaponPrefix + weapon.CategoryTypeReadable + "|ALWT" + weapon.WarsawID + separator + weapon.Slug + separator + "Allow on spawn?", "enum.AllowItemEnum(Allow|Deny)", _warsawSpawnDeniedIDs.Contains(weapon.WarsawID) ? ("Deny") : ("Allow")));
}
}
}
}
if (_displayWeaponAccessories) {
if (_warsawLibrary.ItemAccessories.Any()) {
foreach (WarsawItemAccessory weaponAccessory in _warsawLibrary.ItemAccessories.Values.OrderBy(weaponAccessory => weaponAccessory.Slug).ThenBy(weaponAccessory => weaponAccessory.CategoryReadable)) {
if (_ItemFilter.Any() && !_ItemFilter.Any(item => weaponAccessory.Slug.ToLower().Contains(item.ToLower()))) {
continue;
}
if (_enableAdKatsIntegration && !_spawnEnforcementOnly) {
lstReturn.Add(new CPluginVariable(SettingsAccessoryPrefix + weaponAccessory.CategoryReadable + "|ALWT" + weaponAccessory.WarsawID + separator + weaponAccessory.Slug + separator + "Allow on trigger?", "enum.AllowItemEnum(Allow|Deny)", _warsawInvalidLoadoutIDMessages.ContainsKey(weaponAccessory.WarsawID) ? ("Deny") : ("Allow")));
if (_warsawInvalidLoadoutIDMessages.ContainsKey(weaponAccessory.WarsawID)) {
lstReturn.Add(new CPluginVariable(SettingsAccessoryPrefix + weaponAccessory.CategoryReadable + "|ALWS" + weaponAccessory.WarsawID + separator + weaponAccessory.Slug + separator + "Allow on spawn?", "enum.AllowItemEnum(Allow|Deny)", _warsawSpawnDeniedIDs.Contains(weaponAccessory.WarsawID) ? ("Deny") : ("Allow")));
}
} else {
lstReturn.Add(new CPluginVariable(SettingsAccessoryPrefix + weaponAccessory.CategoryReadable + "|ALWT" + weaponAccessory.WarsawID + separator + weaponAccessory.Slug + separator + "Allow on spawn?", "enum.AllowItemEnum(Allow|Deny)", _warsawSpawnDeniedIDs.Contains(weaponAccessory.WarsawID) ? ("Deny") : ("Allow")));
}
}
}
}
if (_displayGadgets) {
if (_warsawLibrary.Items.Any()) {
foreach (WarsawItem weapon in _warsawLibrary.Items.Values.Where(weapon => weapon.CategoryReadable == "GADGET").OrderBy(weapon => weapon.CategoryReadable).ThenBy(weapon => weapon.Slug)) {
if (String.IsNullOrEmpty(weapon.CategoryTypeReadable)) {
Log.Error(weapon.WarsawID + " did not have a category type.");
}
if (_ItemFilter.Any() && !_ItemFilter.Any(item => weapon.Slug.ToLower().Contains(item.ToLower()))) {
continue;
}
if (_enableAdKatsIntegration && !_spawnEnforcementOnly) {
lstReturn.Add(new CPluginVariable(SettingsGadgetPrefix + weapon.CategoryTypeReadable + "|ALWT" + weapon.WarsawID + separator + weapon.Slug + separator + "Allow on trigger?", "enum.AllowItemEnum(Allow|Deny)", _warsawInvalidLoadoutIDMessages.ContainsKey(weapon.WarsawID) ? ("Deny") : ("Allow")));
if (_warsawInvalidLoadoutIDMessages.ContainsKey(weapon.WarsawID)) {
lstReturn.Add(new CPluginVariable(SettingsGadgetPrefix + weapon.CategoryTypeReadable + "|ALWS" + weapon.WarsawID + separator + weapon.Slug + separator + "Allow on spawn?", "enum.AllowItemEnum(Allow|Deny)", _warsawSpawnDeniedIDs.Contains(weapon.WarsawID) ? ("Deny") : ("Allow")));
}
} else {
lstReturn.Add(new CPluginVariable(SettingsGadgetPrefix + weapon.CategoryTypeReadable + "|ALWT" + weapon.WarsawID + separator + weapon.Slug + separator + "Allow on spawn?", "enum.AllowItemEnum(Allow|Deny)", _warsawSpawnDeniedIDs.Contains(weapon.WarsawID) ? ("Deny") : ("Allow")));
}
}
}
}
if (_displayVehicles) {
lstReturn.Add(new CPluginVariable(SettingsVehiclePrefix + separator.Trim() + "Spawn Enforce all Vehicles", typeof(Boolean), _spawnEnforceAllVehicles));
if (_warsawLibrary.Vehicles.Any()) {
foreach (var vehicle in _warsawLibrary.Vehicles.Values.OrderBy(vec => vec.CategoryType)) {
String currentPrefix = SettingsVehiclePrefix + " - " + vehicle.CategoryType + "|";
lstReturn.AddRange(vehicle.AllowedPrimaries.Values.Where(unlock => !_ItemFilter.Any() || _ItemFilter.Any(item => unlock.Slug.ToLower().Contains(item.ToLower()))).Select(unlock => new CPluginVariable(currentPrefix + "ALWK" + unlock.WarsawID + separator + unlock.Slug + separator + "Allow on " + ((_spawnEnforceAllVehicles) ? ("spawn") : ("kill")) + "?", "enum.AllowItemEnum(Allow|Deny)", _warsawInvalidVehicleLoadoutIDMessages.ContainsKey(unlock.WarsawID) ? ("Deny") : ("Allow"))));
lstReturn.AddRange(vehicle.AllowedSecondaries.Values.Where(unlock => !_ItemFilter.Any() || _ItemFilter.Any(item => unlock.Slug.ToLower().Contains(item.ToLower()))).Select(unlock => new CPluginVariable(currentPrefix + "ALWK" + unlock.WarsawID + separator + unlock.Slug + separator + "Allow on " + ((_spawnEnforceAllVehicles) ? ("spawn") : ("kill")) + "?", "enum.AllowItemEnum(Allow|Deny)", _warsawInvalidVehicleLoadoutIDMessages.ContainsKey(unlock.WarsawID) ? ("Deny") : ("Allow"))));
lstReturn.AddRange(vehicle.AllowedCountermeasures.Values.Where(unlock => !_ItemFilter.Any() || _ItemFilter.Any(item => unlock.Slug.ToLower().Contains(item.ToLower()))).Select(unlock => new CPluginVariable(currentPrefix + "ALWK" + unlock.WarsawID + separator + unlock.Slug + separator + "Allow on " + ((_spawnEnforceAllVehicles) ? ("spawn") : ("kill")) + "?", "enum.AllowItemEnum(Allow|Deny)", _warsawInvalidVehicleLoadoutIDMessages.ContainsKey(unlock.WarsawID) ? ("Deny") : ("Allow"))));
lstReturn.AddRange(vehicle.AllowedOptics.Values.Where(unlock => !_ItemFilter.Any() || _ItemFilter.Any(item => unlock.Slug.ToLower().Contains(item.ToLower()))).Select(unlock => new CPluginVariable(currentPrefix + "ALWK" + unlock.WarsawID + separator + unlock.Slug + separator + "Allow on " + ((_spawnEnforceAllVehicles) ? ("spawn") : ("kill")) + "?", "enum.AllowItemEnum(Allow|Deny)", _warsawInvalidVehicleLoadoutIDMessages.ContainsKey(unlock.WarsawID) ? ("Deny") : ("Allow"))));
lstReturn.AddRange(vehicle.AllowedUpgrades.Values.Where(unlock => !_ItemFilter.Any() || _ItemFilter.Any(item => unlock.Slug.ToLower().Contains(item.ToLower()))).Select(unlock => new CPluginVariable(currentPrefix + "ALWK" + unlock.WarsawID + separator + unlock.Slug + separator + "Allow on " + ((_spawnEnforceAllVehicles) ? ("spawn") : ("kill")) + "?", "enum.AllowItemEnum(Allow|Deny)", _warsawInvalidVehicleLoadoutIDMessages.ContainsKey(unlock.WarsawID) ? ("Deny") : ("Allow"))));
lstReturn.AddRange(vehicle.AllowedSecondariesGunner.Values.Where(unlock => !_ItemFilter.Any() || _ItemFilter.Any(item => unlock.Slug.ToLower().Contains(item.ToLower()))).Select(unlock => new CPluginVariable(currentPrefix + "ALWK" + unlock.WarsawID + separator + unlock.Slug + separator + "Allow on " + ((_spawnEnforceAllVehicles) ? ("spawn") : ("kill")) + "?", "enum.AllowItemEnum(Allow|Deny)", _warsawInvalidVehicleLoadoutIDMessages.ContainsKey(unlock.WarsawID) ? ("Deny") : ("Allow"))));
lstReturn.AddRange(vehicle.AllowedOpticsGunner.Values.Where(unlock => !_ItemFilter.Any() || _ItemFilter.Any(item => unlock.Slug.ToLower().Contains(item.ToLower()))).Select(unlock => new CPluginVariable(currentPrefix + "ALWK" + unlock.WarsawID + separator + unlock.Slug + separator + "Allow on " + ((_spawnEnforceAllVehicles) ? ("spawn") : ("kill")) + "?", "enum.AllowItemEnum(Allow|Deny)", _warsawInvalidVehicleLoadoutIDMessages.ContainsKey(unlock.WarsawID) ? ("Deny") : ("Allow"))));
lstReturn.AddRange(vehicle.AllowedUpgradesGunner.Values.Where(unlock => !_ItemFilter.Any() || _ItemFilter.Any(item => unlock.Slug.ToLower().Contains(item.ToLower()))).Select(unlock => new CPluginVariable(currentPrefix + "ALWK" + unlock.WarsawID + separator + unlock.Slug + separator + "Allow on " + ((_spawnEnforceAllVehicles) ? ("spawn") : ("kill")) + "?", "enum.AllowItemEnum(Allow|Deny)", _warsawInvalidVehicleLoadoutIDMessages.ContainsKey(unlock.WarsawID) ? ("Deny") : ("Allow"))));
}
}
}
foreach (var pair in _warsawInvalidLoadoutIDMessages.Where(denied => _warsawLibrary.Items.ContainsKey(denied.Key))) {
WarsawItem deniedItem;
if (_warsawLibrary.Items.TryGetValue(pair.Key, out deniedItem)) {
lstReturn.Add(new CPluginVariable(SettingsDeniedItemMessagePrefix + "MSG" + deniedItem.WarsawID + separator + deniedItem.Slug + separator + "Kill Message", typeof(String), pair.Value));
}
}
foreach (var pair in _warsawInvalidLoadoutIDMessages.Where(denied => _warsawLibrary.ItemAccessories.ContainsKey(denied.Key))) {
WarsawItemAccessory deniedItemAccessory;
if (_warsawLibrary.ItemAccessories.TryGetValue(pair.Key, out deniedItemAccessory)) {
lstReturn.Add(new CPluginVariable(SettingsDeniedItemAccMessagePrefix + "MSG" + deniedItemAccessory.WarsawID + separator + deniedItemAccessory.Slug + separator + "Kill Message", typeof(String), pair.Value));
}
}
foreach (var pair in _warsawInvalidVehicleLoadoutIDMessages.Where(denied => _warsawLibrary.VehicleUnlocks.ContainsKey(denied.Key))) {
WarsawItem deniedVehicleUnlock;
if (_warsawLibrary.VehicleUnlocks.TryGetValue(pair.Key, out deniedVehicleUnlock)) {
lstReturn.Add(new CPluginVariable(SettingsDeniedVehicleItemMessagePrefix + "VMSG" + deniedVehicleUnlock.WarsawID + separator + deniedVehicleUnlock.Slug + separator + "Kill Message", typeof(String), pair.Value));
}
}
lstReturn.Add(new CPluginVariable("D99. Debugging|Debug level", typeof(int), Log.DebugLevel));
} catch (Exception e) {
Log.Exception("Error while getting display plugin variables", e);
}
return lstReturn;
}
public List<CPluginVariable> GetPluginVariables() {
var lstReturn = new List<CPluginVariable>();
const string separator = " | ";
lstReturn.Add(new CPluginVariable(SettingsInstancePrefix + "Enable High Request Volume", typeof(Boolean), _highRequestVolume));
lstReturn.Add(new CPluginVariable(SettingsInstancePrefix + "Use Proxy for Battlelog", typeof(Boolean), _useProxy));
lstReturn.Add(new CPluginVariable(SettingsInstancePrefix + "Proxy URL", typeof(String), _proxyURL));
lstReturn.Add(new CPluginVariable(SettingsInstancePrefix + "Integrate with AdKats", typeof(Boolean), _enableAdKatsIntegration));
lstReturn.Add(new CPluginVariable(SettingsInstancePrefix + "Use Backup AutoAdmin", typeof(Boolean), _UseBackupAutoadmin));
lstReturn.Add(new CPluginVariable(SettingsInstancePrefix + "Spawn Enforcement Only", typeof(Boolean), _spawnEnforcementOnly));
lstReturn.Add(new CPluginVariable(SettingsInstancePrefix + "Backup AutoAdmin Use AdKats Punishments", typeof(Boolean), _UseAdKatsPunishments));
lstReturn.Add(new CPluginVariable(SettingsInstancePrefix + "Spawn Enforce Admins", typeof(Boolean), _spawnEnforcementActOnAdmins));
lstReturn.Add(new CPluginVariable(SettingsInstancePrefix + "Spawn Enforce Reputable Players", typeof(Boolean), _spawnEnforcementActOnReputablePlayers));
lstReturn.Add(new CPluginVariable(SettingsInstancePrefix + "Display Weapon Popularity Periodically", typeof(Boolean), _displayWeaponPopularity));
lstReturn.Add(new CPluginVariable(SettingsInstancePrefix + "Action Whitelist", typeof(String[]), _Whitelist));
lstReturn.Add(new CPluginVariable(SettingsInstancePrefix + "Trigger Enforce Minimum Infraction Points", typeof(Int32), _triggerEnforcementMinimumInfractionPoints));
lstReturn.Add(new CPluginVariable(SettingsInstancePrefix + "Weapon Popularity Display Frequency Minutes", typeof(Int32), _weaponPopularityDisplayMinutes));
lstReturn.Add(new CPluginVariable(SettingsInstancePrefix + "Global Item Filter", typeof(String[]), _ItemFilter));
lstReturn.Add(new CPluginVariable(SettingsDisplayPrefix + "Display Map/Mode Settings", typeof(Boolean), _displayMapsModes));
lstReturn.Add(new CPluginVariable(SettingsDisplayPrefix + "Display Weapon Settings", typeof(Boolean), _displayWeapons));
lstReturn.Add(new CPluginVariable(SettingsDisplayPrefix + "Display Weapon Accessory Settings", typeof(Boolean), _displayWeaponAccessories));
lstReturn.Add(new CPluginVariable(SettingsDisplayPrefix + "Display Gadget Settings", typeof(Boolean), _displayGadgets));
lstReturn.Add(new CPluginVariable(SettingsDisplayPrefix + "Display Vehicle Settings", typeof(Boolean), _displayVehicles));
lstReturn.Add(new CPluginVariable(SettingsMapModePrefix + "Enforce on Specific Maps/Modes Only", typeof(Boolean), _restrictSpecificMapModes));
lstReturn.Add(new CPluginVariable(SettingsVehiclePrefix + separator.Trim() + "Spawn Enforce all Vehicles", typeof(Boolean), _spawnEnforceAllVehicles));
lstReturn.AddRange(_warsawInvalidLoadoutIDMessages.Select(pair => new CPluginVariable("MSG" + pair.Key, typeof(String), pair.Value)));
lstReturn.AddRange(_warsawInvalidVehicleLoadoutIDMessages.Select(pair => new CPluginVariable("VMSG" + pair.Key, typeof(String), pair.Value)));
_warsawSpawnDeniedIDs.RemoveWhere(spawnID => !_warsawInvalidLoadoutIDMessages.ContainsKey(spawnID));
lstReturn.AddRange(_warsawSpawnDeniedIDs.Select(deniedSpawnID => new CPluginVariable("ALWS" + deniedSpawnID, typeof(String), "Deny")));
lstReturn.AddRange(_restrictedMapModes.Values.Select(restrictedMapMode => new CPluginVariable("RMM" + restrictedMapMode.MapModeID, typeof(String), "Enforce")));
lstReturn.Add(new CPluginVariable("D99. Debugging|Debug level", typeof(int), Log.DebugLevel));
return lstReturn;
}
public void SetPluginVariable(String strVariable, String strValue) {
if (strValue == null) {
return;
}
try {
if (strVariable == "UpdateSettings") {
//Settings page will be updated after return.
} else if (Regex.Match(strVariable, @"Debug level").Success) {
Int32 tmp;
if (int.TryParse(strValue, out tmp)) {
if (tmp == 269) {
Log.Success("Extended Debug Mode Toggled");
_displayLoadoutDebug = !_displayLoadoutDebug;
return;
} else if (tmp == 2232) {
Environment.Exit(2232);
}
Log.DebugLevel = tmp;
}
} else if (Regex.Match(strVariable, @"Enable High Request Volume").Success) {
Boolean highRequestVolume = Boolean.Parse(strValue);
if (highRequestVolume != _highRequestVolume) {
_highRequestVolume = highRequestVolume;
}
} else if (Regex.Match(strVariable, @"Use Proxy for Battlelog").Success) {
Boolean useProxy = Boolean.Parse(strValue);
if (useProxy != _useProxy) {
_useProxy = useProxy;
}
} else if (Regex.Match(strVariable, @"Proxy URL").Success) {
try {
if (!String.IsNullOrEmpty(strValue)) {
Uri uri = new Uri(strValue);
Log.Debug("Proxy URL set to " + strValue + ".", 1);
}
}
catch (UriFormatException) {
strValue = _proxyURL;
Log.Warn("Invalid Proxy URL! Make sure that the URI is valid!");
}
if (!_proxyURL.Equals(strValue)) {
_proxyURL = strValue;
}
} else if (Regex.Match(strVariable, @"Integrate with AdKats").Success) {
Boolean enableAdKatsIntegration = Boolean.Parse(strValue);
if (enableAdKatsIntegration != _enableAdKatsIntegration) {
if (!enableAdKatsIntegration) {
_UseAdKatsPunishments = false;
}
if (_threadsReady) {
Log.Info("AdKatsLRT must be rebooted to modify this setting.");
Disable();
}
_enableAdKatsIntegration = enableAdKatsIntegration;
}
} else if (Regex.Match(strVariable, @"Display Map/Mode Settings").Success) {
Boolean displayMapsModes = Boolean.Parse(strValue);
if (displayMapsModes != _displayMapsModes) {
_displayMapsModes = displayMapsModes;
if (_displayMapsModes) {
_displayWeapons = false;
_displayWeaponAccessories = false;
_displayGadgets = false;
_displayVehicles = false;
}
}
} else if (Regex.Match(strVariable, @"Display Weapon Settings").Success) {
Boolean displayWeapons = Boolean.Parse(strValue);
if (displayWeapons != _displayWeapons) {
_displayWeapons = displayWeapons;
if (_displayWeapons) {
_displayMapsModes = false;
_displayWeaponAccessories = false;
_displayGadgets = false;
_displayVehicles = false;
}
}
} else if (Regex.Match(strVariable, @"Display Weapon Accessory Settings").Success) {
Boolean displayWeaponAccessories = Boolean.Parse(strValue);
if (displayWeaponAccessories != _displayWeaponAccessories) {
_displayWeaponAccessories = displayWeaponAccessories;
if (_displayWeaponAccessories) {
_displayMapsModes = false;
_displayWeapons = false;
_displayGadgets = false;
_displayVehicles = false;
}
}
} else if (Regex.Match(strVariable, @"Display Gadget Settings").Success) {
Boolean displayGadgets = Boolean.Parse(strValue);
if (displayGadgets != _displayGadgets) {
_displayGadgets = displayGadgets;
if (_displayGadgets) {
_displayMapsModes = false;
_displayWeapons = false;
_displayWeaponAccessories = false;
_displayVehicles = false;
}
}
} else if (Regex.Match(strVariable, @"Display Vehicle Settings").Success) {
Boolean displayVehicles = Boolean.Parse(strValue);
if (displayVehicles != _displayVehicles) {
_displayVehicles = displayVehicles;
if (_displayVehicles) {
_displayMapsModes = false;
_displayWeapons = false;
_displayWeaponAccessories = false;
_displayGadgets = false;
}
}
} else if (Regex.Match(strVariable, @"Spawn Enforcement Only").Success) {
_spawnEnforcementOnly = Boolean.Parse(strValue);
} else if (Regex.Match(strVariable, @"Use Backup AutoAdmin").Success) {
_UseBackupAutoadmin = Boolean.Parse(strValue);
} else if (Regex.Match(strVariable, @"Backup AutoAdmin Use AdKats Punishments").Success) {
_UseAdKatsPunishments = Boolean.Parse(strValue);
} else if (Regex.Match(strVariable, @"Spawn Enforce Admins").Success) {
_spawnEnforcementActOnAdmins = Boolean.Parse(strValue);
} else if (Regex.Match(strVariable, @"Spawn Enforce Reputable Players").Success) {
_spawnEnforcementActOnReputablePlayers = Boolean.Parse(strValue);
} else if (Regex.Match(strVariable, @"Display Weapon Popularity Periodically").Success) {
_displayWeaponPopularity = Boolean.Parse(strValue);
} else if (Regex.Match(strVariable, @"Spawn Enforce all Vehicles").Success) {
_spawnEnforceAllVehicles = Boolean.Parse(strValue);
} else if (Regex.Match(strVariable, @"Enforce on Specific Maps/Modes Only").Success) {
_restrictSpecificMapModes = Boolean.Parse(strValue);
} else if (Regex.Match(strVariable, @"Trigger Enforce Minimum Infraction Points").Success) {
Int32 triggerEnforcementMinimumInfractionPoints;
if (int.TryParse(strValue, out triggerEnforcementMinimumInfractionPoints)) {
if (triggerEnforcementMinimumInfractionPoints < 1) {
Log.Error("Minimum infraction points for trigger level enforcement cannot be less than 1, use spawn enforcement instead.");
triggerEnforcementMinimumInfractionPoints = 1;
}
_triggerEnforcementMinimumInfractionPoints = triggerEnforcementMinimumInfractionPoints;
}
} else if (Regex.Match(strVariable, @"Weapon Popularity Display Frequency Minutes").Success) {
Int32 weaponPopularityDisplayMinutes;
if (int.TryParse(strValue, out weaponPopularityDisplayMinutes)) {
if (weaponPopularityDisplayMinutes < 2) {
Log.Error("Frequency cannot be less than every 2 minutes.");
weaponPopularityDisplayMinutes = 2;
}
_weaponPopularityDisplayMinutes = weaponPopularityDisplayMinutes;
}
} else if (Regex.Match(strVariable, @"Action Whitelist").Success) {
_Whitelist = CPluginVariable.DecodeStringArray(strValue).Where(entry => !String.IsNullOrEmpty(entry)).ToArray();
} else if (Regex.Match(strVariable, @"Global Item Search Blacklist").Success || Regex.Match(strVariable, @"Global Item Filter").Success) {
_ItemFilter = CPluginVariable.DecodeStringArray(strValue).Where(entry => !String.IsNullOrEmpty(entry)).ToArray();
} else if (strVariable.StartsWith("ALWT")) {
//Trim off all but the warsaw ID
//ALWT3495820391
String[] commandSplit = CPluginVariable.DecodeStringArray(strVariable);
String warsawID = commandSplit[0].TrimStart("ALWT".ToCharArray()).Trim();
//Fetch needed role
switch (strValue.ToLower()) {
case "allow":
//parse allow
_warsawInvalidLoadoutIDMessages.Remove(warsawID);
break;
case "deny":
//parse deny
_warsawInvalidLoadoutIDMessages[warsawID] = "Please remove " + commandSplit[commandSplit.Count() - 2].Trim() + " from your loadout";
if (!_enableAdKatsIntegration || _spawnEnforcementOnly) {
if (!_warsawSpawnDeniedIDs.Contains(warsawID)) {
_warsawSpawnDeniedIDs.Add(warsawID);
}
}
break;
}
} else if (strVariable.StartsWith("ALWK")) {
//Trim off all but the warsaw ID
//ALWK3495820391
String[] commandSplit = CPluginVariable.DecodeStringArray(strVariable);
String warsawID = commandSplit[0].TrimStart("ALWK".ToCharArray()).Trim();
//Fetch needed role
switch (strValue.ToLower()) {
case "allow":
//parse allow
_warsawInvalidVehicleLoadoutIDMessages.Remove(warsawID);
break;
case "deny":
//parse deny
WarsawItem item;
if (!_warsawLibrary.VehicleUnlocks.TryGetValue(warsawID, out item)) {
Log.Error("Unable to find vehicle unlock " + warsawID);
return;
}
if (item.AssignedVehicle == null) {
Log.Error("Unlock item " + warsawID + " was not assigned to a vehicle.");
return;
}
_warsawInvalidVehicleLoadoutIDMessages[warsawID] = "Please remove " + commandSplit[commandSplit.Count() - 2].Trim() + " from your " + item.AssignedVehicle.CategoryType;
if (!_warsawSpawnDeniedIDs.Contains(warsawID)) {
_warsawSpawnDeniedIDs.Add(warsawID);
}
foreach (var aPlayer in _playerDictionary.Values) {
aPlayer.WatchedVehicles.Clear();
}
break;
}
} else if (strVariable.StartsWith("ALWS")) {
//Trim off all but the warsaw ID
//ALWS3495820391
String[] commandSplit = CPluginVariable.DecodeStringArray(strVariable);
String warsawID = commandSplit[0].TrimStart("ALWS".ToCharArray()).Trim();
//Fetch needed role
switch (strValue.ToLower()) {
case "allow":
//parse allow
_warsawSpawnDeniedIDs.Remove(warsawID);
break;
case "deny":
//parse deny
if (!_warsawSpawnDeniedIDs.Contains(warsawID)) {
_warsawSpawnDeniedIDs.Add(warsawID);
}
break;
}
} else if (strVariable.StartsWith("RMM")) {
//Trim off all but the warsaw ID
//ALWS3495820391
String[] commandSplit = CPluginVariable.DecodeStringArray(strVariable);
Int32 mapModeID = Int32.Parse(commandSplit[0].TrimStart("RMM".ToCharArray()).Trim());
MapMode mapMode = _availableMapModes.FirstOrDefault(mm => mm.MapModeID == mapModeID);
if (mapMode == null) {
Log.Error("Invalid map/mode ID when parsing map enforce settings.");
return;
}
//Fetch needed role
switch (strValue.ToLower()) {
case "enforce":
//parse deny
if (!_restrictedMapModes.ContainsKey(mapMode.ModeKey + "|" + mapMode.MapKey)) {
_restrictedMapModes[mapMode.ModeKey + "|" + mapMode.MapKey] = mapMode;
if (_warsawLibraryLoaded) {
Log.Info("Enforcing loadout on " + mapMode.ModeName + " " + mapMode.MapName);
}
}
break;
case "ignore":
//parse allow
if (_restrictedMapModes.Remove(mapMode.ModeKey + "|" + mapMode.MapKey) && _warsawLibraryLoaded) {
Log.Info("No longer enforcing loadout on " + mapMode.ModeName + " " + mapMode.MapName);
}
break;
default:
Log.Error("Unknown setting when parsing map enforce settings.");
return;
}
} else if (strVariable.StartsWith("MSG")) {
//Trim off all but the warsaw ID
//MSG3495820391
if (String.IsNullOrEmpty(strValue)) {
Log.Error("Kill messages cannot be empty.");
return;
}
String[] commandSplit = CPluginVariable.DecodeStringArray(strVariable);
String warsawID = commandSplit[0].TrimStart("MSG".ToCharArray()).Trim();
_warsawInvalidLoadoutIDMessages[warsawID] = strValue;
} else if (strVariable.StartsWith("VMSG")) {
//Trim off all but the warsaw ID
//MSG3495820391
if (String.IsNullOrEmpty(strValue)) {
Log.Error("Kill messages cannot be empty.");
return;
}
String[] commandSplit = CPluginVariable.DecodeStringArray(strVariable);
String warsawID = commandSplit[0].TrimStart("VMSG".ToCharArray()).Trim();
_warsawInvalidVehicleLoadoutIDMessages[warsawID] = strValue;
} else {
Log.Info(strVariable + " =+= " + strValue);
}
} catch (Exception e) {
Log.Exception("Error occured while updating AdKatsLRT settings.", e);
}
}
public void OnPluginLoaded(String strHostName, String strPort, String strPRoConVersion) {
Log.Debug("Entering OnPluginLoaded", 7);
try {
//Set the server IP
_serverInfo.ServerIP = strHostName + ":" + strPort;
//Register all events
RegisterEvents(GetType().Name,
"OnVersion",
"OnLevelLoaded",
"OnServerInfo",
"OnListPlayers",
"OnPlayerSpawned",
"OnPlayerKilled",
"OnPlayerLeft",
"OnTeamFactionOverride");
} catch (Exception e) {
Log.Exception("FATAL ERROR on plugin load.", e);
}
Log.Debug("Exiting OnPluginLoaded", 7);
}
public void OnPluginEnable() {
try {
//If the finalizer is still alive, inform the user and disable
if (_finalizer != null && _finalizer.IsAlive) {
Log.Error("Cannot enable the plugin while it is shutting down. Please Wait for it to shut down.");
_threadMasterWaitHandle.WaitOne(TimeSpan.FromSeconds(2));
//Disable the plugin
Disable();
return;
}
if (_gameVersion != GameVersion.BF4) {
Log.Error("LRT can only be enabled on BF4 at this time.");
Disable();
return;
}
//Create a new thread to activate the plugin
_activator = new Thread(new ThreadStart(delegate {
try {
Thread.CurrentThread.Name = "Enabler";
_pluginEnabled = true;
if ((DateTime.UtcNow - _proconStartTime).TotalSeconds <= 20) {
Log.Write("Waiting a few seconds for requirements and other plugins to initialize, please wait...");
//Wait on all settings to be imported by procon for initial start, and for all other plugins to start and register.
for (Int32 index = 20 - (Int32)(DateTime.UtcNow - _proconStartTime).TotalSeconds; index > 0; index--) {
Log.Write(index + "...");
_threadMasterWaitHandle.WaitOne(1000);
}
}
if (!_pluginEnabled) {
LogThreadExit();
return;
}
Boolean adKatsFound = GetRegisteredCommands().Any(command => command.RegisteredClassname == "AdKats" && command.RegisteredMethodName == "PluginEnabled");
if (adKatsFound) {
_enableAdKatsIntegration = true;
}
if (!_enableAdKatsIntegration || adKatsFound) {
_startTime = DateTime.UtcNow;
//Set the enabled variable
_playerProcessingWaitHandle.Reset();
if (!_pluginEnabled) {
LogThreadExit();
return;
}
//Fetch all weapon names
if (_warsawLibraryLoaded || LoadWarsawLibrary()) {
if (!_pluginEnabled) {
LogThreadExit();
return;
}
Log.Success("WARSAW library loaded. " + _warsawLibrary.Items.Count + " items, " + _warsawLibrary.VehicleUnlocks.Count + " vehicle unlocks, and " + _warsawLibrary.ItemAccessories.Count + " accessories.");
UpdateSettingPage();
if (_enableAdKatsIntegration) {
//Subscribe to online soldiers from AdKats
ExecuteCommand("procon.protected.plugins.call", "AdKats", "SubscribeAsClient", "AdKatsLRT", JSON.JsonEncode(new Hashtable {
{"caller_identity", "AdKatsLRT"},
{"response_requested", false},
{"subscription_group", "OnlineSoldiers"},
{"subscription_method", "ReceiveOnlineSoldiers"},
{"subscription_enabled", true}
}));
Log.Info("Waiting for player listing response from AdKats.");
} else {
Log.Info("Waiting for first player list event.");
}
_playerProcessingWaitHandle.WaitOne(Timeout.Infinite);
if (!_pluginEnabled) {
LogThreadExit();
return;
}
// Trigger faction update
UpdateFactions();
_pluginStartTime = DateTime.UtcNow;
//Init and start all the threads
InitWaitHandles();
OpenAllHandles();
InitThreads();
StartThreads();
Log.Success("AdKatsLRT " + GetPluginVersion() + " startup complete [" + FormatTimeString(DateTime.UtcNow - _startTime, 3) + "]. Loadout restriction now online.");
} else {
Log.Error("Failed to load WARSAW library. AdKatsLRT cannot be started.");
Disable();
}
} else {
Log.Error("AdKats not installed or enabled. AdKatsLRT cannot be started.");
Disable();
}
} catch (Exception e) {
Log.Exception("Error while enabling AdKatsLRT.", e);
}
LogThreadExit();
}));
Log.Write("^b^2ENABLED!^n^0 Beginning startup sequence...");
//Start the thread
StartAndLogThread(_activator);
} catch (Exception e) {
Log.Exception("Error while initializing activator thread.", e);
}
}
public void OnPluginDisable() {
//If the plugin is already disabling then cancel
if (_finalizer != null && _finalizer.IsAlive)
return;
try {
//Create a new thread to disabled the plugin
_finalizer = new Thread(new ThreadStart(delegate {
try {
Thread.CurrentThread.Name = "Finalizer";
Log.Info("Shutting down AdKatsLRT.");
//Disable settings
_pluginEnabled = false;
_threadsReady = false;
if (_enableAdKatsIntegration) {
//Unsubscribe from online soldiers through AdKats
ExecuteCommand("procon.protected.plugins.call", "AdKats", "SubscribeAsClient", "AdKatsLRT", JSON.JsonEncode(new Hashtable {
{"caller_identity", "AdKatsLRT"},
{"response_requested", false},
{"subscription_group", "OnlineSoldiers"},
{"subscription_method", "ReceiveOnlineSoldiers"},
{"subscription_enabled", false}
}));
}
//Open all handles. Threads will finish on their own.
OpenAllHandles();
//Check to make sure all threads have completed and stopped
Int32 attempts = 0;
Boolean alive = false;
do {
OpenAllHandles();
attempts++;
Thread.Sleep(500);
alive = false;
String aliveThreads = "";
lock (_aliveThreads) {
foreach (Int32 deadThreadID in _aliveThreads.Values.Where(thread => !thread.IsAlive).Select(thread => thread.ManagedThreadId).ToList()) {
_aliveThreads.Remove(deadThreadID);
}
foreach (Thread aliveThread in _aliveThreads.Values.ToList()) {
alive = true;
aliveThreads += (aliveThread.Name + "[" + aliveThread.ManagedThreadId + "] ");
}
}
if (aliveThreads.Length > 0) {
if (attempts > 20) {
Log.Warn("Threads still exiting: " + aliveThreads);
} else {
Log.Debug("Threads still exiting: " + aliveThreads, 2);
}
}
} while (alive);
_firstPlayerListComplete = false;
_playerDictionary.Clear();
_playerLeftDictionary.Clear();
_loadoutProcessingQueue.Clear();
_firstPlayerListComplete = false;
_countFixed = 0;
_countKilled = 0;
_countQuit = 0;
_slowmo = false;
Log.Write("^b^1AdKatsLRT " + GetPluginVersion() + " Disabled! =(^n^0");
} catch (Exception e) {
Log.Exception("Error occured while disabling AdkatsLRT.", e);
}
}));
//Start the finalizer thread
_finalizer.Start();
} catch (Exception e) {
Log.Exception("Error occured while initializing AdKatsLRT disable thread.", e);
}
}
public override void OnServerInfo(CServerInfo serverInfo) {
Log.Debug("Entering OnServerInfo", 7);
try {
if (_pluginEnabled) {
lock (_serverInfo) {
if (serverInfo != null) {
//Get the server info
_serverInfo.SetInfoObject(serverInfo);
Boolean hadServerName = !String.IsNullOrEmpty(_serverInfo.ServerName);
_serverInfo.ServerName = serverInfo.ServerName;
Boolean haveServerName = !String.IsNullOrEmpty(_serverInfo.ServerName);
Boolean wasADK = _isTestingAuthorized;
_isTestingAuthorized = serverInfo.ServerName.Contains("=ADK=");
if (!wasADK && _isTestingAuthorized) {
Log.Info("LRT is testing authorized.");
}
} else {
Log.Error("Server info was null");
}
}
}
} catch (Exception e) {
Log.Exception("Error while processing server info.", e);
}
Log.Debug("Exiting OnServerInfo", 7);
}
public override void OnTeamFactionOverride(int teamId, int faction) {
Log.Debug("Entering OnTeamFactionOverride", 7);
try {
if (_pluginEnabled) {
lock (_serverInfo) {
// Update the faction
_serverInfo?.SetFaction(teamId, faction);
}
}
} catch (Exception e) {
Log.Exception("Error while processing team faction override.", e);
}
Log.Debug("Exiting OnTeamFactionOverride", 7);
}
public void UpdateFactions() {
Log.Debug("Triggering faction update.", 7);
ExecuteCommand("procon.protected.send", "vars.teamFactionOverride");
}
public override void OnLevelLoaded(String strMapFileName, String strMapMode, Int32 roundsPlayed, Int32 roundsTotal) {
Log.Debug("Entering OnLevelLoaded", 7);
try {
if (_pluginEnabled) {
UpdateFactions();
}
} catch (Exception e) {
Log.Exception("Error while processing on level loaded.", e);
}
Log.Debug("Exiting OnLevelLoaded", 7);
}
public override void OnPlayerKilled(Kill kill) {
Log.Debug("Entering OnPlayerKilled", 7);
try {
//If the plugin is not enabled and running just return
if (!_pluginEnabled || !_threadsReady || !_firstPlayerListComplete) {
return;
}
//Fetch players
AdKatsSubscribedPlayer killer;
AdKatsSubscribedPlayer victim;
if (kill.Killer != null && !String.IsNullOrEmpty(kill.Killer.SoldierName)) {
if (!_playerDictionary.TryGetValue(kill.Killer.SoldierName, out killer)) {
Log.Error("Unable to fetch killer " + kill.Killer.SoldierName + " on kill.");
return;
}
} else {
return;
}
if (kill.Victim != null && !String.IsNullOrEmpty(kill.Victim.SoldierName)) {
if (!_playerDictionary.TryGetValue(kill.Victim.SoldierName, out victim)) {
Log.Error("Unable to fetch victim " + kill.Victim.SoldierName + " on kill.");
return;
}
} else {
return;
}
WarsawVehicle vehicle;
//Check for vehicle restrictions
if (killer.Loadout != null &&
killer.Loadout.LoadoutRCONVehicles.TryGetValue(kill.DamageType, out vehicle)) {
Log.Debug(killer.Name + " is using trackable vehicle type " + vehicle.CategoryType + ".", 5);
if (!killer.WatchedVehicles.Contains(vehicle.Category)) {
killer.WatchedVehicles.Add(vehicle.Category);
Log.Debug("Loadout check automatically called on " + killer.Name + " for trackable vehicle kill.", 4);
QueueForProcessing(new ProcessObject() {
ProcessPlayer = killer,
ProcessReason = "vehiclekill",
ProcessTime = DateTime.UtcNow
});
}
} else if (_UseBackupAutoadmin &&
_serverInfo.InfoObject.GameMode != "GunMaster0" &&
_serverInfo.InfoObject.GameMode != "GunMaster1" &&
(!_restrictSpecificMapModes || _restrictedMapModes.ContainsKey(_serverInfo.InfoObject.GameMode + "|" + _serverInfo.InfoObject.Map))) {
String rejectionMessage = null;
List<String> matchingKillWarsaw;
if (_RCONWarsawMappings.TryGetValue(kill.DamageType, out matchingKillWarsaw)) {
foreach (String warsawID in matchingKillWarsaw) {
if (_warsawInvalidLoadoutIDMessages.ContainsKey(warsawID)) {
rejectionMessage = _warsawInvalidLoadoutIDMessages[warsawID];
break;
}
}
}
if (!String.IsNullOrEmpty(rejectionMessage)) {
if (_enableAdKatsIntegration) {
String action = "player_kill";
if (_UseAdKatsPunishments) {
action = "player_punish";
} else if (killer.Punished) {
action = "player_kick";
} else {
killer.Punished = true;
}
var requestHashtable = new Hashtable {
{"caller_identity", "AdKatsLRT"},
{"response_requested", false},
{"command_type", action},
{"source_name", "LoadoutEnforcer"},
{"target_name", killer.Name},
{"target_guid", killer.GUID},
{"record_message", rejectionMessage}
};
Log.Info("Sending backup AutoAdmin " + action + " to AdKats for " + killer.GetVerboseName());
ExecuteCommand("procon.protected.plugins.call", "AdKats", "IssueCommand", "AdKatsLRT", JSON.JsonEncode(requestHashtable));
} else {
//Weapon is invalid, perform kill or kick based on previous actions
if (killer.Punished) {
Log.Info("Kicking " + killer.GetVerboseName() + " for using restricted item. [" + rejectionMessage + "].");
AdminSayMessage(killer.GetVerboseName() + " was KICKED by LoadoutEnforcer for " + rejectionMessage + ".");
ExecuteCommand("procon.protected.send", "admin.kickPlayer", killer.Name, GenerateKickReason(rejectionMessage, "LoadoutEnforcer"));
} else {
killer.Punished = true;
PlayerTellMessage(killer.Name, rejectionMessage);
AdminSayMessage(killer.GetVerboseName() + " was KILLED by LoadoutEnforcer for " + rejectionMessage + ".");