Merge branch 'master' of git://github.com/TShock/TShock

This commit is contained in:
Twitchy 2011-06-21 16:13:49 +12:00
commit 93e381a0a7
9 changed files with 98 additions and 56 deletions

View file

@ -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 <player> ", 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 <player> ", 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);
}
}

View file

@ -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
{

View file

@ -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}",

View file

@ -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")]
[assembly: AssemblyVersion("2.2.0.0620")]
[assembly: AssemblyFileVersion("2.2.0.0620")]

View file

@ -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);

View file

@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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
/// <param name="e"></param>
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;

View file

@ -67,6 +67,9 @@
<Reference Include="TerrariaServerAPI">
<HintPath>TerrariaServerBins\TerrariaServerAPI.dll</HintPath>
</Reference>
<Reference Include="XNAHelpers">
<HintPath>TerrariaServerBins\XNAHelpers.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="BackupManager.cs" />
@ -134,7 +137,7 @@
</PropertyGroup>
<ProjectExtensions>
<VisualStudio>
<UserProperties BuildVersion_UpdateAssemblyVersion="True" BuildVersion_UpdateFileVersion="True" BuildVersion_BuildAction="Both" BuildVersion_BuildVersioningStyle="None.None.None.MonthAndDayStamp" BuildVersion_StartDate="2011/6/17" BuildVersion_IncrementBeforeBuild="False" />
<UserProperties BuildVersion_IncrementBeforeBuild="False" BuildVersion_StartDate="2011/6/17" BuildVersion_BuildVersioningStyle="None.None.None.MonthAndDayStamp" BuildVersion_BuildAction="Both" BuildVersion_UpdateFileVersion="True" BuildVersion_UpdateAssemblyVersion="True" />
</VisualStudio>
</ProjectExtensions>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

Binary file not shown.