Example #1
0
        void OpenToolCupboard(BasePlayer player, string command, string[] args)
        {
            if (!permission.UserHasPermission(player.UserIDString, "tcmanager.openinv") && !player.IsAdmin)
            {
                player.ChatMessage(Lang("NoCommandPermission", player.UserIDString));
                return;
            }
            BuildingPrivlidge privilege = player.GetBuildingPrivilege();

            if (!privilege)
            {
                player.ChatMessage(Lang("NoBuildingPrivilege", player.UserIDString));
                return;
            }
            if (!privilege.IsAuthed(player) && !player.IsAdmin)
            {
                player.ChatMessage(Lang("NoAuthorization", player.UserIDString));
                return;
            }

            player.EndLooting();
            timer.Once(0.1f, delegate() {
                LootContainer(player, privilege);
            });
        }
Example #2
0
        private object OnCupboardAuthorize(BuildingPrivlidge privilege, BasePlayer player)
        {
            if (HasPermission(player))
            {
                return(null);
            }

            if (!Configuration.EnforceCupboards)
            {
                return(null);
            }

            if (privilege.authorizedPlayers.Count < Configuration.MaxPlayers)
            {
                return(null);
            }

            ProcessConfiguration(player, "cupboard");
            LogToFile("Cupboard", Lang("logMessage")
                      .Replace("{time}", DateTime.UtcNow.ToShortDateString())
                      .Replace("{player}", player.displayName)
                      .Replace("{steamID}", player.UserIDString)
                      .Replace("{coordinates}", FormattedCoordinates(player)), this);

            return(false);
        }
        private bool CupboardAuthCheck(BuildingPrivlidge priv, ulong hitEntityOwnerID)
        {
            string hitId    = null;
            string entowner = null;

            foreach (var auth in priv.authorizedPlayers.Select(x => x.userid).ToArray())
            {
#if DEBUG
                hitId    = auth.ToString();
                entowner = hitEntityOwnerID.ToString();
                Puts($"CupboardAuthCheck:       Comparing {hitId} to {entowner}");
#endif
                if (auth == hitEntityOwnerID)
                {
#if DEBUG
                    Puts("CupboardAuthCheck:       Entity/block protected by authed cupboard!");
#endif
                    return(true);
                }
            }
#if DEBUG
            Puts("CupboardAuthCheck:       Entity/block NOT protected by authed cupboard!");
#endif
            return(false);
        }
Example #4
0
        // checks if the player is authorized to damage the entity
        bool CheckAuthDamage(BaseCombatEntity entity, BasePlayer player)
        {
            // check if the player is the owner of the entity
            if (player.userID == entity.OwnerID)
            {
                return(true);                // player is the owner, allow damage
            }
            // assume no authorization by default
            bool authed = false;
            // check for cupboards which overlap the entity
            var hit = Physics.OverlapBox(entity.transform.position, entity.bounds.extents / 2f, entity.transform.rotation, triggerMask);

            // loop through cupboards
            foreach (var ent in hit)
            {
                // get cupboard BuildingPrivilidge
                BuildingPrivlidge privs = ent.GetComponentInParent <BuildingPrivlidge>();
                // check if the player is authorized on the cupboard
                if (privs != null)
                {
                    if (!privs.IsAuthed(player))
                    {
                        return(false);                        // return false if not authorized on any single cupboard which overlaps this entity
                    }
                    else
                    {
                        authed = true;                         // set authed to true to indicate player is authorized on at least one cupboard
                    }
                }
            }
            return(authed);
        }
Example #5
0
        private string GetOwnerPlayer(BuildingPrivlidge priv, ulong id = 0UL)
        {
            if (priv == null || !priv.AnyAuthed())
            {
                return(string.Empty);
            }

            if (config.General.CupboardSettings.anyAuthed)
            {
                for (int i = 0; i < priv.authorizedPlayers.Count; i++)
                {
                    var player = priv.authorizedPlayers[i];

                    if (player != null && permission.UserHasPermission(player.userid.ToString(), config.General.permission))
                    {
                        return(player.userid.ToString());
                    }
                }
            }
            else
            {
                var player = priv.authorizedPlayers.Find(x => x.userid == id);

                if (player != null)
                {
                    return(player.userid.ToString());
                }
            }

            return(string.Empty);
        }
