use of org.terasology.engine.network.NetworkComponent in project Terasology by MovingBlocks.
the class NetworkSystemImpl method shutdown.
@Override
public void shutdown() {
allChannels.close().awaitUninterruptibly();
if (serverChannelFuture != null) {
serverChannelFuture.channel().closeFuture();
// Wait until all threads are terminated.
try {
bossGroup.shutdownGracefully().sync();
workerGroup.shutdownGracefully().sync();
bossGroup.terminationFuture().sync();
workerGroup.terminationFuture().sync();
} catch (InterruptedException e) {
logger.error("Cannot terminateFuture - interrupted");
throw new RuntimeException(e);
}
}
if (clientGroup != null) {
clientGroup.shutdownGracefully().syncUninterruptibly();
}
// Shut down all event loops to terminate all threads.
processPendingDisconnects();
clientList.forEach(this::processRemovedClient);
server = null;
nextNetId = 1;
netIdToEntityId.clear();
if (mode != NetworkMode.CLIENT) {
if (this.entityManager != null) {
for (EntityRef entity : entityManager.getEntitiesWith(NetworkComponent.class)) {
NetworkComponent netComp = entity.getComponent(NetworkComponent.class);
netComp.setNetworkId(0);
entity.saveComponent(netComp);
}
this.entityManager.unsubscribe(this);
}
}
mode = NetworkMode.NONE;
entityManager = null;
eventLibrary = null;
componentLibrary = null;
eventSerializer = null;
entitySerializer = null;
clientList.clear();
netClientList.clear();
blockManager = null;
ownerLookup.clear();
ownedLookup.clear();
ownershipHelper = null;
storageManager = null;
logger.info("Network shutdown");
}
use of org.terasology.engine.network.NetworkComponent in project Terasology by MovingBlocks.
the class NetEntityRefTypeHandler method serializeNonNull.
@Override
public PersistedData serializeNonNull(EntityRef value, PersistedDataSerializer serializer) {
BlockComponent blockComponent = value.getComponent(BlockComponent.class);
if (blockComponent != null) {
Vector3ic pos = blockComponent.getPosition();
return serializer.serialize(pos.x(), pos.y(), pos.z());
}
NetworkComponent netComponent = value.getComponent(NetworkComponent.class);
if (netComponent != null) {
return serializer.serialize(netComponent.getNetworkId());
}
return serializer.serializeNull();
}
Aggregations