Search in sources :

Example 11 with Client

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

the class StorageManagerTest method createClientMock.

private Client createClientMock(String clientId, EntityRef charac) {
    EntityRef clientEntity = createClientEntity(charac);
    Client client = mock(Client.class);
    when(client.getEntity()).thenReturn(clientEntity);
    when(client.getId()).thenReturn(clientId);
    return client;
}
Also used : Client(org.terasology.network.Client) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 12 with Client

use of org.terasology.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.logic.common.DisplayNameComponent) Client(org.terasology.network.Client) EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponent(org.terasology.network.ClientComponent)

Example 13 with Client

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

the class PlayerSystem method spawnPlayer.

private void spawnPlayer(EntityRef clientEntity) {
    ClientComponent client = clientEntity.getComponent(ClientComponent.class);
    PlayerFactory playerFactory = new PlayerFactory(entityManager, worldProvider);
    EntityRef playerCharacter = playerFactory.newInstance(clientEntity);
    Client clientListener = networkSystem.getOwner(clientEntity);
    Vector3i distance = clientListener.getViewDistance().getChunkDistance();
    updateRelevanceEntity(clientEntity, distance);
    client.character = playerCharacter;
    clientEntity.saveComponent(client);
    playerCharacter.send(new OnPlayerSpawnedEvent());
}
Also used : OnPlayerSpawnedEvent(org.terasology.logic.players.event.OnPlayerSpawnedEvent) Vector3i(org.terasology.math.geom.Vector3i) Client(org.terasology.network.Client) ClientComponent(org.terasology.network.ClientComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 14 with Client

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

the class PlayerSystem method onConnect.

@ReceiveEvent(components = ClientComponent.class)
public void onConnect(ConnectedEvent connected, EntityRef entity) {
    LocationComponent loc = entity.getComponent(LocationComponent.class);
    // for new clients, the player store will return default values
    PlayerStore playerStore = connected.getPlayerStore();
    Client owner = networkSystem.getOwner(entity);
    Vector3i minViewDist = ViewDistance.LEGALLY_BLIND.getChunkDistance();
    if (playerStore.hasCharacter()) {
        Vector3f storedLocation = playerStore.getRelevanceLocation();
        loc.setWorldPosition(storedLocation);
        entity.saveComponent(loc);
        if (worldProvider.isBlockRelevant(storedLocation)) {
            // chunk for spawning location is ready, so spawn right now
            playerStore.restoreEntities();
            EntityRef character = playerStore.getCharacter();
            Vector3i viewDist = owner.getViewDistance().getChunkDistance();
            addRelevanceEntity(entity, viewDist, owner);
            restoreCharacter(entity, character);
        } else {
            // otherwise wait until chunk is ready
            addRelevanceEntity(entity, minViewDist, owner);
            clientsPreparingToSpawn.add(new SpawningClientInfo(entity, storedLocation, playerStore));
        }
    } else {
        Vector3f spawnPosition = worldGenerator.getSpawnPosition(entity);
        loc.setWorldPosition(spawnPosition);
        entity.saveComponent(loc);
        addRelevanceEntity(entity, minViewDist, owner);
        if (worldProvider.isBlockRelevant(spawnPosition)) {
            spawnPlayer(entity);
        } else {
            clientsPreparingToSpawn.add(new SpawningClientInfo(entity, spawnPosition));
        }
    }
}
Also used : PlayerStore(org.terasology.persistence.PlayerStore) Vector3f(org.terasology.math.geom.Vector3f) Vector3i(org.terasology.math.geom.Vector3i) Client(org.terasology.network.Client) LocationComponent(org.terasology.logic.location.LocationComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Aggregations

Client (org.terasology.network.Client)14 EntityRef (org.terasology.entitySystem.entity.EntityRef)7 ClientComponent (org.terasology.network.ClientComponent)5 Vector3f (org.terasology.math.geom.Vector3f)3 Vector3i (org.terasology.math.geom.Vector3i)3 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)2 AliveCharacterComponent (org.terasology.logic.characters.AliveCharacterComponent)2 LocationComponent (org.terasology.logic.location.LocationComponent)2 NetworkComponent (org.terasology.network.NetworkComponent)2 NetworkSystem (org.terasology.network.NetworkSystem)2 EntityData (org.terasology.protobuf.EntityData)2 BlockComponent (org.terasology.world.block.BlockComponent)2 FileSystem (java.nio.file.FileSystem)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)1 Before (org.junit.Before)1 ResourceUrn (org.terasology.assets.ResourceUrn)1 AssetManager (org.terasology.assets.management.AssetManager)1