Example #6
0
        private bool RemoveFromWhiteList(BuildingPrivlidge cb, BasePlayer player)
        {
            if (!cb.IsAuthed(player))
            {
                return(false);
            }

            int i = 0;

            foreach (var authedPlayer in cb.authorizedPlayers)
            {
                if (authedPlayer.userid == player.userID)
                {
                    cb.authorizedPlayers.RemoveAt(i);
                    cb.SendNetworkUpdate();
                    if (cb.CheckEntity(player))
                    {
                        player.SetInsideBuildingPrivilege(cb, false);
                    }

                    return(true);
                }
                i++;
            }

            return(false);
        }
Example #7
0
 public void RemoveBuildingPrivilege(BuildingPrivlidge ent)
 {
     if (!(ent == null))
     {
         buildingPrivileges.Remove(ent);
     }
 }
Example #8
0
 ///////////////////////////////////////////////////////////////
 /// <summary>
 /// Called when the player clears a cupboard
 /// </summary>
 /// <param name="privilege"></param>
 /// <param name="player"></param>
 /// ///////////////////////////////////////////////////////////////
 // ReSharper disable once UnusedMember.Local
 void OnCupboardClearList(BuildingPrivlidge privilege, BasePlayer player)
 {
     if (CheckPermission(player, UsePermission, false))
     {
         PrintToChat(player, $"{_pluginConfig.Prefix} {Lang("Cleared", player.UserIDString)}");
     }
 }
Example #9
0
        static bool CanAuthorize(BuildingPrivlidge cupboard)
        {
            var owner       = cupboard.authorizedPlayers[0];
            var ownerPlayer = RustCore.FindPlayerById(owner.userid);

            return(ownerPlayer?.isConnected ?? true);
        }
Example #10
0
        /// <summary>
        /// Вызывается, когда игрок что-либо построил
        /// </summary>
        /// <param name="plan">Шпатель</param>
        /// <param name="go">Строение, которое игрок построил</param>
        void OnEntityBuilt(Planner plan, GameObject go)
        {
            if (go == null || plan == null)
            {
                return;
            }
            BuildingPrivlidge privlidge = go.ToBaseEntity() as BuildingPrivlidge;

            if (privlidge == null)
            {
                return;
            }
            var player = plan.GetOwnerPlayer();

            if (player == null)
            {
                return;
            }
            if (ignorePlayers.Contains(player.userID))
            {
                return;
            }
            List <ulong> friends = Friends?.Call("ApiGetFriends", player.userID) as List <ulong>;

            if (friends == null)
            {
                return;
            }
            CupboardAuth(privlidge, friends);
            SendReply(player, Messages["deployCupboardMessage"]);
        }
        private IEnumerator SetupIoEntities()
        {
            List <IOEntity> ioEntities = BaseNetworkable.serverEntities.OfType <IOEntity>().ToList();

            for (int i = 0; i < ioEntities.Count; i++)
            {
                IOEntity entity = ioEntities[i];
                if (entity.OwnerID == 0)
                {
                    continue;
                }

                if (i % _pluginConfig.RepairsPerFrame == 0)
                {
                    yield return(null);
                }

                BuildingPrivlidge priv = entity.GetBuildingPrivilege();
                if (priv == null)
                {
                    continue;
                }

                if (!_ioEntity.ContainsKey(priv.buildingID))
                {
                    _ioEntity[priv.buildingID] = new List <IOEntity> {
                        entity
                    };
                }
                else
                {
                    _ioEntity[priv.buildingID].Add(entity);
                }
            }
        }
