private void SendMap() { try { IsLoading = true; SendPacket(mapSendStartPacket); //Send the pre-fab map start packet Packet pa = new Packet(); //Create a packet to handle the data for the map pa.Add(Level.TotalBlocks); //Add the total amount of blocks to the packet byte[] blocks = new byte[Level.TotalBlocks]; //Temporary byte array so we dont have to keep modding the packet array byte block; //A block byte outside the loop, we save cycles by not making this for every loop iteration Level.ForEachBlock(pos => { //Here we loop through the whole map and check/convert the blocks as necesary //We then add them to our blocks array so we can send them to the player block = Level.Data[pos]; //TODO ADD CHECKING blocks[pos] = block; }); pa.Add(blocks); //add the blocks to the packet pa.GZip(); //GZip the packet int number = (int)Math.Ceiling(((double)(pa.bytes.Length)) / 1024); //The magic number for this packet for (int i = 1; pa.bytes.Length > 0; ++i) { short length = (short)Math.Min(pa.bytes.Length, 1024); byte[] send = new byte[1027]; Packet.HTNO(length).CopyTo(send, 0); Buffer.BlockCopy(pa.bytes, 0, send, 2, length); byte[] tempbuffer = new byte[pa.bytes.Length - length]; Buffer.BlockCopy(pa.bytes, length, tempbuffer, 0, pa.bytes.Length - length); pa.bytes = tempbuffer; send[1026] = (byte)(i * 100 / number); Packet Send = new Packet(send); Send.AddStart(new byte[1] { (byte)Packet.Types.MapData }); SendPacket(Send); } pa = new Packet(); pa.Add(Packet.Types.MapEnd); pa.Add((short)Level.Size.x); pa.Add((short)Level.Size.y); pa.Add((short)Level.Size.z); SendPacket(pa); IsLoading = false; } catch (Exception e) { Logger.LogError(e); } }