Java Code Examples for net.minecraft.util.io.netty.channel.Channel

The following examples show how to use net.minecraft.util.io.netty.channel.Channel. These examples are extracted from open source projects. 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
@Override
protected void initChannel(Channel channel) {
	try {
		channel.config().setOption(ChannelOption.IP_TOS, Integer.valueOf(24));
	} catch (ChannelException channelexception) {
	}
	try {
		channel.config().setOption(ChannelOption.TCP_NODELAY, Boolean.valueOf(false));
	} catch (ChannelException channelexception1) {
	}
	channel.pipeline()
	.addLast("timeout", new ReadTimeoutHandler(30))
	.addLast("legacy_query", new LegacyPingHandler(connection))
	.addLast("splitter", new PacketSplitter())
	.addLast("decoder", new PacketDecoder(NetworkManager.h))
	.addLast("prepender", new PacketPrepender())
	.addLast("encoder", new PacketEncoder(NetworkManager.h));
	NetworkManager networkmanager = new NetworkManager(false);

	networkManagers.add(networkmanager);
	channel.pipeline().addLast("packet_handler", networkmanager);
	networkmanager.a(new HandshakeListener(MinecraftServer.getServer(), networkmanager));
}
 
Example 2
Source Project: PingAPI   Source File: PingInjector.java    License: MIT License 5 votes vote down vote up
/**
 * Iterates through every open NetworkManager and adds my ChannelDuplexHandler subclass into the pipeline
 * This allows you to listen for outgoing packets and modify them before they are sent
 * 
 * The List of NetworkManager instances is converted to an array to avoid ConcurrentModificationExceptions
 * NullPointerExceptions, IllegalArgumentExceptions, and NoSuchElementException only occur if there is a massive amount of ping requests being sent to the server.
 * NullPointerExceptions are thrown when the pipeline has yet to be created. 
 * Since ping responses are handled on separate threads IllegalArgumentExceptions are thrown when this method is invoked at the same time on two different threads
 * This means the null check will be passed and this method will attempt to create a duplicate handler which throws this exception
 * NoSuchElementExceptions have a similar cause. They are caused when the "packet_handler" has yet to be added.
 * The best solution I could find is simply ignoring these exceptions
 */
public void injectOpenConnections() {
	try {
		Field field = ReflectUtils.getFirstFieldByType(NetworkManager.class, Channel.class);
		field.setAccessible(true);
		for(Object manager : networkManagers.toArray()) {
			Channel channel = (Channel) field.get(manager);
			if(channel.pipeline().context("pingapi_handler") == null && (channel.pipeline().context("packet_handler") != null)) {
				channel.pipeline().addBefore("packet_handler", "pingapi_handler", new DuplexHandler());
			}
		}
	} catch(IllegalAccessException e) {
		e.printStackTrace();
	} catch(NullPointerException | IllegalArgumentException | NoSuchElementException ignored) {}
}
 
Example 3
Source Project: PingAPI   Source File: PingInjector.java    License: MIT License 5 votes vote down vote up
/**
 * Iterates through every open NetworkManager and adds my ChannelDuplexHandler subclass into the pipeline
 * This allows you to listen for outgoing packets and modify them before they are sent
 * 
 * The List of NetworkManager instances is converted to an array to avoid ConcurrentModificationExceptions
 * NullPointerExceptions, IllegalArgumentExceptions, and NoSuchElementException only occur if there is a massive amount of ping requests being sent to the server.
 * NullPointerExceptions are thrown when the pipeline has yet to be created. 
 * Since ping responses are handled on separate threads IllegalArgumentExceptions are thrown when this method is invoked at the same time on two different threads
 * This means the null check will be passed and this method will attempt to create a duplicate handler which throws this exception
 * NoSuchElementExceptions have a similar cause. They are caused when the "packet_handler" has yet to be added.
 * The best solution I could find is simply ignoring these exceptions
 */
public void injectOpenConnections() {
	try {
		Field field = ReflectUtils.getFirstFieldByType(NetworkManager.class, Channel.class);
		field.setAccessible(true);
		for(Object manager : networkManagers.toArray()) {
			Channel channel = (Channel) field.get(manager);
			if(channel.pipeline().context("pingapi_handler") == null && (channel.pipeline().context("packet_handler") != null)) {
				channel.pipeline().addBefore("packet_handler", "pingapi_handler", new DuplexHandler());
			}
		}
	} catch(IllegalAccessException e) {
		e.printStackTrace();
	} catch(NullPointerException | IllegalArgumentException | NoSuchElementException ignored) {}
}
 
Example 4
Source Project: PingAPI   Source File: PingInjector.java    License: MIT License 5 votes vote down vote up
/**
 * Iterates through every open NetworkManager and adds my ChannelDuplexHandler subclass into the pipeline
 * This allows you to listen for outgoing packets and modify them before they are sent
 * 
 * The List of NetworkManager instances is converted to an array to avoid ConcurrentModificationExceptions
 * NullPointerExceptions, IllegalArgumentExceptions, and NoSuchElementException only occur if there is a massive amount of ping requests being sent to the server.
 * NullPointerExceptions are thrown when the pipeline has yet to be created. 
 * Since ping responses are handled on separate threads IllegalArgumentExceptions are thrown when this method is invoked at the same time on two different threads
 * This means the null check will be passed and this method will attempt to create a duplicate handler which throws this exception
 * NoSuchElementExceptions have a similar cause. They are caused when the "packet_handler" has yet to be added.
 * The best solution I could find is simply ignoring these exceptions
 */
public void injectOpenConnections() {
	try {
		Field field = ReflectUtils.getFirstFieldByType(NetworkManager.class, Channel.class);
		field.setAccessible(true);
		for(Object manager : networkManagers.toArray()) {
			Channel channel = (Channel) field.get(manager);
			if(channel.pipeline().context("pingapi_handler") == null && (channel.pipeline().context("packet_handler") != null)) {
				channel.pipeline().addBefore("packet_handler", "pingapi_handler", new DuplexHandler());
			}
		}
	} catch(IllegalAccessException e) {
		e.printStackTrace();
	} catch(NullPointerException | IllegalArgumentException | NoSuchElementException ignored) {}
}
 
Example 5
/**
 * Gets the channel
 *
 * @param player player
 * @return the Channel
 */
private static Channel getChannel(Player player) {
	try {
		Object entity = Reflections.getHandle(player);
		return clientChannelField.get(networkManagerField.get(playerConnectionField.get(entity)));
	}
	catch(Exception e) {
		LoggerUtils.exception(e);
		return null;
	}
}
 
Example 6
Source Project: Carbon   Source File: NettyInjector.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static void injectStreamSerializer() throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
	ServerConnection serverConnection = MinecraftServer.getServer().getServerConnection();
	List<NetworkManager> networkManagersList = ((List<NetworkManager>) Utilities.setAccessible(Field.class, serverConnection.getClass().getDeclaredField("f"), true).get(serverConnection));
	Channel channel = (Channel) ((List<ChannelFuture>) Utilities.setAccessible(Field.class, serverConnection.getClass().getDeclaredField("e"), true).get(serverConnection)).get(0).channel();
	ChannelHandler serverHandler = channel.pipeline().first();
	Utilities.setAccessible(Field.class, serverHandler.getClass().getDeclaredField("childHandler"), true).set(serverHandler, new ServerConnectionChannel(serverConnection, networkManagersList));
}
 
Example 7
protected void swapFields() {
    if (CHANNEL_FIELD == null) {
        CHANNEL_FIELD = new Reflection().reflect(NetworkManager.class).getSafeFieldByType(Channel.class).getAccessor();
    }

    if (ADDRESS_FIELD == null) {
        ADDRESS_FIELD = new Reflection().reflect(NetworkManager.class).getSafeFieldByType(InetSocketAddress.class).getAccessor();
    }

    CHANNEL_FIELD.set(this, new NullChannel(null));
    ADDRESS_FIELD.set(this, null);
}
 
Example 8
protected void swapFields() {
    if (CHANNEL_FIELD == null) {
        CHANNEL_FIELD = new Reflection().reflect(NetworkManager.class).getSafeFieldByType(Channel.class).getAccessor();
    }

    if (ADDRESS_FIELD == null) {
        ADDRESS_FIELD = new Reflection().reflect(NetworkManager.class).getSafeFieldByType(InetSocketAddress.class).getAccessor();
    }

    CHANNEL_FIELD.set(this, new NullChannel(null));
    ADDRESS_FIELD.set(this, null);
}
 
Example 9
protected void swapFields() {
    if (CHANNEL_FIELD == null) {
        CHANNEL_FIELD = new Reflection().reflect(NetworkManager.class).getSafeFieldByType(Channel.class).getAccessor();
    }

    if (ADDRESS_FIELD == null) {
        ADDRESS_FIELD = new Reflection().reflect(NetworkManager.class).getSafeFieldByType(SocketAddress.class).getAccessor();
    }

    CHANNEL_FIELD.set(this, new NullChannel(null));
    ADDRESS_FIELD.set(this, new SocketAddress() {});
}
 
Example 10
protected void swapFields() {
    if (CHANNEL_FIELD == null) {
        CHANNEL_FIELD = new Reflection().reflect(NetworkManager.class).getSafeFieldByType(Channel.class).getAccessor();
    }

    if (ADDRESS_FIELD == null) {
        ADDRESS_FIELD = new Reflection().reflect(NetworkManager.class).getSafeFieldByType(SocketAddress.class).getAccessor();
    }

    CHANNEL_FIELD.set(this, new NullChannel(null));
    ADDRESS_FIELD.set(this, new SocketAddress() {});
}
 
Example 11
Source Project: HoloAPI   Source File: PlayerInjector.java    License: GNU General Public License v3.0 4 votes vote down vote up
private Channel getChannel() {
    if (this.channel == null)
        throw new IllegalStateException("The Channel is NULL!");

    return this.channel;
}