Java Code Examples for protocolsupport.protocol.ConnectionImpl#changeAddress()

The following examples show how to use protocolsupport.protocol.ConnectionImpl#changeAddress() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InitialPacketDecoder.java    From ProtocolSupportBungee with GNU Affero General Public License v3.0 6 votes vote down vote up
protected void setProtocol(Channel channel, ProtocolVersion version) {
	ConnectionImpl connection = prepare(channel, version);
	IPipeLineBuilder builder = InitialPacketDecoder.BUILDERS.get(connection.getVersion());
	builder.buildBungeeClientCodec(channel, connection);
	if (encapsulatedinfo == null) {
		builder.buildBungeeClientPipeLine(channel, connection);
	} else {
		ChannelPipeline pipeline = channel.pipeline();
		pipeline.replace(PipelineUtils.FRAME_DECODER, PipelineUtils.FRAME_DECODER, new VarIntFrameDecoder());
		if (encapsulatedinfo.hasCompression()) {
			pipeline.addAfter(PipelineUtils.FRAME_DECODER, "decompress", new PacketDecompressor());
			pipeline.addAfter(PipelineUtils.FRAME_PREPENDER, "compress", new PacketCompressor(256));
		}
		if ((encapsulatedinfo.getAddress() != null) && connection.getRawAddress().getAddress().isLoopbackAddress()) {
			connection.changeAddress(encapsulatedinfo.getAddress());
		}
	}
	buffer.readerIndex(0);
	channel.pipeline().firstContext().fireChannelRead(buffer.unwrap());
}
 
Example 2
Source File: InitialPacketDecoder.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
protected void setProtocol(Channel channel, ProtocolVersion version) {
	ConnectionImpl connection = prepare(channel, version);
	IPipeLineBuilder builder = pipelineBuilders.get(connection.getVersion());
	builder.buildCodec(channel, connection);
	if (encapsulatedinfo == null) {
		builder.buildPipeLine(channel, connection);
	} else {
		PlatformUtils putils = ServerPlatform.get().getMiscUtils();
		putils.setFraming(channel.pipeline(), new VarIntFrameDecoder(), new VarIntFrameEncoder());
		if (encapsulatedinfo.hasCompression()) {
			putils.enableCompression(channel.pipeline(), putils.getCompressionThreshold());
		}
		if ((encapsulatedinfo.getAddress() != null) && connection.getRawAddress().getAddress().isLoopbackAddress()) {
			connection.changeAddress(encapsulatedinfo.getAddress());
		}
	}
	buffer.readerIndex(0);
	channel.pipeline().firstContext().fireChannelRead(buffer.unwrap());
}
 
Example 3
Source File: AbstractHandshakeListener.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
public void handleSetProtocol(NetworkState nextState, String hostname, int port) {
	switch (nextState) {
		case LOGIN: {
			networkManager.setProtocol(NetworkState.LOGIN);
			try {
				final InetAddress address = networkManager.getAddress().getAddress();
				if (ThrottleTracker.isEnabled() && !ServerPlatform.get().getMiscUtils().isProxyEnabled()) {
					if (ThrottleTracker.throttle(address)) {
						disconnect("Connection throttled! Please wait before reconnecting.");
						return;
					}
				}
			} catch (Throwable t) {
				Bukkit.getLogger().log(Level.WARNING, "Failed to check connection throttle", t);
			}

			ConnectionImpl connection = ConnectionImpl.getFromChannel(networkManager.getChannel());
			if (!connection.getVersion().isSupported()) {
				disconnect(MessageFormat.format(ServerPlatform.get().getMiscUtils().getOutdatedServerMessage().replace("'", "''"), ServerPlatform.get().getMiscUtils().getVersionName()));
				break;
			}

			ConnectionHandshakeEvent event = new ConnectionHandshakeEvent(connection, hostname);
			Bukkit.getPluginManager().callEvent(event);
			if (event.getSpoofedAddress() != null) {
				connection.changeAddress(event.getSpoofedAddress());
			}
			if (event.isLoginDenied()) {
				disconnect(event.getDenyLoginMessage());
				return;
			}
			hostname = event.getHostname();
			boolean proxyEnabled = event.shouldParseHostname() && ServerPlatform.get().getMiscUtils().isProxyEnabled();
			SpoofedData sdata = SpoofedDataParser.tryParse(hostname, proxyEnabled);
			if (sdata.isFailed()) {
				disconnect(sdata.getFailMessage());
				return;
			}
			if (proxyEnabled) {
				String spoofedRemoteAddress = sdata.getAddress();
				if (spoofedRemoteAddress != null) {
					connection.changeAddress(new InetSocketAddress(sdata.getAddress(), connection.getAddress().getPort()));
				}
				networkManager.setSpoofedProfile(sdata.getUUID(), sdata.getProperties());
			}
			hostname = sdata.getHostname();

			networkManager.setPacketListener(getLoginListener(networkManager));
			break;
		}
		case STATUS: {
			networkManager.setProtocol(NetworkState.STATUS);
			networkManager.setPacketListener(getStatusListener(networkManager));
			break;
		}
		default: {
			throw new UnsupportedOperationException("Invalid intention " + nextState);
		}
	}

	if (hostname != null) {
		networkManager.setVirtualHost(InetSocketAddress.createUnresolved(hostname, port));
	} else {
		networkManager.setVirtualHost(InetSocketAddress.createUnresolved("127.0.0.1", port));
	}
}