Inheritance: TerrariaPlugin
Esempio n. 1
0
        private static bool HandlePlayerBuff(GetDataHandlerArgs args)
        {
            var id   = args.Data.ReadInt8();
            var type = args.Data.ReadInt8();
            var time = args.Data.ReadInt16();

            if (TShock.CheckIgnores(args.Player))
            {
                args.Player.SendData(PacketTypes.PlayerBuff, "", id);
                return(true);
            }
            if (!TShock.Players[id].TPlayer.hostile)
            {
                args.Player.SendData(PacketTypes.PlayerBuff, "", id);
                return(true);
            }
            if (TShock.Config.RangeChecks && ((Math.Abs(args.Player.TileX - TShock.Players[id].TileX) > 64) || (Math.Abs(args.Player.TileY - TShock.Players[id].TileY) > 64)))
            {
                args.Player.SendData(PacketTypes.PlayerBuff, "", id);
                return(true);
            }
            if ((DateTime.UtcNow - args.Player.LastThreat).TotalMilliseconds < 5000)
            {
                args.Player.SendData(PacketTypes.PlayerBuff, "", id);
                return(true);
            }

            if (WhitelistBuffMaxTime[type] > 0 && time <= WhitelistBuffMaxTime[type])
            {
                return(false);
            }

            args.Player.SendData(PacketTypes.PlayerBuff, "", id);
            return(true);
        }
Esempio n. 2
0
        private static bool HandleTileKill(GetDataHandlerArgs args)
        {
            var tileX = args.Data.ReadInt32();
            var tileY = args.Data.ReadInt32();

            if (tileX < 0 || tileX >= Main.maxTilesX || tileY < 0 || tileY >= Main.maxTilesY)
            {
                return(false);
            }

            if (TShock.CheckIgnores(args.Player))
            {
                args.Player.SendTileSquare(tileX, tileY);
                return(true);
            }

            if (Main.tile[tileX, tileY].type != 0x15 && (!TShock.Utils.MaxChests() && Main.tile[tileX, tileY].type != 0)) //Chest
            {
                args.Player.SendTileSquare(tileX, tileY);
                return(true);
            }

            if (TShock.CheckTilePermission(args.Player, tileX, tileY))
            {
                args.Player.SendTileSquare(tileX, tileY);
                return(true);
            }

            return(false);
        }
Esempio n. 3
0
 public static bool CheckTilePermission(TSPlayer player, int tileX, int tileY)
 {
     if (!player.Group.HasPermission(Permissions.canbuild))
     {
         player.SendMessage("You do not have permission to build!", Color.Red);
         return(true);
     }
     if (!player.Group.HasPermission(Permissions.editspawn) && !TShock.Regions.CanBuild(tileX, tileY, player) && TShock.Regions.InArea(tileX, tileY))
     {
         player.SendMessage("Region protected from changes.", Color.Red);
         return(true);
     }
     if (TShock.Config.DisableBuild)
     {
         if (!player.Group.HasPermission(Permissions.editspawn))
         {
             player.SendMessage("World protected from changes.", Color.Red);
             return(true);
         }
     }
     if (TShock.Config.SpawnProtection)
     {
         if (!player.Group.HasPermission(Permissions.editspawn))
         {
             var flag = TShock.CheckSpawn(tileX, tileY);
             if (flag)
             {
                 player.SendMessage("Spawn protected from changes.", Color.Red);
                 return(true);
             }
         }
     }
     return(false);
 }
Esempio n. 4
0
 /// <summary>
 /// Reloads all configuration settings, groups, regions and raises the reload event.
 /// </summary>
 public void Reload(TSPlayer player)
 {
     FileTools.SetupConfig();
     TShock.HandleCommandLinePostConfigLoad(Environment.GetCommandLineArgs());
     TShock.Groups.LoadPermisions();
     TShock.Regions.ReloadAllRegions();
     Hooks.GeneralHooks.OnReloadEvent(player);
 }
Esempio n. 5
0
        public virtual bool SendRawData(byte[] data)
        {
            if (!RealPlayer || !ConnectionAlive)
            {
                return(false);
            }

            return(TShock.SendBytes(Netplay.serverSock[Index], data));
        }
Esempio n. 6
0
        /// <summary>Creates an ItemBan system given a plugin to register events to and a database.</summary>
        /// <param name="plugin">The executing plugin.</param>
        /// <param name="database">The database the item ban information is stored in.</param>
        /// <returns>A new item ban system.</returns>
        internal ItemBans(TShock plugin, IDbConnection database)
        {
            DataModel = new ItemManager(database);
            Plugin    = plugin;

            ServerApi.Hooks.GameUpdate.Register(plugin, OnGameUpdate);
            GetDataHandlers.PlayerUpdate    += OnPlayerUpdate;
            GetDataHandlers.ChestItemChange += OnChestItemChange;
            GetDataHandlers.TileEdit        += OnTileEdit;
        }
