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.
This commit is contained in:
parent
7b2a4494b5
commit
e370873fff
3 changed files with 23 additions and 7 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -346,7 +346,7 @@ namespace TShockAPI
|
|||
/// <param name="x">The x coordinate they want to build at.</param>
|
||||
/// <param name="y">The y coordinate they want to paint at.</param>
|
||||
/// <returns>True if the player can build at the given point from build, spawn, and region protection.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue