techstack Posted January 13, 2015 Posted January 13, 2015 Hello, I'm working on a mod where I send packets to the clients in the area with simpleNetworkWrapper.sendToAllAround and passing my MachineModMessageEntityToClient class which implements IMessage. When I do so with only 1 player online or in SP it works fine... the data is sent to the client for rendering . But if I have two (& possibly for more players ) online when the packets are sent both clients are kicked from the server and the error below is in the console. I've set break points in the FML code where it is causing the exception and I can see from the message object that it is in the processing of my packet but the packet appears to be in this "EmptyByteBuf" state even though I'm creating it with my constructor that will provide the data to it. I've tried back porting my project to 1.7 and I haven't encountered this problem in 1.7 yet, but i'd prefer to have my mod working in 1.8 because I still have a lot of work to do and 1.8 may be official by then. I'm still somewhat new to modding so I thought maybe another set of eyes my spot what i'm doing wrong or offer a better way to troubleshoot the issue. Any help or guidance is greatly appreciated I've been racking my brain on this one for a few days now. Tech. my project on github: https://github.com/TechStack/TechStack-s-HeavyMachineryMod networkHandler: https://github.com/TechStack/TechStack-s-HeavyMachineryMod/blob/master/src/main/java/com/projectreddog/machinemod/network/MachineModMessageEntityToClientHandler.java Imessage implementation : https://github.com/TechStack/TechStack-s-HeavyMachineryMod/blob/master/src/main/java/com/projectreddog/machinemod/network/MachineModMessageEntityToClient.java Network Registration line 26 specifically: https://github.com/TechStack/TechStack-s-HeavyMachineryMod/blob/master/src/main/java/com/projectreddog/machinemod/init/ModNetwork.java Call that is sending the packet line 213 : https://github.com/TechStack/TechStack-s-HeavyMachineryMod/blob/master/src/main/java/com/projectreddog/machinemod/entity/EntityMachineModRideable.java#L213 ERROR from client side console (spoiler tag seems to not work for me): https://gist.github.com/TechStack/442357d160ee49ac2260 Quote
TheGreyGhost Posted January 13, 2015 Posted January 13, 2015 Hi It's been a while since I worked on packets but I don't see an obvious problem. It looks to me like the handler hasn't even reached your code yet, and given that this works in single player makes me suspicious that it might be a FML bug. FML should automatically add a discriminator byte to the buffer so it should always have at least one byte in it. You could try upgrading Forge to the latest version and seeing if that fixes it. Otherwise, you could add System.out.println to the handlers, the message constructors and toBytes() & fromBytes try to track which methods were actually called, it might give you a clue. Good luck with it; last time I had a Network handler issue (caused by incorrect registration) it took me the whole day to track it down. I'm about to try and work up an example Network handler, if you haven't cracked it in a couple of days I might practice on your project, but no promises -TGG Quote
techstack Posted January 14, 2015 Author Posted January 14, 2015 First , Thank you TheGreyGhost for taking a look & your suggestions I appreciate it. I can confirm the constructor ,frombytes & handler are getting called by the client when it is working properly with only one player within range of the packet location. I can also confirm that sometimes when the client reconnects and other clients are within range that it is not even calling the constructor of my message so it appears to be a bug in FML before my code is running on the client. This plus the fact that I'm not seeing the same behavior when I back port to 1.7 leads me to believe it is a bug in FML 1.8. I'm working with forge 18. build 1285 which is the latest so it sounds like I need to wait until it is corrected. Feel free to use the project as you'd like its the reason its on github I had mostly used other tutorials here on the forums on networking & I have came across a few of your post and examples and I've found them helpful. Thanks again ! Quote
coolAlias Posted January 14, 2015 Posted January 14, 2015 It looks like you have a packet that is trying to read from an empty buffer, so I would double-check your toBytes and fromBytes implementations (the packet you linked looked fine, though). Another thing, in 1.8, the network is handled on a separate thread; see some discussion about it here. Being on a separate thread means that often the world and other objects which you would expect to be up-to-date may actually be out of sync, and odd things can happen. My own network code seems to be working fine in 1.8 and is almost directly ported from 1.7.10. Feel free to take a look. Sorry I can't tell you exactly what is wrong with your specific code Quote http://i.imgur.com/NdrFdld.png[/img]
techstack Posted January 14, 2015 Author Posted January 14, 2015 Hi coolAlias, Thanks for the response. I did come across your discussion with Lex Earlier today and tried separating it into another thread at one point to see if that would help but it did not. I took a look at your project and made a fork to test with. If i use your code but change it to sendtoAll instead of sendTo in your Combo class I get the same error when I have multiple users connected to the dedicated server & I attack a mob after pressing X to "Lock" on to them. Looks like FML has a bug when sending packets to multiple clients but works OK if the packet is going to one player/client. Guess i'm not crazy after all Thanks again for another set of code to confirm it with Quote
coolAlias Posted January 14, 2015 Posted January 14, 2015 Interesting. I haven't tried using sendToAllAround in a multiplayer environment yet, so that's good to know. Thanks for reporting your results, and hopefully it will get fixed soon. Quote http://i.imgur.com/NdrFdld.png[/img]
techstack Posted January 14, 2015 Author Posted January 14, 2015 Is https://github.com/MinecraftForge/FML/ the proper place to report bugs like this or do they use some other issue tracking tool? Quote
TheGreyGhost Posted January 14, 2015 Posted January 14, 2015 Hi Yeah the 'issues' on GitHub is fine. Or you can also post to http://www.minecraftforge.net/forum/index.php/board,15.0.htm. Lex & collaborators see them either way. -TGG Quote
techstack Posted January 16, 2015 Author Posted January 16, 2015 For anyone who may encounter this issue in the future I've created an issue on FML's Github for this @ https://github.com/MinecraftForge/FML/issues/588 I've also created a temporary helper method that will send a packet to all players around a point by sending the packets individually. I'm sure its not as effecient but it seems to work until we have a permanent solution to the root cause. Workaround based on how FML finds players around a point: public static void sendPacketToAllAround( IMessage packet, TargetPoint tp) { for (EntityPlayerMP player : (List<EntityPlayerMP>)FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().playerEntityList) { if (player.dimension == tp.dimension) { double d4 = tp.x - player.posX; double d5 = tp.y - player.posY; double d6 = tp.z - player.posZ; if (d4 * d4 + d5 * d5 + d6 * d6 < tp.range * tp.range) { ModNetwork.simpleNetworkWrapper.sendTo(packet,player ); } } } } Hope this helps ! Quote
Recommended Posts
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.