Ejemplo n.º 1
0
        public static void ProcessRosterIQGet(string username, IQ iq)
        {
            iq.Type  = IqType.result;
            iq.Query = new Roster();

            BLL.Users           api   = new BLL.Users();
            List <DAL.VwFriend> FList = api.ListFriend(username);

            for (int i = 0; i < FList.Count; i++)
            {
                RosterItem ri = new RosterItem();
                ri.Name         = FList[i].VcardFirstName + " " + FList[i].VcardLastName;
                ri.Subscription = (FList[i].FriendStatus == 1) ? SubscriptionType.from : SubscriptionType.both;
                ri.Jid          = new agsXMPP.Jid(FList[i].FriendUserName + "@" + Config.AppSetting.domain);
                if (!string.IsNullOrEmpty(FList[i].GroupName))
                {
                    ri.AddGroup(FList[i].GroupName);
                }
                iq.Query.AddChild(ri);
            }

            int index;

            if (ThreadTools.Users.Online.IsAuthenticated(username, out index))
            {
                ThreadTools.Users.Online[index].Send(iq);
                ThreadTools.Users.Online[index].Send(Rosters.FriendStatus(username));
                ThreadTools.Users.Online[index].Send(Messages.OfflineMessage(username));
                ThreadTools.Users.Online[index].Send(Rosters.PendingStatus(iq.From.User));
            }
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
0
        public static void Avatar(string username, IQ iq)
        {
            DAL.TbUsers cuser;
            BLL.Users   api = new BLL.Users();
            switch (iq.Type)
            {
            case IqType.get:
                if (iq.To != null)
                {
                    cuser = api.Find(iq.To.User);
                }
                else
                {
                    cuser = api.Find(username);
                }

                if (cuser != null)
                {
                    if (!string.IsNullOrEmpty(cuser.TbVcard.VcardPhoto))
                    {
                        iq.SwitchDirection();
                        iq.Type            = IqType.result;
                        iq.Query.Namespace = "jabber:iq:avatar";
                        iq.Query.ChildNodes.Clear();
                        Element dataEl = new Element("data");
                        dataEl.Value = ImageTools.ToBase64(cuser.TbVcard.VcardPhoto);

                        iq.Query.AddChild(dataEl);
                        int index;
                        if (ThreadTools.Users.Online.IsAuthenticated(username, out index))
                        {
                            ThreadTools.Users.Online[index].Send(iq);
                        }
                    }
                }
                break;

            case IqType.set:
            case IqType.result:
                if (iq.Query.HasTag("data"))
                {
                    Element el = iq.Query.SelectSingleElement("data");
                    cuser = api.Find(username);
                    string pname;
                    bool   isSaved;
                    pname = ImageTools.SaveAvatar(el.Value, out isSaved);
                    if (isSaved)
                    {
                        api.ChangeUserPicture(username, pname);
                        Rosters.SendStatus(username);
                    }
                }
                break;
            }
        }