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 :
:::
[22:46:21] [Netty Client IO #1/ERROR] [FML]: NetworkDispatcher exception java.lang.NullPointerException at cpw.mods.fml.client.FMLClientHandler.waitForPlayClient(FMLClientHandler.java:844) ~[FMLClientHandler.class:?] at cpw.mods.fml.common.FMLCommonHandler.waitForPlayClient(FMLCommonHandler.java:585) ~[FMLCommonHandler.class:?] at cpw.mods.fml.common.network.handshake.NetworkDispatcher.clientListenForServerHandshake(NetworkDispatcher.java:154) [NetworkDispatcher.class:?] at cpw.mods.fml.common.network.handshake.FMLHandshakeClientState$1.accept(FMLHandshakeClientState.java:33) ~[FMLHandshakeClientState$1.class:?] at cpw.mods.fml.common.network.handshake.FMLHandshakeClientState$1.accept(FMLHandshakeClientState.java:27) ~[FMLHandshakeClientState$1.class:?] at cpw.mods.fml.common.network.handshake.HandshakeMessageHandler.channelRead0(HandshakeMessageHandler.java:27) ~[HandshakeMessageHandler.class:?] at cpw.mods.fml.common.network.handshake.HandshakeMessageHandler.channelRead0(HandshakeMessageHandler.java:9) ~[HandshakeMessageHandler.class:?] at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98) ~[SimpleChannelInboundHandler.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) ~[MessageToMessageDecoder.class:?] at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?] at cpw.mods.fml.common.network.handshake.ChannelRegistrationHandler.channelRead0(ChannelRegistrationHandler.java:32) ~[ChannelRegistrationHandler.class:?] at cpw.mods.fml.common.network.handshake.ChannelRegistrationHandler.channelRead0(ChannelRegistrationHandler.java:15) ~[ChannelRegistrationHandler.class:?] at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98) ~[SimpleChannelInboundHandler.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) ~[DefaultChannelPipeline.class:?] at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) ~[EmbeddedChannel.class:?] at cpw.mods.fml.common.network.handshake.NetworkDispatcher.handleClientSideCustomPacket(NetworkDispatcher.java:257) ~[NetworkDispatcher.class:?] at cpw.mods.fml.common.network.handshake.NetworkDispatcher.channelRead0(NetworkDispatcher.java:185) ~[NetworkDispatcher.class:?] at cpw.mods.fml.common.network.handshake.NetworkDispatcher.channelRead0(NetworkDispatcher.java:43) ~[NetworkDispatcher.class:?] at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98) ~[SimpleChannelInboundHandler.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?] at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:173) [ByteToMessageDecoder.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?] at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:173) [ByteToMessageDecoder.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) [MessageToMessageDecoder.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?] at io.netty.handler.timeout.ReadTimeoutHandler.channelRead(ReadTimeoutHandler.java:149) [ReadTimeoutHandler.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) [DefaultChannelPipeline.class:?] at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:100) [AbstractNioByteChannel$NioByteUnsafe.class:?] at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:480) [NioEventLoop.class:?] at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:447) [NioEventLoop.class:?] at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:341) [NioEventLoop.class:?] at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101) [SingleThreadEventExecutor$2.class:?] at java.lang.Thread.run(Unknown Source) [?:1.7.0_65]
:::
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); }