Esempio n. 1
0
        private static bool HandlePaintWall(GetDataHandlerArgs args)
        {
            var Start = DateTime.Now;

            var X = args.Data.ReadInt16();
            var Y = args.Data.ReadInt16();
            var T = args.Data.ReadInt8();

            if (!args.Player.Group.HasPermission(EditHouse))
            {
                //lock (HousingDistricts.HPlayers)
                {
                    var rect = new Rectangle(X, Y, 1, 1);
                    return(House.HandlerAction((house) =>
                    {
                        if (HousingDistricts.Timeout(Start))
                        {
                            return false;
                        }
                        if (house != null && house.HouseArea.Intersects(rect))
                        {
                            if (!HTools.OwnsHouse(args.Player.User, house))
                            {
                                args.Player.SendData(PacketTypes.PaintWall, "", X, Y, Main.tile[X, Y].wallColor());
                                return true;
                            }
                        }
                        return false;
                    }));
                }
            }
            return(false);
        }
Esempio n. 2
0
        private static bool HandleSendTileSquare(GetDataHandlerArgs args)
        {
            var Start = DateTime.Now;

            short size  = args.Data.ReadInt16();
            int   tilex = args.Data.ReadInt16();
            int   tiley = args.Data.ReadInt16();

            if (!args.Player.Group.HasPermission(EditHouse))
            {
                //lock (HousingDistricts.HPlayers)
                {
                    var rect = new Rectangle(tilex, tiley, size, size);
                    return(House.HandlerAction((house) =>
                    {
                        if (HousingDistricts.Timeout(Start))
                        {
                            return false;
                        }
                        if (house != null && house.HouseArea.Intersects(rect))
                        {
                            if (!HTools.OwnsHouse(args.Player.User, house))
                            {
                                args.Player.SendTileSquare(tilex, tiley);
                                return true;
                            }
                        }
                        return false;
                    }));
                }
            }
            return(false);
        }
Esempio n. 3
0
        public static bool RedefineHouse(int tx, int ty, int width, int height, string housename)
        {
            try
            {
                var house     = HTools.GetHouseByName(housename);
                var houseName = house.Name;

                try
                {
                    string query = "UPDATE HousingDistrict SET TopX=@0, TopY=@1, BottomX=@2, BottomY=@3, WorldID=@4 WHERE Name=@5";

                    TShock.DB.Query(query, tx, ty, width, height, Main.worldID.ToString(), house.Name);
                }
                catch (Exception ex)
                {
                    TShock.Log.Error(ex.ToString());
                    return(false);
                }

                house.HouseArea = new Rectangle(tx, ty, width, height);

                return(true);
            }
            catch (Exception ex)
            {
                TShock.Log.Error("Error on redefining house: \n" + ex);
                return(false);
            }
        }
Esempio n. 4
0
        private static bool HandleSendTileSquare(GetDataHandlerArgs args)
        {
            short size  = args.Data.ReadInt16();
            int   tilex = args.Data.ReadInt32();
            int   tiley = args.Data.ReadInt32();

            if (!args.Player.Group.HasPermission("edithouse"))
            {
                lock (HousingDistricts.HPlayers)
                {
                    foreach (House house in HousingDistricts.Houses)
                    {
                        if (house.HouseArea.Intersects(new Rectangle(tilex, tiley, 1, 1)) && house.WorldID == Main.worldID.ToString())
                        {
                            if (!HTools.OwnsHouse(args.Player.UserID.ToString(), house.Name))
                            {
                                args.Player.SendTileSquare(tilex, tiley);
                                return(true);
                            }
                        }
                    }
                }
            }
            return(false);
        }
Esempio n. 5
0
        public void OnChat(ServerChatEventArgs e)
        {
            var Start = DateTime.Now;
            var msg   = e.Buffer;
            var ply   = e.Who;
            var tsplr = TShock.Players[e.Who];
            var text  = e.Text;

            if (e.Handled)
            {
                return;
            }

            if (text.StartsWith("/grow"))
            {
                if (!tsplr.Group.HasPermission(Permissions.grow))
                {
                    return;
                }
                var I = Houses.Count;

                for (int i = 0; i < I; i++)
                {
                    if (!HTools.OwnsHouse(tsplr.User, Houses[i]) && Houses[i].HouseArea.Intersects(new Rectangle(tsplr.TileX, tsplr.TileY, 1, 1)))
                    {
                        e.Handled = true;
                        tsplr.SendErrorMessage("You can't build here!");
                        return;
                    }
                }
                return;
            }

            if (HConfig.HouseChatEnabled)
            {
                if (text[0] == '/')
                {
                    return;
                }

                var I = HousingDistricts.Houses.Count;
                for (int i = 0; i < I; i++)
                {
                    if (Timeout(Start))
                    {
                        return;
                    }
                    House house;
                    try { house = HousingDistricts.Houses[i]; }
                    catch { continue; }
                    if (house.ChatEnabled == 1 && house.HouseArea.Intersects(new Rectangle(tsplr.TileX, tsplr.TileY, 1, 1)))
                    {
                        HTools.BroadcastToHouse(house, text, tsplr.Name);
                        e.Handled = true;
                    }
                }
            }
        }
Esempio n. 6
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();
            var  player   = HTools.GetPlayerByID(args.Player.Index);

            int tilex = Math.Abs(x);
            int tiley = Math.Abs(y);

            if (player.AwaitingHouseName)
            {
                if (HTools.InAreaHouseName(x, y) == null)
                {
                    args.Player.SendMessage("Tile is not in any House", Color.Yellow);
                }
                else
                {
                    args.Player.SendMessage("House Name: " + HTools.InAreaHouseName(x, y), Color.Yellow);
                }
                args.Player.SendTileSquare(x, y);
                player.AwaitingHouseName = 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 Vector2 " + args.Player.AwaitingTempPoint, Color.Yellow);
                args.Player.SendTileSquare(x, y);
                args.Player.AwaitingTempPoint = 0;
                return(true);
            }

            if (!args.Player.Group.HasPermission("edithouse"))
            {
                lock (HousingDistricts.HPlayers)
                {
                    foreach (House house in HousingDistricts.Houses)
                    {
                        if (house.HouseArea.Intersects(new Rectangle(tilex, tiley, 1, 1)) && house.WorldID == Main.worldID.ToString())
                        {
                            if (!HTools.OwnsHouse(args.Player.UserID.ToString(), house.Name))
                            {
                                args.Player.SendTileSquare(tilex, tiley);
                                return(true);
                            }
                        }
                    }
                }
            }
            return(false);
        }
Esempio n. 7
0
        public override void Initialize()
        {
            HTools.SetupConfig();

            GameHooks.Initialize += OnInitialize;
            GameHooks.Update     += OnUpdate;
            ServerHooks.Chat     += OnChat;
            NetHooks.GreetPlayer += OnGreetPlayer;
            ServerHooks.Leave    += OnLeave;
            NetHooks.GetData     += GetData;

            GetDataHandlers.InitGetDataHandler();
        }
Esempio n. 8
0
        public static bool OwnsHouse(string UserID, string housename)
        {
            if (String.IsNullOrWhiteSpace(UserID) || UserID == "0" || String.IsNullOrEmpty(housename))
            {
                return(false);
            }
            House H = HTools.GetHouseByName(housename);

            if (H == null)
            {
                return(false);
            }
            return(OwnsHouse(UserID, H));
        }
