Ejemplo n.º 1
0
        /// <summary>
        /// Disables the player for the given <paramref name="reason"/>
        /// </summary>
        /// <param name="reason">The reason why the player was disabled.</param>
        /// <param name="flags">Flags to dictate where this event is logged to.</param>
        public virtual void Disable(string reason = "", DisableFlags flags = DisableFlags.WriteToLog)
        {
            LastThreat = DateTime.UtcNow;
            SetBuff(BuffID.Frozen, 330, true);
            SetBuff(BuffID.Stoned, 330, true);
            SetBuff(BuffID.Webbed, 330, true);

            if (ActiveChest != -1)
            {
                ActiveChest = -1;
                SendData(PacketTypes.ChestOpen, "", -1);
            }

            if (!string.IsNullOrEmpty(reason))
            {
                if ((DateTime.UtcNow - LastDisableNotification).TotalMilliseconds > 5000)
                {
                    if (flags.HasFlag(DisableFlags.WriteToConsole))
                    {
                        if (flags.HasFlag(DisableFlags.WriteToLog))
                        {
                            TShock.Log.ConsoleInfo("Player {0} has been disabled for {1}.", Name, reason);
                        }
                        else
                        {
                            Server.SendInfoMessage("Player {0} has been disabled for {1}.", Name, reason);
                        }
                    }

                    LastDisableNotification = DateTime.UtcNow;
                }
            }

            /*
             * Calling new StackTrace() is incredibly expensive, and must be disabled
             * in release builds.  Use a conditional call instead.
             */
            LogStackFrame();
        }
Ejemplo n.º 2
0
        internal void OnPlayerUpdate(object sender, PlayerUpdateEventArgs args)
        {
            DisableFlags disableFlags = TShock.Config.Settings.DisableSecondUpdateLogs ? DisableFlags.WriteToConsole : DisableFlags.WriteToLogAndConsole;
            bool         useItem      = args.Control.IsUsingItem;
            TSPlayer     player       = args.Player;
            string       itemName     = player.TPlayer.inventory[args.SelectedItem].Name;

            if (DataModel.ItemIsBanned(EnglishLanguage.GetItemNameById(player.TPlayer.inventory[args.SelectedItem].netID), args.Player))
            {
                player.TPlayer.controlUseItem = false;
                player.Disable($"holding banned item: {itemName}", disableFlags);

                SendCorrectiveMessage(player, itemName);

                player.TPlayer.Update(player.TPlayer.whoAmI);
                NetMessage.SendData((int)PacketTypes.PlayerUpdate, -1, player.Index, NetworkText.Empty, player.Index);

                args.Handled = true;
                return;
            }

            args.Handled = false;
            return;
        }
