public static void SyncPortalsOnPlayerJoin(int plr, int fluff, List <Point> dontInclude, out List <Point> portals, out List <Point> portalCenters) { portals = new List <Point>(); portalCenters = new List <Point>(); for (int index = 0; index < 1000; ++index) { Projectile projectile = Main.projectile[index]; if (projectile.active && (projectile.type == 602 || projectile.type == 601)) { Vector2 center = projectile.Center; int sectionX = Netplay.GetSectionX((int)((double)center.X / 16.0)); int sectionY = Netplay.GetSectionY((int)((double)center.Y / 16.0)); for (int x = sectionX - fluff; x < sectionX + fluff + 1; ++x) { for (int y = sectionY - fluff; y < sectionY + fluff + 1; ++y) { if (x >= 0 && x < Main.maxSectionsX && (y >= 0 && y < Main.maxSectionsY) && (!Netplay.Clients[plr].TileSections[x, y] && !dontInclude.Contains(new Point(x, y)))) { portals.Add(new Point(x, y)); if (!portalCenters.Contains(new Point(sectionX, sectionY))) { portalCenters.Add(new Point(sectionX, sectionY)); } } } } } } }
void BRTimer(object obj) { Region region = TShock.Regions.GetRegionByName("BR"); if (MyTiles.Count > 0 && region != null) { for (byte i = 0; i < MyTiles.Count; i++) { Main.tile[MyTiles[i].X, MyTiles[i].Y].ResetToType(MyTiles[i].Type); } MyTiles.Clear(); TSPlayer.All.SendData(PacketTypes.TileSendSection, null, region.Area.X, region.Area.Y, region.Area.Width, region.Area.Height); TSPlayer.All.SendData(PacketTypes.TileFrameSection, null, Netplay.GetSectionX(region.Area.X), Netplay.GetSectionY(region.Area.Y), Netplay.GetSectionX(region.Area.X + region.Area.Width), Netplay.GetSectionY(region.Area.Y + region.Area.Height)); if (config.ping) { Color color = new Color(173, 137, 69); foreach (TSPlayer plr in TShock.Players.Where(p => p != null && p.ConnectionAlive && p.RealPlayer && p.HasPermission("br.ping"))) { NetMessage.SendData(58, plr.Index, -1, null, plr.Index, -0.2410251f); plr.SendData(PacketTypes.CreateCombatTextExtended, "Blocks Regenerated!", (int)color.PackedValue, plr.X, plr.Y); Thread.Sleep(500); NetMessage.SendData(58, plr.Index, -1, null, plr.Index, -0.6057936f); } } } }
public new bool SectionRange(int size, int firstX, int firstY) { for (var i = 0; i < 4; i++) { var x = firstX; var y = firstY; if (i == 1) { x += size; } if (i == 2) { y += size; } if (i == 3) { x += size; y += size; } var sectionX = Netplay.GetSectionX(x); var sectionY = Netplay.GetSectionY(y); if (this.TileSections[sectionX, sectionY]) { return(true); } } return(false); }
/// <summary> /// Requests all tile chunks (200x150 tile 'sections') from the server within a given tile range. /// </summary> /// <param name="tileRange"></param> /// <param name="leftPadding">In chunks.</param> /// <param name="topPadding">In chunks.</param> /// <param name="rightPadding">In chunks.</param> /// <param name="bottomPadding">In chunks.</param> public static void RequestChunksFromServer( Rectangle tileRange, int leftPadding = 0, int topPadding = 0, int rightPadding = 0, int bottomPadding = 0) { int sectX = 200; int sectY = 150; int minX = Math.Max((tileRange.X / sectX) - leftPadding, 0); minX *= sectX; int minY = Math.Max((tileRange.Y / sectY) - topPadding, 0); minY *= sectY; int maxX = tileRange.X + tileRange.Width; maxX += rightPadding * sectX; maxX = Math.Min(maxX, Main.maxTilesX - 1); int maxY = tileRange.Y + tileRange.Height; maxY += bottomPadding * sectY; maxY = Math.Min(maxY, Main.maxTilesY - 1); for (int x = minX; x < maxX; x += sectX) { for (int y = minY; y < maxY; y += sectY) { TileWorldLibraries.RequestChunkFromServer(Netplay.GetSectionX(x), Netplay.GetSectionY(y)); } } }
public bool Remove(object Key, bool Cleanup = true) { lock (Locker) { if (!Data.ContainsKey(Key)) { return(false); } FakeTileRectangle o = Data[Key]; Data.Remove(Key); Order.Remove(Key); int x = o.X, y = o.Y; int w = o.Width, h = o.Height; int sx = Netplay.GetSectionX(x), sy = Netplay.GetSectionY(y); int ex = Netplay.GetSectionX(x + w - 1), ey = Netplay.GetSectionY(y + h - 1); o.Tile.Dispose(); if (Cleanup) { GC.Collect(); } NetMessage.SendData((int)PacketTypes.TileSendSection, -1, -1, null, x, y, w, h); NetMessage.SendData((int)PacketTypes.TileFrameSection, -1, -1, null, sx, sy, ex, ey); return(true); } }
public void ResetSection() { int left = Math.Min(x, x2), right = Math.Max(x, x2); int top = Math.Min(y, y2), bottom = Math.Max(y, y2); int sX = Netplay.GetSectionX(left), sX2 = Netplay.GetSectionX(right); int sY = Netplay.GetSectionY(top), sY2 = Netplay.GetSectionY(bottom); int w = (right - left + 1), h = (bottom - top + 1); bool SendWholeSections = ((w > 200) || (h > 150)); if (SendWholeSections) { foreach (RemoteClient sock in Netplay.Clients.Where(s => s.IsActive)) { for (int i = sX; i <= sX2; i++) { for (int j = sY; j <= sY2; j++) { sock.TileSections[i, j] = false; } } } } else { NetMessage.SendData(10, -1, -1, null, left, top, w, h); NetMessage.SendData(11, -1, -1, null, sX, sY, sX2, sY2); } }
public static void SyncPortalsOnPlayerJoin(int plr, int fluff, List <Point> dontInclude, out List <Point> portals, out List <Point> portalCenters) { portals = new List <Point>(); portalCenters = new List <Point>(); for (int i = 0; i < 1000; i++) { Projectile projectile = Main.projectile[i]; if (!projectile.active || (projectile.type != 602 && projectile.type != 601)) { continue; } Vector2 center = projectile.Center; int sectionX = Netplay.GetSectionX((int)(center.X / 16f)); int sectionY = Netplay.GetSectionY((int)(center.Y / 16f)); for (int j = sectionX - fluff; j < sectionX + fluff + 1; j++) { for (int k = sectionY - fluff; k < sectionY + fluff + 1; k++) { if (j >= 0 && j < Main.maxSectionsX && k >= 0 && k < Main.maxSectionsY && !Netplay.Clients[plr].TileSections[j, k] && !dontInclude.Contains(new Point(j, k))) { portals.Add(new Point(j, k)); if (!portalCenters.Contains(new Point(sectionX, sectionY))) { portalCenters.Add(new Point(sectionX, sectionY)); } } } } } }
public void BackToOriginMap() { try { if (MapUUID != Guid.Empty && Map != null) { Map.Player.Remove(ID); } LeaveMap(Map); MapUUID = Guid.Empty; tsp.SendData(PacketTypes.WorldInfo, "", 0, 0f, 0f, 0f, 0); int sectionX = Netplay.GetSectionX(0); int sectionX2 = Netplay.GetSectionX(Main.maxTilesX); int sectionY = Netplay.GetSectionY(0); int sectionY2 = Netplay.GetSectionY(Main.maxTilesY); for (int i = sectionX; i <= sectionX2; i++) { for (int j = sectionY; j <= sectionY2; j++) { Netplay.Clients[Index].TileSections[i, j] = false; } } tsp.Teleport(SpawnX, SpawnY); UserManager.UpdateInfoToOtherPlayers(this); MapManager.SendProjectile(this); MapManager.SendAllItem(this); } catch (Exception ex) { Log.Error(ex); } }
// World replacement public static void ReplaceTiles(int i, int j, Hooks.TileData data, int style = 0) { WorldGen.PlaceTile(i, j, data.type, true, true, -1, style); if (data.wall != 0) { WorldGen.PlaceWall(i, j, data.wall, true); } OTAPI.Tile.ITile tile = Main.tile[i, j]; tile.type = data.type; if (data.halfBrick) { tile.halfBrick(data.halfBrick); } else { tile.slope(data.slope); } // TODO: sort out slopes after replacing the tiles. This is returning a System.IndexOutOfRangeException. int x = Netplay.GetSectionX(i); int y = Netplay.GetSectionY(j); foreach (RemoteClient sock in Netplay.Clients.Where(t => t.IsActive)) { sock.TileSections[x, y] = false; } }
public static void SyncPortalsOnPlayerJoin(int plr, int fluff, List <Point> dontInclude, out List <Point> portals, out List <Point> portalCenters) { portals = new List <Point>(); portalCenters = new List <Point>(); for (int index1 = 0; index1 < 1000; ++index1) { Projectile projectile = Main.projectile[index1]; if (projectile.active && (projectile.type == 602 || projectile.type == 601)) { Vector2 center = projectile.Center; int sectionX = Netplay.GetSectionX((int)(center.X / 16.0)); int sectionY = Netplay.GetSectionY((int)(center.Y / 16.0)); for (int index2 = sectionX - fluff; index2 < sectionX + fluff + 1; ++index2) { for (int index3 = sectionY - fluff; index3 < sectionY + fluff + 1; ++index3) { if (index2 >= 0 && index2 < Main.maxSectionsX && (index3 >= 0 && index3 < Main.maxSectionsY) && (!Netplay.Clients[plr].TileSections[index2, index3] && !dontInclude.Contains(new Point(index2, index3)))) { portals.Add(new Point(index2, index3)); if (!portalCenters.Contains(new Point(sectionX, sectionY))) { portalCenters.Add(new Point(sectionX, sectionY)); } } } } } } }
public static void SendSection(int whoAmi, int sectionX, int sectionY, bool skipSent = false) { if (sectionX >= 0 && sectionY >= 0 && sectionX < Main.maxSectionsX && sectionY < Main.maxSectionsY) { if (!skipSent || !Terraria.Netplay.Clients[whoAmi].TileSections[sectionX, sectionY]) { Terraria.Netplay.Clients[whoAmi].TileSections[sectionX, sectionY] = true; int number = sectionX * 200; int num = sectionY * 150; int num2 = 150; for (int i = num; i < num + 150; i += num2) { NewNetMessage.SendData(10, whoAmi, -1, "", number, (float)i, 200f, (float)num2, 0); } for (int j = 0; j < 200; j++) { if (Main.npc[j].active && Main.npc[j].townNPC) { int sectionX2 = Netplay.GetSectionX((int)(Main.npc[j].position.X / 16f)); int sectionY2 = Netplay.GetSectionY((int)(Main.npc[j].position.Y / 16f)); if (sectionX2 == sectionX && sectionY2 == sectionY) { NewNetMessage.SendData(23, whoAmi, -1, "", j, 0f, 0f, 0f, 0); } } } } } }
public static void CheckSection(int who, Vector2 position, int fluff = 1) { int sectionX = Netplay.GetSectionX((int)(position.X / 16f)); int sectionY = Netplay.GetSectionY((int)(position.Y / 16f)); int num = 0; for (int i = sectionX - 1; i < sectionX + 2; i++) { for (int j = sectionY - 1; j < sectionY + 2; j++) { if (i >= 0 && i < Main.maxSectionsX && j >= 0 && j < Main.maxSectionsY && !Terraria.Netplay.Clients[who].TileSections[i, j]) { num++; } } } if (num > 0) { int num2 = num; NewNetMessage.SendData(9, who, -1, Lang.inter[44], num2, 0f, 0f, 0f, 0); Terraria.Netplay.Clients[who].StatusText2 = "is receiving tile data"; Terraria.Netplay.Clients[who].StatusMax += num2; for (int k = sectionX - 1; k < sectionX + 2; k++) { for (int l = sectionY - 1; l < sectionY + 2; l++) { if (k >= 0 && k < Main.maxSectionsX && l >= 0 && l < Main.maxSectionsY && !Terraria.Netplay.Clients[who].TileSections[k, l]) { NewNetMessage.SendSection(who, k, l, false); NewNetMessage.SendData(11, who, -1, String.Empty, k, (float)l, (float)k, (float)l, 0); } } } } }
public static void ResendPlayerTileData(HEROsModPlayer player) { int sectionX = Netplay.GetSectionX((int)(player.GameInstance.position.X / 16f)); int sectionY = Netplay.GetSectionY((int)(player.GameInstance.position.Y / 16f)); int num = 0; for (int i = sectionX - 1; i < sectionX + 2; i++) { for (int j = sectionY - 1; j < sectionY + 2; j++) { if (i >= 0 && i < Main.maxSectionsX && j >= 0 && j < Main.maxSectionsY) { num++; } } } int num2 = num; NetMessage.SendData(9, player.Index, -1, Lang.inter[44].ToNetworkText(), num2, 0f, 0f, 0f, 0); Netplay.Clients[player.Index].StatusText2 = "is receiving tile data"; Netplay.Clients[player.Index].StatusMax += num2; for (int k = sectionX - 1; k < sectionX + 2; k++) { for (int l = sectionY - 1; l < sectionY + 2; l++) { if (k >= 0 && k < Main.maxSectionsX && l >= 0 && l < Main.maxSectionsY) { NetMessage.SendSection(player.Index, k, l, false); NetMessage.SendData(11, player.Index, -1, null, k, (float)l, (float)k, (float)l, 0); } } } }
// /// <summary> /// Handles calling and queuing requests to teleport a player to X,Y coords. /// </summary> /// <param name="x">X coord</param> /// <param name="y">Y coord</param> /// <param name="targetId">The target Player ID</param> public static void teleportPlayer(int x, int y, int targetId, bool old = true) { while (x % 2 != 0) { x++; } while (y % 2 != 0) { y++; } if (x > Main.maxTilesX - 2 || y > Main.maxTilesY - 2) { Commands.SendChatMsg("Landmark out of range, or coords off-map.", targetId, Color.Purple); return; } int sectionX = Netplay.GetSectionX(x); int sectionY = Netplay.GetSectionY(y + 1); /* * //does player already have the tilesection available to it? if yes, just teleport without queue * if (Netplay.serverSock[targetId].tileSection[sectionX, sectionY]) * { * TeleportToLocation(targetId, x, y + 1); * return; * }*/ Commands.SendChatMsg("Preparing teleport!", targetId, Color.Bisque); for (int m = sectionX - 1; m < sectionX + 2; m++) { for (int n = sectionY - 1; n < sectionY + 1; n++) { NetMessage.SendSection(targetId, m, n); } } //additional section update details, 11 requests client determines tile frames and walls. NetMessage.SendData(11, targetId, -1, "", sectionX - 2, (float)(sectionY - 1), (float)(sectionX + 2), (float)(sectionY + 1), 0); teleQueue.AddLast(new TP { targetId = targetId, x = x, y = y + 1 }); //if timer hasn't been created, create and initialize if (tTimer == null) { tTimer = new System.Timers.Timer(3000); tTimer.Elapsed += new ElapsedEventHandler(TeleportQueueProcess); tTimer.Enabled = true; } else { //else just enable it tTimer.Enabled = true; } }
public static void UpdateTile(int x, int y) { x = Netplay.GetSectionX(x); y = Netplay.GetSectionY(y); foreach (QPlayer ply in QMain.Players) { Netplay.serverSock[ply.Index].tileSection[x, y] = false; } }
public void Packet69(string text, int number, float number2, float number3, float number4, int number5) { Begin(Packet.CHEST_NAME_UPDATE); Netplay.GetSectionX((int)number2); Netplay.GetSectionY((int)number3); Short((short)number); Short((short)number2); Short((short)number3); String(text); End(); }
private static void DistributeChangesIntoChunks(HashSet <int> dirtiedPackedTileCoords) { foreach (int dirtiedPackedTileCoord in dirtiedPackedTileCoords) { int x = (dirtiedPackedTileCoord >> 16) & 0xFFFF; int y = dirtiedPackedTileCoord & 0xFFFF; Point key = default(Point); key.X = Netplay.GetSectionX(x); key.Y = Netplay.GetSectionY(y); if (!_changesByChunkCoords.TryGetValue(key, out ChunkChanges value)) { value = new ChunkChanges(key.X, key.Y); _changesByChunkCoords[key] = value; } value.DirtiedPackedTileCoords.Add(dirtiedPackedTileCoord); } }
public void KillTile(int number, float number2, float number3, float number4, int number5) { //throw new NotImplementedException("NewNetMessage.KillTile()"); Begin(Packet.KILL_TILE); Byte((byte)number); Short((short)number2); Short((short)number3); Short((short)number4); Netplay.GetSectionX((int)number2); Netplay.GetSectionY((int)number3); Short((short)number5); End(); }
public static void ResetSection(int x, int y, int width, int height) { var lowX = Netplay.GetSectionX(x); var highX = Netplay.GetSectionX(x + width); var lowY = Netplay.GetSectionY(y); var highY = Netplay.GetSectionY(y + height); foreach (var sock in Netplay.Clients.Where(s => s.IsActive)) { for (var i = lowX; i <= highX; i++) { for (var j = lowY; j <= highY; j++) { sock.TileSections[i, j] = false; } } } }
private void ResetSection() { var startx = Netplay.GetSectionX((int)posx); var endx = Netplay.GetSectionX((int)(posx + width)); var starty = Netplay.GetSectionY((int)posy); var endy = Netplay.GetSectionY((int)(posy - 1)); foreach (var sock in Netplay.Clients.Where(s => s.IsActive)) { for (var i = startx; i <= endx; i++) { for (var j = endy; j <= starty; j++) { sock.TileSections[i, j] = false; } } } }
public static void ResetSection(int x1, int y1, int x2, int y2) { int lowX = Netplay.GetSectionX(x1); int highX = Netplay.GetSectionX(x2); int lowY = Netplay.GetSectionY(y1); int highY = Netplay.GetSectionY(y2); foreach (RemoteClient sock in Netplay.Clients.Where(s => s.IsActive)) { for (int i = lowX; i <= highX; i++) { for (int j = lowY; j <= highY; j++) { sock.TileSections[i, j] = false; } } } }
public static void ResetSection(int x, int y, int x2, int y2) { int lowX = Netplay.GetSectionX(x); int highX = Netplay.GetSectionX(x2); int lowY = Netplay.GetSectionY(y); int highY = Netplay.GetSectionY(y2); foreach (ServerSock sock in Netplay.serverSock) { for (int i = lowX; i <= highX; i++) { for (int j = lowY; j <= highY; j++) { sock.tileSection[i, j] = false; } } } }
private static void DistributeChangesIntoChunks(HashSet <int> dirtiedPackedTileCoords) { foreach (int dirtiedPackedTileCoord in dirtiedPackedTileCoords) { int x = dirtiedPackedTileCoord >> 16 & (int)ushort.MaxValue; int y = dirtiedPackedTileCoord & (int)ushort.MaxValue; Point key; key.X = Netplay.GetSectionX(x); key.Y = Netplay.GetSectionY(y); NetLiquidModule.ChunkChanges chunkChanges; if (!NetLiquidModule._changesByChunkCoords.TryGetValue(key, out chunkChanges)) { chunkChanges = new NetLiquidModule.ChunkChanges(key.X, key.Y); NetLiquidModule._changesByChunkCoords[key] = chunkChanges; } chunkChanges.DirtiedPackedTileCoords.Add(dirtiedPackedTileCoord); } }
public static void ResetSection(int x, int y, int x2, int y2) { int lowX = Netplay.GetSectionX(x); int highX = Netplay.GetSectionX(x2); int lowY = Netplay.GetSectionY(y); int highY = Netplay.GetSectionY(y2); foreach (RemoteClient sock in Netplay.Clients.Where(s => s.IsActive)) { int w = sock.TileSections.GetLength(0), h = sock.TileSections.GetLength(1); for (int i = lowX; i <= highX; i++) { for (int j = lowY; j <= highY; j++) { if (i < 0 || j < 0 || i >= w || j >= h) { continue; } sock.TileSections[i, j] = false; } } } }
private static void OnDraw(DrawArgs args) { HashSet <int> players; if (args.PlayerIndex == -1) { players = (args.Node.GetRoot() as RootVisualObject).Players; } else { players = new HashSet <int>() { args.PlayerIndex } }; players.Remove(args.ExceptPlayerIndex); if (players.Count == 0) { return; } // Yes, we are converting HashSet<int> to NetworkText to pass it to NetMessage.SendData for FakeManager... Terraria.Localization.NetworkText playerList = FakesEnabled ? Terraria.Localization.NetworkText.FromLiteral(String.Concat(players.Select(p => (char)p))) : null; int size = Math.Max(args.Width, args.Height); if (size >= 50 || args.ForcedSection) { if (FakesEnabled) { NetMessage.SendData(10, -1, -1, playerList, args.X, args.Y, args.Width, args.Height); } else { foreach (int i in players) { NetMessage.SendData(10, i, -1, null, args.X, args.Y, args.Width, args.Height); } } if (args.Frame) { int lowX = Netplay.GetSectionX(args.X); int highX = Netplay.GetSectionX(args.X + args.Width - 1); int lowY = Netplay.GetSectionY(args.Y); int highY = Netplay.GetSectionY(args.Y + args.Height - 1); if (FakesEnabled) { NetMessage.SendData(11, -1, -1, playerList, lowX, lowY, highX, highY); } else { foreach (int i in players) { NetMessage.SendData(11, i, -1, null, lowX, lowY, highX, highY); } } } } else { if (FakesEnabled) { NetMessage.SendData(20, -1, -1, playerList, size, args.X, args.Y); } else { foreach (int i in players) { NetMessage.SendData(20, i, -1, null, size, args.X, args.Y); } } } }
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); }
public override void Process(int whoAmI, byte[] readBuffer, int length, int num) { int num13 = ReadInt32(readBuffer); int num14 = ReadInt32(readBuffer); bool flag3 = true; if (num13 == -1 || num14 == -1) { flag3 = false; } else { if (num13 < 10 || num13 > Main.maxTilesX - 10) { flag3 = false; } else { if (num14 < 10 || num14 > Main.maxTilesY - 10) { flag3 = false; } } } int num15 = Netplay.GetSectionX(Main.spawnTileX) - 2; int num16 = Netplay.GetSectionY(Main.spawnTileY) - 1; int num17 = num15 + 5; int num18 = num16 + 3; if (num15 < 0) { num15 = 0; } if (num17 >= Main.maxSectionsX) { num17 = Main.maxSectionsX - 1; } if (num16 < 0) { num16 = 0; } if (num18 >= Main.maxSectionsY) { num18 = Main.maxSectionsY - 1; } int num19 = (num17 - num15) * (num18 - num16); int num20 = -1; int num21 = -1; if (flag3) { num13 = Netplay.GetSectionX(num13) - 2; num14 = Netplay.GetSectionY(num14) - 1; num20 = num13 + 5; num21 = num14 + 3; if (num13 < 0) { num13 = 0; } if (num20 >= Main.maxSectionsX) { num20 = Main.maxSectionsX - 1; } if (num14 < 0) { num14 = 0; } if (num21 >= Main.maxSectionsY) { num21 = Main.maxSectionsY - 1; } for (int num22 = num13; num22 < num20; num22++) { for (int num23 = num14; num23 < num21; num23++) { if (num22 < num15 || num22 >= num17 || num23 < num16 || num23 >= num18) { num19++; } } } } ServerSlot serverSock = Terraria.Netplay.Clients[whoAmI] as ServerSlot; if (serverSock.state == SlotState.SENDING_WORLD) { serverSock.state = SlotState.SENDING_TILES; } else { serverSock.Kick("Invalid operation at this state."); } NewNetMessage.SendData(9, whoAmI, -1, Lang.inter[44], num19, 0f, 0f, 0f, 0); Terraria.Netplay.Clients[whoAmI].StatusText2 = "is receiving tile data"; Terraria.Netplay.Clients[whoAmI].StatusMax += num19; for (int num24 = num15; num24 < num17; num24++) { for (int num25 = num16; num25 < num18; num25++) { NewNetMessage.SendSection(whoAmI, num24, num25, false); } } if (flag3) { for (int num26 = num13; num26 < num20; num26++) { for (int num27 = num14; num27 < num21; num27++) { NewNetMessage.SendSection(whoAmI, num26, num27, true); } } NewNetMessage.SendData(11, whoAmI, -1, String.Empty, num13, (float)num14, (float)(num20 - 1), (float)(num21 - 1), 0); } NewNetMessage.SendData(11, whoAmI, -1, String.Empty, num15, (float)num16, (float)(num17 - 1), (float)(num18 - 1), 0); for (int num28 = 0; num28 < 400; num28++) { if (Main.item[num28].active) { NewNetMessage.SendData(21, whoAmI, -1, String.Empty, num28, 0f, 0f, 0f, 0); NewNetMessage.SendData(22, whoAmI, -1, String.Empty, num28, 0f, 0f, 0f, 0); } } for (int num29 = 0; num29 < 200; num29++) { if (Main.npc[num29].active) { System.Diagnostics.Debug.WriteLine("Sending 23"); NewNetMessage.SendData(23, whoAmI, -1, String.Empty, num29, 0f, 0f, 0f, 0); } } for (int num30 = 0; num30 < 1000; num30++) { if (Main.projectile[num30].active && (Main.projPet[Main.projectile[num30].type] || Main.projectile[num30].netImportant)) { NewNetMessage.SendData(27, whoAmI, -1, String.Empty, num30, 0f, 0f, 0f, 0); } } NewNetMessage.SendData(49, whoAmI, -1, String.Empty, 0, 0f, 0f, 0f, 0); NewNetMessage.SendData(57, whoAmI, -1, String.Empty, 0, 0f, 0f, 0f, 0); NewNetMessage.SendData(7, whoAmI, -1, String.Empty, 0, 0f, 0f, 0f, 0); }
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); } }