public SetAllowedGroups ( String groups ) : void | ||
groups | String | String of group names to set |
리턴 | void |
public bool AllowGroup(string regionName, string groups) { string groupsNew = ""; using ( var reader = database.QueryReader("SELECT * FROM Regions WHERE RegionName=@0 AND WorldID=@1", regionName, Main.worldID.ToString())) { if (reader.Read()) { groupsNew = reader.Get <string>("Groups"); } } if (groupsNew != "") { groupsNew += ","; } groupsNew += groups; int q = database.Query("UPDATE Regions SET Groups=@0 WHERE RegionName=@1 AND WorldID=@2", groupsNew, regionName, Main.worldID.ToString()); Region r = GetRegionByName(regionName); if (r != null) { r.SetAllowedGroups(groupsNew); } else { return(false); } return(q > 0); }
/// <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 id = reader.Get <int>("Id"); 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(id, 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 userid; if (Int32.TryParse(splitids[i], out userid)) // if unparsable, it's not an int, so silently skip { r.AllowedIDs.Add(userid); } 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()); } }
/// <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 id = reader.Get <int>("Id"); 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(id, 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 userid; if (Int32.TryParse(splitids[i], out userid)) // if unparsable, it's not an int, so silently skip { r.AllowedIDs.Add(userid); } else { TShock.Log.Warn("UserIDs 有一列不可用数据: " + splitids[i]); } } } catch (Exception e) { TShock.Log.Error("数据库中含有无效的用户ID. (UserIDs 数据类型是整数)."); TShock.Log.Error("很多操作会受到影响. 你必须手动删除这些数据并修复."); TShock.Log.Error(e.ToString()); TShock.Log.Error(e.StackTrace); } Regions.Add(r); } } } catch (Exception ex) { TShock.Log.Error(ex.ToString()); } }
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(','); string owner = reader.Get <string>("Owner"); string groups = reader.Get <string>("Groups"); int z = reader.Get <int>("Z"); 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 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); } } }
/// <summary> /// Allows a group to use a region /// </summary> /// <param name="regionName">Region name</param> /// <param name="groupName">Group's name</param> /// <returns>Whether the change was successfull</returns> public bool AllowGroup(string regionName, string groupName) { string mergedGroups = ""; using ( var reader = database.QueryReader("SELECT `Groups` FROM Regions WHERE RegionName=@0 AND WorldID=@1", regionName, Main.worldID.ToString())) { if (reader.Read()) { mergedGroups = reader.Get <string>("Groups"); } } string[] groups = mergedGroups.Split(','); // Is the group already allowed to the region? if (groups.Contains(groupName)) { return(true); } if (mergedGroups != "") { mergedGroups += ","; } mergedGroups += groupName; int q = database.Query("UPDATE Regions SET `Groups`=@0 WHERE RegionName=@1 AND WorldID=@2", mergedGroups, regionName, Main.worldID.ToString()); Region r = GetRegionByName(regionName); if (r != null) { r.SetAllowedGroups(mergedGroups); } else { return(false); } return(q > 0); }
/// <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 id = reader.Get<int>("Id"); 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(id, 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 userid; if (Int32.TryParse(splitids[i], out userid)) // if unparsable, it's not an int, so silently skip r.AllowedIDs.Add(userid); 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 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(','); string owner = reader.Get<string>("Owner"); string groups = reader.Get<string>("Groups"); Region r = new Region(new Rectangle(X1, Y1, width, height), name, owner, Protected != 0, Main.worldID.ToString()); 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 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); } } }