public ChatEndpoint(string s) { loadEndpointPair(ChatEndpoint.decodeEndpointAddress(s)); hexCode = s; lastSeen = DateTime.Now; online = true; }
//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)); } }
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)); }
// 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; } } } } }
public LVUserItem(ChatEndpoint ce) { relatedEndpoint = ce; base.Text = ce.ToString(); base.ForeColor = (relatedEndpoint.online ? System.Drawing.Color.Black : System.Drawing.Color.DarkGray); }