private async Task SendAckQueueAsync() { RaknetSession session = this; var queue = session.OutgoingAckQueue; int queueCount = queue.Count; if (queueCount == 0) { return; } var acks = new Acks(); for (int i = 0; i < queueCount; i++) { if (!queue.TryDequeue(out int ack)) { break; } Interlocked.Increment(ref ConnectionInfo.NumberOfAckSent); acks.acks.Add(ack); } if (acks.acks.Count > 0) { byte[] data = acks.Encode(); await _packetSender.SendDataAsync(data, session.EndPoint); } //acks.PutPool(); }
private async Task SendNackQueueAsync() { RaknetSession session = this; var queue = session.OutgoingNackQueue; int queueCount = queue.Count; if (queueCount == 0) { return; } var acks = new CustomNak(); for (int i = 0; i < queueCount; i++) { if (!queue.TryDequeue(out int ack)) { break; } ConnectionInfo.NumberOfPlayers++; acks.naks.Add(ack); } if (acks.naks.Count > 0) { byte[] data = acks.Encode(); await _packetSender.SendDataAsync(data, session.EndPoint); } //acks.PutPool(); }
public void Close(RaknetSession session) { var ackQueue = session.WaitingForAckQueue; foreach (var kvp in ackQueue) { if (ackQueue.TryRemove(kvp.Key, out Datagram datagram)) { datagram.PutPool(); } } var splits = session.Splits; foreach (var kvp in splits) { if (splits.TryRemove(kvp.Key, out SplitPartPacket[] splitPartPackets))
//public ConcurrentDictionary<IPEndPoint, RakSession> _sessions = new ConcurrentDictionary<IPEndPoint, RakSession>(); private void SendConnectionRequest(IPEndPoint targetEndPoint, short mtuSize) { RaknetSession session = _connection.Session; // lock (session) { if (session != null) { Log.Warn($"Session already exist, ignoring"); return; } session = new RaknetSession(_connectionInfo, _connection, targetEndPoint, mtuSize) { State = ConnectionState.Connecting, LastUpdatedTime = DateTime.UtcNow, NetworkIdentifier = ClientGuid, }; session.CustomMessageHandler = _connection.CustomMessageHandlerFactory?.Invoke(session); _connection.Session = session; /*if (!sessions.TryAdd(targetEndPoint, session)) * { * Log.Warn($"Session already exist, ignoring"); * return; * }*/ } var packet = ConnectionRequest.CreateObject(); packet.clientGuid = ClientGuid; packet.timestamp = DateTime.UtcNow.Ticks; packet.doSecurity = 0; session.SendPacket(packet); }