SPIGOT-7171: Ability to get the IP/hostname players are requesting status of

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot 2022-10-28 20:19:11 +11:00
parent a8d96f30a4
commit 814c67ace8
5 changed files with 25 additions and 29 deletions

View file

@ -1,6 +1,14 @@
--- a/net/minecraft/network/NetworkManager.java
+++ b/net/minecraft/network/NetworkManager.java
@@ -164,7 +164,7 @@
@@ -84,6 +84,7 @@
private float averageSentPackets;
private int tickCount;
private boolean handlingFault;
+ public String hostname = ""; // CraftBukkit - add field
public NetworkManager(EnumProtocolDirection enumprotocoldirection) {
this.receiving = enumprotocoldirection;
@@ -164,7 +165,7 @@
}
private static <T extends PacketListener> void genericsFtw(Packet<T> packet, PacketListener packetlistener) {
@ -9,7 +17,7 @@
}
public void setListener(PacketListener packetlistener) {
@@ -289,7 +289,7 @@
@@ -289,7 +290,7 @@
public void disconnect(IChatBaseComponent ichatbasecomponent) {
if (this.channel.isOpen()) {

View file

@ -18,7 +18,11 @@
private static final IChatBaseComponent IGNORE_STATUS_REASON = IChatBaseComponent.literal("Ignoring status request");
private final MinecraftServer server;
private final NetworkManager connection;
@@ -26,6 +35,40 @@
@@ -23,9 +32,44 @@
@Override
public void handleIntention(PacketHandshakingInSetProtocol packethandshakinginsetprotocol) {
+ this.connection.hostname = packethandshakinginsetprotocol.hostName + ":" + packethandshakinginsetprotocol.port; // CraftBukkit - set hostname
switch (packethandshakinginsetprotocol.getIntention()) {
case LOGIN:
this.connection.setProtocol(EnumProtocol.LOGIN);
@ -59,11 +63,3 @@
if (packethandshakinginsetprotocol.getProtocolVersion() != SharedConstants.getCurrentVersion().getProtocolVersion()) {
IChatMutableComponent ichatmutablecomponent;
@@ -39,6 +82,7 @@
this.connection.disconnect(ichatmutablecomponent);
} else {
this.connection.setListener(new LoginListener(this.server, this.connection));
+ ((LoginListener) this.connection.getPacketListener()).hostname = packethandshakinginsetprotocol.hostName + ":" + packethandshakinginsetprotocol.port; // CraftBukkit - set hostname
}
break;
case STATUS:

View file

@ -13,15 +13,7 @@
public class LoginListener implements TickablePacketListener, PacketLoginInListener {
private static final AtomicInteger UNIQUE_THREAD_ID = new AtomicInteger(0);
@@ -59,6 +65,7 @@
private EntityPlayer delayedAcceptPlayer;
@Nullable
private ProfilePublicKey.a profilePublicKeyData;
+ public String hostname = ""; // CraftBukkit - add field
public LoginListener(MinecraftServer minecraftserver, NetworkManager networkmanager) {
this.state = LoginListener.EnumProtocolState.HELLO;
@@ -88,6 +95,13 @@
@@ -88,6 +94,13 @@
}
@ -35,13 +27,13 @@
@Override
public NetworkManager getConnection() {
return this.connection;
@@ -123,10 +137,12 @@
@@ -123,10 +136,12 @@
}
}
- IChatBaseComponent ichatbasecomponent = this.server.getPlayerList().canPlayerLogin(this.connection.getRemoteAddress(), this.gameProfile);
+ // CraftBukkit start - fire PlayerLoginEvent
+ EntityPlayer s = this.server.getPlayerList().canPlayerLogin(this, this.gameProfile, profilepublickey, hostname);
+ EntityPlayer s = this.server.getPlayerList().canPlayerLogin(this, this.gameProfile, profilepublickey);
- if (ichatbasecomponent != null) {
- this.disconnect(ichatbasecomponent);
@ -51,7 +43,7 @@
} else {
this.state = LoginListener.EnumProtocolState.ACCEPTED;
if (this.server.getCompressionThreshold() >= 0 && !this.connection.isMemoryConnection()) {
@@ -139,7 +155,7 @@
@@ -139,7 +154,7 @@
EntityPlayer entityplayer = this.server.getPlayerList().getPlayer(this.gameProfile.getId());
try {
@ -60,7 +52,7 @@
if (entityplayer != null) {
this.state = LoginListener.EnumProtocolState.DELAY_ACCEPT;
@@ -188,7 +204,7 @@
@@ -188,7 +203,7 @@
public void handleHello(PacketLoginInStart packetlogininstart) {
Validate.validState(this.state == LoginListener.EnumProtocolState.HELLO, "Unexpected hello packet", new Object[0]);
Validate.validState(isValidUsername(packetlogininstart.name()), "Invalid characters in username", new Object[0]);
@ -69,7 +61,7 @@
GameProfile gameprofile = this.server.getSingleplayerProfile();
if (gameprofile != null && packetlogininstart.name().equalsIgnoreCase(gameprofile.getName())) {
@@ -249,6 +265,43 @@
@@ -249,6 +264,43 @@
try {
LoginListener.this.gameProfile = LoginListener.this.server.getSessionService().hasJoinedServer(new GameProfile((UUID) null, gameprofile.getName()), s, this.getAddress());
if (LoginListener.this.gameProfile != null) {
@ -113,7 +105,7 @@
LoginListener.LOGGER.info("UUID of player {} is {}", LoginListener.this.gameProfile.getName(), LoginListener.this.gameProfile.getId());
LoginListener.this.state = LoginListener.EnumProtocolState.READY_TO_ACCEPT;
} else if (LoginListener.this.server.isSingleplayer()) {
@@ -268,6 +321,11 @@
@@ -268,6 +320,11 @@
LoginListener.this.disconnect(IChatBaseComponent.translatable("multiplayer.disconnect.authservers_down"));
LoginListener.LOGGER.error("Couldn't verify username because servers are unavailable");
}

View file

@ -32,7 +32,7 @@
+ CraftIconCache icon = server.server.getServerIcon();
+
+ ServerListPingEvent() {
+ super(((InetSocketAddress) connection.getRemoteAddress()).getAddress(), server.getMotd(), server.previewsChat(), server.getPlayerList().getMaxPlayers());
+ super(connection.hostname, ((InetSocketAddress) connection.getRemoteAddress()).getAddress(), server.getMotd(), server.previewsChat(), server.getPlayerList().getMaxPlayers());
+ }
+
+ @Override

View file

@ -317,7 +317,7 @@
- @Nullable
- public IChatBaseComponent canPlayerLogin(SocketAddress socketaddress, GameProfile gameprofile) {
+ // CraftBukkit start - Whole method, SocketAddress to LoginListener, added hostname to signature, return EntityPlayer
+ public EntityPlayer canPlayerLogin(LoginListener loginlistener, GameProfile gameprofile, ProfilePublicKey profilepublickey, String hostname) {
+ public EntityPlayer canPlayerLogin(LoginListener loginlistener, GameProfile gameprofile, ProfilePublicKey profilepublickey) {
IChatMutableComponent ichatmutablecomponent;
- if (this.bans.isBanned(gameprofile)) {
@ -349,7 +349,7 @@
+
+ EntityPlayer entity = new EntityPlayer(this.server, this.server.getLevel(World.OVERWORLD), gameprofile, profilepublickey);
+ Player player = entity.getBukkitEntity();
+ PlayerLoginEvent event = new PlayerLoginEvent(player, hostname, ((java.net.InetSocketAddress) socketaddress).getAddress());
+ PlayerLoginEvent event = new PlayerLoginEvent(player, loginlistener.connection.hostname, ((java.net.InetSocketAddress) socketaddress).getAddress());
+
+ if (getBans().isBanned(gameprofile) && !getBans().get(gameprofile).hasExpired()) {
GameProfileBanEntry gameprofilebanentry = (GameProfileBanEntry) this.bans.get(gameprofile);