BungeeCord Support

* Provides support for IP forwarding via BungeeCord.
* Treats Bungee as Online Mode.

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot
2014-04-12 21:23:58 +10:00
parent 496995ccaa
commit 3d4c222263
11 changed files with 206 additions and 56 deletions

View File

@@ -40,7 +40,7 @@
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.Level;
@@ -192,12 +195,70 @@
@@ -192,11 +195,69 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.BlockHitResult;
@@ -50,7 +50,7 @@
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.slf4j.Logger;
+
+// CraftBukkit start
+import com.mojang.datafixers.util.Pair;
+import java.util.Arrays;
@@ -107,10 +107,9 @@
+import org.bukkit.inventory.InventoryView;
+import org.bukkit.inventory.SmithingInventory;
+// CraftBukkit end
+
public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl implements ServerGamePacketListener, ServerPlayerConnection, TickablePacketListener {
static final Logger LOGGER = LogUtils.getLogger();
@@ -247,7 +308,7 @@
private boolean waitingForSwitchToConfig;
@@ -127,7 +126,7 @@
- this.chatMessageChain = new FutureChain(server);
+ this.chatMessageChain = new FutureChain(server.chatExecutor); // CraftBukkit - async chat
}
+
+ // CraftBukkit start - add fields and methods
+ private int lastTick = MinecraftServer.currentTick;
+ private int allowedPlayerTicks = 1;
@@ -143,7 +142,7 @@
+ private float lastYaw = Float.MAX_VALUE;
+ private boolean justTeleported = false;
+ // CraftBukkit end
+
@Override
public void tick() {
+ org.bukkit.craftbukkit.SpigotTimings.playerConnectionTimer.startTiming(); // Spigot
@@ -959,12 +958,10 @@
}
}
@@ -1564,8 +2066,123 @@
}
@@ -1566,6 +2068,121 @@
return false;
+ }
+
}
+ // CraftBukkit start - add method
+ public void chat(String s, PlayerChatMessage original, boolean async) {
+ if (s.isEmpty() || this.player.getChatVisibility() == ChatVisiblity.HIDDEN) {
@@ -997,7 +994,7 @@
+
+ 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
+ ServerGamePacketListenerImpl.this.server.getPlayerList().broadcastChatMessage(original, ServerGamePacketListenerImpl.this.player, ChatType.bind(ChatType.CHAT, (Entity) ServerGamePacketListenerImpl.this.player));
+ return null;
+ }
@@ -1033,7 +1030,7 @@
+
+ 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
+ ServerGamePacketListenerImpl.this.server.getPlayerList().broadcastChatMessage(original, ServerGamePacketListenerImpl.this.player, ChatType.bind(ChatType.CHAT, (Entity) ServerGamePacketListenerImpl.this.player));
+ return;
+ }
@@ -1049,8 +1046,8 @@
+ this.server.console.sendMessage(s);
+ }
+ }
}
+ }
+
+ private void handleCommand(String s) {
+ org.bukkit.craftbukkit.SpigotTimings.playerCommandTimer.startTiming(); // Spigot
+ if ( org.spigotmc.SpigotConfig.logCommands ) // Spigot
@@ -1197,7 +1194,21 @@
this.send(new ClientboundPlayerChatPacket(message.link().sender(), message.link().index(), message.signature(), message.signedBody().pack(this.messageSignatureCache), message.unsignedContent(), message.filterMask(), params));
this.addPendingMessage(message);
}
@@ -1718,9 +2410,17 @@
@@ -1703,6 +2395,13 @@
return this.connection.getRemoteAddress();
}
+ // Spigot Start
+ public SocketAddress getRawAddress()
+ {
+ return this.connection.channel.remoteAddress();
+ }
+ // Spigot End
+
public void switchToConfig() {
this.waitingForSwitchToConfig = true;
this.removePlayerFromWorld();
@@ -1718,9 +2417,17 @@
@Override
public void handleInteract(ServerboundInteractPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
@@ -1215,7 +1226,7 @@
this.player.resetLastActionTime();
this.player.setShiftKeyDown(packet.isUsingSecondaryAction());
@@ -1733,20 +2433,58 @@
@@ -1733,20 +2440,58 @@
if (this.player.canInteractWithEntity(axisalignedbb, 3.0D)) {
packet.dispatch(new ServerboundInteractPacket.Handler() {
@@ -1278,7 +1289,7 @@
}
}
@@ -1755,19 +2493,20 @@
@@ -1755,19 +2500,20 @@
@Override
public void onInteraction(InteractionHand hand) {
@@ -1302,7 +1313,7 @@
label23:
{
if (entity instanceof AbstractArrow) {
@@ -1785,6 +2524,11 @@
@@ -1785,6 +2531,11 @@
}
ServerGamePacketListenerImpl.this.player.attack(entity);
@@ -1314,7 +1325,7 @@
return;
}
}
@@ -1809,7 +2553,7 @@
@@ -1809,7 +2560,7 @@
case PERFORM_RESPAWN:
if (this.player.wonGame) {
this.player.wonGame = false;
@@ -1323,7 +1334,7 @@
this.resetPosition();
CriteriaTriggers.CHANGED_DIMENSION.trigger(this.player, Level.END, Level.OVERWORLD);
} else {
@@ -1817,11 +2561,11 @@
@@ -1817,11 +2568,11 @@
return;
}
@@ -1337,7 +1348,7 @@
}
}
break;
@@ -1834,15 +2578,21 @@
@@ -1834,15 +2585,21 @@
@Override
public void handleContainerClose(ServerboundContainerClosePacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
@@ -1361,7 +1372,7 @@
this.player.containerMenu.sendAllDataToRemote();
} else if (!this.player.containerMenu.stillValid(this.player)) {
ServerGamePacketListenerImpl.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, this.player.containerMenu);
@@ -1855,7 +2605,284 @@
@@ -1855,7 +2612,284 @@
boolean flag = packet.getStateId() != this.player.containerMenu.getStateId();
this.player.containerMenu.suppressRemoteUpdates();
@@ -1647,7 +1658,7 @@
ObjectIterator objectiterator = Int2ObjectMaps.fastIterable(packet.getChangedSlots()).iterator();
while (objectiterator.hasNext()) {
@@ -1901,8 +2928,22 @@
@@ -1901,8 +2935,22 @@
return;
}
@@ -1671,7 +1682,7 @@
if (containerrecipebook_a == RecipeBookMenu.PostPlaceAction.PLACE_GHOST_RECIPE) {
this.player.connection.send(new ClientboundPlaceGhostRecipePacket(this.player.containerMenu.containerId, craftingmanager_d.display().display()));
}
@@ -1917,6 +2958,7 @@
@@ -1917,6 +2965,7 @@
@Override
public void handleContainerButtonClick(ServerboundContainerButtonClickPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
@@ -1679,7 +1690,7 @@
this.player.resetLastActionTime();
if (this.player.containerMenu.containerId == packet.containerId() && !this.player.isSpectator()) {
if (!this.player.containerMenu.stillValid(this.player)) {
@@ -1945,7 +2987,44 @@
@@ -1945,7 +2994,44 @@
boolean flag1 = packet.slotNum() >= 1 && packet.slotNum() <= 45;
boolean flag2 = itemstack.isEmpty() || itemstack.getCount() <= itemstack.getMaxStackSize();
@@ -1724,7 +1735,7 @@
if (flag1 && flag2) {
this.player.inventoryMenu.getSlot(packet.slotNum()).setByPlayer(itemstack);
this.player.inventoryMenu.setRemoteSlot(packet.slotNum(), itemstack);
@@ -1972,6 +3051,7 @@
@@ -1972,6 +3058,7 @@
}
private void updateSignText(ServerboundSignUpdatePacket packet, List<FilteredText> signText) {
@@ -1732,7 +1743,7 @@
this.player.resetLastActionTime();
ServerLevel worldserver = this.player.serverLevel();
BlockPos blockposition = packet.getPos();
@@ -1993,7 +3073,17 @@
@@ -1993,7 +3080,17 @@
@Override
public void handlePlayerAbilities(ServerboundPlayerAbilitiesPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
@@ -1751,7 +1762,7 @@
}
@Override
@@ -2058,7 +3148,7 @@
@@ -2058,7 +3155,7 @@
if (!this.waitingForSwitchToConfig) {
throw new IllegalStateException("Client acknowledged config, but none was requested");
} else {
@@ -1760,7 +1771,7 @@
}
}
@@ -2083,8 +3173,10 @@
@@ -2083,8 +3180,10 @@
});
}

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/server/network/ServerHandshakePacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerHandshakePacketListenerImpl.java
@@ -13,8 +13,17 @@
@@ -13,8 +13,22 @@
import net.minecraft.network.protocol.status.StatusProtocols;
import net.minecraft.server.MinecraftServer;
@@ -11,6 +11,11 @@
+
public class ServerHandshakePacketListenerImpl implements ServerHandshakePacketListener {
+ // 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;
@@ -18,7 +23,7 @@
private static final Component IGNORE_STATUS_REASON = Component.translatable("disconnect.ignoring_status_request");
private final MinecraftServer server;
private final Connection connection;
@@ -26,6 +35,7 @@
@@ -26,6 +40,7 @@
@Override
public void handleIntention(ClientIntentionPacket packet) {
@@ -26,7 +31,7 @@
switch (packet.intention()) {
case LOGIN:
this.beginLogin(packet, false);
@@ -59,13 +69,47 @@
@@ -59,19 +74,78 @@
private void beginLogin(ClientIntentionPacket packet, boolean transfer) {
this.connection.setupOutboundProtocol(LoginProtocols.CLIENTBOUND);
@@ -77,3 +82,34 @@
}
this.connection.send(new ClientboundLoginDisconnectPacket(ichatmutablecomponent));
this.connection.disconnect((Component) ichatmutablecomponent);
} else {
this.connection.setupInboundProtocol(LoginProtocols.SERVERBOUND, new ServerLoginPacketListenerImpl(this.server, this.connection, transfer));
+ // Spigot Start
+ String[] split = packet.hostName().split("\00");
+ if (org.spigotmc.SpigotConfig.bungee) {
+ if ( ( split.length == 3 || split.length == 4 ) && ( ServerHandshakePacketListenerImpl.HOST_PATTERN.matcher( split[1] ).matches() ) ) {
+ this.connection.hostname = split[0];
+ this.connection.address = new java.net.InetSocketAddress(split[1], ((java.net.InetSocketAddress) this.connection.getRemoteAddress()).getPort());
+ this.connection.spoofedUUID = com.mojang.util.UndashedUuid.fromStringLenient( split[2] );
+ } else
+ {
+ Component chatmessage = Component.literal("If you wish to use IP forwarding, please enable it in your BungeeCord config as well!");
+ this.connection.send(new ClientboundLoginDisconnectPacket(chatmessage));
+ this.connection.disconnect(chatmessage);
+ return;
+ }
+ if ( split.length == 4 )
+ {
+ this.connection.spoofedProfile = ServerHandshakePacketListenerImpl.gson.fromJson(split[3], com.mojang.authlib.properties.Property[].class);
+ }
+ } else if ( ( split.length == 3 || split.length == 4 ) && ( ServerHandshakePacketListenerImpl.HOST_PATTERN.matcher( split[1] ).matches() ) ) {
+ Component chatmessage = Component.literal("Unknown data in login hostname, did you forget to enable BungeeCord in spigot.yml?");
+ this.connection.send(new ClientboundLoginDisconnectPacket(chatmessage));
+ this.connection.disconnect(chatmessage);
+ return;
+ }
+ // Spigot End
}
}

View File

@@ -99,7 +99,7 @@
+ @Override
+ public void run() {
+ try {
+ GameProfile gameprofile = UUIDUtil.createOfflineProfile(ServerLoginPacketListenerImpl.this.requestedUsername);
+ GameProfile gameprofile = ServerLoginPacketListenerImpl.this.createOfflineProfile(ServerLoginPacketListenerImpl.this.requestedUsername); // Spigot
+
+ ServerLoginPacketListenerImpl.this.callPlayerPreLoginEvents(gameprofile);
+ ServerLoginPacketListenerImpl.LOGGER.info("UUID of player {} is {}", gameprofile.getName(), gameprofile.getId());
@@ -160,7 +160,7 @@
}
}
@@ -205,6 +281,12 @@
@@ -205,11 +281,17 @@
if (profileresult != null) {
GameProfile gameprofile = profileresult.profile();
@@ -173,7 +173,19 @@
ServerLoginPacketListenerImpl.LOGGER.info("UUID of player {} is {}", gameprofile.getName(), gameprofile.getId());
ServerLoginPacketListenerImpl.this.startClientVerification(gameprofile);
} else if (ServerLoginPacketListenerImpl.this.server.isSingleplayer()) {
@@ -222,6 +304,11 @@
ServerLoginPacketListenerImpl.LOGGER.warn("Failed to verify username but will let them in anyway!");
- ServerLoginPacketListenerImpl.this.startClientVerification(UUIDUtil.createOfflineProfile(s1));
+ ServerLoginPacketListenerImpl.this.startClientVerification(ServerLoginPacketListenerImpl.this.createOfflineProfile(s1)); // Spigot
} else {
ServerLoginPacketListenerImpl.this.disconnect(Component.translatable("multiplayer.disconnect.unverified_username"));
ServerLoginPacketListenerImpl.LOGGER.error("Username '{}' tried to join with an invalid session", s1);
@@ -217,11 +299,16 @@
} catch (AuthenticationUnavailableException authenticationunavailableexception) {
if (ServerLoginPacketListenerImpl.this.server.isSingleplayer()) {
ServerLoginPacketListenerImpl.LOGGER.warn("Authentication servers are down but will let them in anyway!");
- ServerLoginPacketListenerImpl.this.startClientVerification(UUIDUtil.createOfflineProfile(s1));
+ ServerLoginPacketListenerImpl.this.startClientVerification(ServerLoginPacketListenerImpl.this.createOfflineProfile(s1)); // Spigot
} else {
ServerLoginPacketListenerImpl.this.disconnect(Component.translatable("multiplayer.disconnect.authservers_down"));
ServerLoginPacketListenerImpl.LOGGER.error("Couldn't verify username because servers are unavailable");
}
@@ -242,7 +254,7 @@
this.connection.setupInboundProtocol(ConfigurationProtocols.SERVERBOUND, serverconfigurationpacketlistenerimpl);
serverconfigurationpacketlistenerimpl.startConfiguration();
@@ -264,12 +389,18 @@
@@ -264,12 +389,44 @@
@Override
public void handleCookieResponse(ServerboundCookieResponsePacket packet) {
@@ -255,6 +267,32 @@
this.disconnect(ServerCommonPacketListenerImpl.DISCONNECT_UNEXPECTED_QUERY);
}
+ // Spigot start
+ protected GameProfile createOfflineProfile(String s) {
+ java.util.UUID uuid;
+ if ( this.connection.spoofedUUID != null )
+ {
+ uuid = this.connection.spoofedUUID;
+ } else
+ {
+ uuid = UUIDUtil.createOfflinePlayerUUID( s );
+ }
+
+ GameProfile gameProfile = new GameProfile( uuid, s );
+
+ if (this.connection.spoofedProfile != null)
+ {
+ for ( com.mojang.authlib.properties.Property property : this.connection.spoofedProfile )
+ {
+ if ( !ServerHandshakePacketListenerImpl.PROP_PATTERN.matcher( property.name()).matches() ) continue;
+ gameProfile.getProperties().put( property.name(), property );
+ }
+ }
+
+ return gameProfile;
+ }
+ // Spigot end
+
public static enum State {
- HELLO, KEY, AUTHENTICATING, NEGOTIATING, VERIFYING, WAITING_FOR_DUPE_DISCONNECT, PROTOCOL_SWITCHING, ACCEPTED;