Solved How would I get the domain a player is using to ping the server?

Discussion in 'Spigot Plugin Development' started by retrodaredevil, May 16, 2016.

  1. I would like to change the motd with ServerListPingEvent based on the domain a player is using to ping the server. I can do different things when a player joins based on that shown here: https://www.spigotmc.org/threads/getting-the-domain-a-player-used-to-log-in.68416/ but I would like to be able to get the address in the ping event.

    I looked at the javadoc and the only thing I could find is getAddress() which I don't think would work.

    Since there doesn't seem to be anything in the javadoc for this, how would I do this?

    Javadoc: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/server/ServerListPingEvent.html
     
    #1 retrodaredevil, May 16, 2016
    Last edited: May 17, 2016
  2.  
  3. getAddress returns the ip of the client (or an object to get that) Say a player typed in play.myserver.com and logged into that. I want to know what domain the player is connecting to.
     
  4. Ah, fair enough, I interpreted "the domain the player is using to ping the server" as "the domain of the player". Not sure how one would go about doing that, as I have not needed to use it.
     
    • Agree Agree x 1
  5. I'm not really sure how I would change some of that code to make it listen for when players ping the server. Is there a packet I can listen for or something simpler? I haven't messed with reflection and the only thing I've used nms for is sending packets.
     
  6. Check this out, according to this the client includes the hostname/port information when it sends the Handshake packet to the server:
    http://wiki.vg/Protocol#Serverbound

    ideally, you wouldn't have to use nms, you could just use ProtocolLib to grab the information you need, because the information in the event seems to be insufficient. But if ProtocolLib isn't an option, then injecting netty will do the same thing, but would require some extra knowledge of packets.
     
    • Useful Useful x 1
  7. I looked at that I can't figure out what packet type to listen for. I looked at the javadoc and pressed CTRL+space way too many times.

    EDIT: I listened for a HandshakingInSetProtocol packet with PacketListenerAPI then got the domain from the field called hostname then stored that variable and listened for PacketStatusOutServerInfo and changed the motd of that. (I could probably use a ServerListPingEvent but I already had the code set up to change the ping with that.
    If anyone needs the code in the future please send me a PM. I'd be happy to help.
     
    #9 retrodaredevil, May 17, 2016
    Last edited: May 17, 2016