Example #1
0
        /// <summary>
        /// Inserts a region with the specified name.
        /// </summary>
        /// <param name="name">The name.</param>
        public void Add(string name)
        {
            var region = new XRegion(name, new List <RegionAction>());

            _regions.Add(region);
            _dbConnection.Query("INSERT INTO XRegions (Name, Actions, TempGroup) VALUES (@0, @1, @2)", name, string.Empty,
                                string.Empty);
        }
Example #2
0
        /// <summary>
        /// Updates a region.
        /// </summary>
        /// <param name="region">The region.</param>
        public void Update(XRegion region)
        {
            _dbConnection.Query("UPDATE XRegions SET Actions = @0, TempGroup = @1 WHERE Name = @2",
                                string.Join(",", region.Actions), region.TempGroup?.Name ?? string.Empty, region.Region.Name);

            _dbConnection.Query("DELETE FROM XRegionBans WHERE Name = @0", region.Region.Name);
            _dbConnection.Query("INSERT INTO XRegionBans (Name, ItemBans, ProjectileBans) VALUES (@0, @1, @2)",
                                region.Region.Name, string.Join(",", region.BannedItems), string.Join(",", region.BannedProjectiles));
        }
Example #3
0
        /// <summary>
        /// Loads the regions.
        /// </summary>
        public void Load()
        {
            _regions.Clear();
            using (var reader = _dbConnection.QueryReader("SELECT * FROM XRegions"))
            {
                while (reader.Read())
                {
                    var name      = reader.Get <string>("Name");
                    var actions   = new List <RegionAction>();
                    var tempGroup = TShock.Groups.GetGroupByName(reader.Get <string>("TempGroup") ?? "");
                    foreach (var actionName in reader.Get <string>("Actions").Split(','))
                    {
                        if (Enum.TryParse <RegionAction>(actionName, out var action))
                        {
                            actions.Add(action);
                        }
                    }

                    var region = new XRegion(name, actions)
                    {
                        TempGroup = tempGroup
                    };
                    using (var banReader = _dbConnection.QueryReader("SELECT * FROM XRegionBans WHERE Name = @0", name))
                    {
                        if (banReader.Read())
                        {
                            foreach (var itemBan in banReader.Get <string>("ItemBans").Split(','))
                            {
                                if (int.TryParse(itemBan, out var itemId))
                                {
                                    region.BannedItems.Add(itemId);
                                }
                            }
                            foreach (var projectileBan in banReader.Get <string>("ProjectileBans").Split(','))
                            {
                                if (int.TryParse(projectileBan, out var projectileId))
                                {
                                    region.BannedProjectiles.Add(projectileId);
                                }
                            }
                        }
                    }
                    _regions.Add(region);
                }
            }
        }