diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 64773b67..ecc9a4e3 100755 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -177,19 +177,18 @@ namespace TShockAPI if (cmd == null) { + return false; + } + + if (!cmd.CanRun(player)) + { + Tools.SendLogs(string.Format("{0} tried to execute {1}", player.Name, cmd.Name), Color.Red); + player.SendMessage("You do not have access to that command.", Color.Red); } else { - if (!cmd.CanRun(player)) - { - Tools.SendLogs(string.Format("{0} tried to execute {1}", player.Name, cmd.Name), Color.Red); - player.SendMessage("You do not have access to that command.", Color.Red); - } - else - { - Tools.SendLogs(string.Format("{0} executed: /{1}", player.Name, cmdText), Color.Red); - cmd.Run(cmdText, player, args); - } + Tools.SendLogs(string.Format("{0} executed: /{1}", player.Name, cmdText), Color.Red); + cmd.Run(cmdText, player, args); } return true; } @@ -655,20 +654,38 @@ namespace TShockAPI private static void Home(CommandArgs args) { - TShock.Teleport(args.Player.Index, args.TPlayer.SpawnX * 16 + 8 - args.TPlayer.width / 2, - args.TPlayer.SpawnY * 16 - args.TPlayer.height); + if (!args.Player.RealPlayer) + { + args.Player.SendMessage("You cant use teleport commands!"); + return; + } + + args.Player.Spawn(); args.Player.SendMessage("Teleported to your spawnpoint."); } private static void Spawn(CommandArgs args) { - TShock.Teleport(args.Player.Index, Main.spawnTileX * 16 + 8 - args.TPlayer.width / 2, - Main.spawnTileY * 16 - args.TPlayer.height); - args.Player.SendMessage("Teleported to the map's spawnpoint."); + if (!args.Player.RealPlayer) + { + args.Player.SendMessage("You cant use teleport commands!"); + return; + } + + if (args.Player.Teleport(Main.spawnTileX, Main.spawnTileY)) + args.Player.SendMessage("Teleported to the map's spawnpoint."); + else + args.Player.SendMessage("Can't teleport because you have set custom spawnpoint.", Color.Red); } private static void TP(CommandArgs args) { + if (!args.Player.RealPlayer) + { + args.Player.SendMessage("You cant use teleport commands!"); + return; + } + if (args.Parameters.Count < 1) { args.Player.SendMessage("Invalid syntax! Proper syntax: /tp ", Color.Red); @@ -684,13 +701,21 @@ namespace TShockAPI else { var plr = players[0]; - TShock.Teleport(args.Player.Index, plr.X, plr.Y); - args.Player.SendMessage(string.Format("Teleported to {0}", plr.Name)); + if (args.Player.Teleport(plr.TileX, plr.TileY)) + args.Player.SendMessage(string.Format("Teleported to {0}", plr.Name)); + else + args.Player.SendMessage("Can't teleport because you have set custom spawnpoint.", Color.Red); } } private static void TPHere(CommandArgs args) { + if (!args.Player.RealPlayer) + { + args.Player.SendMessage("You cant use teleport commands!"); + return; + } + if (args.Parameters.Count < 1) { args.Player.SendMessage("Invalid syntax! Proper syntax: /tphere ", Color.Red); @@ -710,9 +735,14 @@ namespace TShockAPI else { var plr = players[0]; - TShock.Teleport(plr.Index, args.Player.X, args.Player.Y); - plr.SendMessage(string.Format("You were teleported to {0}.", plr.Name)); - args.Player.SendMessage(string.Format("You brought {0} here.", plr.Name)); + if (plr.Teleport(args.Player.TileX, args.Player.TileY)) + { + plr.SendMessage(string.Format("You were teleported to {0}.", plr.Name)); + args.Player.SendMessage(string.Format("You brought {0} here.", plr.Name)); + } + else + args.Player.SendMessage("Can't teleport because target player has set custom spawnpoint.", Color.Red); + } } diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 39231a5b..1929c3ce 100755 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -21,9 +21,9 @@ using System.Diagnostics; using System.IO; using System.Text; using Microsoft.Xna.Framework; -using StreamBinary; using Terraria; using TerrariaAPI; +using XNAHelpers; namespace TShockAPI { diff --git a/TShockAPI/Log.cs b/TShockAPI/Log.cs index 8263356b..7dcf6129 100644 --- a/TShockAPI/Log.cs +++ b/TShockAPI/Log.cs @@ -117,16 +117,14 @@ namespace TShockAPI return; } - StackTrace trace = new StackTrace(); - StackFrame frame = null; + string caller = "TShock"; - frame = trace.GetFrame(2); - - string caller = "TShock: "; - - if (frame != null && frame.GetMethod().DeclaringType != null) + StackFrame frame = new StackTrace().GetFrame(2); + if (frame != null) { - caller += frame.GetMethod().DeclaringType.Name + ": "; + var meth = frame.GetMethod(); + if (meth != null) + caller = meth.DeclaringType.Name; } _logWriter.WriteLine(string.Format("{0} - {1}: {2}: {3}", diff --git a/TShockAPI/Properties/AssemblyInfo.cs b/TShockAPI/Properties/AssemblyInfo.cs index d5eb1cb0..ba1cac2c 100644 --- a/TShockAPI/Properties/AssemblyInfo.cs +++ b/TShockAPI/Properties/AssemblyInfo.cs @@ -35,5 +35,5 @@ using System.Runtime.InteropServices; // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.1.0.0618")] -[assembly: AssemblyFileVersion("2.1.0.0618")] \ No newline at end of file +[assembly: AssemblyVersion("2.2.0.0620")] +[assembly: AssemblyFileVersion("2.2.0.0620")] \ No newline at end of file diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 7a4b9835..e026b201 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -130,6 +130,31 @@ namespace TShockAPI NetMessage.SendData((int)PacketTypes.Disconnect, Index, -1, reason, 0x0, 0f, 0f, 0f); } + public bool Teleport(int tileX, int tileY) + { + if (TPlayer.SpawnX >= 0 && TPlayer.SpawnY >= 0) + return false; + + int oldSpawnX = Main.spawnTileX; + int oldSpawnY = Main.spawnTileY; + Main.spawnTileX = tileX; + Main.spawnTileY = tileY; + //Send only that player the new spawn point data + NetMessage.SendData((int)PacketTypes.WorldInfo, Index, -1, "", 0, 0f, 0f, 0f); + //Force them to respawn + Spawn(); + //Reset to old spawnpoint and send spawn data back to player + Main.spawnTileX = (int)oldSpawnX; + Main.spawnTileY = (int)oldSpawnY; + NetMessage.SendData((int)PacketTypes.WorldInfo, Index, -1, "", 0, 0f, 0f, 0f); + return true; + } + + public void Spawn() + { + NetMessage.SendData((int)PacketTypes.PlayerSpawn, Index, -1, "", Index, 0.0f, 0.0f, 0.0f); + } + public virtual void SendTileSquare(int x, int y, int size = 10) { NetMessage.SendData((int)PacketTypes.TileSendSquare, Index, -1, "", size, (float)(x - (size / 2)), (float)(y - (size / 2)), 0f); diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 7c2e3d4e..64421f3b 100755 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -17,6 +17,7 @@ along with this program. If not, see . */ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Diagnostics; using System.IO; using System.Net; @@ -29,7 +30,7 @@ using TerrariaAPI.Hooks; namespace TShockAPI { - [APIVersion(1, 4)] + [APIVersion(1, 5)] public class TShock : TerrariaPlugin { public static readonly Version VersionNum = Assembly.GetExecutingAssembly().GetName().Version; @@ -256,7 +257,7 @@ namespace TShockAPI private void OnChat(messageBuffer msg, int ply, string text, HandledEventArgs e) { - if (Main.netMode != 2) + if (Main.netMode != 2 || e.Handled) return; if (msg.whoAmI != ply) @@ -293,6 +294,9 @@ namespace TShockAPI /// private void ServerHooks_OnCommand(string text, HandledEventArgs e) { + if (e.Handled) + return; + // Damn you ThreadStatic and Redigit if (Main.rand == null) { @@ -335,6 +339,9 @@ namespace TShockAPI private void GetData(GetDataEventArgs e) { + if (Main.netMode != 2 || e.Handled) + return; + PacketTypes type = e.MsgID; TSPlayer player = Players[e.Msg.whoAmI]; @@ -372,7 +379,7 @@ namespace TShockAPI private void OnGreetPlayer(int who, HandledEventArgs e) { - if (Main.netMode != 2) + if (Main.netMode != 2 || e.Handled) return; TSPlayer player = Players[who]; @@ -410,27 +417,6 @@ namespace TShockAPI * Useful stuff: * */ - public static void Teleport(int ply, int x, int y) - { - int oldSpawnX = Main.spawnTileX; - int oldSpawnY = Main.spawnTileY; - Main.spawnTileX = x; - Main.spawnTileY = y; - //Send only that player the new spawn point data - NetMessage.SendData(7, ply, -1, "", 0, 0f, 0f, 0f); - //Force them to respawn - NetMessage.SendData(12, ply, -1, "", ply, 0.0f, 0.0f, 0.0f); - //Reset to old spawnpoint and send spawn data back to player - Main.spawnTileX = (int)oldSpawnX; - Main.spawnTileY = (int)oldSpawnY; - NetMessage.SendData(7, ply, -1, "", 0, 0f, 0f, 0f); - } - - public static void Teleport(int ply, float x, float y) - { - Teleport(ply, (int)x, (int)y); - } - public static void StartInvasion() { Main.invasionType = 1; diff --git a/TShockAPI/TShockAPI.csproj b/TShockAPI/TShockAPI.csproj index 473f3abd..aa28d8e9 100644 --- a/TShockAPI/TShockAPI.csproj +++ b/TShockAPI/TShockAPI.csproj @@ -67,6 +67,9 @@ TerrariaServerBins\TerrariaServerAPI.dll + + TerrariaServerBins\XNAHelpers.dll + @@ -134,7 +137,7 @@ - +