Ejemplo n.º 1
0
 public ChatEndpoint(string s)
 {
     loadEndpointPair(ChatEndpoint.decodeEndpointAddress(s));
     hexCode  = s;
     lastSeen = DateTime.Now;
     online   = true;
 }
Ejemplo n.º 2
0
 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) + ":" +
             ((int)(DateTime.Now.Ticks / 100)).ToString("X8") + ":" +
             Properties.Settings.Default.Color + ":" +
             WebUtility.UrlEncode(whisper) + ":Whisper;";
         target.MsgStack.Add(new ChatMessage(msg));
     }
 }
Ejemplo n.º 3
0
 public MulticonMgr(int inP, int outP)
 {
     inClient  = new UdpClient(new IPEndPoint(IPAddress.Any, inP));
     outClient = new UdpClient(new IPEndPoint(IPAddress.Any, outP));
     self      = new ChatEndpoint(getEndpoint(inClient), getEndpoint(outClient));
 }
Ejemplo n.º 4
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);
                }

                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;
                            }
                        }

                }

            }
        }