Paper/CraftBukkit-Patches/0047-Fire-PreLogin-Events-in-Offline-Mode.patch

146 Zeilen
7.5 KiB
Diff

2016-03-01 01:23:45 +01:00
From 375f19d5b86d8c2498918195a67c992259ffa5f6 Mon Sep 17 00:00:00 2001
From: md_5 <git@md-5.net>
Date: Wed, 18 Dec 2013 13:32:10 +1100
Subject: [PATCH] Fire PreLogin Events in Offline Mode
diff --git a/src/main/java/net/minecraft/server/LoginListener.java b/src/main/java/net/minecraft/server/LoginListener.java
2016-02-29 22:33:06 +01:00
index 3cca9ff..71d24b2 100644
--- a/src/main/java/net/minecraft/server/LoginListener.java
+++ b/src/main/java/net/minecraft/server/LoginListener.java
2015-02-28 12:36:22 +01:00
@@ -13,6 +13,7 @@ import java.util.Arrays;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.logging.Level;
import javax.crypto.SecretKey;
import org.apache.commons.lang3.Validate;
import org.apache.logging.log4j.LogManager;
2016-02-29 22:33:06 +01:00
@@ -80,10 +81,23 @@ public class LoginListener implements PacketLoginInListener, ITickable {
2014-11-28 02:17:45 +01:00
}
+ // Spigot start
+ public void initUUID()
+ {
+ UUID uuid = UUID.nameUUIDFromBytes( ( "OfflinePlayer:" + this.i.getName() ).getBytes( Charsets.UTF_8 ) );
+
+ this.i = new GameProfile( uuid, this.i.getName() );
+ }
+ // Spigot end
+
2014-11-28 02:17:45 +01:00
public void b() {
+ // Spigot start - Moved to initUUID
+ /*
if (!this.i.isComplete()) {
this.i = this.a(this.i);
}
+ */
+ // Spigot end
// CraftBukkit start - fire PlayerLoginEvent
2014-11-28 02:17:45 +01:00
EntityPlayer s = this.server.getPlayerList().attemptLogin(this, this.i, hostname);
2016-02-29 22:33:06 +01:00
@@ -133,7 +147,22 @@ public class LoginListener implements PacketLoginInListener, ITickable {
2015-02-28 12:36:22 +01:00
this.g = LoginListener.EnumProtocolState.KEY;
2016-02-29 22:33:06 +01:00
this.networkManager.sendPacket(new PacketLoginOutEncryptionBegin(this.j, this.server.O().getPublic(), this.e));
} else {
2015-02-28 12:36:22 +01:00
- this.g = LoginListener.EnumProtocolState.READY_TO_ACCEPT;
+ // Spigot start
2016-02-29 22:33:06 +01:00
+ new Thread("User Authenticator #" + LoginListener.b.incrementAndGet()) {
+
+ @Override
+ public void run() {
+ try {
+ initUUID();
+ new LoginHandler().fireEvents();
+ LoginListener.this.g = LoginListener.EnumProtocolState.READY_TO_ACCEPT;
+ } catch (Exception ex) {
+ disconnect("Failed to verify username!");
+ server.server.getLogger().log(java.util.logging.Level.WARNING, "Exception verifying " + i.getName(), ex);
+ }
+ }
+ }.start();
2015-02-28 12:36:22 +01:00
+ // Spigot end
}
2014-11-28 02:17:45 +01:00
}
2016-02-29 22:33:06 +01:00
@@ -162,6 +191,39 @@ public class LoginListener implements PacketLoginInListener, ITickable {
2015-02-28 12:36:22 +01:00
return;
}
2015-02-28 12:36:22 +01:00
+ new LoginHandler().fireEvents();
2016-02-29 22:33:06 +01:00
+ } else if (LoginListener.this.server.R()) {
2015-02-28 12:36:22 +01:00
+ LoginListener.c.warn("Failed to verify username but will let them in anyway!");
+ LoginListener.this.i = LoginListener.this.a(gameprofile);
+ LoginListener.this.g = LoginListener.EnumProtocolState.READY_TO_ACCEPT;
+ } else {
+ LoginListener.this.disconnect("Failed to verify username!");
+ LoginListener.c.error("Username \'" + gameprofile.getName() + "\' tried to join with an invalid session"); // CraftBukkit - fix null pointer
+ }
+ } catch (AuthenticationUnavailableException authenticationunavailableexception) {
2016-02-29 22:33:06 +01:00
+ if (LoginListener.this.server.R()) {
2015-02-28 12:36:22 +01:00
+ LoginListener.c.warn("Authentication servers are down but will let them in anyway!");
+ LoginListener.this.i = LoginListener.this.a(gameprofile);
+ LoginListener.this.g = LoginListener.EnumProtocolState.READY_TO_ACCEPT;
+ } else {
+ LoginListener.this.disconnect("Authentication servers are down. Please try again later, sorry!");
+ LoginListener.c.error("Couldn\'t verify username because servers are unavailable");
+ }
+ // CraftBukkit start - catch all exceptions
+ } catch (Exception exception) {
+ disconnect("Failed to verify username!");
+ server.server.getLogger().log(java.util.logging.Level.WARNING, "Exception verifying " + gameprofile.getName(), exception);
+ // CraftBukkit end
+ }
+ }
+ }).start();
+ }
+ }
+
+ // Spigot start
+ public class LoginHandler {
+
+ public void fireEvents() throws Exception {
String playerName = i.getName();
java.net.InetAddress address = ((java.net.InetSocketAddress) networkManager.getSocketAddress()).getAddress();
java.util.UUID uniqueId = i.getId();
2016-02-29 22:33:06 +01:00
@@ -196,34 +258,9 @@ public class LoginListener implements PacketLoginInListener, ITickable {
2015-02-28 12:36:22 +01:00
// CraftBukkit end
LoginListener.c.info("UUID of player " + LoginListener.this.i.getName() + " is " + LoginListener.this.i.getId());
LoginListener.this.g = LoginListener.EnumProtocolState.READY_TO_ACCEPT;
2016-02-29 22:33:06 +01:00
- } else if (LoginListener.this.server.R()) {
2015-02-28 12:36:22 +01:00
- LoginListener.c.warn("Failed to verify username but will let them in anyway!");
- LoginListener.this.i = LoginListener.this.a(gameprofile);
- LoginListener.this.g = LoginListener.EnumProtocolState.READY_TO_ACCEPT;
- } else {
- LoginListener.this.disconnect("Failed to verify username!");
- LoginListener.c.error("Username \'" + gameprofile.getName() + "\' tried to join with an invalid session"); // CraftBukkit - fix null pointer
- }
- } catch (AuthenticationUnavailableException authenticationunavailableexception) {
2016-02-29 22:33:06 +01:00
- if (LoginListener.this.server.R()) {
2015-02-28 12:36:22 +01:00
- LoginListener.c.warn("Authentication servers are down but will let them in anyway!");
- LoginListener.this.i = LoginListener.this.a(gameprofile);
- LoginListener.this.g = LoginListener.EnumProtocolState.READY_TO_ACCEPT;
- } else {
- LoginListener.this.disconnect("Authentication servers are down. Please try again later, sorry!");
- LoginListener.c.error("Couldn\'t verify username because servers are unavailable");
- }
- // CraftBukkit start - catch all exceptions
- } catch (Exception exception) {
- disconnect("Failed to verify username!");
- server.server.getLogger().log(java.util.logging.Level.WARNING, "Exception verifying " + gameprofile.getName(), exception);
- // CraftBukkit end
- }
-
2016-02-29 22:33:06 +01:00
}
2015-02-28 12:36:22 +01:00
- }).start();
}
2016-02-29 22:33:06 +01:00
- }
2015-02-28 12:36:22 +01:00
+ // Spigot end
protected GameProfile a(GameProfile gameprofile) {
UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + gameprofile.getName()).getBytes(Charsets.UTF_8));
--
2016-02-29 22:33:06 +01:00
2.5.0