Esempio n. 7
0
 /// <summary>
 /// Reloads all configuration settings, groups, regions and raises the reload event.
 /// </summary>
 public void Reload()
 {
     FileTools.SetupConfig();
     TShock.HandleCommandLinePostConfigLoad(Environment.GetCommandLineArgs());
     TShock.Groups.LoadPermisions();
     TShock.Regions.Reload();
     TShock.ItemBans.DataModel.UpdateItemBans();
     TShock.ProjectileBans.UpdateBans();
     TShock.TileBans.UpdateBans();
 }
Esempio n. 8
0
        private static bool HandleTileKill(GetDataHandlerArgs args)
        {
            int tilex = args.Data.ReadInt32();
            int tiley = args.Data.ReadInt32();

            if (tilex < 0 || tilex >= Main.maxTilesX || tiley < 0 || tiley >= Main.maxTilesY)
            {
                return(false);
            }

            if (Main.tile[tilex, tiley].type != 0x15 && (!Tools.MaxChests() && Main.tile[tilex, tiley].type != 0)) //Chest
            {
                Log.Debug(string.Format("TileKill(TileXY:{0}_{1}, Type:{2})",
                                        tilex, tiley, Main.tile[tilex, tiley].type));
                Tools.ForceKick(args.Player, string.Format(TShock.Config.TileKillAbuseReason, Main.tile[tilex, tiley].type));
                return(true);
            }
            if (!args.Player.Group.HasPermission(Permissions.canbuild))
            {
                args.Player.SendMessage("You do not have permission to build!", Color.Red);
                args.Player.SendTileSquare(tilex, tiley);
                return(true);
            }
            if (!args.Player.Group.HasPermission(Permissions.editspawn) && !TShock.Regions.CanBuild(tilex, tiley, args.Player) && TShock.Regions.InArea(tilex, tiley))
            {
                args.Player.SendMessage("Region protected from changes.", Color.Red);
                args.Player.SendTileSquare(tilex, tiley);
                return(true);
            }
            if (TShock.Config.DisableBuild)
            {
                if (!args.Player.Group.HasPermission(Permissions.editspawn))
                {
                    args.Player.SendMessage("World protected from changes.", Color.Red);
                    args.Player.SendTileSquare(tilex, tiley);
                    return(true);
                }
            }
            if (TShock.Config.SpawnProtection)
            {
                if (!args.Player.Group.HasPermission(Permissions.editspawn))
                {
                    var flag = TShock.CheckSpawn(tilex, tiley);
                    if (flag)
                    {
                        args.Player.SendMessage("Spawn protected from changes.", Color.Red);
                        args.Player.SendTileSquare(tilex, tiley);
                        return(true);
                    }
                }
            }
            return(false);
        }
Esempio n. 9
0
        private static bool HandleSign(GetDataHandlerArgs args)
        {
            var id = args.Data.ReadInt16();
            var x  = args.Data.ReadInt32();
            var y  = args.Data.ReadInt32();

            if (TShock.CheckTilePermission(args.Player, x, y))
            {
                args.Player.SendData(PacketTypes.SignNew, "", id);
                return(true);
            }
            return(false);
        }
Esempio n. 10
0
        private static bool HandlePlayerUpdate(GetDataHandlerArgs args)
        {
            var plr     = args.Data.ReadInt8();
            var control = args.Data.ReadInt8();
            var item    = args.Data.ReadInt8();
            var pos     = new Vector2(args.Data.ReadSingle(), args.Data.ReadSingle());
            var vel     = new Vector2(args.Data.ReadSingle(), args.Data.ReadSingle());

            if (item < 0 || item >= args.TPlayer.inventory.Length)
            {
                return(true);
            }

            if ((control & 32) == 32)
            {
                if (!args.Player.Group.HasPermission(Permissions.usebanneditem) && TShock.Itembans.ItemIsBanned(args.TPlayer.inventory[item].name))
                {
                    args.Player.LastThreat = DateTime.UtcNow;
                    args.Player.SendMessage(string.Format("You cannot use {0} on this server. Your actions are being ignored.", args.TPlayer.inventory[item].name), Color.Red);
                    return(true);
                }
            }

            if (!pos.Equals(args.Player.LastNetPosition))
            {
                float distance = Vector2.Distance(new Vector2((pos.X / 16f), (pos.Y / 16f)), new Vector2(Main.spawnTileX, Main.spawnTileY));
                if (TShock.CheckIgnores(args.Player) && distance > 6f)
                {
                    if (args.Player.IgnoreActionsForCheating)
                    {
                        args.Player.SendMessage("You have been disabled for cheating! Please login with a new character!", Color.Red);
                    }
                    else if (TShock.Config.ServerSideInventory && !args.Player.IsLoggedIn)
                    {
                        args.Player.SendMessage("Server Side Inventory is enabled! Please /register or /login to play!", Color.Red);
                    }
                    else if (TShock.Config.AlwaysPvP && !args.TPlayer.hostile)
                    {
                        args.Player.SendMessage("PvP is forced! Enable PvP else you can't move or do anything!", Color.Red);
                    }
                    args.Player.Spawn();
                    return(true);
                }
            }

            args.Player.LastNetPosition = pos;
            return(false);
        }
