Page 1 of 1

Playing with packets and phx...

Posted: Thu Jul 01, 2010 10:14 am
by Pere
I have added this line to ExBrExtraUserInfo:
writeS(getClient().getActiveChar().getName());

What do you think that this should send to my client? Of course, my character name!
But no, sometimes (only sometimes) it sends me the name of the character that sent me his charinfo!!!

How the hell can I receive a packet whose getClient() is not my client??

It is very strange, no need to know but I'm very curious :S

Re: Playing with packets and phx...

Posted: Thu Jul 01, 2010 10:41 am
by janiii
because the packet is broadcasted also to other players around you? you broadcast the packet, so the players will get the packet with your info.

Re: Playing with packets and phx...

Posted: Thu Jul 01, 2010 11:22 am
by Pere
In the packet's class, if you do getClient() (the same than this.getClient(), so packet.getClient()) you are getting the client which will receive the packet.. as far as I know -_-

I want this to get if the packet receiver is GM, to send him different title colors depending on character's things like being clan leader or not.. but sometimes the GM receives the info like he was a player. And then, "debugging" with the method that I told in the post above, I've got that.

Re: Playing with packets and phx...

Posted: Thu Jul 01, 2010 11:39 am
by janiii
ExBrExtraUserInfo is a server packet. you give the packet parameter with a l2pcinstance, but you broadcast it to other players too.

Re: Playing with packets and phx...

Posted: Thu Jul 01, 2010 11:49 am
by JIV
it dont work that way :) i dont recommend you using getClient() for SendablePacket if its sended to multiple users. Simple workaround - send to each player new packet.

Re: Playing with packets and phx...

Posted: Thu Jul 01, 2010 12:08 pm
by Pere
uh lol true!
thank you for opening my eyes ^^

Re: Playing with packets and phx...

Posted: Thu Jul 01, 2010 9:19 pm
by JIV
checked again and it looks like mmocore implementation mistake..
try: http://pastebin.com/sn2JPTg8 should fix issue.

Re: Playing with packets and phx...

Posted: Fri Jul 02, 2010 6:20 pm
by Pere
I'm wondering why is this commented... maybe too risky to uncomment xD

Re: Playing with packets and phx...

Posted: Sat Jul 03, 2010 8:13 am
by Pere
Forget about my last comment, thank you so much ;D

Re: Playing with packets and phx...

Posted: Sat Jul 03, 2010 8:27 am
by JIV
its working now?

Re: Playing with packets and phx...

Posted: Sat Jul 03, 2010 8:51 am
by Pere
could not test yet, I must restart more than 1 server to change a lib u.U

Re: Playing with packets and phx...

Posted: Sat Jul 03, 2010 9:57 am
by Pere
Tested, and was a total mess to comment the first setclient! It caused too many nullpointers in the packet handlers, like creaturesay or enterworld.
I've uncommented this and now everything seems to work perfectly, even with broadcasted packets! ^^
I'd suggest a commit for the SelectorThread part.

Re: Playing with packets and phx...

Posted: Sat Jul 03, 2010 10:37 am
by JIV
its not safe either :) patch is wrong, cause getClient is used promary for runImpl() and when you change it during write it can fail there. maybe create new getWriteClient(), active client during white.

Re: Playing with packets and phx...

Posted: Sat Jul 03, 2010 6:54 pm
by Pere
And what about only setting it to the current write client and then not setting to null?
..well, indeed this is really dirty, we/I should create another variable better to get the client in write processes.

EDIT: here the patch if anyone is interested or you want to commit

Code: Select all

Index: src/org/mmocore/network/AbstractPacket.java===================================================================--- src/org/mmocore/network/AbstractPacket.java	(revision 4322)+++ src/org/mmocore/network/AbstractPacket.java	(working copy)@@ -28,9 +28,15 @@     protected ByteBuffer _buf;      T _client;+    T _writeClient;      public final T getClient()     {         return _client;     }++    public final T getWriteClient()+    {+        return _writeClient;+    } }Index: src/org/mmocore/network/SelectorThread.java===================================================================--- src/org/mmocore/network/SelectorThread.java	(revision 4322)+++ src/org/mmocore/network/SelectorThread.java	(working copy)@@ -565,12 +565,16 @@         final int dataPos = headerPos + HEADER_SIZE;         WRITE_BUFFER.position(dataPos); +        // set client+        sp._writeClient = client;         // set the write buffer         sp._buf = WRITE_BUFFER;         // write content to buffer         sp.write();         // delete the write buffer         sp._buf = null;+        // release client+        sp._writeClient = null;          // size (inclusive header)         int dataSize = WRITE_BUFFER.position() - dataPos;