/// <summary> /// Broadcasts a message to all clients to update the provided entity. /// Note that this is broadcast only. No updating should happen until /// a message is received. /// </summary> /// <param name="entity">The entity to update.</param> public void RequestUpdateEntity(INetworkEntity entity) { if (Role == NetworkRole.Server) { UpdateEntity(entity.EntityId, entity.OwnerId, entity.GetState(), true, ServerTime); } else { SendDataMessage(entity, NetworkMessageType.Update); } }
/// <summary> /// Uses the provided entity to compose a data message. /// ReliableSequenced method is suggested to balance performance with deliverability. /// </summary> /// <param name="entity">The entity to build a message from.</param> /// <param name="action">The type of message to send.</param> /// <param name="method">Delivery method.</param> /// <param name="recipient">The recipient connection. Will send to all if null.</param> private void SendDataMessage(INetworkEntity entity, NetworkMessageType action, NetConnection recipient = null) { // clients can't force a message for an entity they don't own if (Role != NetworkRole.Server && entity.OwnerId != NetworkId) { throw new RedGrinException("Cannot send an update for an entity that is not owned by this client!"); } object payload = entity.GetState(); SendDataMessage(entity.EntityId, entity.OwnerId, payload, action, recipient); }
/// <summary> /// Uses the provided entity to compose a data message. /// ReliableSequenced method is suggested to balance performance with deliverability. /// </summary> /// <param name="entity">The entity to build a message from.</param> /// <param name="action">The type of message to send.</param> /// <param name="method">Delivery method.</param> /// <param name="recipient">The recipient connection. Will send to all if null.</param> private void SendDataMessage(INetworkEntity entity, NetworkMessageType action, NetConnection recipient = null) { object payload = entity.GetState(); SendDataMessage(entity.Id, payload, action, recipient); }