From 9d55122da8bf205571f8a4822f973e0fd0ec4a74 Mon Sep 17 00:00:00 2001 From: White Date: Thu, 16 Jul 2015 15:36:32 +0930 Subject: [PATCH] Teleport handler now handles wormhole potions. Added a permission to use wormhole potions --- TShockAPI/GetDataHandlers.cs | 52 ++++++++++++++++++++++++------------ TShockAPI/Permissions.cs | 3 +++ 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 95a7bd15..35344120 100755 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -3564,40 +3564,58 @@ namespace TShockAPI private static bool HandleTeleport(GetDataHandlerArgs args) { - var flag = (BitsByte)args.Data.ReadInt8(); - var id = args.Data.ReadInt16(); + BitsByte flag = (BitsByte)args.Data.ReadByte(); + short id = args.Data.ReadInt16(); var x = args.Data.ReadSingle(); var y = args.Data.ReadSingle(); if (OnTeleport(id, flag, x, y)) return true; + int type = 0; byte style = 0; - var isNPC = false || (flag & 1) == 1; + bool isNPC = type == 1; - if ((flag & 2) != 2) + if (flag[0]) { - if ((flag & 4) == 4) - { - style++; - } + type = 1; + } + if (flag[1]) + { + type = 2; + } + if (flag[2]) + { + style++; + } + if (flag[3]) + { + style += 2; + } - if ((flag & 8) == 8) - { - style++; - } + //Rod of Discord teleport (usually (may be used by modded clients to teleport)) + if (type == 0 && !args.Player.Group.HasPermission(Permissions.rod)) + { + args.Player.SendErrorMessage("You do not have permission to teleport."); + args.Player.Teleport(args.TPlayer.position.X, args.TPlayer.position.Y); + return true; + } - if (id > (isNPC ? 200 : 255)) - { - return true; - } + //NPC teleport + if (type == 1 && id >= Main.maxNPCs) + { + return true; + } + //Player to player teleport (wormhole potion, usually (may be used by modded clients to teleport)) + if (type == 2) + { if (id >= Main.maxPlayers || Main.player[id] == null || TShock.Players[id] == null) { return true; } - if (!isNPC && !args.Player.Group.HasPermission(Permissions.rod)) + if (!args.Player.Group.HasPermission(Permissions.wormhole)) { args.Player.SendErrorMessage("You do not have permission to teleport."); args.Player.Teleport(args.TPlayer.position.X, args.TPlayer.position.Y); diff --git a/TShockAPI/Permissions.cs b/TShockAPI/Permissions.cs index 369042a3..cfd88811 100644 --- a/TShockAPI/Permissions.cs +++ b/TShockAPI/Permissions.cs @@ -252,6 +252,9 @@ namespace TShockAPI [Description("User can use the Rod of Discor.")] public static readonly string rod = "tshock.tp.rod"; + [Description("User can use wormhole potions.")] + public static readonly string wormhole = "tshock.tp.wormhole"; + // tshock.world nodes [Description("User can change expert state.")]