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

160 lines
7.4 KiB
Diff
Raw Normal View History

From 9e2c25116d18e4cd360d8c7a55b9e096e8648d39 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
2014-11-28 02:17:45 +01:00
index ba2b912..a59ea80 100644
--- a/src/main/java/net/minecraft/server/LoginListener.java
+++ b/src/main/java/net/minecraft/server/LoginListener.java
2014-11-28 02:17:45 +01:00
@@ -60,10 +60,23 @@ public class LoginListener implements PacketLoginInListener, IUpdatePlayerListBo
}
+ // 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);
@@ -98,7 +111,7 @@ public class LoginListener implements PacketLoginInListener, IUpdatePlayerListBo
this.g = EnumProtocolState.KEY;
2014-11-28 02:17:45 +01:00
this.networkManager.handle(new PacketLoginOutEncryptionBegin(this.j, this.server.P().getPublic(), this.e));
} else {
- this.g = EnumProtocolState.READY_TO_ACCEPT;
+ (new ThreadPlayerLookupUUID(this, "User Authenticator #" + b.incrementAndGet())).start(); // Spigot
}
2014-11-28 02:17:45 +01:00
}
diff --git a/src/main/java/net/minecraft/server/ThreadPlayerLookupUUID.java b/src/main/java/net/minecraft/server/ThreadPlayerLookupUUID.java
2014-11-28 02:17:45 +01:00
index bbceef0..8b93fd5 100644
--- a/src/main/java/net/minecraft/server/ThreadPlayerLookupUUID.java
+++ b/src/main/java/net/minecraft/server/ThreadPlayerLookupUUID.java
2014-11-28 02:17:45 +01:00
@@ -24,50 +24,19 @@ class ThreadPlayerLookupUUID extends Thread {
GameProfile gameprofile = LoginListener.b(this.a);
try {
+ // Spigot Start
2014-11-28 02:17:45 +01:00
+ if ( !LoginListener.a( this.a ).getOnlineMode() )
+ {
+ a.initUUID();
+ fireLoginEvents();
+ return;
+ }
+ // Spigot End
2014-11-28 02:17:45 +01:00
String s = (new BigInteger(MinecraftEncryption.a(LoginListener.c(this.a), LoginListener.a(this.a).P().getPublic(), LoginListener.d(this.a)))).toString(16);
2014-11-28 02:17:45 +01:00
LoginListener.a(this.a, LoginListener.a(this.a).aB().hasJoinedServer(new GameProfile((UUID) null, gameprofile.getName()), s));
if (LoginListener.b(this.a) != null) {
- // CraftBukkit start - fire PlayerPreLoginEvent
2014-11-28 02:17:45 +01:00
- if (!this.a.networkManager.g()) {
- return;
- }
-
2014-11-28 02:17:45 +01:00
- String playerName = LoginListener.b(this.a).getName();
- java.net.InetAddress address = ((java.net.InetSocketAddress) a.networkManager.getSocketAddress()).getAddress();
2014-11-28 02:17:45 +01:00
- java.util.UUID uniqueId = LoginListener.b(this.a).getId();
- final org.bukkit.craftbukkit.CraftServer server = LoginListener.a(this.a).server;
-
- AsyncPlayerPreLoginEvent asyncEvent = new AsyncPlayerPreLoginEvent(playerName, address, uniqueId);
- server.getPluginManager().callEvent(asyncEvent);
-
- if (PlayerPreLoginEvent.getHandlerList().getRegisteredListeners().length != 0) {
- final PlayerPreLoginEvent event = new PlayerPreLoginEvent(playerName, address, uniqueId);
- if (asyncEvent.getResult() != PlayerPreLoginEvent.Result.ALLOWED) {
- event.disallow(asyncEvent.getResult(), asyncEvent.getKickMessage());
- }
- Waitable<PlayerPreLoginEvent.Result> waitable = new Waitable<PlayerPreLoginEvent.Result>() {
- @Override
- protected PlayerPreLoginEvent.Result evaluate() {
- server.getPluginManager().callEvent(event);
- return event.getResult();
- }};
-
2014-11-28 02:17:45 +01:00
- LoginListener.a(this.a).processQueue.add(waitable);
- if (waitable.get() != PlayerPreLoginEvent.Result.ALLOWED) {
- this.a.disconnect(event.getKickMessage());
- return;
- }
- } else {
- if (asyncEvent.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) {
- this.a.disconnect(asyncEvent.getKickMessage());
- return;
- }
- }
- // CraftBukkit end
2014-11-28 02:17:45 +01:00
-
- LoginListener.e().info("UUID of player " + LoginListener.b(this.a).getName() + " is " + LoginListener.b(this.a).getId());
- LoginListener.a(this.a, EnumProtocolState.READY_TO_ACCEPT);
+ fireLoginEvents(); // Spigot
2014-11-28 02:17:45 +01:00
} else if (LoginListener.a(this.a).S()) {
LoginListener.e().warn("Failed to verify username but will let them in anyway!");
LoginListener.a(this.a, this.a.a(gameprofile));
@@ -93,4 +62,48 @@ class ThreadPlayerLookupUUID extends Thread {
}
2014-11-28 02:17:45 +01:00
}
+
+ private void fireLoginEvents() throws Exception
+ {
+ // CraftBukkit start - fire PlayerPreLoginEvent
2014-11-28 02:17:45 +01:00
+ if (!this.a.networkManager.g()) {
+ return;
+ }
+
2014-11-28 02:17:45 +01:00
+ String playerName = LoginListener.b(this.a).getName();
+ java.net.InetAddress address = ((java.net.InetSocketAddress) a.networkManager.getSocketAddress()).getAddress();
2014-11-28 02:17:45 +01:00
+ java.util.UUID uniqueId = LoginListener.b(this.a).getId();
+ final org.bukkit.craftbukkit.CraftServer server = LoginListener.a(this.a).server;
+
+ AsyncPlayerPreLoginEvent asyncEvent = new AsyncPlayerPreLoginEvent(playerName, address, uniqueId);
+ server.getPluginManager().callEvent(asyncEvent);
+
+ if (PlayerPreLoginEvent.getHandlerList().getRegisteredListeners().length != 0) {
+ final PlayerPreLoginEvent event = new PlayerPreLoginEvent(playerName, address, uniqueId);
+ if (asyncEvent.getResult() != PlayerPreLoginEvent.Result.ALLOWED) {
+ event.disallow(asyncEvent.getResult(), asyncEvent.getKickMessage());
+ }
+ Waitable<PlayerPreLoginEvent.Result> waitable = new Waitable<PlayerPreLoginEvent.Result>() {
+ @Override
+ protected PlayerPreLoginEvent.Result evaluate() {
+ server.getPluginManager().callEvent(event);
+ return event.getResult();
+ }};
+
2014-11-28 02:17:45 +01:00
+ LoginListener.a(this.a).processQueue.add(waitable);
+ if (waitable.get() != PlayerPreLoginEvent.Result.ALLOWED) {
+ this.a.disconnect(event.getKickMessage());
+ return;
+ }
+ } else {
+ if (asyncEvent.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) {
+ this.a.disconnect(asyncEvent.getKickMessage());
+ return;
+ }
+ }
+ // CraftBukkit end
+
2014-11-28 02:17:45 +01:00
+ LoginListener.e().info("UUID of player " + LoginListener.b(this.a).getName() + " is " + LoginListener.b(this.a).getId());
+ LoginListener.a(this.a, EnumProtocolState.READY_TO_ACCEPT);
+ }
}
--
2014-11-28 02:17:45 +01:00
2.1.0