Example #12
0
        /// <summary>
        /// Clear lock's whitelist
        /// </summary>
        /// <param name="privilege"></param>
        void ClearAuthorizations(BuildingPrivlidge privilege)
        {
            BaseEntity baseLock = privilege.GetSlot(BaseEntity.Slot.Lock);

            if (baseLock is CodeLock)
            {
                CodeLock masterLock = baseLock as CodeLock;
                BuildingManager.Building building = privilege.GetBuilding();
                foreach (BuildingBlock block in building.buildingBlocks)
                {
                    if (block.GetSlot(BaseEntity.Slot.Lock) is CodeLock)
                    {
                        CodeLock codeLock = (block.GetSlot(BaseEntity.Slot.Lock) as CodeLock);
                        if (masterLock.code == codeLock.code)
                        {
                            codeLock.whitelistPlayers.Clear();
                            codeLock.SendNetworkUpdateImmediate();
                        }
                    }
                }
                foreach (DecayEntity entity in building.decayEntities)
                {
                    if (entity.GetSlot(BaseEntity.Slot.Lock) is CodeLock)
                    {
                        CodeLock codeLock = (entity.GetSlot(BaseEntity.Slot.Lock) as CodeLock);
                        if (masterLock.code == codeLock.code)
                        {
                            codeLock.whitelistPlayers.Clear();
                            codeLock.SendNetworkUpdateImmediate();
                        }
                    }
                }
            }
        }
Example #13
0
 public void AddBuildingPrivilege(BuildingPrivlidge ent)
 {
     if (!(ent == null) && !buildingPrivileges.Contains(ent))
     {
         buildingPrivileges.Add(ent);
     }
 }
Example #14
0
        /// <summary>
        /// Close all linked doors in the building
        /// </summary>
        /// <param name="privilege"></param>
        /// <param name="player"></param>
        private void CloseDoors(BuildingPrivlidge privilege, BasePlayer player)
        {
            uint       doorCount = 0;
            BaseEntity baseLock  = privilege.GetSlot(BaseEntity.Slot.Lock);

            if (baseLock is CodeLock)
            {
                CodeLock masterLock = baseLock as CodeLock;
                BuildingManager.Building building = privilege.GetBuilding();
                foreach (DecayEntity entity in building.decayEntities)
                {
                    if (entity.GetSlot(BaseEntity.Slot.Lock) is CodeLock && entity is Door)
                    {
                        CodeLock codeLock = (entity.GetSlot(BaseEntity.Slot.Lock) as CodeLock);
                        if (masterLock.code == codeLock.code && masterLock != codeLock)
                        {
                            if ((entity as Door).HasFlag(BaseEntity.Flags.Open))
                            {
                                (entity as Door).SetFlag(BaseEntity.Flags.Open, false);
                                (entity as Door).SendNetworkUpdate();
                                doorCount++;
                            }
                        }
                    }
                }
                player.ChatMessage(Lang("ClosedDoors", player.UserIDString, doorCount));
            }
        }
        private void SendNotifications()
        {
            if ((bool)Config["AutomaticNotificationsEnabled"])
            {
                timer.Repeat(Convert.ToSingle(Config["NotificationIntervalInMinutes"]) * 60, 0, () =>
                {
                    foreach (var player in BasePlayer.activePlayerList)
                    {
                        BuildingPrivlidge priv = player.GetBuildingPrivilege();
                        if (!priv)
                        {
                            return;
                        }
                        if (!priv.IsAuthed(player) || !player.IsAdmin)
                        {
                            return;
                        }
                        float minutesLeft = priv.GetProtectedMinutes();

                        if (minutesLeft < Convert.ToSingle(Config["MinutesLeftNeededToSendNotification"]) && minutesLeft > 0f)
                        {
                            PrintToChat(player, String.Format(lang.GetMessage("PrimaryDecayNotification", this, player.UserIDString), minutesLeft));
                        }
                        else if (minutesLeft == 0f)
                        {
                            PrintToChat(player, lang.GetMessage("FinalDecayNotification", this, player.UserIDString));
                        }
                    }
                });
            }
        }
