Ejemplo n.º 1
0
        internal async Task SendPublicMessageAsync(PublicChatRoom chatRoom, string content)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(null);
            }

            if (!_publicRooms.Contains(chatRoom))
            {
                throw new NotSupportedException("Enter ChatRoom first.");
            }

            try
            {
                var message = new Message
                {
                    Content   = content,
                    Sender    = _publicIdentity,
                    TimeStamp = DateTimeOffset.Now.ToUnixTimeSeconds()
                };
                var signedData = await CreateSignAndEncodeDataAsync(message);

                var encrypted = CryptUtils.AesEncryptByteArray(signedData, chatRoom.PreSharedKey);

                var chatRoomIdentifier = chatRoom.GetEncryptedIdentifier();
                var packet             = new PublicMessagePacket(encrypted, chatRoomIdentifier);

                await _networkHandler.SendPacketAsync(packet);
            }
            catch (Exception) when(_disposed)
            {
            }
        }
Ejemplo n.º 2
0
        internal PublicChatRoom EnterPublicChatRoom(string name, byte[] preSharedKey)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }
            if (preSharedKey == null)
            {
                throw new ArgumentNullException(nameof(preSharedKey));
            }
            var chatRoom = new PublicChatRoom(this, name, preSharedKey);

            _publicRooms.Add(chatRoom);
            return(chatRoom);
        }
Ejemplo n.º 3
0
 internal void LeavePublicChatRoom(PublicChatRoom chatRoom)
 {
     _publicRooms.Remove(chatRoom);
 }