Esempio n. 11
0
        private static bool HandlePlayerAnimation(GetDataHandlerArgs args)
        {
            if (TShock.CheckIgnores(args.Player))
            {
                args.Player.SendData(PacketTypes.PlayerAnimation, "", args.Player.Index);
                return(true);
            }

            if ((DateTime.UtcNow - args.Player.LastThreat).TotalMilliseconds < 5000)
            {
                args.Player.SendData(PacketTypes.PlayerAnimation, "", args.Player.Index);
                return(true);
            }

            return(false);
        }
Esempio n. 12
0
        private static bool HandleChestOpen(GetDataHandlerArgs args)
        {
            var x = args.Data.ReadInt32();
            var y = args.Data.ReadInt32();

            if (TShock.CheckIgnores(args.Player))
            {
                return(true);
            }

            if (TShock.Config.RangeChecks && ((Math.Abs(args.Player.TileX - x) > 32) || (Math.Abs(args.Player.TileY - y) > 32)))
            {
                return(true);
            }
            return(false);
        }
Esempio n. 13
0
        private static bool HandleNpcStrike(GetDataHandlerArgs args)
        {
            var id        = args.Data.ReadInt8();
            var direction = args.Data.ReadInt8();
            var dmg       = args.Data.ReadInt16();
            var pvp       = args.Data.ReadInt8();
            var crit      = args.Data.ReadInt8();

            if (Main.npc[id] == null)
            {
                return(true);
            }

            if (dmg > 175)
            {
                args.Player.SendData(PacketTypes.NpcUpdate, "", id);
                return(true);
            }

            if (TShock.CheckIgnores(args.Player))
            {
                args.Player.SendData(PacketTypes.NpcUpdate, "", id);
                return(true);
            }

            if (Main.npc[id].townNPC && !args.Player.Group.HasPermission(Permissions.movenpc))
            {
                args.Player.SendData(PacketTypes.NpcUpdate, "", id);
                return(true);
            }

            if (TShock.Config.RangeChecks && ((Math.Abs(args.Player.TileX - (Main.npc[id].position.X / 16f)) > 128) || (Math.Abs(args.Player.TileY - (Main.npc[id].position.Y / 16f)) > 128)))
            {
                args.Player.SendData(PacketTypes.NpcUpdate, "", id);
                return(true);
            }

            if ((DateTime.UtcNow - args.Player.LastThreat).TotalMilliseconds < 5000)
            {
                args.Player.SendData(PacketTypes.NpcUpdate, "", id);
                return(true);
            }

            return(false);
        }
Esempio n. 14
0
 /*
  * /// <summary>
  * /// Maximum number of bytes to send per update per socket
  * /// </summary>
  * public int BytesPerUpdate { get; set; }
  *
  * private readonly TShock plugin;
  *
  * private PacketBuffer[] buffers = new PacketBuffer[Netplay.Clients.Length];
  *
  * private int[] Bytes = new int[52];
  * private int[] Packets = new int[52];
  * private int[] Compressed = new int[52];
  *
  #if DEBUG_NET
  * Command dump;
  * Command flush;
  #endif
  */
 public PacketBufferer(TShock p)
 {
     /*plugin = p;
      * BytesPerUpdate = 0xFFFF;
      * for (int i = 0; i < buffers.Length; i++)
      *      buffers[i] = new PacketBuffer();
      *
      #if DEBUG_NET
      * dump = new Command("superadmin", Dump, "netdump");
      * flush = new Command("superadmin", Flush, "netflush");
      * Commands.ChatCommands.Add(dump);
      * Commands.ChatCommands.Add(flush);
      #endif
      *
      * ServerApi.Hooks.NetSendBytes.Register(plugin, ServerHooks_SendBytes);
      * ServerApi.Hooks.ServerSocketReset.Register(plugin, ServerHooks_SocketReset);
      * ServerApi.Hooks.GamePostUpdate.Register(plugin, GameHooks_Update);*/
 }
Esempio n. 15
0
        private static bool HandleProjectileNew(GetDataHandlerArgs args)
        {
            var ident     = args.Data.ReadInt16();
            var pos       = new Vector2(args.Data.ReadSingle(), args.Data.ReadSingle());
            var vel       = new Vector2(args.Data.ReadSingle(), args.Data.ReadSingle());
            var knockback = args.Data.ReadSingle();
            var dmg       = args.Data.ReadInt16();
            var owner     = args.Data.ReadInt8();
            var type      = args.Data.ReadInt8();

            var index = TShock.Utils.SearchProjectile(ident);

            if (index > Main.maxProjectiles || index < 0)
            {
                return(true);
            }

            if (args.Player.Index != owner)
            {
                args.Player.SendData(PacketTypes.ProjectileNew, "", index);
                return(true);
            }

            if (dmg > 175)
            {
                args.Player.SendData(PacketTypes.ProjectileNew, "", index);
                return(true);
            }

            if (TShock.CheckIgnores(args.Player))
            {
                args.Player.SendData(PacketTypes.ProjectileNew, "", index);
                return(true);
            }

            if (TShock.CheckProjectilePermission(args.Player, index, type))
            {
                args.Player.LastThreat = DateTime.UtcNow;
                args.Player.SendData(PacketTypes.ProjectileNew, "", index);
                return(true);
            }

            return(false);
        }
