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());
}
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));
}
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());
}
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();
}
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);
}
Aggregations