Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: markustieger <markustieger@gmail.com>
Date: Sun, 17 Sep 2023 15:34:06 +0200
Subject: [PATCH] Replaced the InetAddress with a SocketAddress in
AsyncPlayerPreLoginEvent and PlayerLoginEvent for unix domain socket support


diff --git a/src/main/java/org/bukkit/event/player/AsyncPlayerPreLoginEvent.java b/src/main/java/org/bukkit/event/player/AsyncPlayerPreLoginEvent.java
index fc2d9e85b65347b90bde3b0b13ccae759e33d466..f6b7555012878c398bad562294842ef49d8a859a 100644
--- a/src/main/java/org/bukkit/event/player/AsyncPlayerPreLoginEvent.java
+++ b/src/main/java/org/bukkit/event/player/AsyncPlayerPreLoginEvent.java
@@ -1,6 +1,8 @@
package org.bukkit.event.player;

import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
import java.util.UUID;

import com.destroystokyo.paper.profile.PlayerProfile;
@@ -20,7 +22,7 @@ public class AsyncPlayerPreLoginEvent extends Event {
private net.kyori.adventure.text.Component message; // Paper
//private String name; // Paper - Not used anymore
private final InetAddress ipAddress;
- private final InetAddress rawAddress; // Paper
+ private final java.net.SocketAddress rawSocketAddress; // Paper
//private UUID uniqueId; // Paper - Not used anymore
private final String hostname; // Paper

@@ -59,22 +61,34 @@ public class AsyncPlayerPreLoginEvent extends Event {
*/
@NotNull
public InetAddress getRawAddress() {
- return rawAddress;
+ if (rawSocketAddress instanceof InetSocketAddress inetSocketAddress) return inetSocketAddress.getAddress();
+ return InetAddress.getLoopbackAddress();
+ }
+
+ /**
+ * Gets the raw socket address of the player logging in
+ * @return The socket address
+ */
+ @NotNull
+ public SocketAddress getRawSocketAddress() {
+ return rawSocketAddress;
}
// Paper end

@Deprecated
public AsyncPlayerPreLoginEvent(@NotNull final String name, @NotNull final InetAddress ipAddress, @NotNull final UUID uniqueId, @NotNull PlayerProfile profile) {
- this(name, ipAddress, ipAddress, uniqueId, profile);
+ this(name, ipAddress, new java.net.InetSocketAddress(ipAddress, 0), uniqueId, profile);
}

+ @org.jetbrains.annotations.ApiStatus.Internal // Paper - Use SocketAddress
@Deprecated // Paper - Add hostname
- public AsyncPlayerPreLoginEvent(@NotNull final String name, @NotNull final InetAddress ipAddress, @NotNull final InetAddress rawAddress, @NotNull final UUID uniqueId, @NotNull PlayerProfile profile) {
+ public AsyncPlayerPreLoginEvent(@NotNull final String name, @NotNull final InetAddress ipAddress, @NotNull final java.net.SocketAddress rawSocketAddress, @NotNull final UUID uniqueId, @NotNull PlayerProfile profile) {
// Paper start - Add hostname
- this(name, ipAddress, rawAddress, uniqueId, profile, "");
+ this(name, ipAddress, rawSocketAddress, uniqueId, profile, "");
}

- public AsyncPlayerPreLoginEvent(@NotNull final String name, @NotNull final InetAddress ipAddress, @NotNull final InetAddress rawAddress, @NotNull final UUID uniqueId, @NotNull PlayerProfile profile, @NotNull String hostname) {
+ @org.jetbrains.annotations.ApiStatus.Internal // Paper - Use SocketAddress
+ public AsyncPlayerPreLoginEvent(@NotNull final String name, @NotNull final InetAddress ipAddress, @NotNull final java.net.SocketAddress rawSocketAddress, @NotNull final UUID uniqueId, @NotNull PlayerProfile profile, @NotNull String hostname) {
// Paper end - Add hostname
super(true);
this.profile = profile;
@@ -83,7 +97,7 @@ public class AsyncPlayerPreLoginEvent extends Event {
this.message = net.kyori.adventure.text.Component.empty(); // Paper
//this.name = name; // Paper - Not used anymore
this.ipAddress = ipAddress;
- this.rawAddress = rawAddress; // Paper
+ this.rawSocketAddress = rawSocketAddress; // Paper
//this.uniqueId = uniqueId; // Paper - Not used anymore
this.hostname = hostname; // Paper - Add hostname
}
diff --git a/src/main/java/org/bukkit/event/player/PlayerLoginEvent.java b/src/main/java/org/bukkit/event/player/PlayerLoginEvent.java
index 62fb782baad5c80a3daaa557c0faa674c58a98cf..29a047a6e090beda3701fdb3f6aed21dd2d960df 100644
--- a/src/main/java/org/bukkit/event/player/PlayerLoginEvent.java
+++ b/src/main/java/org/bukkit/event/player/PlayerLoginEvent.java
@@ -1,6 +1,7 @@
package org.bukkit.event.player;

import java.net.InetAddress;
+import java.net.InetSocketAddress;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
@@ -18,7 +19,7 @@ public class PlayerLoginEvent extends PlayerEvent {
private final String hostname;
private Result result = Result.ALLOWED;
private net.kyori.adventure.text.Component message = net.kyori.adventure.text.Component.empty();
- private final InetAddress realAddress; // Spigot
+ private final java.net.SocketAddress realSocketAddress; // Paper

/**
* This constructor defaults message to an empty string, and result to
@@ -28,19 +29,20 @@ public class PlayerLoginEvent extends PlayerEvent {
* @param hostname The hostname that was used to connect to the server
* @param address The address the player used to connect, provided for
* timing issues
- * @param realAddress the actual, unspoofed connecting address
+ * @param realSocketAddress the actual, unspoofed socket address
*/
- public PlayerLoginEvent(@NotNull final Player player, @NotNull final String hostname, @NotNull final InetAddress address, final @NotNull InetAddress realAddress) { // Spigot
+ @org.jetbrains.annotations.ApiStatus.Internal // Paper - Use SocketAddress
+ public PlayerLoginEvent(@NotNull final Player player, @NotNull final String hostname, @NotNull final InetAddress address, final @NotNull java.net.SocketAddress realSocketAddress) { // Paper
super(player);
this.hostname = hostname;
this.address = address;
- // Spigot start
- this.realAddress = realAddress;
+ // Paper start
+ this.realSocketAddress = realSocketAddress;
}

public PlayerLoginEvent(@NotNull final Player player, @NotNull final String hostname, @NotNull final InetAddress address) {
- this(player, hostname, address, address);
- // Spigot end
+ this(player, hostname, address, new java.net.InetSocketAddress(address, 0));
+ // Paper end
}

/**
@@ -52,12 +54,12 @@ public class PlayerLoginEvent extends PlayerEvent {
* timing issues
* @param result The result status for this event
* @param message The message to be displayed if result denies login
- * @param realAddress the actual, unspoofed connecting address
- * @deprecated in favour of {@link #PlayerLoginEvent(Player, String, InetAddress, Result, net.kyori.adventure.text.Component, InetAddress)}
+ * @param realSocketAddress the actual, unspoofed socket address
+ * @deprecated in favour of {@link #PlayerLoginEvent(Player, String, InetAddress, Result, net.kyori.adventure.text.Component, java.net.SocketAddress)}
*/
@Deprecated // Paper
- public PlayerLoginEvent(@NotNull final Player player, @NotNull String hostname, @NotNull final InetAddress address, @NotNull final Result result, @NotNull final String message, @NotNull final InetAddress realAddress) { // Spigot
- this(player, hostname, address, realAddress); // Spigot
+ public PlayerLoginEvent(@NotNull final Player player, @NotNull String hostname, @NotNull final InetAddress address, @NotNull final Result result, @NotNull final String message, @NotNull final java.net.SocketAddress realSocketAddress) { // Paper
+ this(player, hostname, address, realSocketAddress); // Spigot
this.result = result;
this.message = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(message); // Paper
}
@@ -72,10 +74,10 @@ public class PlayerLoginEvent extends PlayerEvent {
* timing issues
* @param result The result status for this event
* @param message The message to be displayed if result denies login
- * @param realAddress the actual, unspoofed connecting address
+ * @param realAddress the actual, unspoofed socket address
*/
- public PlayerLoginEvent(@NotNull final Player player, @NotNull String hostname, @NotNull final InetAddress address, @NotNull final Result result, @NotNull final net.kyori.adventure.text.Component message, @NotNull final InetAddress realAddress) { // Spigot
- this(player, hostname, address, realAddress); // Spigot
+ public PlayerLoginEvent(@NotNull final Player player, @NotNull String hostname, @NotNull final InetAddress address, @NotNull final Result result, @NotNull final net.kyori.adventure.text.Component message, @NotNull final java.net.SocketAddress realAddress) { // Paper
+ this(player, hostname, address, realAddress); // Paper
this.result = result;
this.message = message;
}
@@ -100,7 +102,7 @@ public class PlayerLoginEvent extends PlayerEvent {
}
// Paper end

- // Spigot start
+ // Paper start
/**
* Gets the connection address of this player, regardless of whether it has been spoofed or not.
*
@@ -108,9 +110,20 @@ public class PlayerLoginEvent extends PlayerEvent {
*/
@NotNull
public InetAddress getRealAddress() {
- return realAddress;
+ if (realSocketAddress instanceof InetSocketAddress inetSocketAddress) return inetSocketAddress.getAddress();
+ return InetAddress.getLoopbackAddress();
}
- // Spigot end
+
+ /**
+ * Gets the socket address of this player, regardless of whether it has been spoofed or not.
+ *
+ * @return the player's socket address
+ */
+ @NotNull
+ public java.net.SocketAddress getRealSocketAddress() {
+ return realSocketAddress;
+ }
+ // Paper end

/**
* Gets the current result of the login, as an enum
33 changes: 33 additions & 0 deletions patches/server/0609-Add-Unix-domain-socket-support.patch
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ For Windows and ARM support, JEP-380 is required:
https://inside.java/2021/02/03/jep380-unix-domain-sockets-channels/
This will be possible as of the Minecraft 1.17 Java version bump.

Co-authored-by: MarkusTieger <markustieger@gmail.com>
Tested-by: Mariell Hoversholm <proximyst@proximyst.com>
Reviewed-by: Mariell Hoversholm <proximyst@proximyst.com>

Expand Down Expand Up @@ -139,3 +140,35 @@ index 50c79be12cf8778a2ce451a8c9bb2cdc277d6830..8393c1a2d15d5ad255c9808b0d0edd6a
connection.spoofedUUID = com.mojang.util.UUIDTypeAdapter.fromString( split[2] );
} else
{
diff --git a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
index b026c003e1fc02a9ea426f3126acb788fc09a874..02300b675ef2d6c48b45d05b248b6a604c7f334a 100644
--- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
@@ -331,13 +331,12 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
public void fireEvents() throws Exception {
String playerName = ServerLoginPacketListenerImpl.this.gameProfile.getName();
java.net.InetAddress address = ((java.net.InetSocketAddress) ServerLoginPacketListenerImpl.this.connection.getRemoteAddress()).getAddress();
- java.net.InetAddress rawAddress = ((java.net.InetSocketAddress) connection.channel.remoteAddress()).getAddress(); // Paper
java.util.UUID uniqueId = ServerLoginPacketListenerImpl.this.gameProfile.getId();
final org.bukkit.craftbukkit.CraftServer server = ServerLoginPacketListenerImpl.this.server.server;

// Paper start
com.destroystokyo.paper.profile.PlayerProfile profile = com.destroystokyo.paper.profile.CraftPlayerProfile.asBukkitMirror(ServerLoginPacketListenerImpl.this.gameProfile);
- AsyncPlayerPreLoginEvent asyncEvent = new AsyncPlayerPreLoginEvent(playerName, address, rawAddress, uniqueId, profile); // Paper - add rawAddress
+ AsyncPlayerPreLoginEvent asyncEvent = new AsyncPlayerPreLoginEvent(playerName, address, connection.channel.remoteAddress(), uniqueId, profile); // Paper
server.getPluginManager().callEvent(asyncEvent);
profile = asyncEvent.getPlayerProfile();
profile.complete(true); // Paper - setPlayerProfileAPI
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index 3dbad6f9ea70db07a9bfa199b28def6a67353d80..857087895bc36a924105a3ef7c35ba9d68f5f03d 100644
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -688,7 +688,7 @@ public abstract class PlayerList {

ServerPlayer entity = new ServerPlayer(this.server, this.server.getLevel(Level.OVERWORLD), gameprofile);
Player player = entity.getBukkitEntity();
- PlayerLoginEvent event = new PlayerLoginEvent(player, loginlistener.connection.hostname, ((java.net.InetSocketAddress) socketaddress).getAddress(), ((java.net.InetSocketAddress) loginlistener.connection.channel.remoteAddress()).getAddress());
+ PlayerLoginEvent event = new PlayerLoginEvent(player, loginlistener.connection.hostname, ((java.net.InetSocketAddress) socketaddress).getAddress(), loginlistener.connection.channel.remoteAddress()); // Paper

// Paper start - Fix MC-158900
UserBanListEntry gameprofilebanentry;
2 changes: 1 addition & 1 deletion patches/server/0615-Add-PlayerKickEvent-causes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ index 967ed1f44a4d7c97a14d9415541df000698e8aad..08a69f7a2d153aee1b9637085be04d30

}
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index 3dbad6f9ea70db07a9bfa199b28def6a67353d80..77d80170cabc358c75d58ac7ff19054ba6b7617f 100644
index 857087895bc36a924105a3ef7c35ba9d68f5f03d..51ea06b2018400297beb6d071303f74487bd4d2d 100644
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -678,7 +678,7 @@ public abstract class PlayerList {
Expand Down
2 changes: 1 addition & 1 deletion patches/server/0650-Add-PlayerSetSpawnEvent.patch
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ index eaa1b300870f3bbf5a34cb99e6af116b7c244628..59e02bd5b49e0c900d049a1f1927316d

public void trackChunk(ChunkPos chunkPos, Packet<?> chunkDataPacket) {
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index c8e38ed5e14fb137a7d169c57bc58bdf4421e0cc..c3fb1bbc0e2a44160e86b5bb4ab88f78991fa9e6 100644
index 3f09fb0a628fd0ef7295d2675178876d77ec4f77..d92582178f1806d6dc14a5d446276865daba3846 100644
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -860,7 +860,7 @@ public abstract class PlayerList {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,7 @@ index 52dba7fad11a7280137ade67983e594487e20891..50f6a044385c22336e799efe471ab65e
}
}
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index ffa831673805201932c36b814f4439f3bb5c4c04..64e40e3caa85bff9382a483237301a8f231d1991 100644
index 3e24db6a0d087fc62066bb148150b68a6f5e7d55..915258f3ac51c5472503ddb49addb95c67487cd1 100644
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -895,7 +895,7 @@ public abstract class PlayerList {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ Subject: [PATCH] Added getHostname to AsyncPlayerPreLoginEvent


diff --git a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
index cd4e76fe5b79c7d9e615b4886a568c74db757436..3fcd7bfdb8945b276c94a263e9da6b85ce470366 100644
index 70a768724d43680b4965bbea8a286a546eb73f78..b314967a302279fa07724d21b2d9d1947dbc045f 100644
--- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
@@ -371,7 +371,7 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
@@ -370,7 +370,7 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,

// Paper start
com.destroystokyo.paper.profile.PlayerProfile profile = com.destroystokyo.paper.profile.CraftPlayerProfile.asBukkitMirror(ServerLoginPacketListenerImpl.this.gameProfile);
- AsyncPlayerPreLoginEvent asyncEvent = new AsyncPlayerPreLoginEvent(playerName, address, rawAddress, uniqueId, profile); // Paper - add rawAddress
+ AsyncPlayerPreLoginEvent asyncEvent = new AsyncPlayerPreLoginEvent(playerName, address, rawAddress, uniqueId, profile, ServerLoginPacketListenerImpl.this.connection.hostname); // Paper - add rawAddress & hostname
- AsyncPlayerPreLoginEvent asyncEvent = new AsyncPlayerPreLoginEvent(playerName, address, connection.channel.remoteAddress(), uniqueId, profile); // Paper
+ AsyncPlayerPreLoginEvent asyncEvent = new AsyncPlayerPreLoginEvent(playerName, address, connection.channel.remoteAddress(), uniqueId, profile, ServerLoginPacketListenerImpl.this.connection.hostname); // Paper
server.getPluginManager().callEvent(asyncEvent);
profile = asyncEvent.getPlayerProfile();
profile.complete(true); // Paper - setPlayerProfileAPI
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Subject: [PATCH] Use username instead of display name in


diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index b56a7067faafb687ff5d529b1d4a40c1e15b2ea2..815eb218b6612b13c6deff636509bad35eeace62 100644
index 69ac5d4c6364a64e8fb83f2417987ef4050932b2..175d481981a2a04f065638bfa79057886d58d3a7 100644
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -1430,7 +1430,7 @@ public abstract class PlayerList {
Expand Down
Loading