Search in sources :

Example 6 with C00Handshake

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

the class OldServerPinger method ping.

public void ping(final ServerData server) throws UnknownHostException {
    ServerAddress serveraddress = ServerAddress.func_78860_a(server.serverIP);
    final NetworkManager networkmanager = NetworkManager.func_181124_a(InetAddress.getByName(serveraddress.getIP()), serveraddress.getPort(), false);
    this.pingDestinations.add(networkmanager);
    server.serverMOTD = "Pinging...";
    server.pingToServer = -1L;
    server.playerList = null;
    networkmanager.setNetHandler(new INetHandlerStatusClient() {

        private boolean field_147403_d = false;

        private boolean field_183009_e = false;

        private long field_175092_e = 0L;

        public void handleServerInfo(S00PacketServerInfo packetIn) {
            if (this.field_183009_e) {
                networkmanager.closeChannel(new ChatComponentText("Received unrequested status"));
            } else {
                this.field_183009_e = true;
                ServerStatusResponse serverstatusresponse = packetIn.getResponse();
                if (serverstatusresponse.getServerDescription() != null) {
                    server.serverMOTD = serverstatusresponse.getServerDescription().getFormattedText();
                } else {
                    server.serverMOTD = "";
                }
                if (serverstatusresponse.getProtocolVersionInfo() != null) {
                    server.gameVersion = serverstatusresponse.getProtocolVersionInfo().getName();
                    server.version = serverstatusresponse.getProtocolVersionInfo().getProtocol();
                } else {
                    server.gameVersion = "Old";
                    server.version = 0;
                }
                if (serverstatusresponse.getPlayerCountData() != null) {
                    server.populationInfo = EnumChatFormatting.GRAY + "" + serverstatusresponse.getPlayerCountData().getOnlinePlayerCount() + "" + EnumChatFormatting.DARK_GRAY + "/" + EnumChatFormatting.GRAY + serverstatusresponse.getPlayerCountData().getMaxPlayers();
                    if (ArrayUtils.isNotEmpty(serverstatusresponse.getPlayerCountData().getPlayers())) {
                        StringBuilder stringbuilder = new StringBuilder();
                        for (GameProfile gameprofile : serverstatusresponse.getPlayerCountData().getPlayers()) {
                            if (stringbuilder.length() > 0) {
                                stringbuilder.append("\n");
                            }
                            stringbuilder.append(gameprofile.getName());
                        }
                        if (serverstatusresponse.getPlayerCountData().getPlayers().length < serverstatusresponse.getPlayerCountData().getOnlinePlayerCount()) {
                            if (stringbuilder.length() > 0) {
                                stringbuilder.append("\n");
                            }
                            stringbuilder.append("... and ").append(serverstatusresponse.getPlayerCountData().getOnlinePlayerCount() - serverstatusresponse.getPlayerCountData().getPlayers().length).append(" more ...");
                        }
                        server.playerList = stringbuilder.toString();
                    }
                } else {
                    server.populationInfo = EnumChatFormatting.DARK_GRAY + "???";
                }
                if (serverstatusresponse.getFavicon() != null) {
                    String s = serverstatusresponse.getFavicon();
                    if (s.startsWith("data:image/png;base64,")) {
                        server.setBase64EncodedIconData(s.substring("data:image/png;base64,".length()));
                    } else {
                        OldServerPinger.logger.error("Invalid server icon (unknown format)");
                    }
                } else {
                    server.setBase64EncodedIconData((String) null);
                }
                this.field_175092_e = Minecraft.getSystemTime();
                networkmanager.sendPacket(new C01PacketPing(this.field_175092_e));
                this.field_147403_d = true;
            }
        }

        public void handlePong(S01PacketPong packetIn) {
            long i = this.field_175092_e;
            long j = Minecraft.getSystemTime();
            server.pingToServer = j - i;
            networkmanager.closeChannel(new ChatComponentText("Finished"));
        }

        public void onDisconnect(IChatComponent reason) {
            if (!this.field_147403_d) {
                OldServerPinger.logger.error("Can\'t ping " + server.serverIP + ": " + reason.getUnformattedText());
                server.serverMOTD = EnumChatFormatting.DARK_RED + "Can\'t connect to server.";
                server.populationInfo = "";
                OldServerPinger.this.tryCompatibilityPing(server);
            }
        }
    });
    try {
        networkmanager.sendPacket(new C00Handshake(47, serveraddress.getIP(), serveraddress.getPort(), EnumConnectionState.STATUS));
        networkmanager.sendPacket(new C00PacketServerQuery());
    } catch (Throwable throwable) {
        logger.error((Object) throwable);
    }
}
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) GameProfile(com.mojang.authlib.GameProfile) 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) ServerStatusResponse(net.minecraft.network.ServerStatusResponse) NetworkManager(net.minecraft.network.NetworkManager) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 7 with C00Handshake

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

