예제 #1
0
        public static void ProccessAuthSet(string username, string SID, int UserSessionIndex, IQ iq)
        {
            Auth auth = iq.Query as Auth;

            iq.SwitchDirection();
            string cuser = auth.Username;
            string cpass = auth.Digest;

            if (!string.IsNullOrEmpty(cuser) && !string.IsNullOrEmpty(cpass))
            {
                if (!ThreadTools.Users.Online[UserSessionIndex].Authenticated)
                {
                    int UserIndex;
                    if (!ThreadTools.Users.Online.IsAuthenticated(cuser, out UserIndex))
                    {
                        BLL.Users api = new BLL.Users();
                        if (api.LoginMessenger(cuser, SID, cpass))
                        {
                            iq.Type = IqType.result;
                            ThreadTools.Users.Online[UserSessionIndex].Authenticated = true;
                            ThreadTools.Users.Online[UserSessionIndex].Username      = cuser;
                            iq.Query = null;
                            ThreadTools.Users.Online[UserSessionIndex].Send(iq);

                            api.ChangeUserStatus(cuser, true);

                            Presence p = Rosters.GetPresence(cuser);
                            p.To = new agsXMPP.Jid(cuser + "@" + Config.AppSetting.domain);

                            ThreadTools.Users.Online[UserSessionIndex].Send(p);

                            Rosters.SendStatus(cuser);
                        }
                        else
                        {
                            iq.Type  = IqType.error;
                            iq.Query = null;
                            iq.AddChild(new agsXMPP.protocol.client.Error(ErrorType.auth, ErrorCondition.NotAuthorized));
                            ThreadTools.Users.Online[UserSessionIndex].Send(iq);
                        }
                    }
                    else
                    {
                        iq.Type  = IqType.error;
                        iq.Query = null;
                        iq.AddChild(new agsXMPP.protocol.client.Error(ErrorType.auth, ErrorCondition.Conflict));
                        ThreadTools.Users.Online[UserSessionIndex].Send(iq);
                    }
                }
            }
            else
            {
                iq.Type  = IqType.error;
                iq.Query = null;
                iq.AddChild(new agsXMPP.protocol.client.Error(ErrorType.auth, ErrorCondition.NotAcceptable));
                ThreadTools.Users.Online[UserSessionIndex].Send(iq);
            }
        }
        /// <summary>
        /// Send message to HarmonyHub with UserAuthToken, wait for SessionToken
        /// </summary>
        /// <param name="userAuthToken"></param>
        /// <returns></returns>
        public string SwapAuthToken(string userAuthToken)
        {
            EnsureConnection();

            var iqToSend = new IQ {
                Type = IqType.get, Namespace = "", From = "1", To = "guest"
            };

            iqToSend.AddChild(HarmonyDocuments.LogitechPairDocument(userAuthToken));
            iqToSend.GenerateId();

            var iqGrabber = new IqGrabber(Xmpp);
            var iq        = iqGrabber.SendIq(iqToSend, 5000);

            if (iq != null)
            {
                var match = IdentityRegex.Match(iq.InnerXml);
                if (match.Success)
                {
                    return(match.Groups[1].ToString());
                }
            }

            return(null);
        }
예제 #3
0
        /// <summary>
        /// Send message to HarmonyHub to request Configuration.
        /// Result is parsed by OnIq based on ClientCommandType
        /// </summary>
        public void GetConfig()
        {
            EnsureConnection();

            var iqToSend = new IQ {
                Type = IqType.get, Namespace = "", From = "1", To = "guest"
            };

            iqToSend.AddChild(HarmonyDocuments.ConfigDocument());
            iqToSend.GenerateId();

            var iqGrabber = new IqGrabber(Xmpp);
            var iq        = iqGrabber.SendIq(iqToSend, 10000);

            if (iq != null)
            {
                var match = IdentityRegex.Match(iq.InnerXml);
                if (match.Success)
                {
                    RawConfig = match.Groups[1].ToString();
                    Config    = null;
                    try
                    {
                        Config = new JavaScriptSerializer().Deserialize <HarmonyConfigResult>(RawConfig);
                    }
                    catch { }
                }
            }
        }
