예제 #1
0
    public void StartByInvitation(Friend friend, OperationCompleteEvent opCompleteEvent, object tag)
    {
        object[] objs      = (object[])tag;
        string   sbIP      = (string)objs[0];
        int      sbPort    = (int)objs[1];
        string   hash      = (string)objs[2];
        string   sessionID = (string)objs[3];

        try
        {
            Proxy.IConnection conn = this.control.CreateConnection();
            conn.Connect("", 0, sbIP, sbPort, Proxy.ConnectionType.Tcp);
            sbRouter = new MessageRouter(this.protocol, conn, null, null);

            RegisterCodeEvents();

            sbRouter.SendMessage(Message.ConstructMessage("ANS",
                                                          this.settings.Username + " " + hash + " " + sessionID),
                                 new ResponseReceivedHandler(OnAnswerResponse), opCompleteEvent);
        }
        catch
        {
            opCompleteEvent.Execute(new OperationCompleteArgs("Could not connect", true));
        }
    }
예제 #2
0
 public void Connect(OperationCompleteEvent opCompleteEvent)
 {
     try
     {
         Proxy.IConnection con = this.control.CreateConnection();
         con.Connect("", 0, settings.ServerHost, settings.ServerPort, Proxy.ConnectionType.Tcp);
         dispatchRouter = new MessageRouter(this, con, null, null);
         DoAuthentication(dispatchRouter, opCompleteEvent);
     }
     catch
     {
         opCompleteEvent.Execute(new ConnectionCompleteArgs(ConnectionFailedReport.ConnectionFailed));
     }
 }
예제 #3
0
    public void Connect(OperationCompleteEvent opCompleteEvent)
    {
        this.username = settings.Username;

        // connect to the server first
        try
        {
            Proxy.IConnection conn = this.control.CreateConnection();
            conn.Connect("", 0, settings.ServerHost, settings.ServerPort, Proxy.ConnectionType.Tcp);
            messageRouter = new MessageRouter(this, conn, new ResponseReceivedHandler(OnDefaultMessage), new ResponseReceivedHandler(OnDisconnect));
        }
        catch
        {
            opCompleteEvent.Execute(new ConnectionCompleteArgs(ConnectionFailedReport.ConnectionFailed));
            return;
        }

        // register service events
        messageRouter.AddOneTimeEvent(YahooService.Verify, new ResponseReceivedHandler(OnInitialVerify), opCompleteEvent);
        messageRouter.AddOneTimeEvent(YahooService.Auth, new ResponseReceivedHandler(OnAuthResponse), opCompleteEvent);
        messageRouter.AddOneTimeEvent(YahooService.AuthResponse, new ResponseReceivedHandler(OnAuthResponseResponse), opCompleteEvent);
        messageRouter.AddOneTimeEvent(YahooService.List, new ResponseReceivedHandler(OnList), opCompleteEvent);

        messageRouter.AddPermanentEvent(YahooService.Verify, new ResponseReceivedHandler(OnVerify));
        messageRouter.AddPermanentEvent(YahooService.NewContact, new ResponseReceivedHandler(OnNewContact));

        // status messages
        messageRouter.AddOneTimeEvent(YahooService.UserOnline, new ResponseReceivedHandler(OnInitialUserOnline), opCompleteEvent);
        messageRouter.AddPermanentEvent(YahooService.UserOnline, new ResponseReceivedHandler(OnUserOnline));
        messageRouter.AddPermanentEvent(YahooService.UserOffline, new ResponseReceivedHandler(OnUserOffline));

        messageRouter.AddPermanentEvent(YahooService.UserIsAway, new ResponseReceivedHandler(OnUserIsAway));
        messageRouter.AddPermanentEvent(YahooService.UserIsBack, new ResponseReceivedHandler(OnUserIsBack));

        // conversation messages
        messageRouter.AddPermanentEvent(YahooService.Message, new ResponseReceivedHandler(OnMessage));
        messageRouter.AddPermanentEvent(YahooService.Notify, new ResponseReceivedHandler(OnNotifyMessage));

        // send verify message
        Message verifyMessage = new Message(0, YahooService.Verify);

        messageRouter.SendMessage(verifyMessage);
    }
