Example #1
0
        private String getPassportTicket(String ticketString, String version)
        {
            MSNSocketWrapper sw = new MSNSocketWrapper("nexus.passport.com", 443, true);

            #region GET /rdr/pprdr.asp HTTP/1.0\r\n<FLUSH HERE>\r\n
            MSNMessage outMessage = new MSNMessage("GET /rdr/pprdr.asp HTTP/1.0\r\n\r\n");
            sw.send(outMessage);
            sw.send(new MSNMessage("\r\n"));
            sw.send(new MSNMessage("\r\n"));

            //outMessage = new Message("\r\n");
            //sw.send(outMessage);
            #endregion

            #region process responce
            MSNMessage inMessage = new MSNMessage("SPOONZ");
            while (!inMessage.ToString().Trim().Equals(""))
            {
                inMessage = sw.recieve();

                //<<< HTTP/1.1 200 OK\r\n
                //<<< Server: Microsoft-IIS/5.0\r\n
                //<<< Date: Mon, 02 Jun 2003 11:57:47 GMT\r\n
                //<<< Connection: close\r\n
                //<<< PassportURLs: DARealm=Passport.Net,DALogin=login.passport.com/login2.srf,DAReg=http://register.passport.net/uixpwiz.srf,Properties=https://register.passport.net/editprof.srf,Privacy=http://www.passport.com/consumer/privacypolicy.asp,GeneralRedir=http://nexusrdr.passport.com/redir.asp,Help=http://memberservices.passport.net/memberservice.srf,ConfigVersion=11\r\n
                //<<< Content-Length: 0\r\n
                //<<< Content-Type: text/html\r\n
                //<<< Cache-control: private\r\n
                //<<< \r\n

                if (inMessage.ToString().StartsWith("PassportURLs:"))
                {
                    char[] splitTokens = new char[3];
                    splitTokens[0] = ' ';
                    splitTokens[1] = ',';
                    splitTokens[2] = '=';

                    String[] messageDataTokens = inMessage.ToString().Split(splitTokens);
                    int      daLoginIndex      = 0;

                    while (!messageDataTokens[daLoginIndex].Equals("DALogin") && daLoginIndex < messageDataTokens.Length)
                    {
                        daLoginIndex++;
                    }

                    if (daLoginIndex >= messageDataTokens.Length - 1)
                    {
                        throw new Exception("No DALogin found in PassportURLs from passport nexus");
                    }

                    daLoginIndex++;

                    return(getPassportTicket(ticketString, version, messageDataTokens[daLoginIndex].ToString()));
                }
            }
            throw new Exception("No redirect given in getPassportTicket(" + ticketString + ")");
            #endregion
        }
Example #2
0
        internal MSNMessage recieve(int length)
        {
            try
            {
                String message = "";
                char[] buffer  = new char[length];
                message += reader.Read(buffer, 0, length);

                for (int i = 0; i < length; i++)
                {
                    message += buffer[i].ToString();
                }

                if (message == null)
                {
                    isConnected = false;
                    return(null);
                }

                MSNMessage inMessage = new MSNMessage(message);
                Console.WriteLine("<<< " + inMessage.ToString());
                return(inMessage);
            }
            catch (Exception)
            {
                Console.WriteLine("Error recieving message in MSNSocketWrapper.recieve()");
                isConnected = false;
                return(null);
            }
        }
Example #3
0
        internal void processMessage(MSNMessage message)
        {
            if (message.getCommand().Equals("CHG"))
            {
                currentStatus = MSNStaticHelperFunctions.toUserStatus(message.getData()[0]);

                controller.sendLocalClientStatusChangeMessage();
            }
            else if (message.getCommand().Equals("PRP"))
            {
                Console.WriteLine("MSNLocalClient.processMessage(" + message.ToString() + ") does not handle PRP YET!");
            }
            else if (message.getCommand().Equals("BLP"))
            {
                String[] data = message.getData();

                if (data[1].Equals("AL")) //allow unknown chat
                {
                    handleUnknownContact = MSNEnumerations.UnknownContact.allow_chat;
                }
                else if (data[1].Equals("BL")) //block unknown chat
                {
                    handleUnknownContact = MSNEnumerations.UnknownContact.disallow_chat;
                }
            }
            else if (message.getCommand().Equals("REA"))
            {
                String[] data = message.getData();
                if (data.Length >= 3)
                {
                    friendlyName = HttpUtility.UrlDecode(data[2]);
                    controller.sendLocalClientFriendlyNameChangeMessage();
                }
            }
            else if (message.getCommand().Equals("USR"))
            {
                String[] data = message.getData();
                if (data.Length >= 6)
                {
                    friendlyName = HttpUtility.UrlDecode(data[3]);
                    controller.sendLocalClientFriendlyNameChangeMessage();
                }
            }
        }
