Add replacement for string AddGroup
Add deprecation warnings to previous methods
This commit is contained in:
parent
03d817e0a2
commit
da8ce502bc
1 changed files with 40 additions and 0 deletions
|
|
@ -110,6 +110,45 @@ namespace TShockAPI.DB
|
||||||
return 1 == ret.Count() ? ret.ElementAt(0) : null;
|
return 1 == ret.Count() ? ret.ElementAt(0) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds group with name and permissions if it does not exist.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">name of group</param>
|
||||||
|
/// <param name="parentname">parent of group</param>
|
||||||
|
/// <param name="permissions">permissions</param>
|
||||||
|
/// <param name="chatcolor">chatcolor</param>
|
||||||
|
public void AddGroup(String name, string parentname, String permissions, String chatcolor)
|
||||||
|
{
|
||||||
|
if (GroupExists(name))
|
||||||
|
{
|
||||||
|
throw new GroupExistsException(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
var group = new Group(name, null, chatcolor);
|
||||||
|
group.Permissions = permissions;
|
||||||
|
if (!string.IsNullOrWhiteSpace(parentname))
|
||||||
|
{
|
||||||
|
var parent = groups.FirstOrDefault(gp => gp.Name == parentname);
|
||||||
|
if (parent == null || name == parentname)
|
||||||
|
{
|
||||||
|
var error = "Invalid parent {0} for group {1}".SFormat(parentname, group.Name);
|
||||||
|
TShock.Log.ConsoleError(error);
|
||||||
|
throw new GroupManagerException(error);
|
||||||
|
}
|
||||||
|
group.Parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
string query = (TShock.Config.StorageType.ToLower() == "sqlite")
|
||||||
|
? "INSERT OR IGNORE INTO GroupList (GroupName, Parent, Commands, ChatColor) VALUES (@0, @1, @2, @3);"
|
||||||
|
: "INSERT IGNORE INTO GroupList SET GroupName=@0, Parent=@1, Commands=@2, ChatColor=@3";
|
||||||
|
if (database.Query(query, name, parentname, permissions, chatcolor) == 1)
|
||||||
|
{
|
||||||
|
groups.Add(group);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw new GroupManagerException("Failed to add group '" + name + ".'");
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds group with name and permissions if it does not exist.
|
/// Adds group with name and permissions if it does not exist.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -118,6 +157,7 @@ namespace TShockAPI.DB
|
||||||
/// <param name="permissions">permissions</param>
|
/// <param name="permissions">permissions</param>
|
||||||
/// <param name="chatcolor">chatcolor</param>
|
/// <param name="chatcolor">chatcolor</param>
|
||||||
/// <param name="exceptions">exceptions true indicates use exceptions for errors false otherwise</param>
|
/// <param name="exceptions">exceptions true indicates use exceptions for errors false otherwise</param>
|
||||||
|
[Obsolete("Use AddGroup(name, parentname, permissions, chatcolor) instead.")]
|
||||||
public String AddGroup(String name, string parentname, String permissions, String chatcolor = Group.defaultChatColor, bool exceptions = false)
|
public String AddGroup(String name, string parentname, String permissions, String chatcolor = Group.defaultChatColor, bool exceptions = false)
|
||||||
{
|
{
|
||||||
if (GroupExists(name))
|
if (GroupExists(name))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue