public void SendMessageToIds(IEnumerable <long> uniqueIds, INetworkMessageOut message, MessageDeliveryMethod deliveryMethod, int channel) { if (_netPeer == null) { throw new NullReferenceException("NetPeer was not initialized."); } message.Encrypt(); var connections = new List <NetConnection>(4); foreach (var uniqueId in uniqueIds) { for (int i = 0; i < _netPeer.Connections.Count; i++) { var connection = _netPeer.Connections[i]; if (connection.RemoteUniqueIdentifier == uniqueId) { connections.Add(connection); break; } } } var outMessage = ((NetworkMessageOutLidgren)message).GetInternalMessage(); try { _netPeer.SendMessage(outMessage, connections, deliveryMethod.ToDeliveryMethod(), channel); } catch { // todo: throw? } }
/// <summary> /// Runs on server. /// </summary> public override void Serialize(INetworkMessageOut message) { // remember to write on the same sequence that we read message.Write(_pointsLeft); message.Write(_pointsRight); // always call the base Serialize to ensure all properties are replicated base.Serialize(message); }
public void SendMessageToAll(INetworkMessageOut message, MessageDeliveryMethod deliveryMethod, int channel) { if (_netPeer == null) { throw new NullReferenceException("NetPeer was not initialized."); } message.Encrypt(); var outMessage = ((NetworkMessageOutLidgren)message).GetInternalMessage(); _netPeer.SendMessage(outMessage, _netPeer.Connections, deliveryMethod.ToDeliveryMethod(), channel); }
private static void AppendActorCreationMessage(INetworkMessageOut message, INetworkedActor localActor) { var actorLocation = localActor.GetLocation(); message.Write(localActor.Id); message.Write(actorLocation.X); message.Write(actorLocation.Y); message.Write(CompatibilityManager.GetHashCode(localActor.GetType().Name)); if (localActor.ReplicateProperties) { localActor.Serialize(message); } }
public void SendMessageToId(long uniqueId, INetworkMessageOut message, MessageDeliveryMethod deliveryMethod, int channel) { if (_netPeer == null) { throw new NullReferenceException("NetPeer was not initialized."); } message.Encrypt(); var outMessage = ((NetworkMessageOutLidgren)message).GetInternalMessage(); for (int i = 0; i < _netPeer.Connections.Count; i++) { var connection = _netPeer.Connections[i]; if (connection.RemoteUniqueIdentifier == uniqueId) { _netPeer.SendMessage(outMessage, connection, deliveryMethod.ToDeliveryMethod(), channel); break; } } }
/// <summary> /// This code prepares the message on the server to send properties to all the clients when IsDirty is true. /// </summary> public virtual void Serialize(INetworkMessageOut message) { }
protected void SendMessageToIds(IEnumerable <long> uniqueIds, INetworkMessageOut message, MessageDeliveryMethod deliveryMethod, int channel) { NetworkImplementation?.SendMessageToIds(uniqueIds, message, deliveryMethod, channel); }
protected void SendMessageToId(long uniqueId, INetworkMessageOut message, MessageDeliveryMethod deliveryMethod, int channel) { NetworkImplementation?.SendMessageToId(uniqueId, message, deliveryMethod, channel); }
protected void SendMessageToSender(INetworkMessageIn to, INetworkMessageOut message, MessageDeliveryMethod deliveryMethod, int channel) { NetworkImplementation?.SendMessageToSender(to, message, deliveryMethod, channel); }