Example #16
0
        void OnEntitySpawned(BaseNetworkable entity)
        {
            if (!init)
            {
                return;
            }
            if (entity?.net?.ID == null)
            {
                return;
            }
            if (IsDecayEntity(entity) && !decayEntities.Contains((BaseCombatEntity)entity))
            {
                decayEntities.Add((BaseCombatEntity)entity);
            }
            BuildingPrivlidge privlidge = entity as BuildingPrivlidge;

            if (privlidge != null)
            {
                cupboards.Add(privlidge.net.ID);
            }
            NextTick(() =>
            {
                DecayEntity decEnt = entity as DecayEntity;
                if (decEnt != null)
                {
                    decEnt.CancelInvoke("RunDecay");
                }
            });
        }
            // Code stolen from Assembly-CSharp.dll -> BasePlayer.cs
            public static BuildingPrivlidge GetBuildingPrivilege(OBB obb)
            {
                BuildingBlock     buildingBlock1    = (BuildingBlock)null;
                BuildingPrivlidge buildingPrivlidge = (BuildingPrivlidge)null;

                System.Collections.Generic.List <BuildingBlock> list = Facepunch.Pool.GetList <BuildingBlock>();
                Vis.Entities <BuildingBlock>(obb.position, 16f + obb.extents.magnitude, list, 2097152, QueryTriggerInteraction.Collide);
                for (int index = 0; index < list.Count; ++index)
                {
                    BuildingBlock buildingBlock2 = list[index];
                    if (buildingBlock2.IsOlderThan((BaseEntity)buildingBlock1) && (double)obb.Distance(buildingBlock2.WorldSpaceBounds()) <= 16.0)
                    {
                        BuildingManager.Building building = buildingBlock2.GetBuilding();
                        if (building != null)
                        {
                            BuildingPrivlidge buildingPrivilege = building.GetDominatingBuildingPrivilege();
                            if (!((UnityEngine.Object)buildingPrivilege == (UnityEngine.Object)null))
                            {
                                buildingBlock1    = buildingBlock2;
                                buildingPrivlidge = buildingPrivilege;
                            }
                        }
                    }
                }
                Facepunch.Pool.FreeList <BuildingBlock>(ref list);
                return(buildingPrivlidge);
            }
Example #18
0
 private void OnEntityKill(BuildingPrivlidge entity)
 {
     if (IDData.IDs.ContainsKey(entity.net.ID))
     {
         IDData.IDs.Remove(entity.net.ID);
     }
 }
        void TcstatusCommand(BasePlayer player, string command, string[] args)
        {
            if (!permission.UserHasPermission(player.UserIDString, "decaynotifications.use"))
            {
                PrintToChat(player, lang.GetMessage("NoPermission", this, player.UserIDString));
                return;
            }
            BuildingPrivlidge priviledge = player.GetBuildingPrivilege();

            if (!priviledge)
            {
                PrintToChat(player, lang.GetMessage("NoPriviledge", this, player.UserIDString));
                return;
            }
            if (!priviledge.IsAuthed(player) || !player.IsAdmin)
            {
                return;
            }

            float minutesLeft = priviledge.GetProtectedMinutes();

            if (minutesLeft > 0f)
            {
                PrintToChat(player, String.Format(lang.GetMessage("PrimaryDecayNotification", this, player.UserIDString), minutesLeft));
            }
            else if (minutesLeft == 0)
            {
                PrintToChat(player, lang.GetMessage("FinalDecayNotification", this, player.UserIDString));
            }
            return;
        }
Example #20
0
        private void OnItemDeployed(Deployer deployer, BaseEntity entity)
        {
            BuildingPrivlidge cupboard = entity as BuildingPrivlidge;

            if (cupboard == null)
            {
                return;
            }

            BasePlayer player = deployer.ToPlayer();

            if (config.RestrictToolCupboards && player != null)
            {
                IEnumerable <KeyValuePair <uint, List <PlayerNameID> > > cupboards = toolCupboards.Where(c => c.Value.Contains(new PlayerNameID {
                    userid = player.userID
                }));

                if (cupboards.Count() > config.MaxToolCupboards)
                {
                    cupboard.Kill();
                    Message(player.IPlayer, "MaxToolCupboards", config.MaxToolCupboards);
                }
            }
            else
            {
                if (!toolCupboards.ContainsKey(cupboard.net.ID))
                {
                    toolCupboards.Add(cupboard.net.ID, cupboard.authorizedPlayers);
                }
            }
        }
