<commit_before>package net.md_5.bungee;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import javax.crypto.SecretKey;
import net.md_5.bungee.packet.Packet2Handshake;
import net.md_5.bungee.packet.PacketFCEncryptionResponse;
import net.md_5.bungee.packet.PacketFDEncryptionRequest;
import net.md_5.bungee.packet.PacketFFKick;
import net.md_5.bungee.packet.PacketInputStream;
import net.md_5.bungee.plugin.LoginEvent;
import org.bouncycastle.crypto.io.CipherInputStream;
import org.bouncycastle.crypto.io.CipherOutputStream;

public class InitialHandler implements Runnable
{

    private final Socket socket;
    private PacketInputStream in;
    private OutputStream out;

    public InitialHandler(Socket socket) throws IOException
    {
        this.socket = socket;
        in = new PacketInputStream(socket.getInputStream());
        out = socket.getOutputStream();
    }

    @Override
    public void run()
    {
        try
        {
            byte[] packet = in.readPacket();
            int id = Util.getId(packet);
            switch (id)
            {
                case 0x02:
                    Packet2Handshake handshake = new Packet2Handshake(packet);
                    // fire connect event
                    LoginEvent event = new LoginEvent(handshake.username, socket.getInetAddress());
                    BungeeCord.instance.pluginManager.onHandshake(event);
                    if (event.isCancelled())
                    {
                        throw new KickException(event.getCancelReason());
                    }

                    PacketFDEncryptionRequest request = EncryptionUtil.encryptRequest();
                    out.write(request.getPacket());
                    PacketFCEncryptionResponse response = new PacketFCEncryptionResponse(in.readPacket());

                    SecretKey shared = EncryptionUtil.getSecret(response, request);
                    if (!EncryptionUtil.isAuthenticated(handshake.username, request.serverId, shared))
                    {
                        throw new KickException("Not authenticated with minecraft.net");
                    }

                    // fire post auth event
                    BungeeCord.instance.pluginManager.onHandshake(event);
                    if (event.isCancelled())
                    {
                        throw new KickException(event.getCancelReason());
                    }

                    out.write(new PacketFCEncryptionResponse().getPacket());
                    in = new PacketInputStream(new CipherInputStream(socket.getInputStream(), EncryptionUtil.getCipher(false, shared)));
                    out = new CipherOutputStream(socket.getOutputStream(), EncryptionUtil.getCipher(true, shared));

                    int ciphId = Util.getId(in.readPacket());
                    if (ciphId != 0xCD)
                    {
                        throw new KickException("Unable to receive encrypted client status");
                    }

                    UserConnection userCon = new UserConnection(socket, in, out, handshake);
                    userCon.connect(BungeeCord.instance.config.getServer(handshake.username, handshake.host));
                    break;
                case 0xFE:
                    Configuration conf = BungeeCord.instance.config;
                    throw new KickException(ChatColor.COLOR_CHAR + "1"
                            + "\00" + conf.protcolVersion
                            + "\00" + conf.gameVersion
                            + "\00" + conf.motd
                            + "\00" + BungeeCord.instance.connections.size()
                            + "\00" + conf.maxPlayers);
                default:
                    throw new IllegalArgumentException("Wasn't ready for packet id " + Util.hex(id));
            }
        } catch (KickException ex)
        {
            kick(ex.getMessage());
        } catch (Exception ex)
        {
            kick("[Proxy Error] " + Util.exception(ex));
        }
    }

    private void kick(String message)
    {
        try
        {
            out.write(new PacketFFKick(message).getPacket());
        } catch (IOException ioe)
        {
        } finally
        {
            try
            {
                out.flush();
                socket.close();
            } catch (IOException ioe2)
            {
            }
        }
    }
}<commit_msg>Support 1.3 pings.<commit_after>package net.md_5.bungee;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import javax.crypto.SecretKey;
import net.md_5.bungee.packet.Packet2Handshake;
import net.md_5.bungee.packet.PacketFCEncryptionResponse;
import net.md_5.bungee.packet.PacketFDEncryptionRequest;
import net.md_5.bungee.packet.PacketFFKick;
import net.md_5.bungee.packet.PacketInputStream;
import net.md_5.bungee.plugin.LoginEvent;
import org.bouncycastle.crypto.io.CipherInputStream;
import org.bouncycastle.crypto.io.CipherOutputStream;

