Fixes for PR 2397.

- GroupManager now validates core groups in the constructor.
- EnsureCoreGroupsPresent -> AssertCoreGroupsPresent.
- Fix indentiation in some places.
- Clarify the intent of this PR in CHANGELOG.md.
This commit is contained in:
quake1337 2021-07-31 16:34:43 +02:00
parent c759af6d49
commit 51348d1806
4 changed files with 34 additions and 9 deletions

View file

@ -200,9 +200,11 @@ namespace TShockAPI.DB
LoadPermisions();
Group.DefaultGroup = GetGroupByName(TShock.Config.Settings.DefaultGuestGroupName);
AssertCoreGroupsPresent();
}
internal void EnsureCoreGroupsPresent()
internal void AssertCoreGroupsPresent()
{
if (!GroupExists(TShock.Config.Settings.DefaultGuestGroupName))
{
@ -210,11 +212,33 @@ namespace TShockAPI.DB
throw new Exception("The guest group could not be found.");
}
if(!GroupExists(TShock.Config.Settings.DefaultRegistrationGroupName))
{
if (!GroupExists(TShock.Config.Settings.DefaultRegistrationGroupName))
{
TShock.Log.ConsoleError("The default usergroup could not be found. This may indicate a typo in the configuration file, or that the group was renamed or deleted.");
throw new Exception("The default usergroup could not be found.");
}
}
}
/// <summary>
/// Asserts that the group reference can be safely assigned to the player object.
/// <para>If this assertion fails, and <paramref name="kick"/> is true, the player is disconnected. If <paramref name="kick"/> is false, the player will receive an error message.</para>
/// </summary>
/// <param name="player">The player in question</param>
/// <param name="group">The group we want to assign them</param>
/// <param name="kick">Whether or not failing this check disconnects the player.</param>
/// <returns></returns>
public bool AssertGroupValid(TSPlayer player, Group group, bool kick)
{
if (group == null)
{
if (kick)
player.Disconnect("Your account's group could not be loaded. Please contact server administrators about this.");
else
player.SendErrorMessage("Your account's group could not be loaded. Please contact server administrators about this.");
return false;
}
return true;
}
private void AddDefaultGroup(string name, string parent, string permissions)

View file

@ -322,7 +322,6 @@ namespace TShockAPI
Regions = new RegionManager(DB);
UserAccounts = new UserAccountManager(DB);
Groups = new GroupManager(DB);
Groups.EnsureCoreGroupsPresent();
ProjectileBans = new ProjectileManagager(DB);
TileBans = new TileManager(DB);
RememberedPos = new RememberedPosManager(DB);

View file

@ -216,11 +216,12 @@ namespace TShockAPI
/// Asserts that the group reference can be safely assigned to the player object.
/// <para>If this assertion fails, and <paramref name="kick"/> is true, the player is disconnected. If <paramref name="kick"/> is false, the player will receive an error message.</para>
/// </summary>
/// <param name="player"></param>
/// <param name="group"></param>
/// <param name="player">The player in question</param>
/// <param name="group">The group we want to assign them</param>
/// <param name="kick">Whether or not failing this check disconnects the player.</param>
/// <returns></returns>
public bool AssertGroupValid(TSPlayer player, Group group, bool kick)
{
{
if (group == null)
{
if (kick)