Jump to content

[1.8.9] Send custom C01PacketChatMessage to server?


Recommended Posts

Posted (edited)

Hello everyone, thanks for stopping by.

 

I'm working on a mod for Forge 11.15.1.2318. I understand that's very outdated. My goal is to create a client-side-only mod that extends the maximum length you can type in the chat window from 100 characters to 256 characters, as was changed in the 1.11 update for Minecraft. The reasoning for this is that there are multiple Spigot servers which run 1.8.9 with plugins that allow newer versions to connect and, in turn, allow players to send longer messages... but the 1.8.9 client doesn't take advantage of the upgrade, obviously. (oh, and many people play 1.8 on these servers because the combat mechanics are much smoother than the approximations given to the newer clients, but that's a whole other conversation)

 

So with that explanation out of the way, here's what I've done so far:

 

1) I'm intercepting and cancelling a GuiOpenEvent every time the player tries to open chat, and instead opening my own LongGuiChat, where the maximum character length has been raised to 256.

 

2) As ClientChatEvent doesn't exist in 1.8, I've instead resorted to modifying the sendChatMessage(String, boolean) method of my LongGuiChat class. This method executes when the player presses Enter in chat, and from there creates a new C01PacketChatMessage and adds it to the Player's send queue.

 

3) C01PacketChatMessages truncates the String passed to it down to 100 characters in the constructor. There is no publicly accessible method for modifying the String, which left me creating my own LongC01PacketChatMessage, which extends C01PacketChatMessage but has a constructor which truncates messages to 256 characters.

 

At this point I was feeling pretty optimistic about the project so far. I do not claim to be great at Java by any means, so chances are I've already made several obvious mistakes by now... in which case please let me know, I'd love to learn how to improve.

 

But anyway, I tested on a singleplayer world and to my surprise, it actually let me send 256 character messages which even show up in chat. Apparently the server side doesn't actually check the length of the chat packets. I realize now that was just the client adding the message to its own history, not sending it to the client-server. Then I tested on a Spigot server set up as mentioned at the top of this post. I could open chat and type 256 characters, of course, but the moment I hit send (regardless of if I had typed more than 100 characters), I got kicked from the server with an "Internal Exception: io.netty.handler.codec.EncoderException: java.lang.NullPointerException" in the game, and stack traces in the logs. They seem to all lead to the first line of net.minecraft.util.MessageSerializer.encode:

protected void encode(ChannelHandlerContext p_encode_1_, Packet p_encode_2_, ByteBuf p_encode_3_) throws IOException, Exception
{
	Integer integer = ((EnumConnectionState)p_encode_1_.channel().attr(NetworkManager.attrKeyConnectionState).get()).getPacketId(this.direction, p_encode_2_);

 

At first I thought it was crashing at the getPacketId call, although the stack trace ends at the line I just posted, so I suppose it never actually made it that far. And I have no idea what would be throwing up a null pointer exception in the line I just posted. On the chance that I'm wrong, though, here's the getPacketId method:

public Integer getPacketId(EnumPacketDirection direction, Packet packetIn)
{
    return (Integer)((BiMap)this.directionMaps.get(direction)).inverse().get(packetIn.getClass());
}

 

I assume that if the code does make it that far, it will fail anyway because of the "packetIn.getClass()" call being checked against the BiMap... I have a feeling my extension of C01PacketChatMessage will not be in that map, although I may just be misunderstanding how this works.

 

I should probably also mention that my custom code works 100% perfectly if I just replace my LongC01PacketChatMessage with the original C01PacketChatMessage on the line where I add the message packet to the player's send queue. The issue is, apparently, with my custom packet class, even if I do not change a single thing and simply call super() in the constructor.

 

That's where I'm at now. I'm used to being able to implement every feature I've ever wanted to in Forge, given enough time and research, but at this point I'm wondering if maybe I've chosen something that's beyond the realm of possibilities for once. Do any of you folks here have any suggestions, insights, or advice for this problem? I appreciate any time spent reading this thread, and apologize for the wall of text. Thanks in advance!

Edited by Kalman98
Fixed grammar.
Posted

1.8.9 is no longer supported on this forum due to its age.

Please update to a modern version of Minecraft to receive support.

This is my Forum Signature, I am currently attempting to transform it into a small guide for fixing easier issues using spoiler blocks to keep things tidy.

 

As the most common issue I feel I should put this outside the main bulk:

The only official source for Forge is https://files.minecraftforge.net, and the only site I trust for getting mods is CurseForge.

If you use any site other than these, please take a look at the StopModReposts project and install their browser extension, I would also advise running a virus scan.

 

For players asking for assistance with Forge please expand the spoiler below and read the appropriate section(s) in its/their entirety.

  Reveal hidden contents

 

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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