예제 #1
0
        public static void MessageTransmissionHandler(Message message)
        {
            string sharedSecret;

            if (message.Type == ChatTwo_Protocol.MessageType.CreateUserReply)
            {
                sharedSecret = ChatTwo_Protocol.DefaultSharedSecret;
            }
            else if (message.Type == ChatTwo_Protocol.MessageType.LoginReply && message.To == 0)
            {
                // Not sure I like the idea of having "_tempUser", but it works for now I guess?
                // It could cause problems if multiple login attempts are made from the same client in rapid succession.
                sharedSecret = _tempUsers[message.Ip];
                _tempUsers.Remove(message.Ip);
            }
            else
            {
                sharedSecret = _users.Find(x => x.ID == message.To).Secret;
            }

            byte[] messageBytes = ChatTwo_Protocol.MessageTransmissionHandler(message);

            messageBytes = ChatTwo_Protocol.AddSignatureAndMac(messageBytes, sharedSecret);

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

            args.Destination   = message.Ip;
            args.PacketContent = messageBytes;
            OnMessageTransmission(args);
        }
예제 #2
0
        private static void OnMessageTransmission(PacketTransmissionEventArgs e)
        {
            EventHandler <PacketTransmissionEventArgs> handler = MessageTransmission;

            if (handler != null)
            {
                handler(null, e);
            }
        }
예제 #3
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);
        }