private void SendRaw(Action <Stream> writer, Stormancer.Core.PacketPriority priority, Stormancer.Core.PacketReliability reliability, char channel) { var stream = new BitStream(); writer(new BSStream(stream)); var result = _rakPeer.Send(stream, (RakNet.PacketPriority)priority, (RakNet.PacketReliability)reliability, channel, this.Guid, false); if (result == 0) { throw new InvalidOperationException("Failed to send message."); } }
/// <summary> /// Sends a system request to the remote peer. /// </summary> /// <param name="msgId">Id of the system message</param> /// <param name="writer"></param> /// <param name="priority">The priority of the message to send</param> public void SendSystem(byte msgId, Action <System.IO.Stream> writer, Stormancer.Core.PacketPriority priority) { if (writer == null) { throw new ArgumentNullException("writer"); } SendRaw(s => { s.WriteByte(msgId); writer(s); }, priority, Core.PacketReliability.RELIABLE_ORDERED, (char)0); }
/// <summary> /// Sends a scene request to the remote peer. /// </summary> /// <param name="sceneIndex"></param> /// <param name="route"></param> /// <param name="writer"></param> /// <param name="priority"></param> /// <param name="reliability"></param> public void SendToScene(byte sceneIndex, ushort route, Action <System.IO.Stream> writer, Stormancer.Core.PacketPriority priority, Stormancer.Core.PacketReliability reliability) { if (writer == null) { throw new ArgumentNullException("writer"); } var stream = new BitStream(); var s = new BSStream(stream); s.WriteByte(sceneIndex); s.Write(BitConverter.GetBytes(route), 0, 2); writer(s); char channel = (char)0; if (reliability == Core.PacketReliability.RELIABLE_SEQUENCED || reliability == Core.PacketReliability.UNRELIABLE_SEQUENCED) { channel = GetChannel(sceneIndex, route); } var result = _rakPeer.Send(stream, (RakNet.PacketPriority)priority, (RakNet.PacketReliability)reliability, channel, this.Guid, false); if (result == 0) { throw new InvalidOperationException("Failed to send message."); } }