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

This commit is contained in:
Paul Zhang 2021-02-23 16:47:06 +01:00
parent f1400a74c5
commit 1bc1a162c4
2 changed files with 32 additions and 2 deletions

View file

@ -37,6 +37,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ +
+ private static final HandlerList HANDLERS = new HandlerList(); + private static final HandlerList HANDLERS = new HandlerList();
+ @NotNull private final String originalHandshake; + @NotNull private final String originalHandshake;
+ @NotNull private final String originalSocketAddressHostname;
+ private boolean cancelled; + private boolean cancelled;
+ @Nullable private String serverHostname; + @Nullable private String serverHostname;
+ @Nullable private String socketAddressHostname; + @Nullable private String socketAddressHostname;
@ -50,10 +51,25 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * + *
+ * @param originalHandshake the original handshake string + * @param originalHandshake the original handshake string
+ * @param cancelled if this event is enabled + * @param cancelled if this event is enabled
+ *
+ * @deprecated in favour of {@link PlayerHandshakeEvent(String, String, boolean)}
+ */ + */
+ @Deprecated
+ public PlayerHandshakeEvent(@NotNull String originalHandshake, boolean cancelled) { + 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); + super(true);
+ this.originalHandshake = originalHandshake; + this.originalHandshake = originalHandshake;
+ this.originalSocketAddressHostname = originalSocketAddressHostname;
+ this.cancelled = cancelled; + this.cancelled = cancelled;
+ } + }
+ +
@ -94,6 +110,19 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ } + }
+ +
+ /** + /**
+ * 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. + * Gets the server hostname string.
+ * + *
+ * <p>This should not include the port.</p> + * <p>This should not include the port.</p>

View file

@ -27,7 +27,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ boolean handledByEvent = false; + boolean handledByEvent = false;
+ // Try and handle the handshake through the event + // Try and handle the handshake through the event
+ if (com.destroystokyo.paper.event.player.PlayerHandshakeEvent.getHandlerList().getRegisteredListeners().length != 0) { // Hello? Can you hear me? + 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 (event.callEvent()) {
+ // If we've failed somehow, let the client know so and go no further. + // If we've failed somehow, let the client know so and go no further.
+ if (event.isFailed()) { + if (event.isFailed()) {
@ -38,7 +39,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ } + }
+ +
+ if (event.getServerHostname() != null) packethandshakinginsetprotocol.hostname = event.getServerHostname(); + 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().spoofedUUID = event.getUniqueId();
+ this.getNetworkManager().spoofedProfile = gson.fromJson(event.getPropertiesJson(), com.mojang.authlib.properties.Property[].class); + this.getNetworkManager().spoofedProfile = gson.fromJson(event.getPropertiesJson(), com.mojang.authlib.properties.Property[].class);
+ handledByEvent = true; // Hooray, we did it! + handledByEvent = true; // Hooray, we did it!