예제 #4
0
    private void OnSwitchBoardRequestResponse(MessageRouter router, Message message, object tag)
    {
        object[] o = (object[])tag;

        Friend friend             = (Friend)o[0];
        OperationCompleteEvent op = (OperationCompleteEvent)o[1];

        Regex.Regex regex = new Regex.Regex(@"SB (?<sbServerIP>\d+\.\d+\.\d+\.\d+):(?<sbServerPort>\d+) CKI (?<hash>.*$)");
        Regex.Match match = regex.Match(message.Arguments);

        if (match.Success)
        {
            string sbIP           = match.Groups["sbServerIP"].Value;
            int    sbPort         = int.Parse(match.Groups["sbServerPort"].Value);
            string conversationID = match.Groups["hash"].Value;

            // connect
            try
            {
                Proxy.IConnection conn = this.control.CreateConnection();
                conn.Connect("", 0, sbIP, sbPort, Proxy.ConnectionType.Tcp);
                sbRouter = new MessageRouter(this.protocol, conn, null, new ResponseReceivedHandler(OnForcedDisconnect));
            }
            catch
            {
                op.Execute(new OperationCompleteArgs("Could not connect", true));
                return;
            }

            RegisterCodeEvents();

            sbRouter.SendMessage(Message.ConstructMessage("USR", this.settings.Username + " " + conversationID),
                                 new ResponseReceivedHandler(OnSwitchBoardUsrResponse), tag);
        }
        else
        {
            op.Execute(new OperationCompleteArgs("Could not connect", true));
        }

        router.RemoveMessageEvent(message);
    }
예제 #5
0
    private void OnUsrResponse(MessageRouter router, Message message, object tag)
    {
        router.RemoveMessageEvent(message);
        OperationCompleteEvent op = (OperationCompleteEvent)tag;

        // see if its an XFR or a USR code.
        switch (message.Code)
        {
        case "XFR":                 // we need to connect to a notification server
        {
            // get ip and port of notification server from response string
            Regex.Regex regex = new Regex.Regex(
                @"NS (?<notifyServerIP>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):(?<notifyServerPort>\d{1,5})" +
                @"\s+\d+\s+" +
                @"(?<currentNotifyIP>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):(?<currentNotifyPort>\d{1,5})");
            Regex.Match match = regex.Match(message.Arguments);

            if (!match.Success)
            {
                op.Execute(new ConnectionCompleteArgs(ConnectionFailedReport.InvalidProtocol));
            }
            else
            {
                string notifyIP   = match.Groups["notifyServerIP"].Value;
                int    notifyPort = int.Parse(match.Groups["notifyServerPort"].Value);

                // connect to notification server
                if (this.notifyRouter != null)
                {
                    this.notifyRouter.Close();
                }

                try
                {
                    Proxy.IConnection con = control.CreateConnection();
                    con.Connect("", 0, notifyIP, notifyPort, Proxy.ConnectionType.Tcp);
                    this.notifyRouter = new MessageRouter(this, con,
                                                          new ResponseReceivedHandler(OnDefaultNotifyMessage),
                                                          new ResponseReceivedHandler(OnForcedDisconnect));
                }
                catch
                {
                    op.Execute(new ConnectionCompleteArgs(ConnectionFailedReport.ConnectionFailed));
                    return;
                }

                RegisterEvents();

                // go through authentication again, this time with the new notification server
                DoAuthentication(this.notifyRouter, (OperationCompleteEvent)tag);
            }
        }
        break;

        case "USR":                 // we need to do encrypt and send password
        {
            string challenge = message.Arguments.Substring(6);

            // we need to authenticate with passport server
            string url = this.settings.PassportURL;
            string ticket;

            if (url != string.Empty || url != null || url != "")
            {
                try
                {
                    ticket = Passport.Login(url, challenge, settings.Username, settings.Password);
                }
                catch
                {
                    // passport url is out of date
                    url    = Passport.GetLoginAddress(this.nexusUri);
                    ticket = Passport.Login(url, challenge, settings.Username, settings.Password);
                }
            }
            else
            {
                url    = Passport.GetLoginAddress(this.nexusUri);
                ticket = Passport.Login(url, challenge, settings.Username, settings.Password);
            }

            if (ticket == null || ticket == string.Empty || ticket == "")
            {
                // wrong username / password
                op.Execute(new ConnectionCompleteArgs(ConnectionFailedReport.AuthFailed));
                return;
            }

            // send ticket command
            router.SendMessage(Message.ConstructMessage("USR", "TWN S " + ticket), new ResponseReceivedHandler(OnPasswordSentResponse), tag);
        }
        break;
        }
    }