C#:
using System.Collections.Generic;
using Oxide.Core.Plugins;
namespace Oxide.Plugins;
[Info("FClanTurretAuth", "fufeldev", "1.0.0")]
public class FClanTurretAuth : RustPlugin
{
[PluginReference] private Plugin SClan;
private void OnServerInitialized()
{
AuthorizeAll();
}
private void OnPluginLoaded(Plugin plugin)
{
if (plugin != null && plugin.Name == "SClan") timer.Once(1f, AuthorizeAll);
}
private void OnClanMemberJoined(string userID, string clanTag)
{
timer.Once(1f, AuthorizeAll);
}
private void AuthorizeAll()
{
foreach (BaseNetworkable entity in BaseNetworkable.serverEntities)
{
AutoTurret turret = entity as AutoTurret;
if (turret != null) Authorize(turret);
}
}
private void OnEntitySpawned(AutoTurret turret)
{
if (turret == null || turret.OwnerID == 0) return;
NextTick(() => Authorize(turret));
}
private void Authorize(AutoTurret turret)
{
if (turret == null || turret.IsDestroyed || !turret.OwnerID.IsSteamId()) return;
bool changed = false;
ulong ownerId = turret.OwnerID;
changed |= AddAuth(turret, ownerId);
RelationshipManager.PlayerTeam team = RelationshipManager.ServerInstance?.FindPlayersTeam(ownerId);
if (team?.members != null)
{
foreach (ulong id in team.members)
changed |= AddAuth(turret, id);
}
string clanTag = SClan?.Call<string>("GetClanTag", ownerId) ?? string.Empty;
if (!string.IsNullOrEmpty(clanTag))
{
List<string> members = SClan.Call<List<string>>("GetMembersClan", clanTag);
if (members != null)
{
foreach (string value in members)
if (ulong.TryParse(value, out ulong id))
changed |= AddAuth(turret, id);
}
}
if (!changed) return;
turret.UpdateMaxAuthCapacity();
turret.SendNetworkUpdate();
}
private bool AddAuth(AutoTurret turret, ulong userId)
{
if (!userId.IsSteamId() || turret.IsAuthed(userId) || turret.AtMaxAuthCapacity()) return false;
turret.authorizedPlayers.Add(userId);
turret.authDirty = true;
turret.UpdateMaxAuthCapacity();
return true;
}
}