Esempio n. 16
0
        private static bool UpdateNPCHome(GetDataHandlerArgs args)
        {
            var id       = args.Data.ReadInt16();
            var x        = args.Data.ReadInt16();
            var y        = args.Data.ReadInt16();
            var homeless = args.Data.ReadInt8();

            if (!args.Player.Group.HasPermission(Permissions.movenpc))
            {
                args.Player.SendMessage("You do not have permission to relocate NPCs.", Color.Red);
                args.Player.SendData(PacketTypes.UpdateNPCHome, "", id, Main.npc[id].homeTileX, Main.npc[id].homeTileY, Convert.ToByte(Main.npc[id].homeless));
                return(true);
            }

            if (TShock.CheckTilePermission(args.Player, x, y))
            {
                args.Player.SendData(PacketTypes.UpdateNPCHome, "", id, Main.npc[id].homeTileX, Main.npc[id].homeTileY, Convert.ToByte(Main.npc[id].homeless));
                return(true);
            }
            return(false);
        }
Esempio n. 17
0
        private static bool HandleProjectileKill(GetDataHandlerArgs args)
        {
            var ident = args.Data.ReadInt16();
            var owner = args.Data.ReadInt8();

            if (args.Player.Index != owner)
            {
                return(true);
            }

            var index = TShock.Utils.SearchProjectile(ident);

            if (index > Main.maxProjectiles || index < 0)
            {
                return(true);
            }

            int type = Main.projectile[index].type;

            if (args.Player.Index != Main.projectile[index].owner)
            {
                args.Player.SendData(PacketTypes.ProjectileNew, "", index);
                return(true);
            }

            if (TShock.CheckIgnores(args.Player))
            {
                args.Player.SendData(PacketTypes.ProjectileNew, "", index);
                return(true);
            }

            if (TShock.CheckProjectilePermission(args.Player, index, type))
            {
                args.Player.LastThreat = DateTime.UtcNow;
                args.Player.SendData(PacketTypes.ProjectileNew, "", index);
                return(true);
            }

            return(false);
        }
Esempio n. 18
0
        private static bool HandleItemDrop(GetDataHandlerArgs args)
        {
            var id     = args.Data.ReadInt16();
            var pos    = new Vector2(args.Data.ReadSingle(), args.Data.ReadSingle());
            var vel    = new Vector2(args.Data.ReadSingle(), args.Data.ReadSingle());
            var stacks = args.Data.ReadInt8();
            var prefix = args.Data.ReadInt8();
            var type   = args.Data.ReadInt16();

            if (type == 0) //Item removed, let client do this to prevent item duplication client side
            {
                return(false);
            }

            if (TShock.Config.RangeChecks && ((Math.Abs(args.Player.TileX - (pos.X / 16f)) > 64) || (Math.Abs(args.Player.TileY - (pos.Y / 16f)) > 64)))
            {
                args.Player.SendData(PacketTypes.ItemDrop, "", id);
                return(true);
            }

            Item item = new Item();

            item.netDefaults(type);
            if (stacks > item.maxStack || TShock.Itembans.ItemIsBanned(item.name))
            {
                args.Player.SendData(PacketTypes.ItemDrop, "", id);
                return(true);
            }

            if (TShock.CheckIgnores(args.Player))
            {
                args.Player.SendData(PacketTypes.ItemDrop, "", id);
                return(true);
            }

            return(false);
        }
Esempio n. 19
0
        private static bool HandleChestItem(GetDataHandlerArgs args)
        {
            var id     = args.Data.ReadInt16();
            var slot   = args.Data.ReadInt8();
            var stacks = args.Data.ReadInt8();
            var prefix = args.Data.ReadInt8();
            var type   = args.Data.ReadInt16();

            if (args.TPlayer.chest != id)
            {
                return(false);
            }

            if (TShock.CheckIgnores(args.Player))
            {
                args.Player.SendData(PacketTypes.ChestItem, "", id, slot);
                return(true);
            }

            Item item = new Item();

            item.netDefaults(type);
            if (stacks > item.maxStack || TShock.Itembans.ItemIsBanned(item.name))
            {
                args.Player.SendData(PacketTypes.ChestItem, "", id, slot);
                return(false);
            }

            if (TShock.CheckTilePermission(args.Player, Main.chest[id].x, Main.chest[id].y))
            {
                args.Player.SendData(PacketTypes.ChestItem, "", id, slot);
                return(false);
            }

            return(false);
        }