Example #4
0
        internal MSNMessage recieve()
        {
            try
            {
                String message = reader.ReadLine();

                if (message == null)
                {
                    isConnected = false;
                    return(null);
                }

                MSNMessage inMessage = new MSNMessage(message);
                Console.WriteLine("<<< " + inMessage.ToString());
                return(inMessage);
            }
            catch (Exception)
            {
                Console.WriteLine("Error recieving message in MSNSocketWrapper.recieve()");
                isConnected = false;
                return(null);
            }
        }
Example #5
0
        private void masterReadRedirectLoop()
        {
            MSNMessage inMessage       = new MSNMessage("NULL");
            String     inMessageString = "NULL";

            while (true)
            {
                if (masterSocketWrapper != null && masterSocketWrapper.connected() == true)
                {
                    try
                    {
                        inMessage = masterSocketWrapper.recieve();
                        if (inMessage == null)
                        {
                            if (LoginStatusChanged != null)
                            {
                                LoginStatusChanged(MSNEnumerations.LoginStatus.LOGGED_OUT);
                            }
                            continue;
                        }

                        inMessageString = inMessage.ToString();

                        if (inMessageString.StartsWith("CHG"))
                        {
                            localClient.processMessage(inMessage);
                        }
                        else if (inMessageString.StartsWith("CHL"))
                        {
                            authentication.handleChallenge(inMessage);
                        }
                        else if (inMessageString.StartsWith("QRY"))
                        {
                            //don't need to do anything... just confirming successful CHL QRY responce
                        }
                        else if (inMessageString.StartsWith("BLP"))
                        {
                            localClient.processMessage(inMessage);
                        }
                        else if (inMessageString.StartsWith("PRP"))
                        {
                            localClient.processMessage(inMessage);
                        }
                        else if (inMessageString.StartsWith("REA"))
                        {
                            localClient.processMessage(inMessage);
                        }
                        else if (inMessageString.StartsWith("USR"))
                        {
                            localClient.processMessage(inMessage);
                        }
                        else if (inMessageString.StartsWith("LSG"))
                        {
                            contactsList.processMessage(inMessage);
                        }
                        else if (inMessageString.StartsWith("LST"))
                        {
                            contactsList.processMessage(inMessage);
                        }
                        else if (inMessageString.StartsWith("SYN"))
                        {
                            contactsList.processMessage(inMessage);
                        }
                        else if (inMessageString.StartsWith("ILN"))
                        {
                            contactsList.processMessage(inMessage);
                        }
                        else if (inMessageString.StartsWith("NLN"))
                        {
                            contactsList.processMessage(inMessage);
                        }
                        else if (inMessageString.StartsWith("BPR"))
                        {
                            contactsList.processMessage(inMessage);
                        }
                        else if (inMessageString.StartsWith("XFR"))
                        {
                            switchboardController.processMessage(inMessage);
                        }
                        else if (inMessageString.StartsWith("RNG"))
                        {
                            switchboardController.processMessage(inMessage);
                        }
                        else if (inMessageString.StartsWith("FLN"))
                        {
                            contactsList.processMessage(inMessage);
                        }
                        else
                        {
                            Console.Error.WriteLine("Unknown Message (" + inMessageString + ")");
                        }
                    }
                    catch (Exception)
                    {
                        Console.Error.WriteLine("Error in MSNController.masterReadRedirectLoop()");
                    }

                    Thread.Sleep(5);
                }
                else
                {
                    Thread.Sleep(250);
                }
            }
        }