예제 #4
0
        public void Publish(string node, XmlElement item)
        {
            IQ iq = new IQ(m_Account.Client.Document);

            iq.Type = IQType.set;
            PubSub pubsub = new PubSub(m_Account.Client.Document);

            pubsub.SetAttribute("xmlns", "http://jabber.org/protocol/pubsub");
            Publish publish = new Publish(m_Account.Client.Document);

            publish.SetAttribute("node", node);
            publish.AddChild(item);
            pubsub.AddChild(publish);
            iq.AddChild(pubsub);

            if (m_Account.ConnectionState == AccountConnectionState.Connected)
            {
                m_Account.Send(iq);
            }
            else
            {
                lock (m_Queue) {
                    m_Queue.Enqueue(iq);
                }
            }
        }
예제 #5
0
        private void JabberClient_OnSASLEnd(Object sender, Features feat)
        {
            lock (StateLock)
            {
                State = BindState.Instance;
            }
            if (feat["bind", URI.BIND] != null)
            {
                IQ iq = new IQ(this.Document);
                iq.Type = IQType.set;

                Bind bind = new Bind(this.Document);
                if ((Resource != null) && (Resource != ""))
                {
                    bind.Resource = Resource;
                }

                iq.AddChild(bind);
                this.Tracker.BeginIQ(iq, new IqCB(GotResource), feat);
            }
            else if (feat["session", URI.SESSION] != null)
            {
                IQ iq = new IQ(this.Document);
                iq.Type = IQType.set;
                iq.AddChild(new Session(this.Document));
                this.Tracker.BeginIQ(iq, new IqCB(GotSession), feat);
            }
            else
            {
                IsAuthenticated = true;
            }
        }
예제 #6
0
        private void GotResource(object sender, IQ iq, object state)
        {
            jabber.protocol.stream.Features feat =
                state as jabber.protocol.stream.Features;

            if (iq == null)
            {
                FireOnError(new AuthenticationFailedException("Timeout authenticating"));
                return;
            }
            if (iq.Type != IQType.result)
            {
                Error err = iq.Error;
                if (err == null)
                {
                    FireOnError(new AuthenticationFailedException("Unknown error binding resource"));
                }
                else
                {
                    FireOnError(new AuthenticationFailedException("Error binding resource: " + err.OuterXml));
                }
                return;
            }

            XmlElement bind = iq["bind", URI.BIND];

            if (bind == null)
            {
                FireOnError(new AuthenticationFailedException("No binding returned.  Server implementation error."));
                return;
            }
            XmlElement jid = bind["jid"];

            if (jid == null)
            {
                FireOnError(new AuthenticationFailedException("No jid returned from binding.  Server implementation error."));
                return;
            }
            this[Options.JID] = new JID(jid.InnerText);

            if (feat["session", URI.SESSION] != null)
            {
                IQ iqs = new IQ(this.Document);
                iqs.To   = this.Server;
                iqs.Type = IQType.set;
                iqs.AddChild(new jabber.protocol.stream.Session(this.Document));
                this.Tracker.BeginIQ(iqs, new IqCB(GotSession), feat);
            }
            else
            {
                IsAuthenticated = true;
            }
        }
예제 #7
0
        /// <summary>
        /// Send message to HarmonyHub to request to run a sequence
        /// Result is parsed by OnIq based on ClientCommandType
        /// </summary>
        /// <param name="deviceId"></param>
        /// <param name="command"></param>
        public void Sequence(int sequenceId)
        {
            EnsureConnection();

            var iqToSend = new IQ {
                Type = IqType.get, Namespace = "", From = "1", To = "guest"
            };

            iqToSend.AddChild(HarmonyDocuments.SequenceDocument(sequenceId));
            iqToSend.GenerateId();

            Xmpp.Send(iqToSend);
        }
예제 #8
0
        /// <summary>
        /// Send message to HarmonyHub to request to press a button
        /// Result is parsed by OnIq based on ClientCommandType
        /// </summary>
        /// <param name="deviceId"></param>
        /// <param name="command"></param>
        public void PressButton(string deviceId, string command)
        {
            EnsureConnection();

            var iqToSend = new IQ {
                Type = IqType.get, Namespace = "", From = "1", To = "guest"
            };

            iqToSend.AddChild(HarmonyDocuments.IRCommandDocument(deviceId, command));
            iqToSend.GenerateId();

            Xmpp.Send(iqToSend);
        }
예제 #9
0
        /// <summary>
        /// Send message to HarmonyHub to start a given activity
        /// Result is parsed by OnIq based on ClientCommandType
        /// </summary>
        /// <param name="activityId"></param>
        public void StartActivity(string activityId)
        {
            EnsureConnection();

            var iqToSend = new IQ {
                Type = IqType.get, Namespace = "", From = "1", To = "guest"
            };

            iqToSend.AddChild(HarmonyDocuments.StartActivityDocument(activityId));
            iqToSend.GenerateId();

            Xmpp.Send(iqToSend);
        }
예제 #10
0
        private void Xmpp_OnPresence(object sender, Presence pres)
        {
            var    user = pres.From.User;
            Friend friend;

            //Wack to fix chatroom presences
            if (pres.Status == null && pres.MucUser != null && ChatUtils.GetSummonerId(pres.MucUser.Item.Jid.User) == session.Me.SummonerId)
            {
                SendPresence();
            }
            else if (friends.TryGetValue(user, out friend))
            {
                friend.OnPresence(pres);
                OnStatus(friend);

                if (friend.Status?.GameStatus == GameStatus.inGame)
                {
                    GetInGameData(friend);
                }

                if (!fetchedHistories.Contains(user))
                {
                    fetchedHistories.Add(user);
                    var iq = new IQ(IqType.get, xmpp.MyJID, null)
                    {
                        Id = "arch_" + Guid.NewGuid()
                    };
                    var query = new Element("query")
                    {
                        Namespace = "jabber:iq:riotgames:archive"
                    };
                    query.AddChild(new Element("with", pres.From.Bare));
                    iq.AddChild(query);

                    xmpp.IqGrabber.SendIq(iq, async(s, result, d) => {
                        await Task.Delay(5000);
                        //TODO Fix this disgusting hack
                        var history = result.SelectElements <Message>();
                        foreach (var msg in history.OrderBy(m => DateTime.Parse(m.GetAttribute("stamp"))))
                        {
                            OnMessage(new ChatMessage(friend.User, msg, true));
                        }
                    });
                }
            }
            else
            {
                PresenceRaw?.Invoke(this, pres);
            }
        }
        /// <summary>
        /// Send message to HarmonyHub with UserAuthToken, wait for SessionToken
        /// </summary>
        /// <param name="userAuthToken"></param>
        /// <returns></returns>
        public string SwapAuthToken(string userAuthToken)
        {
            var iqToSend = new IQ {
                Type = IqType.get, Namespace = "", From = "1", To = "guest"
            };

            iqToSend.AddChild(HarmonyDocuments.LogitechPairDocument(userAuthToken));
            iqToSend.GenerateId();

            var iqGrabber = new IqGrabber(Xmpp);

            iqGrabber.SendIq(iqToSend, 10);

            WaitForData(5);

            return(_sessionToken);
        }
예제 #12
0
        /// <summary>
        /// Send message to HarmonyHub to request to press a button
        /// Result is parsed by OnIq based on ClientCommandType
        /// </summary>
        /// <param name="deviceId"></param>
        /// <param name="command"></param>
        public void PressButton(string deviceId, string command)
        {
            _clientCommand = ClientCommandType.PressButton;

            var iqToSend = new IQ {
                Type = IqType.get, Namespace = "", From = "1", To = "guest"
            };

            iqToSend.AddChild(HarmonyDocuments.IrCommandDocument(deviceId, command));
            iqToSend.GenerateId();

            var iqGrabber = new IqGrabber(Xmpp);

            iqGrabber.SendIq(iqToSend, 5);

            WaitForData(5);
        }
