Search in sources :

Example 26 with NetworkComponent

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");
}
Also used : NetworkComponent(org.terasology.engine.network.NetworkComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef)

Example 27 with NetworkComponent

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();
}
Also used : BlockComponent(org.terasology.engine.world.block.BlockComponent) NetworkComponent(org.terasology.engine.network.NetworkComponent) Vector3ic(org.joml.Vector3ic)

Aggregations

NetworkComponent (org.terasology.engine.network.NetworkComponent)27 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)17 Test (org.junit.jupiter.api.Test)7 EntityBuilder (org.terasology.engine.entitySystem.entity.EntityBuilder)7 BlockComponent (org.terasology.engine.world.block.BlockComponent)5 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)4 Component (org.terasology.gestalt.entitysystem.component.Component)3 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)2 LocationComponent (org.terasology.engine.logic.location.LocationComponent)2 ByteString (com.google.protobuf.ByteString)1 Vector3f (org.joml.Vector3f)1 Vector3i (org.joml.Vector3i)1 Vector3ic (org.joml.Vector3ic)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 ComponentSystemManager (org.terasology.engine.core.ComponentSystemManager)1 EngineTime (org.terasology.engine.core.EngineTime)1 ModuleManager (org.terasology.engine.core.module.ModuleManager)1 BeforeDeactivateComponent (org.terasology.engine.entitySystem.entity.lifecycleEvents.BeforeDeactivateComponent)1 BeforeEntityCreated (org.terasology.engine.entitySystem.entity.lifecycleEvents.BeforeEntityCreated)1 OnActivatedComponent (org.terasology.engine.entitySystem.entity.lifecycleEvents.OnActivatedComponent)1