Search in sources :

Example 1 with WrapperChannelDisconnectEvent

use of de.dytanic.cloudnetcore.api.event.network.WrapperChannelDisconnectEvent in project CloudNet by Dytanic.

the class CloudNetClient method channelInactive.

@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
    if ((!channel.isActive() || !channel.isOpen() || !channel.isWritable())) {
        System.out.println("Channel disconnected [" + channel.remoteAddress().toString() + "/serverId=" + networkComponent.getServerId() + "]");
        ctx.close().syncUninterruptibly();
        if (networkComponent instanceof MinecraftServer) {
            ((MinecraftServer) networkComponent).setChannelLostTime(System.currentTimeMillis());
        }
        if (networkComponent instanceof ProxyServer) {
            ((ProxyServer) networkComponent).setChannelLostTime(System.currentTimeMillis());
        }
        if (networkComponent instanceof Wrapper) {
            try {
                ((Wrapper) networkComponent).disconnct();
            } catch (Exception ex) {
                ((Wrapper) networkComponent).getServers().clear();
                ((Wrapper) networkComponent).getProxys().clear();
            }
            CloudNet.getInstance().getEventManager().callEvent(new WrapperChannelDisconnectEvent(((Wrapper) networkComponent)));
        }
        networkComponent.setChannel(null);
    }
}
Also used : Wrapper(de.dytanic.cloudnetcore.network.components.Wrapper) WrapperChannelDisconnectEvent(de.dytanic.cloudnetcore.api.event.network.WrapperChannelDisconnectEvent) IOException(java.io.IOException) MinecraftServer(de.dytanic.cloudnetcore.network.components.MinecraftServer) ProxyServer(de.dytanic.cloudnetcore.network.components.ProxyServer)

Aggregations

WrapperChannelDisconnectEvent (de.dytanic.cloudnetcore.api.event.network.WrapperChannelDisconnectEvent)1 MinecraftServer (de.dytanic.cloudnetcore.network.components.MinecraftServer)1 ProxyServer (de.dytanic.cloudnetcore.network.components.ProxyServer)1 Wrapper (de.dytanic.cloudnetcore.network.components.Wrapper)1 IOException (java.io.IOException)1