Esempio n. 9
0
        private static bool HandleMassWire(GetDataHandlerArgs args)
        {
            var Start = DateTime.Now;

            int x1 = args.Data.ReadInt16();
            int y1 = args.Data.ReadInt16();
            int x2 = args.Data.ReadInt16();
            int y2 = args.Data.ReadInt16();

            var player = HTools.GetPlayerByID(args.Player.Index);;

            if (args.Player.AwaitingTempPoint > 0)
            {
                args.Player.TempPoints[0].X = x1;
                args.Player.TempPoints[0].Y = y1;
                args.Player.TempPoints[1].X = x2;
                args.Player.TempPoints[1].Y = y2;

                args.Player.SendMessage("Protection corners have been set!", Color.Yellow);
                args.Player.AwaitingTempPoint = 0;
                return(true);
            }
            if (!args.Player.Group.HasPermission(EditHouse))
            {
                Rectangle A = new Rectangle(Math.Min(x1, x2), args.TPlayer.direction != 1 ? y1 : y2, Math.Abs(x2 - x1) + 1, 1);
                Rectangle B = new Rectangle(args.TPlayer.direction != 1 ? x2 : x1, Math.Min(y1, y2), 1, Math.Abs(y2 - y1) + 1);

                //lock (HousingDistricts.HPlayers)
                {
                    return(House.HandlerAction((house) =>
                    {
                        if (HousingDistricts.Timeout(Start))
                        {
                            return false;
                        }
                        if (house != null && (house.HouseArea.Intersects(A) || house.HouseArea.Intersects(B)))
                        {
                            if (!HTools.OwnsHouse(args.Player.User, house))
                            {
                                return true;
                            }
                        }
                        return false;
                    }));
                }
            }
            return(false);
        }
Esempio n. 10
0
        public void OnChat(messageBuffer msg, int ply, string text, HandledEventArgs e)
        {
            if (text[0] == '/')
            {
                return;
            }

            var tsplr = TShock.Players[msg.whoAmI];

            foreach (House house in HousingDistricts.Houses)
            {
                if (house.HouseArea.Intersects(new Rectangle(tsplr.TileX, tsplr.TileY, 1, 1)) && house.WorldID == Main.worldID.ToString())
                {
                    HTools.BroadcastToHouse(house.ID, text, tsplr.Name);
                    e.Handled = true;
                }
            }
        }
Esempio n. 11
0
        public static bool AddHouse(int tx, int ty, int width, int height, string housename, string owner, int locked, int chatenabled)
        {
            if (HTools.GetHouseByName(housename) != null)
            {
                return(false);
            }

            try
            {
                TShock.DB.Query("INSERT INTO HousingDistrict (" + cols + ") VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9);", housename, tx, ty, width, height, "", Main.worldID.ToString(), locked, chatenabled, "");
            }
            catch (Exception ex)
            {
                TShock.Log.Error(ex.ToString());
                return(false);
            }

            HousingDistricts.Houses.Add(new House(new Rectangle(tx, ty, width, height), new List <string>(), (HousingDistricts.Houses.Count + 1), housename, locked, chatenabled, new List <string>()));
            return(true);
        }
Esempio n. 12
0
        public static void ChangeLock(CommandArgs args)
        {
            if (args.Parameters.Count > 0)
            {
                string houseName = "";

                for (int i = 0; i < args.Parameters.Count; i++)
                {
                    if (houseName == "")
                    {
                        houseName = args.Parameters[i];
                    }
                    else
                    {
                        houseName = houseName + " " + args.Parameters[i];
                    }
                }

                if (HTools.OwnsHouse(args.Player.UserID.ToString(), houseName))
                {
                    bool locked = HouseTools.ChangeLock(houseName);

                    if (locked)
                    {
                        args.Player.SendMessage("House: " + houseName + " locked", Color.Yellow);
                    }
                    else
                    {
                        args.Player.SendMessage("House: " + houseName + " unlocked", Color.Yellow);
                    }
                }
                else
                {
                    args.Player.SendMessage("You do not own House: " + houseName, Color.Yellow);
                }
            }
            else
            {
                args.Player.SendMessage("Invalid syntax! Proper syntax: /changelock [house]", Color.Red);
            }
        }
Esempio n. 13
0
        public static bool DeleteUser(string houseName, string id)
        {
            var house = HTools.GetHouseByName(houseName);

            if (house == null)
            {
                return(false);
            }

            StringBuilder sb    = new StringBuilder();
            int           count = 0;

            house.Owners.Remove(id);
            var I = house.Owners.Count;

            for (int i = 0; i < I; i++)
            {
                var owner = house.Owners[i];
                count++;
                sb.Append(owner);
                if (count != house.Owners.Count)
                {
                    sb.Append(",");
                }
            }

            try
            {
                string query = "UPDATE HousingDistrict SET Owners=@0 WHERE Name=@1";

                TShock.DB.Query(query, sb.ToString(), houseName);
            }
            catch (Exception ex)
            {
                TShock.Log.Error(ex.ToString());
                return(false);
            }

            return(true);
        }
Esempio n. 14
0
        private static bool HandleTeleport(GetDataHandlerArgs args)
        {
            if (HConfigFile.Config.AllowRod || args.Player.Group.HasPermission(TPHouse))
            {
                return(false);
            }

            var Start = DateTime.Now;

            var Flags = args.Data.ReadInt8();
            var ID    = args.Data.ReadInt16();
            var X     = args.Data.ReadSingle();
            var Y     = args.Data.ReadSingle();

            if ((Flags & 2) != 2 && (Flags & 1) != 1 && !args.Player.Group.HasPermission(TPHouse))
            {
                //lock (HousingDistricts.HPlayers)
                {
                    var rect = new Rectangle((int)(X / 16), (int)(Y / 16), 2, 4);
                    return(House.HandlerAction((house) =>
                    {
                        if (HousingDistricts.Timeout(Start))
                        {
                            return false;
                        }
                        if (house != null && house.HouseArea.Intersects(rect))
                        {
                            if (!HTools.CanVisitHouse(args.Player.User, house))
                            {
                                args.Player.SendErrorMessage(string.Format("You do not have permission to teleport into house '{0}'.", house.Name));
                                args.Player.Teleport(args.TPlayer.position.X, args.TPlayer.position.Y);
                                return true;
                            }
                        }
                        return false;
                    }));
                }
            }
            return(false);
        }
