-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSAMSiteAuth.cs
More file actions
74 lines (63 loc) · 2.28 KB
/
SAMSiteAuth.cs
File metadata and controls
74 lines (63 loc) · 2.28 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
using System.Collections.Generic;
using static BaseVehicle;
namespace Oxide.Plugins
{
[Info("SAMSiteAuth", "haggbart", "2.4.4")]
[Description("Makes SAM Sites act in a similar fashion to shotgun traps and flame turrets.")]
internal class SAMSiteAuth : RustPlugin
{
private readonly object True = true;
private object OnSamSiteTarget(SamSite samSite, BaseCombatEntity target)
{
var mountPoints = (target as BaseVehicle)?.mountPoints;
if (!IsOccupied(target, mountPoints))
return True;
if (samSite.staticRespawn)
return null;
var cupboard = samSite.GetBuildingPrivilege(samSite.WorldSpaceBounds());
if ((object)cupboard == null)
return null;
if (mountPoints != null)
{
foreach (var mountPoint in mountPoints)
{
var player = mountPoint.mountable.GetMounted();
if ((object)player != null && IsAuthed(cupboard, player.userID))
return True;
}
}
foreach (var child in target.children)
{
var player = child as BasePlayer;
if ((object)player != null)
{
if (IsAuthed(cupboard, player.userID))
return True;
}
}
return null;
}
private static bool IsOccupied(BaseCombatEntity entity, List<MountPointInfo> mountPoints)
{
if (mountPoints != null)
{
foreach (var mountPoint in mountPoints)
{
var player = mountPoint.mountable.GetMounted();
if ((object)player != null)
return true;
}
}
foreach (var child in entity.children)
{
if (child is BasePlayer)
return true;
}
return false;
}
private static bool IsAuthed(BuildingPrivlidge cupboard, ulong userId)
{
return cupboard.authorizedPlayers.Contains( userId );
}
}
}