Did some tweaks to Teleport to make the bounds checks in one place.

Fixed item drop packet, as well as update the bounds.
This commit is contained in:
Zack Piispanen 2013-09-30 19:34:43 -04:00
parent b8a5492b20
commit d71aacc58d
4 changed files with 36 additions and 46 deletions

View file

@ -1651,24 +1651,6 @@ namespace TShockAPI
float x, y; float x, y;
if (float.TryParse(args.Parameters[0], out x) && float.TryParse(args.Parameters[1], out y)) if (float.TryParse(args.Parameters[0], out x) && float.TryParse(args.Parameters[1], out y))
{ {
if (x < 500)
{
x = 500;
}
if (y < 500)
{
y = 500;
}
if (x > Main.rightWorld - 500)
{
x = Main.rightWorld - 500;
}
if (y > Main.bottomWorld - 500)
{
y = Main.bottomWorld - 500;
}
args.Player.Teleport(x, y); args.Player.Teleport(x, y);
args.Player.SendSuccessMessage("Teleported!"); args.Player.SendSuccessMessage("Teleported!");
} }

View file

@ -924,6 +924,10 @@ namespace TShockAPI
/// </summary> /// </summary>
public byte Prefix { get; set; } public byte Prefix { get; set; }
/// <summary> /// <summary>
/// No Delay on pickup
/// </summary>
public bool NoDelay { get; set; }
/// <summary>
/// Item type /// Item type
/// </summary> /// </summary>
public short Type { get; set; } public short Type { get; set; }
@ -933,7 +937,7 @@ namespace TShockAPI
/// </summary> /// </summary>
public static HandlerList<ItemDropEventArgs> ItemDrop; public static HandlerList<ItemDropEventArgs> ItemDrop;
private static bool OnItemDrop(short id, Vector2 pos, Vector2 vel, byte stacks, byte prefix, short type) private static bool OnItemDrop(short id, Vector2 pos, Vector2 vel, byte stacks, byte prefix, bool noDelay, short type)
{ {
if (ItemDrop == null) if (ItemDrop == null)
return false; return false;
@ -945,6 +949,7 @@ namespace TShockAPI
Velocity = vel, Velocity = vel,
Stacks = stacks, Stacks = stacks,
Prefix = prefix, Prefix = prefix,
NoDelay = noDelay,
Type = type, Type = type,
}; };
ItemDrop.Invoke(null, args); ItemDrop.Invoke(null, args);
@ -2746,13 +2751,14 @@ namespace TShockAPI
var vel = new Vector2(args.Data.ReadSingle(), args.Data.ReadSingle()); var vel = new Vector2(args.Data.ReadSingle(), args.Data.ReadSingle());
var stacks = args.Data.ReadInt8(); var stacks = args.Data.ReadInt8();
var prefix = args.Data.ReadInt8(); var prefix = args.Data.ReadInt8();
var noDelay = args.Data.ReadBoolean();
var type = args.Data.ReadInt16(); var type = args.Data.ReadInt16();
if (OnItemDrop(id, pos, vel, stacks, prefix, type)) if (OnItemDrop(id, pos, vel, stacks, prefix, noDelay, type))
return true; return true;
// player is attempting to crash clients // player is attempting to crash clients
if (type < -24 || type >= Main.maxItemTypes) if (type < -48 || type >= Main.maxItemTypes)
{ {
return true; return true;
} }
@ -3065,7 +3071,7 @@ namespace TShockAPI
if (OnTeleport(id, flag, x, y)) if (OnTeleport(id, flag, x, y))
return true; return true;
var style = 0; byte style = 0;
var isNPC = false; var isNPC = false;
if ((flag & 1) == 1) if ((flag & 1) == 1)
{ {
@ -3089,29 +3095,12 @@ namespace TShockAPI
return true; return true;
} }
if (x > Main.rightWorld - 500)
{
x = Main.rightWorld - 500;
}
if (x < 500)
{
x = 500;
}
if (y > Main.bottomWorld - 500)
{
y = Main.bottomWorld - 500;
}
if (y < 500)
{
y = 500;
}
if (Main.player[id] == null || TShock.Players[id] == null) if (Main.player[id] == null || TShock.Players[id] == null)
{ {
return true; return true;
} }
if (!args.Player.Group.HasPermission(Permissions.tp)) if (!isNPC && !args.Player.Group.HasPermission(Permissions.tp))
{ {
args.Player.SendErrorMessage("You do not have permission to teleport."); args.Player.SendErrorMessage("You do not have permission to teleport.");
Main.player[id].Teleport(new Vector2(Main.player[id].position.X, Main.player[id].position.Y), style); Main.player[id].Teleport(new Vector2(Main.player[id].position.X, Main.player[id].position.Y), style);
@ -3119,8 +3108,10 @@ namespace TShockAPI
return true; return true;
} }
Main.player[id].Teleport(new Vector2(x, y), style); if (!isNPC)
NetMessage.SendData(65, -1, -1, "", 0, (float)id, x, y, style); {
TShock.Players[id].Teleport(x, y, style);
}
} }
return true; return true;

View file

@ -510,10 +510,27 @@ namespace TShockAPI
} }
} }
public bool Teleport(float x, float y) public bool Teleport(float x, float y, byte style = 1)
{ {
TPlayer.Teleport(new Vector2(x, y), 1); if (x > Main.rightWorld - 500)
NetMessage.SendData(65, -1, -1, "", 0, (float)TPlayer.whoAmi, x, y, 1); {
x = Main.rightWorld - 500;
}
if (x < 500)
{
x = 500;
}
if (y > Main.bottomWorld - 500)
{
y = Main.bottomWorld - 500;
}
if (y < 500)
{
y = 500;
}
TPlayer.Teleport(new Vector2(x, y), style);
NetMessage.SendData(65, -1, -1, "", 0, TPlayer.whoAmi, x, y, style);
return true; return true;
} }

View file

@ -371,7 +371,7 @@ namespace TShockAPI
var found = new List<Item>(); var found = new List<Item>();
Item item = new Item(); Item item = new Item();
string nameLower = name.ToLower(); string nameLower = name.ToLower();
for (int i = -24; i < Main.maxItemTypes; i++) for (int i = -48; i < Main.maxItemTypes; i++)
{ {
item.netDefaults(i); item.netDefaults(i);
if (item.name.ToLower() == nameLower) if (item.name.ToLower() == nameLower)