public static void LevelFinalize(RemoteClient client, Proxy proxy, IPacket _packet) { var packet = (LevelFinalizePacket)_packet; client.SendChat(ChatColors.Yellow + "Download complete. Converting world to Anvil."); if (packet.YSize > 256) { client.SendChat(ChatColors.Red + "Warning! Level is taller than maximum 1.6.2 world height."); client.SendChat(ChatColors.Red + "The top of the world will be cut off."); } proxy.FlushClient(client); WorldConverter.PopulateWorld(client.Level.DefaultWorld, client.ClassicLevelData, packet.XSize, packet.YSize, packet.ZSize); client.SendPacket(new Modern.RespawnPacket(Dimension.Overworld, Difficulty.Normal, GameMode.Creative, 256, "FLAT")); for (int x = 0; x < packet.XSize / 16; x++) { for (int z = 0; z < packet.ZSize / 16; z++) { client.SendPacket(ChunkHelper.CreatePacket(client.Level.DefaultWorld.GetChunk( new Coordinates2D(x, z)))); } } client.SendPacket(new Modern.PlayerPositionAndLookPacket( client.Position.X, client.Position.Y + 1.72, client.Position.Z, client.Position.Y + 0.1, 0, 0, false)); client.SendChat(ChatColors.Yellow + "Conversion complete. Welcome to RetroCraft."); }
internal bool ModernWorker(ref int i, RemoteClient client) { bool disconnect = false; if (LastPing.AddSeconds(30) < DateTime.Now && client.ClassicLoggedIn) { client.SendPacket(new KeepAlivePacket(0)); LastPing = DateTime.Now; } while (client.PacketQueue.Count != 0) { IPacket nextPacket; if (client.PacketQueue.TryDequeue(out nextPacket)) { nextPacket.WritePacket(client.NetworkStream); Console.WriteLine("> {0}", nextPacket.GetType().Name); client.NetworkStream.Flush(); if (nextPacket is DisconnectPacket) { disconnect = true; } if (nextPacket is EncryptionKeyResponsePacket) { client.NetworkStream = new MinecraftStream(new BufferedStream(new AesStream(client.NetworkClient.GetStream(), client.SharedKey))); client.EncryptionEnabled = true; } } } if (disconnect) { Clients.RemoveAt(i--); return(false); } // Read packets var timeout = DateTime.Now.AddMilliseconds(10); while (client.NetworkClient.Available != 0 && DateTime.Now < timeout) { try { var packet = PacketReader.ReadPacket(client.NetworkStream); if (packet is DisconnectPacket) { Disconnect(client); Clients.RemoveAt(i--); return(false); } HandlePacket(client, packet); } catch (SocketException) { Disconnect(client); Clients.RemoveAt(i--); return(false); } catch (InvalidOperationException e) { new DisconnectPacket(e.Message).WritePacket(client.NetworkStream); client.NetworkStream.Flush(); Disconnect(client); Clients.RemoveAt(i--); return(false); } catch (Exception e) { new DisconnectPacket(e.Message).WritePacket(client.NetworkStream); client.NetworkStream.Flush(); Disconnect(client); Clients.RemoveAt(i--); return(false); } } return(true); }
internal static void ServerBlockUpdate(RemoteClient client, Proxy proxy, IPacket _packet) { var packet = (ServerSetBlockPacket)_packet; client.SendPacket(new Modern.BlockChangePacket(packet.X, (byte)packet.Y, packet.Z, (short)packet.BlockType, 0)); }