Search in sources :

Example 11 with C00Handshake

use of v1_8_9.net.minecraft.network.handshake.client.C00Handshake in project sol-client-glassmc by danterusdev.

the class Utils method pingServer.

public void pingServer(String address, IntConsumer callback) throws UnknownHostException {
    ServerAddress serverAddress = ServerAddress.fromString(address);
    NetworkManager networkManager = NetworkManager.createNetworkManagerAndConnect(InetAddress.getByName(serverAddress.getIP()), serverAddress.getPort(), false);
    networkManager.setNetHandler(new INetHandlerStatusClient() {

        private boolean expected = false;

        private long time = 0L;

        @Override
        public void handleServerInfo(S00PacketServerInfo packetIn) {
            if (expected) {
                networkManager.closeChannel(new ChatComponentText("Received unrequested status"));
            } else {
                expected = true;
                time = Minecraft.getSystemTime();
                networkManager.sendPacket(new C01PacketPing(this.time));
            }
        }

        @Override
        public void handlePong(S01PacketPong packetIn) {
            long systemTime = Minecraft.getSystemTime();
            callback.accept((int) (systemTime - time));
            networkManager.closeChannel(new ChatComponentText("Finished"));
        }

        @Override
        public void onDisconnect(IChatComponent reason) {
            callback.accept(-1);
        }
    });
    networkManager.sendPacket(new C00Handshake(47, serverAddress.getIP(), serverAddress.getPort(), EnumConnectionState.STATUS));
    networkManager.sendPacket(new C00PacketServerQuery());
}
Also used : ServerAddress(v1_8_9.net.minecraft.client.multiplayer.ServerAddress) C01PacketPing(v1_8_9.net.minecraft.network.status.client.C01PacketPing) S00PacketServerInfo(v1_8_9.net.minecraft.network.status.server.S00PacketServerInfo) INetHandlerStatusClient(v1_8_9.net.minecraft.network.status.INetHandlerStatusClient) S01PacketPong(v1_8_9.net.minecraft.network.status.server.S01PacketPong) C00PacketServerQuery(v1_8_9.net.minecraft.network.status.client.C00PacketServerQuery) IChatComponent(v1_8_9.net.minecraft.util.IChatComponent) C00Handshake(v1_8_9.net.minecraft.network.handshake.client.C00Handshake) NetworkManager(v1_8_9.net.minecraft.network.NetworkManager) ChatComponentText(v1_8_9.net.minecraft.util.ChatComponentText)

Example 12 with C00Handshake

use of v1_8_9.net.minecraft.network.handshake.client.C00Handshake in project Client by Sol-Client.

the class Utils method pingServer.

public void pingServer(String address, IntConsumer callback) throws UnknownHostException {
    ServerAddress serverAddress = ServerAddress.fromString(address);
    NetworkManager networkManager = NetworkManager.createNetworkManagerAndConnect(InetAddress.getByName(serverAddress.getIP()), serverAddress.getPort(), false);
    networkManager.setNetHandler(new INetHandlerStatusClient() {

        private boolean expected = false;

        private long time = 0L;

        @Override
        public void handleServerInfo(S00PacketServerInfo packetIn) {
            if (expected) {
                networkManager.closeChannel(new ChatComponentText("Received unrequested status"));
            } else {
                expected = true;
                time = Minecraft.getSystemTime();
                networkManager.sendPacket(new C01PacketPing(this.time));
            }
        }

        @Override
        public void handlePong(S01PacketPong packetIn) {
            long systemTime = Minecraft.getSystemTime();
            callback.accept((int) (systemTime - time));
            networkManager.closeChannel(new ChatComponentText("Finished"));
        }

        @Override
        public void onDisconnect(IChatComponent reason) {
            callback.accept(-1);
        }
    });
    networkManager.sendPacket(new C00Handshake(47, serverAddress.getIP(), serverAddress.getPort(), EnumConnectionState.STATUS));
    networkManager.sendPacket(new C00PacketServerQuery());
}
Also used : ServerAddress(net.minecraft.client.multiplayer.ServerAddress) C01PacketPing(net.minecraft.network.status.client.C01PacketPing) S00PacketServerInfo(net.minecraft.network.status.server.S00PacketServerInfo) INetHandlerStatusClient(net.minecraft.network.status.INetHandlerStatusClient) S01PacketPong(net.minecraft.network.status.server.S01PacketPong) C00PacketServerQuery(net.minecraft.network.status.client.C00PacketServerQuery) IChatComponent(net.minecraft.util.IChatComponent) C00Handshake(net.minecraft.network.handshake.client.C00Handshake) NetworkManager(net.minecraft.network.NetworkManager) ChatComponentText(net.minecraft.util.ChatComponentText)

Aggregations

C00Handshake (net.minecraft.network.handshake.client.C00Handshake)11 UnknownHostException (java.net.UnknownHostException)6 NetHandlerLoginClient (net.minecraft.client.network.NetHandlerLoginClient)6 InetAddress (java.net.InetAddress)5 NetworkManager (net.minecraft.network.NetworkManager)5 C00PacketServerQuery (net.minecraft.network.status.client.C00PacketServerQuery)4 ChatComponentText (net.minecraft.util.ChatComponentText)4 GameProfile (com.mojang.authlib.GameProfile)3 GuiDisconnected (net.minecraft.client.gui.GuiDisconnected)3 ServerAddress (net.minecraft.client.multiplayer.ServerAddress)3 C00PacketLoginStart (net.minecraft.network.login.client.C00PacketLoginStart)3 CPacketLoginStart (net.minecraft.network.login.client.CPacketLoginStart)3 INetHandlerStatusClient (net.minecraft.network.status.INetHandlerStatusClient)3 C01PacketPing (net.minecraft.network.status.client.C01PacketPing)3 S00PacketServerInfo (net.minecraft.network.status.server.S00PacketServerInfo)3 S01PacketPong (net.minecraft.network.status.server.S01PacketPong)3 ChatComponentTranslation (net.minecraft.util.ChatComponentTranslation)3 IChatComponent (net.minecraft.util.IChatComponent)3 ServerStatusResponse (net.minecraft.network.ServerStatusResponse)2 TextComponentString (net.minecraft.util.text.TextComponentString)2