Esempio n. 15
0
        public void OnUpdate()
        {
            lock (HPlayers)
            {
                foreach (HPlayer player in HPlayers)
                {
                    int HousesNotIn = 0;
                    foreach (House house in HousingDistricts.Houses)
                    {
                        if (HConfig.NotifyOnEntry)
                        {
                            if (house.HouseArea.Intersects(new Rectangle(player.TSPlayer.TileX, player.TSPlayer.TileY, 1, 1)) && house.WorldID == Main.worldID.ToString())
                            {
                                if (house.Locked == 1 && !player.TSPlayer.Group.HasPermission("enterlocked"))
                                {
                                    if (!HTools.OwnsHouse(player.TSPlayer.UserID.ToString(), house.Name))
                                    {
                                        player.TSPlayer.Teleport((int)player.LastTilePos.X, (int)player.LastTilePos.Y + 3);
                                        player.TSPlayer.SendMessage("House: '" + house.Name + "' Is locked", Color.MediumPurple);
                                    }
                                }
                                else
                                {
                                    if (player.CurHouse != house.Name)
                                    {
                                        player.CurHouse = house.Name;
                                        player.InHouse  = true;

                                        if (HTools.OwnsHouse(player.TSPlayer.UserID.ToString(), player.CurHouse))
                                        {
                                            player.TSPlayer.SendMessage("Entered your house: '" + house.Name + "'", Color.MediumPurple);
                                        }
                                        else
                                        {
                                            player.TSPlayer.SendMessage("Entered the house: '" + house.Name + "'", Color.MediumPurple);
                                            HTools.BroadcastToHouseOwners(player.CurHouse, "'" + player.TSPlayer.Name + "' Entered your house: " + player.CurHouse);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                HousesNotIn++;
                            }
                        }
                    }

                    if (HConfig.NotifyOnExit)
                    {
                        if (HousesNotIn == HousingDistricts.Houses.Count && player.InHouse)
                        {
                            if (HTools.OwnsHouse(player.TSPlayer.UserID.ToString(), player.CurHouse))
                            {
                                player.TSPlayer.SendMessage("Left your house: '" + player.CurHouse + "'", Color.MediumPurple);
                            }
                            else
                            {
                                player.TSPlayer.SendMessage("Left house: '" + player.CurHouse + "'", Color.MediumPurple);
                                HTools.BroadcastToHouseOwners(player.CurHouse, "'" + player.TSPlayer.Name + "' Left your house: " + player.CurHouse);
                            }
                            player.CurHouse = "";
                            player.InHouse  = false;
                        }
                    }
                    player.LastTilePos = new Vector2(player.TSPlayer.TileX, player.TSPlayer.TileY);
                }
            }
        }
Esempio n. 16
0
        public static void House(CommandArgs args)
        {
            string cmd = "help";

            if (args.Parameters.Count > 0)
            {
                cmd = args.Parameters[0].ToLower();
            }
            var player = HTools.GetPlayerByID(args.Player.Index);

            switch (cmd)
            {
            case "name":
            {
                {
                    args.Player.SendMessage("Hit a block to get the name of the house", Color.Yellow);
                    player.AwaitingHouseName = true;
                }
                break;
            }

            case "set":
            {
                int choice = 0;
                if (args.Parameters.Count == 2 &&
                    int.TryParse(args.Parameters[1], out choice) &&
                    choice >= 1 && choice <= 2)
                {
                    args.Player.SendMessage("Hit a block to Set Vector2 " + choice, Color.Yellow);
                    args.Player.AwaitingTempPoint = choice;
                }
                else
                {
                    args.Player.SendMessage("Invalid syntax! Proper syntax: /region set [1/2]", Color.Red);
                }
                break;
            }

            case "add":
            {
                if (args.Parameters.Count > 1)
                {
                    if (!args.Player.TempPoints.Any(p => p == Point.Zero))
                    {
                        string houseName = String.Join(" ", args.Parameters.GetRange(1, args.Parameters.Count - 1));

                        var x      = Math.Min(args.Player.TempPoints[0].X, args.Player.TempPoints[1].X);
                        var y      = Math.Min(args.Player.TempPoints[0].Y, args.Player.TempPoints[1].Y);
                        var width  = Math.Abs(args.Player.TempPoints[0].X - args.Player.TempPoints[1].X);
                        var height = Math.Abs(args.Player.TempPoints[0].Y - args.Player.TempPoints[1].Y);

                        if (HouseTools.AddHouse(x, y, width, height, houseName, 0))
                        {
                            args.Player.TempPoints[0] = Point.Zero;
                            args.Player.TempPoints[1] = Point.Zero;
                            args.Player.SendMessage("Set house " + houseName, Color.Yellow);
                        }
                        else
                        {
                            args.Player.SendMessage("House " + houseName + " already exists", Color.Red);
                        }
                    }
                    else
                    {
                        args.Player.SendMessage("Points not set up yet", Color.Red);
                    }
                }
                else
                {
                    args.Player.SendMessage("Invalid syntax! Proper syntax: /house add [name]", Color.Red);
                }
                break;
            }

            case "allow":
            {
                if (args.Parameters.Count > 2)
                {
                    string playerName = args.Parameters[1];
                    string houseName  = "";
                    User   playerID;

                    for (int i = 2; i < args.Parameters.Count; i++)
                    {
                        if (houseName == "")
                        {
                            houseName = args.Parameters[2];
                        }
                        else
                        {
                            houseName = houseName + " " + args.Parameters[i];
                        }
                    }
                    if ((playerID = TShock.Users.GetUserByName(playerName)) != null)
                    {
                        if (HouseTools.AddNewUser(houseName, playerID.ID.ToString()))
                        {
                            args.Player.SendMessage("Added user " + playerName + " to " + houseName, Color.Yellow);
                        }
                        else
                        {
                            args.Player.SendMessage("House " + houseName + " not found", Color.Red);
                        }
                    }
                    else
                    {
                        args.Player.SendMessage("Player " + playerName + " not found", Color.Red);
                    }
                }
                else
                {
                    args.Player.SendMessage("Invalid syntax! Proper syntax: /house allow [name] [house]", Color.Red);
                }
                break;
            }

            case "delete":
            {
                if (args.Parameters.Count > 1)
                {
                    string houseName = "";

                    for (int i = 1; i < args.Parameters.Count; i++)
                    {
                        if (houseName == "")
                        {
                            houseName = args.Parameters[1];
                        }
                        else
                        {
                            houseName = houseName + " " + args.Parameters[i];
                        }
                    }
                    List <SqlValue> where = new List <SqlValue>();
                    where.Add(new SqlValue("Name", "'" + houseName + "'"));
                    HousingDistricts.SQLWriter.DeleteRow("HousingDistrict", where);

                    foreach (House house in HousingDistricts.Houses)
                    {
                        if (house.Name == houseName)
                        {
                            HousingDistricts.Houses.Remove(house);
                            break;
                        }
                    }
                    args.Player.SendMessage("House: " + houseName + " deleted", Color.Yellow);
                }
                else
                {
                    args.Player.SendMessage("Invalid syntax! Proper syntax: /house delete [house]", Color.Red);
                }
                break;
            }

            case "clear":
            {
                args.Player.TempPoints[0]     = Point.Zero;
                args.Player.TempPoints[1]     = Point.Zero;
                args.Player.AwaitingTempPoint = 0;
                args.Player.SendMessage("Cleared temp area", Color.Yellow);
                break;
            }

            case "list":
            {
                //How many regions per page
                const int pagelimit = 15;
                //How many regions per line
                const int perline = 5;
                //Pages start at 0 but are displayed and parsed at 1
                int page = 0;


                if (args.Parameters.Count > 1)
                {
                    if (!int.TryParse(args.Parameters[1], out page) || page < 1)
                    {
                        args.Player.SendMessage(string.Format("Invalid page number ({0})", page), Color.Red);
                        return;
                    }
                    page--;         //Substract 1 as pages are parsed starting at 1 and not 0
                }

                List <House> houses = new List <House>();

                foreach (House house in HousingDistricts.Houses)
                {
                    if (house.WorldID == Main.worldID.ToString())
                    {
                        houses.Add(house);
                    }
                }

                // Are there even any houses to display?
                if (houses.Count == 0)
                {
                    args.Player.SendMessage("There are currently no houses defined.", Color.Red);
                    return;
                }

                //Check if they are trying to access a page that doesn't exist.
                int pagecount = houses.Count / pagelimit;
                if (page > pagecount)
                {
                    args.Player.SendMessage(string.Format("Page number exceeds pages ({0}/{1})", page + 1, pagecount + 1), Color.Red);
                    return;
                }

                //Display the current page and the number of pages.
                args.Player.SendMessage(string.Format("Current Houses ({0}/{1}):", page + 1, pagecount + 1), Color.Green);

                //Add up to pagelimit names to a list
                var nameslist = new List <string>();
                for (int i = (page * pagelimit); (i < ((page * pagelimit) + pagelimit)) && i < houses.Count; i++)
                {
                    nameslist.Add(houses[i].Name);
                }

                //convert the list to an array for joining
                var names = nameslist.ToArray();
                for (int i = 0; i < names.Length; i += perline)
                {
                    args.Player.SendMessage(string.Join(", ", names, i, Math.Min(names.Length - i, perline)), Color.Yellow);
                }

                if (page < pagecount)
                {
                    args.Player.SendMessage(string.Format("Type /house list {0} for more houses.", (page + 2)), Color.Yellow);
                }
                break;
            }
            }
        }
Esempio n. 17
0
        private static bool HandleChest(GetDataHandlerArgs args)
        {
            var Start = DateTime.Now;

            int action = args.Data.ReadByte();
            int X      = args.Data.ReadInt16();
            int Y      = args.Data.ReadInt16();

            var player = HTools.GetPlayerByID(args.Player.Index);

            /*
             * if (player.AwaitingHouseName)
             * {
             *      if (HTools.InAreaHouseName(x, y) == null)
             *              args.Player.SendMessage("Tile is not in any House", Color.Yellow);
             *      else
             *              args.Player.SendMessage("House Name: " + HTools.InAreaHouseName(x, y), Color.Yellow);
             *
             *      args.Player.SendTileSquare(x, y);
             *      player.AwaitingHouseName = 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;
             *      if (args.Player.AwaitingTempPoint == 1)
             *              args.Player.SendMessage("Top-left corner of protection area has been set!", Color.Yellow);
             *
             *      if (args.Player.AwaitingTempPoint == 2)
             *              args.Player.SendMessage("Bottom-right corner of protection area has been set!", Color.Yellow);
             *
             *      args.Player.SendTileSquare(x, y);
             *      args.Player.AwaitingTempPoint = 0;
             *      return true;
             * }
             */

            if (!args.Player.Group.HasPermission(EditHouse))
            {
                //lock (HousingDistricts.HPlayers)
                {
                    var rect = new Rectangle(X, Y, 1, 1);
                    return(House.HandlerAction((house) =>
                    {
                        if (HousingDistricts.Timeout(Start))
                        {
                            return false;
                        }
                        if (house != null && house.HouseArea.Intersects(rect))
                        {
                            if (!HTools.OwnsHouse(args.Player.User, house))
                            {
                                args.Player.SendTileSquare(X, Y);
                                return true;
                            }
                        }
                        return false;
                    }));
                }
            }
            return(false);
        }
Esempio n. 18
0
        public static void House(CommandArgs args)
        {
            const string AdminHouse = "house.admin";             // Seems right to keep the actual permission names in one place, for easy editing
            const string UseHouse   = "house.use";
            const string LockHouse  = "house.lock";
            const string AllowHouse = "house.allow";
            string       cmd        = "help";
            var          ply        = args.Player; // Makes the code shorter

            if (args.Parameters.Count > 0)
            {
                cmd = args.Parameters[0].ToLower();
            }

            var player = HTools.GetPlayerByID(ply.Index);

            switch (cmd)
            {
            case "name":
            {
                ply.SendMessage("Hit a block to get the name of the house", Color.Yellow);
                player.AwaitingHouseName = true;
                break;
            }

            case "set":
            {
                if (!ply.Group.HasPermission(UseHouse))
                {
                    ply.SendErrorMessage("You do not have permission to use this command!");
                    return;
                }
                if (!ply.IsLoggedIn || ply.User == null || ply.User.ID == 0)
                {
                    ply.SendErrorMessage("You must log-in to use House Protection.");
                    return;
                }
                int choice = 0;
                if (args.Parameters.Count == 2 &&
                    int.TryParse(args.Parameters[1], out choice) &&
                    choice >= 1 && choice <= 2)
                {
                    if (choice == 1)
                    {
                        ply.SendMessage("Now hit the TOP-LEFT block of the area to be protected.", Color.Yellow);
                    }
                    if (choice == 2)
                    {
                        ply.SendMessage("Now hit the BOTTOM-RIGHT block of the area to be protected.", Color.Yellow);
                    }
                    ply.AwaitingTempPoint = choice;
                }
                else
                {
                    ply.SendErrorMessage("Invalid syntax! Proper syntax: /house set [1/2]");
                }

                break;
            }

            case "add":
            {
                if (!ply.Group.HasPermission(UseHouse))
                {
                    ply.SendErrorMessage("You do not have permission to use this command!");
                    return;
                }
                if (!ply.IsLoggedIn || ply.User == null || ply.User.ID == 0)
                {
                    ply.SendErrorMessage("You must log-in to use House Protection.");
                    return;
                }
                if (args.Parameters.Count > 1)
                {
                    List <int> userOwnedHouses = new List <int>();
                    var        maxHouses       = HTools.MaxCount(ply);
                    for (int i = 0; i < HousingDistricts.Houses.Count; i++)
                    {
                        var house = HousingDistricts.Houses[i];
                        if (HTools.OwnsHouse(ply.User, house))
                        {
                            userOwnedHouses.Add(house.ID);
                        }
                    }
                    if (userOwnedHouses.Count < maxHouses || ply.Group.HasPermission("house.bypasscount"))
                    {
                        if (!ply.TempPoints.Any(p => p == Point.Zero))
                        {
                            string houseName = String.Join(" ", args.Parameters.GetRange(1, args.Parameters.Count - 1));

                            if (String.IsNullOrEmpty(houseName))
                            {
                                ply.SendErrorMessage("House name cannot be empty.");
                                return;
                            }

                            var x       = Math.Min(ply.TempPoints[0].X, ply.TempPoints[1].X);
                            var y       = Math.Min(ply.TempPoints[0].Y, ply.TempPoints[1].Y);
                            var width   = Math.Abs(ply.TempPoints[0].X - ply.TempPoints[1].X) + 1;
                            var height  = Math.Abs(ply.TempPoints[0].Y - ply.TempPoints[1].Y) + 1;
                            var maxSize = HTools.MaxSize(ply);
                            if (((width * height) <= maxSize && width >= HConfigFile.Config.MinHouseWidth && height >= HConfigFile.Config.MinHouseHeight) || ply.Group.HasPermission("house.bypasssize"))
                            {
                                Rectangle newHouseR = new Rectangle(x, y, width, height);
                                for (int i = 0; i < HousingDistricts.Houses.Count; i++)
                                {
                                    var house = HousingDistricts.Houses[i];
                                    if ((newHouseR.Intersects(house.HouseArea) && !userOwnedHouses.Contains(house.ID)) && !HConfigFile.Config.OverlapHouses)
                                    {
                                        ply.SendErrorMessage("Your selected area overlaps another players' house, which is not allowed.");
                                        return;
                                    }
                                }
                                if (newHouseR.Intersects(new Rectangle(Main.spawnTileX, Main.spawnTileY, 1, 1)))
                                {
                                    ply.SendErrorMessage("Your selected area overlaps spawnpoint, which is not allowed.");
                                    return;
                                }
                                for (int i = 0; i < TShock.Regions.Regions.Count; i++)
                                {
                                    var Region = TShock.Regions.Regions[i];
                                    if (newHouseR.Intersects(Region.Area) && !Region.HasPermissionToBuildInRegion(ply))
                                    {
                                        ply.SendErrorMessage(string.Format("Your selected area overlaps region '{0}', which is not allowed.", Region.Name));
                                        return;
                                    }
                                }
                                if (HouseManager.AddHouse(x, y, width, height, houseName, ply.User.ID.ToString(), 0, 0))
                                {
                                    ply.TempPoints[0] = Point.Zero;
                                    ply.TempPoints[1] = Point.Zero;
                                    ply.SendMessage("You have created new house " + houseName, Color.Yellow);
                                    HouseManager.AddNewUser(houseName, ply.User.ID.ToString());
                                    TShock.Log.ConsoleInfo("{0} has created a new house: \"{1}\".", ply.User.Name, houseName);
                                }
                                else
                                {
                                    //var WM = HouseTools.WorldMismatch(HouseTools.GetHouseByName(houseName)) ? " with a different WorldID!" : "";
                                    ply.SendErrorMessage("House " + houseName + " already exists");
                                }
                            }
                            else
                            {
                                if ((width * height) >= maxSize)
                                {
                                    ply.SendErrorMessage("Your house exceeds the maximum size of " + maxSize.ToString() + " blocks.");
                                    ply.SendErrorMessage("Width: " + width.ToString() + ", Height: " + height.ToString() + ". Points have been cleared.");
                                    ply.TempPoints[0] = Point.Zero;
                                    ply.TempPoints[1] = Point.Zero;
                                }
                                else if (width < HConfigFile.Config.MinHouseWidth)
                                {
                                    ply.SendErrorMessage("Your house width is smaller than server minimum of " + HConfigFile.Config.MinHouseWidth.ToString() + " blocks.");
                                    ply.SendErrorMessage("Width: " + width.ToString() + ", Height: " + height.ToString() + ". Points have been cleared.");
                                    ply.TempPoints[0] = Point.Zero;
                                    ply.TempPoints[1] = Point.Zero;
                                }
                                else
                                {
                                    ply.SendErrorMessage("Your house height is smaller than server minimum of " + HConfigFile.Config.MinHouseHeight.ToString() + " blocks.");
                                    ply.SendErrorMessage("Width: " + width.ToString() + ", Height: " + height.ToString() + ". Points have been cleared.");
                                    ply.TempPoints[0] = Point.Zero;
                                    ply.TempPoints[1] = Point.Zero;
                                }
                            }
                        }
                        else
                        {
                            ply.SendErrorMessage("Points not set up yet");
                        }
                    }
                    else
                    {
                        ply.SendErrorMessage("House add failed: You have too many houses!");
                    }
                }
                else
                {
                    ply.SendErrorMessage("Invalid syntax! Proper syntax: /house add [name]");
                }

                break;
            }

            case "allow":
            {
                if (HConfigFile.Config.RequirePermissionForAllow && !ply.Group.HasPermission(AllowHouse))
                {
                    ply.SendErrorMessage("You do not have permission to use this command!");
                    return;
                }
                if (!ply.Group.HasPermission(UseHouse))
                {
                    ply.SendErrorMessage("You do not have permission to use this command!");
                    return;
                }
                if ((!ply.IsLoggedIn || ply.User == null || ply.User.ID == 0) && ply.RealPlayer)
                {
                    ply.SendErrorMessage("You must log-in to use House Protection.");
                    return;
                }
                if (args.Parameters.Count > 2)
                {
                    string playerName = args.Parameters[1];
                    User   playerID;
                    string housename = String.Join(" ", args.Parameters.GetRange(2, args.Parameters.Count - 2));
                    var    house     = HTools.GetHouseByName(housename);
                    if (house == null)
                    {
                        ply.SendErrorMessage("No such house!"); return;
                    }
                    if (HTools.OwnsHouse(ply.User, house) || ply.Group.HasPermission(AdminHouse))
                    {
                        if ((playerID = TShock.Users.GetUserByName(playerName)) != null)
                        {
                            if (!HTools.OwnsHouse(playerID.ID.ToString(), house))
                            {
                                if (HouseManager.AddNewUser(house.Name, playerID.ID.ToString()))
                                {
                                    ply.SendMessage("Added user " + playerName + " to " + house.Name, Color.Yellow);
                                    TShock.Log.ConsoleInfo("{0} has allowed {1} to house: \"{2}\".", ply.User.Name, playerID.Name, house.Name);
                                }
                                else
                                {
                                    ply.SendErrorMessage("Failed to add user.");
                                }
                            }
                            else
                            {
                                ply.SendErrorMessage("Player " + playerName + " is already allowed to build in '" + house.Name + "'.");
                            }
                        }
                        else
                        {
                            ply.SendErrorMessage("Player " + playerName + " not found");
                        }
                    }
                    else
                    {
                        ply.SendErrorMessage("You do not own house: " + house.Name);
                    }
                }
                else
                {
                    ply.SendErrorMessage("Invalid syntax! Proper syntax: /house allow [name] [house]");
                }
                break;
            }

            case "disallow":
            {
                if (HConfigFile.Config.RequirePermissionForAllow && !ply.Group.HasPermission(AllowHouse))
                {
                    ply.SendErrorMessage("You do not have permission to use this command!");
                    return;
                }
                if (!ply.Group.HasPermission(UseHouse))
                {
                    ply.SendErrorMessage("You do not have permission to use this command!");
                    return;
                }
                if ((!ply.IsLoggedIn || ply.User == null || ply.User.ID == 0) && ply.RealPlayer)
                {
                    ply.SendErrorMessage("You must log-in to use House Protection.");
                    return;
                }
                if (args.Parameters.Count > 2)
                {
                    string playerName = args.Parameters[1];
                    User   playerID;
                    var    house = HTools.GetHouseByName(String.Join(" ", args.Parameters.GetRange(2, args.Parameters.Count - 2)));
                    if (house == null)
                    {
                        ply.SendErrorMessage("No such house!"); return;
                    }
                    if (HTools.OwnsHouse(ply.User, house.Name) || ply.Group.HasPermission(AdminHouse))
                    {
                        if ((playerID = TShock.Users.GetUserByName(playerName)) != null)
                        {
                            if (HouseManager.DeleteUser(house.Name, playerID.ID.ToString()))
                            {
                                ply.SendMessage("Deleted user " + playerName + " from " + house.Name, Color.Yellow);
                                TShock.Log.ConsoleInfo("{0} has disallowed {1} to house: \"{2}\".", ply.User.Name, playerID.Name, house.Name);
                            }
                            else
                            {
                                ply.SendErrorMessage("Failed to delete user.");
                            }
                        }
                        else
                        {
                            ply.SendErrorMessage("Player " + playerName + " not found");
                        }
                    }
                    else
                    {
                        ply.SendErrorMessage("You do not own house: " + house.Name);
                    }
                }
                else
                {
                    ply.SendErrorMessage("Invalid syntax! Proper syntax: /house disallow [name] [house]");
                }
                break;
            }

            case "delete":
            {
                if (!ply.Group.HasPermission(UseHouse))
                {
                    ply.SendErrorMessage("You do not have permission to use this command!");
                    return;
                }
                if ((!ply.IsLoggedIn || ply.User == null || ply.User.ID == 0) && ply.RealPlayer)
                {
                    ply.SendErrorMessage("You must log-in to use House Protection.");
                    return;
                }
                if (args.Parameters.Count > 1)
                {
                    string houseName = String.Join(" ", args.Parameters.GetRange(1, args.Parameters.Count - 1));
                    var    house     = HTools.GetHouseByName(houseName);
                    if (house == null)
                    {
                        ply.SendErrorMessage("No such house!");
                        return;
                    }

                    if (HTools.OwnsHouse(ply.User, house.Name) || ply.Group.HasPermission(AdminHouse))
                    {
                        try
                        {
                            TShock.DB.Query("DELETE FROM HousingDistrict WHERE Name=@0", house.Name);
                        }
                        catch (Exception ex)
                        {
                            TShock.Log.Error(ex.ToString());
                        }
                        HousingDistricts.Houses.Remove(house);
                        ply.SendMessage("House: " + house.Name + " deleted", Color.Yellow);
                        TShock.Log.ConsoleInfo("{0} has deleted house: \"{1}\".", ply.User.Name, house.Name);
                        break;
                    }
                    else
                    {
                        ply.SendErrorMessage("You do not own house: " + house.Name);
                        break;
                    }
                }
                else
                {
                    ply.SendErrorMessage("Invalid syntax! Proper syntax: /house delete [house]");
                }
                break;
            }

            case "clear":
            {
                if (!ply.Group.HasPermission(UseHouse))
                {
                    ply.SendErrorMessage("You do not have permission to use this command!");
                    return;
                }
                ply.TempPoints[0]     = Point.Zero;
                ply.TempPoints[1]     = Point.Zero;
                ply.AwaitingTempPoint = 0;
                ply.SendMessage("Cleared points!", Color.Yellow);
                break;
            }

            case "list":
            {
                //How many regions per page
                const int pagelimit = 15;
                //How many regions per line
                const int perline = 5;
                //Pages start at 0 but are displayed and parsed at 1
                int page = 0;


                if (args.Parameters.Count > 1)
                {
                    if (!int.TryParse(args.Parameters[1], out page) || page < 1)
                    {
                        ply.SendErrorMessage(string.Format("Invalid page number ({0})", page));
                        return;
                    }
                    page--;                                     //Substract 1 as pages are parsed starting at 1 and not 0
                }

                List <House> houses = HousingDistricts.Houses;

                /*
                 * for (int i = 0; i < HousingDistricts.Houses.Count; i++)
                 * {
                 *      var house = HousingDistricts.Houses[i];
                 *      if (!HouseTools.WorldMismatch(house))
                 *              houses.Add(house);
                 * }
                 */
                // Are there even any houses to display?
                if (houses.Count == 0)
                {
                    ply.SendMessage("There are currently no houses defined.", Color.Yellow);
                    return;
                }

                //Check if they are trying to access a page that doesn't exist.
                int pagecount = houses.Count / pagelimit;
                if (page > pagecount)
                {
                    ply.SendErrorMessage(string.Format("Page number exceeds pages ({0}/{1})", page + 1, pagecount + 1));
                    return;
                }

                //Display the current page and the number of pages.
                ply.SendMessage(string.Format("Current Houses ({0}/{1}):", page + 1, pagecount + 1), Color.Green);

                //Add up to pagelimit names to a list
                var nameslist = new List <string>();
                for (int i = (page * pagelimit); (i < ((page * pagelimit) + pagelimit)) && i < houses.Count; i++)
                {
                    nameslist.Add(houses[i].Name);
                }

                //convert the list to an array for joining
                var names = nameslist.ToArray();
                for (int i = 0; i < names.Length; i += perline)
                {
                    ply.SendMessage(string.Join(", ", names, i, Math.Min(names.Length - i, perline)), Color.Yellow);
                }

                if (page < pagecount)
                {
                    ply.SendMessage(string.Format("Type /house list {0} for more houses.", (page + 2)), Color.Yellow);
                }

                break;
            }

            case "redefine":
            {
                if (!ply.Group.HasPermission(UseHouse))
                {
                    ply.SendErrorMessage("You do not have permission to use this command!");
                    return;
                }
                if (!ply.IsLoggedIn || ply.User == null || ply.User.ID == 0)
                {
                    ply.SendErrorMessage("You must log-in to use House Protection.");
                    return;
                }
                if (args.Parameters.Count > 1)
                {
                    if (!ply.TempPoints.Any(p => p == Point.Zero))
                    {
                        string houseName = String.Join(" ", args.Parameters.GetRange(1, args.Parameters.Count - 1));
                        if (HTools.OwnsHouse(ply.User, houseName) || ply.Group.HasPermission(AdminHouse))
                        {
                            var x       = Math.Min(ply.TempPoints[0].X, ply.TempPoints[1].X);
                            var y       = Math.Min(ply.TempPoints[0].Y, ply.TempPoints[1].Y);
                            var width   = Math.Abs(ply.TempPoints[0].X - ply.TempPoints[1].X) + 1;
                            var height  = Math.Abs(ply.TempPoints[0].Y - ply.TempPoints[1].Y) + 1;
                            var maxSize = HTools.MaxSize(ply);

                            if ((width * height) <= maxSize && width >= HConfigFile.Config.MinHouseWidth && height >= HConfigFile.Config.MinHouseHeight)
                            {
                                Rectangle newHouseR = new Rectangle(x, y, width, height);
                                for (int i = 0; i < HousingDistricts.Houses.Count; i++)
                                {
                                    var house = HousingDistricts.Houses[i];
                                    if ((newHouseR.Intersects(house.HouseArea) && !house.Owners.Contains(ply.User.ID.ToString())) && !HConfigFile.Config.OverlapHouses)
                                    {                                                     // user is allowed to intersect their own house
                                        ply.SendErrorMessage("Your selected area overlaps another players' house, which is not allowed.");
                                        return;
                                    }
                                }
                                if (newHouseR.Intersects(new Rectangle(Main.spawnTileX, Main.spawnTileY, 1, 1)))
                                {
                                    ply.SendErrorMessage("Your selected area overlaps spawnpoint, which is not allowed.");
                                    return;
                                }
                                for (int i = 0; i < TShock.Regions.Regions.Count; i++)
                                {
                                    var Region = TShock.Regions.Regions[i];
                                    if (newHouseR.Intersects(Region.Area) && !Region.HasPermissionToBuildInRegion(ply))
                                    {
                                        ply.SendErrorMessage(string.Format("Your selected area overlaps region '{0}', which is not allowed.", Region.Name));
                                        return;
                                    }
                                }
                                if (HouseManager.RedefineHouse(x, y, width, height, houseName))
                                {
                                    ply.TempPoints[0] = Point.Zero;
                                    ply.TempPoints[1] = Point.Zero;
                                    ply.SendMessage("Redefined house " + houseName, Color.Yellow);
                                }
                                else
                                {
                                    ply.SendErrorMessage("Error redefining house " + houseName);
                                }
                            }
                            else
                            {
                                if ((width * height) >= maxSize)
                                {
                                    ply.SendErrorMessage("Your house exceeds the maximum size of " + maxSize.ToString() + " blocks.");
                                    ply.SendErrorMessage("Width: " + width.ToString() + ", Height: " + height.ToString() + ". Points have been cleared.");
                                    ply.TempPoints[0] = Point.Zero;
                                    ply.TempPoints[1] = Point.Zero;
                                }
                                else if (width < HConfigFile.Config.MinHouseWidth)
                                {
                                    ply.SendErrorMessage("Your house width is smaller than server minimum of " + HConfigFile.Config.MinHouseWidth.ToString() + " blocks.");
                                    ply.SendErrorMessage("Width: " + width.ToString() + ", Height: " + height.ToString() + ". Points have been cleared.");
                                    ply.TempPoints[0] = Point.Zero;
                                    ply.TempPoints[1] = Point.Zero;
                                }
                                else
                                {
                                    ply.SendErrorMessage("Your house height is smaller than server minimum of " + HConfigFile.Config.MinHouseHeight.ToString() + " blocks.");
                                    ply.SendErrorMessage("Width: " + width.ToString() + ", Height: " + height.ToString() + ". Points have been cleared.");
                                    ply.TempPoints[0] = Point.Zero;
                                    ply.TempPoints[1] = Point.Zero;
                                }
                            }
                        }
                        else
                        {
                            ply.SendErrorMessage("You do not own house: " + houseName);
                        }
                    }
                    else
                    {
                        ply.SendErrorMessage("Points not set up yet");
                    }
                }
                else
                {
                    ply.SendErrorMessage("Invalid syntax! Proper syntax: /house redefine [name]");
                }
                break;
            }

            case "info":
            {
                if ((!ply.IsLoggedIn || ply.User == null || ply.User.ID == 0) && ply.RealPlayer || !ply.Group.HasPermission(UseHouse))
                {
                    ply.SendErrorMessage("You do not have permission to use this command!");
                    return;
                }
                if (args.Parameters.Count > 1)
                {
                    var house = HTools.GetHouseByName(args.Parameters[1]);
                    if (house == null)
                    {
                        ply.SendErrorMessage("No such house!");
                        return;
                    }
                    string OwnerNames   = "";
                    string VisitorNames = "";
                    for (int i = 0; i < house.Owners.Count; i++)
                    {
                        var ID = house.Owners[i];
                        try { OwnerNames += (String.IsNullOrEmpty(OwnerNames) ? "" : ", ") + TShock.Users.GetUserByID(System.Convert.ToInt32(ID)).Name; }
                        catch { }
                    }
                    for (int i = 0; i < house.Visitors.Count; i++)
                    {
                        var ID = house.Visitors[i];
                        try { VisitorNames += (String.IsNullOrEmpty(VisitorNames) ? "" : ", ") + TShock.Users.GetUserByID(System.Convert.ToInt32(ID)).Name; }
                        catch { }
                    }
                    ply.SendMessage("House '" + house.Name + "':", Color.LawnGreen);
                    ply.SendMessage("Chat enabled: " + (house.ChatEnabled == 1 ? "yes" : "no"), Color.LawnGreen);
                    ply.SendMessage("Locked: " + (house.Locked == 1 ? "yes" : "no"), Color.LawnGreen);
                    ply.SendMessage("Owners: " + OwnerNames, Color.LawnGreen);
                    ply.SendMessage("Visitors: " + VisitorNames, Color.LawnGreen);
                }
                else
                {
                    ply.SendErrorMessage("Invalid syntax! Proper syntax: /house info [house]");
                }
                break;
            }

            case "lock":
            {
                if (HConfigFile.Config.DisableUpdateTimer)
                {
                    ply.SendErrorMessage("Sorry, you can't lock houses on this server.");
                    return;
                }
                if (!ply.Group.HasPermission(LockHouse))
                {
                    ply.SendErrorMessage("You do not have permission to use this command!");
                    return;
                }
                if ((!ply.IsLoggedIn || ply.User == null || ply.User.ID == 0) && ply.RealPlayer)
                {
                    ply.SendErrorMessage("You must log-in to use House Protection.");
                    return;
                }
                if (ply.Group.HasPermission("house.lock"))
                {
                    if (args.Parameters.Count > 1)
                    {
                        string houseName = String.Join(" ", args.Parameters.GetRange(1, args.Parameters.Count - 1));
                        var    house     = HTools.GetHouseByName(houseName);
                        if (house == null)
                        {
                            ply.SendErrorMessage("No such house!"); return;
                        }

                        if (HTools.OwnsHouse(ply.User, house))
                        {
                            bool locked = HouseManager.ChangeLock(house);
                            ply.SendMessage("House: " + house.Name + (locked ? " locked" : " unlocked"), Color.Yellow);
                            TShock.Log.ConsoleInfo("{0} has locked house: \"{1}\".", ply.User.Name, house.Name);
                        }
                        else
                        {
                            ply.SendErrorMessage("You do not own House: " + house.Name);
                        }
                    }
                    else
                    {
                        ply.SendErrorMessage("Invalid syntax! Proper syntax: /house lock [house]");
                    }
                }
                else
                {
                    ply.SendErrorMessage("You do not have access to that command.");
                }
                break;
            }

            case "reload":
            {
                if (ply.Group.HasPermission("house.root"))
                {
                    HouseReload(args);
                }
                break;
            }

            case "chat":
            {
                if (!HConfigFile.Config.HouseChatEnabled)
                {
                    ply.SendErrorMessage("Sorry, this feature is disabled on this server.");
                    return;
                }
                if (!ply.Group.HasPermission(UseHouse))
                {
                    ply.SendErrorMessage("You do not have permission to use this command!");
                    return;
                }
                if ((!ply.IsLoggedIn || ply.User == null || ply.User.ID == 0) && ply.RealPlayer)
                {
                    ply.SendErrorMessage("You must log-in to use House Protection.");
                    return;
                }
                if (args.Parameters.Count > 1)
                {
                    var house = HTools.GetHouseByName(args.Parameters[1]);
                    if (house == null)
                    {
                        ply.SendErrorMessage("No such house!"); return;
                    }
                    if (HTools.OwnsHouse(ply.User, house.Name))
                    {
                        if (args.Parameters.Count > 2)
                        {
                            if (args.Parameters[2].ToLower() == "on")
                            {
                                HouseManager.ToggleChat(house, 1);
                                ply.SendMessage(house.Name + " chat is now enabled.", Color.Lime);
                            }
                            else if (args.Parameters[2].ToLower() == "off")
                            {
                                HouseManager.ToggleChat(house, 0);
                                ply.SendMessage(house.Name + " chat is now disabled.", Color.Lime);
                            }
                            else
                            {
                                ply.SendErrorMessage("Invalid syntax! Use /house chat <housename> (on|off)");
                            }
                        }
                        else
                        {
                            HouseManager.ToggleChat(house, (house.ChatEnabled == 0 ? 1 : 0));
                            ply.SendMessage(house.Name + " chat is now " + (house.ChatEnabled == 0 ? "disabled." : "enabled."), Color.Lime);
                        }
                    }
                    else
                    {
                        ply.SendErrorMessage("You do not own " + house.Name + ".");
                    }
                }
                else
                {
                    ply.SendErrorMessage("Invalid syntax! Use /house chat <housename> (on|off)");
                }
                break;
            }

            case "addvisitor":
            {
                if (HConfigFile.Config.DisableUpdateTimer)
                {
                    ply.SendErrorMessage("Sorry, you can't lock houses on this server.");
                    return;
                }
                if (!ply.Group.HasPermission(UseHouse))
                {
                    ply.SendErrorMessage("You do not have permission to use this command!");
                    return;
                }
                if ((!ply.IsLoggedIn || ply.User == null || ply.User.ID == 0) && ply.RealPlayer)
                {
                    ply.SendErrorMessage("You must log-in to use House Protection.");
                    return;
                }
                if (args.Parameters.Count > 2)
                {
                    string playerName = args.Parameters[1];
                    User   playerID;
                    var    house = HTools.GetHouseByName(args.Parameters[2]);
                    if (house == null)
                    {
                        ply.SendErrorMessage("No such house!"); return;
                    }
                    if (HTools.OwnsHouse(ply.User, house) || ply.Group.HasPermission(AdminHouse))
                    {
                        if ((playerID = TShock.Users.GetUserByName(playerName)) != null)
                        {
                            if (!HTools.CanVisitHouse(playerID.ID.ToString(), house))
                            {
                                if (HouseManager.AddNewVisitor(house, playerID.ID.ToString()))
                                {
                                    ply.SendMessage("Added user " + playerName + " to " + house.Name + " as a visitor.", Color.Yellow);
                                }
                                else
                                {
                                    ply.SendErrorMessage("Failed to add visitor.");
                                }
                            }
                            else
                            {
                                ply.SendErrorMessage("Player " + playerName + " is already allowed to visit '" + house.Name + "'.");
                            }
                        }
                        else
                        {
                            ply.SendErrorMessage("Player " + playerName + " not found");
                        }
                    }
                    else
                    {
                        ply.SendErrorMessage("You do not own house: " + house.Name);
                    }
                }
                else
                {
                    ply.SendErrorMessage("Invalid syntax! Proper syntax: /house addvisitor [name] [house]");
                }
                break;
            }

            case "delvisitor":
            {
                if (HConfigFile.Config.DisableUpdateTimer)
                {
                    ply.SendErrorMessage("Sorry, you can't lock houses on this server.");
                    return;
                }
                if (!ply.Group.HasPermission(UseHouse))
                {
                    ply.SendErrorMessage("You do not have permission to use this command!");
                    return;
                }
                if ((!ply.IsLoggedIn || ply.User == null || ply.User.ID == 0) && ply.RealPlayer)
                {
                    ply.SendErrorMessage("You must log-in to use House Protection.");
                    return;
                }
                if (args.Parameters.Count > 2)
                {
                    string playerName = args.Parameters[1];
                    User   playerID;
                    var    house = HTools.GetHouseByName(args.Parameters[2]);
                    if (house == null)
                    {
                        ply.SendErrorMessage("No such house!"); return;
                    }
                    if (HTools.OwnsHouse(ply.User, house) || ply.Group.HasPermission(AdminHouse))
                    {
                        if ((playerID = TShock.Users.GetUserByName(playerName)) != null)
                        {
                            if (HouseManager.DeleteVisitor(house, playerID.ID.ToString()))
                            {
                                ply.SendMessage("Added user " + playerName + " to " + house.Name + " as a visitor.", Color.Yellow);
                            }
                            else
                            {
                                ply.SendErrorMessage("Failed to delete visitor.");
                            }
                        }
                        else
                        {
                            ply.SendErrorMessage("Player " + playerName + " not found");
                        }
                    }
                    else
                    {
                        ply.SendErrorMessage("You do not own house: " + house.Name);
                    }
                }
                else
                {
                    ply.SendErrorMessage("Invalid syntax! Proper syntax: /house delvisitor [name] [house]");
                }
                break;
            }

            default:
            {
                ply.SendMessage("To create a house, use these commands:", Color.Lime);
                ply.SendMessage("/house set 1", Color.Lime);
                ply.SendMessage("/house set 2", Color.Lime);
                ply.SendMessage("/house add HouseName", Color.Lime);
                ply.SendMessage("Other /house commands: list, allow, disallow, redefine, name, delete, clear, info," +
                                (HConfigFile.Config.HouseChatEnabled ? " chat," : "") +
                                (HConfigFile.Config.DisableUpdateTimer ? "" : "addvisitor, delvisitor, lock,") +
                                " reload", Color.Lime);
                break;
            }
            }
        }
Esempio n. 19
0
 public static void BroadcastToHouseOwners(string housename, string text)
 {
     BroadcastToHouseOwners(HTools.GetHouseByName(housename), text);
 }
Esempio n. 20
0
        public void OnUpdate(object sender, ElapsedEventArgs e)
        {
            if (Main.worldID == 0)
            {
                return;
            }
            if (ULock)
            {
                return;
            }
            ULock = true;
            var Start = DateTime.Now;

            if (Main.rand == null)
            {
                Main.rand = new UnifiedRandom();
            }
            lock (HPlayers)
            {
                var I = HousingDistricts.HPlayers.Count;
                for (int i = 0; i < I; i++)
                {
                    if (UTimeout(Start))
                    {
                        return;
                    }
                    var           player       = HousingDistricts.HPlayers[i];
                    List <string> NewCurHouses = new List <string>(player.CurHouses);
                    int           HousesNotIn  = 0;
                    try
                    {
                        House.UpdateAction((house) =>
                        {
                            if (UTimeout(Start))
                            {
                                return;
                            }
                            try
                            {
                                if (house.HouseArea.Intersects(new Rectangle(player.TSPlayer.TileX, player.TSPlayer.TileY, 1, 1)))
                                {
                                    if (house.Locked == 1 && !player.TSPlayer.Group.HasPermission("house.enterlocked"))
                                    {
                                        if (!HTools.CanVisitHouse(player.TSPlayer.User, house))
                                        {
                                            player.TSPlayer.Teleport((int)player.LastTilePos.X * 16, (int)player.LastTilePos.Y * 16);
                                            player.TSPlayer.SendMessage("House: '" + house.Name + "' Is locked", Color.LightSeaGreen);
                                        }
                                        else
                                        {
                                            if (!player.CurHouses.Contains(house.Name) && HConfig.NotifyOnEntry)
                                            {
                                                NewCurHouses.Add(house.Name);
                                                if (HTools.OwnsHouse(player.TSPlayer.User, house) && HConfig.NotifySelf)
                                                {
                                                    player.TSPlayer.SendMessage(HConfig.NotifyOnOwnHouseEntryString.Replace("$HOUSE_NAME", house.Name), Color.LightSeaGreen);
                                                }
                                                else
                                                {
                                                    if (HConfig.NotifyVisitor)
                                                    {
                                                        player.TSPlayer.SendMessage(HConfig.NotifyOnEntryString.Replace("$HOUSE_NAME", house.Name), Color.LightSeaGreen);
                                                    }

                                                    if (HConfig.NotifyOwner)
                                                    {
                                                        HTools.BroadcastToHouseOwners(house.Name, HConfig.NotifyOnOtherEntryString.Replace("$PLAYER_NAME", player.TSPlayer.Name).Replace("$HOUSE_NAME", house.Name));
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (!player.CurHouses.Contains(house.Name) && HConfig.NotifyOnEntry)
                                        {
                                            NewCurHouses.Add(house.Name);
                                            if (HTools.OwnsHouse(player.TSPlayer.User, house) && HConfig.NotifySelf)
                                            {
                                                player.TSPlayer.SendMessage(HConfig.NotifyOnOwnHouseEntryString.Replace("$HOUSE_NAME", house.Name), Color.LightSeaGreen);
                                            }
                                            else
                                            {
                                                if (HConfig.NotifyVisitor)
                                                {
                                                    player.TSPlayer.SendMessage(HConfig.NotifyOnEntryString.Replace("$HOUSE_NAME", house.Name), Color.LightSeaGreen);
                                                }

                                                if (HConfig.NotifyOwner)
                                                {
                                                    HTools.BroadcastToHouseOwners(house.Name, HConfig.NotifyOnOtherEntryString.Replace("$PLAYER_NAME", player.TSPlayer.Name).Replace("$HOUSE_NAME", house.Name));
                                                }
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    NewCurHouses.Remove(house.Name);
                                    HousesNotIn++;
                                }
                            }
                            catch (Exception ex)
                            {
                                TShock.Log.Error(ex.ToString());
                            }
                        });
                    }
                    catch (Exception ex)
                    {
                        TShock.Log.Error(ex.ToString());
                        continue;
                    }

                    if (HConfig.NotifyOnExit)
                    {
                        {
                            var K = player.CurHouses.Count;
                            for (int k = 0; k < K; k++)
                            {
                                if (UTimeout(Start))
                                {
                                    return;
                                }
                                var cHouse = player.CurHouses[k];
                                if (!NewCurHouses.Contains(cHouse))
                                {
                                    if (HTools.OwnsHouse(player.TSPlayer.User, cHouse))
                                    {
                                        if (HConfig.NotifySelf)
                                        {
                                            player.TSPlayer.SendMessage(HConfig.NotifyOnOwnHouseExitString.Replace("$HOUSE_NAME", cHouse), Color.LightSeaGreen);
                                        }
                                    }
                                    else
                                    {
                                        if (HConfig.NotifyVisitor)
                                        {
                                            player.TSPlayer.SendMessage(HConfig.NotifyOnExitString.Replace("$HOUSE_NAME", cHouse), Color.LightSeaGreen);
                                        }

                                        if (HConfig.NotifyOwner)
                                        {
                                            HTools.BroadcastToHouseOwners(cHouse, HConfig.NotifyOnOtherExitString.Replace("$PLAYER_NAME", player.TSPlayer.Name).Replace("$HOUSE_NAME", cHouse));
                                        }
                                    }
                                }
                            }
                        }
                    }

                    player.CurHouses   = NewCurHouses;
                    player.LastTilePos = new Vector2(player.TSPlayer.TileX, player.TSPlayer.TileY);
                }
            }
            ULock = false;
        }