Esempio n. 20
0
        private static bool HandleLiquidSet(GetDataHandlerArgs args)
        {
            int  x      = args.Data.ReadInt32();
            int  y      = args.Data.ReadInt32();
            byte liquid = args.Data.ReadInt8();
            bool lava   = args.Data.ReadBoolean();

            //The liquid was picked up.
            if (liquid == 0)
            {
                return(false);
            }

            int plyX  = Math.Abs(args.Player.TileX);
            int plyY  = Math.Abs(args.Player.TileY);
            int tileX = Math.Abs(x);
            int tileY = Math.Abs(y);

            bool bucket = false;

            for (int i = 0; i < 44; i++)
            {
                if (args.TPlayer.inventory[i].type >= 205 && args.TPlayer.inventory[i].type <= 207)
                {
                    bucket = true;
                    break;
                }
            }

            if (!args.Player.Group.HasPermission(Permissions.canbuild))
            {
                args.Player.SendMessage("You do not have permission to build!", Color.Red);
                args.Player.SendTileSquare(x, y);
                return(true);
            }

            if (lava && !args.Player.Group.HasPermission(Permissions.canlava))
            {
                args.Player.SendMessage("You do not have permission to use lava", Color.Red);
                Tools.SendLogs(string.Format("{0} tried using lava", args.Player.Name), Color.Red);
                args.Player.SendTileSquare(x, y);
                return(true);
            }
            if (!lava && !args.Player.Group.HasPermission(Permissions.canwater))
            {
                args.Player.SendMessage("You do not have permission to use water", Color.Red);
                Tools.SendLogs(string.Format("{0} tried using water", args.Player.Name), Color.Red);
                args.Player.SendTileSquare(x, y);
                return(true);
            }

            if (!bucket)
            {
                Log.Debug(string.Format("{0}(PlyXY:{1}_{2}, TileXY:{3}_{4}, Result:{5}_{6}, Amount:{7})",
                                        lava ? "Lava" : "Water", plyX, plyY, tileX, tileY,
                                        Math.Abs(plyX - tileX), Math.Abs(plyY - tileY), liquid));
                return(Tools.HandleGriefer(args.Player, TShock.Config.IllogicalLiquidUseReason));;
            }
            if (TShock.Config.RangeChecks && ((Math.Abs(plyX - tileX) > 32) || (Math.Abs(plyY - tileY) > 32)))
            {
                Log.Debug(string.Format("Liquid(PlyXY:{0}_{1}, TileXY:{2}_{3}, Result:{4}_{5}, Amount:{6})",
                                        plyX, plyY, tileX, tileY, Math.Abs(plyX - tileX), Math.Abs(plyY - tileY), liquid));
                return(Tools.HandleGriefer(args.Player, TShock.Config.LiquidAbuseReason));
            }

            if (TShock.Config.SpawnProtection)
            {
                if (!args.Player.Group.HasPermission(Permissions.editspawn))
                {
                    var flag = TShock.CheckSpawn(x, y);
                    if (flag)
                    {
                        args.Player.SendMessage("The spawn is protected!", Color.Red);
                        args.Player.SendTileSquare(x, y);
                        return(true);
                    }
                }
            }
            return(false);
        }
Esempio n. 21
0
        private static bool HandleSendTileSquare(GetDataHandlerArgs args)
        {
            var size  = args.Data.ReadInt16();
            var tileX = args.Data.ReadInt32();
            var tileY = args.Data.ReadInt32();

            if (size > 5)
            {
                return(true);
            }

            if ((DateTime.UtcNow - args.Player.LastThreat).TotalMilliseconds < 5000)
            {
                args.Player.SendTileSquare(tileX, tileY, size);
                return(true);
            }

            if (TShock.CheckIgnores(args.Player))
            {
                args.Player.SendTileSquare(tileX, tileY);
                return(true);
            }

            var tiles = new NetTile[size, size];

            for (int x = 0; x < size; x++)
            {
                for (int y = 0; y < size; y++)
                {
                    tiles[x, y] = new NetTile(args.Data);
                }
            }

            bool changed = false;

            for (int x = 0; x < size; x++)
            {
                int realx = tileX + x;
                if (realx < 0 || realx >= Main.maxTilesX)
                {
                    continue;
                }

                for (int y = 0; y < size; y++)
                {
                    int realy = tileY + y;
                    if (realy < 0 || realy >= Main.maxTilesY)
                    {
                        continue;
                    }

                    var tile    = Main.tile[realx, realy];
                    var newtile = tiles[x, y];
                    if (TShock.CheckTilePermission(args.Player, x, y))
                    {
                        continue;
                    }
                    if ((tile.type == 128 && newtile.Type == 128) || (tile.type == 105 && newtile.Type == 105))
                    {
                        if (TShock.Config.EnableInsecureTileFixes)
                        {
                            return(false);
                        }
                    }

                    if (tile.type == 0x17 && newtile.Type == 0x2)
                    {
                        tile.type = 0x2;
                        changed   = true;
                    }
                    else if (tile.type == 0x19 && newtile.Type == 0x1)
                    {
                        tile.type = 0x1;
                        changed   = true;
                    }
                    else if ((tile.type == 0xF && newtile.Type == 0xF) ||
                             (tile.type == 0x4F && newtile.Type == 0x4F))
                    {
                        tile.frameX = newtile.FrameX;
                        tile.frameY = newtile.FrameY;
                        changed     = true;
                    }
                    // Holy water/Unholy water
                    else if (tile.type == 1 && newtile.Type == 117)
                    {
                        tile.type = 117;
                        changed   = true;
                    }
                    else if (tile.type == 1 && newtile.Type == 25)
                    {
                        tile.type = 25;
                        changed   = true;
                    }
                    else if (tile.type == 117 && newtile.Type == 25)
                    {
                        tile.type = 25;
                        changed   = true;
                    }
                    else if (tile.type == 25 && newtile.Type == 117)
                    {
                        tile.type = 117;
                        changed   = true;
                    }
                    else if (tile.type == 2 && newtile.Type == 23)
                    {
                        tile.type = 23;
                        changed   = true;
                    }
                    else if (tile.type == 2 && newtile.Type == 109)
                    {
                        tile.type = 109;
                        changed   = true;
                    }
                    else if (tile.type == 23 && newtile.Type == 109)
                    {
                        tile.type = 109;
                        changed   = true;
                    }
                    else if (tile.type == 109 && newtile.Type == 23)
                    {
                        tile.type = 23;
                        changed   = true;
                    }
                    else if (tile.type == 23 && newtile.Type == 109)
                    {
                        tile.type = 109;
                        changed   = true;
                    }
                    else if (tile.type == 53 && newtile.Type == 116)
                    {
                        tile.type = 116;
                        changed   = true;
                    }
                    else if (tile.type == 53 && newtile.Type == 112)
                    {
                        tile.type = 112;
                        changed   = true;
                    }
                    else if (tile.type == 112 && newtile.Type == 116)
                    {
                        tile.type = 116;
                        changed   = true;
                    }
                    else if (tile.type == 116 && newtile.Type == 112)
                    {
                        tile.type = 112;
                        changed   = true;
                    }
                    else if (tile.type == 112 && newtile.Type == 53)
                    {
                        tile.type = 53;
                        changed   = true;
                    }
                    else if (tile.type == 109 && newtile.Type == 2)
                    {
                        tile.type = 2;
                        changed   = true;
                    }
                    else if (tile.type == 116 && newtile.Type == 53)
                    {
                        tile.type = 53;
                        changed   = true;
                    }
                    else if (tile.type == 117 && newtile.Type == 1)
                    {
                        tile.type = 1;
                        changed   = true;
                    }
                }
            }

            if (changed)
            {
                TSPlayer.All.SendTileSquare(tileX, tileY, size);
                WorldGen.RangeFrame(tileX, tileY, tileX + size, tileY + size);
            }
            return(true);
        }
