Fixed /region allowg adding an already existing group to the database multiple times.

This commit is contained in:
CoderCow 2013-06-27 12:18:37 +02:00
parent 2b1d2093ff
commit 102c50a638

View file

@ -473,27 +473,33 @@ namespace TShockAPI.DB
return false; return false;
} }
public bool AllowGroup(string regionName, string groups) public bool AllowGroup(string regionName, string groupName)
{ {
string groupsNew = ""; string mergedGroups = "";
using ( 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())) Main.worldID.ToString()))
{ {
if (reader.Read()) if (reader.Read())
groupsNew = reader.Get<string>("Groups"); mergedGroups = 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, 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()); regionName, Main.worldID.ToString());
Region r = GetRegionByName(regionName); Region r = GetRegionByName(regionName);
if (r != null) if (r != null)
{ {
r.SetAllowedGroups(groupsNew); r.SetAllowedGroups(mergedGroups);
} }
else else
{ {