Ejemplo n.º 3
0
        /// <summary>Called by OnGameUpdate once per second to execute tasks regularly but not too often.</summary>
        /// <param name="args">The standard event arguments.</param>
        internal void OnSecondlyUpdate(EventArgs args)
        {
            DisableFlags disableFlags = TShock.Config.Settings.DisableSecondUpdateLogs ? DisableFlags.WriteToConsole : DisableFlags.WriteToLogAndConsole;

            foreach (TSPlayer player in TShock.Players)
            {
                if (player == null || !player.Active)
                {
                    continue;
                }

                // Untaint now, re-taint if they fail the check.
                UnTaint(player);

                // No matter the player type, we do a check when a player is holding an item that's banned.
                if (DataModel.ItemIsBanned(EnglishLanguage.GetItemNameById(player.TPlayer.inventory[player.TPlayer.selectedItem].netID), player))
                {
                    string itemName = player.TPlayer.inventory[player.TPlayer.selectedItem].Name;
                    player.Disable($"holding banned item: {itemName}", disableFlags);
                    SendCorrectiveMessage(player, itemName);
                }

                // If SSC isn't enabled OR if SSC is enabled and the player is logged in
                // In a case like this, we do the full check too.
                if (!Main.ServerSideCharacter || (Main.ServerSideCharacter && player.IsLoggedIn))
                {
                    // The Terraria inventory is composed of a multicultural set of arrays
                    // with various different contents and beliefs

                    // Armor ban checks
                    foreach (Item item in player.TPlayer.armor)
                    {
                        if (DataModel.ItemIsBanned(EnglishLanguage.GetItemNameById(item.type), player))
                        {
                            Taint(player);
                            SendCorrectiveMessage(player, item.Name);
                        }
                    }

                    // Dye ban checks
                    foreach (Item item in player.TPlayer.dye)
                    {
                        if (DataModel.ItemIsBanned(EnglishLanguage.GetItemNameById(item.type), player))
                        {
                            Taint(player);
                            SendCorrectiveMessage(player, item.Name);
                        }
                    }

                    // Misc equip ban checks
                    foreach (Item item in player.TPlayer.miscEquips)
                    {
                        if (DataModel.ItemIsBanned(EnglishLanguage.GetItemNameById(item.type), player))
                        {
                            Taint(player);
                            SendCorrectiveMessage(player, item.Name);
                        }
                    }

                    // Misc dye ban checks
                    foreach (Item item in player.TPlayer.miscDyes)
                    {
                        if (DataModel.ItemIsBanned(EnglishLanguage.GetItemNameById(item.type), player))
                        {
                            Taint(player);
                            SendCorrectiveMessage(player, item.Name);
                        }
                    }
                }
            }

            // Set the update time to now, so that we know when to execute next.
            // We do this at the end so that the task can't re-execute faster than we expected.
            // (If we did this at the start of the method, the method execution would count towards the timer.)
            LastTimelyRun = DateTime.UtcNow;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Disables the player for the given <paramref name="reason"/>
        /// </summary>
        /// <param name="reason">The reason why the player was disabled.</param>
        /// <param name="flags">Flags to dictate where this event is logged to.</param>
        public virtual void Disable(string reason = "", DisableFlags flags = DisableFlags.WriteToLog)
        {
            LastThreat = DateTime.UtcNow;
            SetBuff(BuffID.Frozen, 330, true);
            SetBuff(BuffID.Stoned, 330, true);
            SetBuff(BuffID.Webbed, 330, true);

            if (ActiveChest != -1)
            {
                ActiveChest = -1;
                SendData(PacketTypes.ChestOpen, "", -1);
            }

            if (!string.IsNullOrEmpty(reason))
            {
                if ((DateTime.UtcNow - LastDisableNotification).TotalMilliseconds > 5000)
                {
                    if (flags.HasFlag(DisableFlags.WriteToConsole))
                    {
                        if (flags.HasFlag(DisableFlags.WriteToLog))
                        {
                            TShock.Log.ConsoleInfo("Player {0} has been disabled for {1}.", Name, reason);
                        }
                        else
                        {
                            Server.SendInfoMessage("Player {0} has been disabled for {1}.", Name, reason);
                        }
                    }

                    LastDisableNotification = DateTime.UtcNow;
                }
            }

            var trace = new StackTrace();
            StackFrame frame = null;
            frame = trace.GetFrame(1);
            if (frame != null && frame.GetMethod().DeclaringType != null)
                TShock.Log.Debug(frame.GetMethod().DeclaringType.Name + " called Disable().");
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Disables the player for the given <paramref name="reason"/>
        /// </summary>
        /// <param name="reason">The reason why the player was disabled.</param>
        /// <param name="flags">Flags to dictate where this event is logged to.</param>
        public virtual void Disable(string reason = "", DisableFlags flags = DisableFlags.WriteToLog)
        {
            LastThreat = DateTime.UtcNow;
            SetBuff(BuffID.Frozen, 330, true);
            SetBuff(BuffID.Stoned, 330, true);
            SetBuff(BuffID.Webbed, 330, true);

            if (ActiveChest != -1)
            {
                ActiveChest = -1;
                SendData(PacketTypes.ChestOpen, "", -1);
            }

            if (!string.IsNullOrEmpty(reason))
            {
                if ((DateTime.UtcNow - LastDisableNotification).TotalMilliseconds > 5000)
                {
                    if (flags.HasFlag(DisableFlags.WriteToConsole))
                    {
                        if (flags.HasFlag(DisableFlags.WriteToLog))
                        {
                            TShock.Log.ConsoleInfo("Player {0} has been disabled for {1}.", Name, reason);
                        }
                        else
                        {
                            Server.SendInfoMessage("Player {0} has been disabled for {1}.", Name, reason);
                        }
                    }

                    LastDisableNotification = DateTime.UtcNow;
                }
            }

            /*
             * Calling new StackTrace() is incredibly expensive, and must be disabled
             * in release builds.  Use a conditional call instead.
             */
            LogStackFrame();
        }