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

161 lines
7.5 KiB
Diff

From 731f42f442109e046706fe7c92d9e71359eadc99 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
index dddd9aa..0d82e7d 100644
--- a/src/main/java/net/minecraft/server/LoginListener.java
+++ b/src/main/java/net/minecraft/server/LoginListener.java
@@ -59,12 +59,25 @@ public class LoginListener implements PacketLoginInListener {
}
}
+ // Spigot start
+ public void initUUID()
+ {
+ String uuid = UUID.nameUUIDFromBytes( ( "OfflinePlayer:" + this.i.getName() ).getBytes( Charsets.UTF_8 ) ).toString().replaceAll( "-", "" );
+
+ this.i = new GameProfile( uuid, this.i.getName() );
+ }
+ // Spigot end
+
public void c() {
+ // Spigot start - Moved to initUUID
+ /*
if (!this.i.isComplete()) {
UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + this.i.getName()).getBytes(Charsets.UTF_8));
this.i = new GameProfile(uuid.toString().replaceAll("-", ""), this.i.getName());
}
+ */
+ // Spigot end
// CraftBukkit start - fire PlayerLoginEvent
EntityPlayer s = this.server.getPlayerList().attemptLogin(this, this.i, this.hostname);
@@ -99,7 +112,7 @@ public class LoginListener implements PacketLoginInListener {
this.g = EnumProtocolState.KEY;
this.networkManager.handle(new PacketLoginOutEncryptionBegin(this.j, this.server.J().getPublic(), this.e), new GenericFutureListener[0]);
} else {
- this.g = EnumProtocolState.READY_TO_ACCEPT;
+ (new ThreadPlayerLookupUUID(this, "User Authenticator #" + b.incrementAndGet())).start(); // Spigot
}
}
diff --git a/src/main/java/net/minecraft/server/ThreadPlayerLookupUUID.java b/src/main/java/net/minecraft/server/ThreadPlayerLookupUUID.java
index 496b7c9..fe4502a 100644
--- a/src/main/java/net/minecraft/server/ThreadPlayerLookupUUID.java
+++ b/src/main/java/net/minecraft/server/ThreadPlayerLookupUUID.java
@@ -22,48 +22,22 @@ class ThreadPlayerLookupUUID extends Thread {
public void run() {
try {
+ // Spigot Start
+ if ( !LoginListener.b( this.a ).getOnlineMode() )
+ {
+ a.initUUID();
+ fireLoginEvents();
+ LoginListener.e().info( "UUID of player " + LoginListener.d( this.a ).getName() + " is " + LoginListener.d( this.a ).getId() );
+ LoginListener.a( this.a, EnumProtocolState.READY_TO_ACCEPT );
+ return;
+ }
+ // Spigot End
String s = (new BigInteger(MinecraftEncryption.a(LoginListener.a(this.a), LoginListener.b(this.a).J().getPublic(), LoginListener.c(this.a)))).toString(16);
-
LoginListener.a(this.a, LoginListener.b(this.a).at().hasJoinedServer(new GameProfile((String) null, LoginListener.d(this.a).getName()), s));
if (LoginListener.d(this.a) != null) {
- // CraftBukkit start - fire PlayerPreLoginEvent
- if (!this.a.networkManager.isConnected()) {
- return;
- }
-
- String playerName = LoginListener.d(this.a).getName();
- java.net.InetAddress address = ((java.net.InetSocketAddress) a.networkManager.getSocketAddress()).getAddress();
- java.util.UUID uniqueId = UtilUUID.b(LoginListener.d(this.a).getId());
- final org.bukkit.craftbukkit.CraftServer server = LoginListener.b(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();
- }};
-
- LoginListener.b(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
-
+ // Spigot Start
+ fireLoginEvents();
+ // Spigot End
LoginListener.e().info("UUID of player " + LoginListener.d(this.a).getName() + " is " + LoginListener.d(this.a).getId());
LoginListener.a(this.a, EnumProtocolState.READY_TO_ACCEPT);
} else {
@@ -80,4 +54,45 @@ class ThreadPlayerLookupUUID extends Thread {
// CraftBukkit end
}
}
+
+ private void fireLoginEvents() throws Exception
+ {
+ // CraftBukkit start - fire PlayerPreLoginEvent
+ if (!this.a.networkManager.isConnected()) {
+ return;
+ }
+
+ String playerName = LoginListener.d(this.a).getName();
+ java.net.InetAddress address = ((java.net.InetSocketAddress) a.networkManager.getSocketAddress()).getAddress();
+ java.util.UUID uniqueId = UtilUUID.b(LoginListener.d(this.a).getId());
+ final org.bukkit.craftbukkit.CraftServer server = LoginListener.b(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();
+ }};
+
+ LoginListener.b(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
+ }
}
--
1.8.5.2.msysgit.0