Teleport code has been cleaned up.
Added tp prevention based on permission tp. Updated to latest server exe.
This commit is contained in:
parent
584950bc6f
commit
fddaf657a5
4 changed files with 161 additions and 14 deletions
|
|
@ -1641,16 +1641,49 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
if (args.Parameters.Count < 1)
|
if (args.Parameters.Count < 1)
|
||||||
{
|
{
|
||||||
args.Player.SendErrorMessage("Invalid syntax! Proper syntax: /tp <player> ");
|
args.Player.SendErrorMessage("Invalid syntax! Proper syntax: /tp <player>");
|
||||||
|
args.Player.SendErrorMessage(" /tp <x> <y>");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.Parameters.Count < 2)
|
if(args.Parameters.Count == 2)
|
||||||
|
{
|
||||||
|
float x, 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.SendSuccessMessage("Teleported!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
string plStr = String.Join(" ", args.Parameters);
|
string plStr = String.Join(" ", args.Parameters);
|
||||||
var players = TShock.Utils.FindPlayer(plStr);
|
var players = TShock.Utils.FindPlayer(plStr);
|
||||||
if (players.Count == 0)
|
if (players.Count == 0)
|
||||||
args.Player.SendErrorMessage("Invalid player!");
|
{
|
||||||
|
args.Player.SendErrorMessage("Invalid user name.");
|
||||||
|
args.Player.SendErrorMessage("Proper syntax: /tp <player>");
|
||||||
|
args.Player.SendErrorMessage(" /tp <x> <y>");
|
||||||
|
}
|
||||||
|
|
||||||
else if (players.Count > 1)
|
else if (players.Count > 1)
|
||||||
TShock.Utils.SendMultipleMatchError(args.Player, players.Select(p => p.Name));
|
TShock.Utils.SendMultipleMatchError(args.Player, players.Select(p => p.Name));
|
||||||
else if (!players[0].TPAllow && !args.Player.Group.HasPermission(Permissions.tpall))
|
else if (!players[0].TPAllow && !args.Player.Group.HasPermission(Permissions.tpall))
|
||||||
|
|
@ -1662,7 +1695,7 @@ namespace TShockAPI
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var plr = players[0];
|
var plr = players[0];
|
||||||
if (args.Player.Teleport(plr.TileX*16, plr.TileY*16 + 48))
|
if (args.Player.Teleport(plr.TileX * 16, plr.TileY * 16 + 48))
|
||||||
{
|
{
|
||||||
args.Player.SendSuccessMessage(string.Format("Teleported to {0}.", plr.Name));
|
args.Player.SendSuccessMessage(string.Format("Teleported to {0}.", plr.Name));
|
||||||
if (!args.Player.Group.HasPermission(Permissions.tphide))
|
if (!args.Player.Group.HasPermission(Permissions.tphide))
|
||||||
|
|
@ -1670,13 +1703,8 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
float x = float.Parse(args.Parameters[0]);
|
|
||||||
float y = float.Parse(args.Parameters[1]);
|
|
||||||
args.Player.Teleport(x, y);
|
|
||||||
args.Player.SendSuccessMessage("Teleported!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void TPHere(CommandArgs args)
|
private static void TPHere(CommandArgs args)
|
||||||
|
|
|
||||||
|
|
@ -1130,6 +1130,53 @@ namespace TShockAPI
|
||||||
return args.Handled;
|
return args.Handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// For use with a NPCStrike event
|
||||||
|
/// </summary>
|
||||||
|
public class TeleportEventArgs : HandledEventArgs
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// ???
|
||||||
|
/// </summary>
|
||||||
|
public Int16 ID { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Flag is a bit field
|
||||||
|
/// if the first bit is set -> 0 = player, 1 = NPC
|
||||||
|
/// if the second bit is set, ignore this packet
|
||||||
|
/// if the third bit is set, style +1
|
||||||
|
/// if the fourth bit is set, style +1
|
||||||
|
/// </summary>
|
||||||
|
public byte Flag { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// X Location
|
||||||
|
/// </summary>
|
||||||
|
public float X { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Y Location
|
||||||
|
/// </summary>
|
||||||
|
public float Y { get; set; }
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// NPCStrike - Called when an NPC is attacked
|
||||||
|
/// </summary>
|
||||||
|
public static HandlerList<TeleportEventArgs> Teleport;
|
||||||
|
|
||||||
|
private static bool OnTeleport(Int16 id, byte f, float x, float y)
|
||||||
|
{
|
||||||
|
if (Teleport == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var args = new TeleportEventArgs
|
||||||
|
{
|
||||||
|
ID = id,
|
||||||
|
Flag = f,
|
||||||
|
X = x,
|
||||||
|
Y = y
|
||||||
|
};
|
||||||
|
Teleport.Invoke(null, args);
|
||||||
|
return args.Handled;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
public static void InitGetDataHandler()
|
public static void InitGetDataHandler()
|
||||||
{
|
{
|
||||||
|
|
@ -1174,7 +1221,8 @@ namespace TShockAPI
|
||||||
{PacketTypes.PasswordSend, HandlePassword},
|
{PacketTypes.PasswordSend, HandlePassword},
|
||||||
{PacketTypes.ContinueConnecting2, HandleConnecting},
|
{PacketTypes.ContinueConnecting2, HandleConnecting},
|
||||||
{PacketTypes.ProjectileDestroy, HandleProjectileKill},
|
{PacketTypes.ProjectileDestroy, HandleProjectileKill},
|
||||||
{PacketTypes.SpawnBossorInvasion, HandleSpawnBoss}
|
{PacketTypes.SpawnBossorInvasion, HandleSpawnBoss},
|
||||||
|
{PacketTypes.Teleport, HandleTeleport}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2980,5 +3028,76 @@ namespace TShockAPI
|
||||||
TShock.Utils.SendLogs(string.Format("{0} summoned {1}", args.Player.Name, boss), Color.PaleVioletRed, args.Player);
|
TShock.Utils.SendLogs(string.Format("{0} summoned {1}", args.Player.Name, boss), Color.PaleVioletRed, args.Player);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool HandleTeleport(GetDataHandlerArgs args)
|
||||||
|
{
|
||||||
|
var flag = args.Data.ReadInt8();
|
||||||
|
var id = args.Data.ReadInt16();
|
||||||
|
var x = args.Data.ReadSingle();
|
||||||
|
var y = args.Data.ReadSingle();
|
||||||
|
|
||||||
|
if (OnTeleport(id, flag, x, y))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
var style = 0;
|
||||||
|
var isNPC = false;
|
||||||
|
if ((flag & 1) == 1)
|
||||||
|
{
|
||||||
|
isNPC = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((flag & 2) != 2)
|
||||||
|
{
|
||||||
|
if ((flag & 4) == 4)
|
||||||
|
{
|
||||||
|
style++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((flag & 8) == 8)
|
||||||
|
{
|
||||||
|
style++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (id > (isNPC ? 200 : 255))
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!args.Player.Group.HasPermission(Permissions.tp))
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
NetMessage.SendData(65, -1, -1, "", 0, (float)id, Main.player[id].position.X, Main.player[id].position.Y, style);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Main.player[id].Teleport(new Vector2(x, y), style);
|
||||||
|
NetMessage.SendData(65, -1, -1, "", 0, (float)id, x, y, style);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="TerrariaServer, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
<Reference Include="TerrariaServer, Version=1.14.0.0, Culture=neutral, processorArchitecture=x86">
|
||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<ExecutableExtension>.exe</ExecutableExtension>
|
<ExecutableExtension>.exe</ExecutableExtension>
|
||||||
<HintPath>..\TerrariaServerBins\TerrariaServer.exe</HintPath>
|
<HintPath>..\TerrariaServerBins\TerrariaServer.exe</HintPath>
|
||||||
|
|
@ -183,7 +183,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ProjectExtensions>
|
<ProjectExtensions>
|
||||||
<VisualStudio>
|
<VisualStudio>
|
||||||
<UserProperties BuildVersion_IncrementBeforeBuild="False" BuildVersion_StartDate="2011/6/17" BuildVersion_BuildVersioningStyle="None.None.None.MonthAndDayStamp" BuildVersion_BuildAction="Both" BuildVersion_UpdateFileVersion="True" BuildVersion_UpdateAssemblyVersion="True" />
|
<UserProperties BuildVersion_UpdateAssemblyVersion="True" BuildVersion_UpdateFileVersion="True" BuildVersion_BuildAction="Both" BuildVersion_BuildVersioningStyle="None.None.None.MonthAndDayStamp" BuildVersion_StartDate="2011/6/17" BuildVersion_IncrementBeforeBuild="False" />
|
||||||
</VisualStudio>
|
</VisualStudio>
|
||||||
</ProjectExtensions>
|
</ProjectExtensions>
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue