예제 #1
0
        void SendToEncrypted(Span <byte> payload, uint userId, IPEndPoint endPoint, CachedEncryptionKey keyInfo)
        {
            var packet       = _sendBufferPool.Get();
            int packetLength = _packetEncryption.CreateEncryptedPacket(payload, packet, false, userId, keyInfo);

            _socket.SendTo(packet, 0, packetLength, SocketFlags.None, endPoint);
            _sendBufferPool.Add(packet);
        }
예제 #2
0
        public void SendFloorIdle(ushort groupId, Span <IPEndPoint> endPoints, CachedEncryptionKey keyInfo)
        {
            var buffer = _sendBufferPool.Get();

            // Packet Type
            buffer[0] = (byte)RopuPacketType.FloorIdle;
            // Group ID (ushort)
            buffer.WriteUshort(groupId, 1);

            BulkSendEncrypted(buffer.AsSpan(0, 3), groupId, endPoints, keyInfo);
            _sendBufferPool.Add(buffer);
        }
예제 #3
0
        void BulkSendEncrypted(Span <byte> payload, ushort groupId, Span <IPEndPoint> endPoints, CachedEncryptionKey keyInfo)
        {
            var packet       = _sendBufferPool.Get();
            int packetLength = _packetEncryption.CreateEncryptedPacket(payload, packet, true, groupId, keyInfo);

            BulkSendAsync(packet, packetLength, endPoints, () => _sendBufferPool.Add(packet));
        }
예제 #4
0
        public void SendCallStartFailed(CallFailedReason reason, uint userId, IPEndPoint endPoint, CachedEncryptionKey keyInfo)
        {
            var buffer = _sendBufferPool.Get();

            // Packet Type
            buffer[0] = (byte)RopuPacketType.CallStartFailed;
            // User ID (uint32)
            buffer.WriteUint(userId, 1);
            //* Reason (byte) 0 = insufficient resources, 255 = other reason
            buffer[5] = (byte)CallFailedReason.InsufficientResources;

            SendToEncrypted(buffer.AsSpan(0, 6), userId, endPoint, keyInfo);
            _sendBufferPool.Add(buffer);
        }
예제 #5
0
        public void BulkSendAsync(byte[] buffer, int length, Span <IPEndPoint> endPoints, Action <object?> onComplete, object state, uint groupId, CachedEncryptionKey keyInfo)
        {
            var token = _bulkRequestTokenPool.Get();

            token.Reset();
            token.Finished = onComplete;
            token.State    = state;

            for (int endpointIndex = 0; endpointIndex < endPoints.Length; endpointIndex++)
            {
                var args = _socketEventArgsPool.Get();
                args.RemoteEndPoint = endPoints[endpointIndex];
                SetBufferEncrypted(args, buffer, length, groupId, keyInfo);
                args.UserToken = token;

                if (!_socket.SendToAsync(args))
                {
                    //completed syncronously
                    _socketEventArgsPool.Add(args); //release the memory back to the pool
                }
                else
                {
                    token.IncrementWaitingCount();
                }
            }
            lock (_asyncCompleteLock)
            {
                if (token.WaitingCount == 0)
                {
                    token.Finish();
                    return;
                }
            }
        }
예제 #6
0
        void SetBufferEncrypted(SocketAsyncEventArgs args, byte[] buffer, int length, uint groupId, CachedEncryptionKey keyInfo)
        {
            int packetLength = _packetEncryption.CreateEncryptedPacket(buffer.AsSpan(0, length), _encryptedBuffer, true, groupId, keyInfo);

            args.SetBuffer(_encryptedBuffer, 0, packetLength);
        }
예제 #7
0
        public void SendGroupPacket(byte[] packet, int length, IPEndPoint target, uint groupId, CachedEncryptionKey keyInfo)
        {
            int packetLength = _packetEncryption.CreateEncryptedPacket(packet.AsSpan(0, length), _encryptedBuffer, true, groupId, keyInfo);

            _socket.SendTo(_encryptedBuffer, 0, packetLength, SocketFlags.None, target);
        }