-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLanguageEnforcer.cs
More file actions
2016 lines (1763 loc) · 101 KB
/
LanguageEnforcer.cs
File metadata and controls
2016 lines (1763 loc) · 101 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// This code may be distributed under the terms and conditions of the GNU LGPL v3
// The LGPL can be read here: http://www.gnu.org/licenses/lgpl.html
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using PRoCon.Core;
using PRoCon.Core.Players;
using PRoCon.Core.Plugin;
using Api = PRoCon.Core.Plugin.PRoConPluginAPI;
namespace PRoConEvents {
public class LanguageEnforcer : LanguageEnforcerBase, IPRoConPluginInterface {
private readonly Dictionary<string, string> _badwordSection = new Dictionary<string, string>();
private readonly char[] _commandStartChars = { '!', '#', '@', '/' };
private readonly Regex _failPrevent = new Regex("(\\W(?<![!%\\|\\+\\*'-\\.]))");
private readonly List<SuccessiveMeasure> _measures = GetDefaultMeasures();
private readonly Dictionary<string, MeasureOverride> _overrides = new Dictionary<string, MeasureOverride>();
private readonly Dictionary<string, string> _regexBadwordSection = new Dictionary<string, string>();
private float _adminCoolDown = 3; //cooldown steps per day
private string[] _badwords = new string[0];
private string[] _badwordsCache = new string[0];
private float _coolDown = 3; //cooldown steps per day
private bool _disallowPlayerSelfReset;
private bool _ignoreSquadChat;
private uint _maxUpdateCounter = 6;
private Regex[] _regexBadwords = new Regex[0];
private string[] _regexBadwordsCache = new string[0]; //used for displaying since Regex.ToString may return other things than the user specified
private string _resCounterReset = "Your Language counter has been reset.";
private string[] _resLangInfo = { "LanguageEnforcer kills do not affect your stats!", "Lang killed while dead = kill on spawn", "Your counter will be decreased by %cooldown% daily", "Your current counter reads %count%" };
private string _resLatentKill = "LanguageEnforcer killed for previous language";
private bool _saveCountersAsap = true;
private DateTime _startup; //deactivate the regex setting for the first few seconds to prevent messup via procon
private bool _updateAvailable;
private uint _updateCounter = 5;
private bool _warnWhitelisted; //tells if whitelisted players should be warned
private HashSet<string> _whitelist = new HashSet<string>(); //Hashset Contains is the fastest
private bool _whitelistAdmins;
/// <summary>
/// Wrapper for the regex Badwords since a ready regex class is faster than making a new one
/// </summary>
private string[] RegexBadwords
{
get => _regexBadwordsCache;
set
{
_regexBadwordsCache = value;
//cut off anything after '#' to use that as a comment
_regexBadwords = CreateSections(value, true).Select(r => r.IndexOf('#') >= 0 ? r.Substring(0, r.IndexOf('#')) : r).Where(r => !string.IsNullOrEmpty(r)).Select(r => new Regex(r, RegexOptions.IgnoreCase)).ToArray();
}
}
public void OnPluginLoaded(string strHostName, string strPort, string strPRoConVersion) {
try {
_badwords = File.ReadAllLines(PluginFolder + "badwords.txt");
RegexBadwords = File.ReadAllLines(PluginFolder + "regexbadwords.txt");
_startup = DateTime.Now;
}
catch {
WriteLog("^bLanguage Enforcer^2: Couldn't load badwords. Please make sure filesystem access is granted");
}
//by default all will be registered! so this should speed up the layer
RegisterEvents(GetType().Name, "OnAccountLogin", "OnListPlayers", "OnPlayerJoin", "OnPlayerKilled", "OnPlayerSpawned", "OnRoundOver", "OnPlayerLeft", "OnGlobalChat", "OnTeamChat", "OnSquadChat", "OnPluginDisable", "OnPluginEnable", "OnPunkbusterPlayerInfo");
}
private static List<SuccessiveMeasure> GetDefaultMeasures() {
return new List<SuccessiveMeasure> {
new SuccessiveMeasure {
Action = BadwordAction.Warn,
PublicMessage = new[] { "%player% warned for Language violation. {Next Time: Kill}" },
PrivateMessage = new[] { "Type \"!langinfo\" for more information" },
YellMessage = new[] { "Watch your Language!" },
YellTime = 15
},
new SuccessiveMeasure {
Action = BadwordAction.Kill,
PublicMessage = new[] { "%player% killed for Language violation. {Next Time: Mute}" },
PrivateMessage = new[] { "%player%, you risk being REMOVED if you continue using this type of lanuage!" },
YellMessage = new[] { "Watch your Language!" },
YellTime = 30
},
new SuccessiveMeasure {
Action = BadwordAction.Mute,
PublicMessage = new[] { "%player% muted for Language violation. {Next Time: TempMute}" },
PrivateMessage = new[] { "%player% muted for Language violation. {Next Time: TempMute}" }
},
new SuccessiveMeasure {
Action = BadwordAction.TempMute,
PublicMessage = new[] { "%player% temp muted %time% minutes for Language violation." },
PrivateMessage = new[] { "%player% temp muted %time% minutes for Language violation." },
TBanTime = 120,
Count = 3
},
new SuccessiveMeasure {
Action = BadwordAction.TempMute,
PublicMessage = new[] { "%player% temp muted %time% minutes for Language violation." },
PrivateMessage = new[] { "%player% temp muted %time% minutes for Language violation." },
TBanTime = 900
},
new SuccessiveMeasure {
Action = BadwordAction.PermaMute,
PublicMessage = new[] { "%player% perma muted for Language violation." },
PrivateMessage = new[] { "%player% perma muted for Language violation." }
},
new SuccessiveMeasure()
};
}
public override void OnAccountLogin(string accountName, string ip, CPrivileges privileges) {
if (!LookForUpdates)
return;
_updateCounter = _maxUpdateCounter - 1;
CheckForUpdates();
}
public void CheckForUpdates() {
if (_updateAvailable) {
const string m = "^1Your Version of the LanguageEnforcer is outdated!";
ConsoleWrite(m);
ExecuteCommand("procon.protected.chat.write", m);
return;
}
_updateCounter++;
if (_updateCounter == _maxUpdateCounter) {
_updateCounter = 0;
try {
string result;
using (var webClient = new WebClient()) {
result = webClient.DownloadString("https://raw.githubusercontent.com/Hedius/LanguageEnforcer/main/version.txt");
}
if (result != GetPluginVersion()) {
_updateAvailable = true;
CheckForUpdates();
}
}
catch {
WriteLog("^bLanguage Enforcer^2: Update Check failed!");
}
}
}
public override void OnPlayerKilled(Kill k) {
try {
CachePlayerInfo(k.Killer);
CachePlayerInfo(k.Victim);
}
catch (Exception exc) {
WriteLog(exc.ToString());
}
}
public override void OnRoundOver(int winningTeamId) {
base.OnRoundOver(winningTeamId);
Guids.Clear();
}
/// <summary>
/// Clears the GUIDs, the online admins, the tbd-list and calculates the a cooled down heat value for each player in
/// the players list.
/// </summary>
protected override void Cleanup() {
base.Cleanup();
var temp = Players.ToArray(); //remove in foreach will otherwise kill the enumerator
foreach (var player in temp) {
var days = (DateTime.Now - player.Value.LastAction).TotalDays;
player.Value.Heat = Math.Max(-1D, player.Value.Heat - GetCooldown(player.Key) * days);
player.Value.LastAction = DateTime.Now;
if (player.Value.Heat < -0.9D)
Players.Remove(player.Key);
}
}
public override void OnSquadChat(string speaker, string message, int teamId, int squadId) {
if (_ignoreSquadChat) {
if (message.StartsWithOneOf(_commandStartChars))
ExecuteInGameCommand(speaker, message);
}
else {
OnChat(speaker, message);
}
}
protected override void OnChat(string speaker, string message) {
try {
if (message.StartsWithOneOf(_commandStartChars) && ExecuteInGameCommand(speaker, message))
return; //no search for badwords necessary
if (speaker == "Server")
return;
var admin = IsAdmin(speaker);
var whitelisted = (_whitelistAdmins && admin) || _whitelist.Contains(speaker.ToLowerFast());
if (!whitelisted || _warnWhitelisted) {
string match;
Regex rmatch;
var mo = MeasureOverride.NoOverride;
if ((match = _badwords.FirstOrDefault(message.ContainsIgnoreCaseFast)) != null) {
if (_badwordSection.ContainsKey(match)) {
var section = _badwordSection[match];
if (_overrides.ContainsKey(section))
mo = _overrides[section];
}
if (LogToAdKats)
LogViolation(speaker, message, match);
TakeMeasure(speaker, message, WhitelistOverride(mo, whitelisted));
WriteLog(string.Format("LanguageEnforcer: Player {0} triggered the word '{1}'", speaker, match));
}
else if ((rmatch = _regexBadwords.FirstOrDefault(r => r.IsMatch(message))) != null) {
var idx = _regexBadwords.Select((r, i) => new {
regex = r,
index = i
}).FirstOrDefault(item => item.regex == rmatch);
if (idx != null) {
match = RegexBadwords.Select(r => r.IndexOf('#') >= 0 ? r.Substring(0, r.IndexOf('#')) : r).Where(r => !string.IsNullOrEmpty(r) && !Regex.IsMatch(r, "^{\\w+}$")).ElementAt(idx.index);
if (_regexBadwordSection.ContainsKey(match)) {
var section = _regexBadwordSection[match];
if (_overrides.ContainsKey(section))
mo = _overrides[section];
}
TakeMeasure(speaker, message, WhitelistOverride(mo, whitelisted));
if (LogToAdKats)
LogViolation(speaker, message, match);
WriteLog(string.Format("LanguageEnforcer: Player {0} triggered the word {1}", speaker, match));
}
else {
WriteLog("LanguageEnforcer: Error while trying to determine match");
if (LogToAdKats)
LogViolation(speaker, message, "Unknown");
TakeMeasure(speaker, message, WhitelistOverride(mo, whitelisted));
}
}
if (whitelisted)
Players.Remove(speaker);
}
}
catch (Exception exc) {
WriteLog(exc.ToString());
}
}
private MeasureOverride WhitelistOverride(MeasureOverride mo, bool whitelisted) {
if (!whitelisted)
return mo;
return new MeasureOverride {
TBanTime = 0,
YellTime = mo.YellTime,
PrivateMessage = mo.PrivateMessage,
PublicMessage = mo.PublicMessage,
YellMessage = mo.YellMessage,
MinimumAction = BadwordAction.Warn,
AlwaysUseMinAction = true,
MinimumCounter = -1,
Severity = 0,
IsWhitelisted = true,
NoAdKats = true
};
}
/// <summary>
/// Check if the player issued a command and execute the according command
/// </summary>
/// <returns>true if there is no need to check for badwords anymore</returns>
private bool ExecuteInGameCommand(string speaker, string message) {
message = message.Substring(1);
if (IsAdmin(speaker)) //admin commands
{
if (message.StartsWith("langreset", StringComparison.OrdinalIgnoreCase) || message.StartsWith("langr ", StringComparison.OrdinalIgnoreCase)) {
var idx = message.IndexOf(' ');
return ManuallyResetPlayer(speaker, message.Substring(idx + 1));
}
/*
No longer needed. Adkats will issue this.
if (message.StartsWith("langpunish", StringComparison.OrdinalIgnoreCase) || message.StartsWith("langp ", StringComparison.OrdinalIgnoreCase))
{
var idx = message.IndexOf(' ');
return ManuallyPunishPlayer(speaker, message.Substring(idx + 1));
}
*/
if (message.StartsWith("langcounter", StringComparison.OrdinalIgnoreCase) || message.StartsWith("langc ", StringComparison.OrdinalIgnoreCase)) {
var args = message.Split(' ');
if (args.Length != 2 && args.Length != 3) {
PlayerSay(speaker, "Wrong command usage");
return false;
}
var player = FindPlayerName(args[1]);
if (player == null) {
PlayerSay(speaker, "Player not found");
return false;
}
if (_disallowPlayerSelfReset && speaker == player)
return false;
PlayerInfo pi;
if (Players.ContainsKey(speaker)) {
pi = Players[speaker];
}
else {
pi = new PlayerInfo {
LastAction = DateTime.Now,
Heat = -1F
};
Players.Add(speaker, pi);
}
if (args.Length == 2) {
PlayerSay(speaker, "Counter of " + player + " reads " + GetCounter(player));
}
else //length=3
{
pi.Heat = Convert.ToDouble(args[2].Replace(',', '.'), CultureInfo.InvariantCulture.NumberFormat) - 1;
pi.LastAction = DateTime.Now;
PlayerSay(speaker, "Counter of " + player + " now reads " + (pi.Heat + 1).ToString("0.00"));
}
return true;
}
}
//public commands
if (message.StartsWith("langinfo", StringComparison.OrdinalIgnoreCase)) {
foreach (var line in _resLangInfo)
PlayerSay(speaker, ProconUtil.ProcessMessage(line, speaker, false, 0, "", false, this));
return message.Length == 8;
}
return false;
}
internal void ShowRules(string target) {
ExecuteAdKatsCommand("self_rules", target, "Telling Player Rules");
}
private bool ManuallyResetPlayer(string speaker, string player) {
player = FindPlayerName(player);
if (player == null) {
PlayerSay(speaker, "Player not found!");
return false;
}
if (_disallowPlayerSelfReset && speaker == player)
return false;
Players.Remove(player);
PlayerSay(player, ProconUtil.ProcessMessage(_resCounterReset, player, false, 0, "", false, this));
AdminSay(string.Format("LanguageEnforcer: Player {0} now has a clean jacket", player));
return true;
}
private bool ManuallyPunishPlayer(string speaker, string player) {
player = FindPlayerName(player);
if (player == null) {
PlayerSay(speaker, "Player not found!");
return false;
}
TakeMeasure(player, "", MeasureOverride.NoOverride);
return true;
}
/// <summary>
/// Issue a punish over from AdKats. Called by adkats.
/// This command will always work. The incoming name is already normalized by AdKats)
/// </summary>
/// <param name="commandParams">name, guid</param>
public void RemoteManuallyPunishPlayer(params string[] commandParams) {
var name = commandParams[1];
// Add the guid to the guid cache if it is missing
var guid = commandParams[2];
CachePlayerInfo(name, guid);
TakeMeasure(name, "(Triggered by Admin)", MeasureOverride.NoOverride);
}
/// <summary>
/// Reset the counters for a player.
/// </summary>
/// <param name="commandParams">name, guid</param>
public void RemoteManuallyResetPlayer(params string[] commandParams) {
var name = commandParams[1];
// Add the guid to the guid cache if it is missing
var guid = commandParams[2];
CachePlayerInfo(name, guid);
if (Players.ContainsKey(name))
Players.Remove(name);
AdminSay(string.Format("LanguageEnforcer: Player {0} now has a clean jacket", name));
}
/// <summary>
/// Autocompletion for in-game commands
/// </summary>
/// <param name="player">a fragment of a player name</param>
/// <returns>the actual player name or null if there were 0 or multiple matches</returns>
private string FindPlayerName(string player) {
var names = Players.Where(p => p.Key.ContainsIgnoreCaseFast(player)).ToArray();
if (names.Length != 1) {
var names2 = Guids.Where(p => p.Key.ContainsIgnoreCaseFast(player)).ToArray();
if (names2.Length != 1)
return null;
return names2[0].Key;
}
return names[0].Key;
}
/// <summary>
/// Punishes a Player for bad language
/// </summary>
private void TakeMeasure(string speaker, string quote, MeasureOverride mo) {
PlayerInfo pi;
if (Players.ContainsKey(speaker)) {
pi = Players[speaker];
}
else {
pi = new PlayerInfo {
LastAction = DateTime.Now,
Heat = -1F
};
if (Guids.ContainsKey(speaker))
pi.Guid = Guids[speaker];
Players.Add(speaker, pi);
}
if (pi.Heat > -1) {
//cooldown logic
var days = (DateTime.Now - pi.LastAction).TotalDays;
pi.Heat = Math.Max(-1F, pi.Heat - GetCooldown(speaker) * days);
}
if (!mo.IsWhitelisted)
pi.Heat = Math.Max(pi.Heat + mo.Severity, mo.MinimumCounter);
pi.LastAction = DateTime.Now;
var mea = (int)Math.Ceiling(pi.Heat);
TakeMeasure(speaker, mea, quote, mo);
if (SaveCounters && _saveCountersAsap)
WriteCounters();
}
private void TakeMeasure(string player, int measureIdx, string quote, MeasureOverride mo) {
BadwordAction next;
var now = GetMeasure(measureIdx, out next);
if (now.GetAction(mo, UseAdKatsPunish) == BadwordAction.Warn) {
var guid = Guids.ContainsKey(player) ? Guids[player] : "unknown";
WriteLog(string.Format("LanguageEnforcer: Player {0} warned. GUID = {1}", player, guid));
}
now.TakeMeasure(this, player, now.Action != next, quote, mo);
}
private SuccessiveMeasure GetMeasure(int measureIdx, out BadwordAction nextAction) {
var current = 0;
var count = _measures.Count;
SuccessiveMeasure ret = null;
for (var i = 0; i < count; i++) {
if (_measures[i].Action == BadwordAction.ListEnd)
break;
ret = _measures[i];
var next = (int)(current + ret.Count);
if (measureIdx < next) {
nextAction = measureIdx + 1 < next ? ret.Action : _measures[Math.Min(i + 1, count - 1)].Action;
if (nextAction == BadwordAction.ListEnd)
nextAction = ret.Action;
return ret;
}
current = next;
}
nextAction = ret.Action;
return ret;
}
internal int GetCounter(string player) {
if (Players.ContainsKey(player)) {
var pi = Players[player];
var days = (DateTime.Now - pi.LastAction).TotalDays;
return (int)Math.Ceiling(Math.Max(0F, pi.Heat - GetCooldown(player) * days)) + 1;
}
return 0;
}
internal float GetCooldown(string player) {
return IsAdmin(player) ? _adminCoolDown : _coolDown;
}
#region Settings
public bool LookForUpdates
{
get => base.LookForUpdates;
set
{
base.LookForUpdates = value;
RunUpdateTask = value;
}
}
public List<CPluginVariable> GetDisplayPluginVariables() {
return new List<CPluginVariable>(GetVariables(false));
}
public List<CPluginVariable> GetPluginVariables() {
return new List<CPluginVariable>(GetVariables(true));
}
public IEnumerable<CPluginVariable> GetVariables(bool getAll) {
//type safety + needs less space
var badActEnum = ProconUtil.CreateEnumString<BadwordAction>();
var badActEnumNoEnd = badActEnum.Replace(BadwordAction.ListEnd + "|", "");
Func<string, float, CPluginVariable> floatPluginVariable = (name, value) => new CPluginVariable(name, typeof(string), value.ToString("0.00", CultureInfo.InvariantCulture.NumberFormat));
Func<string, uint, CPluginVariable> unIntPluginVariable = (name, value) => new CPluginVariable(name, typeof(int), value);
Func<string, bool, CPluginVariable> yesNoPluginVariable = (name, value) => new CPluginVariable(name, typeof(enumBoolYesNo), value ? enumBoolYesNo.Yes : enumBoolYesNo.No);
Func<string, string, CPluginVariable> stringPluginVariable = (name, value) => new CPluginVariable(name, typeof(string), value.SavePrepare(getAll));
Func<string, IEnumerable<string>, CPluginVariable> sArrayPluginVariable = (name, value) => new CPluginVariable(name, typeof(string[]), value.SavePrepare(getAll));
Func<string, string, CPluginVariable> actionPluginVariable = (name, value) => new CPluginVariable(name, badActEnum, value);
Func<string, string, CPluginVariable> overridePluginVariable = (name, value) => new CPluginVariable(name, badActEnumNoEnd, value);
Func<string, uint?, CPluginVariable> ovIntPluginVariable = (name, value) => new CPluginVariable(name, typeof(string), value == null ? "No override" : value.ToString());
yield return floatPluginVariable("2 - General|Cooldown steps per day", _coolDown);
yield return floatPluginVariable("2 - General|Admin cooldown per day", _adminCoolDown);
yield return new CPluginVariable("2 - General|Log to", ProconUtil.CreateEnumString<LoggingTarget>(), LogTarget.ToString());
yield return yesNoPluginVariable("2 - General|Load/Save counters to disk", SaveCounters);
if (SaveCounters)
yield return yesNoPluginVariable("2 - General|Save counters on every punish", _saveCountersAsap);
yield return yesNoPluginVariable("2 - General|Log violations to AdKats", LogToAdKats);
yield return yesNoPluginVariable("2 - General|Use AdKats punishment", UseAdKatsPunish);
yield return yesNoPluginVariable("2 - General|Look for Updates", LookForUpdates);
if (LookForUpdates || getAll)
yield return unIntPluginVariable("2 - General|Look for Updates every X hours", _maxUpdateCounter);
for (var i = 0; i < _measures.Count; i++) {
var measure = _measures[i];
var meastring = measure.Action.ToString();
var dispNo = i + 1;
switch (measure.Action) {
case BadwordAction.Warn:
yield return actionPluginVariable(string.Format("3.{0} - Measure {0} - {1} x{2}|Measure #{0} - Measure", dispNo, meastring, measure.Count), meastring);
yield return unIntPluginVariable(string.Format("3.{0} - Measure {0} - {1} x{2}|Measure #{0} - Repeat X times", dispNo, meastring, measure.Count), measure.Count);
yield return sArrayPluginVariable(string.Format("3.{0} - Measure {0} - {1} x{2}|Measure #{0} - Public chat message", dispNo, meastring, measure.Count), measure.PublicMessage);
yield return sArrayPluginVariable(string.Format("3.{0} - Measure {0} - {1} x{2}|Measure #{0} - Private chat message", dispNo, meastring, measure.Count), measure.PrivateMessage);
yield return sArrayPluginVariable(string.Format("3.{0} - Measure {0} - {1} x{2}|Measure #{0} - Yell message", dispNo, meastring, measure.Count), measure.YellMessage);
yield return unIntPluginVariable(string.Format("3.{0} - Measure {0} - {1} x{2}|Measure #{0} - Yell time (sec.)", dispNo, meastring, measure.Count), measure.YellTime);
yield return sArrayPluginVariable(string.Format("3.{0} - Measure {0} - {1} x{2}|Measure #{0} - Command", dispNo, meastring, measure.Count), measure.Command);
break;
case BadwordAction.Kill:
goto case BadwordAction.Warn;
case BadwordAction.Kick:
yield return actionPluginVariable(string.Format("3.{0} - Measure {0} - Kick x{1}|Measure #{0} - Measure", dispNo, measure.Count), meastring);
yield return unIntPluginVariable(string.Format("3.{0} - Measure {0} - Kick x{1}|Measure #{0} - Repeat X times", dispNo, measure.Count), measure.Count);
yield return sArrayPluginVariable(string.Format("3.{0} - Measure {0} - Kick x{1}|Measure #{0} - Public chat message", dispNo, measure.Count), measure.PublicMessage);
yield return sArrayPluginVariable(string.Format("3.{0} - Measure {0} - Kick x{1}|Measure #{0} - Kick reason", dispNo, measure.Count), measure.PrivateMessage);
yield return sArrayPluginVariable(string.Format("3.{0} - Measure {0} - Kick x{1}|Measure #{0} - Command", dispNo, measure.Count), measure.Command);
break;
case BadwordAction.TBan:
yield return actionPluginVariable(string.Format("3.{0} - Measure {0} - TBan{2} x{1}|Measure #{0} - Measure", dispNo, measure.Count, measure.TBanTime), meastring);
yield return unIntPluginVariable(string.Format("3.{0} - Measure {0} - TBan{2} x{1}|Measure #{0} - Repeat X times", dispNo, measure.Count, measure.TBanTime), measure.Count);
yield return sArrayPluginVariable(string.Format("3.{0} - Measure {0} - TBan{2} x{1}|Measure #{0} - Public chat message", dispNo, measure.Count, measure.TBanTime), measure.PublicMessage);
yield return sArrayPluginVariable(string.Format("3.{0} - Measure {0} - TBan{2} x{1}|Measure #{0} - TBan reason", dispNo, measure.Count, measure.TBanTime), measure.PrivateMessage);
yield return unIntPluginVariable(string.Format("3.{0} - Measure {0} - TBan{2} x{1}|Measure #{0} - TBan minutes", dispNo, measure.Count, measure.TBanTime), measure.TBanTime);
yield return sArrayPluginVariable(string.Format("3.{0} - Measure {0} - TBan{2} x{1}|Measure #{0} - Command", dispNo, measure.Count, measure.TBanTime), measure.Command);
break;
case BadwordAction.PermBan:
yield return actionPluginVariable(string.Format("3.{0} - Measure {0} - Permanent Ban|Measure #{0} - Measure", dispNo), meastring);
yield return sArrayPluginVariable(string.Format("3.{0} - Measure {0} - Permanent Ban|Measure #{0} - Public chat message", dispNo), measure.PublicMessage);
yield return sArrayPluginVariable(string.Format("3.{0} - Measure {0} - Permanent Ban|Measure #{0} - Ban reason", dispNo), measure.PrivateMessage);
yield return sArrayPluginVariable(string.Format("3.{0} - Measure {0} - Permanent Ban|Measure #{0} - Command", dispNo), measure.Command);
break;
case BadwordAction.Mute:
yield return actionPluginVariable(string.Format("3.{0} - Measure {0} - Mute x{1}|Measure #{0} - Measure", dispNo, measure.Count), meastring);
yield return unIntPluginVariable(string.Format("3.{0} - Measure {0} - Mute x{1}|Measure #{0} - Repeat X times", dispNo, measure.Count), measure.Count);
yield return sArrayPluginVariable(string.Format("3.{0} - Measure {0} - Mute x{1}|Measure #{0} - Public chat message", dispNo, measure.Count), measure.PublicMessage);
yield return sArrayPluginVariable(string.Format("3.{0} - Measure {0} - Mute x{1}|Measure #{0} - Mute reason", dispNo, measure.Count), measure.PrivateMessage);
yield return sArrayPluginVariable(string.Format("3.{0} - Measure {0} - Mute x{1}|Measure #{0} - Command", dispNo, measure.Count), measure.Command);
break;
case BadwordAction.TempMute:
yield return actionPluginVariable(string.Format("3.{0} - Measure {0} - Temp Mute{2} x{1}|Measure #{0} - Measure", dispNo, measure.Count, measure.TBanTime), meastring);
yield return unIntPluginVariable(string.Format("3.{0} - Measure {0} - Temp Mute{2} x{1}|Measure #{0} - Repeat X times", dispNo, measure.Count, measure.TBanTime), measure.Count);
yield return sArrayPluginVariable(string.Format("3.{0} - Measure {0} - Temp Mute{2} x{1}|Measure #{0} - Public chat message", dispNo, measure.Count, measure.TBanTime), measure.PublicMessage);
yield return sArrayPluginVariable(string.Format("3.{0} - Measure {0} - Temp Mute{2} x{1}|Measure #{0} - Mute reason", dispNo, measure.Count, measure.TBanTime), measure.PrivateMessage);
yield return unIntPluginVariable(string.Format("3.{0} - Measure {0} - Temp Mute{2} x{1}|Measure #{0} - Mute minutes", dispNo, measure.Count, measure.TBanTime), measure.TBanTime);
yield return sArrayPluginVariable(string.Format("3.{0} - Measure {0} - Temp Mute{2} x{1}|Measure #{0} - Command", dispNo, measure.Count, measure.TBanTime), measure.Command);
break;
case BadwordAction.PermaMute:
yield return actionPluginVariable(string.Format("3.{0} - Measure {0} - Permanent Mute x{1}|Measure #{0} - Measure", dispNo, measure.Count), meastring);
yield return unIntPluginVariable(string.Format("3.{0} - Measure {0} - Permanent Mute x{1}|Measure #{0} - Repeat X times", dispNo, measure.Count, measure.TBanTime), measure.Count);
yield return sArrayPluginVariable(string.Format("3.{0} - Measure {0} - Permanent Mute x{1}|Measure #{0} - Public chat message", dispNo, measure.Count), measure.PublicMessage);
yield return sArrayPluginVariable(string.Format("3.{0} - Measure {0} - Permanent Mute x{1}|Measure #{0} - Mute reason", dispNo, measure.Count), measure.PrivateMessage);
yield return sArrayPluginVariable(string.Format("3.{0} - Measure {0} - Permanent Mute x{1}|Measure #{0} - Command", dispNo, measure.Count), measure.Command);
break;
// Hedius: Well... this is fully redundant, but I am too lazy to fix the code of other persons. So i gotta make it worse. Shame on me...
// actually switching the text field value would be nicer... not gonna do it... works like that...
case BadwordAction.TempForceMute:
yield return actionPluginVariable(string.Format("3.{0} - Measure {0} - Temp Force Mute{2} x{1}|Measure #{0} - Measure", dispNo, measure.Count, measure.TBanTime), meastring);
yield return unIntPluginVariable(string.Format("3.{0} - Measure {0} - Temp Force Mute{2} x{1}|Measure #{0} - Repeat X times", dispNo, measure.Count, measure.TBanTime), measure.Count);
yield return sArrayPluginVariable(string.Format("3.{0} - Measure {0} - Temp Force Mute{2} x{1}|Measure #{0} - Public chat message", dispNo, measure.Count, measure.TBanTime), measure.PublicMessage);
yield return sArrayPluginVariable(string.Format("3.{0} - Measure {0} - Temp Force Mute{2} x{1}|Measure #{0} - Mute reason", dispNo, measure.Count, measure.TBanTime), measure.PrivateMessage);
yield return unIntPluginVariable(string.Format("3.{0} - Measure {0} - Temp Force Mute{2} x{1}|Measure #{0} - Mute minutes", dispNo, measure.Count, measure.TBanTime), measure.TBanTime);
yield return sArrayPluginVariable(string.Format("3.{0} - Measure {0} - Temp Force Mute{2} x{1}|Measure #{0} - Command", dispNo, measure.Count, measure.TBanTime), measure.Command);
break;
case BadwordAction.PermaForceMute:
yield return actionPluginVariable(string.Format("3.{0} - Measure {0} - Permanent Force Mute x{1}|Measure #{0} - Measure", dispNo, measure.Count), meastring);
yield return unIntPluginVariable(string.Format("3.{0} - Measure {0} - Permanent Force Mute x{1}|Measure #{0} - Repeat X times", dispNo, measure.Count, measure.TBanTime), measure.Count);
yield return sArrayPluginVariable(string.Format("3.{0} - Measure {0} - Permanent Force Mute x{1}|Measure #{0} - Public chat message", dispNo, measure.Count), measure.PublicMessage);
yield return sArrayPluginVariable(string.Format("3.{0} - Measure {0} - Permanent Force Mute x{1}|Measure #{0} - Mute reason", dispNo, measure.Count), measure.PrivateMessage);
yield return sArrayPluginVariable(string.Format("3.{0} - Measure {0} - Permanent Force Mute x{1}|Measure #{0} - Command", dispNo, measure.Count), measure.Command);
break;
case BadwordAction.ShowRules:
yield return actionPluginVariable(string.Format("3.{0} - Measure {0} - Show Rules|Measure #{0} - Measure", dispNo), meastring);
yield return sArrayPluginVariable(string.Format("3.{0} - Measure {0} - Show Rules|Measure #{0} - Command", dispNo), measure.Command);
break;
case BadwordAction.Custom:
yield return actionPluginVariable(string.Format("3.{0} - Measure {0} - Custom Command|Measure #{0} - Measure", dispNo), meastring);
yield return sArrayPluginVariable(string.Format("3.{0} - Measure {0} - Custom Command|Measure #{0} - Command", dispNo), measure.Command);
break;
}
if (measure.Action == BadwordAction.ListEnd) {
yield return actionPluginVariable(string.Format("3.{0} - Measure List End|Measure #{0} - Measure", dispNo), meastring);
break; //end the for-loop (not possible inside switch)
}
}
yield return sArrayPluginVariable("4 - Excluded Players|Whitelist", _whitelist);
yield return yesNoPluginVariable("4 - Excluded Players|Treat Admins as Whitelisted", _whitelistAdmins);
yield return yesNoPluginVariable("4 - Excluded Players|Disallow player self reset", _disallowPlayerSelfReset);
yield return yesNoPluginVariable("4 - Excluded Players|Warn Whitelisted", _warnWhitelisted);
yield return yesNoPluginVariable("4 - Excluded Players|Ignore squad chat", _ignoreSquadChat);
yield return sArrayPluginVariable("1 - Wordlists|Badwords", _badwordsCache);
yield return sArrayPluginVariable("1 - Wordlists|Regex Badwords", RegexBadwords);
yield return stringPluginVariable("5 - Messages|Latent kill message", _resLatentKill);
yield return stringPluginVariable("5 - Messages|Counter reset message", _resCounterReset);
yield return sArrayPluginVariable("5 - Messages|!langinfo message", _resLangInfo);
var sections = _badwordSection.Values.Concat(_regexBadwordSection.Values).Distinct().ToArray();
for (var index = 0; index < sections.Length; index++) {
var dispNo = index + 1;
var section = sections[index];
var enabled = _overrides.ContainsKey(section);
yield return yesNoPluginVariable(string.Format("6.{0} - Measure override section '{1}'|Section '{1}' - Enabled", dispNo, section), enabled);
if (enabled) {
var mo = _overrides[section];
if (UseAdKatsPunish) {
yield return yesNoPluginVariable(string.Format("6.{0} - Measure override section '{1}'|Section '{1}' - Use AdKats punish", dispNo, section), !mo.NoAdKats);
}
else {
yield return floatPluginVariable(string.Format("6.{0} - Measure override section '{1}'|Section '{1}' - Severity", dispNo, section), mo.Severity);
yield return yesNoPluginVariable(string.Format("6.{0} - Measure override section '{1}'|Section '{1}' - Allow higher measures", dispNo, section), !mo.AlwaysUseMinAction);
yield return floatPluginVariable(string.Format("6.{0} - Measure override section '{1}'|Section '{1}' - Minimum counter afterwards", dispNo, section), mo.MinimumCounter + 1);
}
if (!UseAdKatsPunish || (UseAdKatsPunish && mo.NoAdKats)) {
yield return overridePluginVariable(string.Format("6.{0} - Measure override section '{1}'|Section '{1}' - Measure", dispNo, section), mo.MinimumAction.ToString());
if (mo.MinimumAction != BadwordAction.ShowRules && mo.MinimumAction != BadwordAction.Custom) {
yield return sArrayPluginVariable(string.Format("6.{0} - Measure override section '{1}'|Section '{1}' - Public message", dispNo, section), mo.PublicMessage);
yield return sArrayPluginVariable(string.Format("6.{0} - Measure override section '{1}'|Section '{1}' - Private message", dispNo, section), mo.PrivateMessage);
yield return sArrayPluginVariable(string.Format("6.{0} - Measure override section '{1}'|Section '{1}' - Yell message", dispNo, section), mo.YellMessage);
yield return ovIntPluginVariable(string.Format("6.{0} - Measure override section '{1}'|Section '{1}' - Yell time (sec.)", dispNo, section), mo.YellTime);
yield return sArrayPluginVariable(string.Format("6.{0} - Measure override section '{1}'|Section '{1}' - Command", dispNo, section), mo.Command);
}
}
else {
yield return sArrayPluginVariable(string.Format("6.{0} - Measure override section '{1}'|Section '{1}' - Public message", dispNo, section), mo.PublicMessage);
}
if (mo.MinimumAction != BadwordAction.ShowRules && mo.MinimumAction != BadwordAction.Custom && (!UseAdKatsPunish || (UseAdKatsPunish && mo.NoAdKats && mo.MinimumAction == BadwordAction.TBan)))
yield return ovIntPluginVariable(string.Format("6.{0} - Measure override section '{1}'|Section '{1}' - TBan/Mute minutes", dispNo, section), mo.TBanTime);
}
}
if (!getAll) //do not save
{
yield return new CPluginVariable("0 - Commands|Manually punish Player (Not a setting)", typeof(string), "");
yield return new CPluginVariable("0 - Commands|Manually reset Player (Not a setting)", typeof(string), "");
}
}
public void SetPluginVariable(string strVariable, string strValue) {
const string yes = "Yes";
if (strVariable.Contains('|'))
strVariable = strVariable.Substring(strVariable.IndexOf('|') + 1);
switch (strVariable) {
case "Cooldown steps per day":
_coolDown = Convert.ToSingle(strValue.Replace(',', '.'), CultureInfo.InvariantCulture.NumberFormat);
return;
case "Admin cooldown per day":
_adminCoolDown = Convert.ToSingle(strValue.Replace(',', '.'), CultureInfo.InvariantCulture.NumberFormat);
return;
case "Log to":
LogTarget = Enum.Parse(typeof(LoggingTarget), CPluginVariable.Decode(strValue)) as LoggingTarget? ?? LoggingTarget.Console;
return;
case "Load/Save counters to disk":
SaveCounters = strValue == yes;
return;
case "Save counters on every punish":
_saveCountersAsap = strValue == yes;
return;
case "Log violations to AdKats":
LogToAdKats = strValue == yes;
return;
case "Use AdKats punishment":
UseAdKatsPunish = strValue == yes;
return;
case "Look for Updates":
LookForUpdates = strValue == yes;
return;
case "Look for Updates every X hours":
_updateCounter = (_maxUpdateCounter = uint.Parse(strValue)) - 1;
return;
case "Whitelist":
_whitelist = new HashSet<string>(CPluginVariable.DecodeStringArray(strValue.ToLowerFast()));
return;
case "Treat Admins as Whitelisted":
_whitelistAdmins = strValue == yes;
return;
case "Disallow player self reset":
_disallowPlayerSelfReset = strValue == yes;
return;
case "Warn Whitelisted":
_warnWhitelisted = strValue == yes;
return;
case "Ignore squad chat":
_ignoreSquadChat = strValue == yes;
return;
case "Badwords":
WriteBadwords(strValue, false);
return;
case "Regex Badwords":
WriteBadwords(strValue, true);
return;
case "Latent kill message":
_resLatentKill = CPluginVariable.Decode(strValue);
return;
case "Counter reset message":
_resCounterReset = CPluginVariable.Decode(strValue);
return;
case "!langinfo message":
_resLangInfo = CPluginVariable.DecodeStringArray(strValue);
return;
case "Manually punish Player (Not a setting)":
ManuallyPunishPlayer("Server", CPluginVariable.Decode(strValue).Trim());
return;
case "Manually reset Player (Not a setting)":
ManuallyResetPlayer("Server", CPluginVariable.Decode(strValue).Trim());
return;
}
//Measure list assignment
if (Regex.IsMatch(strVariable, "^Measure #\\d+ - ")) {
var index = int.Parse(strVariable.Substring(9, strVariable.IndexOf(' ', 9) - 9)) - 1;
if (strVariable.ContainsFast("reason")) {
_measures[index].PrivateMessage = CPluginVariable.DecodeStringArray(strValue);
return;
}
strVariable = Regex.Replace(strVariable, "^Measure #\\d+ - ", "");
var msg = new string[0];
switch (strVariable) {
case "Repeat X times":
_measures[index].Count = uint.Parse(strValue);
return;
case "Yell time (sec.)":
_measures[index].YellTime = uint.Parse(strValue);
return;
case "TBan minutes":
case "Mute minutes":
case "TBan/Mute minutes":
_measures[index].TBanTime = uint.Parse(strValue);
return;
case "Public chat message":
msg = CPluginVariable.DecodeStringArray(strValue);
if (msg.Length == 1 && string.IsNullOrEmpty(msg[0]))
msg = new string[0];
_measures[index].PublicMessage = msg;
return;
case "Private chat message":
msg = CPluginVariable.DecodeStringArray(strValue);
if (msg.Length == 1 && string.IsNullOrEmpty(msg[0]))
msg = new string[0];
_measures[index].PrivateMessage = msg;
return;
case "Yell message":
msg = CPluginVariable.DecodeStringArray(strValue);
if (msg.Length == 1 && string.IsNullOrEmpty(msg[0]))
msg = new string[0];
_measures[index].YellMessage = msg;
return;
case "Command":
msg = CPluginVariable.DecodeStringArray(strValue);
if (msg.Length == 1 && string.IsNullOrEmpty(msg[0]))
msg = new string[0];
_measures[index].Command = msg;
return;
case "Measure":
var act = (BadwordAction)Enum.Parse(typeof(BadwordAction), CPluginVariable.Decode(strValue));
if (act == BadwordAction.ListEnd && index == 0)
return;
if (act != BadwordAction.ListEnd && _measures[index].Action == BadwordAction.ListEnd && index + 1 < _measures.Count)
_measures[index + 1].Action = BadwordAction.ListEnd;
if (index >= _measures.Count - 1 && act != BadwordAction.ListEnd)
_measures.Add(new SuccessiveMeasure());
_measures[index].Action = act;
return;
}
}
var r = new Regex("^Section '(.+)' - (.+)");
var m = r.Match(strVariable);
if (m.Success) {
var section = m.Groups[1].Value;
var setting = m.Groups[2].Value;
if (setting == "Enabled") {
if (strValue == yes) {
if (!_overrides.ContainsKey(section))
_overrides.Add(section, new MeasureOverride());
}
else {
if (_overrides.ContainsKey(section))
_overrides.Remove(section);
}
return;
}
if (!_overrides.ContainsKey(section))
_overrides.Add(section, new MeasureOverride());
var ovr = _overrides[section];
var msg = new string[0];
switch (setting) {
case "Use AdKats punish":
ovr.NoAdKats = strValue != yes;
return;
case "Severity":
ovr.Severity = Convert.ToSingle(strValue.Replace(',', '.'), CultureInfo.InvariantCulture.NumberFormat);
return;
case "Measure":
ovr.MinimumAction = (BadwordAction)Enum.Parse(typeof(BadwordAction), CPluginVariable.Decode(strValue));
break;
case "Allow higher measures":
ovr.AlwaysUseMinAction = strValue != yes;
return;
case "Minimum counter afterwards":
ovr.MinimumCounter = Convert.ToSingle(strValue.Replace(',', '.'), CultureInfo.InvariantCulture.NumberFormat) - 1;
return;
case "Public message":
msg = CPluginVariable.DecodeStringArray(strValue);
if (msg.Length == 1 && string.IsNullOrEmpty(msg[0]))
msg = null;
ovr.PublicMessage = msg;
break;
case "Private message":
msg = CPluginVariable.DecodeStringArray(strValue);
if (msg.Length == 1 && string.IsNullOrEmpty(msg[0]))
msg = null;
ovr.PrivateMessage = msg;
break;
case "Yell message":
msg = CPluginVariable.DecodeStringArray(strValue);
if (msg.Length == 1 && string.IsNullOrEmpty(msg[0]))
msg = null;
ovr.YellMessage = msg;
break;
case "Command":
msg = CPluginVariable.DecodeStringArray(strValue);
if (msg.Length == 1 && string.IsNullOrEmpty(msg[0]))
msg = null;
ovr.Command = msg;
break;
case "Yell time (sec.)":
uint data1;
if (uint.TryParse(strValue, out data1))
ovr.YellTime = data1;
else
ovr.YellTime = null;
return;
case "TBan minutes":
case "Mute minutes":
uint data2;
if (uint.TryParse(strValue, out data2))
ovr.TBanTime = data2;
else
ovr.TBanTime = null;
return;
}
if (ovr.MinimumAction == BadwordAction.ListEnd)
ovr.MinimumAction = BadwordAction.Warn;
}
}
private void WriteBadwords(string setting, bool isRegex) {
var words = string.IsNullOrEmpty(setting) ? new string[0] : CPluginVariable.DecodeStringArray(setting);
if (isRegex) {
if (_failPrevent.IsMatch(setting)) {
WriteLog("LanguageEnforcer: prevented regex messup. PLEASE CHECK YOUR SETTINGS!");
return;
}
if ((DateTime.Now - _startup).TotalSeconds < 5)
return;
RegexBadwords = words;
}
else {
_badwordsCache = words;
_badwords = CreateSections(words, false).ToArray();
}
CheckForWordlistDuplicates();
try {
File.WriteAllLines(PluginFolder + (isRegex ? "regexbadwords.txt" : "badwords.txt"), words);
}
catch {
WriteLog("^bLanguage Enforcer^2: Couldn't save badwords. Please make sure filesystem access is granted");
}
}
private IEnumerable<string> CreateSections(IEnumerable<string> words, bool isRegex) {
if (isRegex)
_regexBadwordSection.Clear();
else
_badwordSection.Clear();
var r = new Regex("^{\\w+}$");
string key = null;
foreach (var word in words.Where(word => !string.IsNullOrEmpty(word))) {
if (r.IsMatch(word)) {
key = word.Substring(1, word.Length - 2);
continue;
}
if (key != null)
try {
if (isRegex)
_regexBadwordSection.Add(word.IndexOf('#') >= 0 ? word.Substring(0, word.IndexOf('#')) : word, key);
else
_badwordSection.Add(word, key);
}
catch (ArgumentException exc) {
} // duplicate key
yield return word;
}
}
protected override void WriteCounters() {
try {
File.WriteAllLines(PluginFolder + "LangEnforcerCounters.txt", Players.Select(pair => string.Join(" ", pair.Key, pair.Value.Heat.ToString("0.0000", CultureInfo.InvariantCulture), pair.Value.LastAction.Ticks.ToString(), pair.Value.Guid)).ToArray());
}
catch {
WriteLog("^bLanguage Enforcer^2: Couldn't save counters. Please make sure filesystem access is granted");
}
}
protected override void LoadCounters() {
try {
Players.Clear();
var data = File.ReadAllLines(PluginFolder + "LangEnforcerCounters.txt");
foreach (var tokens in data.Select(line => line.Split(' '))) {