Problème de protocole



  • Coucou le monde, voilà j'ai crée pour mon menu personnalisé un système de connexion inclus directement dans celui-ci :

    Tout fonctionne bien… Quand on se connecte à une partie solo juste avant sinon on a droit à un magnifique NullPointerExeption :

    Je suppose (grandement) que le problème vient d'un protocole qui retourne NULL à un moment donné mais pourquoi le faire que quand on c'est pas connecté à une partie solo juste avant ?! Voici mon code qui gère tout ça :

    private void initiateServerConnection()
    
        {
            this.isConnecting = true;
            ((GuiShunayteButton) this.buttonList.get(1)).setVisible(false);
            ((GuiShunayteButton) this.buttonList.get(2)).setVisible(false);
            ((GuiShunayteButton) this.buttonList.get(3)).setVisible(false);
            ((GuiShunayteButton) this.buttonList.get(5)).setVisible(false);
    
            ((GuiShunayteButton) this.buttonList.get(0)).setButtonName(I18n.format("menu.connect.connecting", new Object[0]));
    
            ServerAddress serveraddress = ServerAddress.func_78860_a(server.serverIP);
            mc.loadWorld((WorldClient)null);
            mc.setServerData(server);
            this.connectToServer(serveraddress.getIP(), serveraddress.getPort());
            ((GuiShunayteButton) this.buttonList.get(6)).setVisible(true);
        }
    
        private void connectToServer(final String p_146367_1_, final int p_146367_2_)
        {
            logger.info("Connecting to " + p_146367_1_ + ", " + p_146367_2_);
            (new Thread("Server Connector #" + field_146372_a.incrementAndGet())
            {
                public void run()
                {
    
                    InetAddress inetaddress = null;
    
                    try
                    {
                        if (GuiShunayteMainMenu.this.field_146373_h)
                        {
                            return;
                        }
    
                        inetaddress = InetAddress.getByName(p_146367_1_);
    
                        GuiShunayteMainMenu.this.field_146371_g = NetworkManager.provideLanClient(inetaddress, p_146367_2_);
                        GuiShunayteMainMenu.this.field_146371_g.setNetHandler(new NetHandlerLoginClient(GuiShunayteMainMenu.this.field_146371_g, GuiShunayteMainMenu.this.mc, GuiShunayteMainMenu.this.screen));
    
                        GuiShunayteMainMenu.this.field_146371_g.scheduleOutboundPacket(new C00Handshake(5, p_146367_1_, p_146367_2_, EnumConnectionState.LOGIN), new GenericFutureListener[0]);
                        GuiShunayteMainMenu.this.field_146371_g.scheduleOutboundPacket(new C00PacketLoginStart(GuiShunayteMainMenu.this.mc.getSession().func_148256_e()), new GenericFutureListener[0]);
    
                    }
                    catch (UnknownHostException unknownhostexception)
                    {
                        if (GuiShunayteMainMenu.this.field_146373_h)
                        {
                            return;
                        }
    
                        GuiShunayteMainMenu.logger.error("Couldn\'t connect to server", unknownhostexception);
                        GuiShunayteMainMenu.this.mc.displayGuiScreen(new GuiDisconnected(GuiShunayteMainMenu.this.screen, "connect.failed", new ChatComponentTranslation("disconnect.genericReason", new Object[] {"Unknown host"})));
                    }
                    catch (Exception exception)
                    {
                        if (GuiShunayteMainMenu.this.field_146373_h)
                        {
                            return;
                        }
    
                        GuiShunayteMainMenu.logger.error("Couldn\'t connect to server", exception);
                        String s = exception.toString();
    
                        if (inetaddress != null)
                        {
                            String s1 = inetaddress.toString() + ":" + p_146367_2_;
                            s = s.replaceAll(s1, "");
                        }
    
                        GuiShunayteMainMenu.this.mc.displayGuiScreen(new GuiDisconnected(GuiShunayteMainMenu.this.screen, "connect.failed", new ChatComponentTranslation("disconnect.genericReason", new Object[] {s})));
                    }
                }
            }).start();
        }
    

    Merci d'avance 😃



  • Essaie plutôt çà pour te connecter à un serveur :

    
    FMLClientHandler.instance().connectToServerAtStartup(adress, port);
    
    

    Ton code devrait ressembler à çà :

    
    private void initiateServerConnection()
    
    {
    this.isConnecting = true;
    ((GuiShunayteButton) this.buttonList.get(1)).setVisible(false);
    ((GuiShunayteButton) this.buttonList.get(2)).setVisible(false);
    ((GuiShunayteButton) this.buttonList.get(3)).setVisible(false);
    ((GuiShunayteButton) this.buttonList.get(5)).setVisible(false);
    
    ((GuiShunayteButton) this.buttonList.get(0)).setButtonName(I18n.format("menu.connect.connecting", new Object[0]));
    
    FMLClientHandler.instance().connectToServerAtStartup(adress, port);
    ((GuiShunayteButton) this.buttonList.get(6)).setVisible(true);
    }