the class RealmsServerStatusPinger method pingServer.

public void pingServer(final String p_pingServer_1_, final RealmsServerPing p_pingServer_2_) throws UnknownHostException {
    if (p_pingServer_1_ != null && !p_pingServer_1_.startsWith("0.0.0.0") && !p_pingServer_1_.isEmpty()) {
        RealmsServerAddress realmsserveraddress = RealmsServerAddress.parseString(p_pingServer_1_);
        final NetworkManager networkmanager = NetworkManager.func_181124_a(InetAddress.getByName(realmsserveraddress.getHost()), realmsserveraddress.getPort(), false);
        this.connections.add(networkmanager);
        networkmanager.setNetHandler(new INetHandlerStatusClient() {

            private boolean field_154345_e = false;

            public void handleServerInfo(S00PacketServerInfo packetIn) {
                ServerStatusResponse serverstatusresponse = packetIn.getResponse();
                if (serverstatusresponse.getPlayerCountData() != null) {
                    p_pingServer_2_.nrOfPlayers = String.valueOf(serverstatusresponse.getPlayerCountData().getOnlinePlayerCount());
                    if (ArrayUtils.isNotEmpty(serverstatusresponse.getPlayerCountData().getPlayers())) {
                        StringBuilder stringbuilder = new StringBuilder();
                        for (GameProfile gameprofile : serverstatusresponse.getPlayerCountData().getPlayers()) {
                            if (stringbuilder.length() > 0) {
                                stringbuilder.append("\n");
                            }
                            stringbuilder.append(gameprofile.getName());
                        }
                        if (serverstatusresponse.getPlayerCountData().getPlayers().length < serverstatusresponse.getPlayerCountData().getOnlinePlayerCount()) {
                            if (stringbuilder.length() > 0) {
                                stringbuilder.append("\n");
                            }
                            stringbuilder.append("... and ").append(serverstatusresponse.getPlayerCountData().getOnlinePlayerCount() - serverstatusresponse.getPlayerCountData().getPlayers().length).append(" more ...");
                        }
                        p_pingServer_2_.playerList = stringbuilder.toString();
                    }
                } else {
                    p_pingServer_2_.playerList = "";
                }
                networkmanager.sendPacket(new C01PacketPing(Realms.currentTimeMillis()));
                this.field_154345_e = true;
            }

            public void handlePong(S01PacketPong packetIn) {
                networkmanager.closeChannel(new ChatComponentText("Finished"));
            }

            public void onDisconnect(IChatComponent reason) {
                if (!this.field_154345_e) {
                    RealmsServerStatusPinger.LOGGER.error("Can\'t ping " + p_pingServer_1_ + ": " + reason.getUnformattedText());
                }
            }
        });
        try {
            networkmanager.sendPacket(new C00Handshake(RealmsSharedConstants.NETWORK_PROTOCOL_VERSION, realmsserveraddress.getHost(), realmsserveraddress.getPort(), EnumConnectionState.STATUS));
            networkmanager.sendPacket(new C00PacketServerQuery());
        } catch (Throwable throwable) {
            LOGGER.error((Object) throwable);
        }
    }
}
Also used : C01PacketPing(net.minecraft.network.status.client.C01PacketPing) S00PacketServerInfo(net.minecraft.network.status.server.S00PacketServerInfo) INetHandlerStatusClient(net.minecraft.network.status.INetHandlerStatusClient) GameProfile(com.mojang.authlib.GameProfile) 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) ServerStatusResponse(net.minecraft.network.ServerStatusResponse) NetworkManager(net.minecraft.network.NetworkManager) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 8 with C00Handshake

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

