Иконка ресурса

FREE DynamicCupShare : 2.7.9 2.7.9

Нет прав для скачивания
C#:
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using Oxide.Core;
using Oxide.Core.Libraries.Covalence;
using Oxide.Core.Plugins;
using UnityEngine;
using ProtoBuf;
using Facepunch;
using Facepunch.Extend;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Oxide.Game.Rust;
namespace Oxide.Plugins {
    [Info("DynamicCupShare", "FuJiCuRa", "2.7.9", ResourceId = 20)]
    [Description("Dynamic sharing of cupboards/doors/boxes/lockers/turrets/quarries")]
    internal class DynamicCupShare : RustPlugin {
        [PluginReference]
        private Plugin Clans, Friends;
        private static DynamicCupShare Instance {
            get;
            set;
        }
        private bool Changed = false;
        private bool Initialized = false;
        private bool clansEnabled = false;
        private bool friendsEnabled = false;
        private bool friendsAPIEnabled = false;
        private bool pluginDisabled = false;
        private List<ulong> usdCnslInpt = new List<ulong>();
        private Hash<ulong, bool> adminAccessEnabled = new Hash<ulong, bool>();
        private Hash<ulong, List<uint>> adminCupboards = new Hash<ulong, List<uint>>();
        private Hash<ulong, List<uint>> adminTurrets = new Hash<ulong, List<uint>>();
        private StoredData playerPrefs = new StoredData();
        private Dictionary<string, List<uint>> playerCupboards = new Dictionary<string, List<uint>>();
        private Dictionary<string, List<uint>> playerTurrets = new Dictionary<string, List<uint>>();
        private List<object> pseudoAdminPerms = new List<object>();
        private List<string> pseudoPerms = new List<string>();
        [ProtoContract(ImplicitFields = ImplicitFields.AllFields)]
        private class StoredData {
            public Dictionary<ulong, PlayerInfo> PlayerInfo = new Dictionary<ulong, PlayerInfo>();
            public int saveStamp = 0;
            public string lastStorage = string.Empty;
            public StoredData() {
            }
        }
        [ProtoContract(ImplicitFields = ImplicitFields.AllFields)]
        internal class PlayerInfo {
            public bool CS;
            public bool DS;
            public bool BS;
            public bool TS;
            public bool LS;
            public bool QS;
            public bool AA;
            public bool CCS;
            public bool CDS;
            public bool CBS;
            public bool CLS;
            public bool CQS;
            public bool CTS;
            public bool TCS;
            public bool TDS;
            public bool TBS;
            public bool TLS;
            public bool TQS;
            public bool TTS;
            [JsonIgnore]
            [ProtoIgnore]
            public bool CanAutoAuth;
            [JsonIgnore]
            [ProtoIgnore]
            public bool HasClanShare;
            [JsonIgnore]
            [ProtoIgnore]
            public bool HasFriendShare;
            [JsonIgnore]
            [ProtoIgnore]
            public bool HasTeamShare;
            [JsonIgnore]
            [ProtoIgnore]
            public BuildingPrivilegeHandler BPH;
            public PlayerInfo() {
                BPH = null;
            }
        }
        private int UnixTimeStampUTC() {
            int unixTimeStamp;
            DateTime currentTime = DateTime.Now;
            DateTime zuluTime = currentTime.ToUniversalTime();
            DateTime unixEpoch = new DateTime(1970, 1, 1);
            unixTimeStamp = (int)zuluTime.Subtract(unixEpoch).TotalSeconds;
            return unixTimeStamp;
        }
        private string shareCommand;
        private bool useFriendsApi;
        private bool useClans;
        private bool useClanAlliances;
        private bool useProtostorageUserdata;
        private bool blockCupClearClanMembers;
        private bool blockCupAccessNotSameClan;
        private bool blockCupClearFriends;
        private bool allowLaddersIntoBlocked;
        private bool allowTwigIntoBlocked;
        private bool notifyPlayersBeingBlocked;
        private bool allowIcebergBuilding;
        private bool allowIcesheetBuilding;
        private bool allowIcelakeBuilding;
        private string permGetClanShares;
        private bool usePermGetClanShares;
        private string permGetFriendShares;
        private bool usePermGetFriendShares;
        private string permGetTeamShares;
        private bool usePermGetTeamShares;
        private string permAutoAuth;
        private bool usePermAutoAuth;
        private bool clanTurretShareOverride;
        private bool includeFlameTurrets;
        private bool includeGunTraps;
        private bool includeSamSites;
        private bool samSiteShootEmptyVehicles;
        private bool enableCupSharing;
        private bool enableDoorSharing;
        private bool enableBoxSharing;
        private bool enableLockerSharing;
        private bool enableTurretSharing;
        private bool enableAutoAuth;
        private bool enableQuarrySharing;
        private bool enableQuarrySwitchCheck;
        private bool notifyAuthCupboard;
        private bool notifyAuthTurret;
        private bool CupShare;
        private bool DoorShare;
        private bool TurretShare;
        private bool BoxShare;
        private bool LockerShare;
        private bool QuarryShare;
        private bool AutoAuth;
        private bool ClanCupShare;
        private bool ClanDoorShare;
        private bool ClanBoxShare;
        private bool ClanLockerShare;
        private bool ClanTurretShare;
        private bool ClanQuarryShare;
        private bool TeamShareEnabled;
        private bool TeamCupShare;
        private bool TeamDoorShare;
        private bool TeamTurretShare;
        private bool TeamBoxShare;
        private bool TeamLockerShare;
        private bool TeamQuarryShare;
        private bool toggleCupShare;
        private bool toggleDoorShare;
        private bool toggleTurretShare;
        private bool toggleBoxShare;
        private bool toggleLockerShare;
        private bool toggleQuarryShare;
        private bool toggleAutoAuth;
        private bool toggleClanCupShare;
        private bool toggleClanDoorShare;
        private bool toggleClanBoxShare;
        private bool toggleClanLockerShare;
        private bool toggleClanQuarryShare;
        private bool toggleClanTurretShare;
        private bool toggleTeamCupShare;
        private bool toggleTeamDoorShare;
        private bool toggleTeamTurretShare;
        private bool toggleTeamBoxShare;
        private bool toggleTeamLockerShare;
        private bool toggleTeamQuarryShare;
        private bool adminsRemainCupAuthed;
        private bool adminsRemainTurretAuthed;
        private bool enableAdminmodeAtLogin;
        private int cupboardAuthMaxUsers;
        private string pluginPrefix;
        private string prefixColor;
        private string prefixFormat;
        private string colorTextMsg;
        private string colorCmdUsage;
        private string colorON;
        private string colorOFF;
        private object GetConfig(string menu, string datavalue, object defaultValue) {
            Dictionary<string, object> data = Config[menu] as Dictionary<string, object>;
            if (data == null) {
                data = new Dictionary<string, object>();
                Config[menu] = data;
                Changed = true;
            }
            object value;
            if (!data.TryGetValue(datavalue, out value)) {
                value = defaultValue;
                data[datavalue] = value;
                Changed = true;
            }
            return value;
        }
        private void LoadVariables() {
            shareCommand = Convert.ToString(GetConfig("Command", "shareCommand", "share"));
            useFriendsApi = Convert.ToBoolean(GetConfig("Options", "useFriendsApi", true));
            useClans = Convert.ToBoolean(GetConfig("Options", "useClans", true));
            useClanAlliances = Convert.ToBoolean(GetConfig("Options", "useClanAlliances", true));
            pseudoAdminPerms = (List<object>)GetConfig("Options", "pseudoAdminPerms", new List<object> {
                "fauxadmin.allowed", "fakeadmin.allow"
            }
            );
            useProtostorageUserdata = Convert.ToBoolean(GetConfig("Storage", "useProtostorageUserdata", false));
            permGetClanShares = Convert.ToString(GetConfig("Permission", "permGetClanShares", "dynamiccupshare.getclanshares"));
            usePermGetClanShares = Convert.ToBoolean(GetConfig("Permission", "usePermGetClanShares", false));
            permGetFriendShares = Convert.ToString(GetConfig("Permission", "permGetFriendShares", "dynamiccupshare.getfriendshares"));
            usePermGetFriendShares = Convert.ToBoolean(GetConfig("Permission", "usePermGetFriendShares", false));
            permGetTeamShares = Convert.ToString(GetConfig("Permission", "permGetTeamShares", "dynamiccupshare.getteamshares"));
            usePermGetTeamShares = Convert.ToBoolean(GetConfig("Permission", "usePermGetTeamShares", false));
            permAutoAuth = Convert.ToString(GetConfig("Permission", "permGetShares", "dynamiccupshare.autoauth"));
            usePermAutoAuth = Convert.ToBoolean(GetConfig("Permission", "usePermAutoAuth", false));
            clanTurretShareOverride = Convert.ToBoolean(GetConfig("Security", "clanTurretShareOverride", false));
            blockCupClearClanMembers = Convert.ToBoolean(GetConfig("Security", "blockCupClearClanMembers", true));
            blockCupAccessNotSameClan = Convert.ToBoolean(GetConfig("Security", "blockCupAccessNotSameClan", false));
            blockCupClearFriends = Convert.ToBoolean(GetConfig("Security", "blockCupClearFriends", true));
            allowLaddersIntoBlocked = Convert.ToBoolean(GetConfig("Blocker", "allowLaddersIntoBlocked", true));
            allowTwigIntoBlocked = Convert.ToBoolean(GetConfig("Blocker", "allowTwigIntoBlocked", false));
            notifyPlayersBeingBlocked = Convert.ToBoolean(GetConfig("Blocker", "notifyPlayersBeingBlocked", true));
            allowIcebergBuilding = Convert.ToBoolean(GetConfig("Blocker", "allowIcebergBuilding", false));
            allowIcesheetBuilding = Convert.ToBoolean(GetConfig("Blocker", "allowIcesheetBuilding", true));
            allowIcelakeBuilding = Convert.ToBoolean(GetConfig("Blocker", "allowIcelakeBuilding", true));
            notifyAuthCupboard = Convert.ToBoolean(GetConfig("Notification", "notifyAuthCupboard", true));
            notifyAuthTurret = Convert.ToBoolean(GetConfig("Notification", "notifyAuthTurret", true));
            CupShare = Convert.ToBoolean(GetConfig("PlayerDefaults", "CupShare", false));
            DoorShare = Convert.ToBoolean(GetConfig("PlayerDefaults", "DoorShare", false));
            TurretShare = Convert.ToBoolean(GetConfig("PlayerDefaults", "TurretShare", false));
            BoxShare = Convert.ToBoolean(GetConfig("PlayerDefaults", "BoxShare", false));
            LockerShare = Convert.ToBoolean(GetConfig("PlayerDefaults", "LockerShare", false));
            QuarryShare = Convert.ToBoolean(GetConfig("PlayerDefaults", "QuarryShare", false));
            AutoAuth = Convert.ToBoolean(GetConfig("PlayerDefaults", "AutoAuth", true));
            ClanCupShare = Convert.ToBoolean(GetConfig("PlayerDefaults", "ClanCupShare", true));
            ClanDoorShare = Convert.ToBoolean(GetConfig("PlayerDefaults", "ClanDoorShare", true));
            ClanBoxShare = Convert.ToBoolean(GetConfig("PlayerDefaults", "ClanBoxShare", true));
            ClanLockerShare = Convert.ToBoolean(GetConfig("PlayerDefaults", "ClanLockerShare", true));
            ClanQuarryShare = Convert.ToBoolean(GetConfig("PlayerDefaults", "ClanQuarryShare", true));
            ClanTurretShare = Convert.ToBoolean(GetConfig("PlayerDefaults", "ClanTurretShare", true));
            //TeamCupShare = Convert.ToBoolean(GetConfig("PlayerDefaults", "TeamCupShare", false));
            //TeamDoorShare = Convert.ToBoolean(GetConfig("PlayerDefaults", "TeamDoorShare", false));
            //TeamTurretShare = Convert.ToBoolean(GetConfig("PlayerDefaults", "TeamTurretShare", false));
            //TeamBoxShare = Convert.ToBoolean(GetConfig("PlayerDefaults", "TeamBoxShare", false));
            //TeamLockerShare = Convert.ToBoolean(GetConfig("PlayerDefaults", "TeamLockerShare", false));
            //TeamQuarryShare = Convert.ToBoolean(GetConfig("PlayerDefaults", "TeamQuarryShare", false));
            toggleCupShare = Convert.ToBoolean(GetConfig("PlayerToggles", "CupShare", true));
            toggleDoorShare = Convert.ToBoolean(GetConfig("PlayerToggles", "DoorShare", true));
            toggleTurretShare = Convert.ToBoolean(GetConfig("PlayerToggles", "TurretShare", true));
            toggleBoxShare = Convert.ToBoolean(GetConfig("PlayerToggles", "BoxShare", true));
            toggleLockerShare = Convert.ToBoolean(GetConfig("PlayerToggles", "LockerShare", true));
            toggleQuarryShare = Convert.ToBoolean(GetConfig("PlayerToggles", "QuarryShare", true));
            toggleAutoAuth = Convert.ToBoolean(GetConfig("PlayerToggles", "AutoAuth", true));
            toggleClanCupShare = Convert.ToBoolean(GetConfig("PlayerToggles", "ClanCupShare", true));
            toggleClanDoorShare = Convert.ToBoolean(GetConfig("PlayerToggles", "ClanDoorShare", true));
            toggleClanBoxShare = Convert.ToBoolean(GetConfig("PlayerToggles", "ClanBoxShare", true));
            toggleClanLockerShare = Convert.ToBoolean(GetConfig("PlayerToggles", "ClanLockerShare", true));
            toggleClanQuarryShare = Convert.ToBoolean(GetConfig("PlayerToggles", "ClanQuarryShare", true));
            toggleClanTurretShare = Convert.ToBoolean(GetConfig("PlayerToggles", "ClanTurretShare", true));
            //toggleTeamCupShare = Convert.ToBoolean(GetConfig("PlayerToggles", "TeamCupShare", true));
            //toggleTeamDoorShare = Convert.ToBoolean(GetConfig("PlayerToggles", "TeamDoorShare", true));
            //toggleTeamTurretShare = Convert.ToBoolean(GetConfig("PlayerToggles", "TeamTurretShare", true));
            //toggleTeamBoxShare = Convert.ToBoolean(GetConfig("PlayerToggles", "TeamBoxShare", true));
            //toggleTeamLockerShare = Convert.ToBoolean(GetConfig("PlayerToggles", "TeamLockerShare", true));
            //toggleTeamQuarryShare = Convert.ToBoolean(GetConfig("PlayerToggles", "TeamQuarryShare", true));
            //TeamShareEnabled = Convert.ToBoolean(GetConfig("PlayerToggles", "TeamShareEnabled", true));
            enableCupSharing = Convert.ToBoolean(GetConfig("Functions", "enableCupSharing", true));
            enableDoorSharing = Convert.ToBoolean(GetConfig("Functions", "enableDoorSharing", true));
            enableBoxSharing = Convert.ToBoolean(GetConfig("Functions", "enableBoxSharing", true));
            enableLockerSharing = Convert.ToBoolean(GetConfig("Functions", "enableLockerSharing", true));
            enableQuarrySharing = Convert.ToBoolean(GetConfig("Functions", "enableQuarrySharing", false));
            enableQuarrySwitchCheck = Convert.ToBoolean(GetConfig("Functions", "enableQuarrySwitchCheck", false));
            enableTurretSharing = Convert.ToBoolean(GetConfig("Functions", "enableTurretSharing", true));
            enableAutoAuth = Convert.ToBoolean(GetConfig("Functions", "enableAutoAuth", true));
            includeFlameTurrets = Convert.ToBoolean(GetConfig("Functions", "includeFlameTurrets", true));
            includeGunTraps = Convert.ToBoolean(GetConfig("Functions", "includeGunTraps", true));
            includeSamSites = Convert.ToBoolean(GetConfig("Functions", "includeSamSites", true));
            cupboardAuthMaxUsers = Convert.ToInt32(GetConfig("Functions", "cupboardAuthMaxUsers (0 is disabled)", 0));
            samSiteShootEmptyVehicles = Convert.ToBoolean(GetConfig("Functions", "samSiteShootEmptyVehicles", false));
            adminsRemainCupAuthed = Convert.ToBoolean(GetConfig("Adminmode", "adminsRemainCupAuthed", false));
            adminsRemainTurretAuthed = Convert.ToBoolean(GetConfig("Adminmode", "adminsRemainTurretAuthed", false));
            enableAdminmodeAtLogin = Convert.ToBoolean(GetConfig("Adminmode", "enableAdminmodeAtLogin", false));
            pluginPrefix = Convert.ToString(GetConfig("Formatting", "pluginPrefix", "DynaShare"));
            prefixColor = Convert.ToString(GetConfig("Formatting", "prefixColor", "#ffa500"));
            prefixFormat = Convert.ToString(GetConfig("Formatting", "prefixFormat", "<color={0}>{1}</color>: "));
            colorTextMsg = Convert.ToString(GetConfig("Formatting", "colorTextMsg", "#ffffff"));
            colorCmdUsage = Convert.ToString(GetConfig("Formatting", "colorCmdUsage", "#ffff00"));
            colorON = Convert.ToString(GetConfig("Formatting", "colorON", "#008000"));
            colorOFF = Convert.ToString(GetConfig("Formatting", "colorOFF", "#c0c0c0"));
            bool configremoval = false;
            if ((Config.Get("Security") as Dictionary<string, object>).ContainsKey("blockCupAuthClanMembers")) {
                (Config.Get("Security") as Dictionary<string, object>).Remove("blockCupAuthClanMembers");
                (Config.Get("Security") as Dictionary<string, object>).Remove("blockCupAuthFriends");
                configremoval = true;
            }
            if ((Config.Get("Functions") as Dictionary<string, object>).ContainsKey("addAdminsToCupboards")) {
                (Config.Get("Functions") as Dictionary<string, object>).Remove("addAdminsToCupboards");
                configremoval = true;
            }
            if ((Config.Get("Options") as Dictionary<string, object>).ContainsKey("pluginDelayOnFreshStart")) {
                (Config.Get("Options") as Dictionary<string, object>).Remove("pluginDelayOnFreshStart");
                configremoval = true;
            }
            if ((Config.Get("Blocker") as Dictionary<string, object>).ContainsKey("excludeAdminsFromBlocking")) {
                (Config.Get("Blocker") as Dictionary<string, object>).Remove("excludeAdminsFromBlocking");
                configremoval = true;
            }
            if (Config.Get("Blocking") != null) {
                Config.Remove("Blocking");
                configremoval = true;
            }
            if ((Config.Get("Options") as Dictionary<string, object>).ContainsKey("useFriendsIO")) {
                (Config.Get("Options") as Dictionary<string, object>).Remove("useFriendsIO");
                configremoval = true;
            }
            if (!Changed && !configremoval) return;
            SaveConfig();
            Changed = false;
        }
        protected override void LoadDefaultConfig() {
            Config.Clear();
            LoadVariables();
        }
        protected override void LoadDefaultMessages() {
            lang.RegisterMessages(new Dictionary<string, string> {
                {
                    "ShareEnabled", "Cupboard sharing for friends enabled"
                }
                , {
                    "ShareDisabled", "Cupboard sharing for friends disabled"
                }
                , {
                    "CodesEnabled", "Door sharing for friends enabled"
                }
                , {
                    "CodesDisabled", "Door sharing for friends disabled"
                }
                , {
                    "BoxesEnabled", "Box sharing for friends enabled"
                }
                , {
                    "BoxesDisabled", "Box sharing for friends disabled"
                }
                , {
                    "LockersEnabled", "Locker sharing for friends enabled"
                }
                , {
                    "LockersDisabled", "Locker sharing for friends disabled"
                }
                , {
                    "QuarriesEnabled", "Quarry sharing for friends enabled"
                }
                , {
                    "QuarriesDisabled", "Quarry sharing for friends disabled"
                }
                , {
                    "TurretEnabled", "Turret sharing for friends enabled"
                }
                , {
                    "TurretDisabled", "Turret sharing for friends disabled"
                }
                , {
                    "ClanShareEnabled", "Cupboard sharing for clan enabled"
                }
                , {
                    "ClanShareDisabled", "Cupboard sharing for clan disabled"
                }
                , {
                    "ClanCodesEnabled", "Door sharing for clan enabled"
                }
                , {
                    "ClanCodesDisabled", "Door sharing for clan disabled"
                }
                , {
                    "ClanBoxesEnabled", "Box sharing for clan enabled"
                }
                , {
                    "ClanBoxesDisabled", "Box sharing for clan disabled"
                }
                , {
                    "ClanLockersEnabled", "Locker sharing for clan enabled"
                }
                , {
                    "ClanLockersDisabled", "Locker sharing for clan disabled"
                }
                , {
                    "ClanQuarriesEnabled", "Quarry sharing for clan enabled"
                }
                , {
                    "ClanQuarriesDisabled", "Quarry sharing for clan disabled"
                }
                , {
                    "ClanTurretEnabled", "Turret sharing for clan enabled"
                }
                , {
                    "ClanTurretDisabled", "Turret sharing for clan disabled"
                }
                , {
                    "AdminAccessEnabled", "Admin access mode enabled"
                }
                , {
                    "AdminAccessDisabled", "Admin access mode disabled"
                }
                , {
                    "AutoAuthEnabled", "Cupboard automatic authorization enabled"
                }
                , {
                    "AutoAuthDisabled", "Cupboard automatic authorization disabled"
                }
                , {
                    "CupAuth", "Cupboard authorized"
                }
                , {
                    "TurretAuth", "Turret authorized"
                }
                , {
                    "NoAccess", "You are not granted for this feature"
                }
                , {
                    "NotEnabled", "The specific function '{0}' is currently not active"
                }
                , {
                    "SwitchBlocked", "The admin blocked the '{0}' switch"
                }
                , {
                    "SharedAll", "Enabled all available sharing functions"
                }
                , {
                    "NotSupported", "The specific function '{0}' is not available"
                }
                , {
                    "NotFound", "The player '{0}' was not found."
                }
                , {
                    "NeedArgs", "Please define a target playername."
                }
                , {
                    "CupAuthDisabledOwner", "Authorization denied.'{0}' has cup sharing deactivated"
                }
                , {
                    "CupAuthDisabledSelf", "Authorization denied.You need to activate cup sharing"
                }
                , {
                    "CupAuthClearBlocked", "Clear authorized list denied"
                }
                , {
                    "CupAuthNotSameClanBlocked", "Authorization denied"
                }
                , {
                    "CupAuthMaxUsers", "This cupboard already has the maximum amount of authorized players ({0})"
                }
                , {
                    "BlockBuildIntoBlocked", "You can't build or place into blocked area!"
                }
                , {
                    "BlockBuildOnIceBergs", "You can't build or place on icebergs"
                }
                , {
                    "BlockBuildOnIceSheets", "You can't build or place on icesheets"
                }
                , {
                    "BlockBuildOnIceLakes", "You can't build or place on icelakes"
                }
                , {
                    "DoorClanNotShared", "Clan member '{0}' has door sharing deactivated"
                }
                , {
                    "DoorClanNotSharedSelf", "Your clan door sharing is deactivated"
                }
                , {
                    "BoxClanNotShared", "Clan member '{0}' has box sharing deactivated"
                }
                , {
                    "BoxClanNotSharedSelf", "Your clan box sharing is deactivated"
                }
                , {
                    "LockerClanNotShared", "Clan member '{0}' has locker sharing deactivated"
                }
                , {
                    "LockerClanNotSharedSelf", "Your clan locker sharing is deactivated"
                }
                , {
                    "CupClanNotShared", "Authorization denied.Clan member '{0}' has cup sharing deactivated"
                }
                , {
                    "QuarryNoLootAccess", "You are not allowed access this storage."
                }
                , {
                    "QuarryNoStartStop", "You are not allowed use this machine."
                }
                , {
                    "AccessRights", "You can access these shares:"
                }
                , {
                    "CommandPlgDisabled", "Plugin disabled! Please contact your server admin"
                }
                , {
                    "CommandUsage", "Command usage:"
                }
                , {
                    "CommandToggle", "All switches toggle their setting (on<>off)"
                }
                , {
                    "CommandFriendCup", "Friends Cupboard:"
                }
                , {
                    "CommandFriendDoor", "Friends Door:"
                }
                , {
                    "CommandFriendBox", "Friends Box:"
                }
                , {
                    "CommandFriendLocker", "Friends Locker:"
                }
                , {
                    "CommandFriendQuarry", "Friends Quarry:"
                }
                , {
                    "CommandFriendTurret", "Friends Turret:"
                }
                , {
                    "CommandAutoAuth", "Cup/Turret authorization:"
                }
                , {
                    "CommandClanCup", "Clan Cupboard:"
                }
                , {
                    "CommandClanDoor", "Clan Door:"
                }
                , {
                    "CommandClanBox", "Clan Box:"
                }
                , {
                    "CommandClanLocker", "Clan Locker:"
                }
                , {
                    "CommandClanQuarry", "Clan Quarry:"
                }
                , {
                    "CommandClanTurret", "Clan Members not targeted by Turrets:"
                }
                , {
                    "CommandClanTurretM", "Clan Turret:"
                }
                , {
                    "CommandTeamCup", "Team Cupboard:"
                }
                , {
                    "CommandTeamDoor", "Team Door:"
                }
                , {
                    "CommandTeamBox", "Team Box:"
                }
                , {
                    "CommandTeamLocker", "Team Locker:"
                }
                , {
                    "CommandTeamQuarry", "Team Quarry:"
                }
                , {
                    "CommandTeamTurret", "Team Members not targeted by Turrets:"
                }
                , {
                    "CommandTeamTurretM", "Team Turret:"
                }
                , {
                    "CommandAdminAccess", "Admin access status"
                }
                , {
                    "HelpCups", "Get the description for sharing of cupboards"
                }
                , {
                    "HelpDoors", "Get the description for sharing of doors"
                }
                , {
                    "HelpBoxes", "Get the description for sharing of boxes"
                }
                , {
                    "HelpLockers", "Get the description for sharing of lockers"
                }
                , {
                    "HelpQuarries", "Get the description for sharing of quarries"
                }
                , {
                    "HelpTurrets", "Get the description for sharing of turrets"
                }
                , {
                    "HelpAutoAuth", "Get the description for automatic authorization"
                }
                , {
                    "HelpNotAvailable", "This help topics does'nt exist"
                }
                , {
                    "DescriptionCups", "By enabling cup sharing for friends/members, then those players get build rights in every cupboard range, which you own and where yourself are authed.It does not share in case you are not selfauthed."
                }
                , {
                    "DescriptionDoors", "By enabling door sharing for friends/members, then those players can open each of your locked doors; Without any direct lock access."
                }
                , {
                    "DescriptionBoxes", "By enabling box sharing for friends/members, then those players can open each of your locked boxes; Without any direct lock access."
                }
                , {
                    "DescriptionLockers", "By enabling locker sharing for friends/members, then those players can open each of your lockers; Without any direct lock access."
                }
                , {
                    "DescriptionQuarries", "By enabling quarry sharing for friends/members, then those players can open each of your fuelstorages and hopperoutputs; Other players will be blocked."
                }
                , {
                    "DescriptionTurrets", "By enabling turret sharing for friends/members, then those players will not be targeted by your turrets/traps."
                }
                , {
                    "DescriptionAutoAuth", "By enabling automatic authorization for cups and turrets, you can skip the selfauth steps after placement by this automation."
                }
                ,
            }
            , this);
        }
        private void Init() {
            StateDisabled();
            ClansDisabled();
            LoadVariables();
            LoadDefaultMessages();
            cmd.AddChatCommand(shareCommand, this, "ShareCommand");
            cmd.AddConsoleCommand(shareCommand, this, "cShareCommand");
            permission.RegisterPermission(permGetClanShares, this);
            permission.RegisterPermission(permGetFriendShares, this);
            permission.RegisterPermission(permAutoAuth, this);
            List<string> filter = RustExtension.Filter.ToList();
            filter.Add("Calling hook CanBeTargeted resulted in a conflict");
            RustExtension.Filter = filter.ToArray();
            LdPlyrDt();
        }
        private void LdPlyrDt() {
            StoredData protoStorage = new StoredData();
            if (ProtoStorage.Exists(new string[] {
                Title
            }
            )) protoStorage = ProtoStorage.Load<StoredData>(new string[] {
                Title
            }
            ) ?? new StoredData();
            StoredData jsonStorage = new StoredData();
            if (Interface.GetMod().DataFileSystem.ExistsDatafile(Title)) jsonStorage = Interface.GetMod().DataFileSystem.ReadObject<StoredData>(Title);
            bool lastwasProto = protoStorage.lastStorage == "proto" && protoStorage.saveStamp > jsonStorage.saveStamp;
            if (useProtostorageUserdata) {
                if (lastwasProto) {
                    playerPrefs = ProtoStorage.Load<StoredData>(new string[] {
                        Title
                    }
                    ) ?? new StoredData();
                    return;
                }
                else {
                    if (Interface.GetMod().DataFileSystem.ExistsDatafile(Title)) playerPrefs = Interface.GetMod().DataFileSystem.ReadObject<StoredData>(Title);
                }
            }
            else {
                if (!lastwasProto) {
                    playerPrefs = Interface.GetMod().DataFileSystem.ReadObject<StoredData>(Title);
                    return;
                }
                else {
                    if (ProtoStorage.Exists(new string[] {
                        Title
                    }
                    )) playerPrefs = ProtoStorage.Load<StoredData>(new string[] {
                        Title
                    }
                    ) ?? new StoredData();
                }
            }
        }
        private void SaveData() {
            if (pluginDisabled) return;
            playerPrefs.saveStamp = UnixTimeStampUTC();
            playerPrefs.lastStorage = useProtostorageUserdata ? "proto" : "json";
            if (useProtostorageUserdata) ProtoStorage.Save<StoredData>(playerPrefs, new string[] {
                Title
            }
            );
            else Interface.Oxide.DataFileSystem.WriteObject(Title, playerPrefs);
        }
        private void Loaded() {
            Instance = this;
        }
        private void OnServerInitialized() {
            if (Initialized) return;
            foreach (string pseudoPerm in pseudoAdminPerms.ConvertAll(obj => Convert.ToString(obj)).ToList()) {
                if (permission.PermissionExists(pseudoPerm)) pseudoPerms.Add(pseudoPerm.ToLower());
            }
            Initialize();
        }
        private void Initialize() {
            if (Clans && useClans) {
                clansEnabled = true;
                Puts("Plugin 'Clans' found - Clan support activated");
                ClansEnabled();
            }
            if (!Clans && useClans) PrintWarning("Plugin 'Clans' not found - Clan support not active");
            if (useFriendsApi) if (Friends && useFriendsApi && !friendsEnabled) {
                friendsEnabled = true;
                friendsAPIEnabled = true;
                Puts("Plugin Friends found - Friends support activated");
            }
            if (useFriendsApi && !friendsEnabled) PrintWarning("No Friend Plugin found - Friend support not active");
            if (!clansEnabled && !friendsEnabled) {
                PrintWarning("No supported requirements found - Plugin unload!");
                Interface.Oxide.UnloadPlugin(Title);
                return;
            }
            adminAccessEnabled = new Hash<ulong, bool>();
            adminCupboards = new Hash<ulong, List<uint>>();
            adminTurrets = new Hash<ulong, List<uint>>();
            playerCupboards = new Dictionary<string, List<uint>>();
            playerTurrets = new Dictionary<string, List<uint>>();
            foreach (BasePlayer player in BasePlayer.activePlayerList.ToList()) SetPlayer(player);
            foreach (BasePlayer player in BasePlayer.sleepingPlayerList.ToList()) SetPlayer(player);
            List<BaseEntity> plyrObjcts = BaseNetworkable.serverEntities.Where(p => (p is BuildingPrivlidge || p is AutoTurret || p is GunTrap || p is FlameTurret || p is BaseLock)).Cast<BaseEntity>().ToList();
            foreach (BaseEntity plyrObjct in plyrObjcts) {
                if (plyrObjct is CodeLock && plyrObjct.GetParentEntity() && !playerPrefs.PlayerInfo.ContainsKey(plyrObjct.GetParentEntity().OwnerID)) {
                    AddPlayerData(plyrObjct.GetParentEntity().OwnerID);
                    continue;
                }
                if (plyrObjct is CodeLock || plyrObjct.OwnerID == 0uL) continue;
                string owner = plyrObjct.OwnerID.ToString();
                if (plyrObjct is BuildingPrivlidge) {
                    List<uint> player;
                    if (!playerCupboards.TryGetValue(owner, out player)) playerCupboards.Add(owner, new List<uint>());
                    playerCupboards[owner].Add(plyrObjct.net.ID);
                    if (!playerPrefs.PlayerInfo.ContainsKey(plyrObjct.OwnerID)) AddPlayerData(plyrObjct.OwnerID);
                }
                else if (plyrObjct is AutoTurret) {
                    List<uint> player;
                    if (!playerTurrets.TryGetValue(owner, out player)) playerTurrets.Add(owner, new List<uint>());
                    playerTurrets[owner].Add(plyrObjct.net.ID);
                    if (!playerPrefs.PlayerInfo.ContainsKey(plyrObjct.OwnerID)) AddPlayerData(plyrObjct.OwnerID);
                }
                else if (!playerPrefs.PlayerInfo.ContainsKey(plyrObjct.OwnerID)) {
                    AddPlayerData(plyrObjct.OwnerID);
                }
            }
            if (enableQuarrySharing && enableQuarrySwitchCheck) {
                foreach (MiningQuarry quarry in BaseNetworkable.serverEntities.Where(p => p is MiningQuarry && (p as BaseEntity).OwnerID != 0uL).Cast<MiningQuarry>().ToList()) quarry.engineSwitchPrefab.instance.gameObject.transform.GetOrAddComponent<QuarryHandler>();
            }
            StateEnabled();
            Initialized = true;
        }
        private bool GetAdmin(BasePlayer player) {
            return player.IsAdmin || IsPsdAdmn(player.UserIDString);
        }
        private bool AccessOn(ulong id) {
            bool obj;
            return adminAccessEnabled.TryGetValue(id, out obj) && (bool)obj == true;
        }
        private PlayerInfo SetPlayer(BasePlayer player) {
            if (player == null || player.userID < 76561197960265729uL) return null;
            if (GetAdmin(player)) {
                adminAccessEnabled[player.userID] = enableAdminmodeAtLogin;
                adminCupboards[player.userID] = new List<uint>();
                adminTurrets[player.userID] = new List<uint>();
            }
            List<uint> entries;
            if (!playerCupboards.TryGetValue(player.UserIDString, out entries)) playerCupboards.Add(player.UserIDString, new List<uint>());
            if (!playerTurrets.TryGetValue(player.UserIDString, out entries)) playerTurrets.Add(player.UserIDString, new List<uint>());
            PlayerInfo p;
            if (!playerPrefs.PlayerInfo.TryGetValue(player.userID, out p)) {
                PlayerInfo info = new PlayerInfo();
                info.CS = CupShare;
                info.DS = DoorShare;
                info.TS = TurretShare;
                info.BS = BoxShare;
                info.LS = LockerShare;
                info.QS = QuarryShare;
                info.AA = AutoAuth;
                info.CCS = ClanCupShare;
                info.CDS = ClanDoorShare;
                info.CBS = ClanBoxShare;
                info.CLS = ClanLockerShare;
                info.CQS = ClanQuarryShare;
                info.CTS = ClanTurretShare;
                info.HasClanShare = !usePermGetClanShares || usePermGetClanShares && permission.UserHasPermission(player.UserIDString, permGetClanShares);
                info.HasFriendShare = !usePermGetFriendShares || usePermGetFriendShares && permission.UserHasPermission(player.UserIDString, permGetFriendShares);
                info.HasTeamShare = !usePermGetTeamShares || usePermGetTeamShares && permission.UserHasPermission(player.UserIDString, permGetTeamShares);
                info.CanAutoAuth = !usePermAutoAuth || usePermAutoAuth && permission.UserHasPermission(player.UserIDString, permAutoAuth);
                playerPrefs.PlayerInfo.Add(player.userID, info);
                return info;
            }
            else {
                p.HasClanShare = !usePermGetClanShares || usePermGetClanShares && permission.UserHasPermission(player.UserIDString, permGetClanShares);
                p.HasFriendShare = !usePermGetFriendShares || usePermGetFriendShares && permission.UserHasPermission(player.UserIDString, permGetFriendShares);
                p.HasTeamShare = !usePermGetTeamShares || usePermGetTeamShares && permission.UserHasPermission(player.UserIDString, permGetTeamShares);
                p.CanAutoAuth = !usePermAutoAuth || usePermAutoAuth && permission.UserHasPermission(player.UserIDString, permAutoAuth);
            }
            return p;
        }
        private bool IsPsdAdmn(string id) {
            foreach (string perm in pseudoPerms) if (permission.UserHasPermission(id, perm)) return true;
            return false;
        }
        private void OnUserPermissionGranted(string id, string perm) {
            if (pseudoPerms.Contains(perm.ToLower())) {
                adminAccessEnabled[Convert.ToUInt64(id)] = enableAdminmodeAtLogin;
                adminCupboards[Convert.ToUInt64(id)] = new List<uint>();
                adminTurrets[Convert.ToUInt64(id)] = new List<uint>();
            }
        }
        private PlayerInfo AddPlayerData(ulong userID) {
            PlayerInfo info = new PlayerInfo();
            info.CS = CupShare;
            info.DS = DoorShare;
            info.TS = TurretShare;
            info.BS = BoxShare;
            info.LS = LockerShare;
            info.QS = QuarryShare;
            info.AA = AutoAuth;
            info.CCS = ClanCupShare;
            info.CDS = ClanDoorShare;
            info.CBS = ClanBoxShare;
            info.CLS = ClanLockerShare;
            info.CQS = ClanQuarryShare;
            info.CTS = ClanTurretShare;
            info.HasClanShare = !usePermGetClanShares || usePermGetClanShares && permission.UserHasPermission(userID.ToString(), permGetClanShares);
            info.HasFriendShare = !usePermGetFriendShares || usePermGetFriendShares && permission.UserHasPermission(userID.ToString(), permGetFriendShares);
            info.CanAutoAuth = !usePermAutoAuth || usePermAutoAuth && permission.UserHasPermission(userID.ToString(), permAutoAuth);
            playerPrefs.PlayerInfo.Add(userID, info);
            return info;
        }
        private void OnPlayerDisconnected(BasePlayer player, string reason) {
            if (!GetAdmin(player)) return;
            adminAccessEnabled.Remove(player.userID);
            List<uint> cups;
            if (adminCupboards.TryGetValue(player.userID, out cups)) {
                foreach (uint cup in cups) {
                    BuildingPrivlidge ent = (BuildingPrivlidge)BaseNetworkable.serverEntities.Find(cup);
                    if (ent) {
                        ent.authorizedPlayers.RemoveAll((PlayerNameID x) => x.userid == player.userID);
                        ent.SendNetworkUpdate(BasePlayer.NetworkQueue.Update);
                    }
                }
                adminCupboards.Remove(player.userID);
            }
            List<uint> turrets;
            if (adminTurrets.TryGetValue(player.userID, out turrets)) {
                foreach (uint turret in turrets) {
                    AutoTurret ent = (AutoTurret)BaseNetworkable.serverEntities.Find(turret);
                    if (ent) {
                        ent.authorizedPlayers.RemoveAll((PlayerNameID x) => x.userid == player.userID);
                        ent.SendNetworkUpdate(BasePlayer.NetworkQueue.Update);
                    }
                }
                adminTurrets.Remove(player.userID);
            }
        }
        private void Unload() {
            SaveData();
            bool isOn = !Interface.Oxide.IsShuttingDown;
            foreach (KeyValuePair<ulong, List<uint>> admin in adminCupboards.ToList()) foreach (uint cup in adminCupboards[admin.Key].ToList()) {
                BuildingPrivlidge p = (BuildingPrivlidge)BaseNetworkable.serverEntities.Find(cup);
                if (p) {
                    p.authorizedPlayers.RemoveAll((PlayerNameID x) => x.userid == admin.Key);
                    if (isOn) p.SendNetworkUpdate(BasePlayer.NetworkQueue.Update);
                }
            }
            foreach (KeyValuePair<ulong, List<uint>> admin in adminTurrets.ToList()) foreach (uint turret in adminTurrets[admin.Key].ToList()) {
                AutoTurret t = (AutoTurret)BaseNetworkable.serverEntities.Find(turret);
                if (t) {
                    t.authorizedPlayers.RemoveAll((PlayerNameID x) => x.userid == admin.Key);
                    if (isOn) t.SendNetworkUpdate(BasePlayer.NetworkQueue.Update);
                }
            }
            if (!isOn) return;
            List<BuildingPrivilegeHandler> bphandlers = UnityEngine.Object.FindObjectsOfType<BuildingPrivilegeHandler>().ToList();
            if (bphandlers.Count > 0) foreach (BuildingPrivilegeHandler handler in bphandlers) UnityEngine.Object.Destroy(handler);
            List<QuarryHandler> qhandlers = UnityEngine.Object.FindObjectsOfType<QuarryHandler>().ToList();
            if (qhandlers.Count > 0) foreach (QuarryHandler handler in qhandlers) UnityEngine.Object.Destroy(handler);
            List<string> filter = RustExtension.Filter.ToList();
            filter.Remove("Calling hook CanBeTargeted resulted in a conflict");
            RustExtension.Filter = filter.ToArray();
        }
        private void OnServerSave() {
            SaveData();
        }
        private void OnPluginUnloaded(Plugin name) {
            if (!Initialized || name.Name == Title) return;
            if (name.Name == "Clans" && useClans && clansEnabled) {
                clansEnabled = false;
                Puts("Clans support disabled");
                ClansDisabled();
            }
            if (name.Name == "Friends" && useFriendsApi && friendsAPIEnabled) {
                friendsAPIEnabled = false;
                friendsEnabled = false;
                Puts("Friends support disabled");
            }
            if (!clansEnabled && !friendsEnabled && !pluginDisabled) {
                pluginDisabled = true;
                PrintWarning("Sharing functions disabled - Plugin paused!");
                StateDisabled();
            }
        }
        private void OnPluginLoaded(Plugin name) {
            if (!Initialized || name.Name == Title) return;
            if (name.Name == "Clans" && useClans && !clansEnabled) {
                clansEnabled = true;
                Puts("Clans support enabled");
                ClansEnabled();
            }
            if (name.Name == "Friends" && useFriendsApi && !friendsAPIEnabled) {
                friendsAPIEnabled = true;
                friendsEnabled = true;
                Puts("Friends support enabled");
            }
            if ((clansEnabled || friendsEnabled) && pluginDisabled) {
                pluginDisabled = false;
                Puts("Sharing functions re-enabled - Plugin unpaused!");
                StateEnabled();
            }
        }
        private object CanBuild(Planner plan, Construction prefab, Construction.Target target) {
            if (plan == null || prefab == null || allowLaddersIntoBlocked && prefab.hierachyName.Contains("ladder.wooden.wall") || allowTwigIntoBlocked && prefab.hierachyName.Contains("floor")) 
// ... [Code preview truncated due to length. Full source in attached file] ...

Автор
15FPS
Скачиваний
0
Просмотры
1
Первый выпуск
Обновление
Оценка
0.00 звёзд 0 оценок
Сверху