How should I get socket?

Discussion in 'Plugin Development' started by courage322, Jul 20, 2015.

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

    courage322

    Hello everyone!
    I wanna send and recieve some data to the client using plugin, and I should make it into AsyncPlayerPreLoginEvent handler, but I can't get Player/CraftPlayer from this event, that's why I can't get socket which server using to communicate with this client. But socket is already created, so I can't create new TCP connection for this port, it would be easier with UDP, but server using TCP.

    The question is:
    How can I get socket which server using to send/recieve packets for player which isn't connected yet?
     
  2. @courage322 I'm pretty sure the socket code for Bukkit is protected. But you can mess with some packets. @mine-care loves that kind of stuff. I'm sure he can help you.
     
    mine-care likes this.
  3. Offline

    mine-care

    @bwfcwalshy Packetttyy!! :D #GOPACKETS!

    @courage322 Please clear up what you need from packets and i will do my best to help you :D
     
  4. Offline

    xTrollxDudex

    It should be possible to obtain the connection of the player once Login Start is received by the server, however, where the server puts that connection, I am not sure.
     
  5. @courage322
    If you get the MinecraftServer instance, something like CraftServer#getHandle() or CraftServer#getServer(), there is a private/protected field called q which is of type ServerConnection. Within this class at field h is a list of NetworkManager that handle packet stuff. You can compare each networkmanager's IP with that of the PreLoginEvent and then mess around with it (e.g. there's a channel field in NetworkManager, where you can add custom channel handlers to intercept incoming/outgoing data)
     
  6. Or just inject your own handler into the network pipeline. Listen for the packet you need -> do what you want to do.
     
Thread Status:
Not open for further replies.

Share This Page