public override void Encode(MinecraftStream stream) { stream.WriteVarInt(SharedSecret.Length); stream.Write(SharedSecret); stream.WriteVarInt(VerifyToken.Length); stream.Write(VerifyToken); }
public State WriteTo(MinecraftStream stream, State state) { stream.Write(WindowID); stream.Write(NumberOfSlots); stream.Write(EntityID); return(state); }
public override void Encode(MinecraftStream stream) { stream.WriteString(ServerId); stream.WriteVarInt(PublicKey.Length); stream.Write(PublicKey); stream.WriteVarInt(VerifyToken.Length); stream.Write(VerifyToken); }
public void SendPacket(Packet packet) { if (packet.PacketId == -1) { throw new Exception(); } byte[] encodedPacket; using (MemoryStream ms = new MemoryStream()) { using (MinecraftStream mc = new MinecraftStream(ms)) { mc.WriteVarInt(packet.PacketId); packet.Encode(mc); encodedPacket = ms.ToArray(); mc.Position = 0; mc.SetLength(0); if (CompressionEnabled) { if (encodedPacket.Length >= CompressionThreshold) { byte[] compressed; CompressData(encodedPacket, out compressed); mc.WriteVarInt(encodedPacket.Length); mc.Write(compressed); } else //Uncompressed { mc.WriteVarInt(0); mc.Write(encodedPacket); } encodedPacket = ms.ToArray(); } } } PacketWriteQueue.Add(encodedPacket); /*using (MemoryStream ms = new MemoryStream()) * { * using (MinecraftStream mc = new MinecraftStream(ms)) * { * if (EncryptionInitiated) * { * mc.InitEncryption(SharedSecret); * } * * mc.WriteVarInt(encodedPacket.Length); * mc.Write(encodedPacket); * } * SendDataInternal(ms.ToArray()); * }*/ }
public void WriteTo(MinecraftStream stream) { if (Cache != null) { stream.Write(Cache); return; } byte[] sectionData; int sectionBitmask = 0; using (MemoryStream ms = new MemoryStream()) { using (MinecraftStream mc = new MinecraftStream(ms)) { for (int i = 0; i < Sections.Length; i++) { ChunkSection section = Sections[i]; if (section.IsAllAir) { continue; } sectionBitmask |= 1 << i; section.WriteTo(mc, true); } } sectionData = ms.ToArray(); } using (MemoryStream ms = new MemoryStream()) { using (MinecraftStream mc = new MinecraftStream(ms)) { mc.WriteInt(Coordinates.X); mc.WriteInt(Coordinates.Z); mc.WriteBool(true); mc.WriteVarInt(sectionBitmask); //Primary Bitmask mc.WriteVarInt(sectionData.Length + 256); mc.Write(sectionData, 0, sectionData.Length); mc.Write(Biomes); mc.WriteVarInt(0); //No block entities for now } Cache = ms.ToArray(); } stream.Write(Cache); }
public State WriteTo(MinecraftStream stream, State state) { stream.Write(X); stream.Write(Y); stream.Write(Z); stream.Write(Yaw); stream.Write(Pitch); stream.WriteByte(Flags); stream.WriteVarInt(TeleportId); return(state); }
private void SendQueue() { using (NetworkStream ms = new NetworkStream(Socket)) { using (MinecraftStream mc = new MinecraftStream(ms)) { _sendStream = mc; while (!CancellationToken.IsCancellationRequested) { try { EnqueuedPacket packet = PacketWriteQueue.Take(CancellationToken.Token); var data = EncodePacket(packet); mc.WriteVarInt(data.Length); mc.Write(data); } catch (EndOfStreamException) { } catch (OperationCanceledException) { break; } } } } }
private void SendQueue() { using NetworkStream ms = new NetworkStream(Socket); using MinecraftStream mc = new MinecraftStream(ms); _sendStream = mc; while (!CancellationToken.IsCancellationRequested) { try { if (PacketWriteQueue.TryTake(out var packet, 3500)) { // Log.Info($"Sent: {packet.Packet}"); var data = EncodePacket(packet); Interlocked.Increment(ref PacketsOut); Interlocked.Add(ref PacketSizeOut, data.Length); mc.WriteVarInt(data.Length); mc.Write(data); } else { // Log.Warn($"No data sent in the last 3.5 seconds... :/"); } // EnqueuedPacket packet = PacketWriteQueue.Take(CancellationToken.Token); } catch (EndOfStreamException) { } catch (OperationCanceledException) { break; } } }
public void WriteTo(MinecraftStream stream, bool writeSkylight = true) { long[] types = Types.Backing; stream.WriteByte(13); //Bits Per Block stream.WriteVarInt(0); //Palette Length stream.WriteVarInt(types.Length); for (int i = 0; i < types.Length; i++) { stream.WriteLong(types[i]); } stream.Write(BlockLight.Data); if (writeSkylight) { stream.Write(SkyLight.Data); } }
private byte[] EncodePacket(EnqueuedPacket enqueued) { var packet = enqueued.Packet; byte[] encodedPacket; using (MemoryStream ms = new MemoryStream()) { using (MinecraftStream mc = new MinecraftStream(ms)) { mc.WriteVarInt(packet.PacketId); packet.Encode(mc); encodedPacket = ms.ToArray(); mc.Position = 0; mc.SetLength(0); if (enqueued.CompressionEnabled) { if (encodedPacket.Length >= CompressionThreshold) { byte[] compressed; CompressData(encodedPacket, out compressed); mc.WriteVarInt(encodedPacket.Length); mc.Write(compressed); } else //Uncompressed { mc.WriteVarInt(0); mc.Write(encodedPacket); } encodedPacket = ms.ToArray(); } } } return(encodedPacket); }
public override void Encode(MinecraftStream stream) { stream.WriteInt(ChunkX); stream.WriteInt(ChunkZ); stream.WriteBool(GroundUp); stream.WriteVarInt(PrimaryBitmask); stream.WriteVarInt(Buffer.Length); stream.Write(Buffer, 0, Buffer.Length); stream.WriteVarInt(TileEntities.Count); foreach (var tileEntity in TileEntities) { stream.WriteNbtCompound(tileEntity); } }
public State WriteTo(MinecraftStream stream, State state) { stream.Write(EntityId); stream.Write(Gamemode); stream.Write(Dimension); stream.Write(HashedSeed); stream.Write(MaxPlayers); stream.WriteString(LevelType); stream.WriteVarInt(ViewDistance); stream.Write(ReducedDebugInfo); stream.Write(EnableRespawnScreen); return(state); }
public MinecraftPacket(MinecraftClient client, Stream stream) { Client = client; Data = new MinecraftStream((RecyclableMemoryStream)RMSManager.Get().GetStream(GetType().FullName)); Length = Client.CompressionEnabled ? (int)stream.Length : new VarInt(stream).Value; long _pos = stream.Position; Id = new VarInt(stream).Value; byte[] data = new byte[Length - (stream.Position - _pos)]; stream.Read(data, 0, data.Length); Data.Write(data); Data.Seek(0, SeekOrigin.Begin); }
private byte[] EncodePacket(EnqueuedPacket enqueued) { var packet = enqueued.Packet; byte[] encodedPacket; using (MemoryStream ms = new MemoryStream()) { using (MinecraftStream mc = new MinecraftStream(ms)) { mc.WriteVarInt(packet.PacketId); packet.Encode(mc); encodedPacket = ms.ToArray(); mc.Position = 0; mc.SetLength(0); if (enqueued.CompressionEnabled) { if (encodedPacket.Length >= CompressionThreshold) { //byte[] compressed; //CompressData(encodedPacket, out compressed); mc.WriteVarInt(encodedPacket.Length); using (ZlibStream outZStream = new ZlibStream(mc, CompressionMode.Compress, CompressionLevel.Default, true)) { outZStream.Write(encodedPacket, 0, encodedPacket.Length); } // mc.Write(compressed); } else //Uncompressed { mc.WriteVarInt(0); mc.Write(encodedPacket); } encodedPacket = ms.ToArray(); } } } return(encodedPacket); }
public override void Write(MinecraftStream stream) { base.Write(stream); stream.WriteString(Name); stream.WriteVarInt(Properties.Count); foreach (var properties in Properties) { stream.Write(properties.ToArray()); } stream.WriteVarInt(Gamemode); stream.WriteVarInt(Ping); stream.WriteBoolean(HasDisplayName); if (HasDisplayName) { stream.WriteChat(DisplayName); } }
public override void Encode(MinecraftStream stream) { stream.WriteString(Channel); stream.WriteVarInt(Data.Length); stream.Write(Data, 0, Data.Length); }
public override void Encode(MinecraftStream stream) { stream.Write(Data); }
public State WriteTo(MinecraftStream stream, State state) { stream.Write(Reason); stream.Write(Value); return(state); }
public State WriteTo(MinecraftStream stream, State state) { stream.Write(Threshold); return(state); }
public State WriteTo(MinecraftStream stream, State state) { stream.Write(KeepAliveID); return(state); }
public readonly State WriteTo(MinecraftStream stream, State state) { stream.Write(Time); return(state); }
public override void Encode(MinecraftStream stream) { stream.WriteVarInt(MessageId); stream.WriteString(Channel); stream.Write(Data); }
public override void Encode(MinecraftStream stream) { stream.WriteVarInt(MessageId); stream.WriteBool(Succesful); stream.Write(Data); }
public State WriteTo(MinecraftStream stream, State state) { stream.Write(X); stream.Write(Z); return(state); }
public State WriteTo(MinecraftStream stream, State state) { stream.Write(Position); return(state); }