use of org.terasology.network.internal.pipelineFactory.TerasologyServerPipelineFactory in project Terasology by MovingBlocks.
the class NetworkSystemImpl method host.
@Override
public void host(int port, boolean dedicatedServer) throws HostingFailedException {
if (mode == NetworkMode.NONE) {
try {
if (hibernationSettings.isPresent()) {
hibernationSettings.get().setHibernationAllowed(false);
}
mode = dedicatedServer ? NetworkMode.DEDICATED_SERVER : NetworkMode.LISTEN_SERVER;
for (EntityRef entity : entityManager.getEntitiesWith(NetworkComponent.class)) {
registerNetworkEntity(entity);
}
generateSerializationTables();
factory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool());
ServerBootstrap bootstrap = new ServerBootstrap(factory);
bootstrap.setPipelineFactory(new TerasologyServerPipelineFactory(this));
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setOption("child.keepAlive", true);
Channel listenChannel = bootstrap.bind(new InetSocketAddress(port));
allChannels.add(listenChannel);
logger.info("Started server on port {}", port);
if (config.getServerMOTD() != null) {
logger.info("Server MOTD is \"{}\"", config.getServerMOTD());
} else {
logger.info("No server MOTD is defined");
}
// enumerate all network interfaces that listen
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
while (interfaces.hasMoreElements()) {
NetworkInterface ifc = interfaces.nextElement();
if (!ifc.isLoopback()) {
for (InterfaceAddress ifadr : ifc.getInterfaceAddresses()) {
InetAddress adr = ifadr.getAddress();
logger.info("Listening on network interface \"{}\", hostname \"{}\" ({})", ifc.getDisplayName(), adr.getCanonicalHostName(), adr.getHostAddress());
}
}
}
nextNetworkTick = time.getRealTimeInMs();
} catch (SocketException e) {
throw new HostingFailedException("Could not identify network interfaces", e);
} catch (ChannelException e) {
if (e.getCause() instanceof BindException) {
throw new HostingFailedException("Port already in use (are you already hosting a game?)", e.getCause());
} else {
throw new HostingFailedException("Failed to host game", e.getCause());
}
}
}
}
Aggregations