use of org.terasology.engine.network.Client in project Terasology by MovingBlocks.
the class ServerViewDistanceSystem method onChangeViewDistanceChanged.
@ReceiveEvent(components = ClientComponent.class)
public void onChangeViewDistanceChanged(ViewDistanceChangedEvent request, EntityRef entity) {
Client client = networkSystem.getOwner(entity);
if (client != null) {
client.setViewDistanceMode(request.getNewViewRange());
relevanceSystem.updateRelevanceEntityDistance(entity, client.getViewDistance().getChunkDistance());
}
}
use of org.terasology.engine.network.Client 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";
}
use of org.terasology.engine.network.Client in project Terasology by MovingBlocks.
the class SetupLocalPlayer method step.
@Override
public boolean step() {
PlayerConfig playerConfig = context.get(PlayerConfig.class);
Client localClient = context.get(NetworkSystem.class).joinLocal(playerConfig.playerName.get(), playerConfig.color.get());
context.get(LocalPlayer.class).setClientEntity(localClient.getEntity());
return true;
}
use of org.terasology.engine.network.Client in project Terasology by MovingBlocks.
the class NetworkSystemImpl method joinLocal.
@Override
public Client joinLocal(String preferredName, Color color) {
Client localClient = new LocalClient(preferredName, color, entityManager);
clientList.add(localClient);
clientPlayerLookup.put(localClient.getEntity(), localClient);
connectClient(localClient);
return localClient;
}
use of org.terasology.engine.network.Client in project Terasology by MovingBlocks.
the class NetClient method sendInitialEntities.
private void sendInitialEntities(NetData.NetMessage.Builder message) {
int[] initial = netInitial.toArray();
netInitial.clear();
Arrays.sort(initial);
for (int netId : initial) {
netRelevant.add(netId);
EntityRef entity = networkSystem.getEntity(netId);
if (!entity.hasComponent(NetworkComponent.class)) {
logger.error("Sending net entity with no network component: {} - {}", netId, entity);
continue;
}
// Note: Send owner->server fields on initial create
Client owner = networkSystem.getOwner(entity);
EntityData.PackedEntity entityData = entitySerializer.serialize(entity, true, new ServerComponentFieldCheck(owner == this, true)).build();
NetData.CreateEntityMessage.Builder createMessage = NetData.CreateEntityMessage.newBuilder().setEntity(entityData);
BlockComponent blockComponent = entity.getComponent(BlockComponent.class);
if (blockComponent != null) {
createMessage.setBlockPos(NetMessageUtil.convert(blockComponent.getPosition()));
}
message.addCreateEntity(createMessage);
}
}
Aggregations