Hydroxocobalamin
Hydroxocobalamin

Reputation: 79

Send "MOTD" to Minecraft client from custom Netty server

I have a basic Netty server (From the tutorial) (http://netty.io/wiki/user-guide-for-4.x.html), and it recieves the requests from the client, but how would I go about sending a string to the client?

For example, on a normal Minecraft server, you specify the "MOTD" in the configuration file, and when a client pings it from the server list, it will display that string. I need to do the same thing, but from my server code.

Upvotes: 2

Views: 1972

Answers (2)

Limnic
Limnic

Reputation: 1876

If you wish to send the MoTD to the client you will have to figure out what gets sent in terms of protocol and data.

For example in the most basic form the data sent could be 1 byte for action (display motd) and then variable length for a string.

If I had to find out how to send this I would go look at the open-source bukkit repositories or the Minecraft Decompiled Code Repository to find out the way to do it myself.

Update: Upon looking at the code it seems that also Minecraft uses Netty, so this plays in your advantage in terms of understanding it. Unfortunately the code is unofficially decompiled and thus obfuscated.

Update 2: I believe the class you should inspect is

net.minecraft.server.PacketStatusOutServerInfo

and the data sent appears to be JSON generated by the ServerPing class.

You can also check out Minecraft Protocol (specifically Ping); a place where modders can find an explanation of protocol & encryption.

Upvotes: 2

user2982130
user2982130

Reputation:

This handler shows the sending of the MOTD:

https://github.com/Bukkit/mc-dev/blob/c1627dc9cc7505581993eb0fa15597cb36e94244/net/minecraft/server/LegacyPingHandler.java

It just happens to be that the MOTD handling goes on line number 69: https://github.com/Bukkit/mc-dev/blob/c1627dc9cc7505581993eb0fa15597cb36e94244/net/minecraft/server/LegacyPingHandler.java/#L69

When the channel receives the ping packet, it encodes the response into a ByteBuf and writes it back out of the channel.

Note that there are a few decompilation errors on the file - ignore them and fix it.

Upvotes: 1

Related Questions