Example #21
0
        private void AuthToCupboard(BuildingPrivlidge cupboard, Dictionary <ulong, string> authList, BasePlayer player = null)
        {
            IEnumerable <ulong> currentAuth = cupboard.authorizedPlayers.Select(x => x.userid);

            foreach (var friend in authList)
            {
                if (currentAuth.Contains(friend.Key))
                {
                    continue;
                }

                cupboard.authorizedPlayers.Add(new ProtoBuf.PlayerNameID
                {
                    userid     = friend.Key,
                    username   = friend.Value,
                    ShouldPool = true
                });
            }
            cupboard.SendNetworkUpdateImmediate();
            if (player != null)
            {
                player.SendNetworkUpdateImmediate();
                SendReply(player, string.Format(msg("cupboardSuccess"), authList.Count));
            }
        }
Example #22
0
            void TryLoadInfo(AreaInfo info)
            {
                BuildingPrivlidge cupboard = null;

                if (info.CupboardId != null)
                {
                    cupboard = BaseNetworkable.serverEntities.Find((uint)info.CupboardId) as BuildingPrivlidge;
                    if (cupboard == null)
                    {
                        Instance.Log($"[LOAD] Area {Id}: Cupboard entity {info.CupboardId} not found, treating as unclaimed");
                        return;
                    }
                }

                if (info.FactionId != null)
                {
                    Faction faction = Instance.Factions.Get(info.FactionId);
                    if (faction == null)
                    {
                        Instance.Log($"[LOAD] Area {Id}: Claimed by unknown faction {info.FactionId}, treating as unclaimed");
                        return;
                    }
                }

                Name          = info.Name;
                Type          = info.Type;
                FactionId     = info.FactionId;
                ClaimantId    = info.ClaimantId;
                ClaimCupboard = cupboard;

                if (FactionId != null)
                {
                    Instance.Log($"[LOAD] Area {Id}: Claimed by {FactionId}, type = {Type}, cupboard = {Util.Format(ClaimCupboard)}");
                }
            }
    private void Split(BuildingManager.Building building)
    {
        while (building.HasBuildingBlocks())
        {
            BuildingBlock          buildingBlock = building.buildingBlocks.get_Item(0);
            uint                   newID         = BuildingManager.server.NewBuildingID();
            Action <BuildingBlock> action        = (Action <BuildingBlock>)(b => b.AttachToBuilding(newID));
            buildingBlock.EntityLinkBroadcast <BuildingBlock>(action);
        }
        while (building.HasBuildingPrivileges())
        {
            BuildingPrivlidge buildingPrivlidge   = building.buildingPrivileges.get_Item(0);
            BuildingBlock     nearbyBuildingBlock = buildingPrivlidge.GetNearbyBuildingBlock();
            buildingPrivlidge.AttachToBuilding(Object.op_Implicit((Object)nearbyBuildingBlock) ? nearbyBuildingBlock.buildingID : 0U);
        }
        while (building.HasDecayEntities())
        {
            DecayEntity   decayEntity         = building.decayEntities.get_Item(0);
            BuildingBlock nearbyBuildingBlock = decayEntity.GetNearbyBuildingBlock();
            decayEntity.AttachToBuilding(Object.op_Implicit((Object)nearbyBuildingBlock) ? nearbyBuildingBlock.buildingID : 0U);
        }
        if (!ConVar.AI.nav_carve_use_building_optimization)
        {
            return;
        }
        building.isNavMeshCarvingDirty = true;
        int ticks = 2;

        this.UpdateNavMeshCarver(building, ref ticks, 0);
    }
