Search in sources :

Example 26 with ClientComponent

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

the class PermissionCommands method usePermissionKey.

@Command(shortDescription = "Use an one time key to get all permissions", helpText = "The config file contains a one time key which can be used to get all permissions.", runOnServer = true, requiredPermission = PermissionManager.NO_PERMISSION)
public String usePermissionKey(@CommandParam("key") String key, @Sender EntityRef client) {
    PermissionConfig permissionConfig = config.getPermission();
    String expectedKey = permissionConfig.getOneTimeAuthorizationKey();
    if (expectedKey != null && !expectedKey.equals("") && key.equals(expectedKey)) {
        permissionConfig.setOneTimeAuthorizationKey("");
        ClientComponent clientComponent = client.getComponent(ClientComponent.class);
        EntityRef clientInfo = clientComponent.clientInfo;
        for (String permission : findAllPermissions()) {
            permissionManager.addPermission(clientInfo, permission);
        }
        PermissionSetComponent permissionSetComp = clientInfo.getComponent(PermissionSetComponent.class);
        return "Permission key used: You have now the following permissions: " + permissionSetComp.permissions;
    } else {
        return "Key invalid or used";
    }
}
Also used : PermissionConfig(org.terasology.engine.config.PermissionConfig) ClientComponent(org.terasology.engine.network.ClientComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ConsoleCommand(org.terasology.engine.logic.console.commandSystem.ConsoleCommand) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Example 27 with ClientComponent

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

the class PermissionCommands method listPermissions.

@Command(shortDescription = "Lists all permission the specified player has", helpText = "Lists all permission the specified player has", runOnServer = true, requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION)
public String listPermissions(@CommandParam(value = "player", suggester = UsernameSuggester.class) String player) {
    for (EntityRef client : entityManager.getEntitiesWith(ClientComponent.class)) {
        ClientComponent clientComponent = client.getComponent(ClientComponent.class);
        if (clientHasName(clientComponent, player)) {
            EntityRef clientInfo = clientComponent.clientInfo;
            PermissionSetComponent permissionSetComp = clientInfo.getComponent(PermissionSetComponent.class);
            return Objects.toString(permissionSetComp.permissions);
        }
    }
    return "Player not found";
}
Also used : EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ClientComponent(org.terasology.engine.network.ClientComponent) ConsoleCommand(org.terasology.engine.logic.console.commandSystem.ConsoleCommand) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Example 28 with ClientComponent

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

the class PermissionCommands method removePermission.

@Command(shortDescription = "Removes specified permission from player", helpText = "Removes specified permission from player", runOnServer = true, requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION)
public String removePermission(@CommandParam(value = "player", suggester = UsernameSuggester.class) String player, @CommandParam("permission") String permission, @Sender EntityRef requester) {
    boolean permissionGiven = false;
    ClientComponent requesterClientComponent = requester.getComponent(ClientComponent.class);
    EntityRef requesterClientInfo = requesterClientComponent.clientInfo;
    if (!permissionManager.hasPermission(requesterClientInfo, permission)) {
        return String.format("You can't remove the permission %s because you don't have it yourself", permission);
    }
    for (EntityRef client : entityManager.getEntitiesWith(ClientComponent.class)) {
        ClientComponent clientComponent = client.getComponent(ClientComponent.class);
        if (clientHasName(clientComponent, player)) {
            permissionManager.removePermission(clientComponent.clientInfo, permission);
            permissionGiven = true;
        }
    }
    if (permissionGiven) {
        return "Permission " + permission + " removed from player " + player;
    } else {
        return "Unable to find player " + player;
    }
}
Also used : ClientComponent(org.terasology.engine.network.ClientComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ConsoleCommand(org.terasology.engine.logic.console.commandSystem.ConsoleCommand) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Example 29 with ClientComponent

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

the class OnlinePlayersOverlay method determinePlayerListText.

private String determinePlayerListText() {
    Iterable<EntityRef> allClients = entityManager.getEntitiesWith(ClientComponent.class);
    StringBuilder sb = new StringBuilder();
    boolean first = true;
    for (EntityRef clientEntity : allClients) {
        if (!first) {
            sb.append("\n");
        }
        ClientComponent clientComp = clientEntity.getComponent(ClientComponent.class);
        sb.append(PlayerUtil.getColoredPlayerName(clientComp.clientInfo));
        first = false;
    }
    return sb.toString();
}
Also used : EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ClientComponent(org.terasology.engine.network.ClientComponent)

Example 30 with ClientComponent

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

the class StorageManagerTest method createClientEntity.

private EntityRef createClientEntity(EntityRef charac) {
    ClientComponent clientComponent = new ClientComponent();
    clientComponent.local = true;
    clientComponent.character = charac;
    EntityRef clientEntity = entityManager.create(clientComponent);
    return clientEntity;
}
Also used : ClientComponent(org.terasology.engine.network.ClientComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef)

Aggregations

ClientComponent (org.terasology.engine.network.ClientComponent)54 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)30 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)27 Vector3f (org.joml.Vector3f)13 LocationComponent (org.terasology.engine.logic.location.LocationComponent)13 CharacterMovementComponent (org.terasology.engine.logic.characters.CharacterMovementComponent)11 DisplayNameComponent (org.terasology.engine.logic.common.DisplayNameComponent)10 ConsoleCommand (org.terasology.engine.logic.console.commandSystem.ConsoleCommand)8 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)6 CharacterTeleportEvent (org.terasology.engine.logic.characters.CharacterTeleportEvent)6 DropItemEvent (org.terasology.engine.logic.inventory.events.DropItemEvent)4 BlockFamily (org.terasology.engine.world.block.family.BlockFamily)4 BlockItemFactory (org.terasology.engine.world.block.items.BlockItemFactory)4 Quaternionf (org.joml.Quaternionf)3 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)3 LocalPlayer (org.terasology.engine.logic.players.LocalPlayer)3 Client (org.terasology.engine.network.Client)3 Vector3ic (org.joml.Vector3ic)2 EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)2 AliveCharacterComponent (org.terasology.engine.logic.characters.AliveCharacterComponent)2