Esempio n. 22
0
        private static bool HandleTile(GetDataHandlerArgs args)
        {
            var type     = args.Data.ReadInt8();
            var tileX    = args.Data.ReadInt32();
            var tileY    = args.Data.ReadInt32();
            var tiletype = args.Data.ReadInt8();

            if (tileX < 0 || tileX >= Main.maxTilesX || tileY < 0 || tileY >= Main.maxTilesY)
            {
                return(false);
            }

            if (args.Player.AwaitingName)
            {
                if (TShock.Regions.InAreaRegionName(tileX, tileY) == null)
                {
                    args.Player.SendMessage("Region is not protected", Color.Yellow);
                }
                else
                {
                    args.Player.SendMessage("Region Name: " + TShock.Regions.InAreaRegionName(tileX, tileY), Color.Yellow);
                }
                args.Player.SendTileSquare(tileX, tileY);
                args.Player.AwaitingName = false;
                return(true);
            }

            if (args.Player.AwaitingTempPoint > 0)
            {
                args.Player.TempPoints[args.Player.AwaitingTempPoint - 1].X = tileX;
                args.Player.TempPoints[args.Player.AwaitingTempPoint - 1].Y = tileY;
                args.Player.SendMessage("Set Temp Point " + args.Player.AwaitingTempPoint, Color.Yellow);
                args.Player.SendTileSquare(tileX, tileY);
                args.Player.AwaitingTempPoint = 0;
                return(true);
            }

            if (type == 1 || type == 3)
            {
                if (tiletype >= ((type == 1) ? Main.maxTileSets : Main.maxWallTypes))
                {
                    return(true);
                }
                if (tiletype == 48 && !args.Player.Group.HasPermission(Permissions.usebanneditem) && TShock.Itembans.ItemIsBanned("Spikes"))
                {
                    args.Player.SendTileSquare(tileX, tileY);
                    return(true);
                }
                if (type == 1 && tiletype == 21 && TShock.Utils.MaxChests())
                {
                    args.Player.SendMessage("Reached world's max chest limit, unable to place more!", Color.Red);
                    args.Player.SendTileSquare(tileX, tileY);
                    return(true);
                }
                if (tiletype == 141 && !args.Player.Group.HasPermission(Permissions.usebanneditem) && TShock.Itembans.ItemIsBanned("Explosives"))
                {
                    args.Player.SendTileSquare(tileX, tileY);
                    return(true);
                }
            }

            if (TShock.CheckIgnores(args.Player))
            {
                args.Player.SendTileSquare(tileX, tileY);
                return(true);
            }

            if (TShock.CheckTilePermission(args.Player, tileX, tileY))
            {
                args.Player.SendTileSquare(tileX, tileY);
                return(true);
            }

            if (type == 0 && Main.tileSolid[Main.tile[tileX, tileY].type] && args.Player.Active)
            {
                args.Player.TileThreshold++;
                var coords = new Vector2(tileX, tileY);
                if (!args.Player.TilesDestroyed.ContainsKey(coords))
                {
                    args.Player.TilesDestroyed.Add(coords, Main.tile[tileX, tileY]);
                }
            }

            if ((DateTime.UtcNow - args.Player.LastThreat).TotalMilliseconds < 5000)
            {
                args.Player.SendTileSquare(tileX, tileY);
                return(true);
            }

            return(false);
        }
