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);
}
}
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;
}
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();
}
Aggregations