Example #24
0
        void AuthorizePlayer(BasePlayer player, string command, string[] args)
        {
            if (!permission.UserHasPermission(player.UserIDString, "tcmanager.auth") && !player.IsAdmin)
            {
                player.ChatMessage(Lang("NoCommandPermission", player.UserIDString));
                return;
            }
            BuildingPrivlidge privilege = player.GetBuildingPrivilege();

            if (!privilege)
            {
                player.ChatMessage(Lang("NoBuildingPrivilege", player.UserIDString));
                return;
            }
            if (!privilege.IsAuthed(player))
            {
                player.ChatMessage(Lang("NoAuthorization", player.UserIDString));
                return;
            }
            if (args.Length == 0)
            {
                player.ChatMessage(Lang("AuthUsage", player.UserIDString));
                return;
            }

            List <BasePlayer> playerList = FindPlayer(args[0]);

            if (playerList.Count == 1)
            {
                BasePlayer newPlayer = playerList[0];
                privilege.authorizedPlayers.Add(new ProtoBuf.PlayerNameID()
                {
                    userid = newPlayer.userID, username = newPlayer.displayName
                });
                privilege.SendNetworkUpdateImmediate();
                player.ChatMessage(Lang("AuthorizePlayer", player.UserIDString, newPlayer.displayName));
                if (MasterLock)
                {
                    MasterLock.Call("AddAuthorization", privilege, newPlayer, player);
                }
            }
            else if (playerList.Count == 0)
            {
                player.ChatMessage(Lang("PlayerNotFound", player.UserIDString, args[0].ToString()));
            }
            else
            {
                String playerNames = String.Empty;
                foreach (BasePlayer bPlayer in playerList)
                {
                    if (!String.IsNullOrEmpty(playerNames))
                    {
                        playerNames += ", ";
                    }
                    playerNames += bPlayer.displayName;
                }
                player.ChatMessage(Lang("MultiplePlayers", player.UserIDString, playerNames));
            }
        }
Example #25
0
 static bool CanAuthorize(BuildingPrivlidge cupboard)
 {
     foreach (var authorized in cupboard.authorizedPlayers)
     {
         return(BasePlayer.Find(authorized.userid.ToString()));
     }
     return(false);
 }
Example #26
0
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Building Privilege Search
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        Dictionary <string, object> GetBuildingPrivilegeData(BuildingPrivlidge bp)
        {
            var bpdata = new Dictionary <string, object>();

            bpdata.Add("pos", bp.transform.position);

            return(bpdata);
        }
 public void RemoveBuildingPrivilege(BuildingPrivlidge ent)
 {
     if (Object.op_Equality((Object)ent, (Object)null))
     {
         return;
     }
     this.buildingPrivileges.Remove(ent);
 }
Example #28
0
 void OnCupboardClearList(BuildingPrivlidge privlidge, BasePlayer player)
 {
     timer.Once(0.1f, () => UseBuildingImage(player));
     foreach (var p in privlidge.authorizedPlayers.Select(p => BasePlayer.FindByID(p.userid)).Where(p => p != null))
     {
         timer.Once(0.1f, () => UseBuildingImage(p));
     }
 }
Example #29
0
 public void RemoveBuildingPrivilege(BuildingPrivlidge ent)
 {
     if (ent == null)
     {
         return;
     }
     this.buildingPrivileges.Remove(ent);
 }
 public void AddBuildingPrivilege(BuildingPrivlidge ent)
 {
     if (Object.op_Equality((Object)ent, (Object)null) || this.buildingPrivileges.Contains(ent))
     {
         return;
     }
     this.buildingPrivileges.Add(ent);
 }
Example #31
0
 public Array UserIDsFromBuildingPrivlidge(BuildingPrivlidge buildingpriv)
 {
     return buildingpriv.authorizedPlayers.Select(eid => eid.userid.ToString()).ToArray();
 }
Example #32
0
 private object IOnCupboardDeauthorize(BuildingPrivlidge priviledge, BaseEntity.RPCMessage msg)
 {
     return Interface.CallHook("OnCupboardDeauthorize", priviledge, msg.player);
 }
Example #33
0
 private void GetToolCupboardUsers(BasePlayer player, BuildingPrivlidge cupboard)
 {
     SendReply(player, string.Format("{0} - {1} {2} {3}",Toolcupboard,Math.Round(cupboard.transform.position.x).ToString(),Math.Round(cupboard.transform.position.y).ToString(),Math.Round(cupboard.transform.position.z).ToString()));
     if (cupboard.authorizedPlayers.Count == 0)
     {
         SendReply(player, noCupboardPlayers);
         return;
     }
     foreach (ProtoBuf.PlayerNameID pnid in cupboard.authorizedPlayers)
     {
         SendReply(player, string.Format("{0} - {1}", pnid.username.ToString(), pnid.userid.ToString()));
     }
 }