Esempio n. 23
0
        private static bool HandleTile(GetDataHandlerArgs args)
        {
            byte type     = args.Data.ReadInt8();
            int  x        = args.Data.ReadInt32();
            int  y        = args.Data.ReadInt32();
            byte tiletype = args.Data.ReadInt8();

            if (args.Player.AwaitingName)
            {
                if (TShock.Regions.InAreaRegionName(x, y) == null)
                {
                    args.Player.SendMessage("Region is not protected", Color.Yellow);
                }
                else
                {
                    args.Player.SendMessage("Region Name: " + TShock.Regions.InAreaRegionName(x, y), Color.Yellow);
                }
                args.Player.SendTileSquare(x, y);
                args.Player.AwaitingName = false;
                return(true);
            }

            if (args.Player.AwaitingTempPoint > 0)
            {
                args.Player.TempPoints[args.Player.AwaitingTempPoint - 1].X = x;
                args.Player.TempPoints[args.Player.AwaitingTempPoint - 1].Y = y;
                args.Player.SendMessage("Set Temp Point " + args.Player.AwaitingTempPoint, Color.Yellow);
                args.Player.SendTileSquare(x, y);
                args.Player.AwaitingTempPoint = 0;
                return(true);
            }

            if (!args.Player.Group.HasPermission(Permissions.canbuild))
            {
                if (!args.Player.HasBeenSpammedWithBuildMessage)
                {
                    args.Player.SendMessage("You do not have permission to build!", Color.Red);
                    args.Player.HasBeenSpammedWithBuildMessage = true;
                }
                args.Player.SendTileSquare(x, y);
                return(true);
            }
            if (type == 1 || type == 3)
            {
                int plyX  = Math.Abs(args.Player.TileX);
                int plyY  = Math.Abs(args.Player.TileY);
                int tileX = Math.Abs(x);
                int tileY = Math.Abs(y);

                if (tiletype >= ((type == 1) ? Main.maxTileSets : Main.maxWallTypes))
                {
                    Tools.HandleGriefer(args.Player, string.Format(TShock.Config.TileAbuseReason, "Invalid tile type"));
                    return(true);
                }
                if (TShock.Config.RangeChecks && ((Math.Abs(plyX - tileX) > 32) || (Math.Abs(plyY - tileY) > 32)))
                {
                    if (!(type == 1 && ((tiletype == 0 && args.Player.TPlayer.selectedItem == 114) || (tiletype == 53 && args.Player.TPlayer.selectedItem == 266))))
                    {
                        Log.Debug(string.Format("TilePlaced(PlyXY:{0}_{1}, TileXY:{2}_{3}, Result:{4}_{5}, Type:{6})",
                                                plyX, plyY, tileX, tileY, Math.Abs(plyX - tileX), Math.Abs(plyY - tileY), tiletype));
                        return(Tools.HandleGriefer(args.Player, TShock.Config.RangeCheckBanReason));
                    }
                }
                if (tiletype == 48 && !args.Player.Group.HasPermission(Permissions.canspike))
                {
                    args.Player.SendMessage("You do not have permission to place spikes.", Color.Red);
                    Tools.SendLogs(string.Format("{0} tried to place spikes", args.Player.Name), Color.Red);
                    args.Player.SendTileSquare(x, y);
                    return(true);
                }
                if (type == 1 && tiletype == 21 && Tools.MaxChests())
                {
                    args.Player.SendMessage("Reached world's max chest limit, unable to place more!", Color.Red);
                    Log.Info("Reached world's chest limit, unable to place more.");
                    args.Player.SendTileSquare(x, y);
                    return(true);
                }
            }
            if (!args.Player.Group.HasPermission(Permissions.editspawn) && !TShock.Regions.CanBuild(x, y, args.Player) && TShock.Regions.InArea(x, y))
            {
                if ((DateTime.UtcNow - args.Player.LastTileChangeNotify).TotalMilliseconds > 1000)
                {
                    args.Player.SendMessage("Region Name: " + TShock.Regions.InAreaRegionName(x, y) + " protected from changes.", Color.Red);
                    args.Player.LastTileChangeNotify = DateTime.UtcNow;
                }
                args.Player.SendTileSquare(x, y);
                return(true);
            }
            if (TShock.Config.DisableBuild)
            {
                if (!args.Player.Group.HasPermission(Permissions.editspawn))
                {
                    if ((DateTime.UtcNow - args.Player.LastTileChangeNotify).TotalMilliseconds > 1000)
                    {
                        args.Player.SendMessage("World protected from changes.", Color.Red);
                        args.Player.LastTileChangeNotify = DateTime.UtcNow;
                    }
                    args.Player.SendTileSquare(x, y);
                    return(true);
                }
            }
            if (TShock.Config.SpawnProtection)
            {
                if (!args.Player.Group.HasPermission(Permissions.editspawn))
                {
                    var flag = TShock.CheckSpawn(x, y);
                    if (flag)
                    {
                        if ((DateTime.UtcNow - args.Player.LastTileChangeNotify).TotalMilliseconds > 1000)
                        {
                            args.Player.SendMessage("Spawn protected from changes.", Color.Red);
                            args.Player.LastTileChangeNotify = DateTime.UtcNow;
                        }
                        args.Player.SendTileSquare(x, y);
                        return(true);
                    }
                }
            }
            if (type == 0 && BlacklistTiles[Main.tile[x, y].type] && args.Player.Active)
            {
                args.Player.TileThreshold++;
                var coords = new Vector2(x, y);
                if (!args.Player.TilesDestroyed.ContainsKey(coords))
                {
                    args.Player.TilesDestroyed.Add(coords, Main.tile[x, y].Data);
                }
            }

            if ((DateTime.UtcNow - args.Player.LastExplosive).TotalMilliseconds < 1000)
            {
                args.Player.SendMessage("Please wait another " + (1000 - (DateTime.UtcNow - args.Player.LastExplosive).TotalMilliseconds) + " milliseconds before placing/destroying tiles", Color.Red);
                args.Player.SendTileSquare(x, y);
                return(true);
            }
            return(false);
        }
