use of org.terasology.network.internal.pipelineFactory.TerasologyClientPipelineFactory in project Terasology by MovingBlocks.
the class NetworkSystemImpl method join.
@Override
public JoinStatus join(String address, int port) throws InterruptedException {
if (mode == NetworkMode.NONE) {
if (hibernationSettings.isPresent()) {
hibernationSettings.get().setHibernationAllowed(false);
}
factory = new NioClientSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool());
ClientBootstrap bootstrap = new ClientBootstrap(factory);
bootstrap.setPipelineFactory(new TerasologyClientPipelineFactory(this));
bootstrap.setOption("tcpNoDelay", true);
bootstrap.setOption("keepAlive", true);
ChannelFuture connectCheck = bootstrap.connect(new InetSocketAddress(address, port));
try {
connectCheck.await();
} catch (InterruptedException e) {
connectCheck.cancel();
connectCheck.getChannel().getCloseFuture().awaitUninterruptibly();
factory.releaseExternalResources();
throw e;
}
if (!connectCheck.isSuccess()) {
logger.warn("Failed to connect to server", connectCheck.getCause());
connectCheck.getChannel().getCloseFuture().awaitUninterruptibly();
factory.releaseExternalResources();
return new JoinStatusImpl("Failed to connect to server - " + connectCheck.getCause().getMessage());
} else {
allChannels.add(connectCheck.getChannel());
ClientConnectionHandler connectionHandler = connectCheck.getChannel().getPipeline().get(ClientConnectionHandler.class);
if (connectionHandler == null) {
JoinStatusImpl status = new JoinStatusImpl();
status.setComplete();
return status;
} else {
return connectionHandler.getJoinStatus();
}
}
}
return new JoinStatusImpl("Network system already active");
}
Aggregations