public class InitialHandler implements Runnable
{

    private final Socket socket;
    private PacketInputStream in;
    private OutputStream out;

    public InitialHandler(Socket socket) throws IOException
    {
        this.socket = socket;
        in = new PacketInputStream(socket.getInputStream());
        out = socket.getOutputStream();
    }

    @Override
    public void run()
    {
        try
        {
            byte[] packet = in.readPacket();
            int id = Util.getId(packet);
            switch (id)
            {
                case 0x02:
                    Packet2Handshake handshake = new Packet2Handshake(packet);
                    // fire connect event
                    LoginEvent event = new LoginEvent(handshake.username, socket.getInetAddress());
                    BungeeCord.instance.pluginManager.onHandshake(event);
                    if (event.isCancelled())
                    {
                        throw new KickException(event.getCancelReason());
                    }

                    PacketFDEncryptionRequest request = EncryptionUtil.encryptRequest();
                    out.write(request.getPacket());
                    PacketFCEncryptionResponse response = new PacketFCEncryptionResponse(in.readPacket());

                    SecretKey shared = EncryptionUtil.getSecret(response, request);
                    if (!EncryptionUtil.isAuthenticated(handshake.username, request.serverId, shared))
                    {
                        throw new KickException("Not authenticated with minecraft.net");
                    }

                    // fire post auth event
                    BungeeCord.instance.pluginManager.onHandshake(event);
                    if (event.isCancelled())
                    {
                        throw new KickException(event.getCancelReason());
                    }

                    out.write(new PacketFCEncryptionResponse().getPacket());
                    in = new PacketInputStream(new CipherInputStream(socket.getInputStream(), EncryptionUtil.getCipher(false, shared)));
                    out = new CipherOutputStream(socket.getOutputStream(), EncryptionUtil.getCipher(true, shared));

                    int ciphId = Util.getId(in.readPacket());
                    if (ciphId != 0xCD)
                    {
                        throw new KickException("Unable to receive encrypted client status");
                    }

                    UserConnection userCon = new UserConnection(socket, in, out, handshake);
                    userCon.connect(BungeeCord.instance.config.getServer(handshake.username, handshake.host));
                    break;
                case 0xFE:
                    socket.setSoTimeout(100);
                    boolean newPing = true;
                    try
                    {
                        socket.getInputStream().read();
                        newPing = false;
                    } catch (IOException ex)
                    {
                    }
                    Configuration conf = BungeeCord.instance.config;
                    String ping = (newPing) ? ChatColor.COLOR_CHAR + "1"
                            + "\00" + conf.protcolVersion
                            + "\00" + conf.gameVersion
                            + "\00" + conf.motd
                            + "\00" + BungeeCord.instance.connections.size()
                            + "\00" + conf.maxPlayers
                            : conf.motd + ChatColor.COLOR_CHAR + BungeeCord.instance.connections.size() + ChatColor.COLOR_CHAR + conf.maxPlayers;
                    throw new KickException(ping);
                default:
                    throw new IllegalArgumentException("Wasn't ready for packet id " + Util.hex(id));
            }
        } catch (KickException ex)
        {
            kick(ex.getMessage());
        } catch (Exception ex)
        {
            kick("[Proxy Error] " + Util.exception(ex));
        }
    }

    private void kick(String message)
    {
        try
        {
            out.write(new PacketFFKick(message).getPacket());
        } catch (IOException ioe)
        {
        } finally
        {
            try
            {
                out.flush();
                socket.close();
            } catch (IOException ioe2)
            {
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.08875613398762534, 'fraction_numerical': 0.006294004693834009, 'mean_word_length': 1.5503264417845484, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3394840', 'n_tokens_mistral': 2411, 'n_tokens_neox': 2245, 'n_words': 442}