Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A sideonly issue in MBE_60 #8

Closed
herbix opened this issue May 16, 2015 · 5 comments
Closed

A sideonly issue in MBE_60 #8

herbix opened this issue May 16, 2015 · 5 comments

Comments

@herbix
Copy link

herbix commented May 16, 2015

Since MessageHandlerOnClient uses client only class Minecraft, it would throw a ClassNotFoundException in a dedicated server when MessageHandlerOnClient is loaded. But StartupCommon uses MessageHandlerOnClient. So I doubt whether these codes work on dedicated servers.

I would use different network registration at dedicated server and client. At client, I would use MBE60 codes:

simpleNetworkWrapper.registerMessage(MessageHandlerOnServer.class, AirstrikeMessageToServer.class,
                                          AIRSTRIKE_MESSAGE_ID, Side.SERVER);
simpleNetworkWrapper.registerMessage(MessageHandlerOnClient.class, TargetEffectMessageToClient.class,
                                          TARGET_EFFECT_MESSAGE_ID, Side.CLIENT);

While at a dedicated server, I would use this:

simpleNetworkWrapper.registerMessage(MessageHandlerOnServer.class, AirstrikeMessageToServer.class,
                                          AIRSTRIKE_MESSAGE_ID, Side.SERVER);
simpleNetworkWrapper.registerMessage(MessageHandlerOnServerButHandleClientMessage.class, TargetEffectMessageToClient.class,
                                          TARGET_EFFECT_MESSAGE_ID, Side.CLIENT);

And define MessageHandlerOnServerButHandleClientMessage:

public class MessageHandlerOnServerButHandleClientMessage implements IMessageHandler<TargetEffectMessageToClient, IMessage> {
  public IMessage onMessage(final TargetEffectMessageToClient message, MessageContext ctx) {
    throw new RuntimeException("Cannot handle TargetEffectMessageToClient at a dedicated server.");
  }
}
@TheGreyGhost
Copy link
Owner

Hi Herbix
Yes you could be right, I will try it and see. Thanks for the report.
-TGG

@TheGreyGhost
Copy link
Owner

Hi Herbix
I have previously tested the code on dedicated server with a built mod and it worked fine, but I think it might be luck. Probably better to not register the client side handler on the dedicated server, as you suggest. I will update the code and retest it.
-TGG

@herbix
Copy link
Author

herbix commented May 18, 2015

Some client side handlers are needed, or TargetEffectMessageToClient cannot be handled on the dedicated server. But not the one on the client.

@TheGreyGhost
Copy link
Owner

Yes. The problem is that the dedicated server needs to have something registered for that message ID, even if there is no server handler. A weakness in the simple network wrapper design, I think.

I reckon your approach is good, with a slight twist - what I am thinking of:
(1) Always register a server message handler in common, even if there is no handler (use a dummy class similar to yours)
(2) Register the client message handler in clientonly.
A message which arrives on the client by mistake will trigger the normal handler not found from Forge.
The reason I'm not thinking to use DedicatedServer proxy code is because this is very unusual for modders (they're not used to seeing it, unlike Client proxy), and also because MBE is not set up for that :)

I'll test it out and commit when I'm done...

-TGG

@TheGreyGhost
Copy link
Owner

Tested it; seems to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants