mirror of
https://hub.spigotmc.org/stash/scm/spigot/spigot.git
synced 2025-07-04 11:22:58 +00:00
299 lines
18 KiB
Diff
299 lines
18 KiB
Diff
From cb257b0860cc6e0b258d36a8c6a41e6bc3b1113a Mon Sep 17 00:00:00 2001
|
|
From: md_5 <git@md-5.net>
|
|
Date: Sat, 12 Apr 2014 21:23:58 +1000
|
|
Subject: [PATCH] BungeeCord Support
|
|
|
|
* Provides support for IP forwarding via BungeeCord.
|
|
* Treats Bungee as Online Mode.
|
|
|
|
diff --git a/src/main/java/net/minecraft/network/NetworkManager.java b/src/main/java/net/minecraft/network/NetworkManager.java
|
|
index 8cf54fdf8..2765cda6c 100644
|
|
--- a/src/main/java/net/minecraft/network/NetworkManager.java
|
|
+++ b/src/main/java/net/minecraft/network/NetworkManager.java
|
|
@@ -95,6 +95,10 @@ public class NetworkManager extends SimpleChannelInboundHandler<Packet<?>> {
|
|
private final Queue<Consumer<NetworkManager>> pendingActions = Queues.newConcurrentLinkedQueue();
|
|
public Channel channel;
|
|
public SocketAddress address;
|
|
+ // Spigot Start
|
|
+ public java.util.UUID spoofedUUID;
|
|
+ public com.mojang.authlib.properties.Property[] spoofedProfile;
|
|
+ // Spigot End
|
|
@Nullable
|
|
private volatile PacketListener disconnectListener;
|
|
@Nullable
|
|
diff --git a/src/main/java/net/minecraft/network/protocol/handshake/PacketHandshakingInSetProtocol.java b/src/main/java/net/minecraft/network/protocol/handshake/PacketHandshakingInSetProtocol.java
|
|
index caf396b38..544390eed 100644
|
|
--- a/src/main/java/net/minecraft/network/protocol/handshake/PacketHandshakingInSetProtocol.java
|
|
+++ b/src/main/java/net/minecraft/network/protocol/handshake/PacketHandshakingInSetProtocol.java
|
|
@@ -12,7 +12,8 @@ public record PacketHandshakingInSetProtocol(int protocolVersion, String hostNam
|
|
private static final int MAX_HOST_LENGTH = 255;
|
|
|
|
private PacketHandshakingInSetProtocol(PacketDataSerializer packetdataserializer) {
|
|
- this(packetdataserializer.readVarInt(), packetdataserializer.readUtf(255), packetdataserializer.readUnsignedShort(), ClientIntent.byId(packetdataserializer.readVarInt()));
|
|
+ // Spigot - increase max hostName length
|
|
+ this(packetdataserializer.readVarInt(), packetdataserializer.readUtf(Short.MAX_VALUE), packetdataserializer.readUnsignedShort(), ClientIntent.byId(packetdataserializer.readVarInt()));
|
|
}
|
|
|
|
private void write(PacketDataSerializer packetdataserializer) {
|
|
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
|
index 1befcf743..75c893364 100644
|
|
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
|
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
|
@@ -239,7 +239,14 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
|
|
if (!this.usesAuthentication()) {
|
|
DedicatedServer.LOGGER.warn("**** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!");
|
|
DedicatedServer.LOGGER.warn("The server will make no attempt to authenticate usernames. Beware.");
|
|
- DedicatedServer.LOGGER.warn("While this makes the game possible to play without internet access, it also opens up the ability for hackers to connect with any username they choose.");
|
|
+ // Spigot start
|
|
+ if (org.spigotmc.SpigotConfig.bungee) {
|
|
+ DedicatedServer.LOGGER.warn("Whilst this makes it possible to use BungeeCord, unless access to your server is properly restricted, it also opens up the ability for hackers to connect with any username they choose.");
|
|
+ DedicatedServer.LOGGER.warn("Please see http://www.spigotmc.org/wiki/firewall-guide/ for further information.");
|
|
+ } else {
|
|
+ DedicatedServer.LOGGER.warn("While this makes the game possible to play without internet access, it also opens up the ability for hackers to connect with any username they choose.");
|
|
+ }
|
|
+ // Spigot end
|
|
DedicatedServer.LOGGER.warn("To change this, set \"online-mode\" to \"true\" in the server.properties file.");
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/network/HandshakeListener.java b/src/main/java/net/minecraft/server/network/HandshakeListener.java
|
|
index fc21e03ed..1124ea42c 100644
|
|
--- a/src/main/java/net/minecraft/server/network/HandshakeListener.java
|
|
+++ b/src/main/java/net/minecraft/server/network/HandshakeListener.java
|
|
@@ -19,6 +19,11 @@ import java.util.HashMap;
|
|
|
|
public class HandshakeListener implements PacketHandshakingInListener {
|
|
|
|
+ // Spigot start
|
|
+ private static final com.google.gson.Gson gson = new com.google.gson.Gson();
|
|
+ static final java.util.regex.Pattern HOST_PATTERN = java.util.regex.Pattern.compile("[0-9a-f\\.:]{0,45}");
|
|
+ static final java.util.regex.Pattern PROP_PATTERN = java.util.regex.Pattern.compile("\\w{0,16}");
|
|
+ // Spigot end
|
|
// CraftBukkit start - add fields
|
|
private static final HashMap<InetAddress, Long> throttleTracker = new HashMap<InetAddress, Long>();
|
|
private static int throttleCounter = 0;
|
|
@@ -115,6 +120,31 @@ public class HandshakeListener implements PacketHandshakingInListener {
|
|
this.connection.disconnect(ichatbasecomponent);
|
|
} else {
|
|
this.connection.setupInboundProtocol(LoginProtocols.SERVERBOUND, new LoginListener(this.server, this.connection, flag));
|
|
+ // Spigot Start
|
|
+ String[] split = packethandshakinginsetprotocol.hostName().split("\00");
|
|
+ if (org.spigotmc.SpigotConfig.bungee) {
|
|
+ if ( ( split.length == 3 || split.length == 4 ) && ( HOST_PATTERN.matcher( split[1] ).matches() ) ) {
|
|
+ connection.hostname = split[0];
|
|
+ connection.address = new java.net.InetSocketAddress(split[1], ((java.net.InetSocketAddress) connection.getRemoteAddress()).getPort());
|
|
+ connection.spoofedUUID = com.mojang.util.UndashedUuid.fromStringLenient( split[2] );
|
|
+ } else
|
|
+ {
|
|
+ IChatBaseComponent chatmessage = IChatBaseComponent.literal("If you wish to use IP forwarding, please enable it in your BungeeCord config as well!");
|
|
+ this.connection.send(new PacketLoginOutDisconnect(chatmessage));
|
|
+ this.connection.disconnect(chatmessage);
|
|
+ return;
|
|
+ }
|
|
+ if ( split.length == 4 )
|
|
+ {
|
|
+ connection.spoofedProfile = gson.fromJson(split[3], com.mojang.authlib.properties.Property[].class);
|
|
+ }
|
|
+ } else if ( ( split.length == 3 || split.length == 4 ) && ( HOST_PATTERN.matcher( split[1] ).matches() ) ) {
|
|
+ IChatBaseComponent chatmessage = IChatBaseComponent.literal("Unknown data in login hostname, did you forget to enable BungeeCord in spigot.yml?");
|
|
+ this.connection.send(new PacketLoginOutDisconnect(chatmessage));
|
|
+ this.connection.disconnect(chatmessage);
|
|
+ return;
|
|
+ }
|
|
+ // Spigot End
|
|
}
|
|
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/network/LoginListener.java b/src/main/java/net/minecraft/server/network/LoginListener.java
|
|
index aaf68153d..bfd49a7e1 100644
|
|
--- a/src/main/java/net/minecraft/server/network/LoginListener.java
|
|
+++ b/src/main/java/net/minecraft/server/network/LoginListener.java
|
|
@@ -182,7 +182,7 @@ public class LoginListener implements PacketLoginInListener, TickablePacketListe
|
|
@Override
|
|
public void run() {
|
|
try {
|
|
- GameProfile gameprofile = UUIDUtil.createOfflineProfile(LoginListener.this.requestedUsername);
|
|
+ GameProfile gameprofile = createOfflineProfile(LoginListener.this.requestedUsername); // Spigot
|
|
|
|
LoginListener.this.callPlayerPreLoginEvents(gameprofile);
|
|
LoginListener.LOGGER.info("UUID of player {} is {}", gameprofile.getName(), gameprofile.getId());
|
|
@@ -294,7 +294,7 @@ public class LoginListener implements PacketLoginInListener, TickablePacketListe
|
|
LoginListener.this.startClientVerification(gameprofile);
|
|
} else if (LoginListener.this.server.isSingleplayer()) {
|
|
LoginListener.LOGGER.warn("Failed to verify username but will let them in anyway!");
|
|
- LoginListener.this.startClientVerification(UUIDUtil.createOfflineProfile(s1));
|
|
+ LoginListener.this.startClientVerification(LoginListener.this.createOfflineProfile(s1)); // Spigot
|
|
} else {
|
|
LoginListener.this.disconnect(IChatBaseComponent.translatable("multiplayer.disconnect.unverified_username"));
|
|
LoginListener.LOGGER.error("Username '{}' tried to join with an invalid session", s1);
|
|
@@ -302,7 +302,7 @@ public class LoginListener implements PacketLoginInListener, TickablePacketListe
|
|
} catch (AuthenticationUnavailableException authenticationunavailableexception) {
|
|
if (LoginListener.this.server.isSingleplayer()) {
|
|
LoginListener.LOGGER.warn("Authentication servers are down but will let them in anyway!");
|
|
- LoginListener.this.startClientVerification(UUIDUtil.createOfflineProfile(s1));
|
|
+ LoginListener.this.startClientVerification(LoginListener.this.createOfflineProfile(s1)); // Spigot
|
|
} else {
|
|
LoginListener.this.disconnect(IChatBaseComponent.translatable("multiplayer.disconnect.authservers_down"));
|
|
LoginListener.LOGGER.error("Couldn't verify username because servers are unavailable");
|
|
@@ -401,6 +401,32 @@ public class LoginListener implements PacketLoginInListener, TickablePacketListe
|
|
this.disconnect(ServerCommonPacketListenerImpl.DISCONNECT_UNEXPECTED_QUERY);
|
|
}
|
|
|
|
+ // Spigot start
|
|
+ protected GameProfile createOfflineProfile(String s) {
|
|
+ java.util.UUID uuid;
|
|
+ if ( connection.spoofedUUID != null )
|
|
+ {
|
|
+ uuid = connection.spoofedUUID;
|
|
+ } else
|
|
+ {
|
|
+ uuid = UUIDUtil.createOfflinePlayerUUID( s );
|
|
+ }
|
|
+
|
|
+ GameProfile gameProfile = new GameProfile( uuid, s );
|
|
+
|
|
+ if (connection.spoofedProfile != null)
|
|
+ {
|
|
+ for ( com.mojang.authlib.properties.Property property : connection.spoofedProfile )
|
|
+ {
|
|
+ if ( !HandshakeListener.PROP_PATTERN.matcher( property.name()).matches() ) continue;
|
|
+ gameProfile.getProperties().put( property.name(), property );
|
|
+ }
|
|
+ }
|
|
+
|
|
+ return gameProfile;
|
|
+ }
|
|
+ // Spigot end
|
|
+
|
|
private static enum EnumProtocolState {
|
|
|
|
HELLO, KEY, AUTHENTICATING, NEGOTIATING, VERIFYING, WAITING_FOR_DUPE_DISCONNECT, PROTOCOL_SWITCHING, ACCEPTED, WAITING_FOR_COOKIES, DISCONNECTED; // CraftBukkit
|
|
diff --git a/src/main/java/net/minecraft/server/network/PlayerConnection.java b/src/main/java/net/minecraft/server/network/PlayerConnection.java
|
|
index b9328e974..8dfa8bbf3 100644
|
|
--- a/src/main/java/net/minecraft/server/network/PlayerConnection.java
|
|
+++ b/src/main/java/net/minecraft/server/network/PlayerConnection.java
|
|
@@ -2225,7 +2225,7 @@ public class PlayerConnection extends ServerCommonPacketListenerImpl implements
|
|
|
|
String message = String.format(queueEvent.getFormat(), queueEvent.getPlayer().getDisplayName(), queueEvent.getMessage());
|
|
if (((LazyPlayerSet) queueEvent.getRecipients()).isLazy()) {
|
|
- if (originalFormat.equals(queueEvent.getFormat()) && originalMessage.equals(queueEvent.getMessage()) && queueEvent.getPlayer().getName().equalsIgnoreCase(queueEvent.getPlayer().getDisplayName())) {
|
|
+ if (!org.spigotmc.SpigotConfig.bungee && originalFormat.equals(queueEvent.getFormat()) && originalMessage.equals(queueEvent.getMessage()) && queueEvent.getPlayer().getName().equalsIgnoreCase(queueEvent.getPlayer().getDisplayName())) { // Spigot
|
|
PlayerConnection.this.server.getPlayerList().broadcastChatMessage(original, PlayerConnection.this.player, ChatMessageType.bind(ChatMessageType.CHAT, (Entity) PlayerConnection.this.player));
|
|
return null;
|
|
}
|
|
@@ -2261,7 +2261,7 @@ public class PlayerConnection extends ServerCommonPacketListenerImpl implements
|
|
|
|
s = String.format(event.getFormat(), event.getPlayer().getDisplayName(), event.getMessage());
|
|
if (((LazyPlayerSet) event.getRecipients()).isLazy()) {
|
|
- if (originalFormat.equals(event.getFormat()) && originalMessage.equals(event.getMessage()) && event.getPlayer().getName().equalsIgnoreCase(event.getPlayer().getDisplayName())) {
|
|
+ if (!org.spigotmc.SpigotConfig.bungee && originalFormat.equals(event.getFormat()) && originalMessage.equals(event.getMessage()) && event.getPlayer().getName().equalsIgnoreCase(event.getPlayer().getDisplayName())) { // Spigot
|
|
PlayerConnection.this.server.getPlayerList().broadcastChatMessage(original, PlayerConnection.this.player, ChatMessageType.bind(ChatMessageType.CHAT, (Entity) PlayerConnection.this.player));
|
|
return;
|
|
}
|
|
@@ -2507,6 +2507,13 @@ public class PlayerConnection extends ServerCommonPacketListenerImpl implements
|
|
return this.connection.getRemoteAddress();
|
|
}
|
|
|
|
+ // Spigot Start
|
|
+ public SocketAddress getRawAddress()
|
|
+ {
|
|
+ return this.connection.channel.remoteAddress();
|
|
+ }
|
|
+ // Spigot End
|
|
+
|
|
public void switchToConfig() {
|
|
this.waitingForSwitchToConfig = true;
|
|
this.removePlayerFromWorld();
|
|
diff --git a/src/main/java/net/minecraft/server/players/NameReferencingFileConverter.java b/src/main/java/net/minecraft/server/players/NameReferencingFileConverter.java
|
|
index 1bcc5529d..4bff22370 100644
|
|
--- a/src/main/java/net/minecraft/server/players/NameReferencingFileConverter.java
|
|
+++ b/src/main/java/net/minecraft/server/players/NameReferencingFileConverter.java
|
|
@@ -64,7 +64,7 @@ public class NameReferencingFileConverter {
|
|
return new String[i];
|
|
});
|
|
|
|
- if (minecraftserver.usesAuthentication()) {
|
|
+ if (minecraftserver.usesAuthentication() || org.spigotmc.SpigotConfig.bungee) { // Spigot: bungee = online mode, for now.
|
|
minecraftserver.getProfileRepository().findProfilesByNames(astring, profilelookupcallback);
|
|
} else {
|
|
for (String s : astring) {
|
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
index 2416577dc..570a52b75 100644
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
@@ -524,7 +524,7 @@ public abstract class PlayerList {
|
|
EntityPlayer entity = new EntityPlayer(this.server, this.server.getLevel(World.OVERWORLD), gameprofile, ClientInformation.createDefault());
|
|
entity.transferCookieConnection = loginlistener;
|
|
Player player = entity.getBukkitEntity();
|
|
- PlayerLoginEvent event = new PlayerLoginEvent(player, loginlistener.connection.hostname, ((java.net.InetSocketAddress) socketaddress).getAddress());
|
|
+ PlayerLoginEvent event = new PlayerLoginEvent(player, loginlistener.connection.hostname, ((java.net.InetSocketAddress) socketaddress).getAddress(), ((java.net.InetSocketAddress) loginlistener.connection.channel.remoteAddress()).getAddress());
|
|
|
|
if (this.bans.isBanned(gameprofile)) {
|
|
GameProfileBanEntry gameprofilebanentry = (GameProfileBanEntry) this.bans.get(gameprofile);
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
index ce2f291bd..d84f4ab27 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
@@ -805,7 +805,13 @@ public final class CraftServer implements Server {
|
|
|
|
@Override
|
|
public long getConnectionThrottle() {
|
|
- return this.configuration.getInt("settings.connection-throttle");
|
|
+ // Spigot Start - Automatically set connection throttle for bungee configurations
|
|
+ if (org.spigotmc.SpigotConfig.bungee) {
|
|
+ return -1;
|
|
+ } else {
|
|
+ return this.configuration.getInt("settings.connection-throttle");
|
|
+ }
|
|
+ // Spigot End
|
|
}
|
|
|
|
@Override
|
|
@@ -1816,7 +1822,7 @@ public final class CraftServer implements Server {
|
|
if (result == null) {
|
|
GameProfile profile = null;
|
|
// Only fetch an online UUID in online mode
|
|
- if (getOnlineMode()) {
|
|
+ if (getOnlineMode() || org.spigotmc.SpigotConfig.bungee) { // Spigot: bungee = online mode, for now.
|
|
// This is potentially blocking :(
|
|
profile = console.getProfileCache().get(name).orElse(null);
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
index 2b1520c12..f728b8975 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -2353,6 +2353,12 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
private final Player.Spigot spigot = new Player.Spigot()
|
|
{
|
|
|
|
+ @Override
|
|
+ public InetSocketAddress getRawAddress()
|
|
+ {
|
|
+ return (InetSocketAddress) getHandle().connection.getRawAddress();
|
|
+ }
|
|
+
|
|
@Override
|
|
public void respawn()
|
|
{
|
|
diff --git a/src/main/java/org/spigotmc/SpigotConfig.java b/src/main/java/org/spigotmc/SpigotConfig.java
|
|
index 130016282..1e6b13103 100644
|
|
--- a/src/main/java/org/spigotmc/SpigotConfig.java
|
|
+++ b/src/main/java/org/spigotmc/SpigotConfig.java
|
|
@@ -214,4 +214,14 @@ public class SpigotConfig
|
|
commands.put( "restart", new RestartCommand( "restart" ) );
|
|
WatchdogThread.doStart( timeoutTime, restartOnCrash );
|
|
}
|
|
+
|
|
+ public static boolean bungee;
|
|
+ private static void bungee() {
|
|
+ if ( version < 4 )
|
|
+ {
|
|
+ set( "settings.bungeecord", false );
|
|
+ System.out.println( "Outdated config, disabling BungeeCord support!" );
|
|
+ }
|
|
+ bungee = getBoolean( "settings.bungeecord", false );
|
|
+ }
|
|
}
|
|
--
|
|
2.49.0
|
|
|