-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAntiNoobRaid.cs
2733 lines (2326 loc) · 110 KB
/
AntiNoobRaid.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
using Oxide.Core;
using System;
using System.Collections.Generic;
using Oxide.Core.Plugins;
using Oxide.Core.Libraries.Covalence;
using Rust;
using UnityEngine;
using Newtonsoft.Json;
using System.Linq;
/*========================================================*
* *
* *************************************************** *
* *Original author : Slydelix on versions <1.8.5 * *
* *Maintainer(s) : RustySpoon342 from v1.8.6 * *
* *************************************************** *
* *
* Patch Submissions : Nivex on versions 1.8.9, 1.9.0 *
* *
*=========================================================*/
namespace Oxide.Plugins
{
[Info("AntiNoobRaid", "MasterSplinter", "2.1.1", ResourceId = 2697)]
class AntiNoobRaid : RustPlugin
{
[PluginReference] private Plugin PlaytimeTracker, WipeProtection, Clans, StartProtection;
//Pre-release Version Number
private bool beta = false;
private string betaversion = "0.0.6";
private List<BasePlayer> cooldown = new List<BasePlayer>();
private List<BasePlayer> MessageCooldown = new List<BasePlayer>();
private List<ulong> LeaderLower = new List<ulong>();
private List<BuildingBlock> _blocks = new List<BuildingBlock>();
private Timer CheckingPT;
private Timer CheckingC;
//private Dictionary<ulong, Timer> RaidTimerDictionary = new Dictionary<ulong, Timer>();
private Dictionary<string, string> raidtools = new Dictionary<string, string>
{
{"ammo.rocket.fire", "rocket_fire" },
{"ammo.rocket.hv", "rocket_hv" },
{"ammo.rocket.basic", "rocket_basic" },
{"ammo.rocket.smoke", "rocket_smoke" },
{"explosive.timed", "explosive.timed.deployed" },
{"surveycharge", "survey_charge.deployed" },
{"explosive.satchel", "explosive.satchel.deployed" },
{"grenade.beancan", "grenade.beancan.deployed" },
{"grenade.f1", "grenade.f1.deployed" },
{"ammo.grenadelauncher.he", "40mm_grenade_he" },
{"ammo.rifle", "riflebullet" },
{"ammo.rifle.explosive", "riflebullet_explosive" },
{"ammo.rifle.incendiary", "riflebullet_fire" },
{"ammo.pistol", "pistolbullet" },
{"ammo.pistol.fire", "pistolbullet_fire" },
{"ammo.shotgun", "shotgunbullet" },
{"ammo.shotgun.fire", "shotgunbullet_fire" },
{"ammo.shotgun.slug", "shotgunslug" },
{"ammo.rocket.mlrs", "rocket_mlrs" },
{"arrow.wooden", "arrow_wooden" },
{"arrow.hv", "arrow_hv" },
{"arrow.fire", "arrow_fire" },
{"arrow.bone", "arrow_bone" }
};
private Dictionary<string, string> RaidToolsCheck = new Dictionary<string, string>
{
{"ammo.rocket.fire", "rocket_fire" },
{"ammo.rocket.hv", "rocket_hv" },
{"ammo.rocket.basic", "rocket_basic" },
{"ammo.rocket.smoke", "rocket_smoke" },
{"explosive.timed", "explosive.timed.deployed" },
{"surveycharge", "survey_charge.deployed" },
{"explosive.satchel", "explosive.satchel.deployed" },
{"grenade.beancan", "grenade.beancan.deployed" },
{"grenade.f1", "grenade.f1.deployed" },
{"ammo.grenadelauncher.he", "40mm_grenade_he" },
{"ammo.grenadelauncher.buckshot", "shotgunbullet" },
{"ammo.rifle", "riflebullet" },
{"ammo.rifle.hv", "riflebullet" },
{"ammo.pistol", "pistolbullet" },
{"ammo.pistol.hv", "pistolbullet" },
{"ammo.shotgun", "shotgunbullet" },
{"ammo.shotgun.slug", "shotgunslug" },
{"ammo.handmade.shell", "handmade_shell.projectile" },
{"ammo.rocket.mlrs", "rocket_mlrs" },
{"ammo.nailgun.nails", "nailgun.entity" },
{"flamethrower", "flamethrower.entity" },
{"arrow.wooden", "arrow_wooden" },
{"arrow.hv", "arrow_hv" },
{"arrow.bone", "arrow_bone" },
{"spear.stone","spear_stone.entity" },
{"speargun.spear","speargun_spear" },
{"spear.wooden", "spear_wooden.entity" },
{"knife.bone", "knife_bone.entity" },
{"bone.club", "bone_club.entity" },
{"knife.butcher", "butcherknife.entity" },
{"machete", "machete.weapon" },
{"knife.combat", "knife.combat.entity" },
{"longsword", "longsword.entity" },
{"mace", "mace.entity" },
{"paddle", "paddle.entity" },
{"pitchfork", "pitchfork.entity" },
{"salvaged.cleaver", "salvaged_cleaver.entity" },
{"salvaged.sword", "salvaged_sword.entity" },
{"hatchet", "hatchet.entity" },
{"pickaxe", "pickaxe.entity" },
{"axe.salvaged", "axe_salvaged.entity" },
{"hammer.salvaged", "hammer_salvaged.entity" },
{"icepick.salvaged", "icepick_salvaged.entity" },
{"stonehatchet", "stonehatchet.entity" },
{"stone.pickaxe", "stone_pickaxe.entity" },
{"rock", "rock.entity" },
{"skull", "skull.entity" },
{"jackhammer", "jackhammer.entity" }
};
private Dictionary<string, string> NotSupportedRaidTools = new Dictionary<string, string>
{
{"ammo.rifle.explosive", "riflebullet_explosive" },
{"ammo.rifle.incendiary", "riflebullet_fire" },
{"ammo.pistol.fire", "pistolbullet_fire" },
{"ammo.shotgun.fire", "shotgunbullet_fire" },
{"flamethrower", "flamethrower.entity" },
{"snowball", "snowballgunbullet" },
{"arrow.fire", "arrow_fire" }
};
private int layers = LayerMask.GetMask("Construction", "Deployed");
private readonly string AdminPerm = "antinoobraid.admin";
private readonly string NoobPerm = "antinoobraid.noob";
#region Config
private class ConfigFile
{
[JsonProperty(PropertyName = "Main Settings")]
public MainSettings Main = new MainSettings();
[JsonProperty(PropertyName = "Other Settings")]
public OtherSettings Other = new OtherSettings();
[JsonProperty(PropertyName = "Team & Clan Settings")]
public RelationshipSettings Relationship = new RelationshipSettings();
[JsonProperty(PropertyName = "Refund Settings")]
public RefundSettings Refund = new RefundSettings();
[JsonProperty(PropertyName = "Manage Messages")]
public ManageMessages Messages = new ManageMessages();
[JsonProperty(PropertyName = "Entity Settings")]
public EntitySettings Entity = new EntitySettings();
[JsonProperty(PropertyName = "Weapon Settings")]
public WeaponSettings RaidTools = new WeaponSettings();
[JsonProperty(PropertyName = "Advance Settings")]
public AdvanceSettings Advance = new AdvanceSettings();
public static readonly ConfigFile DefaultConfigFile = new ConfigFile();
}
public class MainSettings
{
[JsonProperty("Time (seconds) after which noob will lose protection (in-game time)")]
public int ProtectionTime = 43200;
[JsonProperty("Days of inactivity after which player will be raidable")]
public double InactivityRemove = 3;
[JsonProperty("Remove noob status of a raider on raid attempt")]
public bool UnNoobNew = true;
[JsonProperty("Remove noob status of a raider who is manually marked as a noob on raid attempt")]
public bool UnNoobManual = true;
}
public class OtherSettings
{
[JsonProperty("Allow Patrol Helicopter to damage noob structures (This will allow players to raid noobs with Patrol Helicopter)")]
public bool PatrolHeliDamage = true;
[JsonProperty("Ignore twig when calculating base ownership (prevents exploiting)")]
public bool IgnoreTwig = true;
[JsonProperty("Check full ownership of the base instead of only one block")]
public bool CheckFullOwnership = true;
[JsonProperty("Kill fireballs when someone tries to raid protected player with fire (prevents lag)")]
public bool KillFire = true;
[JsonProperty("Clear Player Data on Map-Wipe")]
public bool MapWipe = false;
}
public class RelationshipSettings
{
[JsonProperty("Enable 'Clan' Support (Allow clan members to destroy each others entities & Remove protection from clan members when a member tries to raid)")]
public bool CheckClan = true;
[JsonProperty("Enable 'Team' Support (Allow team members to destroy each others entities & Remove protection from team members when a member tries to raid)")]
public bool CheckTeam = true;
[JsonProperty("Enable 'Team' playtime sync (Sync's all player's within a team to the highest playtime)")]
public bool SyncTeamPlaytime = true;
}
public class RefundSettings
{
[JsonProperty("Refund explosives")]
public bool RefundItem = true;
[JsonProperty("Refunds before player starts losing explosives")]
public int RefundTimes = 4;
}
public class ManageMessages
{
[JsonProperty("Notify player on first connection with protection time")]
public bool MessageOnFirstConnection = true;
[JsonProperty("Use game tips to send most messages to players")]
public bool UseGT = false;
[JsonProperty("Show message for not being able to raid")]
public bool ShowMessage = true;
[JsonProperty("Show time until raidable")]
public bool ShowTime = false;
[JsonProperty("Show time until raidable only to owners")]
public bool ShowOwnerTime = true;
[JsonProperty("Show message on first Twig placement that Twig is not protected")]
public bool ShowMessageTwig = true;
}
public class EntitySettings
{
[JsonProperty("List of entities that can be destroyed even if owner is noob")]
public Dictionary<string, string> AllowedEntities = AllowedEntitiesDictionary;
[JsonProperty("List of entities that can be destroyed without losing noob protection")]
public Dictionary<string, string> AllowedEntitiesNoob = AllowedEntitiesNoobDictionary;
public static Dictionary<string, string> AllowedEntitiesDictionary = new Dictionary<string, string>
{
{"ShortPrefabName", "Common Name"}, {"beartrap", "Snap Trap"}, {"landmine", "Landmine"},
};
public static Dictionary<string, string> AllowedEntitiesNoobDictionary = new Dictionary<string, string>
{
{"ShortPrefabName", "Common Name"}, {"campfire", "Camp Fire"},
};
}
public class WeaponSettings
{
[JsonProperty("List of Weapons/Tools that won't trigger player to lose noob protection")]
public Dictionary<string, string> AllowedRaidTools = AllowedRaidToolsDictionary;
public static Dictionary<string, string> AllowedRaidToolsDictionary = new Dictionary<string, string>
{
{"ShortPrefabName", "Common Name"}, {"rocket_smoke", "Smoke Rocket WIP!!!!"},
};
}
public class AdvanceSettings
{
[JsonProperty("User data refresh interval (seconds)")]
public int Frequency = 30;
[JsonProperty("Save interval (seconds)")]
public int SaveFrequency = 60;
[JsonProperty("Save data on Server Save")]
public bool OnServerSave = true;
[JsonProperty("Show structure has no owner in console")]
public bool ShowNoOwnerBase = false;
[JsonProperty("Enable Logs (Logs can be found in /oxide/logs/antinoobraid)")]
public bool EnableLogging = true;
}
private ConfigFile config;
protected override void LoadDefaultConfig()
{
Config.Clear();
PrintWarning("Creating new config file");
NextTick(() => Config.WriteObject(config));
SaveConfig();
}
#endregion
#region Lang
protected override void LoadDefaultMessages()
{
lang.RegisterMessages(new Dictionary<string, string>()
{
{"NoPlayerFound", "Couldn't find '{0}'"},
{"NotNumber", "{0} is not a number" },
{"antinoobcmd_syntax", "Wrong syntax! /antinoob <addnoob|removenoob|wipe>" },
{"antinoobcmd_addnoob_syntax", "Wrong syntax! /antinoob addnoob <name/steamid>" },
{"antinoobcmd_alreadynoob", "{0} is already marked as a noob" },
{"antinoobcmd_marked", "Marked {0} as a noob" },
{"antinoobcmd_removenoob_syntax", "Wrong syntax! /antinoob removenoob <name/steamid>" },
{"antinoobcmd_removednoob", "{0} does not have a noob status anymore" },
{"antinoobcmd_missingnoob", "{0} is not a noob" },
{"antinoobcmd_wipe_syntax", "Missing argument! <all|playerdata|attempts>" },
{"dataFileWiped", "Data file successfully wiped"},
{"dataFileWiped_attempts", "Data file successfully wiped (raid attempts)"},
{"dataFileWiped_playerdata", "Data file successfully wiped (player data)"},
{"struct_noowner","Structure at {0} has no owner! OwnerID = {1} buildingID = {2}" },
{"clan_lostnoob" , "Clan '{0}' lost their noob status because they tried to raid" },
{"lost_teamsprotection" , "You lost your team noob protection for damaging a structure" },
{"lost_clansprotection" , "You lost your clan noob protection for damaging a structure" },
{"new_user_lostprotection" , "You lost your noob protection for damaging a structure" },
{"console_lostnoobstatus", "{0} hasn't connected for {1} days so he lost his noob status (can be raided)"},
{"console_notenough", "{0} doesn't have enough hours in game to be marked as a non-noob"},
{"firstconnectionmessage", "You are a new player so your buildings are protected for first {0} hours of your time on server"},
{"pt_notInstalled", "Playtime Tracker is not installed, will check again in 15 seconds!"},
{"pt_detected", "Playtime Tracker detected"},
{"C_notInstalled", "Clans is not installed, will check again in 15 seconds!"},
{"C_detected", "Clans detected"},
{"userinfo_nofound", "Failed to get playtime info for {0}! trying again in 300 seconds!"},
{"userinfo_nofound_2nd_attempt", "Failed to get playtime info for {0}! Has been marked as non-noob!"},
{"userinfo_found", "Successfully got playtime info for {0}!"},
{"twig_can_attack", "This structure is Twig & is not raid protected. Please upgrade to Wood or higer for protection!"},
{"can_attack", "This structure is not raid protected"},
{"NotLooking", "You are not looking at a building/deployable"},
{"refunditem_help", "Wrong Syntax! /refunditem add <you have to hold the item you want to add>\n/refunditem remove <you have to hold the item you want to remove>\n/refunditem list\n/refunditem clear\n/refunditem all <sets all raid tools as refundable>"},
{"refunditem_needholditem", "You need to hold the item you want to add/remove from refund list"},
{"refunditem_notexplosive", "This item is not an explosive"},
{"refunditem_added", "Added '{0}' to list of items to refund"},
{"refunditem_alreadyonlist", "This item is already on the list"},
{"refunditem_notonlist", "This item is not on the list"},
{"refunditem_removed", "Removed '{0}' from the list of items to refund"},
{"refunditem_addedall", "Added all raid tools to refund list"},
{"refunditem_cleared", "Cleared list of items to refund"},
{"refunditem_empty", "There are no item set up yet"},
{"refunditem_list", "List of items which will get refunded: \n{0}"},
{"refund_free", "Your '{0}' was refunded."},
{"refund_last", "Your '{0}' was refunded but will not be next time."},
{"refund_1time", "Your '{0}' was refunded. After 1 more attempt it wont be refunded."},
{"refund_nTimes", "Your '{0}' was refunded. After {1} more attempts it wont be refunded"},
{"cannot_attack_no_time", "This entity cannot be destroyed because it was built by a new player"},
{"cannot_attack_time", "This entity cannot be destroyed because it was built by a new player ({0})"},
{"looking_item", "The entity name is {0}"},
{"notlooking_item", "You need to look at a deployed item to get the name!"},
{"holding_item", "The items name is {0}"},
{"notholding_item", "You need to hold a Raiding Tool to get the name!"},
{"Not_Supported", "This Raiding Tool is not supported for \"Weapon Settings\"!"},
{"Increase_Refresh", "Increase \"User data refresh interval\" in the Config and reload! Can't be less or equal than 10 seconds." },
{"secs", " seconds"},
{"mins", " minutes"},
{"min", " minute"},
{"hours", " hours"},
{"hour", " hour"},
{"day", " day"},
{"days", " days"}
}, this);
}
#endregion
#region DataFile/Classes
private class BuildingInfo
{
public static HashSet<BuildingInfo> buildCache = new HashSet<BuildingInfo>();
public BuildingInfo() { }
public uint buildingID;
public ulong OwnerID;
public DateTime lastUpdate;
public static BuildingInfo GetByBuildingID(uint bID)
{
foreach (var entry in buildCache)
if (entry.buildingID == bID) return entry;
return null;
}
public double GetCacheAge()
{
if (lastUpdate == null) return -1;
return DateTime.UtcNow.Subtract(lastUpdate).TotalSeconds;
}
}
private class ClanInfo
{
public static HashSet<ClanInfo> clanCache = new HashSet<ClanInfo>();
public ClanInfo() { }
public static ClanInfo FindClanByName(string clanName)
{
foreach (var clan in ClanInfo.clanCache)
if (clan.clanName == clanName) return clan;
return null;
}
public static ClanInfo GetClanOf(ulong playerID)
{
foreach (var clan in ClanInfo.clanCache)
if (clan.members.Contains(playerID)) return clan;
return null;
}
public string clanName { get; set; }
public List<ulong> members = new List<ulong>();
}
private class StoredData
{
public Dictionary<ulong, double> players = new Dictionary<ulong, double>();
public Dictionary<ulong, int> AttackAttempts = new Dictionary<ulong, int>();
public List<ulong> playersWithNoData = new List<ulong>();
public List<ulong> FirstMessaged = new List<ulong>();
public List<ulong> InTeam = new List<ulong>();
public List<ulong> ShowTwigsNotProtected = new List<ulong>();
public Dictionary<ulong, string> lastConnection = new Dictionary<ulong, string>();
public List<ulong> IgnoredPlayers = new List<ulong>();
public StoredData()
{
}
}
private class StoredDataItemList
{
public Dictionary<string, string> ItemList = new Dictionary<string, string>();
public StoredDataItemList()
{
}
}
private void SaveData() => Interface.Oxide.DataFileSystem.WriteObject($"{this.Name}\\{this.Name}_Data", storedData);
private void SaveDataItemList() => Interface.Oxide.DataFileSystem.WriteObject($"{this.Name}\\{this.Name}_RefundItemList", storedDataItemList);
StoredData storedData;
StoredDataItemList storedDataItemList;
#endregion
#region Setup/Saving
private void Init()
{
permission.RegisterPermission(AdminPerm, this);
permission.RegisterPermission(NoobPerm, this);
storedData = Interface.Oxide.DataFileSystem.ReadObject<StoredData>($"{this.Name}\\{this.Name}_Data");
storedDataItemList = Interface.Oxide.DataFileSystem.ReadObject<StoredDataItemList>($"{this.Name}\\{this.Name}_RefundItemList");
config = Config.ReadObject<ConfigFile>();
Unsubscribe(nameof(OnEntityDeath));
Unsubscribe(nameof(OnEntityKill));
Unsubscribe(nameof(OnEntitySpawned));
Unsubscribe(nameof(OnEntityTakeDamage));
//if (config.AutoMinutes <= 0 && config.AutoAddProtection) PrintError("Time (minutes) after which the raided person gains raid protection is set to 0!!! Change this!!");
}
private void RegisterCommands()
{
foreach (var command in AdminCommands)
AddCovalenceCommand(command.Key, command.Value, AdminPerm);
}
private void OnServerInitialized(bool isStartup) // Reminder use this hook instead of Loaded(). Thanks Nivex
{
foreach (var block in BaseEntity.saveList.OfType<BuildingBlock>()) _blocks.Add(block);
Subscribe(nameof(OnEntityDeath));
Subscribe(nameof(OnEntityKill));
Subscribe(nameof(OnEntitySpawned));
Subscribe(nameof(OnEntityTakeDamage));
RegisterCommands();
foreach (var entry in storedData.players.Where(x => !storedData.lastConnection.ContainsKey(x.Key)))
storedData.lastConnection.Add(entry.Key, string.Empty);
StartChecking();
CheckPlayersWithNoInfo();
if (!config.Advance.OnServerSave)
{
float args = config.Advance.SaveFrequency;
int offset = (int) args;
timer.Every(offset, SaveData);
}
if (beta) PrintWarning($"Debug Version: {betaversion}");
if (config.Advance.Frequency <= 10)
{
timer.Every(15f, () =>
{
PrintWarning(lang.GetMessage("Increase_Refresh", this, null));
});
}
if (PlaytimeTracker == null)
{
PrintWarning(lang.GetMessage("pt_notInstalled", this, null));
CheckingPT = timer.Every(15f, () =>
{
if (PlaytimeTracker == null)
{
PrintWarning(lang.GetMessage("pt_notInstalled", this, null));
}
else
{
PrintWarning(lang.GetMessage("pt_detected", this, null));
timer.Destroy(ref CheckingPT);
}
});
}
if (config.Relationship.CheckClan && Clans != null)
{
timer.Every(60f, RefreshClanCache);
}
if (config.Relationship.CheckClan && Clans == null)
{
PrintWarning(lang.GetMessage("C_notInstalled", this, null));
CheckingC = timer.Every(15f, () =>
{
if (Clans == null)
{
PrintWarning(lang.GetMessage("C_notInstalled", this, null));
}
else
{
PrintWarning(lang.GetMessage("C_detected", this, null));
timer.Destroy(ref CheckingC);
}
});
}
}
private void Unload()
{
LeaderLower.Clear();
SaveData();
SaveDataItemList();
}
private void OnServerSave()
{
if (config.Advance.OnServerSave) timer.Once(UnityEngine.Random.Range(5, 15), SaveData);
}
private void OnNewSave()
{
if (config.Other.MapWipe == true)
{
storedData.players.Clear();
storedData.IgnoredPlayers.Clear();
storedData.lastConnection.Clear();
storedData.ShowTwigsNotProtected.Clear();
storedData.InTeam.Clear();
storedData.FirstMessaged.Clear();
storedData.playersWithNoData.Clear();
storedData.AttackAttempts.Clear();
SaveData();
PrintWarning("New savefile detected. All Player Data was cleared!");
}
}
#endregion
#region Commands
private Dictionary<string, string> AdminCommands = new Dictionary<string, string>
{
{ "antinoob", "AntiNoobCommand" },
{ "checkname", "CheckNameCmd" },
{ "refunditem", "RefundCmd" },
};
private void AntiNoobCommand(IPlayer player, string command, string[] args)
{
if (args.Length < 1)
{
player.Reply(lang.GetMessage("antinoobcmd_syntax", this, player.Id));
return;
}
switch (args[0].ToLower())
{
case "addnoob":
{
if (args.Length < 2)
{
player.Reply(lang.GetMessage("antinoobcmd_addnoob_syntax", this, player.Id));
return;
}
var p = covalence.Players.FindPlayer(args[1]);
if (p == null)
{
player.Reply(lang.GetMessage("NoPlayerFound", this, player.Id), null, args[1]);
return;
}
foreach (var entry in storedData.players)
{
if (entry.Key == ulong.Parse(p.Id))
{
if (storedData.players[entry.Key] == -25d)
{
player.Reply(lang.GetMessage("antinoobcmd_alreadynoob", this, player.Id), null, p.Name);
return;
}
storedData.players[entry.Key] = -25d;
player.Reply(lang.GetMessage("antinoobcmd_marked", this, player.Id), null, p.Name);
return;
}
}
player.Reply(lang.GetMessage("NoPlayerFound", this, player.Id), null, args[1]);
return;
}
case "removenoob":
{
if (args.Length < 2)
{
player.Reply(lang.GetMessage("antinoobcmd_removenoob_syntax", this, player.Id));
return;
}
var p = covalence.Players.FindPlayer(args[1]);
if (p == null)
{
player.Reply(lang.GetMessage("NoPlayerFound", this, player.Id), null, args[1]);
}
foreach (var entry in storedData.players)
{
if (entry.Key == ulong.Parse(p.Id))
{
if (storedData.players[entry.Key] == -50d)
{
player.Reply(lang.GetMessage("antinoobcmd_missingnoob", this, player.Id), null, p.Name);
return;
}
storedData.players[entry.Key] = -50d;
player.Reply(lang.GetMessage("antinoobcmd_removednoob", this, player.Id), null, p.Name);
return;
}
}
player.Reply(lang.GetMessage("NoPlayerFound", this, player.Id), null, args[1]);
return;
}
case "wipe":
{
if (args.Length < 2)
{
player.Reply(lang.GetMessage("antinoobcmd_wipe_syntax", this, player.Id));
return;
}
switch (args[1].ToLower())
{
case "all":
{
storedData.lastConnection.Clear();
storedData.playersWithNoData.Clear();
storedData.FirstMessaged.Clear();
storedData.AttackAttempts.Clear();
storedDataItemList.ItemList.Clear();
storedData.players.Clear();
player.Reply(lang.GetMessage("dataFileWiped", this, player.Id));
return;
}
case "playerdata":
{
storedData.players.Clear();
player.Reply(lang.GetMessage("dataFileWiped_playerdata", this, player.Id));
return;
}
case "attempts":
{
storedData.AttackAttempts.Clear();
player.Reply(lang.GetMessage("dataFileWiped_attempts", this, player.Id));
return;
}
default:
{
player.Reply(lang.GetMessage("antinoobcmd_wipe_syntax", this, player.Id));
return;
}
}
}
default:
{
player.Reply(lang.GetMessage("antinoobcmd_syntax", this, player.Id));
return;
}
}
}
[ChatCommand("checknew")]
private void CheckNewCmd(BasePlayer player, string command, string[] args)
{
BaseEntity hitEnt = GetLookAtEntity(player);
if (hitEnt == null)
{
SendReply(player, lang.GetMessage("NotLooking", this, player.UserIDString));
return;
}
if (config.Messages.ShowMessage && config.Other.IgnoreTwig && (hitEnt as BuildingBlock)?.grade == BuildingGrade.Enum.Twigs)
{
SendReply(player, lang.GetMessage("twig_can_attack", this, player.UserIDString));
return;
}
ulong owner = config.Other.CheckFullOwnership ? FullOwner(hitEnt) : hitEnt.OwnerID;
if (owner == 0u || !storedData.players.ContainsKey(owner)) return;
MessagePlayer(player, owner);
}
[ChatCommand("entdebug")]
private void EntDebugCmd(BasePlayer player, string command, string[] args)
{
if (!player.IsAdmin) return;
BaseEntity ent = GetLookAtEntity(player);
if (ent == null)
{
SendReply(player, "No entity");
return;
}
var ownerid = (FullOwner(ent) != 0) ? FullOwner(ent) : ent.OwnerID;
if (args.Length < 1)
{
SendReply(player, "OwnerID: " + ent.OwnerID);
SendReply(player, "FullOwner: " + FullOwner(ent));
if (storedData.players.ContainsKey(ownerid))
{
var tiem = (int)storedData.players[ownerid];
switch (tiem)
{
case -25:
{
SendReply(player, "Time: -25d (manually set noob)");
break;
}
case -50:
{
SendReply(player, "Time: -50d (damaged structure, clan lost protection, inactive)");
break;
}
default:
{
SendReply(player, "Time: " + tiem + " ('natural' time)");
if (tiem >= config.Main.ProtectionTime) SendReply(player, "Should be raidable");
else SendReply(player, "Shouldn't be raidable");
break;
}
}
}
else SendReply(player, "StoredData does not contain info for " + ownerid);
return;
}
var t = ulong.Parse(args[0]);
ent.OwnerID = t;
ent.SendNetworkUpdate();
SendReply(player, "Set OwnerID: " + ent.OwnerID);
return;
}
private void CheckNameCmd(IPlayer p, string command, string[] args)
{
BasePlayer player = p.Object as BasePlayer;
BaseEntity hitEnt = GetLookAtEntity(player);
Item helditem = player.GetActiveItem();
if (player == null) return;
if (args.Length < 1)
{
return;
}
switch (args[0].ToLower())
{
case "looking":
{
if (hitEnt == null)
{
p.Reply(lang.GetMessage("notlooking_item", this, p.Id));
return;
}
if (hitEnt != null)
{
p.Reply(lang.GetMessage("looking_item", this, player.UserIDString), null, hitEnt);
return;
}
return;
}
case "holding":
{
if (helditem == null)
{
p.Reply(lang.GetMessage("notholding_item", this, p.Id));
return;
}
if (NotSupportedRaidTools.ContainsKey(helditem.info.shortname))
{
p.Reply(lang.GetMessage("Not_Supported", this, p.Id));
return;
}
if (RaidToolsCheck.ContainsKey(helditem.info.shortname))
{
p.Reply(lang.GetMessage("holding_item", this, player.UserIDString), null, RaidToolsCheck[helditem.info.shortname]);
return;
}
else
{
p.Reply(lang.GetMessage("notholding_item", this, p.Id));
return;
}
}
}
}
private void RefundCmd(IPlayer p, string command, string[] args)
{
BasePlayer player = p.Object as BasePlayer;
if (player == null) return;
if (args.Length < 1)
{
p.Reply(lang.GetMessage("refunditem_help", this, p.Id));
return;
}
Item helditem = player.GetActiveItem();
switch (args[0].ToLower())
{
case "add":
{
if (player.GetActiveItem() == null)
{
p.Reply(lang.GetMessage("refunditem_needholditem", this, player.UserIDString));
return;
}
if (raidtools.ContainsKey(helditem.info.shortname))
{
if (!storedDataItemList.ItemList.ContainsKey(helditem.info.shortname))
{
storedDataItemList.ItemList.Add(helditem.info.shortname, raidtools[helditem.info.shortname]);
p.Reply(lang.GetMessage("refunditem_added", this, player.UserIDString), null, helditem.info.displayName.english);
return;
}
p.Reply(lang.GetMessage("refunditem_alreadyonlist", this, player.UserIDString));
return;
}
p.Reply(lang.GetMessage("refunditem_notexplosive", this, player.UserIDString));
SaveDataItemList();
return;
}
case "remove":
{
if (player.GetActiveItem() == null)
{
p.Reply(lang.GetMessage("refunditem_needholditem", this, player.UserIDString));
return;
}
if (storedDataItemList.ItemList.ContainsKey(helditem.info.shortname))
{
storedDataItemList.ItemList.Remove(helditem.info.shortname);
p.Reply(lang.GetMessage("refunditem_removed", this, player.UserIDString), null, helditem.info.displayName.english);
return;
}
p.Reply(lang.GetMessage("refunditem_notonlist", this, player.UserIDString));
SaveDataItemList();
return;
}
case "all":
{
foreach (var t in raidtools)
if (!storedDataItemList.ItemList.ContainsKey(t.Key)) storedDataItemList.ItemList.Add(t.Key, t.Value);
p.Reply(lang.GetMessage("refunditem_addedall", this, player.UserIDString));
SaveDataItemList();
return;
}
case "clear":
{
storedDataItemList.ItemList.Clear();
p.Reply(lang.GetMessage("refunditem_cleared", this, player.UserIDString));
SaveDataItemList();
return;
}
case "list":
{
if (storedDataItemList.ItemList.Count < 1)
{
p.Reply(lang.GetMessage("refunditem_empty", this, player.UserIDString));
return;
}
List<string> T2 = new List<string>();
foreach (var entry in storedDataItemList.ItemList)
{
Item item = ItemManager.CreateByName(entry.Key, 1);
if (item.info.displayName.english == null)
LogToFile("other", "Failed to find display name for " + entry.Key, this, true);
T2.Add(item?.info?.displayName?.english);
}
string final = string.Join("\n", T2.ToArray());
p.Reply(lang.GetMessage("refunditem_list", this, player.UserIDString), null, final);
return;
}
default:
{
p.Reply(lang.GetMessage("refunditem_help", this, player.UserIDString));
return;
}
}
}
#endregion
#region Rust/uMod Hooks
private object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitinfo)
{
var owner = config.Other.CheckFullOwnership ? FullOwner(entity) : entity.OwnerID;
BasePlayer attacker = hitinfo.InitiatorPlayer;
var dmgType = hitinfo?.damageTypes?.GetMajorityDamageType() ?? DamageType.Generic;
string name = CheckForRaidingTools(hitinfo);
if (hitinfo == null || entity == null || attacker == null || owner == 0) return null; //null checks
if (!entity.OwnerID.IsSteamId() || !attacker.userID.IsSteamId()) return null;
if (entity?.OwnerID == attacker?.userID) return null;
if (dmgType == DamageType.Decay || dmgType == DamageType.Generic || dmgType == DamageType.Bite || dmgType == DamageType.Fun_Water) return null;
if (entity.OwnerID == 0u || CheckForBuildingOrDeployable(entity, hitinfo) == false) return null;
if (HasProtection(attacker) == true) return null;
if (config.Other.IgnoreTwig && (entity as BuildingBlock)?.grade == BuildingGrade.Enum.Twigs) return null;
if (CheckForHelicopterOrMLRS(entity, hitinfo) == true) return null;
if (NullWeaponCheck(entity, hitinfo) == true) return null;