Exemple #1
0
        private MSNContact getContact(String username)
        {
            if (contacts.ContainsKey(username))
            {
                return(contacts[username]);
            }
            else
            {
                MSNContact newContact = new MSNContact(controller, username);
                contacts.Add(username, newContact);

                controller.sendAddRemoveContactMessage(username, true);
                return(newContact);
            }
        }
Exemple #2
0
        private void processMessageLoop()
        {
            MSNMessage message = new MSNMessage("NULL");

            while (true)
            {
                if (processingQueue.Count > 0)
                {
                    try
                    {
                        #region get message from queue
                        message = processingQueue.Dequeue();

                        String   command = message.getCommand();
                        String[] data    = message.getTokens();
                        #endregion
                        #region handle SYN
                        if (command.Equals("SYN"))
                        {
                            //SYN 9 1 18 7
                            versionID = int.Parse(data[2]);
                        }
                        #endregion
                        #region handle GTC
                        else if (command.Equals("GTC"))
                        {
                            //GTC A
                            if (data[1].Equals("A"))     //manual
                            {
                                handleNewContact = MSNEnumerations.NewContact.manual_add;
                            }
                            else if (data[1].Equals("N"))     //auto
                            {
                                handleNewContact = MSNEnumerations.NewContact.auto_add;
                            }
                        }
                        #endregion
                        #region handle LSG
                        else if (command.Equals("LSG"))
                        {
                            //LSG 0 Individuals 0

                            if (!data[2].Equals("~"))
                            {
                                String   groupName = HttpUtility.UrlDecode(data[2]);
                                MSNGroup g         = new MSNGroup(controller, groupName, int.Parse(data[1]));

                                if (!groupsByName.ContainsKey(groupName))
                                {
                                    groupsByName.Add(groupName, g);
                                    groupsByNumber.Add(int.Parse(data[1]), g);
                                }
                            }
                        }
                        #endregion
                        #region handle LST
                        else if (command.Equals("LST"))
                        {
                            //LST [email protected] derek_bartram 11 3
                            //all contacts send 11!?!

                            String username = data[1];

                            #region get / make contact
                            MSNContact c = getContact(username);

                            lastContact = c;
                            #endregion

                            #region process friendly name
                            c.FriendlyName = HttpUtility.UrlDecode(data[2]);
                            #endregion

                            #region process groups
                            if (data.Length == 5)
                            {
                                char[] splitChars = new char[1];
                                splitChars[0] = ',';

                                String[] groupIDs = data[4].Split(splitChars);

                                for (int i = 0; i < groupIDs.Length; i++)
                                {
                                    int groupID = int.Parse(groupIDs[i]);
                                    if (groupsByNumber.ContainsKey(int.Parse(groupIDs[i])))
                                    {
                                        MSNGroup g = groupsByNumber[int.Parse(groupIDs[i])];
                                        c.Groups.Add(g);
                                        g.Contacts.Add(c);
                                    }
                                }
                            }
                            #endregion
                        }
                        #endregion
                        #region handle BPR
                        else if (command.Equals("BPR"))
                        {
                            //BPR 12182 [email protected] PHH 555%20555%204321
                            //BPR 12182 [email protected] PHW I%20AM%20DUMB\r\n
                            //BPR 12182 [email protected] PHM I%20Dont%20Have%20One\r\n
                            //BPR 12182 [email protected] MOB Y\r\n

                            //BPR MOB Y

                            MSNContact c           = lastContact;
                            String     phoneString = "";
                            if (data.Length == 3)
                            {
                                phoneString = HttpUtility.UrlDecode(data[2]);
                            }

                            c.setPhone(MSNStaticHelperFunctions.toPhoneTypes(data[1]), phoneString);
                        }
                        #endregion
                        #region handle ILN
                        else if (command.Equals("ILN"))
                        {
                            //ILN 10 NLN [email protected] 80%25%20Andy%20::%205.5%20ml%20Marky 1347272748 %3Cmsnobj%20Creator%3D%22webmaster%40norbosoft.zzn.com%22%20Size%3D%2216657%22%20Type%3D%223%22%20Location%3D%22TFR100.dat%22%20Friendly%3D%22UwBpAGQAAAA%3D%22%20SHA1D%3D%22LCJswyrzD1bDGR41HJ3xmfoBbqM%3D%22%20SHA1C%3D%22bYULHZIyQUxMB%2BFM1FNO%2BYAiP6M%3D%22%20contenttype%3D%22M%22%20contentid%3D%22U3097935%22%2F%3E

                            MSNContact c = getContact(data[3]);
                            c.Status = MSNStaticHelperFunctions.toUserStatus(data[2]);
                            if (data.Length >= 5)
                            {
                                c.FriendlyName = HttpUtility.UrlDecode(data[4]);
                            }
                        }
                        #endregion
                        #region handle NLN
                        else if (command.Equals("NLN"))
                        {
                            //NLN AWY [email protected] derek_bartram 1347272812 %3Cmsnobj%20Creator%3D%22derek_bartram%40hotmail.com%22%20Size%3D%2229106%22%20Type%3D%223%22%20Location%3D%22xpp539.dat%22%20Friendly%3D%22AAA%3D%22%20SHA1D%3D%22YeWGuRSbOGhJ1Wbk3JY5vCzoqT8%3D%22%20SHA1C%3D%22nj0278TZP%2FP4yIGc6qxIXrY2olQ%3D%22%2F%3E
                            MSNContact c = getContact(data[2]);
                            c.Status = MSNStaticHelperFunctions.toUserStatus(data[1]);
                            if (data.Length >= 4)
                            {
                                c.FriendlyName = HttpUtility.UrlDecode(data[3]);
                            }
                        }
                        #endregion

                        else if (command.Equals("FLN"))
                        {
                            MSNContact c = getContact(data[1]);
                            c.Status = MSNStaticHelperFunctions.toUserStatus("FLN");
                        }

                        #region unknown
                        else
                        {
                            throw new Exception("Unknown message type in MSNContactsList.processMessageLoop() <" + message.ToString() + ">");
                        }
                        #endregion
                    }
                    catch (Exception)
                    {
                        Console.Error.WriteLine("Error processing command in MSNContactsList.processMessageLoop()\r\n" + message.ToString());
                    }
                }
                else
                {
                    Thread.Sleep(20);
                }
            }
        }