Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[1.7.10] How to send a message to server during ClientConnectedToServerEvent

Featured Replies

Posted

I want to send some information just after the handshake completed(handling ClientConnectedToServerEvent), and the mod on server side will check the information and do something.

The problem is, the server never receives the message sent during ClientConnectedToServerEvent.

The code is shown below:

	@SubscribeEvent
	public void onClientConnectedToServer(ClientConnectedToServerEvent event) {
		if (event.connectionType.equals("MODDED")) {
			FMLLog.info("send to server");
			LIUtils.netHandler.sendToServer(message());
		}
	}

Actually, I get my FMLLog:

[00:12:19] [Netty Client IO #2/DEBUG] [FML/]: Server FML protocol version 2, 4 byte dimension received 0
[00:12:19] [Netty Client IO #2/TRACE] [FML/]: $ServerHello->FMLHandshakeClientState$2:HELLO
[00:12:19] [Netty Client IO #2/INFO] [FML/]: Server protocol version 2
[00:12:19] [Netty Client IO #2/DEBUG] [FML/]: Received override dimension 0
[00:12:19] [Netty IO #5/TRACE] [FML/]: $ClientHello->FMLHandshakeServerState$2:HELLO
[00:12:19] [Netty IO #5/INFO] [FML/]: Client protocol version 2
[00:12:19] [Netty IO #5/TRACE] [FML/]: $ModList:7 mods->FMLHandshakeServerState$2:HELLO
[00:12:19] [Netty IO #5/INFO] [FML/]: Client attempting to join with 7 mods : [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected]
[00:12:19] [Netty IO #5/INFO] [FML/]: Attempting connection with missing mods [] at CLIENT
[00:12:19] [Netty Client IO #2/TRACE] [FML/]: $ModList:7 mods->FMLHandshakeClientState$3:WAITINGSERVERDATA
[00:12:19] [Netty Client IO #2/INFO] [FML/]: Attempting connection with missing mods [] at SERVER
[00:12:19] [Netty IO #5/TRACE] [FML/]: $HandshakeAck:{2}->FMLHandshakeServerState$3:WAITINGCACK
[00:12:19] [Netty Client IO #2/TRACE] [FML/]: $HandshakeAck:{2}->FMLHandshakeClientState$5:PENDINGCOMPLETE
[00:12:19] [Netty IO #5/TRACE] [FML/]: $HandshakeAck:{4}->FMLHandshakeServerState$4:COMPLETE
[00:12:19] [Netty Client IO #2/TRACE] [FML/]: $HandshakeAck:{3}->FMLHandshakeClientState$6:COMPLETE
[00:12:19] [Netty IO #5/TRACE] [FML/]: $HandshakeAck:{5}->FMLHandshakeServerState$5:DONE
[00:12:20] [server thread/INFO] [FML/]: [server thread] Server side modded connection established
[00:12:20] [Client thread/DEBUG] [FML/]: The fluid minecraft:lava has been selected as the default fluid for lava
[00:12:20] [Client thread/DEBUG] [FML/]: The fluid minecraft:water has been selected as the default fluid for water
[00:12:20] [Client thread/DEBUG] [FML/]: The fluid LIUtils:imagproj has been selected as the default fluid for imagproj
[00:12:20] [Client thread/INFO] [FML/]: [Client thread] Client side modded connection established
[00:12:20] [Client thread/INFO] [FML/]: send to server
[00:12:20] [Client thread/DEBUG] [FML/]: Overriding dimension: using 0

However, it just doesn't receive the message i want....

It would be appreciated if someone can help me, thanks!

Nothing here, really

1. Did you register msg?

2. If yes, server might not have constructed EntityPlayer for you at time of sending, but I don't remember - try using EntityCOnstruction event to check that.

1.7.10 is no longer supported by forge, you are on your own.

  • Author

Yes.

 

But i don't very understand the relationship between EntityPlayer and SimpleNetworkWrapper...

I supposed..when ClientConnectedToServerEvent is fired, the SimpleNetworkWrapper in LIUtils is ready.

 

The netHandler is created like this:

public static SimpleNetworkWrapper netHandler = NetworkRegistry.INSTANCE.newSimpleChannel("LIUtils");

Nothing here, really

Checked on my own, indeed - communication seems to be impossible before:

[server thread/INFO] [FML]: [server thread] Server side modded connection established

...occurs.

You will probably have to send data elsewhere.

 

Edit:

I'd go with:

1. ServerRequest in PlayerLoggedInEvent

2. Client receives request and sends data.

1.7.10 is no longer supported by forge, you are on your own.

  • Author

Checked on my own, indeed - communication seems to be impossible before:

[server thread/INFO] [FML]: [server thread] Server side modded connection established

...occurs.

You will probably have to send data elsewhere.

 

Edit:

I'd go with:

1. ServerRequest in PlayerLoggedInEvent

2. Client receives request and sends data.

 

The log shown in #1 indicates, "send to server" is after "[server thread] Server side modded connection established".

However... The server doesn't receive that packet.

 

And, your solution means i have to give up sending message just after handshaking?

:( It would be appreciated if i can send that as early as possible...

 

 

 

By the way, I have tried this way:

1. Handle ClientConnectedToServer, and wait for 60ticks (of course, by tickcount and handling ClientTickEvent)

2. Send the packet

3. So, server does receive the packet....

 

But.... ":( It would be appreciated if i can send that as early as possible..."

I mean... just after handshaking, or some way to inject the handshaking procedure?

 

Thanks for everyone's help...

Nothing here, really

  • Author

Why do you need to send things so early?

er... Just do some check, make sure client and server have same script file(a part of mod, but be allowed to be modified by any text editor)

If they mismatched, the player would be kicked

Nothing here, really

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.