Exemple #1
0
        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);
        }
Exemple #2
0
        private void ClassicWorker(ref int i, RemoteClient client)
        {
            bool disconnect = false;

            while (client.ClassicQueue.Count != 0)
            {
                ClassicPacket nextPacket;
                if (client.ClassicQueue.TryDequeue(out nextPacket))
                {
                    nextPacket.WritePacket(client.ClassicStream);
                    client.ClassicStream.Flush();
                    if (nextPacket is Craft.Net.Classic.Networking.DisconnectPlayerPacket)
                    {
                        disconnect = true;
                    }
                }
            }
            if (disconnect)
            {
                Clients.RemoveAt(i--);
                return;
            }
            // Read packets
            var timeout = DateTime.Now.AddMilliseconds(10);

            while (client.ClassicClient.Available != 0 && DateTime.Now < timeout)
            {
                try
                {
                    var packet = ClassicReader.ReadPacket(client.ClassicStream);
                    Console.WriteLine("< {0}", packet.GetType().Name);
                    if (packet is Craft.Net.Classic.Networking.DisconnectPlayerPacket)
                    {
                        new DisconnectPacket(((Craft.Net.Classic.Networking.DisconnectPlayerPacket)packet).Reason)
                        .WritePacket(client.NetworkStream);
                        client.NetworkStream.Flush();
                        Disconnect(client);
                        Clients.RemoveAt(i--);
                        return;
                    }
                    HandleClassicPacket(client, packet);
                }
                catch (SocketException)
                {
                    Disconnect(client);
                    Clients.RemoveAt(i--);
                    return;
                }
                catch (InvalidOperationException e)
                {
                    new DisconnectPacket(e.Message).WritePacket(client.NetworkStream);
                    client.NetworkStream.Flush();
                    Clients.RemoveAt(i--);
                    return;
                }
                catch (Exception e)
                {
                    new DisconnectPacket(e.Message).WritePacket(client.NetworkStream);
                    client.NetworkStream.Flush();
                    Disconnect(client);
                    Clients.RemoveAt(i--);
                    return;
                }
            }
        }
Exemple #3
0
        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));
        }