Search in sources :

Example 1 with ClientInfoComponent

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

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

the class AbstractClient method createClientInfoEntity.

/**
 * Creates a client information entity on the current entity.
 * @param entityManager
 * @return Returns the client information.
 */
private EntityRef createClientInfoEntity(EntityManager entityManager) {
    EntityRef clientInfo;
    clientInfo = entityManager.create("engine:clientInfo");
    // mark clientInfo entities with a dedicated component
    ClientInfoComponent cic = new ClientInfoComponent();
    cic.playerId = getId();
    clientInfo.addComponent(cic);
    return clientInfo;
}
Also used : ClientInfoComponent(org.terasology.engine.network.ClientInfoComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef)

Example 3 with ClientInfoComponent

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

the class AbstractClient method disconnect.

@Override
public void disconnect() {
    EntityRef clientInfoEntity = clientEntity.getComponent(ClientComponent.class).clientInfo;
    ClientInfoComponent clientInfoComp = clientInfoEntity.getComponent(ClientInfoComponent.class);
    clientInfoComp.client = EntityRef.NULL;
    clientInfoEntity.saveComponent(clientInfoComp);
    clientEntity.destroy();
}
Also used : ClientInfoComponent(org.terasology.engine.network.ClientInfoComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ClientComponent(org.terasology.engine.network.ClientComponent)

Aggregations

EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)3 ClientInfoComponent (org.terasology.engine.network.ClientInfoComponent)3 ClientComponent (org.terasology.engine.network.ClientComponent)2 DisplayNameComponent (org.terasology.engine.logic.common.DisplayNameComponent)1