3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-15 02:50:09 +01:00

Implements PlayerHandshakeEvent#getOriginalSocketAddressHostname and deprecates PlayerHandshakeEvent(String, boolean) in favour of PlayerHandshakeEvent(String, String, boolean)

Dieser Commit ist enthalten in:
Paul Zhang 2021-02-23 16:47:06 +01:00 committet von Mariell Hoversholm
Ursprung 6fab1ee3aa
Commit 5d779a6212
4 geänderte Dateien mit 40 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -7,10 +7,10 @@ Subject: [PATCH] Add handshake event to allow plugins to handle client
diff --git a/src/main/java/com/destroystokyo/paper/event/player/PlayerHandshakeEvent.java b/src/main/java/com/destroystokyo/paper/event/player/PlayerHandshakeEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..d67dade3af3fb0f8b7e5c267087abf6320b433e7
index 0000000000000000000000000000000000000000..2f9412e0ba177f1e23befd64681a4a5a1994563d
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/player/PlayerHandshakeEvent.java
@@ -0,0 +1,248 @@
@@ -0,0 +1,277 @@
+package com.destroystokyo.paper.event.player;
+
+import net.kyori.adventure.text.Component;
@ -37,6 +37,7 @@ index 0000000000000000000000000000000000000000..d67dade3af3fb0f8b7e5c267087abf63
+
+ private static final HandlerList HANDLERS = new HandlerList();
+ @NotNull private final String originalHandshake;
+ @NotNull private final String originalSocketAddressHostname;
+ private boolean cancelled;
+ @Nullable private String serverHostname;
+ @Nullable private String socketAddressHostname;
@ -50,10 +51,25 @@ index 0000000000000000000000000000000000000000..d67dade3af3fb0f8b7e5c267087abf63
+ *
+ * @param originalHandshake the original handshake string
+ * @param cancelled if this event is enabled
+ *
+ * @deprecated in favour of {@link PlayerHandshakeEvent(String, String, boolean)}
+ */
+ @Deprecated
+ public PlayerHandshakeEvent(@NotNull String originalHandshake, boolean cancelled) {
+ this(originalHandshake, "127.0.0.1", cancelled);
+ }
+
+ /**
+ * Creates a new {@link PlayerHandshakeEvent}.
+ *
+ * @param originalHandshake the original handshake string
+ * @param originalSocketAddressHostname the original socket address hostname
+ * @param cancelled if this event is enabled
+ */
+ public PlayerHandshakeEvent(@NotNull String originalHandshake, @NotNull String originalSocketAddressHostname, boolean cancelled) {
+ super(true);
+ this.originalHandshake = originalHandshake;
+ this.originalSocketAddressHostname = originalSocketAddressHostname;
+ this.cancelled = cancelled;
+ }
+
@ -94,6 +110,19 @@ index 0000000000000000000000000000000000000000..d67dade3af3fb0f8b7e5c267087abf63
+ }
+
+ /**
+ * Gets the original socket address hostname.
+ *
+ * <p>This does not include the port.</p>
+ * <p>In cases where this event is manually fired and the plugin wasn't updated yet, the default is {@code "127.0.0.1"}.</p>
+ *
+ * @return the original socket address hostname
+ */
+ @NotNull
+ public String getOriginalSocketAddressHostname() {
+ return this.originalSocketAddressHostname;
+ }
+
+ /**
+ * Gets the server hostname string.
+ *
+ * <p>This should not include the port.</p>

Datei anzeigen

@ -6,7 +6,7 @@ Subject: [PATCH] Add handshake event to allow plugins to handle client
diff --git a/src/main/java/net/minecraft/server/HandshakeListener.java b/src/main/java/net/minecraft/server/HandshakeListener.java
index 69fd0a7b230c6f6eb46a43477465f77b265cc3c9..4de8646811f25b6217cffcd31fc14bcf79151b1a 100644
index 69fd0a7b230c6f6eb46a43477465f77b265cc3c9..bad5d4f165d1e469ed583b036f78e467b94691fd 100644
--- a/src/main/java/net/minecraft/server/HandshakeListener.java
+++ b/src/main/java/net/minecraft/server/HandshakeListener.java
@@ -14,7 +14,7 @@ public class HandshakeListener implements PacketHandshakingInListener {
@ -18,7 +18,7 @@ index 69fd0a7b230c6f6eb46a43477465f77b265cc3c9..4de8646811f25b6217cffcd31fc14bcf
public HandshakeListener(MinecraftServer minecraftserver, NetworkManager networkmanager) {
this.b = minecraftserver;
@@ -73,8 +73,33 @@ public class HandshakeListener implements PacketHandshakingInListener {
@@ -73,8 +73,34 @@ public class HandshakeListener implements PacketHandshakingInListener {
this.c.close(chatmessage);
} else {
this.c.setPacketListener(new LoginListener(this.b, this.c));
@ -27,7 +27,8 @@ index 69fd0a7b230c6f6eb46a43477465f77b265cc3c9..4de8646811f25b6217cffcd31fc14bcf
+ boolean handledByEvent = false;
+ // Try and handle the handshake through the event
+ if (com.destroystokyo.paper.event.player.PlayerHandshakeEvent.getHandlerList().getRegisteredListeners().length != 0) { // Hello? Can you hear me?
+ com.destroystokyo.paper.event.player.PlayerHandshakeEvent event = new com.destroystokyo.paper.event.player.PlayerHandshakeEvent(packethandshakinginsetprotocol.hostname, !proxyLogicEnabled);
+ java.net.InetSocketAddress socketAddress = (java.net.InetSocketAddress) this.getNetworkManager().socketAddress;
+ com.destroystokyo.paper.event.player.PlayerHandshakeEvent event = new com.destroystokyo.paper.event.player.PlayerHandshakeEvent(packethandshakinginsetprotocol.hostname, socketAddress.getAddress().getHostAddress(), !proxyLogicEnabled);
+ if (event.callEvent()) {
+ // If we've failed somehow, let the client know so and go no further.
+ if (event.isFailed()) {
@ -38,7 +39,7 @@ index 69fd0a7b230c6f6eb46a43477465f77b265cc3c9..4de8646811f25b6217cffcd31fc14bcf
+ }
+
+ if (event.getServerHostname() != null) packethandshakinginsetprotocol.hostname = event.getServerHostname();
+ if (event.getSocketAddressHostname() != null) this.getNetworkManager().socketAddress = new java.net.InetSocketAddress(event.getSocketAddressHostname(), ((java.net.InetSocketAddress) this.getNetworkManager().getSocketAddress()).getPort());
+ if (event.getSocketAddressHostname() != null) this.getNetworkManager().socketAddress = new java.net.InetSocketAddress(event.getSocketAddressHostname(), socketAddress.getPort());
+ this.getNetworkManager().spoofedUUID = event.getUniqueId();
+ this.getNetworkManager().spoofedProfile = gson.fromJson(event.getPropertiesJson(), com.mojang.authlib.properties.Property[].class);
+ handledByEvent = true; // Hooray, we did it!

Datei anzeigen

@ -61,10 +61,10 @@ index 0000000000000000000000000000000000000000..5caca6439d2135e34880d501397fe2ea
+
+}
diff --git a/src/main/java/net/minecraft/server/HandshakeListener.java b/src/main/java/net/minecraft/server/HandshakeListener.java
index 4de8646811f25b6217cffcd31fc14bcf79151b1a..6d9080abb63a6d13d1184ff6949ba86a470ea390 100644
index bad5d4f165d1e469ed583b036f78e467b94691fd..89a83253c99c387e1c91c434952c549d598b11aa 100644
--- a/src/main/java/net/minecraft/server/HandshakeListener.java
+++ b/src/main/java/net/minecraft/server/HandshakeListener.java
@@ -133,6 +133,10 @@ public class HandshakeListener implements PacketHandshakingInListener {
@@ -134,6 +134,10 @@ public class HandshakeListener implements PacketHandshakingInListener {
throw new UnsupportedOperationException("Invalid intention " + packethandshakinginsetprotocol.b());
}

Datei anzeigen

@ -5,7 +5,7 @@ Subject: [PATCH] Fix hex colors not working in some kick messages
diff --git a/src/main/java/net/minecraft/server/HandshakeListener.java b/src/main/java/net/minecraft/server/HandshakeListener.java
index 471826ee4b32fe73d3c39755005e3287f9673c3c..79f726ef43e70b8882890007146df199824d14e3 100644
index a9337dc61d6370453a15ad284e44ad071e00572f..5843632fedafbd3e5cafd799cc779c39c9866c76 100644
--- a/src/main/java/net/minecraft/server/HandshakeListener.java
+++ b/src/main/java/net/minecraft/server/HandshakeListener.java
@@ -35,7 +35,7 @@ public class HandshakeListener implements PacketHandshakingInListener {
@ -33,7 +33,7 @@ index 471826ee4b32fe73d3c39755005e3287f9673c3c..79f726ef43e70b8882890007146df199
}
this.c.sendPacket(new PacketLoginOutDisconnect(chatmessage));
@@ -82,7 +82,7 @@ public class HandshakeListener implements PacketHandshakingInListener {
@@ -83,7 +83,7 @@ public class HandshakeListener implements PacketHandshakingInListener {
if (event.callEvent()) {
// If we've failed somehow, let the client know so and go no further.
if (event.isFailed()) {