Search in sources :

Example 6 with Client

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

the class ServerViewDistanceSystem method onChangeViewDistanceChanged.

@ReceiveEvent(components = ClientComponent.class)
public void onChangeViewDistanceChanged(ViewDistanceChangedEvent request, EntityRef entity) {
    Client client = networkSystem.getOwner(entity);
    if (client != null) {
        client.setViewDistanceMode(request.getNewViewRange());
        relevanceSystem.updateRelevanceEntityDistance(entity, client.getViewDistance().getChunkDistance());
    }
}
Also used : Client(org.terasology.engine.network.Client) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 7 with Client

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

the class ServerCommands method kick.

private String kick(EntityRef clientEntity) {
    Client client = networkSystem.getOwner(clientEntity);
    if (!client.isLocal()) {
        EntityRef clientInfo = clientEntity.getComponent(ClientComponent.class).clientInfo;
        DisplayNameComponent name = clientInfo.getComponent(DisplayNameComponent.class);
        logger.info("Kicking user {}", name.name);
        networkSystem.forceDisconnect(client);
        return "User kick triggered for '" + name.name + "'";
    }
    return "Request declined";
}
Also used : DisplayNameComponent(org.terasology.engine.logic.common.DisplayNameComponent) Client(org.terasology.engine.network.Client) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ClientComponent(org.terasology.engine.network.ClientComponent)

Example 8 with Client

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

the class SetupLocalPlayer method step.

@Override
public boolean step() {
    PlayerConfig playerConfig = context.get(PlayerConfig.class);
    Client localClient = context.get(NetworkSystem.class).joinLocal(playerConfig.playerName.get(), playerConfig.color.get());
    context.get(LocalPlayer.class).setClientEntity(localClient.getEntity());
    return true;
}
Also used : LocalPlayer(org.terasology.engine.logic.players.LocalPlayer) NetworkSystem(org.terasology.engine.network.NetworkSystem) Client(org.terasology.engine.network.Client) PlayerConfig(org.terasology.engine.config.PlayerConfig)

Example 9 with Client

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

the class NetworkSystemImpl method joinLocal.

@Override
public Client joinLocal(String preferredName, Color color) {
    Client localClient = new LocalClient(preferredName, color, entityManager);
    clientList.add(localClient);
    clientPlayerLookup.put(localClient.getEntity(), localClient);
    connectClient(localClient);
    return localClient;
}
Also used : Client(org.terasology.engine.network.Client)

Example 10 with Client

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

the class NetClient method sendInitialEntities.

private void sendInitialEntities(NetData.NetMessage.Builder message) {
    int[] initial = netInitial.toArray();
    netInitial.clear();
    Arrays.sort(initial);
    for (int netId : initial) {
        netRelevant.add(netId);
        EntityRef entity = networkSystem.getEntity(netId);
        if (!entity.hasComponent(NetworkComponent.class)) {
            logger.error("Sending net entity with no network component: {} - {}", netId, entity);
            continue;
        }
        // Note: Send owner->server fields on initial create
        Client owner = networkSystem.getOwner(entity);
        EntityData.PackedEntity entityData = entitySerializer.serialize(entity, true, new ServerComponentFieldCheck(owner == this, true)).build();
        NetData.CreateEntityMessage.Builder createMessage = NetData.CreateEntityMessage.newBuilder().setEntity(entityData);
        BlockComponent blockComponent = entity.getComponent(BlockComponent.class);
        if (blockComponent != null) {
            createMessage.setBlockPos(NetMessageUtil.convert(blockComponent.getPosition()));
        }
        message.addCreateEntity(createMessage);
    }
}
Also used : BlockComponent(org.terasology.engine.world.block.BlockComponent) NetworkComponent(org.terasology.engine.network.NetworkComponent) EntityData(org.terasology.protobuf.EntityData) ServerComponentFieldCheck(org.terasology.engine.network.serialization.ServerComponentFieldCheck) Client(org.terasology.engine.network.Client) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef)

Aggregations

Client (org.terasology.engine.network.Client)14 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)7 ClientComponent (org.terasology.engine.network.ClientComponent)5 Vector3ic (org.joml.Vector3ic)3 Vector3f (org.joml.Vector3f)2 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)2 AliveCharacterComponent (org.terasology.engine.logic.characters.AliveCharacterComponent)2 LocationComponent (org.terasology.engine.logic.location.LocationComponent)2 NetworkComponent (org.terasology.engine.network.NetworkComponent)2 NetworkSystem (org.terasology.engine.network.NetworkSystem)2 BlockComponent (org.terasology.engine.world.block.BlockComponent)2 EntityData (org.terasology.protobuf.EntityData)2 Map (java.util.Map)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Quaternionf (org.joml.Quaternionf)1 Vector3fc (org.joml.Vector3fc)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 PlayerConfig (org.terasology.engine.config.PlayerConfig)1 ModuleManager (org.terasology.engine.core.module.ModuleManager)1 EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)1