Esempio n. 1
0
// Event
        private void initializeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (cm != null)
            {
                cm.closeAll();
            }
            cm = new MulticonMgr(int.Parse(Properties.Settings.Default.RecvPort), int.Parse(Properties.Settings.Default.SendPort));
            selfEndpointTb.Text = cm.self.hexCode;
        }
Esempio n. 2
0
// Proc
        private void processReceivedSendcode(ChatMessage p)
        {
            ChatReceipt receipt = new ChatReceipt(cm.self.hexCode, p.owner, p.tickCode);

            if (!(cm.neighbours[p.ownerHex].nickname == p.owner))
            {
                cm.neighbours[p.ownerHex].nickname = p.owner;
                LVUserItem[] bucket = new LVUserItem[listView1.Items.Count];
                listView1.Items.CopyTo(bucket, 0);
                listView1.Items.Clear();
                listView1.Items.AddRange(bucket);
            }

            // adviseReceived

            if (Properties.Settings.Default.Secret != "")
            {
                string message = ("R:" + receipt);
                byte[] key     = Convert.FromBase64String(Properties.Settings.Default.Secret.Split(':')[0]);
                byte[] iv      = Convert.FromBase64String(Properties.Settings.Default.Secret.Split(':')[1]);
                byte[] msgB    = MulticonMgr.EncryptStringToBytes(message, key, iv);
                MulticonMgr.sendBytes(msgB, cm.neighbours[p.ownerHex].InPoint, cm.outClient);
            }
            else
            {
                MulticonMgr.sendString(
                    ("R:" + receipt),
                    cm.neighbours[p.ownerHex].InPoint, cm.outClient);
            }
            //identify duplicates and add and rotate.
            bool isDup = false;

            foreach (ChatMessage histMsg in ConvoStack)
            {
                if (histMsg.tickCode == p.tickCode)
                {
                    if (histMsg.owner == p.owner)
                    {
                        isDup = true;
                    }
                }
            }
            if (!isDup)
            {
                if (ConvoStack.Count > (Properties.Settings.Default.ChatHistory))
                {
                    ConvoStack.RemoveAt(0);
                }
                ConvoStack.Add(p);
            }
        }
Esempio n. 3
0
        public void tunnelPaths(byte[] key, byte[] iv)
        {
            string neighborString = "!:Net:";

            foreach (ChatEndpoint n in neighbours.Values)
            {
                neighborString += n.encodeEndpointAddress() + ";";
            }
            byte[] encPing = MulticonMgr.EncryptStringToBytes(neighborString, key, iv);
            foreach (ChatEndpoint n in neighbours.Values)
            {
                sendBytes(encPing, n.InPoint, outClient);
                sendBytes(encPing, n.OutPoint, inClient);
            }
        }
Esempio n. 4
0
        //whisper function
        private void sendChatMessage(ChatEndpoint target)
        {
            string whisper = Microsoft.VisualBasic.Interaction.InputBox("Please enter your message", "Whisper");

            if (whisper != null && whisper != "")
            {
                string msg = "" +
                             cm.self.hexCode + ":" +
                             WebUtility.UrlEncode(Properties.Settings.Default.Name) + ":" +
                             MulticonMgr.genTick() + ":" +
                             Properties.Settings.Default.Color + ":" +
                             WebUtility.UrlEncode(whisper) + ":Whisper;";
                target.MsgStack.Add(new ChatMessage(msg));
            }
        }
Esempio n. 5
0
// CONSTUCTOR

// SEND MESSAGE FUNCTION
        private void sendChatMessage()
        {
            string msg = "" +
                         cm.self.hexCode + ":" +
                         WebUtility.UrlEncode(Properties.Settings.Default.Name) + ":" +
                         MulticonMgr.genTick() + ":" +
                         Properties.Settings.Default.Color + ":" +
                         WebUtility.UrlEncode(chatMsgTb.Text + ";");

            foreach (ChatEndpoint n in cm.neighbours.Values)
            {
                n.MsgStack.Add(new ChatMessage(msg));
            }
            chatMsgTb.Text = "";
        }
Esempio n. 6
0
// END LISTENING LOOP



// PROCESS FUNCTIONS
        private void processReceivedSendcode(string p)
        {
            //split packed messages and handle
            string[] msgArray = p.Substring(2, p.Length - 2).Split(';');
            foreach (string msg in msgArray)
            {
                ChatMessage msgMsg = new ChatMessage(msg);
                cm.neighbours[msgMsg.ownerHex].nickname = msgMsg.owner;
                ChatReceipt receipt = new ChatReceipt(cm.self.hexCode, msgMsg.owner, msgMsg.tickCode);
                bool        isDup   = false;
                // adviseReceived

                if (Properties.Settings.Default.Secret != "")
                {
                    string message = ("R:" + receipt);
                    byte[] key     = Convert.FromBase64String(Properties.Settings.Default.Secret.Split(':')[0]);
                    byte[] iv      = Convert.FromBase64String(Properties.Settings.Default.Secret.Split(':')[1]);
                    byte[] msgB    = MulticonMgr.EncryptStringToBytes(message, key, iv);
                    MulticonMgr.sendBytes(msgB, cm.neighbours[msgMsg.ownerHex].InPoint, cm.outClient);
                }
                else
                {
                    MulticonMgr.sendString(
                        ("R:" + receipt),
                        cm.neighbours[msgMsg.ownerHex].InPoint, cm.outClient);
                }
                //identify duplicates and add and rotate.
                foreach (ChatMessage histMsg in ConvoStack)
                {
                    if (histMsg.tickCode == msgMsg.tickCode)
                    {
                        if (histMsg.owner == msgMsg.owner)
                        {
                            isDup = true;
                        }
                    }
                }
                if (!isDup)
                {
                    if (ConvoStack.Count > (Properties.Settings.Default.ChatHistory))
                    {
                        ConvoStack.RemoveAt(0);
                    }
                    ConvoStack.Add(msgMsg);
                }
            }
        }
