@Override public String getUUID() { return getPendingConnection().getUUID(); }
@Override public UUID getUniqueId() { return getPendingConnection().getUniqueId(); }
public String getExtraDataInHandshake() { return this.getPendingConnection().getExtraDataInHandshake(); }
public void addConnection(UserConnection con) { connectionLock.writeLock().lock(); try { connections.put( con.getName(), con ); connectionsByUUID.put( con.getUniqueId(), con ); connectionsByOfflineUUID.put( con.getPendingConnection().getOfflineId(), con ); } finally { connectionLock.writeLock().unlock(); } }
public void removeConnection(UserConnection con) { connectionLock.writeLock().lock(); try { // TODO See #1218 if ( connections.get( con.getName() ) == con ) { connections.remove( con.getName() ); connectionsByUUID.remove( con.getUniqueId() ); connectionsByOfflineUUID.remove( con.getPendingConnection().getOfflineId() ); } } finally { connectionLock.writeLock().unlock(); } }
@Override protected void initChannel(Channel ch) throws Exception { PipelineUtils.BASE.initChannel( ch ); ch.pipeline().addAfter( PipelineUtils.FRAME_DECODER, PipelineUtils.PACKET_DECODER, new MinecraftDecoder( Protocol.HANDSHAKE, false, getPendingConnection().getVersion() ) ); ch.pipeline().addAfter( PipelineUtils.FRAME_PREPENDER, PipelineUtils.PACKET_ENCODER, new MinecraftEncoder( Protocol.HANDSHAKE, false, getPendingConnection().getVersion() ) ); ch.pipeline().get( HandlerBoss.class ).setHandler( new ServerConnector( bungee, UserConnection.this, target ) ); } };
public ServerInfo updateAndGetNextServer(ServerInfo currentTarget) { if ( serverJoinQueue == null ) { serverJoinQueue = new LinkedList<>( getPendingConnection().getListener().getServerPriority() ); } ServerInfo next = null; while ( !serverJoinQueue.isEmpty() ) { ServerInfo candidate = ProxyServer.getInstance().getServerInfo( serverJoinQueue.remove() ); if ( !Objects.equals( currentTarget, candidate ) ) { next = candidate; break; } } return next; }
@Override public void rewriteServerbound(ByteBuf packet, int oldId, int newId) { super.rewriteServerbound( packet, oldId, newId ); //Special cases int readerIndex = packet.readerIndex(); int packetId = DefinedPacket.readVarInt( packet ); int packetIdLength = packet.readerIndex() - readerIndex; if ( packetId == 0x18 /* Spectate */ && !BungeeCord.getInstance().getConfig().isIpForward() ) { UUID uuid = DefinedPacket.readUUID( packet ); ProxiedPlayer player; if ( ( player = BungeeCord.getInstance().getPlayer( uuid ) ) != null ) { int previous = packet.writerIndex(); packet.readerIndex( readerIndex ); packet.writerIndex( readerIndex + packetIdLength ); DefinedPacket.writeUUID( ( (UserConnection) player ).getPendingConnection().getOfflineId(), packet ); packet.writerIndex( previous ); } } packet.readerIndex( readerIndex ); } }
@Override public void rewriteServerbound(ByteBuf packet, int oldId, int newId) { super.rewriteServerbound( packet, oldId, newId ); // Special cases int readerIndex = packet.readerIndex(); int packetId = DefinedPacket.readVarInt( packet ); int packetIdLength = packet.readerIndex() - readerIndex; if ( packetId == 0x28 /* Spectate : PacketPlayInSpectate */ && !BungeeCord.getInstance().getConfig().isIpForward() ) { UUID uuid = DefinedPacket.readUUID( packet ); ProxiedPlayer player; if ( ( player = BungeeCord.getInstance().getPlayer( uuid ) ) != null ) { int previous = packet.writerIndex(); packet.readerIndex( readerIndex ); packet.writerIndex( readerIndex + packetIdLength ); DefinedPacket.writeUUID( ( (UserConnection) player ).getPendingConnection().getOfflineId(), packet ); packet.writerIndex( previous ); } } packet.readerIndex( readerIndex ); } }
@Override public void rewriteServerbound(ByteBuf packet, int oldId, int newId) { super.rewriteServerbound( packet, oldId, newId ); // Special cases int readerIndex = packet.readerIndex(); int packetId = DefinedPacket.readVarInt( packet ); int packetIdLength = packet.readerIndex() - readerIndex; if ( packetId == 0x1B /* Spectate : PacketPlayInSpectate */ && !BungeeCord.getInstance().getConfig().isIpForward() ) { UUID uuid = DefinedPacket.readUUID( packet ); ProxiedPlayer player; if ( ( player = BungeeCord.getInstance().getPlayer( uuid ) ) != null ) { int previous = packet.writerIndex(); packet.readerIndex( readerIndex ); packet.writerIndex( readerIndex + packetIdLength ); DefinedPacket.writeUUID( ( (UserConnection) player ).getPendingConnection().getOfflineId(), packet ); packet.writerIndex( previous ); } } packet.readerIndex( readerIndex ); } }
@Override public void rewriteServerbound(ByteBuf packet, int oldId, int newId) { super.rewriteServerbound( packet, oldId, newId ); // Special cases int readerIndex = packet.readerIndex(); int packetId = DefinedPacket.readVarInt( packet ); int packetIdLength = packet.readerIndex() - readerIndex; if ( packetId == 0x1B /* Spectate : PacketPlayInSpectate */ && !BungeeCord.getInstance().getConfig().isIpForward() ) { UUID uuid = DefinedPacket.readUUID( packet ); ProxiedPlayer player; if ( ( player = BungeeCord.getInstance().getPlayer( uuid ) ) != null ) { int previous = packet.writerIndex(); packet.readerIndex( readerIndex ); packet.writerIndex( readerIndex + packetIdLength ); DefinedPacket.writeUUID( ( (UserConnection) player ).getPendingConnection().getOfflineId(), packet ); packet.writerIndex( previous ); } } packet.readerIndex( readerIndex ); } }
@Override public void rewriteServerbound(ByteBuf packet, int oldId, int newId) { super.rewriteServerbound( packet, oldId, newId ); // Special cases int readerIndex = packet.readerIndex(); int packetId = DefinedPacket.readVarInt( packet ); int packetIdLength = packet.readerIndex() - readerIndex; if ( packetId == 0x1B /* Spectate : PacketPlayInSpectate */ && !BungeeCord.getInstance().getConfig().isIpForward() ) { UUID uuid = DefinedPacket.readUUID( packet ); ProxiedPlayer player; if ( ( player = BungeeCord.getInstance().getPlayer( uuid ) ) != null ) { int previous = packet.writerIndex(); packet.readerIndex( readerIndex ); packet.writerIndex( readerIndex + packetIdLength ); DefinedPacket.writeUUID( ( (UserConnection) player ).getPendingConnection().getOfflineId(), packet ); packet.writerIndex( previous ); } } packet.readerIndex( readerIndex ); } }
@Override public void rewriteServerbound(ByteBuf packet, int oldId, int newId) { super.rewriteServerbound( packet, oldId, newId ); // Special cases int readerIndex = packet.readerIndex(); int packetId = DefinedPacket.readVarInt( packet ); int packetIdLength = packet.readerIndex() - readerIndex; if ( packetId == 0x1E /* Spectate : PacketPlayInSpectate */ && !BungeeCord.getInstance().getConfig().isIpForward() ) { UUID uuid = DefinedPacket.readUUID( packet ); ProxiedPlayer player; if ( ( player = BungeeCord.getInstance().getPlayer( uuid ) ) != null ) { int previous = packet.writerIndex(); packet.readerIndex( readerIndex ); packet.writerIndex( readerIndex + packetIdLength ); DefinedPacket.writeUUID( ( (UserConnection) player ).getPendingConnection().getOfflineId(), packet ); packet.writerIndex( previous ); } } packet.readerIndex( readerIndex ); } }
@Override public void rewriteServerbound(ByteBuf packet, int oldId, int newId) { super.rewriteServerbound( packet, oldId, newId ); // Special cases int readerIndex = packet.readerIndex(); int packetId = DefinedPacket.readVarInt( packet ); int packetIdLength = packet.readerIndex() - readerIndex; if ( packetId == 0x1B /* Spectate : PacketPlayInSpectate */ && !BungeeCord.getInstance().getConfig().isIpForward() ) { UUID uuid = DefinedPacket.readUUID( packet ); ProxiedPlayer player; if ( ( player = BungeeCord.getInstance().getPlayer( uuid ) ) != null ) { int previous = packet.writerIndex(); packet.readerIndex( readerIndex ); packet.writerIndex( readerIndex + packetIdLength ); DefinedPacket.writeUUID( ( (UserConnection) player ).getPendingConnection().getOfflineId(), packet ); packet.writerIndex( previous ); } } packet.readerIndex( readerIndex ); } }
public void init() { this.entityRewrite = EntityMap.getEntityMap( getPendingConnection().getVersion() ); this.displayName = name; tabListHandler = new ServerUnique( this ); Collection<String> g = bungee.getConfigurationAdapter().getGroups( name ); g.addAll( bungee.getConfigurationAdapter().getGroups( getUniqueId().toString() ) ); for ( String s : g ) { addGroups( s ); } forgeClientHandler = new ForgeClientHandler( this ); // Set whether the connection has a 1.8 FML marker in the handshake. forgeClientHandler.setFmlTokenInHandshake( this.getPendingConnection().getExtraDataInHandshake().contains( ForgeConstants.FML_HANDSHAKE_TOKEN ) ); }
@Override public void handle(PacketWrapper packet) throws Exception { con.getEntityRewrite().rewriteClientbound( packet.buf, con.getServerEntityId(), con.getClientEntityId(), con.getPendingConnection().getVersion() ); con.sendPacket( packet ); }
@Override public void handle(Chat chat) throws Exception { int maxLength = ( con.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_11 ) ? 256 : 100; Preconditions.checkArgument( chat.getMessage().length() <= maxLength, "Chat message too long" ); // Mojang limit, check on updates ChatEvent chatEvent = new ChatEvent( con, con.getServer(), chat.getMessage() ); if ( !bungee.getPluginManager().callEvent( chatEvent ).isCancelled() ) { chat.setMessage( chatEvent.getMessage() ); if ( !chatEvent.isCommand() || !bungee.getPluginManager().dispatchCommand( con, chat.getMessage().substring( 1 ) ) ) { con.getServer().unsafe().sendPacket( chat ); } } throw CancelSendSignal.INSTANCE; }
public UpstreamBridge(ProxyServer bungee, UserConnection con) { this.bungee = bungee; this.con = con; BungeeCord.getInstance().addConnection( con ); con.getTabListHandler().onConnect(); con.unsafe().sendPacket( BungeeCord.getInstance().registerChannels( con.getPendingConnection().getVersion() ) ); }
@Override public void handle(PacketWrapper packet) throws Exception { if ( con.getServer() != null ) { con.getEntityRewrite().rewriteServerbound( packet.buf, con.getClientEntityId(), con.getServerEntityId(), con.getPendingConnection().getVersion() ); con.getServer().getCh().write( packet ); } }
@Override public void connected(ChannelWrapper channel) throws Exception { this.ch = channel; this.handshakeHandler = new ForgeServerHandler( user, ch, target ); Handshake originalHandshake = user.getPendingConnection().getHandshake(); Handshake copiedHandshake = new Handshake( originalHandshake.getProtocolVersion(), originalHandshake.getHost(), originalHandshake.getPort(), 2 ); if ( BungeeCord.getInstance().config.isIpForward() ) { String newHost = copiedHandshake.getHost() + "\00" + user.getAddress().getHostString() + "\00" + user.getUUID(); LoginResult profile = user.getPendingConnection().getLoginProfile(); if ( profile != null && profile.getProperties() != null && profile.getProperties().length > 0 ) { newHost += "\00" + BungeeCord.getInstance().gson.toJson( profile.getProperties() ); } copiedHandshake.setHost( newHost ); } else if ( !user.getExtraDataInHandshake().isEmpty() ) { // Only restore the extra data if IP forwarding is off. // TODO: Add support for this data with IP forwarding. copiedHandshake.setHost( copiedHandshake.getHost() + user.getExtraDataInHandshake() ); } channel.write( copiedHandshake ); channel.setProtocol( Protocol.LOGIN ); channel.write( new LoginRequest( user.getName() ) ); }