Listening for custom packets

Discussion in 'Plugin Development' started by _Filip, Nov 3, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    _Filip

    How would I create my own listener for packets?
    I don't know where to start, I looked at the protocolLib code, but that didn't help,
    I know a bit about sockets, and listening for information, but that's about it.
    And if you can't create a listener, can you intercept the packets, read the information, then send it through?
     
  2. Offline

    1Rogue

    Why not just use ProtocolLib itself?
     
  3. Offline

    _Filip

    1Rogue I'm really just experimenting.
     
  4. Offline

    Axe2760

  5. Offline

    _Filip

    Axe2760 interesting, thanks!
    Now do you know how to listen for already existing packets?
     
  6. Offline

    Axe2760

    swampshark19 I'd pretty much go with 1Rogue said, ProtocolLib. I'd have no idea, sorry. :p
     
  7. Offline

    Coelho

    If you're just experimenting, use ProtocolLib, otherwise you're just wasting your time. If you have the option to, I recommend using plugin channels.

    If you want to delve into the depths, in 1.6.4 and the fake 1.7.2 builds, you can just make a ProxyPlayerConnection and intercept the method that reads the packet.
     
  8. Offline

    _Filip

    Coelho
    Would I have to use reflection to get ProxyPlayerConnection?
     
  9. Offline

    Coelho

    You probably would need to.
     
  10. swampshark19 There are a few way to make this possible.
    The first way: proxy the player networkmanager and override the queue method. You will have to set your network proxy to every new player that joins. This is considered to be the most easy way. (You also need to override some other methods but Im on my phone now so I can't look them up that quick)

    The second way is by making a proxy class for each packet and register them in the Packet class, also fairly easy but a lot of work.

    Then there is another way that takes some more effort but I am not going to announce this here as I am experimentating with this)

    Those are the 3 ways I know of. I think the easiest thing would be to just create proxy objects for each packet you want, because proxying the playerConnection is a bit dangerous. (Injecting your own proxy packets is too but the chance of failure is lower).
    To end my answer, if I were you I would just use ProtocolLib since it is just the best tool out there. Also when creating your own method to do this you still would have to check if protocollib is present because else you will break it.

    swampshark19 About the use reflection to get the proxy stuff. No, you have to make it yourself and then use reflection to inject it into the EntityPlayer.

    Coelho Oh I found an answer by the packet master (@Comphenix) himself: https://forums.bukkit.org/threads/h...endpacket-packet-no-libs.127365/#post-1534849 , I said you have to override the queue method. Forget that, the queue method is used to queue outgoing packets. You have to override the handle methods.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
Thread Status:
Not open for further replies.

Share This Page