use of de.dytanic.cloudnetcore.api.event.network.ChannelConnectEvent in project CloudNet by Dytanic.
the class CloudNetServer method initChannel.
@Override
protected void initChannel(Channel channel) throws Exception {
System.out.println("Channel [" + channel.remoteAddress().toString() + "] connecting...");
ChannelConnectEvent channelConnectEvent = new ChannelConnectEvent(false, channel);
CloudNet.getInstance().getEventManager().callEvent(channelConnectEvent);
if (channelConnectEvent.isCancelled()) {
channel.close().syncUninterruptibly();
return;
}
String[] address = channel.remoteAddress().toString().split(":");
String host = address[0].replaceFirst(NetworkUtils.SLASH_STRING, NetworkUtils.EMPTY_STRING);
for (Wrapper cn : CloudNet.getInstance().getWrappers().values()) {
if (cn.getChannel() == null && cn.getNetworkInfo().getHostName().equalsIgnoreCase(host)) {
if (sslContext != null)
channel.pipeline().addLast(sslContext.newHandler(channel.alloc()));
NetworkUtils.initChannel(channel);
channel.pipeline().addLast("client", new CloudNetClientAuth(channel, this));
return;
}
if (cn.getNetworkInfo().getHostName().equals(host)) {
if (sslContext != null)
channel.pipeline().addLast(sslContext.newHandler(channel.alloc()));
NetworkUtils.initChannel(channel);
CloudNetClientAuth cloudNetProxyClientAuth = new CloudNetClientAuth(channel, this);
channel.pipeline().addLast("client", cloudNetProxyClientAuth);
return;
}
}
channel.close().addListener(ChannelFutureListener.CLOSE_ON_FAILURE).addListener(ChannelFutureListener.CLOSE_ON_FAILURE);
}
Aggregations