Example #1
0
        public static void IQs(string sid, string username, IQ iq)
        {
            try
            {
                string iqId = string.Empty;
                if (iq.HasAttribute("id"))
                {
                    iqId = iq.Id;
                }

                int UserSessionIndex;
                ThreadTools.Users.Online.IsSessionExists(sid, out UserSessionIndex);

                if (ThreadTools.Users.Online[UserSessionIndex].Authenticated)
                {
                    iq.From = new agsXMPP.Jid(username + "@" + Config.AppSetting.domain);
                }

                if (iq.HasTag("ping"))
                {
                    XML.IQs.PingPong(username, UserSessionIndex, iqId);
                }
                else if (iq.HasTag("vCard"))
                {
                    XML.IQs.ProccessVcard(username, UserSessionIndex, iq);
                }
                else if (iq.HasTag("pubsub"))
                {
                    //to do
                }
                else if (iq.Query != null)
                {
                    if (iq.Query.Namespace == "http://jabber.org/protocol/disco#info" && iq.Type == IqType.get)
                    {
                        ThreadTools.Users.Online[UserSessionIndex].Send(XML.Server.features(username, iq));
                    }
                    else if (iq.Query.GetType() == typeof(Auth))
                    {
                        Auth auth = iq.Query as Auth;
                        switch (iq.Type)
                        {
                        case IqType.get:
                            XML.IQs.ProccessAuthGet(username, UserSessionIndex, iq);
                            break;

                        case IqType.set:
                            XML.IQs.ProccessAuthSet(username, sid, UserSessionIndex, iq);
                            break;
                        }
                    }
                    else if (iq.Query.GetType() == typeof(Register))
                    {
                        XML.IQs.SubmitChangePassForm(username, iq);
                    }
                    else if (iq.Query.GetType() == typeof(Roster))
                    {
                        if (iq.Type == IqType.get)
                        {
                            XML.IQs.ProcessRosterIQGet(username, iq);
                        }
                        else
                        {
                            XML.IQs.ProcessRosterIQSet(username, iq);
                        }
                    }
                    else if (iq.Query.GetType() == typeof(Last))
                    {
                        if (iq.Type == IqType.get)
                        {
                            if (iq.To != null)
                            {
                                BLL.Users api = new BLL.Users();
                                iq.SwitchDirection();
                                iq.Type = IqType.result;
                                DateTime d    = api.LastActivity(iq.To.User);
                                TimeSpan diff = DateTime.Now - d;
                                Last     lt   = iq.Query as Last;
                                lt.Seconds = diff.Seconds;
                                ThreadTools.Users.Online[UserSessionIndex].Send(iq);
                            }
                        }
                    }
                    else if (iq.Query.GetType() == typeof(agsXMPP.protocol.iq.version.Version))
                    {
                        iq.SwitchDirection();
                        if (iq.From != null)
                        {
                            ThreadTools.Users.Online[UserSessionIndex].Send(iq);
                        }
                    }
                    else if (iq.Query.Namespace.IndexOf("avatar") > -1)
                    {
                        XML.IQs.Avatar(username, iq);
                    }
                }
            }
            catch (Exception ex)
            {
                LogTools.Write(sid, ex, "Proccess.IQs");
            }
        }