/// <summary>
/// Send a raw byte array payload as a packet
/// </summary>
/// <param name="payload">The packet payload</param>
/// <param name="setSequence">Whether the second, third, and fourth bytes
/// should be modified to the current stream sequence number</param>
public void SendPacketUnqueued(byte[] payload, bool setSequence)
{
try
{
if (setSequence && payload.Length > 3)
{
uint sequence = (uint)Interlocked.Increment(ref Sequence);
payload[1] = (byte)(sequence >> 16);
payload[2] = (byte)(sequence >> 8);
payload[3] = (byte)(sequence % 256);
}
Stats.SentBytes += (ulong)payload.Length;
++Stats.SentPackets;
UDPPacketBuffer buf = new UDPPacketBuffer(ipEndPoint);
Buffer.BlockCopy(payload, 0, buf.Data, 0, payload.Length);
buf.DataLength = payload.Length;
AsyncBeginSend(buf);
}
catch (SocketException)
{
Logger.Log("Tried to send a " + payload.Length +
" byte payload on a closed socket, shutting down " + this.ToString(),
Helpers.LogLevel.Info, Client);
Network.DisconnectSim(this, false);
return;
}
catch (Exception e)
{
Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e);
}
}