diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index e494c421..3bb6400c 100755 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -1248,7 +1248,8 @@ namespace TShockAPI { PacketTypes.PaintWall, HandlePaintWall }, { PacketTypes.DoorUse, HandleDoorUse }, { PacketTypes.CompleteAnglerQuest, HandleCompleteAnglerQuest }, - { PacketTypes.NumberOfAnglerQuestsCompleted, HandleNumberOfAnglerQuestsCompleted } + { PacketTypes.NumberOfAnglerQuestsCompleted, HandleNumberOfAnglerQuestsCompleted }, + { PacketTypes.MassWireOperation, HandleMassWireOperation } }; } @@ -2364,15 +2365,15 @@ namespace TShockAPI return false; } - private static bool HandlePlayerTeam(GetDataHandlerArgs args) - { - byte id = args.Data.ReadInt8(); - byte team = args.Data.ReadInt8(); - if (OnPlayerTeam(id, team)) - return true; + private static bool HandlePlayerTeam(GetDataHandlerArgs args) + { + byte id = args.Data.ReadInt8(); + byte team = args.Data.ReadInt8(); + if (OnPlayerTeam(id, team)) + return true; - if (id != args.Player.Index) - return true; + if (id != args.Player.Index) + return true; if ((DateTime.UtcNow - args.Player.LastPvPTeamChange).TotalSeconds < 5) { @@ -2381,8 +2382,8 @@ namespace TShockAPI } args.Player.LastPvPTeamChange = DateTime.UtcNow; - return false; - } + return false; + } private static bool HandlePlayerUpdate(GetDataHandlerArgs args) { @@ -3838,5 +3839,42 @@ namespace TShockAPI // Never sent by vanilla client, ignore this return true; } + + private static bool HandleMassWireOperation(GetDataHandlerArgs args) + { + short startX = args.Data.ReadInt16(); + short startY = args.Data.ReadInt16(); + short endX = args.Data.ReadInt16(); + short endY = args.Data.ReadInt16(); + args.Data.ReadByte(); // Ignore toolmode + + List points = Utils.Instance.GetMassWireOperationRange( + new Point(startX, startY), + new Point(endX, endY), + args.Player.TPlayer.direction == 1); + + int x; + int y; + foreach (Point p in points) + { + /* Perform similar checks to TileKill + * The server-side nature of this packet removes the need to use SendTileSquare + * Range checks are currently ignored here as the items that send this seem to have infinite range */ + + x = p.X; + y = p.Y; + + if (!TShock.Utils.TilePlacementValid(x, y) || (args.Player.Dead && TShock.Config.PreventDeadModification)) + return true; + + if (TShock.CheckIgnores(args.Player)) + return true; + + if (TShock.CheckTilePermission(args.Player, x, y)) + return true; + } + + return false; + } } } diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index ff91b74f..b26e22ae 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -1086,5 +1086,91 @@ namespace TShockAPI string options = stack > 1 ? "/s" + stack : prefix != 0 ? "/p" + prefix : ""; return String.Format("[i{0}:{1}]", options, netID); } + + /// + /// Gets a list of points selected by a mass-wiring tool. + /// + /// The starting point for the selection. + /// The ending point for the selection. + /// False if facing left, True if facing right. + /// + /// A list of coordinates containing the and + /// points and a list of points between them, forming an L shape based on . + /// + public List GetMassWireOperationRange(Point start, Point end, bool direction = false) + { + List points = new List(); + + #region Tile Selection Logic stolen from Wiring.cs + + // Slightly modified version of Wiring.MassWireOperationInner, ignores a player's wire count + int num = Math.Sign(end.X - start.X); + int num2 = Math.Sign(end.Y - start.Y); + Point pt = new Point(); + int num3; + int num4; + int num5; + if (direction) + { + pt.X = start.X; + num3 = start.Y; + num4 = end.Y; + num5 = num2; + } + else + { + pt.Y = start.Y; + num3 = start.X; + num4 = end.X; + num5 = num; + } + int num6 = num3; + while (num6 != num4) + { + if (direction) + { + pt.Y = num6; + } + else + { + pt.X = num6; + } + points.Add(pt); + num6 += num5; + } + if (direction) + { + pt.Y = end.Y; + num3 = start.X; + num4 = end.X; + num5 = num; + } + else + { + pt.X = end.X; + num3 = start.Y; + num4 = end.Y; + num5 = num2; + } + int num7 = num3; + while (num7 != num4) + { + if (!direction) + { + pt.Y = num7; + } + else + { + pt.X = num7; + } + points.Add(pt); + num7 += num5; + } + points.Add(end); + + #endregion + + return points; + } } }