예제 #13
0
        /// <summary>
        /// Send message to HarmonyHub to start a given activity
        /// Result is parsed by OnIq based on ClientCommandType
        /// </summary>
        /// <param name="activityId"></param>
        public void StartActivity(string activityId)
        {
            _clientCommand = ClientCommandType.StartActivity;

            var iqToSend = new IQ {
                Type = IqType.get, Namespace = "", From = "1", To = "guest"
            };

            iqToSend.AddChild(HarmonyDocuments.StartActivityDocument(activityId));
            iqToSend.GenerateId();

            var iqGrabber = new IqGrabber(Xmpp);

            iqGrabber.SendIq(iqToSend, 10);

            WaitForData(5);
        }
예제 #14
0
        /// <summary>
        /// Send message to HarmonyHub to request Configuration.
        /// Result is parsed by OnIq based on ClientCommandType
        /// </summary>
        public void GetConfig()
        {
            _clientCommand = ClientCommandType.GetConfig;

            var iqToSend = new IQ {
                Type = IqType.get, Namespace = "", From = "1", To = "guest"
            };

            iqToSend.AddChild(HarmonyDocuments.ConfigDocument());
            iqToSend.GenerateId();

            var iqGrabber = new IqGrabber(Xmpp);

            iqGrabber.SendIq(iqToSend, 10);

            WaitForData(5);
        }
예제 #15
0
        public void Bind(string resource)
        {
            var packet = new Packet("resource")
            {
                Value = resource
            };

            var binder = new Packet("bind", "urn:ietf:params:xml:ns:xmpp-bind");

            binder.AddChild(packet);

            var iq = new IQ(IQType.Set);

            iq.AddChild(binder);

            Register(iq);
            Stream.Send(iq);
        }
예제 #16
0
        /// <summary>
        ///     Generate an IQ for the supplied Document
        /// </summary>
        /// <param name="document">Document</param>
        /// <returns>IQ</returns>
        private static IQ GenerateIq(Document document)
        {
            // Create the IQ to send
            var iqToSend = new IQ
            {
                Type      = IqType.get,
                Namespace = "",
                From      = "1",
                To        = "guest"
            };

            // Add the real content for the Harmony
            iqToSend.AddChild(document);

            // Generate an unique ID, this is used to correlate the reply to the request
            iqToSend.GenerateId();
            return(iqToSend);
        }
예제 #17
0
        /// <summary>
        /// Send message to HarmonyHub to request current activity
        /// Result is parsed by OnIq based on ClientCommandType
        /// </summary>
        public void GetCurrentActivity()
        {
            EnsureConnection();

            _clientCommand = ClientCommandType.GetCurrentActivity;

            var iqToSend = new IQ {
                Type = IqType.get, Namespace = "", From = "1", To = "guest"
            };

            iqToSend.AddChild(HarmonyDocuments.GetCurrentActivityDocument());
            iqToSend.GenerateId();

            var iqGrabber = new IqGrabber(Xmpp);

            iqGrabber.SendIq(iqToSend, 10);

            WaitForData(5);
        }
예제 #18
0
        /// <summary>
        /// Send message to HarmonyHub to request current activity
        /// Result is parsed by OnIq based on ClientCommandType
        /// </summary>
        public void GetCurrentActivity()
        {
            EnsureConnection();

            var iqToSend = new IQ {
                Type = IqType.get, Namespace = "", From = "1", To = "guest"
            };

            iqToSend.AddChild(HarmonyDocuments.GetCurrentActivityDocument());
            iqToSend.GenerateId();

            var iqGrabber = new IqGrabber(Xmpp);
            var iq        = iqGrabber.SendIq(iqToSend, 5000);

            if (iq != null)
            {
                var match = IdentityRegex.Match(iq.InnerXml);
                if (match.Success)
                {
                    CurrentActivity = match.Groups[1].ToString().Split('=')[1];
                }
            }
        }
