Solved Packet listener - any way to create it before player login?

Discussion in 'Plugin Development' started by Smerfa, May 14, 2014.

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

    Smerfa

    NOTE: I don't want protocolLib, I wan't remove it from my project, because I only listen to one packet just to initialize code.

    So... how to create packet listener but for first packet - login start, I only know how to create listener after player login ;/
     
  2. Offline

    Garris0n

    Out of curiosity, what are you trying to do?
     
  3. Offline

    Smerfa

    I just need that packet listener :D
    I can't do that in other place :<
     
  4. Offline

    Garris0n

    Before the login I don't believe there's any player to listen to. There is the (Async)PlayerPreLoginEvent, but I'm not sure where in the process that's actually triggered. You could look at how ProtocolLib does it or ask the great and all powerful Comphenix, I suppose.
     
  5. Offline

    Smerfa

    They use CGLib, so I also don't want it :p

    PlayerPreLoginEvent is after start packet, and after EncryptionPacket


    So I need any way to listen to new players or... connections
     
  6. Offline

    Comphenix

    It does, but it's only really necessary for pre-1.7.2 servers and MPCP+.

    If you only need to support CraftBukkit 1.7.2, you can take advantage of Netty's extensibility and register your own channel handler. That way, you'll be able to intercept incoming and outgoing packets relatively easily.

    In order to support login packets, you'll have to add your channel handler as early as possible, which is a tad more tricky. So - I've written a set of classes that can be copied directly into your project, and do all the dirty work for you. They can be found here (TinyProtocol and Reflection). You should look at ExamplePlugin for an idea of how to use it.

    Note that the player parameter in onPacketInAsync and onPacketOutAsync will be NULL for those very early login packets. This is because Minecraft hasn't had an opportunity to create the player instance yet - instead, use the Channel object. It can be used as a unique identity (even after the player has been created), and contains useful information such as the remote IP address and port number.
     
    Smerfa and Garris0n like this.
  7. Offline

    xTrollxDudex

    Comphenix
    I really like how you emphasize the NULL, great for preventing NULLpointer exceptions using your code ;)
     
    Comphenix and Garris0n like this.
  8. Offline

    RawCode

    you can hook into netty core and alter anything, but there is no way to do it in single line.
     
    Garris0n likes this.
  9. xTrollxDudex I think he actually does that because he programs more in another language, C~ languages I guess.... :p
     
    xTrollxDudex likes this.
  10. Offline

    RawCode

    for users who like c great option exists - JNI
     
  11. Offline

    Smerfa

Thread Status:
Not open for further replies.

Share This Page