geekles Posted October 7, 2019 Posted October 7, 2019 (edited) I am currently developing a mod that is an updated version of mods such as "Hardcore Darkness". Being this is my first "real" mod, I was glad to see that I was able to successfully instantiate a new channel for both the server and client to use. This would essentially allow the server to ensure the player has the mod installed before letting them in, which is exactly what I wanted. However, I also want to give the player the option to join a server if they have the mod installed on their client even if the server isn't forge or has the mod installed on the server. However, because of the "forge handshake", it will automatically close the connection from the client to the server if the server doesn't have a channel for it to communicate with my mod with. I want it so that I can disable the client from closing the connection if there is no open channel to communicate with the mod. Not sure how to do this. The mod (at the moment), has no real need to send custom packets to the server since the mechanics simply mess with the visuals (darkness, fog levels, etc.) Therefore there is no need for there to be any information to be synced across all the clients across the server, asides for weather and time which is already sent by the server by default. So far, I know the following lines in the FMLHandshakeHandler is the culprit for the issue: void handleServerModListOnClient(FMLHandshakeMessages.S2CModList serverModList, Supplier<NetworkEvent.Context> c) { LOGGER.debug(FMLHSMARKER, "Logging into server with mod list [{}]", String.join(", ", serverModList.getModList())); boolean accepted = NetworkRegistry.validateClientChannels(serverModList.getChannels()); c.get().setPacketHandled(true); if (!accepted) { LOGGER.error(FMLHSMARKER, "Terminating connection with server, mismatched mod list"); c.get().getNetworkManager().closeChannel(new StringTextComponent("Connection closed - mismatched mod channel list")); return; } [...] I've tried going through the classes to see how it gets from point A (see below) to point B (see above). Too many variables and functions are being called however and it isn't clear how or from what that function gets called. INSTANCE = NetworkRegistry.newSimpleChannel( new ResourceLocation(Blackout.ID, "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals ); Edited October 7, 2019 by geekles Quote
geekles Posted October 7, 2019 Author Posted October 7, 2019 (edited) 1 6 hours ago, diesieben07 said: When registering your channel you provide two predicates (Predicate<String>) to test on server and client whether the remote version should be accepted. If the mod is not installed on the other side, NetworkRegistry.ABSENTwill be passed as the version. If your predicate returns true, the connection is allowed. How would I listen for when this NetworkRegistry.ABSENT is passed? I assume perhaps there's an event I can cancel and handle it myself instead of having the client by default close the connection. Edited October 7, 2019 by geekles Quote
geekles Posted October 7, 2019 Author Posted October 7, 2019 23 minutes ago, diesieben07 said: These two are the predicates I talked about. You need to pass an implementation here (a lambda expression would be easiest) that also handles ABSENT instead of only allowing an exact match of PROTOCOL_VERSION. Which one though. Should both handle an unmatched Protocol_Version? Quote
geekles Posted October 7, 2019 Author Posted October 7, 2019 (edited) 9 minutes ago, diesieben07 said: clientAcceptedVersions: Controls which server versions the client will accept. If you make this accept ABSENT it means that a client with your mod can connect to a server without your mod. serverAcceptedVersions: Controls which client versions the server will accept. If you make this accept ABSENT it means that a client wihtout your mod can connect to a server with your mod. Thank you. I'll give it a try soon. Edited October 7, 2019 by geekles 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.