Search in sources :

Example 26 with NetworkComponent

use of org.terasology.network.NetworkComponent 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 27 with NetworkComponent

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

the class ServerCommands method kickUserByID.

@Command(shortDescription = "Kick user by ID", runOnServer = true, requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION)
public String kickUserByID(@CommandParam("userId") int userId) {
    for (EntityRef clientEntity : entityManager.getEntitiesWith(ClientComponent.class)) {
        EntityRef clientInfo = clientEntity.getComponent(ClientComponent.class).clientInfo;
        NetworkComponent nc = clientInfo.getComponent(NetworkComponent.class);
        if (userId == nc.getNetworkId()) {
            return kick(clientEntity);
        }
    }
    throw new IllegalArgumentException("No such user with ID " + userId);
}
Also used : NetworkComponent(org.terasology.network.NetworkComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponent(org.terasology.network.ClientComponent) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Aggregations

NetworkComponent (org.terasology.network.NetworkComponent)27 EntityRef (org.terasology.entitySystem.entity.EntityRef)18 Test (org.junit.Test)7 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)6 BlockComponent (org.terasology.world.block.BlockComponent)5 Component (org.terasology.entitySystem.Component)3 Prefab (org.terasology.entitySystem.prefab.Prefab)3 Vector3i (org.terasology.math.geom.Vector3i)3 Command (org.terasology.logic.console.commandSystem.annotations.Command)2 Map (java.util.Map)1 Before (org.junit.Before)1 Config (org.terasology.config.Config)1 ComponentSystemManager (org.terasology.engine.ComponentSystemManager)1 EngineTime (org.terasology.engine.EngineTime)1 SimpleUri (org.terasology.engine.SimpleUri)1 ModuleManager (org.terasology.engine.module.ModuleManager)1 EntityManager (org.terasology.entitySystem.entity.EntityManager)1 EventLibrary (org.terasology.entitySystem.metadata.EventLibrary)1 DisplayNameComponent (org.terasology.logic.common.DisplayNameComponent)1 LocationComponent (org.terasology.logic.location.LocationComponent)1