Prevent users from removing default guest group

The default guest group is critical and shouldn't be removed without
either TShock doing something like automatically recreating it if it
doesn't exist, or not having a huge problem if it doesn't exist.

I chose to take the easiest path, preventing users from removing it. In
theory the message gives enough context to imply "okay, go change the
group now."

This should be a relatively small edge case but I wanted to resolve it
while I was here.
This commit is contained in:
Lucas Nicodemus 2021-06-13 01:09:03 -07:00
parent 25a7e9e83a
commit 4d46e58865
3 changed files with 11 additions and 3 deletions

View file

@ -3498,7 +3498,7 @@ namespace TShockAPI
try
{
string response = TShock.Groups.DeleteGroup(args.Parameters[1]);
string response = TShock.Groups.DeleteGroup(args.Parameters[1], true);
if (response.Length > 0)
{
args.Player.SendSuccessMessage(response);
@ -3506,7 +3506,7 @@ namespace TShockAPI
}
catch (GroupManagerException ex)
{
args.Player.SendErrorMessage(ex.ToString());
args.Player.SendErrorMessage(ex.Message);
}
}
#endregion
@ -3542,7 +3542,7 @@ namespace TShockAPI
}
catch (GroupManagerException ex)
{
args.Player.SendErrorMessage(ex.ToString());
args.Player.SendErrorMessage(ex.Message);
}
}
#endregion

View file

@ -456,6 +456,13 @@ namespace TShockAPI.DB
return "Error: Group doesn't exist.";
}
if (name == Group.DefaultGroup.Name)
{
if (exceptions)
throw new GroupManagerException("Unable to remove default guest group.");
return "Error: Unable to remove the default guest group.";
}
if (database.Query("DELETE FROM GroupList WHERE GroupName=@0", name) == 1)
{
groups.Remove(TShock.Groups.GetGroupByName(name));