Example #6
0
        internal MSNSocketWrapper doAuthentication(String address, int port)
        {
            //messenger.hotmail.com:1863
            MSNSocketWrapper sw = new MSNSocketWrapper(address, port, false);

            if (sw.connected() != true)
            {
                throw new Exception("Not connecting to messenger.hotmail.com");
            }

            #region negotiate protocol version (VER)
            #region VER 1 MSNP8 CVR0\r\n
            MSNMessage outMessage = new MSNMessage("VER " + MSNTrIDGenerator.NextID() + " MSNP9 MSNP8 CVR0\r\n");
            sw.send(outMessage);
            #endregion

            #region <<< VER 1 MSNP8 CVR0\r\n
            MSNMessage inMessage = sw.recieve();

            if (inMessage.getCommand().Equals("VER") != true)
            {
                throw new Exception("VER Expected (" + inMessage.ToString() + ")");
            }

            if (inMessage.getTrID() != outMessage.getTrID())
            {
                throw new Exception("Incorrect TrID reponce in VER (" + inMessage.ToString() + ")");
            }

            String[] messageDataTokens = inMessage.getData();

            if (messageDataTokens.Length == 0)
            {
                throw new Exception("No data recieved in VER (" + inMessage.ToString() + ")");
            }

            if (messageDataTokens[0].ToString().Equals("0"))
            {
                throw new Exception("Protocol MSNP9 MSNP8 CVR0 not supported in VER (" + inMessage.ToString() + ")");
            }
            #endregion
            #endregion

            #region negotiate client version (CVR)
            #region CVR 2 0x0409 win 4.10 i386 MSNMSGR 5.0.0544 MSMSGS [email protected]\r\n
            outMessage = new MSNMessage("CVR " + MSNTrIDGenerator.NextID() + " 0x0409 win 4.10 i386 MSNMSGR 7.0.0816 MSMSGS " + username + "\r\n");
            sw.send(outMessage);
            #endregion

            #region CVR 2 7.0.0816 7.0.0816 1.0.0000 http://download.microsoft.com/download/8/a/4/8a42bcae-f533-4468-b871-d2bc8dd32e9e/SETUP9x.EXE http://messenger.msn.com\r\n
            inMessage = sw.recieve();

            if (inMessage.getCommand().Equals("CVR") != true)
            {
                throw new Exception("CVR Expected (" + inMessage.ToString() + ")");
            }

            if (inMessage.getTrID() != outMessage.getTrID())
            {
                throw new Exception("Incorrect TrID reponce in CVR (" + inMessage.ToString() + ")");
            }

            messageDataTokens = inMessage.getData();

            if (messageDataTokens.Length == 0)
            {
                throw new Exception("No data recieved in CVR (" + inMessage.ToString() + ")");
            }
            #endregion
            #endregion

            #region get session tpf -> passport session ticket (USR)
            #region USR 3 TWN I [email protected]\r\n
            outMessage = new MSNMessage("USR " + MSNTrIDGenerator.NextID() + " TWN I " + username + "\r\n");
            sw.send(outMessage);
            #endregion

            #region get responce
            inMessage = sw.recieve();

            if (!(inMessage.getCommand().Equals("XFR") == true || inMessage.getCommand().Equals("USR") == true))
            {
                throw new Exception("USR/XFR Expected (" + inMessage.ToString() + ")");
            }

            //HANDLE INITIAL USR
            if (inMessage.getCommand().Equals("USR"))
            {
                String[] data = inMessage.getData();
                if (data.Length >= 6)
                {
                    initialFriendlyName = HttpUtility.UrlDecode(data[4]);
                }
            }

            if (inMessage.getTrID() != outMessage.getTrID())
            {
                throw new Exception("Incorrect TrID reponce in CVR (" + inMessage.ToString() + ")");
            }
            #endregion

            #region XFR 3 NS 207.46.106.118:1863 0 207.46.104.20:1863\r\n
            if (inMessage.getCommand().Equals("XFR"))
            {
                messageDataTokens = inMessage.getData();

                if (messageDataTokens.Length != 4)
                {
                    throw new Exception("Incorrect data length in XFR (" + inMessage.ToString() + ")");
                }

                try
                {
                    char[] splitTokens = new char[1];
                    splitTokens[0] = ':';
                    String[] addressDataTokens = messageDataTokens[1].Split(splitTokens);
                    String   newAddress        = addressDataTokens[0];
                    int      newPort           = int.Parse(addressDataTokens[1]);

                    return(doAuthentication(newAddress, newPort));
                }
                catch (FormatException)
                {
                    throw new Exception("Format error in XFR (" + inMessage.ToString() + ")");
                }
            }
            #endregion

            String sessionTicket = "";

            //First USR
            #region USR 3 TWN S lc=1033,id=507,tw=40,fs=1,ru=http%3A%2F%2Fmessenger%2Emsn%2Ecom,ct=1062764229,kpp=1,kv=5,ver=2.1.0173.1,tpf=43f8a4c8ed940c04e3740be46c4d1619\r\n
            if (inMessage.getCommand().Equals("USR"))
            {
                String messageStr = inMessage.ToString();
                messageStr = messageStr.Replace("\r\n", "");

                char[] splitTokens = new char[1];
                splitTokens[0] = '=';

                messageDataTokens = messageStr.Split(splitTokens);
                String tpf = messageDataTokens[messageDataTokens.Length - 1].ToString();
                String ver = messageDataTokens[messageDataTokens.Length - 3].ToString().Replace(",rn", "");
                sessionTicket = getPassportTicket(tpf, ver);
            }
            #endregion
            #endregion

            #region final authentication (USR)
            #region USR 4 TWN S t=53*1hAu8ADuD3TEwdXoOMi08sD*2!cMrntTwVMTjoB3p6stWTqzbkKZPVQzA5NOt19SLI60PY!b8K4YhC!Ooo5ug$$&p=5eKBBC!yBH6ex5mftp!a9DrSb0B3hU8aqAWpaPn07iCGBw5akemiWSd7t2ot!okPvIR!Wqk!MKvi1IMpxfhkao9wpxlMWYAZ!DqRfACmyQGG112Bp9xrk04!BVBUa9*H9mJLoWw39m63YQRE1yHnYNv08nyz43D3OnMcaCoeSaEHVM7LpR*LWDme29qq2X3j8N\r\n
            outMessage = new MSNMessage("USR " + MSNTrIDGenerator.NextID() + " TWN S " + sessionTicket + "\r\n");
            sw.send(outMessage);
            #endregion

            #region USR 4 OK [email protected] example%20display%20name 1 0\r\n
            inMessage = sw.recieve();

            if (inMessage.getCommand().Equals("USR"))
            {
                String[] data = inMessage.getData();
                if (data.Length >= 3)
                {
                    initialFriendlyName = HttpUtility.UrlDecode(data[2]);
                }
            }

            if (!inMessage.getCommand().Equals("USR"))
            {
                throw new Exception("Unexpected command responce for USR in doAuthentication(" + address + ", " + port + ")");
            }

            if (inMessage.getTrID() != outMessage.getTrID())
            {
                throw new Exception("Unexpected TrID responce for USR in doAuthentication(" + address + ", " + port + ")");
            }

            messageDataTokens = inMessage.getData();

            if (messageDataTokens.Length != 5)
            {
                throw new Exception("Unexpected length data responce for USR in doAuthentication(" + address + ", " + port + ")");
            }

            if (!messageDataTokens[0].Equals("OK"))
            {
                throw new Exception("Unknown failure to authentication for USR in doAuthentication(" + address + ", " + port + ")");
            }

            if (!messageDataTokens[1].Equals(username))
            {
                throw new Exception("Authenticated as incorrect user for USR in doAuthentication(" + address + ", " + port + ")");
            }

            //#############################################################################################################################
            // AUTHENTICATION PASSED // AUTHENTICATION PASSED // AUTHENTICATION PASSED // AUTHENTICATION PASSED // AUTHENTICATION PASSED //
            //#############################################################################################################################
            return(sw);

            #endregion
            #endregion
        }
