Paper/nms-patches/LoginListener.patch

129 lines
6.6 KiB
Diff
Raw Normal View History

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/LoginListener.java
+++ b/net/minecraft/server/LoginListener.java
2018-12-25 22:00:00 +01:00
@@ -18,6 +18,12 @@
2015-02-26 23:41:06 +01:00
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+// CraftBukkit start
+import org.bukkit.craftbukkit.util.Waitable;
+import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
+import org.bukkit.event.player.PlayerPreLoginEvent;
+// CraftBukkit end
+
2019-04-23 04:00:00 +02:00
public class LoginListener implements PacketLoginInListener {
2015-02-26 23:41:06 +01:00
private static final AtomicInteger b = new AtomicInteger(0);
2018-12-25 22:00:00 +01:00
@@ -32,6 +38,7 @@
2016-06-09 03:43:49 +02:00
private final String j;
private SecretKey loginKey;
2015-02-26 23:41:06 +01:00
private EntityPlayer l;
+ public String hostname = ""; // CraftBukkit - add field
public LoginListener(MinecraftServer minecraftserver, NetworkManager networkmanager) {
2015-02-26 23:41:06 +01:00
this.g = LoginListener.EnumProtocolState.HELLO;
2018-12-25 22:00:00 +01:00
@@ -60,6 +67,20 @@
2017-05-30 13:25:59 +02:00
}
+ // CraftBukkit start
+ @Deprecated
+ public void disconnect(String s) {
+ try {
+ IChatBaseComponent ichatbasecomponent = new ChatComponentText(s);
2019-04-25 04:00:00 +02:00
+ LoginListener.LOGGER.info("Disconnecting {}: {}", this.d(), s);
2017-05-30 13:25:59 +02:00
+ this.networkManager.sendPacket(new PacketLoginOutDisconnect(ichatbasecomponent));
+ this.networkManager.close(ichatbasecomponent);
+ } catch (Exception exception) {
2019-04-25 04:00:00 +02:00
+ LoginListener.LOGGER.error("Error whilst disconnecting player", exception);
2017-05-30 13:25:59 +02:00
+ }
+ }
+ // CraftBukkit end
+
2019-07-20 01:00:00 +02:00
@Override
public NetworkManager a() {
return this.networkManager;
@@ -81,10 +102,12 @@
this.i = this.a(this.i);
}
2018-07-15 02:00:00 +02:00
- IChatBaseComponent ichatbasecomponent = this.server.getPlayerList().attemptLogin(this.networkManager.getSocketAddress(), this.i);
+ // CraftBukkit start - fire PlayerLoginEvent
+ EntityPlayer s = this.server.getPlayerList().attemptLogin(this, this.i, hostname);
2018-07-15 02:00:00 +02:00
- if (ichatbasecomponent != null) {
- this.disconnect(ichatbasecomponent);
+ if (s == null) {
2018-07-15 02:00:00 +02:00
+ // this.disconnect(ichatbasecomponent);
+ // CraftBukkit end
} else {
2015-02-26 23:41:06 +01:00
this.g = LoginListener.EnumProtocolState.ACCEPTED;
2019-07-20 01:00:00 +02:00
if (this.server.az() >= 0 && !this.networkManager.isLocal()) {
@@ -98,9 +121,9 @@
2015-02-26 23:41:06 +01:00
if (entityplayer != null) {
2016-02-29 22:32:46 +01:00
this.g = LoginListener.EnumProtocolState.DELAY_ACCEPT;
2015-02-26 23:41:06 +01:00
- this.l = this.server.getPlayerList().processLogin(this.i);
+ this.l = this.server.getPlayerList().processLogin(this.i, s); // CraftBukkit - add player reference
} else {
- this.server.getPlayerList().a(this.networkManager, this.server.getPlayerList().processLogin(this.i));
+ this.server.getPlayerList().a(this.networkManager, this.server.getPlayerList().processLogin(this.i, s)); // CraftBukkit - add player reference
}
}
2019-07-20 01:00:00 +02:00
@@ -148,6 +171,43 @@
2015-02-26 23:41:06 +01:00
2019-04-23 04:00:00 +02:00
LoginListener.this.i = LoginListener.this.server.getMinecraftSessionService().hasJoinedServer(new GameProfile((UUID) null, gameprofile.getName()), s, this.a());
2015-02-26 23:41:06 +01:00
if (LoginListener.this.i != null) {
+ // CraftBukkit start - fire PlayerPreLoginEvent
2016-02-29 22:32:46 +01:00
+ if (!networkManager.isConnected()) {
2015-02-26 23:41:06 +01:00
+ return;
+ }
+
+ String playerName = i.getName();
+ java.net.InetAddress address = ((java.net.InetSocketAddress) networkManager.getSocketAddress()).getAddress();
+ java.util.UUID uniqueId = i.getId();
+ final org.bukkit.craftbukkit.CraftServer server = LoginListener.this.server.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.this.server.processQueue.add(waitable);
+ if (waitable.get() != PlayerPreLoginEvent.Result.ALLOWED) {
+ disconnect(event.getKickMessage());
+ return;
+ }
+ } else {
+ if (asyncEvent.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) {
+ disconnect(asyncEvent.getKickMessage());
+ return;
+ }
+ }
+ // CraftBukkit end
2019-04-25 04:00:00 +02:00
LoginListener.LOGGER.info("UUID of player {} is {}", LoginListener.this.i.getName(), LoginListener.this.i.getId());
2015-02-26 23:41:06 +01:00
LoginListener.this.g = LoginListener.EnumProtocolState.READY_TO_ACCEPT;
2019-04-23 04:00:00 +02:00
} else if (LoginListener.this.server.isEmbeddedServer()) {
2019-07-20 01:00:00 +02:00
@@ -167,6 +227,11 @@
2017-05-30 13:25:59 +02:00
LoginListener.this.disconnect(new ChatMessage("multiplayer.disconnect.authservers_down", new Object[0]));
2019-04-25 04:00:00 +02:00
LoginListener.LOGGER.error("Couldn't verify username because servers are unavailable");
2015-02-26 23:41:06 +01:00
}
+ // 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
}
}