use of org.terasology.network.NetworkComponent in project Terasology by MovingBlocks.
the class ServerImpl method updateEntity.
private void updateEntity(NetData.UpdateEntityMessage updateEntity) {
EntityRef currentEntity = networkSystem.getEntity(updateEntity.getNetId());
if (currentEntity.exists()) {
NetworkComponent netComp = currentEntity.getComponent(NetworkComponent.class);
if (netComp == null) {
logger.error("Updating entity with no network component: {}, expected netId {}", currentEntity, updateEntity.getNetId());
return;
}
if (netComp.getNetworkId() != updateEntity.getNetId()) {
logger.error("Network ID wrong before update");
}
boolean blockEntityBefore = currentEntity.hasComponent(BlockComponent.class);
entitySerializer.deserializeOnto(currentEntity, updateEntity.getEntity());
BlockComponent blockComponent = currentEntity.getComponent(BlockComponent.class);
if (blockComponent != null && !blockEntityBefore) {
if (!blockEntityRegistry.getExistingBlockEntityAt(blockComponent.getPosition()).equals(currentEntity)) {
logger.error("Failed to associated new block entity");
}
}
if (netComp.getNetworkId() != updateEntity.getNetId()) {
logger.error("Network ID lost in update: {}, {} -> {}", currentEntity, updateEntity.getNetId(), netComp.getNetworkId());
}
} else {
logger.warn("Received update for non-existent entity {}", updateEntity.getNetId());
}
}
use of org.terasology.network.NetworkComponent in project Terasology by MovingBlocks.
the class PojoEntityRef method toString.
@Override
public String toString() {
Prefab parent = getParentPrefab();
StringBuilder builder = new StringBuilder();
builder.append("EntityRef{id = ");
builder.append(id);
NetworkComponent networkComponent = getComponent(NetworkComponent.class);
if (networkComponent != null) {
builder.append(", netId = ");
builder.append(networkComponent.getNetworkId());
}
if (parent != null) {
builder.append(", prefab = '");
builder.append(parent.getUrn());
builder.append("'");
}
builder.append("}");
return builder.toString();
}
use of org.terasology.network.NetworkComponent in project Terasology by MovingBlocks.
the class EventSystemImpl method broadcastEvent.
private void broadcastEvent(EntityRef entity, Event event, EventMetadata metadata) {
if (networkSystem.getMode().isServer()) {
NetworkComponent netComp = entity.getComponent(NetworkComponent.class);
BlockComponent blockComp = entity.getComponent(BlockComponent.class);
if (netComp != null || blockComp != null) {
Client instigatorClient = null;
if (metadata.isSkipInstigator() && event instanceof NetworkEvent) {
instigatorClient = networkSystem.getOwner(((NetworkEvent) event).getInstigator());
}
for (Client client : networkSystem.getPlayers()) {
if (!client.equals(instigatorClient)) {
client.send(event, entity);
}
}
}
}
}
use of org.terasology.network.NetworkComponent in project Terasology by MovingBlocks.
the class NetworkOwnershipTest method testClientNoInitialEntityIfNotOwnedAndReplicateToOwner.
@Test
public void testClientNoInitialEntityIfNotOwnedAndReplicateToOwner() {
connectClient();
NetworkComponent netComp = new NetworkComponent();
netComp.replicateMode = NetworkComponent.ReplicateMode.OWNER;
EntityRef entity = entityManager.create(netComp);
networkSystem.registerNetworkEntity(entity);
assertTrue(entity.getComponent(NetworkComponent.class).getNetworkId() != 0);
verify(client, times(0)).setNetInitial(entity.getComponent(NetworkComponent.class).getNetworkId());
}
use of org.terasology.network.NetworkComponent in project Terasology by MovingBlocks.
the class NetworkOwnershipTest method testClientSentInitialOnlyOnce.
@Test
public void testClientSentInitialOnlyOnce() {
EntityBuilder builder = entityManager.newBuilder();
NetworkComponent netComp = builder.addComponent(new NetworkComponent());
netComp.replicateMode = NetworkComponent.ReplicateMode.OWNER;
builder.setOwner(clientEntity);
EntityRef entity = builder.build();
networkSystem.registerNetworkEntity(entity);
connectClient();
networkSystem.updateOwnership(entity);
verify(client, times(1)).setNetInitial(entity.getComponent(NetworkComponent.class).getNetworkId());
}
Aggregations