Skip to content

Added API to get player's proxy address#10399

Closed
nostalfinals wants to merge 1 commit into
PaperMC:masterfrom
nostalfinals:master
Closed

Added API to get player's proxy address#10399
nostalfinals wants to merge 1 commit into
PaperMC:masterfrom
nostalfinals:master

Conversation

@nostalfinals
Copy link
Copy Markdown
Contributor

Introduction

This patch added an API to get the player's proxy address.
It will be useful if the server uses multiple proxy instances that support HAProxy Protocol (frp, nginx, etc.) and wants to know which proxy instance the player uses.

How?

I added a method, which is Player#getProxyAddress. This method returns an InetSocketAddress, if the server didn't enable Proxy Protocol, or the player didn't connect with an HAProxy instance, then it will return null.

Example

@EventHandler
fun playerJoinEvent(event: PlayerJoinEvent) {
    val player = event.player
    val proxyAddr = player.proxyAddress

    if (proxyAddr == null) {
        logger.info("Player ${player.name} didn't connect with a proxy!")
        return
    }

    logger.info("Player ${player.name} is using proxy: ${proxyAddr.hostString}:${proxyAddr.port}")
}

@nostalfinals nostalfinals requested a review from a team as a code owner April 8, 2024 17:54
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 8, 2024

Please do not open pull requests from the master branch, create a new branch instead.

@github-actions github-actions Bot closed this Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant