Closed sep1 closed 5 years ago
That's because you're using a HashSupport to send the packet. It takes as the first argument the name or the hash of the packet.
If you want to use the header id, then don't use the HashSupport, or remove the header from the packet and add the hash/name as the first argument of the function.
Thanks! There is another problem. This is the code:
protected void initExtension() {
hashSupport = new HashSupport(this);
hashSupport.intercept(HMessage.Side.TOCLIENT, "RoomUserTalk", this::goSendMessage);
}
private void goSendMessage(HMessage message) {
HPacket packet = message.getPacket();
String speechtext = packet.readString();
sendToServer(new HPacket("{l}{u:280}{s:"+speechtext+"}{i:0}{i:0}"));
}
the speechtext variable return empty. What is the reason?
Check RoomUserTalk's structure, it doesn't start with a string, so it can't read it or it reads a corrupted one
mmm, i'm still trying but i dont get it...
RoomUserTalk: {l}{u:830}{i:6313}{s:whatever}{i:0}{i:0}{i:0}{i:-1}
Don't you see that the string is in the second position? do:
HPacket packet = message.getPacket();
packet.readInteger(); // ADD THIS
String speechtext = packet.readString();
Now it's clear! Thank you very much. I appreciate it. ;)
Hello,
i'm trying to send a packet to the server using this method as suggested here
hashSupport.sendToServer(new HPacket("{l}{u:280}{s:This is a test!}{i:0}{i:0}"));
but i'm getting this error:
gearth.protocol.HPacket cannot be converted to java.lang.String