Search in sources :

Example 11 with DisplayNameComponent

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

the class AbstractClient method createEntity.

/**
 * Creates an entity for the client connection, checking if name and color options can be used.
 * @param preferredName Passes players preferred name to check availability, giving a best alternative if it is used already.
 * @param color Creates or changes the player's color component to match argument
 * @param entityManager
 */
protected void createEntity(String preferredName, Color color, EntityManager entityManager) {
    // Create player entity
    clientEntity = entityManager.create("engine:client");
    // TODO: Send event for clientInfo creation, don't create here.
    EntityRef clientInfo = findClientEntityRef(entityManager);
    if (!clientInfo.exists()) {
        clientInfo = createClientInfoEntity(entityManager);
    }
    ClientInfoComponent clientInfoComp = clientInfo.getComponent(ClientInfoComponent.class);
    clientInfoComp.client = clientEntity;
    clientInfo.saveComponent(clientInfoComp);
    ClientComponent clientComponent = clientEntity.getComponent(ClientComponent.class);
    clientComponent.clientInfo = clientInfo;
    clientEntity.saveComponent(clientComponent);
    addOrSetColorComponent(clientInfo, color);
    DisplayNameComponent displayNameComponent = clientInfo.getComponent(DisplayNameComponent.class);
    if (displayNameComponent == null || !displayNameComponent.name.equals(preferredName)) {
        String bestAvailableName = findUniquePlayerName(preferredName, entityManager, clientInfo);
        addOrSetDisplayNameComponent(clientInfo, bestAvailableName);
    }
}
Also used : DisplayNameComponent(org.terasology.engine.logic.common.DisplayNameComponent) ClientInfoComponent(org.terasology.engine.network.ClientInfoComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ClientComponent(org.terasology.engine.network.ClientComponent)

Example 12 with DisplayNameComponent

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

the class AbstractClient method addOrSetDisplayNameComponent.

/**
 * Used to change or add a display name to the client entity.
 * @param clientInfo
 * @param name Function will set the client entities name to this.
 */
private void addOrSetDisplayNameComponent(EntityRef clientInfo, String name) {
    DisplayNameComponent component = clientInfo.getComponent(DisplayNameComponent.class);
    if (component != null) {
        component.name = name;
        clientInfo.saveComponent(component);
    } else {
        component = new DisplayNameComponent();
        component.name = name;
        clientInfo.addComponent(component);
    }
}
Also used : DisplayNameComponent(org.terasology.engine.logic.common.DisplayNameComponent)

Example 13 with DisplayNameComponent

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

Example 14 with DisplayNameComponent

use of org.terasology.engine.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.engine.logic.common.DisplayNameComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ClientComponent(org.terasology.engine.network.ClientComponent) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Example 15 with DisplayNameComponent

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

Aggregations

DisplayNameComponent (org.terasology.engine.logic.common.DisplayNameComponent)21 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)18 ClientComponent (org.terasology.engine.network.ClientComponent)13 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)10 Vector3f (org.joml.Vector3f)4 CharacterTeleportEvent (org.terasology.engine.logic.characters.CharacterTeleportEvent)4 LocationComponent (org.terasology.engine.logic.location.LocationComponent)4 ColorComponent (org.terasology.engine.network.ColorComponent)3 PlayerCharacterComponent (org.terasology.engine.logic.players.PlayerCharacterComponent)2 HashSet (java.util.HashSet)1 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)1 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)1 CharacterMovementComponent (org.terasology.engine.logic.characters.CharacterMovementComponent)1 MovementMode (org.terasology.engine.logic.characters.MovementMode)1 SetMovementModeEvent (org.terasology.engine.logic.characters.events.SetMovementModeEvent)1 ChatMessageEvent (org.terasology.engine.logic.chat.ChatMessageEvent)1 Client (org.terasology.engine.network.Client)1 ClientInfoComponent (org.terasology.engine.network.ClientInfoComponent)1 NetworkComponent (org.terasology.engine.network.NetworkComponent)1 Color (org.terasology.nui.Color)1