Search in sources :

Example 1 with CPacketLoginStart

use of net.minecraft.network.login.client.CPacketLoginStart in project 3arthh4ck by 3arthqu4ke.

the class GuiConnectingPingBypass method connect.

/**
 * Connects to the given server via PingBypass.
 *
 * @param proxyIP the pingbypass ip.
 * @param proxyPort the pingbypass port.
 * @param actualIP ip of the server we want to connect to.
 * @param actualPort port of the server we want to connect to.
 */
private void connect(final String proxyIP, final int proxyPort, final String actualIP, final int actualPort) {
    LOGGER.info("Connecting to PingBypass: {}, {}", proxyIP, proxyPort);
    (new Thread("Server Connector #" + CONNECTION_ID.incrementAndGet()) {

        public void run() {
            InetAddress inetaddress = null;
            try {
                if (cancel) {
                    return;
                }
                inetaddress = InetAddress.getByName(proxyIP);
                networkManager = NetworkManager.createNetworkManagerAndConnect(inetaddress, proxyPort, mc.gameSettings.isUsingNativeTransport());
                networkManager.setNetHandler(new NetHandlerLoginClient(networkManager, mc, previousGuiScreen));
                networkManager.sendPacket(new C00Handshake(actualIP, actualPort, EnumConnectionState.LOGIN, true));
                networkManager.sendPacket(new CPacketLoginStart(mc.getSession().getProfile()));
            } catch (UnknownHostException e) {
                if (cancel) {
                    return;
                }
                LOGGER.error("Couldn't connect to PingBypass", e);
                mc.addScheduledTask(() -> mc.displayGuiScreen(new GuiDisconnected(previousGuiScreen, "connect.failed", new TextComponentTranslation("disconnect.genericReason", "Unknown host"))));
            } catch (Exception exception) {
                if (cancel) {
                    return;
                }
                LOGGER.error("Couldn't connect to PingBypass", exception);
                String s = exception.toString();
                if (inetaddress != null) {
                    String s1 = inetaddress + ":" + proxyPort;
                    s = s.replace(s1, "");
                }
                String finalS = s;
                mc.addScheduledTask(() -> mc.displayGuiScreen(new GuiDisconnected(previousGuiScreen, "connect.failed", new TextComponentTranslation("disconnect.genericReason", finalS))));
            }
        }
    }).start();
}
Also used : NetHandlerLoginClient(net.minecraft.client.network.NetHandlerLoginClient) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) UnknownHostException(java.net.UnknownHostException) C00Handshake(net.minecraft.network.handshake.client.C00Handshake) TextComponentString(net.minecraft.util.text.TextComponentString) GuiDisconnected(net.minecraft.client.gui.GuiDisconnected) InetAddress(java.net.InetAddress) UnknownHostException(java.net.UnknownHostException) CPacketLoginStart(net.minecraft.network.login.client.CPacketLoginStart)

Example 2 with CPacketLoginStart

use of net.minecraft.network.login.client.CPacketLoginStart in project Almura by AlmuraDev.

the class ConnectingGui method connect.

private void connect(final String ip, final int port) {
    LOGGER.info("Connecting to {}, {}", ip, Integer.valueOf(port));
    (new Thread("Server Connector #" + CONNECTION_ID.incrementAndGet()) {

        public void run() {
            InetAddress inetaddress = null;
            try {
                if (ConnectingGui.this.cancel) {
                    return;
                }
                inetaddress = InetAddress.getByName(ip);
                if (Almura.networkManager != null) {
                    Almura.networkManager = null;
                }
                Almura.networkManager = NetworkManager.createNetworkManagerAndConnect(inetaddress, port, ConnectingGui.this.mc.gameSettings.isUsingNativeTransport());
                Almura.networkManager.setNetHandler(new NetHandlerLoginClient(Almura.networkManager, ConnectingGui.this.mc, ConnectingGui.this.previousGuiScreen));
                Almura.networkManager.sendPacket(new C00Handshake(ip, port, EnumConnectionState.LOGIN));
                Almura.networkManager.sendPacket(new CPacketLoginStart(ConnectingGui.this.mc.getSession().getProfile()));
            } catch (UnknownHostException unknownhostexception) {
                if (ConnectingGui.this.cancel) {
                    return;
                }
                ConnectingGui.LOGGER.error("Couldn't connect to server", (Throwable) unknownhostexception);
                new DisconnectedGui("Could not connect to server.").display();
            } catch (Exception exception) {
                if (ConnectingGui.this.cancel) {
                    return;
                }
                ConnectingGui.LOGGER.error("Couldn't connect to server", (Throwable) exception);
                String s = exception.toString();
                if (inetaddress != null) {
                    String s1 = inetaddress + ":" + port;
                    s = s.replaceAll(s1, "");
                }
                new DisconnectedGui("Exception encountered.  Could not connect to server.").display();
            }
        }
    }).start();
}
Also used : NetHandlerLoginClient(net.minecraft.client.network.NetHandlerLoginClient) UnknownHostException(java.net.UnknownHostException) C00Handshake(net.minecraft.network.handshake.client.C00Handshake) TextComponentString(net.minecraft.util.text.TextComponentString) InetAddress(java.net.InetAddress) UnknownHostException(java.net.UnknownHostException) CPacketLoginStart(net.minecraft.network.login.client.CPacketLoginStart)

Example 3 with CPacketLoginStart

use of net.minecraft.network.login.client.CPacketLoginStart 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)

Aggregations

NetHandlerLoginClient (net.minecraft.client.network.NetHandlerLoginClient)3 C00Handshake (net.minecraft.network.handshake.client.C00Handshake)3 CPacketLoginStart (net.minecraft.network.login.client.CPacketLoginStart)3 InetAddress (java.net.InetAddress)2 UnknownHostException (java.net.UnknownHostException)2 TextComponentString (net.minecraft.util.text.TextComponentString)2 GameProfile (com.mojang.authlib.GameProfile)1 GameProfileRepository (com.mojang.authlib.GameProfileRepository)1 MinecraftSessionService (com.mojang.authlib.minecraft.MinecraftSessionService)1 YggdrasilAuthenticationService (com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService)1 File (java.io.File)1 SocketAddress (java.net.SocketAddress)1 Minecraft (net.minecraft.client.Minecraft)1 GuiDisconnected (net.minecraft.client.gui.GuiDisconnected)1 GuiScreenWorking (net.minecraft.client.gui.GuiScreenWorking)1 NetworkManager (net.minecraft.network.NetworkManager)1 PlayerProfileCache (net.minecraft.server.management.PlayerProfileCache)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1