private void PoundTrack(Point spot) { if (Main.tile[spot.X, spot.Y].type == 314 && Minecart.FrameTrack(spot.X, spot.Y, pound: true) && Main.netMode == 1) { NetMessage.SendData(17, -1, -1, null, 15, spot.X, spot.Y, 1f); } }
private void PoundTrack(Point spot) { if (Main.tile[spot.X, spot.Y].type != (ushort)314 || !Minecart.FrameTrack(spot.X, spot.Y, true, false) || Main.netMode != 1) { return; } NetMessage.SendData(17, -1, -1, (NetworkText)null, 15, (float)spot.X, (float)spot.Y, 1f, 0, 0, 0); }
public override void Process(int whoAmI, byte[] readBuffer, int length, int num) { byte action = ReadByte(readBuffer); int x = (int)ReadInt16(readBuffer); int y = (int)ReadInt16(readBuffer); short type = ReadInt16(readBuffer); int style = (int)ReadByte(readBuffer); bool fail = type == 1; var player = Main.player[whoAmI]; if (x < 0 || y < 0 || x >= Main.maxTilesX || y >= Main.maxTilesY) { player.Kick("Out of range tile received from client."); return; } if (!Terraria.Netplay.Clients[whoAmI].TileSections[Netplay.GetSectionX(x), Netplay.GetSectionY(y)]) { Tools.WriteLine("{0} @ {1}: {2} attempted to alter world in unloaded tile."); return; } //TODO implement the old methods var ctx = new HookContext { Connection = (Terraria.Netplay.Clients[whoAmI] as ServerSlot).conn, Sender = player, Player = player, }; var args = new HookArgs.PlayerWorldAlteration { X = x, Y = y, Action = action, Type = type, Style = style }; HookPoints.PlayerWorldAlteration.Invoke(ref ctx, ref args); if (ctx.CheckForKick()) { return; } if (ctx.Result == HookResult.IGNORE) { return; } if (ctx.Result == HookResult.RECTIFY) { //Terraria.WorldGen.SquareTileFrame (x, y, true); NewNetMessage.SendTileSquare(whoAmI, x, y, 1); return; } if (Main.tile[x, y] == null) { Main.tile[x, y] = new Tile(); } if (Main.netMode == 2) { if (!fail) { if (action == 0 || action == 2 || action == 4) { Terraria.Netplay.Clients[whoAmI].SpamDeleteBlock += 1f; } if (action == 1 || action == 3) { Terraria.Netplay.Clients[whoAmI].SpamAddBlock += 1f; } } if (!Terraria.Netplay.Clients[whoAmI].TileSections[Netplay.GetSectionX(x), Netplay.GetSectionY(y)]) { fail = true; } } if (action == 0) { WorldGen.KillTile(x, y, fail, false, false); } if (action == 1) { WorldGen.PlaceTile(x, y, (int)type, false, true, -1, style); } if (action == 2) { WorldGen.KillWall(x, y, fail); } if (action == 3) { WorldGen.PlaceWall(x, y, (int)type, false); } if (action == 4) { WorldGen.KillTile(x, y, fail, false, true); } if (action == 5) { WorldGen.PlaceWire(x, y); } if (action == 6) { WorldGen.KillWire(x, y); } if (action == 7) { WorldGen.PoundTile(x, y); } if (action == 8) { WorldGen.PlaceActuator(x, y); } if (action == 9) { WorldGen.KillActuator(x, y); } if (action == 10) { WorldGen.PlaceWire2(x, y); } if (action == 11) { WorldGen.KillWire2(x, y); } if (action == 12) { WorldGen.PlaceWire3(x, y); } if (action == 13) { WorldGen.KillWire3(x, y); } if (action == 14) { WorldGen.SlopeTile(x, y, (int)type); } if (action == 15) { Minecart.FrameTrack(x, y, true, false); } if (Main.netMode != 2) { return; } NewNetMessage.SendData(17, -1, whoAmI, String.Empty, (int)action, (float)x, (float)y, (float)type, style); if (action == 1 && type == 53) { NewNetMessage.SendTileSquare(-1, x, y, 1); return; } }
public bool Read(int bufferId, int start, int length) { var buffer = NetMessage.buffer[bufferId]; ActionType action = (ActionType)buffer.reader.ReadByte(); int x = (int)buffer.reader.ReadInt16(); int y = (int)buffer.reader.ReadInt16(); short type = buffer.reader.ReadInt16(); int style = (int)buffer.reader.ReadByte(); bool fail = type == 1; if (!WorldGen.InWorld(x, y, 3)) { return(true); } var player = Main.player[bufferId]; //TODO implement the old methods var ctx = new HookContext { Connection = player.Connection.Socket, Sender = player, Player = player, }; var args = new TDSMHookArgs.PlayerWorldAlteration { X = x, Y = y, Action = action, Type = type, Style = style }; TDSMHookPoints.PlayerWorldAlteration.Invoke(ref ctx, ref args); if (ctx.CheckForKick()) { return(true); } if (ctx.Result == HookResult.IGNORE) { return(true); } if (ctx.Result == HookResult.RECTIFY) { //Terraria.WorldGen.SquareTileFrame (x, y, true); NetMessage.SendTileSquare(bufferId, x, y, 1); return(true); } if (Main.tile[x, y] == null) { Main.tile[x, y] = new OTA.Memory.MemTile(); } if (Main.netMode == 2) { if (!fail) { if (action == ActionType.KillTile || action == ActionType.KillWall || action == ActionType.KillTile1) { Netplay.Clients[bufferId].SpamDeleteBlock += 1; } if (action == ActionType.PlaceTile || action == ActionType.PlaceWall) { Netplay.Clients[bufferId].SpamAddBlock += 1; } } if (!Netplay.Clients[bufferId].TileSections[Netplay.GetSectionX(x), Netplay.GetSectionY(y)]) { fail = true; } } switch (action) { case ActionType.KillTile: WorldGen.KillTile(x, y, fail, false, false); break; case ActionType.PlaceTile: WorldGen.PlaceTile(x, y, (int)type, false, true, -1, style); break; case ActionType.KillWall: WorldGen.KillWall(x, y, fail); break; case ActionType.PlaceWall: WorldGen.PlaceWall(x, y, (int)type, false); break; case ActionType.KillTile1: WorldGen.KillTile(x, y, fail, false, true); break; case ActionType.PlaceWire: WorldGen.PlaceWall(x, y, (int)type, false); break; case ActionType.KillWire: WorldGen.KillWire(x, y); break; case ActionType.PoundTile: WorldGen.PoundTile(x, y); break; case ActionType.PlaceActuator: WorldGen.PlaceActuator(x, y); break; case ActionType.KillActuator: WorldGen.KillActuator(x, y); break; case ActionType.PlaceWire2: WorldGen.PlaceWire2(x, y); break; case ActionType.KillWire2: WorldGen.KillWire2(x, y); break; case ActionType.PlaceWire3: WorldGen.PlaceWire3(x, y); break; case ActionType.KillWire3: WorldGen.KillWire3(x, y); break; case ActionType.SlopeTile: WorldGen.SlopeTile(x, y, (int)type); break; case ActionType.FrameTrack: Minecart.FrameTrack(x, y, true, false); break; case ActionType.PlaceWire4: WorldGen.PlaceWire4(x, y); break; case ActionType.KillWire4: WorldGen.KillWire4(x, y); break; case ActionType.PlaceLogicGate: Wiring.SetCurrentUser(bufferId); Wiring.PokeLogicGate(x, y); Wiring.SetCurrentUser(-1); return(true); case ActionType.Actuate: Wiring.SetCurrentUser(bufferId); Wiring.Actuate(x, y); Wiring.SetCurrentUser(-1); return(true); } if (Main.netMode != 2) { return(true); } NetMessage.SendData(17, -1, bufferId, "", (int)action, (float)x, (float)y, (float)type, style, 0, 0); if (action == ActionType.PlaceTile && type == 53) { NetMessage.SendTileSquare(-1, x, y, 1); } return(true); }
private static void ProcessTileBreak(int bufferId) { var buffer = NetMessage.buffer[bufferId]; byte action = buffer.reader.ReadByte(); int x = (int)buffer.reader.ReadInt16(); int y = (int)buffer.reader.ReadInt16(); short type = buffer.reader.ReadInt16(); int style = (int)buffer.reader.ReadByte(); bool fail = type == 1; if (!WorldGen.InWorld(x, y, 3)) { return; } var player = Main.player[bufferId]; //TODO implement the old methods var ctx = new HookContext { Connection = player.Connection, Sender = player, Player = player, }; var args = new HookArgs.PlayerWorldAlteration { X = x, Y = y, Action = action, Type = type, Style = style }; HookPoints.PlayerWorldAlteration.Invoke(ref ctx, ref args); if (ctx.CheckForKick()) { return; } if (ctx.Result == HookResult.IGNORE) { return; } if (ctx.Result == HookResult.RECTIFY) { //Terraria.WorldGen.SquareTileFrame (x, y, true); NetMessage.SendTileSquare(bufferId, x, y, 1); return; } if (Main.tile[x, y] == null) { Main.tile[x, y] = new Tile(); } if (Main.netMode == 2) { if (!fail) { if (action == 0 || action == 2 || action == 4) { Netplay.Clients[bufferId].SpamDeleteBlock += 1; } if (action == 1 || action == 3) { Netplay.Clients[bufferId].SpamAddBlock += 1; } } if (!Netplay.Clients[bufferId].TileSections[Netplay.GetSectionX(x), Netplay.GetSectionY(y)]) { fail = true; } } if (action == 0) { WorldGen.KillTile(x, y, fail, false, false); } if (action == 1) { WorldGen.PlaceTile(x, y, (int)type, false, true, -1, style); } if (action == 2) { WorldGen.KillWall(x, y, fail); } if (action == 3) { WorldGen.PlaceWall(x, y, (int)type, false); } if (action == 4) { WorldGen.KillTile(x, y, fail, false, true); } if (action == 5) { WorldGen.PlaceWire(x, y); } if (action == 6) { WorldGen.KillWire(x, y); } if (action == 7) { WorldGen.PoundTile(x, y); } if (action == 8) { WorldGen.PlaceActuator(x, y); } if (action == 9) { WorldGen.KillActuator(x, y); } if (action == 10) { WorldGen.PlaceWire2(x, y); } if (action == 11) { WorldGen.KillWire2(x, y); } if (action == 12) { WorldGen.PlaceWire3(x, y); } if (action == 13) { WorldGen.KillWire3(x, y); } if (action == 14) { WorldGen.SlopeTile(x, y, (int)type); } if (action == 15) { Minecart.FrameTrack(x, y, true, false); } if (Main.netMode != 2) { return; } NetMessage.SendData(17, -1, bufferId, "", (int)action, (float)x, (float)y, (float)type, style, 0, 0); if (action == 1 && type == 53) { NetMessage.SendTileSquare(-1, x, y, 1); } }