Jump to content

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


EAirPeter

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

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