private void SendDatagram(PlayerNetworkSession session, Datagram datagram) { if (datagram.MessageParts.Count == 0) { datagram.PutPool(); Log.WarnFormat("Failed to resend #{0}", datagram.Header.datagramSequenceNumber.IntValue()); return; } datagram.Header.datagramSequenceNumber = Interlocked.Increment(ref session.DatagramSequenceNumber); datagram.TransmissionCount++; byte[] data = datagram.Encode(); datagram.Timer.Restart(); if (!session.WaitingForAcksQueue.TryAdd(datagram.Header.datagramSequenceNumber.IntValue(), datagram)) { Log.Warn(string.Format("Datagram sequence unexpectedly existed in the ACK/NAK queue already {0}", datagram.Header.datagramSequenceNumber.IntValue())); } //datagram.PutPool(); lock (session.SyncRoot) { SendData(data, session.EndPoint); } }
internal async Task SendDatagramAsync(RakSession session, Datagram datagram) { if (datagram.MessageParts.Count == 0) { Log.Warn($"Failed to send #{datagram.Header.DatagramSequenceNumber.IntValue()}"); datagram.PutPool(); return; } if (datagram.TransmissionCount > 10) { if (Log.IsDebugEnabled) { Log.Warn($"Retransmission count exceeded. No more resend of #{datagram.Header.DatagramSequenceNumber.IntValue()} Type: {datagram.FirstMessageId} (0x{datagram.FirstMessageId:x2}) for {session.Username}"); } datagram.PutPool(); Interlocked.Increment(ref ServerInfo.NumberOfFails); //TODO: Disconnect! Because of encryption, this connection can't be used after this point return; } datagram.Header.DatagramSequenceNumber = Interlocked.Increment(ref session.DatagramSequenceNumber); datagram.TransmissionCount++; datagram.RetransmitImmediate = false; byte[] buffer = ArrayPool <byte> .Shared.Rent(1600); int length = (int)datagram.GetEncoded(ref buffer); datagram.Timer.Restart(); if (!session.WaitingForAckQueue.TryAdd(datagram.Header.DatagramSequenceNumber.IntValue(), datagram)) { Log.Warn($"Datagram sequence unexpectedly existed in the ACK/NAK queue already {datagram.Header.DatagramSequenceNumber.IntValue()}"); datagram.PutPool(); } //lock (session.SyncRoot) { await SendDataAsync(buffer, length, session.EndPoint); ArrayPool <byte> .Shared.Return(buffer); } }
internal void SendDatagram(PlayerNetworkSession session, Datagram datagram) { if (datagram.MessageParts.Count == 0) { datagram.PutPool(); Log.WarnFormat("Failed to resend #{0}", datagram.Header.datagramSequenceNumber.IntValue()); return; } if (datagram.TransmissionCount > 10) { if (Log.IsDebugEnabled) { Log.WarnFormat("Retransmission count exceeded. No more resend of #{0} Type: {2} (0x{2:x2}) for {1}", datagram.Header.datagramSequenceNumber.IntValue(), session.Username, datagram.FirstMessageId); } datagram.PutPool(); Interlocked.Increment(ref ServerInfo.NumberOfFails); return; } datagram.Header.datagramSequenceNumber = Interlocked.Increment(ref session.DatagramSequenceNumber); datagram.TransmissionCount++; datagram.RetransmitImmediate = false; //byte[] data = datagram.Encode(); byte[] data; var lenght = (int)datagram.GetEncoded(out data); datagram.Timer.Restart(); if (!session.WaitingForAcksQueue.TryAdd(datagram.Header.datagramSequenceNumber.IntValue(), datagram)) { Log.Warn(string.Format("Datagram sequence unexpectedly existed in the ACK/NAK queue already {0}", datagram.Header.datagramSequenceNumber.IntValue())); } lock (session.SyncRoot) { SendData(data, lenght, session.EndPoint); } }
internal void SendDatagram(PlayerNetworkSession session, Datagram datagram) { if (datagram.MessageParts.Count == 0) { datagram.PutPool(); Log.WarnFormat("Failed to resend #{0}", datagram.Header.datagramSequenceNumber.IntValue()); return; } if (datagram.TransmissionCount > 10) { if (Log.IsDebugEnabled) { Log.WarnFormat("TIMEOUT, Retransmission count remove from ACK queue #{0} Type: {2} (0x{2:x2}) for {1}", datagram.Header.datagramSequenceNumber.IntValue(), session.Username, datagram.FirstMessageId); } datagram.PutPool(); Interlocked.Increment(ref ServerInfo.NumberOfFails); return; } datagram.Header.datagramSequenceNumber = Interlocked.Increment(ref session.DatagramSequenceNumber); datagram.TransmissionCount++; byte[] data = datagram.Encode(); datagram.Timer.Restart(); if (!session.WaitingForAcksQueue.TryAdd(datagram.Header.datagramSequenceNumber.IntValue(), datagram)) { Log.Warn(string.Format("Datagram sequence unexpectedly existed in the ACK/NAK queue already {0}", datagram.Header.datagramSequenceNumber.IntValue())); } lock (session.SyncRoot) { SendData(data, session.EndPoint); Thread.Sleep(12); } }
private void SendDatagram(IPEndPoint senderEndpoint, Datagram datagram) { PlayerNetworkSession session; if (_playerSessions.TryGetValue(senderEndpoint, out session)) { if (datagram.MessageParts.Count != 0) { //if (!isResend) { datagram.Header.datagramSequenceNumber = Interlocked.Increment(ref session.DatagramSequenceNumber); } byte[] data = datagram.Encode(); SendData(data, senderEndpoint, session.SyncRoot); datagram.TransmissionCount++; datagram.Timer.Restart(); if (!session.Player.IsBot) { session.WaitingForAcksQueue.TryAdd(datagram.Header.datagramSequenceNumber, datagram); } } if (session.Player.IsBot) { foreach (MessagePart part in datagram.MessageParts) { part.PutPool(); } datagram.PutPool(); } } }
private void SendDatagram(PlayerNetworkSession session, Datagram datagram) { if (datagram.MessageParts.Count == 0) { datagram.PutPool(); Log.WarnFormat("Failed to resend #{0}", datagram.Header.datagramSequenceNumber.IntValue()); return; } datagram.Header.datagramSequenceNumber = Interlocked.Increment(ref session.DatagramSequenceNumber); datagram.TransmissionCount++; byte[] data = datagram.Encode(); datagram.Timer.Restart(); if (!session.WaitingForAcksQueue.TryAdd(datagram.Header.datagramSequenceNumber.IntValue(), datagram)) { Log.Warn(string.Format("Datagram sequence unexpectedly existed in the ACK/NAK queue already {0}", datagram.Header.datagramSequenceNumber.IntValue())); } lock (session.SyncRoot) { SendData(data, session.EndPoint); } }
private void SendDatagram(IPEndPoint senderEndpoint, Datagram datagram) { PlayerNetworkSession session; if (_playerSessions.TryGetValue(senderEndpoint, out session)) { if (datagram.MessageParts.Count != 0) { //if (!isResend) { datagram.Header.datagramSequenceNumber = Interlocked.Increment(ref session.DatagramSequenceNumber); } byte[] data = datagram.Encode(); SendData(data, senderEndpoint, session.SyncRoot); datagram.TransmissionCount++; datagram.Timer.Restart(); if (!session.Player.IsBot) { session.WaitingForAcksQueue.TryAdd(datagram.Header.datagramSequenceNumber, datagram); } } if (session.Player.IsBot) { foreach (MessagePart part in datagram.MessageParts) { part.PutPool(); } datagram.PutPool(); } } }
private void SendDatagram(IPEndPoint senderEndpoint, Datagram datagram) { PlayerNetworkSession session; if (_playerSessions.TryGetValue(senderEndpoint, out session)) { if (datagram.MessageParts.Count != 0) { //if (!isResend) { datagram.Header.datagramSequenceNumber = Interlocked.Increment(ref session.DatagramSequenceNumber); } byte[] data = datagram.Encode(); if (!session.Player.IsBot) { if (!session.WaitingForAcksQueue.TryAdd(datagram.Header.datagramSequenceNumber.IntValue(), datagram)) { Log.Warn(string.Format("Datagram sequence unexpectedly existed in the ACK/NAK queue already {0}", datagram.Header.datagramSequenceNumber.IntValue())); } } datagram.TransmissionCount++; SendData(data, senderEndpoint, session.SyncRoot); datagram.Timer.Restart(); } if (session.Player.IsBot) { foreach (MessagePart part in datagram.MessageParts) { part.PutPool(); } datagram.PutPool(); } } }
private void SendDatagram(PlayerNetworkSession session, Datagram datagram, bool updateCounter) { if (datagram.MessageParts.Count == 0) { datagram.PutPool(); Log.WarnFormat("Failed to resend #{0}", datagram.Header.datagramSequenceNumber.IntValue()); return; } if (updateCounter) { datagram.Header.datagramSequenceNumber = Interlocked.Increment(ref session.DatagramSequenceNumber); } datagram.TransmissionCount++; byte[] data = datagram.Encode(); datagram.Timer.Restart(); if (!session.WaitingForAcksQueue.TryAdd(datagram.Header.datagramSequenceNumber.IntValue(), datagram)) { Log.Warn(string.Format("Datagram sequence unexpectedly existed in the ACK/NAK queue already {0}", datagram.Header.datagramSequenceNumber.IntValue())); } lock (session.SyncRoot) { SendData(data, session.EndPoint, session.SyncRoot); int sndDelay = (int) (50f/4f); sndDelay = sndDelay + (20*(1/(datagram.Header.datagramSequenceNumber.IntValue() + 1))); //Thread.Sleep(sndDelay); // Really important to slow down speed a bit } }