void SendMap() { // write MapBegin //Logger.Log( "Send: MapBegin()" ); writer.Write(OpCode.MapBegin); // grab a compressed copy of the map byte[] blockData; Map map = Server.Map; using (MemoryStream mapStream = new MemoryStream()) { using (GZipStream compressor = new GZipStream(mapStream, CompressionMode.Compress)) { int convertedBlockCount = IPAddress.HostToNetworkOrder(map.Volume); compressor.Write(BitConverter.GetBytes(convertedBlockCount), 0, 4); byte[] rawData = (UsesCustomBlocks ? map.Blocks : map.GetFallbackMap()); compressor.Write(rawData, 0, rawData.Length); } blockData = mapStream.ToArray(); } // Transfer the map copy byte[] buffer = new byte[1024]; int mapBytesSent = 0; while (mapBytesSent < blockData.Length) { int chunkSize = blockData.Length - mapBytesSent; if (chunkSize > 1024) { chunkSize = 1024; } else { // CRC fix for ManicDigger for (int i = 0; i < buffer.Length; i++) { buffer[i] = 0; } } Buffer.BlockCopy(blockData, mapBytesSent, buffer, 0, chunkSize); byte progress = (byte)(100 * mapBytesSent / blockData.Length); // write in chunks of 1024 bytes or less //Logger.Log( "Send: MapChunk({0},{1})", chunkSize, progress ); writer.Write(OpCode.MapChunk); writer.Write((short)chunkSize); writer.Write(buffer, 0, 1024); writer.Write(progress); mapBytesSent += chunkSize; } // write MapEnd writer.Write(OpCode.MapEnd); writer.Write((short)map.Width); writer.Write((short)map.Height); writer.Write((short)map.Length); // write spawn point writer.Write(Packet.MakeAddEntity(255, Name, map.Spawn).Bytes); writer.Write(Packet.MakeTeleport(255, map.Spawn).Bytes); lastValidPosition = map.Spawn; }