Search in sources :

Example 1 with Client

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

the class StorageManagerTest method setup.

@BeforeEach
public void setup(@TempDir Path tempHome) throws Exception {
    super.setup();
    PathManager.getInstance().useOverrideHomePath(tempHome);
    savePath = PathManager.getInstance().getSavePath("testSave");
    assert !Files.isRegularFile(tempHome.resolve("global.dat"));
    entityManager = context.get(EngineEntityManager.class);
    moduleEnvironment = mock(ModuleEnvironment.class);
    blockManager = context.get(BlockManager.class);
    extraDataManager = context.get(ExtraBlockDataManager.class);
    ModuleManager moduleManager = mock(ModuleManager.class);
    when(moduleManager.getEnvironment()).thenReturn(moduleEnvironment);
    RecordedEventStore recordedEventStore = new RecordedEventStore();
    recordAndReplayUtils = new RecordAndReplayUtils();
    CharacterStateEventPositionMap characterStateEventPositionMap = new CharacterStateEventPositionMap();
    DirectionAndOriginPosRecorderList directionAndOriginPosRecorderList = new DirectionAndOriginPosRecorderList();
    recordAndReplaySerializer = new RecordAndReplaySerializer(entityManager, recordedEventStore, recordAndReplayUtils, characterStateEventPositionMap, directionAndOriginPosRecorderList, moduleManager, mock(TypeRegistry.class));
    recordAndReplayCurrentStatus = context.get(RecordAndReplayCurrentStatus.class);
    esm = new ReadWriteStorageManager(savePath, moduleEnvironment, entityManager, blockManager, extraDataManager, false, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus);
    context.put(StorageManager.class, esm);
    this.character = entityManager.create();
    Client client = createClientMock(PLAYER_ID, character);
    NetworkSystem networkSystem = mock(NetworkSystem.class);
    when(networkSystem.getMode()).thenReturn(NetworkMode.NONE);
    when(networkSystem.getPlayers()).thenReturn(Arrays.asList(client));
    context.put(NetworkSystem.class, networkSystem);
    AssetManager assetManager = context.get(AssetManager.class);
    BlockFamilyDefinitionData data = new BlockFamilyDefinitionData();
    data.setBlockFamily(SymmetricFamily.class);
    assetManager.loadAsset(new ResourceUrn("test:testblock"), data, BlockFamilyDefinition.class);
    assetManager.loadAsset(new ResourceUrn("test:testblock2"), data, BlockFamilyDefinition.class);
    testBlock = context.get(BlockManager.class).getBlock("test:testblock");
    testBlock2 = context.get(BlockManager.class).getBlock("test:testblock2");
    context.put(ChunkProvider.class, mock(ChunkProvider.class));
    WorldProvider worldProvider = mock(WorldProvider.class);
    when(worldProvider.getWorldInfo()).thenReturn(new WorldInfo());
    context.put(WorldProvider.class, worldProvider);
}
Also used : EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) AssetManager(org.terasology.gestalt.assets.management.AssetManager) NetworkSystem(org.terasology.engine.network.NetworkSystem) RecordedEventStore(org.terasology.engine.recording.RecordedEventStore) ExtraBlockDataManager(org.terasology.engine.world.chunks.blockdata.ExtraBlockDataManager) ModuleManager(org.terasology.engine.core.module.ModuleManager) RecordAndReplaySerializer(org.terasology.engine.recording.RecordAndReplaySerializer) DirectionAndOriginPosRecorderList(org.terasology.engine.recording.DirectionAndOriginPosRecorderList) BlockFamilyDefinitionData(org.terasology.engine.world.block.loader.BlockFamilyDefinitionData) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) BlockManager(org.terasology.engine.world.block.BlockManager) RecordAndReplayUtils(org.terasology.engine.recording.RecordAndReplayUtils) WorldProvider(org.terasology.engine.world.WorldProvider) WorldInfo(org.terasology.engine.world.internal.WorldInfo) RecordAndReplayCurrentStatus(org.terasology.engine.recording.RecordAndReplayCurrentStatus) Client(org.terasology.engine.network.Client) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) ChunkProvider(org.terasology.engine.world.chunks.ChunkProvider) CharacterStateEventPositionMap(org.terasology.engine.recording.CharacterStateEventPositionMap) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with Client

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

Example 3 with Client

use of org.terasology.engine.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);
    Vector3ic minViewDist = ViewDistance.LEGALLY_BLIND.getChunkDistance();
    if (playerStore.hasCharacter()) {
        Vector3fc 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();
            Vector3ic 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 {
        Vector3fc 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 : Vector3fc(org.joml.Vector3fc) PlayerStore(org.terasology.engine.persistence.PlayerStore) Vector3ic(org.joml.Vector3ic) Client(org.terasology.engine.network.Client) LocationComponent(org.terasology.engine.logic.location.LocationComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 4 with Client

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

the class NetworkSystemImpl method update.

@Override
public void update() {
    if (mode != NetworkMode.NONE) {
        if (entityManager != null) {
            processPendingConnections();
            processPendingDisconnects();
            long currentTimer = time.getRealTimeInMs();
            boolean netTick = false;
            if (currentTimer > nextNetworkTick) {
                nextNetworkTick += NET_TICK_RATE;
                netTick = true;
            }
            PerformanceMonitor.startActivity("Client update");
            for (Client client : clientList) {
                client.update(netTick);
            }
            PerformanceMonitor.endActivity();
            if (server != null) {
                server.update(netTick);
            }
        }
    }
}
Also used : Client(org.terasology.engine.network.Client)

Example 5 with Client

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

the class EventSystemReplayImpl method broadcastEvent.

private void broadcastEvent(EntityRef entity, Event event, EventMetadata metadata) {
    if (networkSystem.getMode().isServer()) {
        NetworkComponent netComp = entity.getComponent(NetworkComponent.class);
        BlockComponent blockComp = entity.getComponent(BlockComponent.class);
        if (netComp != null || blockComp != null) {
            Client instigatorClient = null;
            if (metadata.isSkipInstigator() && event instanceof NetworkEvent) {
                instigatorClient = networkSystem.getOwner(((NetworkEvent) event).getInstigator());
            }
            for (Client client : networkSystem.getPlayers()) {
                if (!client.equals(instigatorClient)) {
                    client.send(event, entity);
                }
            }
        }
    }
}
Also used : BlockComponent(org.terasology.engine.world.block.BlockComponent) NetworkComponent(org.terasology.engine.network.NetworkComponent) NetworkEvent(org.terasology.engine.network.NetworkEvent) Client(org.terasology.engine.network.Client)

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