sirjonasxx / G-Earth

Cross-platform Habbo packet manipulator
MIT License
92 stars 47 forks source link

Error gearth.protocol.HPacket cannot be converted to java.lang.String #35

Closed sep1 closed 5 years ago

sep1 commented 5 years ago

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

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

sep1 commented 5 years ago

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?

XePeleato commented 5 years ago

Check RoomUserTalk's structure, it doesn't start with a string, so it can't read it or it reads a corrupted one

sep1 commented 5 years ago

mmm, i'm still trying but i dont get it...

XePeleato commented 5 years ago

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();
sep1 commented 5 years ago

Now it's clear! Thank you very much. I appreciate it. ;)