Esempio n. 24
0
        private static bool HandlePlayerDamage(GetDataHandlerArgs args)
        {
            var id        = args.Data.ReadInt8();
            var direction = args.Data.ReadInt8();
            var dmg       = args.Data.ReadInt16();
            var pvp       = args.Data.ReadInt8();
            var crit      = args.Data.ReadInt8();

            int    textlength = (int)(args.Data.Length - args.Data.Position - 1);
            string deathtext  = "";

            if (textlength > 0)
            {
                deathtext = Encoding.ASCII.GetString(args.Data.ReadBytes(textlength));
                if (!TShock.Utils.ValidString(deathtext))
                {
                    return(true);
                }
            }

            if (TShock.Players[id] == null)
            {
                return(true);
            }

            if (dmg > 175)
            {
                args.Player.SendData(PacketTypes.PlayerHp, "", id);
                args.Player.SendData(PacketTypes.PlayerUpdate, "", id);
                return(true);
            }

            if (!TShock.Players[id].TPlayer.hostile)
            {
                args.Player.SendData(PacketTypes.PlayerHp, "", id);
                args.Player.SendData(PacketTypes.PlayerUpdate, "", id);
                return(true);
            }

            if (TShock.CheckIgnores(args.Player))
            {
                args.Player.SendData(PacketTypes.PlayerHp, "", id);
                args.Player.SendData(PacketTypes.PlayerUpdate, "", id);
                return(true);
            }

            if (TShock.Config.RangeChecks && ((Math.Abs(args.Player.TileX - TShock.Players[id].TileX) > 128) || (Math.Abs(args.Player.TileY - TShock.Players[id].TileY) > 128)))
            {
                args.Player.SendData(PacketTypes.PlayerHp, "", id);
                args.Player.SendData(PacketTypes.PlayerUpdate, "", id);
                return(true);
            }

            if ((DateTime.UtcNow - args.Player.LastThreat).TotalMilliseconds < 5000)
            {
                args.Player.SendData(PacketTypes.PlayerHp, "", id);
                args.Player.SendData(PacketTypes.PlayerUpdate, "", id);
                return(true);
            }

            return(false);
        }
Esempio n. 25
0
        private static bool HandleLiquidSet(GetDataHandlerArgs args)
        {
            int  tileX  = args.Data.ReadInt32();
            int  tileY  = args.Data.ReadInt32();
            byte liquid = args.Data.ReadInt8();
            bool lava   = args.Data.ReadBoolean();

            //The liquid was picked up.
            if (liquid == 0)
            {
                return(false);
            }

            if (tileX < 0 || tileX >= Main.maxTilesX || tileY < 0 || tileY >= Main.maxTilesY)
            {
                return(false);
            }

            if (TShock.CheckIgnores(args.Player))
            {
                args.Player.SendTileSquare(tileX, tileY);
                return(true);
            }

            if ((DateTime.UtcNow - args.Player.LastThreat).TotalMilliseconds < 5000)
            {
                args.Player.SendTileSquare(tileX, tileY);
                return(true);
            }

            bool bucket = false;

            for (int i = 0; i < 49; i++)
            {
                if (args.TPlayer.inventory[i].type >= 205 && args.TPlayer.inventory[i].type <= 207)
                {
                    bucket = true;
                    break;
                }
            }
            if (!bucket)
            {
                args.Player.SendTileSquare(tileX, tileY);
                return(true);
            }

            if (lava && !args.Player.Group.HasPermission(Permissions.usebanneditem) && TShock.Itembans.ItemIsBanned("Lava Bucket"))
            {
                args.Player.SendTileSquare(tileX, tileY);
                return(true);
            }

            if (!lava && !args.Player.Group.HasPermission(Permissions.usebanneditem) && TShock.Itembans.ItemIsBanned("Water Bucket"))
            {
                args.Player.SendTileSquare(tileX, tileY);
                return(true);
            }
            if (TShock.CheckTilePermission(args.Player, tileX, tileY))
            {
                args.Player.SendTileSquare(tileX, tileY);
                return(true);
            }

            return(false);
        }