public static void OnRegionDeleted(Region region) { if (RegionDeleted == null) return; RegionDeleted(new RegionDeletedEventArgs(region)); }
public static void OnRegionLeft(TSPlayer player, Region region) { if (RegionLeft == null) { return; } RegionLeft(new RegionLeftEventArgs(player, region)); }
public static void OnRegionEntered(TSPlayer player, Region region) { if (RegionEntered == null) { return; } RegionEntered(new RegionEnteredEventArgs(player, region)); }
public void AddRegion() { Region r = new Region( new Rectangle(100,100,100,100), "test", "test", true, "test"); Assert.IsTrue(manager.AddRegion(r.Area.X, r.Area.Y, r.Area.Width, r.Area.Height, r.Name, r.Owner, r.WorldID)); Assert.AreEqual(1, manager.Regions.Count); Assert.IsNotNull(manager.ZacksGetRegionByName("test")); Region r2 = new Region(new Rectangle(201, 201, 100, 100), "test2", "test2", true, "test"); manager.AddRegion(r2.Area.X, r2.Area.Y, r2.Area.Width, r2.Area.Height, r2.Name, r2.Owner, r2.WorldID); Assert.AreEqual(2, manager.Regions.Count); Assert.IsNotNull(manager.ZacksGetRegionByName("test2")); }
/// <summary> /// Reloads all regions. /// </summary> public void Reload() { try { using (var reader = database.QueryReader("SELECT * FROM Regions WHERE WorldID=@0", Main.worldID.ToString())) { Regions.Clear(); while (reader.Read()) { int X1 = reader.Get<int>("X1"); int Y1 = reader.Get<int>("Y1"); int height = reader.Get<int>("height"); int width = reader.Get<int>("width"); int Protected = reader.Get<int>("Protected"); string mergedids = reader.Get<string>("UserIds"); string name = reader.Get<string>("RegionName"); string owner = reader.Get<string>("Owner"); string groups = reader.Get<string>("Groups"); int z = reader.Get<int>("Z"); string[] splitids = mergedids.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries); Region r = new Region(new Rectangle(X1, Y1, width, height), name, owner, Protected != 0, Main.worldID.ToString(), z); r.SetAllowedGroups(groups); try { for (int i = 0; i < splitids.Length; i++) { int id; if (Int32.TryParse(splitids[i], out id)) // if unparsable, it's not an int, so silently skip r.AllowedIDs.Add(id); else TShock.Log.Warn("One of your UserIDs is not a usable integer: " + splitids[i]); } } catch (Exception e) { TShock.Log.Error("Your database contains invalid UserIDs (they should be ints)."); TShock.Log.Error("A lot of things will fail because of this. You must manually delete and re-create the allowed field."); TShock.Log.Error(e.ToString()); TShock.Log.Error(e.StackTrace); } Regions.Add(r); } } } catch (Exception ex) { TShock.Log.Error(ex.ToString()); } }
public void AddRegion() { Region r = new Region(new Rectangle(100, 100, 100, 100), "test", "test", true, "test", 0); Assert.IsTrue(manager.AddRegion(r.Area.X, r.Area.Y, r.Area.Width, r.Area.Height, r.Name, r.Owner, r.WorldID)); Assert.AreEqual(1, manager.Regions.Count); Assert.IsNotNull(manager.ZacksGetRegionByName("test")); Region r2 = new Region(new Rectangle(201, 201, 100, 100), "test2", "test2", true, "test", 0); manager.AddRegion(r2.Area.X, r2.Area.Y, r2.Area.Width, r2.Area.Height, r2.Name, r2.Owner, r2.WorldID); Assert.AreEqual(2, manager.Regions.Count); Assert.IsNotNull(manager.ZacksGetRegionByName("test2")); }
public void ReloadForUnitTest(String n) { using (var reader = database.QueryReader("SELECT * FROM Regions WHERE WorldID=@0", n)) { Regions.Clear(); while (reader.Read()) { int X1 = reader.Get<int>("X1"); int Y1 = reader.Get<int>("Y1"); int height = reader.Get<int>("height"); int width = reader.Get<int>("width"); int Protected = reader.Get<int>("Protected"); string MergedIDs = reader.Get<string>("UserIds"); string name = reader.Get<string>("RegionName"); string[] SplitIDs = MergedIDs.Split(','); Region r = new Region(new Rectangle(X1, Y1, width, height), name, Protected != 0, Main.worldID.ToString()); try { for (int i = 0; i < SplitIDs.Length; i++) { int id; if (Int32.TryParse(SplitIDs[i], out id)) // if unparsable, it's not an int, so silently skip r.AllowedIDs.Add(id); else if (SplitIDs[i] == "") // Split gotcha, can return an empty string with certain conditions // but we only want to let the user know if it's really a nonparsable integer. Log.Warn("UnitTest: One of your UserIDs is not a usable integer: " + SplitIDs[i]); } } catch (Exception e) { Log.Error("Your database contains invalid UserIDs (they should be ints)."); Log.Error("A lot of things will fail because of this. You must manually delete and re-create the allowed field."); Log.Error(e.Message); Log.Error(e.StackTrace); } Regions.Add(r); } } }
public void ImportOld() { String file = Path.Combine(TShock.SavePath, "regions.xml"); if (!File.Exists(file)) return; Region region; Rectangle rect; using (var reader = XmlReader.Create(new StreamReader(file), new XmlReaderSettings { CloseInput = true })) { // Parse the file and display each of the nodes. while (reader.Read()) { if (reader.NodeType != XmlNodeType.Element || reader.Name != "ProtectedRegion") continue; region = new Region(); rect = new Rectangle(); bool endregion = false; while (reader.Read() && !endregion) { if (reader.NodeType != XmlNodeType.Element) continue; string name = reader.Name; while (reader.Read() && reader.NodeType != XmlNodeType.Text) ; int t = 0; switch (name) { case "RegionName": region.Name = reader.Value; break; case "Point1X": int.TryParse(reader.Value, out t); rect.X = t; break; case "Point1Y": int.TryParse(reader.Value, out t); rect.Y = t; break; case "Point2X": int.TryParse(reader.Value, out t); rect.Width = t; break; case "Point2Y": int.TryParse(reader.Value, out t); rect.Height = t; break; case "Protected": region.DisableBuild = reader.Value.ToLower().Equals("true"); break; case "WorldName": region.WorldID = reader.Value; break; case "AllowedUserCount": break; case "IP": region.AllowedIDs.Add(int.Parse(reader.Value)); break; default: endregion = true; break; } } region.Area = rect; string query = (TShock.Config.StorageType.ToLower() == "sqlite") ? "INSERT OR IGNORE INTO Regions VALUES (@0, @1, @2, @3, @4, @5, @6, @7);" : "INSERT IGNORE INTO Regions SET X1=@0, Y1=@1, height=@2, width=@3, RegionName=@4, WorldID=@5, UserIds=@6, Protected=@7;"; database.Query(query, region.Area.X, region.Area.Y, region.Area.Width, region.Area.Height, region.Name, region.WorldID, "", region.DisableBuild); //Todo: What should this be? We don't really have a way to go from ips to userids /*string.Join(",", region.AllowedIDs)*/ } } String path = Path.Combine(TShock.SavePath, "old_configs"); String file2 = Path.Combine(path, "regions.xml"); if (!Directory.Exists(path)) Directory.CreateDirectory(path); if (File.Exists(file2)) File.Delete(file2); File.Move(file, file2); ReloadAllRegions(); }
public RegionCreatedEventArgs(Region region) { Region = region; }
public RegionLeftEventArgs(TSPlayer ply, Region region) { Player = ply; Region = region; }
public RegionEnteredEventArgs(TSPlayer ply, Region region) { Player = ply; Region = region; }
public RegionDeletedEventArgs(Region region) { Region = region; }
/// <summary> /// Adds a region to the database. /// </summary> /// <param name="tx">TileX of the top left corner.</param> /// <param name="ty">TileY of the top left corner.</param> /// <param name="width">Width of the region in tiles.</param> /// <param name="height">Height of the region in tiles.</param> /// <param name="regionname">The name of the region.</param> /// <param name="owner">The User Account Name of the person who created this region.</param> /// <param name="worldid">The world id that this region is in.</param> /// <param name="z">The Z index of the region.</param> /// <returns>Whether the region was created and added successfully.</returns> public bool AddRegion(int tx, int ty, int width, int height, string regionname, string owner, string worldid, int z = 0) { if (GetRegionByName(regionname) != null) { return false; } try { database.Query( "INSERT INTO Regions (X1, Y1, width, height, RegionName, WorldID, UserIds, Protected, Groups, Owner, Z) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10);", tx, ty, width, height, regionname, worldid, "", 1, "", owner, z); int id; using (QueryResult res = database.QueryReader("SELECT Id FROM Regions WHERE RegionName = @0 AND WorldID = @1", regionname, worldid)) { if (res.Read()) { id = res.Get<int>("Id"); } else { return false; } } Region region = new Region(id, new Rectangle(tx, ty, width, height), regionname, owner, true, worldid, z); Regions.Add(region); Hooks.RegionHooks.OnRegionCreated(region); return true; } catch (Exception ex) { TShock.Log.Error(ex.ToString()); } return false; }
/// <summary> /// Adds a region to the database. /// </summary> /// <param name="tx">TileX of the top left corner.</param> /// <param name="ty">TileY of the top left corner.</param> /// <param name="width">Width of the region in tiles.</param> /// <param name="height">Height of the region in tiles.</param> /// <param name="regionname">The name of the region.</param> /// <param name="owner">The User Account Name of the person who created this region.</param> /// <param name="worldid">The world id that this region is in.</param> /// <param name="z">The Z index of the region.</param> /// <returns>Whether the region was created and added successfully.</returns> public bool AddRegion(int tx, int ty, int width, int height, string regionname, string owner, string worldid, int z = 0) { if (GetRegionByName(regionname) != null) { return false; } try { database.Query( "INSERT INTO Regions (X1, Y1, width, height, RegionName, WorldID, UserIds, Protected, Groups, Owner, Z) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10);", tx, ty, width, height, regionname, worldid, "", 1, "", owner, z); var region = new Region(new Rectangle(tx, ty, width, height), regionname, owner, true, worldid, z); Regions.Add(region); Hooks.RegionHooks.OnRegionCreated(region); return true; } catch (Exception ex) { TShock.Log.Error(ex.ToString()); } return false; }
public FlaggedRegion(Region r, int f ) { region = r; flags = f; }
public FlaggedRegion(Region r ) { region = r; }