From e370873fff5a3d511c0a7a05da5f1d70f95aa973 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Fri, 22 Dec 2017 01:27:14 -0700 Subject: [PATCH] Warn players if they can't modify the world This reimplements warnings that CheckTilePermissions previously had. It defaults to on because every single call currently in TShock expects it to be on. --- CHANGELOG.md | 1 + TShockAPI/Bouncer.cs | 3 --- TShockAPI/TSPlayer.cs | 26 ++++++++++++++++++++++---- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e081c0b6..db04f777 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Fix message requiring login not using the command specifier set in the config file. (@hakusaro) * Move `TShock.CheckRangePermission()` to `TSPlayer.IsInRange` which **returns the opposite** of what the previous method did (see updated docs). (@hakusaro) * Move `TShock.CheckSpawn` to `Utils.IsInSpawn`. (@hakusaro) +* Replace `TShock.CheckTilePermission` with `TSPlayer.HasBuildPermission`, `TSPlayer.HasPaintPermission`, and `TSPlayer.HasModifiedIceSuccessfully` respectively. (@hakusaro) ## TShock 4.3.25 * Fixed a critical exploit in the Terraria protocol that could cause massive unpreventable world corruption as well as a number of other problems. Thanks to @bartico6 for reporting. Fixed by the efforts of @QuiCM, @hakusaro, and tips in the right directioon from @bartico6. diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index 77d602a7..d17c5266 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -533,11 +533,8 @@ namespace TShockAPI short y = args.Y; byte homeless = args.Homeless; - // Calls to TShock.CheckTilePermission need to be broken up into different subsystems - // In particular, this handles both regions and other things. Ouch. if (!args.Player.HasBuildPermission(x, y)) { - args.Player.SendErrorMessage("You do not have access to modify this area."); args.Player.SendData(PacketTypes.UpdateNPCHome, "", id, Main.npc[id].homeTileX, Main.npc[id].homeTileY, Convert.ToByte(Main.npc[id].homeless)); args.Handled = true; diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index a5aa17f2..dad3ca4e 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -346,7 +346,7 @@ namespace TShockAPI /// The x coordinate they want to build at. /// The y coordinate they want to paint at. /// True if the player can build at the given point from build, spawn, and region protection. - public bool HasBuildPermission(int x, int y) + public bool HasBuildPermission(int x, int y, bool shouldWarnPlayer = true) { BuildPermissionFailPoint failure = BuildPermissionFailPoint.GeneralBuild; // The goal is to short circuit on easy stuff as much as possible. @@ -356,10 +356,12 @@ namespace TShockAPI // (General build protection takes precedence over spawn protection) if (!TShock.Config.DisableBuild || HasPermission(Permissions.antibuild)) { + failure = BuildPermissionFailPoint.SpawnProtect; // If they have spawn protect bypass, or it isn't spawn, or it isn't in spawn; continue // (If they have spawn protect bypass, we don't care if it's spawn or not) if (!TShock.Config.SpawnProtection || HasPermission(Permissions.editspawn) || !Utils.IsInSpawn(x, y)) { + failure = BuildPermissionFailPoint.Regions; // If they have build permission in this region, then they're allowed to continue if (TShock.Regions.CanBuild(x, y, this)) { @@ -367,12 +369,28 @@ namespace TShockAPI } } } - - // TODO: Implement warning system. - // If they lack build permission, they end up here. // If they have build permission but lack the ability to edit spawn and it's spawn, they end up here. // If they have build, it isn't spawn, or they can edit spawn, but they fail the region check, they end up here. + + // If they shouldn't be warned, exit early. + if (!shouldWarnPlayer) + return false; + + // If they should be warned, warn them. + switch (failure) + { + case BuildPermissionFailPoint.GeneralBuild: + SendErrorMessage("You lack permission to build on this server."); + break; + case BuildPermissionFailPoint.SpawnProtect: + SendErrorMessage("You lack permission to build in the spawn point."); + break; + case BuildPermissionFailPoint.Regions: + SendErrorMessage("You lack permission to build in this region."); + break; + } + return false; }