#EOFException problem mod-->plugin
1 messages ยท Page 1 of 1 (latest)
Here is all the information
--- Plugin ---
onPluginMessageReceived: https://paste.md-5.net/ovacusihuk.java
--- Mods ---
Packet: https://paste.md-5.net/apuwibomam.java
InputEvent: https://paste.md-5.net/gujexigiqo.java
PacketHandler (register): https://paste.md-5.net/quwusedase.java
--- Server ---
Error: https://paste.md-5.net/jimadoraze.md
EOFException problem mod-->plugin
I tried with readLine() it works without exception but I get: (ASCII value of the string length + the string)
Try just new String(bytes)
Well, or you can just skip first 2 bytes and construct the message.
Basically this exception just tells you there's something wrong with the way you encode UTF. Can't really tell why exactly, the code you provided delegates the encoding process
Same result as the readLine()
Yes pretty weird, I think I will do that, but is it possible to create my own writeString() with the correct encoding to be decode by readUTF() ?
I have no Forge experience, you should ask someone from their community
Because I think the way I skip the byte and readline, it is the the proper manner of handling packet
I say that because I never see the others plugins do it
Just skipping the length would actually introduce a serious issue if you were programming in lets say C, but here since you're just encoding&decoding an UUID it's okay I guess
You are right, I was speaking when my packet will have several information
Looking at the source the first bytes is a varint for length and the rest is the string
Oh, wait, I see
It seems like Minecraft's PacketBuffer encodes the length into a single byte in this example, while on plugin's side the ByteArrayDataInput#readUTF() reads exactly 2 bytes to determine the length, so it makes sense why the EOF ๐
Thank for your precisions, I have write my own writeString() and instead of this.writeVarInt() i put a writeShort(), and it works !
Well, if you'd need to read/write anything longer, here's a method to read the varint. PacketByteBuf is a netty thing, I believe it's the same your buffer
private static int readVarInt(final PacketByteBuf buf) {
byte cur;
int varInt = 0;
int i = 0;
do {
varInt |= ((cur = buf.readByte()) & 0b0111_1111) << (i++ * 7);
} while ((cur & 0b1000_0000) == 0b1000_0000);
return varInt;
}
Tested with this code, should work ๐
String longStr = Strings.repeat("a", Short.MAX_VALUE / 2);
var longStrBuf = new PacketByteBuf(Unpooled.buffer(longStr.length() + 2));
longStrBuf.writeString(longStr);
int length = readVarInt(longStrBuf);
byte[] bytes = new byte[length];
longStrBuf.readBytes(bytes);
System.out.printf("Read length: %d, actual length: %d\n", length, longStr.length());
System.out.printf("Decoded str equals original: %b\n", new String(bytes).equals(longStr));
PacketByteBuf is for fabric mod not forge right ?
(I develop in 1.16.5 forge)
The bytebuf is part of Mojangs code
It should be called FriendlyByteBuf
And it does contain that readVarInt code