Search in sources :

Example 16 with NetworkComponent

use of org.terasology.engine.network.NetworkComponent in project Terasology by MovingBlocks.

the class NetworkOwnershipTest method testClientSentInitialIfOwnedEntityRegistered.

@Test
public void testClientSentInitialIfOwnedEntityRegistered() {
    connectClient();
    EntityBuilder builder = entityManager.newBuilder();
    NetworkComponent netComp = builder.addComponent(new NetworkComponent());
    netComp.replicateMode = NetworkComponent.ReplicateMode.OWNER;
    builder.setOwner(clientEntity);
    EntityRef entity = builder.build();
    networkSystem.registerNetworkEntity(entity);
    assertTrue(entity.getComponent(NetworkComponent.class).getNetworkId() != 0);
    verify(client).setNetInitial(entity.getComponent(NetworkComponent.class).getNetworkId());
}
Also used : NetworkComponent(org.terasology.engine.network.NetworkComponent) EntityBuilder(org.terasology.engine.entitySystem.entity.EntityBuilder) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 17 with NetworkComponent

use of org.terasology.engine.network.NetworkComponent in project Terasology by MovingBlocks.

the class NetworkOwnershipTest method setup.

@BeforeEach
public void setup() throws Exception {
    super.setup();
    ModuleManager moduleManager = ModuleManagerFactory.create();
    context.put(ModuleManager.class, moduleManager);
    EngineTime mockTime = mock(EngineTime.class);
    networkSystem = new NetworkSystemImpl(mockTime, context);
    networkSystem.setContext(context);
    context.put(NetworkSystem.class, networkSystem);
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    entityManager = (PojoEntityManager) context.get(EntityManager.class);
    context.put(ComponentSystemManager.class, new ComponentSystemManager(context));
    entityManager.clear();
    client = mock(NetClient.class);
    NetworkComponent clientNetComp = new NetworkComponent();
    clientNetComp.replicateMode = NetworkComponent.ReplicateMode.OWNER;
    clientEntity = entityManager.create(clientNetComp);
    when(client.getEntity()).thenReturn(clientEntity);
    when(client.getId()).thenReturn("dummyID");
    networkSystem.mockHost();
    networkSystem.connectToEntitySystem(entityManager, context.get(EventLibrary.class), mock(BlockEntityRegistry.class));
    networkSystem.registerNetworkEntity(clientEntity);
    context.put(ServerConnectListManager.class, new ServerConnectListManager(context));
}
Also used : NetworkComponent(org.terasology.engine.network.NetworkComponent) EventLibrary(org.terasology.engine.entitySystem.metadata.EventLibrary) EngineTime(org.terasology.engine.core.EngineTime) BlockEntityRegistry(org.terasology.engine.world.BlockEntityRegistry) ModuleManager(org.terasology.engine.core.module.ModuleManager) ComponentSystemManager(org.terasology.engine.core.ComponentSystemManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 18 with NetworkComponent

use of org.terasology.engine.network.NetworkComponent in project Terasology by MovingBlocks.

the class NetworkOwnershipTest method testClientSentInitialOnlyOnce.

@Test
public void testClientSentInitialOnlyOnce() {
    EntityBuilder builder = entityManager.newBuilder();
    NetworkComponent netComp = builder.addComponent(new NetworkComponent());
    netComp.replicateMode = NetworkComponent.ReplicateMode.OWNER;
    builder.setOwner(clientEntity);
    EntityRef entity = builder.build();
    networkSystem.registerNetworkEntity(entity);
    connectClient();
    networkSystem.updateOwnership(entity);
    verify(client, times(1)).setNetInitial(entity.getComponent(NetworkComponent.class).getNetworkId());
}
Also used : NetworkComponent(org.terasology.engine.network.NetworkComponent) EntityBuilder(org.terasology.engine.entitySystem.entity.EntityBuilder) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 19 with NetworkComponent

use of org.terasology.engine.network.NetworkComponent in project Terasology by MovingBlocks.

the class BaseEntityRef method toString.

@Override
public String toString() {
    Prefab parent = getParentPrefab();
    StringBuilder builder = new StringBuilder();
    builder.append("EntityRef{id = ");
    builder.append(getId());
    NetworkComponent networkComponent = getComponent(NetworkComponent.class);
    if (networkComponent != null) {
        builder.append(", netId = ");
        builder.append(networkComponent.getNetworkId());
    }
    if (parent != null) {
        builder.append(", prefab = '");
        builder.append(parent.getUrn());
        builder.append("'");
    }
    builder.append("}");
    return builder.toString();
}
Also used : NetworkComponent(org.terasology.engine.network.NetworkComponent) Prefab(org.terasology.engine.entitySystem.prefab.Prefab)

Example 20 with NetworkComponent

use of org.terasology.engine.network.NetworkComponent in project Terasology by MovingBlocks.

the class ServerCommands method kickUserByID.

@Command(shortDescription = "Kick user by ID", runOnServer = true, requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION)
public String kickUserByID(@CommandParam("userId") int userId) {
    for (EntityRef clientEntity : entityManager.getEntitiesWith(ClientComponent.class)) {
        EntityRef clientInfo = clientEntity.getComponent(ClientComponent.class).clientInfo;
        NetworkComponent nc = clientInfo.getComponent(NetworkComponent.class);
        if (userId == nc.getNetworkId()) {
            return kick(clientEntity);
        }
    }
    throw new IllegalArgumentException("No such user with ID " + userId);
}
Also used : NetworkComponent(org.terasology.engine.network.NetworkComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ClientComponent(org.terasology.engine.network.ClientComponent) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

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