Example #7
0
        private String getPassportTicket(String ticketString, String version, String address)
        {
            char[] splitTokens = new char[2];
            splitTokens[0] = '\\';
            splitTokens[1] = '/';

            #region process address
            String[] addressTokens = address.Split(splitTokens);
            String   pageAddress   = "";

            for (int i = 1; i < addressTokens.Length; i++)
            {
                pageAddress += "/" + addressTokens[i];
            }
            #endregion

            MSNSocketWrapper sw = new MSNSocketWrapper(addressTokens[0], 443, true);

            #region GET /login2.srf HTTP/1.1\r\n
            //      Authorization: Passport1.4 OrgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom,sign-in=example%40passport.com,pwd=password,lc=1033,id=507,tw=40,fs=1,ru=http%3A%2F%2Fmessenger%2Emsn%2Ecom,ct=1062764229,kpp=1,kv=5,ver=2.1.0173.1,tpf=43f8a4c8ed940c04e3740be46c4d1619\r\n
            //      Host: login.passport.com\r\n\r\n
            MSNMessage outMessage = new MSNMessage("GET " + pageAddress + " HTTP/1.1\r\n");
            sw.send(outMessage);

            //outMessage = new Message("Authorization: Passport1.4 OrgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom,sign-in=" + HttpUtility.UrlEncode(username) + ",pwd=" + password + ",lc=1033,id=507,tw=40,fs=1,ru=http%3A%2F%2Fmessenger%2Emsn%2Ecom,ct=1062764229,kpp=1,kv=5,ver=2.1.0173.1,tpf=" + ticketString + "\r\n");
            //outMessage = new Message("Authorization: Passport1.4 OrgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom,sign-in=" + HttpUtility.UrlEncode(username) + ",pwd=" + HttpUtility.UrlEncode(password) + ",lc=1033,id=507,tw=40,fs=1,ru=http%3A%2F%2Fmessenger%2Emsn%2Ecom,ct=1062764229,kpp=1,kv=5,ver=" + version + ",tpf=" + ticketString + "\r\n");
            outMessage = new MSNMessage("Authorization: Passport1.4 OrgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom,sign-in=" + HttpUtility.UrlEncode(username) + ",pwd=" + HttpUtility.UrlEncode(password) + ",lc=1033,id=507,tw=40,fs=1,ver=" + version + ",tpf=" + ticketString + "\r\n");
            sw.send(outMessage);

            outMessage = new MSNMessage("Host: login.passport.com\r\n\r\n");
            sw.send(outMessage);
            #endregion

            #region process responce
            MSNMessage inMessage = sw.recieve();

            if (inMessage.ToString().Equals("HTTP/1.1 302 Found\r\n") == false && inMessage.ToString().Equals("HTTP/1.1 200 OK\r\n") == false)
            {
                //throw new Exception("Incorrect username / password in getPassportTicket(" + ticketString + ", " + address + ")");
            }

            while (inMessage.ToString().Equals("\r\n") != true)
            {
                inMessage = sw.recieve();

                #region successful authentication
                if (inMessage.ToString().StartsWith("Authentication-Info:") && inMessage.ToString().Contains("da-status=success"))
                {
                    //Authentication-Info: Passport1.4 da-status=success,tname=MSPAuth,tname=MSPProf,tname=MSPSec,from-PP='t=53*1hAu8ADuD3TEwdXoOMi08sD*2!cMrntTwVMTjoB3p6stWTqzbkKZPVQzA5NOt19SLI60PY!b8K4YhC!Ooo5ug$$&p=5eKBBC!yBH6ex5mftp!a9DrSb0B3hU8aqAWpaPn07iCGBw5akemiWSd7t2ot!okPvIR!Wqk!MKvi1IMpxfhkao9wpxlMWYAZ!DqRfACmyQGG112Bp9xrk04!BVBUa9*H9mJLoWw39m63YQRE1yHnYNv08nyz43D3OnMcaCoeSaEHVM7LpR*LWDme29qq2X3j8N',ru=http://messenger.msn.com\r\n

                    splitTokens    = new char[1];
                    splitTokens[0] = '\'';

                    String[] messageDataTokens = inMessage.ToString().Split(splitTokens);

                    for (int i = 0; i < messageDataTokens.Length; i++)
                    {
                        if (messageDataTokens[i].StartsWith("t="))
                        {
                            return(messageDataTokens[i]);
                        }
                    }

                    throw new Exception("Unknown authentication ticket in getPassportTicket(" + ticketString + ", " + address + ")");
                }
                #endregion

                #region redirection
                if (inMessage.ToString().StartsWith("Location:"))
                {
                    //Location: https://loginnet.passport.com/login2.srf?lc=1033\r\n
                    return(getPassportTicket(ticketString, version, inMessage.ToString().Replace("Location: ", "").Replace("\r\n", "")));
                }
                #endregion
            }
            #endregion

            throw new Exception("No ticket retrieved from getPassportTicket(" + ticketString + ", " + address);
        }
        private void processIncommingXFR()
        {
            while (incommingXFRQueue.Count > 0)
            {
                MSNMessage message = incommingXFRQueue.Dequeue();

                try
                {
                    #region process command
                    //XFR 12 SB 207.46.26.161:1863 CKI 1790215149.6727142.1184104\r\n
                    String        address      = message.getData()[1].Replace(":1863", "");
                    int           port         = 1863;
                    String        authCode     = message.getData()[3].ToString();
                    String        trID         = message.getTrID().ToString();
                    List <String> initialUsers = newConversationContacts[trID.ToString()];
                    #endregion

                    #region try to find existing switchboard to connect to
                    MSNSwitchboard existingAddTo = null;
                    for (int i = 0; i < activeSwitchboards.Count; i++)
                    {
                        MSNSwitchboard testSwitchboard  = (MSNSwitchboard)activeSwitchboards[i];
                        List <String>  switchboardUsers = testSwitchboard.getConnectedUsers();

                        #region test initial users = switchboardUsers
                        int checkCounter = 0;
                        for (int x = 0; x < initialUsers.Count; x++)
                        {
                            for (int y = 0; y < switchboardUsers.Count; y++)
                            {
                                if (initialUsers[x].Equals(switchboardUsers[y].ToString()))
                                {
                                    checkCounter++;
                                }
                            }
                        }

                        bool usersEqual = false;
                        if (initialUsers.Count == switchboardUsers.Count && checkCounter == initialUsers.Count)
                        {
                            usersEqual = true;
                        }
                        #endregion

                        if (usersEqual)
                        {
                            existingAddTo = testSwitchboard;
                            existingAddTo.reconnect(address, port, authCode, initialUsers);

                            if (SwitchboardReCreated != null)
                            {
                                SwitchboardReCreated(existingAddTo);
                            }
                        }
                    }
                    #endregion

                    #region build switchboard (and load plugins) if no existing switchboard
                    if (existingAddTo == null)
                    {
                        MSNSwitchboard s = new MSNSwitchboard(controller, address, port, authCode, initialUsers);

                        activeSwitchboards.Add(s);

                        if (SwitchboardCreated != null)
                        {
                            SwitchboardCreated(s);
                        }
                    }
                    #endregion
                }
                catch (Exception)
                {
                    Console.WriteLine("Error processing XFR message in MSNSwitchboardController.processXFR(), message = " + message.ToString());
                }
            }
        }
        private void processMessageLoop()
        {
            while (true)
            {
                if (incommingMessageQueue.Count > 0)
                {
                    MSNMessage message = incommingMessageQueue.Dequeue();

                    try
                    {
                        String command = message.getCommand();

                        #region process XFR
                        if (command.StartsWith("XFR"))
                        {
                            incommingXFRQueue.Enqueue(message);

                            Thread t = new Thread(new ThreadStart(processIncommingXFR));
                            t.Start();
                            //Invoke(new RefreshDelegate(processIncommingXFR));
                        }
                        #endregion
                        #region process RNG
                        else if (command.StartsWith("RNG"))
                        {
                            incommingRNGQueue.Enqueue(message);

                            Thread t = new Thread(new ThreadStart(processIncommingRNG));
                            t.Start();
                            //Invoke(new RefreshDelegate(processIncommingRNG));
                        }
                        #endregion
                    }
                    catch (Exception)
                    {
                        if (message != null)
                        {
                            Console.WriteLine("ERROR processing message in MSNSwitchboardController.processMessageLoop(), message = " + message.ToString());
                        }
                        else
                        {
                            Console.WriteLine("ERROR processing message in MSNSwitchboardController.processMessageLoop(), message = null");
                        }
                    }
                }
                else
                {
                    try
                    {
                        Thread.Sleep(50);
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }
        private void processIncommingRNG()
        {
            while (incommingRNGQueue.Count > 0)
            {
                MSNMessage message = incommingRNGQueue.Dequeue();

                try
                {
                    #region process command
                    //RNG 11752013 207.46.108.38:1863 CKI 849102291.520491113 [email protected] Example%20Name\r\n
                    String   address      = message.getData()[0].Replace(":1863", "");
                    int      port         = 1863;
                    String   authCode     = message.getData()[2];
                    String   rngTrID      = message.getTrID().ToString();
                    String[] initialUsers = new String[] { message.getData()[3] };
                    #endregion

                    #region try to find existing switchboard to connect to
                    MSNSwitchboard existingAddTo = null;
                    for (int i = 0; i < activeSwitchboards.Count; i++)
                    {
                        MSNSwitchboard testSwitchboard  = (MSNSwitchboard)activeSwitchboards[i];
                        List <String>  switchboardUsers = testSwitchboard.getConnectedUsers();

                        #region test initial users = switchboardUsers
                        int checkCounter = 0;
                        for (int x = 0; x < initialUsers.Length; x++)
                        {
                            for (int y = 0; y < switchboardUsers.Count; y++)
                            {
                                if (initialUsers[x].Equals(switchboardUsers[y].ToString()))
                                {
                                    checkCounter++;
                                }
                            }
                        }

                        bool usersEqual = false;
                        if (initialUsers.Length == switchboardUsers.Count && checkCounter == initialUsers.Length)
                        {
                            usersEqual = true;
                        }
                        #endregion

                        if (usersEqual)
                        {
                            existingAddTo = testSwitchboard;
                            existingAddTo.reconnect(address, port, authCode, rngTrID);

                            if (SwitchboardReCreated != null)
                            {
                                SwitchboardReCreated(existingAddTo);
                            }
                        }
                    }
                    #endregion

                    #region build switchboard (and load plugins) if no existing switchboard found
                    if (existingAddTo == null)
                    {
                        MSNSwitchboard s = new MSNSwitchboard(controller, address, port, authCode, rngTrID);

                        activeSwitchboards.Add(s);

                        if (SwitchboardCreated != null)
                        {
                            SwitchboardCreated(s);
                        }
                    }
                    #endregion
                }
                catch (Exception)
                {
                    Console.WriteLine("Error processing RNG message in MSNSwitchboardController.processRNG(), message = " + message.ToString());
                }
            }
        }
Example #11
0
        private void processIncommingMessageLoop()
        {
            while (true)
            {
                MSNMessage message = null;

                try
                {
                    #region wait for connected socket
                    while (switchboardSocket.connected() != true)
                    {
                        try
                        {
                            Thread.Sleep(100);
                        }
                        catch (Exception)
                        {
                        }
                    }
                    #endregion

                    message = switchboardSocket.recieve();

                    #region ignore null messages
                    if (message == null)
                    {
                        continue;
                    }
                    #endregion

                    String messageString = message.ToString();

                    #region handle JOI
                    if (messageString.StartsWith("JOI"))
                    {
                        //JOI [email protected] Dave\r\n
                        String username = message.getTokens()[1].ToString();
                        if (connectedUsers.Contains(username) != true)
                        {
                            connectedUsers.Add(username);
                        }

                        if (activeUsers.Contains(username) != true)
                        {
                            activeUsers.Add(username);
                        }

                        sendSwitchboardListenerUserConnectedDisconnected(username, true);
                    }
                    #endregion
                    #region handle CAL
                    else if (messageString.StartsWith("CAL"))
                    {
                        //CAL 8 RINGING 17342299\r\n
                    }
                    #endregion
                    #region handle IRO
                    else if (messageString.StartsWith("IRO"))
                    {
                        //IRO 1 1 2 [email protected] Mike\r\n
                        String username = message.getTokens()[4].ToString();
                        if (connectedUsers.Contains(username) != true)
                        {
                            connectedUsers.Add(username);
                        }

                        if (activeUsers.Contains(username) != true)
                        {
                            activeUsers.Add(username);
                        }

                        sendSwitchboardListenerUserConnectedDisconnected(username, true);
                    }
                    #endregion
                    #region handle MSG
                    else if (messageString.StartsWith("MSG"))
                    {
                        //MSG [email protected] Mike 133\r\n
                        //MIME-Version: 1.0\r\n
                        //Content-Type: text/plain; charset=UTF-8\r\n
                        //X-MMS-IM-Format: FN=Arial; EF=I; CO=0; CS=0; PF=22\r\n
                        //\r\n
                        //Hello! How are you?

                        try
                        {
                            String   wholeString       = messageString + "\r\n" + switchboardSocket.recieve(int.Parse(message.getData()[1]));
                            String[] wholeStringTokens = wholeString.Split(new String[] { "\r\n" }, StringSplitOptions.None);

                            if (wholeStringTokens.Length >= 4 && wholeStringTokens[3].StartsWith("TypingUser:"******"Content-Type: text/x-mms-emoticon"))
                            {
                                String payload = "";
                                for (int i = 4; i < wholeStringTokens.Length; i++)
                                {
                                    payload += wholeStringTokens[i] + "\r\n";
                                }

                                MSNUserMessage num = new MSNUserIncommingEmoticon(wholeStringTokens[0].Split(new char[] { ' ' })[1], payload);
                                incommingMSGQueue.Enqueue(num);
                            }
                            else
                            {
                                #region process payload
                                String payload = "";
                                for (int i = 5; i < wholeStringTokens.Length; i++)
                                {
                                    payload += wholeStringTokens[i] + "\r\n";
                                }
                                if (payload.EndsWith("\r\n"))
                                {
                                    payload = payload.Substring(0, payload.Length - 2);
                                }
                                #endregion

                                if (wholeStringTokens[3].Equals(""))
                                {
                                    wholeStringTokens[3] = "X-MMS-IM-Format: FN=Arial; EF=I; CO=0; CS=0; PF=22";
                                }
                                MSNUserMessage num = new MSNUserIncommingMessage((wholeStringTokens[0].Split(new char[] { ' ' }))[1], (wholeStringTokens[3].Split(new char[] { ' ' }))[1].Replace("FN=", "").Replace(";", ""), payload);
                                incommingMSGQueue.Enqueue(num);
                            }
                        }
                        catch (Exception)
                        {
                            Console.WriteLine("Error processing message in MSNSwitchboard.processIncommingMessage(), message = " + messageString);
                        }
                    }
                    #endregion
                    #region handle BYE
                    else if (messageString.StartsWith("BYE"))
                    {
                        //BYE [email protected]\r\n
                        String username = messageString.Replace("\r\n", "").Split(new char[] { ' ' })[1];
                        activeUsers.Remove(username);
                        //connectedUsers.Remove(username);
                        sendSwitchboardListenerUserConnectedDisconnected(username, false);
                    }
                    #endregion
                }
                catch (Exception)
                {
                    if (message != null)
                    {
                        Console.WriteLine("Error processing incomming message in MSNSwitchboard.processIncommingMessageLoop(), message = " + message.ToString());
                    }
                    else
                    {
                        Console.WriteLine("Error processing incomming message in MSNSwitchboard.processIncommingMessageLoop(), message = NULL");
                    }

                    if (switchboardSocket.connected() != true)
                    {
                        while (switchboardSocket != null && switchboardSocket.connected() != true)
                        {
                            try
                            {
                                Thread.Sleep(300);
                            }
                            catch (Exception)
                            {
                                Console.WriteLine("Error waiting for switchboard to be reconnected in MSNSwitchboard.processIncommingMessageLoop()");
                            }
                        }
                    }
                }
            }
        }
Example #12
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);
                }
            }
        }
Example #13
0
 internal void send(MSNMessage message)
 {
     Console.WriteLine(">>> " + message.ToString());
     writer.Write(message.ToString());
 }