@Override public void handle(PacketWrapper packet) throws Exception { con.getEntityRewrite().rewriteClientbound( packet.buf, con.getServerEntityId(), con.getClientEntityId(), con.getPendingConnection().getVersion() ); con.sendPacket( packet ); }
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 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 exception(Throwable t) throws Exception { if ( obsolete ) { return; } String message = "Exception Connecting:" + Util.exception( t ); if ( user.getServer() == null ) { user.disconnect( message ); } else { user.sendMessage( ChatColor.RED + message ); } }
@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 ); } }
ch.write( BungeeCord.getInstance().registerChannels( user.getPendingConnection().getVersion() ) ); Queue<DefinedPacket> packetQueue = target.getPacketQueue(); synchronized ( packetQueue ) for ( PluginMessage message : user.getPendingConnection().getRelayMessages() ) if ( user.getSettings() != null ) ch.write( user.getSettings() ); if ( user.getForgeClientHandler().getClientModList() == null && !user.getForgeClientHandler().isHandshakeComplete() ) // Vanilla user.getForgeClientHandler().setHandshakeComplete(); if ( user.getServer() == null ) user.setClientEntityId( login.getEntityId() ); user.setServerEntityId( login.getEntityId() ); (byte) user.getPendingConnection().getListener().getTabListSize(), login.getLevelType(), login.isReducedDebugInfo() ); user.unsafe().sendPacket( modLogin ); user.unsafe().sendPacket( new PluginMessage( user.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_13 ? "minecraft:brand" : "MC|Brand", DefinedPacket.toArray( brand ), handshakeHandler.isServerForge() ) ); brand.release(); user.setDimension( login.getDimension() ); } else
for ( PluginMessage message : user.getPendingConnection().getRegisterMessages() ) if ( user.getSettings() != null ) ch.write( user.getSettings() ); if ( user.getForgeClientHandler().getClientModList() == null && !user.getForgeClientHandler().isHandshakeComplete() ) // Vanilla user.getForgeClientHandler().setHandshakeComplete(); if ( user.getServer() == null ) user.setClientEntityId( login.getEntityId() ); user.setServerEntityId( login.getEntityId() ); (byte) user.getPendingConnection().getListener().getTabListSize(), login.getLevelType(), login.isReducedDebugInfo() ); user.unsafe().sendPacket( modLogin ); if ( user.getPendingConnection().getVersion() < ProtocolConstants.MINECRAFT_1_8 ) user.unsafe().sendPacket( new PluginMessage( "MC|Brand", brandString.getBytes(StandardCharsets.UTF_8), handshakeHandler.isServerForge() ) ); } else user.unsafe().sendPacket( new PluginMessage( "MC|Brand", brand, handshakeHandler.isServerForge() ) ); brand.release(); user.getServer().setObsolete( true ); user.getTabListHandler().onServerChange();
if ( pluginMessage.getTag().equals( con.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_13 ? "minecraft:brand" : "MC|Brand" ) ) brand.release(); con.unsafe().sendPacket( pluginMessage ); throw CancelSendSignal.INSTANCE; if ( server != null ) con.connect( server, ServerConnectEvent.Reason.PLUGIN_MESSAGE ); out.writeUTF( con.getAddress().getHostString() ); out.writeInt( con.getAddress().getPort() ); out.writeUTF( con.getUUID() );
if ( player != null ) item.setUuid( player.getUniqueId() ); LoginResult loginResult = player.getPendingConnection().getLoginProfile(); if ( loginResult != null && loginResult.getProperties() != null ) player.setGamemode( item.getGamemode() ); player.setPing( item.getPing() );
@Override public String getUUID() { return getPendingConnection().getUUID(); }
@Override @SuppressWarnings("ThrowableResultIgnored") public void operationComplete(ChannelFuture future) throws Exception { if ( callback != null ) { callback.done( ( future.isSuccess() ) ? ServerConnectRequest.Result.SUCCESS : ServerConnectRequest.Result.FAIL, future.cause() ); } if ( !future.isSuccess() ) { future.channel().close(); pendingConnects.remove( target ); ServerInfo def = updateAndGetNextServer( target ); if ( request.isRetry() && def != null && ( getServer() == null || def != getServer().getInfo() ) ) { sendMessage( bungee.getTranslation( "fallback_lobby" ) ); connect( def, null, true, ServerConnectEvent.Reason.LOBBY_FALLBACK ); } else if ( dimensionChange ) { disconnect( bungee.getTranslation( "fallback_kick", future.cause().getClass().getName() ) ); } else { sendMessage( bungee.getTranslation( "fallback_kick", future.cause().getClass().getName() ) ); } } } };
@Override public void handle(Kick kick) throws Exception { ServerInfo def = user.updateAndGetNextServer( target ); ServerKickEvent event = new ServerKickEvent( user, target, ComponentSerializer.parse( kick.getMessage() ), def, ServerKickEvent.State.CONNECTING ); if ( event.getKickReason().toLowerCase( Locale.ROOT ).contains( "outdated" ) && def != null ) { // Pre cancel the event if we are going to try another server event.setCancelled( true ); } bungee.getPluginManager().callEvent( event ); if ( event.isCancelled() && event.getCancelServer() != null ) { obsolete = true; user.connect( event.getCancelServer(), ServerConnectEvent.Reason.KICK_REDIRECT ); throw CancelSendSignal.INSTANCE; } String message = bungee.getTranslation( "connect_kick", target.getName(), event.getKickReason() ); if ( user.isDimensionChange() ) { user.disconnect( message ); } else { user.sendMessage( message ); } throw CancelSendSignal.INSTANCE; }
@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() ) ); }
Handshake originalHandshake = user.getPendingConnection().getHandshake(); Handshake copiedHandshake = new Handshake( originalHandshake.getProtocolVersion(), originalHandshake.getHost(), originalHandshake.getPort(), 2 ); String newHost = copiedHandshake.getHost() + "\00" + user.getAddress().getHostString() + "\00" + user.getUUID(); LoginResult profile = user.getPendingConnection().getLoginProfile(); if ( user.getForgeClientHandler().isFmlTokenInHandshake() ) newp[newp.length - 1] = new LoginResult.Property( ForgeConstants.EXTRA_DATA, user.getExtraDataInHandshake().replaceAll( "\0", "\1"), "" ); } else if ( !user.getExtraDataInHandshake().isEmpty() ) copiedHandshake.setHost( copiedHandshake.getHost() + user.getExtraDataInHandshake() ); channel.write( user.getPendingConnection().getLoginRequest() );
con.getTabListHandler().onDisconnect(); BungeeCord.getInstance().removeConnection( con ); if ( con.getServer() != null ) packet.setAction( PlayerListItem.Action.REMOVE_PLAYER ); PlayerListItem.Item item = new PlayerListItem.Item(); item.setUuid( con.getUniqueId() ); packet.setItems( new PlayerListItem.Item[] for ( ProxiedPlayer player : con.getServer().getInfo().getPlayers() ) con.getServer().disconnect( "Quitting" );
con.getForgeClientHandler().handle( pluginMessage ); throw CancelSendSignal.INSTANCE; if ( con.getServer() != null && !con.getServer().isForgeServer() && pluginMessage.getData().length > Short.MAX_VALUE ) PluginMessageEvent event = new PluginMessageEvent( con, con.getServer(), pluginMessage.getTag(), pluginMessage.getData().clone() ); if ( bungee.getPluginManager().callEvent( event ).isCancelled() ) con.getPendingConnection().getRelayMessages().add( pluginMessage );
if ( getServer() == null && !ch.isClosing() ) if ( getServer() != null && Objects.equals( getServer().getInfo(), target ) ) sendMessage( bungee.getTranslation( "already_connected" ) ); return; sendMessage( bungee.getTranslation( "already_connecting" ) ); return; .remoteAddress( target.getAddress() ); if ( getPendingConnection().getListener().isSetLocalAddress() && !PlatformDependent.isWindows() ) b.localAddress( getPendingConnection().getListener().getHost().getHostString(), 0 );
@Override public void exception(Throwable t) throws Exception { if ( server.isObsolete() ) { // do not perform any actions if the user has already moved return; } ServerInfo def = con.updateAndGetNextServer( server.getInfo() ); if ( def != null ) { server.setObsolete( true ); con.connectNow( def, ServerConnectEvent.Reason.SERVER_DOWN_REDIRECT ); con.sendMessage( bungee.getTranslation( "server_went_down" ) ); } else { con.disconnect( Util.exception( t ) ); } }
@Override public void exception(Throwable t) throws Exception { if ( server.isObsolete() ) { // do not perform any actions if the user has already moved return; } ServerInfo def = bungee.getServerInfo( con.getPendingConnection().getListener().getFallbackServer() ); if ( server.getInfo() != def ) { server.setObsolete( true ); con.connectNow( def ); con.sendMessage( bungee.getTranslation( "server_went_down" ) ); } else { con.disconnect( Util.exception( t ) ); } }
if ( player != null ) LoginResult profile = player.getPendingConnection().getLoginProfile(); if ( profile != null && profile.getProperties() != null && profile.getProperties().length >= 1 ) packet.readerIndex( readerIndex ); packet.writerIndex( readerIndex + packetIdLength + idLength ); DefinedPacket.writeString( player.getUniqueId().toString(), packet ); DefinedPacket.writeString( username, packet ); DefinedPacket.writeVarInt( profile.getProperties().length, packet );