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

@ -29,7 +29,8 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin
* Correct rejection message in LandGolfBallInCupHandler to output the proper expected player id. (@drunderscore)
* Clarified the error mesage that the console is presented if a rate-limit is reached over REST to indicate that "tokens" actually refers to rate-limit tokens, and not auth tokens, and added a hint as to what config setting determines this. (@hakusaro, @patsore)
* Fixed an issue where, when the console was redirected, input was disabled and commands didn't work, in TSAPI. You can now pass `-disable-commands` to disable the input thread, but by default, it will be enabled. Fixes [#1450](https://github.com/Pryaxis/TShock/issues/1450). (@DeathCradle, @QuiCM)
* Fixed missing group problems & error reporting on startup. (@bartico6)
* Fixed errors on startup not being reported to console. (@bartico6)
* The server now correctly disconnects players with missing groups instead of throwing an exception, stalling the connection (@bartico6)
## TShock 4.5.4
* Fixed ridiculous typo in `GetDataHandlers` which caused TShock to read the wrong field in the packet for `usingBiomeTorches`. (@hakusaro, @Arthri)

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))
{
@ -217,6 +219,28 @@ namespace TShockAPI.DB
}
}
/// <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)
{
if (!GroupExists(name))

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,8 +216,9 @@ 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)
{