Search in sources :

Example 16 with DisplayNameComponent

use of org.terasology.logic.common.DisplayNameComponent 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 17 with DisplayNameComponent

use of org.terasology.logic.common.DisplayNameComponent in project Terasology by MovingBlocks.

the class ServerCommands method listUsers.

@Command(shortDescription = "List users", requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION)
public String listUsers() {
    StringBuilder stringBuilder = new StringBuilder();
    for (EntityRef clientInfo : entityManager.getEntitiesWith(ClientInfoComponent.class)) {
        DisplayNameComponent dnc = clientInfo.getComponent(DisplayNameComponent.class);
        NetworkComponent nc = clientInfo.getComponent(NetworkComponent.class);
        String playerText = PlayerUtil.getColoredPlayerName(clientInfo);
        String line = String.format("%s - %s (%d)", playerText, dnc.description, nc.getNetworkId());
        stringBuilder.append(line);
        stringBuilder.append(Console.NEW_LINE);
    }
    return stringBuilder.toString();
}
Also used : DisplayNameComponent(org.terasology.logic.common.DisplayNameComponent) NetworkComponent(org.terasology.network.NetworkComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 18 with DisplayNameComponent

use of org.terasology.logic.common.DisplayNameComponent in project Terasology by MovingBlocks.

the class ServerCommands method kickUser.

@Command(shortDescription = "Kick user by name", runOnServer = true, requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION)
public String kickUser(@CommandParam("username") String username) {
    for (EntityRef clientEntity : entityManager.getEntitiesWith(ClientComponent.class)) {
        EntityRef clientInfo = clientEntity.getComponent(ClientComponent.class).clientInfo;
        DisplayNameComponent name = clientInfo.getComponent(DisplayNameComponent.class);
        if (username.equalsIgnoreCase(name.name)) {
            return kick(clientEntity);
        }
    }
    throw new IllegalArgumentException("No such user '" + username + "'");
}
Also used : DisplayNameComponent(org.terasology.logic.common.DisplayNameComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponent(org.terasology.network.ClientComponent) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 19 with DisplayNameComponent

use of org.terasology.logic.common.DisplayNameComponent in project Terasology by MovingBlocks.

the class OnlineUsernameSuggester method suggest.

@Override
public Set<String> suggest(EntityRef sender, Object... resolvedParameters) {
    Iterable<EntityRef> clients = entityManager.getEntitiesWith(ClientComponent.class);
    Set<String> clientNames = Sets.newHashSet();
    for (EntityRef client : clients) {
        ClientComponent clientComponent = client.getComponent(ClientComponent.class);
        DisplayNameComponent displayNameComponent = clientComponent.clientInfo.getComponent(DisplayNameComponent.class);
        clientNames.add(displayNameComponent.name);
    }
    return clientNames;
}
Also used : DisplayNameComponent(org.terasology.logic.common.DisplayNameComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponent(org.terasology.network.ClientComponent)

Example 20 with DisplayNameComponent

use of org.terasology.logic.common.DisplayNameComponent in project Terasology by MovingBlocks.

the class UsernameSuggester method suggest.

@Override
public Set<String> suggest(EntityRef sender, Object... resolvedParameters) {
    Set<String> clientNames = Sets.newHashSet();
    for (EntityRef clientInfo : entityManager.getEntitiesWith(ClientInfoComponent.class)) {
        DisplayNameComponent displayNameComponent = clientInfo.getComponent(DisplayNameComponent.class);
        clientNames.add(displayNameComponent.name);
    }
    return clientNames;
}
Also used : DisplayNameComponent(org.terasology.logic.common.DisplayNameComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Aggregations

DisplayNameComponent (org.terasology.logic.common.DisplayNameComponent)23 EntityRef (org.terasology.entitySystem.entity.EntityRef)17 ClientComponent (org.terasology.network.ClientComponent)13 Command (org.terasology.logic.console.commandSystem.annotations.Command)9 CharacterTeleportEvent (org.terasology.logic.characters.CharacterTeleportEvent)4 LocationComponent (org.terasology.logic.location.LocationComponent)4 Vector3f (org.terasology.math.geom.Vector3f)4 Component (org.terasology.entitySystem.Component)2 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)2 Prefab (org.terasology.entitySystem.prefab.Prefab)2 ItemComponent (org.terasology.logic.inventory.ItemComponent)2 PlayerCharacterComponent (org.terasology.logic.players.PlayerCharacterComponent)2 ColorComponent (org.terasology.network.ColorComponent)2 LightComponent (org.terasology.rendering.logic.LightComponent)2 HashSet (java.util.HashSet)1 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)1 CharacterMovementComponent (org.terasology.logic.characters.CharacterMovementComponent)1 MovementMode (org.terasology.logic.characters.MovementMode)1 SetMovementModeEvent (org.terasology.logic.characters.events.SetMovementModeEvent)1 Client (org.terasology.network.Client)1