the class RealmsConnect method connect.

public void connect(final String p_connect_1_, final int p_connect_2_) {
    Realms.setConnectedToRealms(true);
    (new Thread("Realms-connect-task") {

        public void run() {
            InetAddress inetaddress = null;
            try {
                inetaddress = InetAddress.getByName(p_connect_1_);
                if (RealmsConnect.this.aborted) {
                    return;
                }
                RealmsConnect.this.connection = NetworkManager.func_181124_a(inetaddress, p_connect_2_, Minecraft.getMinecraft().gameSettings.func_181148_f());
                if (RealmsConnect.this.aborted) {
                    return;
                }
                RealmsConnect.this.connection.setNetHandler(new NetHandlerLoginClient(RealmsConnect.this.connection, Minecraft.getMinecraft(), RealmsConnect.this.onlineScreen.getProxy()));
                if (RealmsConnect.this.aborted) {
                    return;
                }
                RealmsConnect.this.connection.sendPacket(new C00Handshake(47, p_connect_1_, p_connect_2_, EnumConnectionState.LOGIN));
                if (RealmsConnect.this.aborted) {
                    return;
                }
                RealmsConnect.this.connection.sendPacket(new C00PacketLoginStart(Minecraft.getMinecraft().getSession().getProfile()));
            } catch (UnknownHostException unknownhostexception) {
                Realms.clearResourcePack();
                if (RealmsConnect.this.aborted) {
                    return;
                }
                RealmsConnect.LOGGER.error((String) "Couldn\'t connect to world", (Throwable) unknownhostexception);
                Minecraft.getMinecraft().getResourcePackRepository().func_148529_f();
                Realms.setScreen(new DisconnectedRealmsScreen(RealmsConnect.this.onlineScreen, "connect.failed", new ChatComponentTranslation("disconnect.genericReason", new Object[] { "Unknown host \'" + p_connect_1_ + "\'" })));
            } catch (Exception exception) {
                Realms.clearResourcePack();
                if (RealmsConnect.this.aborted) {
                    return;
                }
                RealmsConnect.LOGGER.error((String) "Couldn\'t connect to world", (Throwable) exception);
                String s = exception.toString();
                if (inetaddress != null) {
                    String s1 = inetaddress.toString() + ":" + p_connect_2_;
                    s = s.replaceAll(s1, "");
                }
                Realms.setScreen(new DisconnectedRealmsScreen(RealmsConnect.this.onlineScreen, "connect.failed", new ChatComponentTranslation("disconnect.genericReason", new Object[] { s })));
            }
        }
    }).start();
}
Also used : NetHandlerLoginClient(net.minecraft.client.network.NetHandlerLoginClient) UnknownHostException(java.net.UnknownHostException) C00PacketLoginStart(net.minecraft.network.login.client.C00PacketLoginStart) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) C00Handshake(net.minecraft.network.handshake.client.C00Handshake) InetAddress(java.net.InetAddress) UnknownHostException(java.net.UnknownHostException)

Example 9 with C00Handshake

use of v1_8_9.net.minecraft.network.handshake.client.C00Handshake in project clientcommands by Earthcomputer.

the class ServerConnectorCVW method connect.

