Add OnDoorUse hook/event in GetDataHandlers
This commit is contained in:
parent
e404176a3b
commit
580b6d7c61
2 changed files with 65 additions and 4 deletions
|
|
@ -21,6 +21,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin
|
|||
* Moved the emoji player index check into a new class of handlers called `IllegalPerSe`, which is designed to help isolate parts of TShock and make it so that "protocol violations" are treated separately from heuristic based anti-cheat checks. (@hakusaro)
|
||||
* Changed `TSPlayer.FindByNameOrID` so that it will continue searching for players and return a list of many players whem ambiguous matches exist in all cases. Specifically, this avoids a scenario where a griefer names themselves `1` and is difficult to enact justice on, because their name will not be found by the matching system used to kick players. To help with ambiguity, this method now processes requests with prefixes `tsi:` and `tsn:`. `tsi:[number]` will process the search as looking for an exact player by ID. `tsn:` will process the search as looking for an exact name, case sensitive. In both cases, the system will return an exact result in the "old-style" result, i.e., a `List<TSPlayer>` with exactly one result. For example, `/kick tsid:1` will match the player with the ID `1`. `/kick tsn:1` will match the username `1`. In addition, players who attempt to join the server with the name prefixes `tsn:` and `tsi:` will be rejected for having invalid names. (@hakusaro, @Onusai)
|
||||
* Added warnings for conditions where a password is set at runtime but can be bypassed. The thinking is that if a user sets a password when they're booting the server, that's what they expect to be the password. The only thing is that sometimes, other config options can basically defeat this as a security feature. The goal is just to communicate more and make things clearer. The server also warns users when UUID login is enabled, because it can be confusing and insecure. (@hakusaro, @Onusai)
|
||||
* Added hook for `OnDoorUse` (`DoorUse`) and associated `DoorUseEventArgs` fired when a door is used. Also added `GetDataHandlers.DoorAction` enum for determining the action of a door. (@hakusaro)
|
||||
|
||||
## TShock 4.5.3
|
||||
* Added permissions for using Teleportation Potions, Magic Conch, and Demon Conch. (@drunderscore)
|
||||
|
|
|
|||
|
|
@ -493,6 +493,50 @@ namespace TShockAPI
|
|||
return args.Handled;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// DoorUseEventArgs - the arguments for a DoorUse event
|
||||
/// </summary>
|
||||
public class DoorUseEventArgs : GetDataHandledEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// X - The x position of the door being used
|
||||
/// </summary>
|
||||
public short X { get; set; }
|
||||
/// <summary>
|
||||
/// Y - The y position of the door being used
|
||||
/// </summary>
|
||||
public short Y { get; set; }
|
||||
/// <summary>
|
||||
/// Direction - Information about which way the door opens or where the player is relative to the door
|
||||
/// </summary>
|
||||
public byte Direction { get; set; }
|
||||
/// <summary>
|
||||
/// Action - The type of thing happening to the door
|
||||
/// </summary>
|
||||
public DoorAction Action { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// DoorUse - called when a door is opened or closed (normal or trap)
|
||||
/// </summary>
|
||||
public static HandlerList<DoorUseEventArgs> DoorUse = new HandlerList<DoorUseEventArgs>();
|
||||
private static bool OnDoorUse(TSPlayer ply, MemoryStream data, short x, short y, byte direction, DoorAction action)
|
||||
{
|
||||
if (DoorUse == null)
|
||||
return false;
|
||||
|
||||
var args = new DoorUseEventArgs
|
||||
{
|
||||
Player = ply,
|
||||
X = x,
|
||||
Y = y,
|
||||
Direction = direction,
|
||||
Action = action
|
||||
};
|
||||
DoorUse.Invoke(null, args);
|
||||
return args.Handled;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// For use in a SendTileRect event
|
||||
/// </summary>
|
||||
|
|
@ -2618,10 +2662,17 @@ namespace TShockAPI
|
|||
|
||||
private static bool HandleDoorUse(GetDataHandlerArgs args)
|
||||
{
|
||||
byte type = (byte)args.Data.ReadByte();
|
||||
byte action = (byte)args.Data.ReadByte();
|
||||
short x = args.Data.ReadInt16();
|
||||
short y = args.Data.ReadInt16();
|
||||
args.Data.ReadByte(); //Ignore direction
|
||||
byte direction = (byte)args.Data.ReadByte(); //Ignore direction
|
||||
|
||||
DoorAction doorAction = (DoorAction)action;
|
||||
|
||||
if (OnDoorUse(args.Player, args.Data, x, y, direction, doorAction))
|
||||
return true;
|
||||
|
||||
ushort tileType = Main.tile[x, y].type;
|
||||
|
||||
if (x >= Main.maxTilesX || y >= Main.maxTilesY || x < 0 || y < 0) // Check for out of range
|
||||
{
|
||||
|
|
@ -2629,13 +2680,12 @@ namespace TShockAPI
|
|||
return true;
|
||||
}
|
||||
|
||||
if (type < 0 || type > 5)
|
||||
if (action < 0 || action > 5)
|
||||
{
|
||||
TShock.Log.ConsoleDebug("GetDataHandlers / HandleDoorUse rejected type 0 5 check {0}", args.Player.Name);
|
||||
return true;
|
||||
}
|
||||
|
||||
ushort tileType = Main.tile[x, y].type;
|
||||
|
||||
if (tileType != TileID.ClosedDoor && tileType != TileID.OpenDoor
|
||||
&& tileType != TileID.TallGateClosed && tileType != TileID.TallGateOpen
|
||||
|
|
@ -3995,6 +4045,16 @@ namespace TShockAPI
|
|||
return true;
|
||||
}
|
||||
|
||||
public enum DoorAction
|
||||
{
|
||||
OpenDoor = 0,
|
||||
CloseDoor,
|
||||
OpenTrapdoor,
|
||||
CloseTrapdoor,
|
||||
OpenTallGate,
|
||||
CloseTallGate
|
||||
}
|
||||
|
||||
public enum EditAction
|
||||
{
|
||||
KillTile = 0,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue