Search in sources :

Example 36 with ClientComponent

use of org.terasology.engine.network.ClientComponent 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 37 with ClientComponent

use of org.terasology.engine.network.ClientComponent 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 38 with ClientComponent

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

the class ConsoleImpl method execute.

@Override
public boolean execute(String rawCommand, EntityRef callingClient) {
    String commandName = processCommandName(rawCommand);
    List<String> processedParameters = processParameters(rawCommand);
    ClientComponent cc = callingClient.getComponent(ClientComponent.class);
    if (cc.local) {
        if (!rawCommand.isEmpty() && (localCommandHistory.isEmpty() || !localCommandHistory.getLast().equals(rawCommand))) {
            localCommandHistory.add(rawCommand);
        }
    }
    return execute(new Name(commandName), processedParameters, callingClient);
}
Also used : ClientComponent(org.terasology.engine.network.ClientComponent) Name(org.terasology.gestalt.naming.Name)

Example 39 with ClientComponent

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

the class ConsoleImpl method clientHasPermission.

private boolean clientHasPermission(EntityRef callingClient, String requiredPermission) {
    Preconditions.checkNotNull(callingClient, "The calling client must not be null!");
    PermissionManager permissionManager = context.get(PermissionManager.class);
    boolean hasPermission = true;
    if (permissionManager != null && requiredPermission != null && !requiredPermission.equals(PermissionManager.NO_PERMISSION)) {
        hasPermission = false;
        ClientComponent clientComponent = callingClient.getComponent(ClientComponent.class);
        if (permissionManager.hasPermission(clientComponent.clientInfo, requiredPermission)) {
            hasPermission = true;
        }
    }
    return hasPermission;
}
Also used : PermissionManager(org.terasology.engine.logic.permission.PermissionManager) ClientComponent(org.terasology.engine.network.ClientComponent)

Example 40 with ClientComponent

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

the class ChatSystem method whisper.

@Command(runOnServer = true, requiredPermission = PermissionManager.CHAT_PERMISSION, shortDescription = "Sends a private message to a specified user")
public String whisper(@Sender EntityRef sender, @CommandParam(value = "user", suggester = OnlineUsernameSuggester.class) String username, @CommandParam("message") String[] message) {
    String messageToString = join(message, " ");
    Iterable<EntityRef> clients = entityManager.getEntitiesWith(ClientComponent.class);
    EntityRef targetClient = null;
    boolean unique = true;
    for (EntityRef client : clients) {
        ClientComponent clientComponent = client.getComponent(ClientComponent.class);
        DisplayNameComponent displayNameComponent = clientComponent.clientInfo.getComponent(DisplayNameComponent.class);
        if (displayNameComponent == null) {
            continue;
        }
        if (displayNameComponent.name.equalsIgnoreCase(username)) {
            if (targetClient == null) {
                targetClient = client;
            } else {
                unique = false;
                break;
            }
        }
    }
    if (!unique) {
        targetClient = null;
        for (EntityRef client : clients) {
            ClientComponent clientComponent = client.getComponent(ClientComponent.class);
            DisplayNameComponent displayNameComponent = clientComponent.clientInfo.getComponent(DisplayNameComponent.class);
            if (displayNameComponent == null) {
                continue;
            }
            if (displayNameComponent.name.equals(username)) {
                if (targetClient == null) {
                    targetClient = client;
                } else {
                    return FontColor.getColored("Found more users with name '" + username + "'.", ConsoleColors.ERROR);
                }
            }
        }
    }
    if (targetClient == null) {
        return FontColor.getColored("User with name '" + username + "' not found.", ConsoleColors.ERROR);
    }
    ClientComponent senderClientComponent = sender.getComponent(ClientComponent.class);
    ClientComponent targetClientComponent = targetClient.getComponent(ClientComponent.class);
    DisplayNameComponent targetDisplayNameComponent = targetClientComponent.clientInfo.getComponent(DisplayNameComponent.class);
    String targetMessage = FontColor.getColored("*whispering* ", ConsoleColors.ERROR) + FontColor.getColored(messageToString, ConsoleColors.CHAT);
    String senderMessage = "You -> " + targetDisplayNameComponent.name + ": " + FontColor.getColored(messageToString, ConsoleColors.CHAT);
    targetClient.send(new ChatMessageEvent(targetMessage, senderClientComponent.clientInfo));
    return senderMessage;
}
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)

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