use of org.terasology.engine.network.NetworkComponent in project Terasology by MovingBlocks.
the class ServerCommands method listUsers.
@Command(shortDescription = "List users", requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION)
public String listUsers() {
StringBuilder stringBuilder = new StringBuilder();
for (EntityRef clientInfo : entityManager.getEntitiesWith(ClientInfoComponent.class)) {
DisplayNameComponent dnc = clientInfo.getComponent(DisplayNameComponent.class);
NetworkComponent nc = clientInfo.getComponent(NetworkComponent.class);
String playerText = PlayerUtil.getColoredPlayerName(clientInfo);
String line = String.format("%s - %s (%d)", playerText, dnc.description, nc.getNetworkId());
stringBuilder.append(line);
stringBuilder.append(Console.NEW_LINE);
}
return stringBuilder.toString();
}
use of org.terasology.engine.network.NetworkComponent in project Terasology by MovingBlocks.
the class NetworkSystemImpl method registerNetworkEntity.
public void registerNetworkEntity(EntityRef entity) {
if (mode == NetworkMode.NONE) {
return;
}
if (mode.isServer()) {
NetworkComponent netComponent = entity.getComponent(NetworkComponent.class);
netComponent.setNetworkId(nextNetId++);
entity.saveComponent(netComponent);
netIdToEntityId.put(netComponent.getNetworkId(), entity.getId());
switch(netComponent.replicateMode) {
case OWNER:
NetClient clientPlayer = getNetOwner(entity);
if (clientPlayer != null) {
clientPlayer.setNetInitial(netComponent.getNetworkId());
}
break;
default:
for (NetClient client : netClientList) {
// TODO: Relevance Check
client.setNetInitial(netComponent.getNetworkId());
}
break;
}
EntityRef owner = entity.getOwner();
if (owner.exists()) {
ownerLookup.put(entity, owner);
ownedLookup.put(owner, entity);
}
}
}
use of org.terasology.engine.network.NetworkComponent in project Terasology by MovingBlocks.
the class NetworkSystemImpl method unregisterNetworkEntity.
public void unregisterNetworkEntity(EntityRef entity) {
if (mode != NetworkMode.CLIENT) {
NetworkComponent netComponent = entity.getComponent(NetworkComponent.class);
if (netComponent != null) {
logger.debug("Unregistering network entity: {} with netId {}", entity, netComponent.getNetworkId());
netIdToEntityId.remove(netComponent.getNetworkId());
if (mode.isServer()) {
for (NetClient client : netClientList) {
client.setNetRemoved(netComponent.getNetworkId());
}
}
netComponent.setNetworkId(NULL_NET_ID);
entity.saveComponent(netComponent);
}
}
ownerLookup.remove(entity);
}
use of org.terasology.engine.network.NetworkComponent in project Terasology by MovingBlocks.
the class NetworkSystemImpl method updateOwnership.
public void updateOwnership(EntityRef entity) {
NetworkComponent netComponent = entity.getComponent(NetworkComponent.class);
if (netComponent == null || netComponent.getNetworkId() == NULL_NET_ID) {
return;
}
EntityRef lastOwnerEntity = ownerLookup.get(entity);
if (lastOwnerEntity == null) {
lastOwnerEntity = EntityRef.NULL;
}
EntityRef newOwnerEntity = entity.getOwner();
if (!Objects.equal(lastOwnerEntity, newOwnerEntity)) {
NetClient lastOwner = getNetOwner(lastOwnerEntity);
NetClient newOwner = getNetOwner(newOwnerEntity);
if (!Objects.equal(lastOwner, newOwner)) {
recursiveUpdateOwnership(entity, lastOwner, newOwner);
if (newOwner != null) {
int id = netComponent.getNetworkId();
for (Component component : entity.iterateComponents()) {
if (componentLibrary.getMetadata(component.getClass()).isReplicated()) {
newOwner.setComponentDirty(id, component.getClass());
}
}
}
}
if (lastOwnerEntity.exists()) {
ownedLookup.remove(lastOwnerEntity, entity);
}
if (newOwnerEntity.exists()) {
ownerLookup.put(entity, newOwnerEntity);
ownedLookup.put(newOwnerEntity, entity);
} else {
ownerLookup.remove(entity);
}
}
}
use of org.terasology.engine.network.NetworkComponent in project Terasology by MovingBlocks.
the class NetworkSystemImpl method onEntityComponentAdded.
@Override
public void onEntityComponentAdded(EntityRef entity, Class<? extends Component> component) {
ComponentMetadata<? extends Component> metadata = componentLibrary.getMetadata(component);
NetworkComponent netComp = entity.getComponent(NetworkComponent.class);
if (netComp != null && netComp.getNetworkId() != NULL_NET_ID) {
if (mode.isServer()) {
if (metadata.isReplicated()) {
for (NetClient client : netClientList) {
logger.debug("Component {} added to {}", component, entity);
client.setComponentAdded(netComp.getNetworkId(), component);
}
}
}
}
updatedOwnedEntities(entity, component, metadata);
}
Aggregations