Esempio n. 7
0
 public void keepAlive(byte[] key, byte[] iv)
 {
     byte[] encPing = MulticonMgr.EncryptStringToBytes("!:PingPong", key, iv);
     sendBytes(encPing, self.InPoint, outClient);
     sendBytes(encPing, self.OutPoint, inClient);
 }
Esempio n. 8
0
 private void secretGenBtn_Click(object sender, EventArgs e)
 {
     secretTb.Text = MulticonMgr.generateKey();
 }
Esempio n. 9
0
// Proc
        private void processSend()
        {
            //remove already-received messages, pack message, send;
            foreach (ChatEndpoint n in cm.neighbours.Values)
            {
                ArrayList RemoveBucket = new ArrayList();
                foreach (ChatMessage Sending in n.MsgStack)
                {
                    lock (this)
                    {
                        foreach (ChatReceipt Received in n.ReceivedStack)
                        {
                            if (Sending.owner == Received.Owner &&
                                Sending.tickCode == Received.Tick)
                            {
                                RemoveBucket.Add(Sending);
                            }
                        }
                    }
                }
                foreach (ChatMessage RemMsg in RemoveBucket)
                {
                    n.MsgStack.Remove(RemMsg);
                }
                if (n.MsgStack.Count > 0)
                {
                    string message = "S:";
                    foreach (ChatMessage Sending in n.MsgStack)
                    {
                        message += Sending.ToString();
                        //identify duplicates and add and rotate.
                        bool isDup = false;
                        foreach (ChatMessage histMsg in ConvoStack)
                        {
                            if (histMsg.tickCode == Sending.tickCode)
                            {
                                if (histMsg.owner == Sending.owner)
                                {
                                    isDup = true;
                                }
                            }
                        }
                        if (!isDup)
                        {
                            if (ConvoStack.Count > (Properties.Settings.Default.ChatHistory))
                            {
                                ConvoStack.RemoveAt(0);
                            }
                            ConvoStack.Add(Sending);
                        }
                    }
                    message = message.Substring(0, message.Length);
                    if (Properties.Settings.Default.Secret != "")
                    {
                        byte[] key  = Convert.FromBase64String(Properties.Settings.Default.Secret.Split(':')[0]);
                        byte[] iv   = Convert.FromBase64String(Properties.Settings.Default.Secret.Split(':')[1]);
                        byte[] msgB = MulticonMgr.EncryptStringToBytes(message, key, iv);
                        MulticonMgr.sendBytes(msgB, n.InPoint, cm.outClient);
                    }
                    else
                    {
                        MulticonMgr.sendString(message, n.InPoint, cm.outClient);
                    }
                }
            }
        }
Esempio n. 10
0
// END SEND MESSAGE



// LISTENING LOOP FUNCTION
        private void listenLoop()
        {
            while (listenSwitch)
            {
                string msg = "";
                if (Properties.Settings.Default.Secret != "")
                {
                    byte[] key = Convert.FromBase64String(Properties.Settings.Default.Secret.Split(':')[0]);
                    byte[] iv  = Convert.FromBase64String(Properties.Settings.Default.Secret.Split(':')[1]);
                    Packet p   = cm.receiveBytes(cm.inClient);
                    string ep  = ChatEndpoint.encodeEndpointAddress((new IPEndPoint(p.sender.Address, 0)), p.sender);
                    ep = ep.Substring(0, 8) + "...." + ep.Substring(12, 4);
                    foreach (string n in cm.neighbours.Keys)
                    {
                        if (System.Text.RegularExpressions.Regex.Match(n, ep).Success)
                        {
                            cm.neighbours[n].lastSeen = DateTime.Now;
                        }
                    }
                    msg = MulticonMgr.DecryptStringFromBytes(p.bytes, key, iv);
                }
                else
                {
                    Packet p = cm.receiveBytes(cm.inClient);
                    msg = Encoding.ASCII.GetString(p.bytes);
                    string ep = ChatEndpoint.encodeEndpointAddress((new IPEndPoint(p.sender.Address, 0)), p.sender);
                    ep = ep.Substring(0, 8) + "...." + ep.Substring(12, 4);
                    foreach (string n in cm.neighbours.Keys)
                    {
                        if (System.Text.RegularExpressions.Regex.Match(n, ep).Success)
                        {
                            cm.neighbours[n].lastSeen = DateTime.Now;
                        }
                    }
                }

                this.msgHistory = msg + "\r\n" + this.msgHistory;
                switch (msg.Substring(0, 2))
                {
                case "S:":
                {
                    lock (this)
                    {
                        foreach (string m in msg.Substring(2, msg.Length - 2).Split(';'))
                        {
                            if (m.Length > 0)
                            {
                                PacketStack.Add(new ChatMessage(m));
                            }
                        }
                        break;
                    }
                }

                case "R:":
                {
                    lock (this)
                    {
                        cm.neighbours[msg.Split(':')[1]].ReceivedStack.Add(new ChatReceipt(msg.Substring(2, msg.Length - 2)));
                        break;
                    }
                }

                case "!:":
                {
                    lock (this)
                    {
                        PacketStack.Insert(0, msg);
                        break;
                    }
                }
                }
            }
        }