@Override
public void connect() {
    Minecraft mc = Minecraft.getMinecraft();
    mc.loadWorld(null);
    System.gc();
    YggdrasilAuthenticationService authService = new YggdrasilAuthenticationService(mc.getProxy(), UUID.randomUUID().toString());
    MinecraftSessionService sessionService = authService.createMinecraftSessionService();
    GameProfileRepository profileRepo = authService.createProfileRepository();
    PlayerProfileCache profileCache = new PlayerProfileCache(profileRepo, new File(mc.mcDataDir, MinecraftServer.USER_CACHE_FILE.getName()));
    TileEntitySkull.setProfileCache(profileCache);
    TileEntitySkull.setSessionService(sessionService);
    PlayerProfileCache.setOnlineMode(false);
    mc.integratedServer = new ClientVirtualServer(mc, dimensionId, gameType, previousServer, chunks, playerTag, authService, sessionService, profileRepo, profileCache);
    mc.getIntegratedServer().startServerThread();
    mc.integratedServerIsRunning = true;
    mc.loadingScreen.displaySavingString(I18n.format("menu.loadingLevel"));
    while (!mc.getIntegratedServer().serverIsInRunLoop()) {
        if (!StartupQuery.check()) {
            mc.loadWorld(null);
            mc.displayGuiScreen(null);
            return;
        }
        String message = mc.getIntegratedServer().getUserMessage();
        if (message != null) {
            mc.loadingScreen.displayLoadingString(I18n.format(message));
        } else {
            mc.loadingScreen.displayLoadingString("");
        }
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
        // ignore
        }
    }
    mc.displayGuiScreen(new GuiScreenWorking());
    SocketAddress socketAddress = mc.getIntegratedServer().getNetworkSystem().addLocalEndpoint();
    NetworkManager netManager = NetworkManager.provideLocalClient(socketAddress);
    netManager.setNetHandler(new NetHandlerLoginClient(netManager, mc, null));
    netManager.sendPacket(new C00Handshake(socketAddress.toString(), 0, EnumConnectionState.LOGIN, true));
    GameProfile gameProfile = mc.getSession().getProfile();
    if (!mc.getSession().hasCachedProperties()) {
        gameProfile = mc.getSessionService().fillProfileProperties(gameProfile, true);
        mc.getSession().setProperties(gameProfile.getProperties());
    }
    netManager.sendPacket(new CPacketLoginStart(gameProfile));
    mc.myNetworkManager = netManager;
}
Also used : PlayerProfileCache(net.minecraft.server.management.PlayerProfileCache) GameProfileRepository(com.mojang.authlib.GameProfileRepository) MinecraftSessionService(com.mojang.authlib.minecraft.MinecraftSessionService) Minecraft(net.minecraft.client.Minecraft) CPacketLoginStart(net.minecraft.network.login.client.CPacketLoginStart) NetHandlerLoginClient(net.minecraft.client.network.NetHandlerLoginClient) GameProfile(com.mojang.authlib.GameProfile) C00Handshake(net.minecraft.network.handshake.client.C00Handshake) YggdrasilAuthenticationService(com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService) SocketAddress(java.net.SocketAddress) NetworkManager(net.minecraft.network.NetworkManager) File(java.io.File) GuiScreenWorking(net.minecraft.client.gui.GuiScreenWorking)

Example 10 with C00Handshake

use of v1_8_9.net.minecraft.network.handshake.client.C00Handshake in project Patcher by Sk1erLLC.

the class ProtocolVersionDetector method isCompatibleWithVersion.

public boolean isCompatibleWithVersion(String ip, int version) {
    ServerAddress address = ServerAddress.fromString(ip);
    String addressIp = address.getIP();
    int addressPort = address.getPort();
    NetworkManager nm = null;
    try {
        nm = NetworkManager.createNetworkManagerAndConnect(InetAddress.getByName(addressIp), addressPort, false);
        VersionCompatibilityStatusState handler = new VersionCompatibilityStatusState(version);
        nm.setNetHandler(handler);
        nm.sendPacket(new C00Handshake(version, addressIp, addressPort, EnumConnectionState.STATUS));
        nm.sendPacket(new C00PacketServerQuery());
        // system, which isn't worth it since we need to wait for the result anyways.
        while (handler.state == VersionCompatibilityStatusState.State.WAITING) {
            nm.checkDisconnected();
            if (nm.isChannelOpen())
                nm.processReceivedPackets();
            try {
                // we aren't busy waiting, just ticking
                // noinspection BusyWait
                Thread.sleep(50L);
            } catch (InterruptedException ignored) {
            }
        }
        return handler.state == VersionCompatibilityStatusState.State.COMPATIBLE;
    } catch (UnknownHostException e) {
        return false;
    } finally {
        if (nm != null && nm.isChannelOpen())
            nm.closeChannel(new ChatComponentText("Done"));
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) C00PacketServerQuery(net.minecraft.network.status.client.C00PacketServerQuery) ServerAddress(net.minecraft.client.multiplayer.ServerAddress) 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