March 15, 201411 yr Hi guys, I've updated my mod to the new network system and got packets from the client to the server to work fine at least at a network level. I'm having issues with server-to-client packets however. I create them the following way: public static void displayNewVillageGUI(EntityPlayer player, Point pos) { final ByteBufOutputStream data = getNewByteBufOutputStream(); try { data.write(ServerReceiver.PACKET_OPENGUI); data.write(CommonGuiHandler.GUI_NEWVILLAGE); StreamReadWrite.writeNullablePoint(pos, data); } catch (final IOException e) { MLN.printException(ServerSender.class+": Error in displayNewVillageGUI", e); } sendPacketToPlayer(createServerPacket(data), player); } public static S3FPacketCustomPayload createServerPacket(ByteBufOutputStream data) { return new S3FPacketCustomPayload(ServerReceiver.PACKET_CHANNEL, data.buffer()); } public static void sendPacketToPlayer(Packet packet, EntityPlayer player) { ((EntityPlayerMP)player).playerNetServerHandler.sendPacket(packet); } And then read them the following way: @SubscribeEvent public void onPacketData(ServerCustomPacketEvent event) { if (FMLCommonHandler.instance().getSide().isServer() && (MLN.LogNetwork>=MLN.MAJOR)) { MLN.major(this, "Received a packet despite being server."); return; } if (event.packet==null) { MLN.error(this, "Received a null packet!"); return; } if (event.packet.payload()==null) { MLN.error(this, "Received a packet with null data on channel: "+event.packet.channel()); return; } if (Mill.clientWorld==null) { MLN.error(this, "Received a packet despite null clientWorld."); return; } ByteBufInputStream data = new ByteBufInputStream(event.packet.payload()); try { final int packettype=data.read(); Mill.clientWorld.millenaireEnabled=true; if (MLN.LogNetwork>=MLN.DEBUG) { MLN.debug(this, "Received client packet type: "+packettype); } (...) } catch (final Exception e) { MLN.printException("Error in ClientReceiver.onPacketData:", e); } } In the packet I gave as example above, the first data written in ("data.write(ServerReceiver.PACKET_OPENGUI);") is 104. On the client side however when I try to read it I get 0. If I look at the content of the packet on the server side and then on the client side using the debugger I get the two attachments below. As you can see most of the content is the same (and fits what I wrote in my packet), but the beginning isn't. On the client side the first byte has changed from 104 to -56. Server: https://dl.dropboxusercontent.com/u/14307461/temp/forge/Capture%20d%E2%80%99%C3%A9cran%202014-03-15%20%C3%A0%2012.27.12.png[/img] Client: https://dl.dropboxusercontent.com/u/14307461/temp/forge/Capture%20d%E2%80%99%C3%A9cran%202014-03-15%20%C3%A0%2012.26.32.png[/img] I assume I must be miss-using the new system in some ways, anybody knows more? BTW my client-to-server code is almost exactly the same, but uses the C17PacketCustomPayload class. Thanks! http://www.millenaire.org/img/dynamicsig.png[/img]
March 16, 201411 yr You seem to be doing a lot more work than is necessary. Take a look at this. It works straight out of the box, all you do is register your packets and initialize/post-initialize the packet pipeline. http://i.imgur.com/NdrFdld.png[/img]
March 16, 201411 yr Author I saw that tutorial, it looks need but would require a lot of refactoring to adapt my mod to it. In any case, I found the issue, and it was really stupid - I had misconfigured my handlers and the packet I was receiving was a server-side packet. Bad luck for me, the content was almost the same as the client packet I was expecting which got me on a completely wrong track. Anyway, onward to the next bug http://www.millenaire.org/img/dynamicsig.png[/img]
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.