CheckTilePermission() public static method

CheckTilePermission - Checks to see if a player has the ability to modify a tile at a given position.
public static CheckTilePermission ( TShockAPI.TSPlayer player, int tileX, int tileY, bool paint = false ) : bool
player TShockAPI.TSPlayer player - The TSPlayer object.
tileX int tileX - The x coordinate of the tile.
tileY int tileY - The y coordinate of the tile.
paint bool paint - Whether or not the tile is paint.
return bool
Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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);
        }