From 102c50a6389ce4b99a4f51220b6cf007b13b76c7 Mon Sep 17 00:00:00 2001 From: CoderCow Date: Thu, 27 Jun 2013 12:18:37 +0200 Subject: [PATCH] Fixed /region allowg adding an already existing group to the database multiple times. --- TShockAPI/DB/RegionManager.cs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/TShockAPI/DB/RegionManager.cs b/TShockAPI/DB/RegionManager.cs index a9cc2739..a4898b3f 100644 --- a/TShockAPI/DB/RegionManager.cs +++ b/TShockAPI/DB/RegionManager.cs @@ -473,27 +473,33 @@ namespace TShockAPI.DB return false; } - public bool AllowGroup(string regionName, string groups) + public bool AllowGroup(string regionName, string groupName) { - string groupsNew = ""; + string mergedGroups = ""; using ( - var reader = database.QueryReader("SELECT * FROM Regions WHERE RegionName=@0 AND WorldID=@1", regionName, + var reader = database.QueryReader("SELECT Groups FROM Regions WHERE RegionName=@0 AND WorldID=@1", regionName, Main.worldID.ToString())) { if (reader.Read()) - groupsNew = reader.Get("Groups"); + mergedGroups = reader.Get("Groups"); } - if (groupsNew != "") - groupsNew += ","; - groupsNew += groups; - int q = database.Query("UPDATE Regions SET Groups=@0 WHERE RegionName=@1 AND WorldID=@2", groupsNew, + string[] groups = mergedGroups.Split(','); + // Is the user 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(groupsNew); + r.SetAllowedGroups(mergedGroups); } else {