Example #1
0
        private static void OnMessageTransmission(PacketTransmissionEventArgs e)
        {
            EventHandler <PacketTransmissionEventArgs> handler = MessageTransmission;

            if (handler != null)
            {
                handler(null, e);
            }
        }
Example #2
0
        /// <summary>
        /// Send a packet to a target IP address.
        /// </summary>
        /// <param name="sender">Default object parameter for event receiving methods. Unused here.</param>
        /// <param name="args">PacketTransmissionEventArgs object containing the byte array to be send and the destination IP address.</param>
        public void SendPacket(object sender, PacketTransmissionEventArgs args)
        {
            ControlledPacket ctrlPacket = new ControlledPacket();

            ctrlPacket.Recipient = args.Destination;
            ctrlPacket.Data      = args.PacketContent;

            _messageSendingControlList.Add(ctrlPacket);
        }
Example #3
0
        public static void MessageTransmissionHandler(Message message)
        {
            byte[] messageBytes = ChatTwo_Protocol.MessageTransmissionHandler(message);

            string sharedSecret;

            if (message.Type == ChatTwo_Protocol.MessageType.CreateUser)
            {
                sharedSecret = ChatTwo_Protocol.DefaultSharedSecret;
            }
            else if (message.Type == ChatTwo_Protocol.MessageType.Login)
            {
                ServerSharedSecret = ByteHelper.GetHashString(messageBytes);
                sharedSecret       = ServerSharedSecret;
            }
            else if (message.To == ChatTwo_Protocol.ServerReserrvedUserID)
            {
                sharedSecret = ServerSharedSecret;
            }
            else
            {
                int userId = message.To;
                sharedSecret = _contacts.Find(x => x.ID == userId).Secret;

                // Testing!!!! REMOVE THIS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                sharedSecret = ChatTwo_Protocol.DefaultSharedSecret;
            }

            messageBytes = ChatTwo_Protocol.AddSignatureAndMac(messageBytes, sharedSecret);

            // Fire an OnMessageTransmission event.
            PacketTransmissionEventArgs args = new PacketTransmissionEventArgs();

            args.Destination   = message.Ip;
            args.PacketContent = messageBytes;
            OnMessageTransmission(args);
        }