diff --git a/CHANGELOG.md b/CHANGELOG.md index 51cdb1b2..573116fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,8 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Added a new `DisablePrimeBombs` config option (`false` by default). Highly recommended to set this to `true` in order to prevent griefing on servers doing a `for the worthy` play-through, since the prime bombs on this seed can destroy most tiles and bypass region protection. (@moisterrific) * Added a new `/respawn` command that lets you respawn yourself or another player. Respawning yourself requires the `tshock.respawn` permission and respawning others requires the `tshock.respawn.other` permission. The full command syntax is `/respawn [player]`. (@moisterrific) * Added a notification message and silent command support for permanently changing a target player's user group. Now players who received a group change will be notified of their new group if they are currently online. (@moisterrific, @QuiCM) +* Changed the TSPlayer IP method to return the loopback IP if RealPlayer is false. (@Rozen4334) +* Fixed a bug that caused sundials to be ignored all the time, instead of only when the player has no permission or time is frozen. (@Rozen4334) * Added colours and usage examples (similiar to how the new ban system looks) for many more commands. (@moisterrific) ## TShock 4.5.5 @@ -50,6 +52,9 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * `OnPlaceTileEntity`: The check was newly added. * `OnPlaceItemFrame`: The check was newly added. * `OnFoodPlatterTryPlacing`: The check was newly added. +* 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) +* The server now rejects login attempts from players who would end up with a missing group. (@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) @@ -78,6 +83,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * TShock defaults to saving backups every 10 minutes, and defaults to keeping backups for 4 hours. (@hakusaro) * Updated SSC bypass messaging. Now, when you connect, you're told if you're bypassing SSC. Console logging has been improved to warn when players are not being saved due to the bypass SSC permission. To turn this warning off, change `WarnPlayersAboutBypassPermission` to `false` in the `sscconfig.json` file. (@hakusaro) * Fix oversight & exploit allowing specially crafted SendTileRectangle packets to perform large-scale world griefing. In addition, `NetTile.Slope` is now the native value (byte), and accessor methods `Slope1`, `Slope2`, and `Slope3` can be used to get the old style of values out. `HalfBrick` and `Actuator` were removed from `NetTile` because these were initialized to zero and never changed or used. (@bartico6) +* Warning: a bug introduced in a prior TShock release may cause your SSC config file to be reset after applying this update. Please backup your config file prior to installing TShock 4.5.3+ if you use SSC. (@cardinal-system) ## TShock 4.5.2 * Added preliminary support for Terraria 1.4.2.2. (@hakusaro) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 7fd52b01..08dfb7cf 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -832,10 +832,16 @@ namespace TShockAPI (usingUUID && account.UUID == args.Player.UUID && !TShock.Config.Settings.DisableUUIDLogin && !String.IsNullOrWhiteSpace(args.Player.UUID))) { - args.Player.PlayerData = TShock.CharacterDB.GetPlayerData(args.Player, account.ID); - var group = TShock.Groups.GetGroupByName(account.Group); + if (!TShock.Groups.AssertGroupValid(args.Player, group, false)) + { + args.Player.SendErrorMessage("Login attempt failed - see the message above."); + return; + } + + args.Player.PlayerData = TShock.CharacterDB.GetPlayerData(args.Player, account.ID); + args.Player.Group = group; args.Player.tempGroup = null; args.Player.Account = account; @@ -5103,7 +5109,7 @@ namespace TShockAPI } IEnumerable cmdNames = from cmd in ChatCommands - where cmd.CanRun(args.Player) && (cmd.Name != "auth" || TShock.SetupToken != 0) + where cmd.CanRun(args.Player) && (cmd.Name != "setup" || TShock.SetupToken != 0) select Specifier + cmd.Name; PaginationTools.SendPage(args.Player, pageNumber, PaginationTools.BuildLinesFromTerms(cmdNames), diff --git a/TShockAPI/DB/GroupManager.cs b/TShockAPI/DB/GroupManager.cs index 3bb50881..750dc7a2 100644 --- a/TShockAPI/DB/GroupManager.cs +++ b/TShockAPI/DB/GroupManager.cs @@ -200,6 +200,45 @@ namespace TShockAPI.DB LoadPermisions(); Group.DefaultGroup = GetGroupByName(TShock.Config.Settings.DefaultGuestGroupName); + + AssertCoreGroupsPresent(); + } + + internal void AssertCoreGroupsPresent() + { + if (!GroupExists(TShock.Config.Settings.DefaultGuestGroupName)) + { + TShock.Log.ConsoleError("The guest group 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 guest group could not be found."); + } + + 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."); + } + } + + /// + /// Asserts that the group reference can be safely assigned to the player object. + /// If this assertion fails, and is true, the player is disconnected. If is false, the player will receive an error message. + /// + /// The player in question + /// The group we want to assign them + /// Whether or not failing this check disconnects the player. + /// + 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) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 3bed28b2..0e6097f1 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -2456,10 +2456,13 @@ namespace TShockAPI args.Player.State = 2; NetMessage.SendData((int)PacketTypes.WorldInfo, args.Player.Index); - args.Player.PlayerData = TShock.CharacterDB.GetPlayerData(args.Player, account.ID); - var group = TShock.Groups.GetGroupByName(account.Group); + if (!TShock.Groups.AssertGroupValid(args.Player, group, true)) + return true; + + args.Player.PlayerData = TShock.CharacterDB.GetPlayerData(args.Player, account.ID); + args.Player.Group = group; args.Player.tempGroup = null; args.Player.Account = account; @@ -3037,6 +3040,9 @@ namespace TShockAPI var group = TShock.Groups.GetGroupByName(account.Group); + if (!TShock.Groups.AssertGroupValid(args.Player, group, true)) + return true; + args.Player.Group = group; args.Player.tempGroup = null; args.Player.Account = account; @@ -3240,6 +3246,7 @@ namespace TShockAPI { TShock.Log.ConsoleDebug($"GetDataHandlers / HandleSpecial rejected enchanted sundial permission {args.Player.Name}"); args.Player.SendErrorMessage("You do not have permission to use the Enchanted Sundial."); + return true; } else if (TShock.Config.Settings.ForceTime != "normal") { @@ -3250,8 +3257,8 @@ namespace TShockAPI } else args.Player.SendErrorMessage("You must set ForceTime to normal via config to use the Enchanted Sundial."); + return true; } - return true; } return false; diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index aadaf746..7dfc377b 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -892,7 +892,7 @@ namespace TShockAPI CacheIP = RealPlayer ? (Netplay.Clients[Index].Socket.IsConnected() ? TShock.Utils.GetRealIP(Netplay.Clients[Index].Socket.GetRemoteAddress().ToString()) : "") - : ""; + : "127.0.0.1"; else return CacheIP; } diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 16fc1cb9..958d6507 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -386,8 +386,8 @@ namespace TShockAPI } catch (Exception ex) { - Log.Error("Fatal Startup Exception"); - Log.Error(ex.ToString()); + Log.ConsoleError("Fatal Startup Exception"); + Log.ConsoleError(ex.ToString()); Environment.Exit(1); } }