Fixed /region allowg adding an already existing group to the database multiple times.
This commit is contained in:
parent
2b1d2093ff
commit
102c50a638
1 changed files with 15 additions and 9 deletions
|
|
@ -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
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue