类net.minecraft.util.io.netty.channel.Channel源码实例Demo

下面列出了怎么用net.minecraft.util.io.netty.channel.Channel的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: Carbon   文件: ServerConnectionChannel.java
@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));
}
 
源代码2 项目: PingAPI   文件: PingInjector.java
/**
 * 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) {}
}
 
源代码3 项目: PingAPI   文件: PingInjector.java
/**
 * 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) {}
}
 
源代码4 项目: PingAPI   文件: PingInjector.java
/**
 * 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) {}
}
 
源代码5 项目: NovaGuilds   文件: PacketExtensionImpl.java
/**
 * 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;
	}
}
 
源代码6 项目: Carbon   文件: NettyInjector.java
@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));
}
 
源代码7 项目: EntityAPI   文件: FixedNetworkManager.java
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);
}
 
源代码8 项目: EntityAPI   文件: FixedNetworkManager.java
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);
}
 
源代码9 项目: EntityAPI   文件: FixedNetworkManager.java
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() {});
}
 
源代码10 项目: EntityAPI   文件: FixedNetworkManager.java
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() {});
}
 
源代码11 项目: HoloAPI   文件: PlayerInjector.java
private Channel getChannel() {
    if (this.channel == null)
        throw new IllegalStateException("The Channel is NULL!");

    return this.channel;
}
 
 类所在包
 同包方法