예제 #19
0
        private void JabberClient_OnSASLEnd(Object sender, protocol.stream.Features feat)
        {
            lock (StateLock)
            {
                State = BindState.Instance;
            }
            if (feat["bind", URI.BIND] != null)
            {
                IQ iq = new IQ(Document) {Type = IQType.Set};

                protocol.stream.Bind bind = new protocol.stream.Bind(Document);
                if (!string.IsNullOrEmpty(Resource))
                    bind.Resource = Resource;

                iq.AddChild(bind);
                Tracker.BeginIQ(iq, GotResource, feat);
            }
            else if (feat["session", URI.SESSION] != null)
            {
                IQ iq = new IQ(Document) {Type = IQType.Set};
                iq.AddChild(new protocol.stream.Session(Document));
                Tracker.BeginIQ(iq, GotSession, feat);
            }
            else
                IsAuthenticated = true;
        }
예제 #20
0
        private void GotResource(object sender, IQ iq, object state)
        {
            protocol.stream.Features feat = state as protocol.stream.Features;

            if (iq == null)
            {
                FireOnError(new AuthenticationFailedException("Timeout authenticating"));
                return;
            }
            if (iq.Type != IQType.Result)
            {
                Error err = iq.Error;
                if (err == null)
                    FireOnError(new AuthenticationFailedException("Unknown error binding resource"));
                else
                    FireOnError(new AuthenticationFailedException("Error binding resource: " + err.OuterXml));
                return;
            }

            XmlElement bind = iq["bind", URI.BIND];
            if (bind == null)
            {
                FireOnError(new AuthenticationFailedException("No binding returned.  Server implementation error."));
                return;
            }
            XmlElement jid = bind["jid"];
            if (jid == null)
            {
                FireOnError(new AuthenticationFailedException("No jid returned from binding.  Server implementation error."));
                return;
            }
            this[Options.JID] = new JID(jid.InnerText);

            if (feat["session", URI.SESSION] != null)
            {
                IQ iqs = new IQ(Document) {Type = IQType.Set};
                iqs.AddChild(new protocol.stream.Session(Document));
                Tracker.BeginIQ(iqs, GotSession, feat);
            }
            else
                IsAuthenticated = true;
        }
예제 #21
0
        private void JabberClient_OnSASLEnd(Object sender, jabber.protocol.stream.Features feat)
        {
            lock (StateLock)
            {
                State = BindState.Instance;
            }
            if (feat["bind", URI.BIND] != null)
            {
                IQ iq = new IQ(this.Document);
                iq.Type = IQType.set;

                jabber.protocol.stream.Bind bind = new jabber.protocol.stream.Bind(this.Document);
                if ((Resource != null) && (Resource != ""))
                    bind.Resource = Resource;

                iq.AddChild(bind);
                this.Tracker.BeginIQ(iq, new IqCB(GotResource), feat);
            }
            else if (feat["session", URI.SESSION] != null)
            {
                IQ iq = new IQ(this.Document);
                iq.Type = IQType.set;
                iq.AddChild(new jabber.protocol.stream.Session(this.Document));
                this.Tracker.BeginIQ(iq, new IqCB(GotSession), feat);
            }
            else
                IsAuthenticated = true;
        }
예제 #22
0
        public void Publish(string node, XmlElement item)
        {
            IQ iq = new IQ(m_Account.Client.Document);
            iq.Type = IQType.set;
            PubSub pubsub = new PubSub(m_Account.Client.Document);
            pubsub.SetAttribute("xmlns", "http://jabber.org/protocol/pubsub");
            Publish publish = new Publish(m_Account.Client.Document);
            publish.SetAttribute("node", node);
            publish.AddChild(item);
            pubsub.AddChild(publish);
            iq.AddChild(pubsub);

            if (m_Account.ConnectionState == AccountConnectionState.Connected) {
                m_Account.Send(iq);
            } else {
                lock (m_Queue) {
                    m_Queue.Enqueue(iq);
                }
            }
        }