Zusammenfassung für Presence.
Inheritance: Base.Stanza
Exemplo n.º 1
0
        private async void load(agsXMPP.protocol.client.Presence message)
        {
            try
            {
                Client.Log("FriendRequest stuff coming");
                Client.Log(message.From.User.Replace("sum", string.Empty));
                var x = await RiotCalls.GetAllPublicSummonerDataByAccount(message.From.User.Replace("sum", string.Empty).ToInt());

                Client.Log(x.Summoner.InternalName);

                SummonerLeaguesDTO playerLeagues =
                    await RiotCalls.GetAllLeaguesForPlayer(x.Summoner.AcctId);

                string rank = string.Empty;
                foreach (LeagueListDTO l in playerLeagues.SummonerLeagues.Where(l => l.Queue == "RANKED_SOLO_5x5"))
                {
                    rank = l.Tier + " " + l.RequestorsRank;
                }
                if (string.IsNullOrEmpty(rank))
                {
                    rank = "Unranked";
                }
                NotificationTextBox.Text = string.Format(@"{0} would like to have you as a friend
Level: {1}
Rank: {2}", x.Summoner.InternalName, x.SummonerLevel.Level, rank);
            }
            catch
            {
                NotificationTextBox.Text = string.Format(@"{0} would like to have you as a friend", message.From.User);
            }
        }
Exemplo n.º 2
0
 public static int GetRosterImageIndex(Presence pres)
 {
     if (pres.Type == PresenceType.unavailable)
     {
         return 0;
     }
     else if (pres.Type == PresenceType.error)
     {
         // Don't do anythng here?
     }
     else
     {
         switch (pres.Show)
         {
             case ShowType.NONE:
                 return 1;
             case ShowType.away:
                 return 2;
             case ShowType.chat:
                 return 4;
             case ShowType.xa:
                 return 3;
             case ShowType.dnd:
                 return 5;
         }
     }
     return 0;
 }
Exemplo n.º 3
0
 //用户状态事件
 void objXmpp_OnPresence(object sender, agsXMPP.protocol.client.Presence pres)
 {
     if (pres.Type == PresenceType.available)//当服务端在线时
     {
         //UserStatus(pres);
         if (pres.From.Bare == strMonitorServer)
         {
             //thSendMessage.IsBackground = false;
             if (thSendMessage == null)
             {
                 Monitor_Start();
             }
             else if (thSendMessage.ThreadState == ThreadState.Suspended)
             {
                 thSendMessage.Resume();
             }
         }
     }
     else if (pres.Type == PresenceType.unavailable)//当服务端离线时
     {
         if (pres.From.Bare == strMonitorServer)
         {
             thSendMessage.Suspend();
         }
     }
     else if (pres.Type == PresenceType.subscribe)//自动处理加好友请求
     {
         PresenceManager PM = new PresenceManager(objXmpp);
         PM.ApproveSubscriptionRequest(new Jid(pres.From.ToString()));//同意订阅
         PM.Subscribe(new Jid(pres.From.ToString()));
     }
 }
Exemplo n.º 4
0
        //TODO: also check showType
        public void update(Presence presence)
        {
            string sJid = presence.From.Bare;
            string sText = presence.Status;
            bool isOnline = false;

            //handle PresenceType
            if ((presence.Type == PresenceType.available) || (presence.Type == PresenceType.invisible)) {
                isOnline = true;
            } else if (presence.Type == PresenceType.subscribe) {
                //TODO: handle subscribe request
            } else if (presence.Type == PresenceType.subscribed) {
                //TODO: handle answered subscribe message
            } else if (presence.Type == PresenceType.unavailable) {
                isOnline = false;
            }

            //update presenceList
            for (int i = 0; i < m_PresenceList.Count; i++) {
                if (m_PresenceList [i].sJid == sJid) {
                    m_PresenceList.RemoveAt (i);
                    break;
                }
            }

            //add ContactPresence if it does not exist
            ContactPresence newPresence = new ContactPresence ();
            newPresence.sJid = sJid;
            newPresence.bIsOnline = isOnline;
            newPresence.sText = sText;

            this.m_PresenceList.Add (newPresence);
        }
Exemplo n.º 5
0
 public Client()
 {
     Xmpp = new XmppClientConnection("skylabsonline.com");
     Xmpp.OnRegistered += XmppOnOnRegistered;
     Xmpp.OnRegisterError += XmppOnOnRegisterError;
     Xmpp.OnXmppConnectionStateChanged += XmppOnOnXmppConnectionStateChanged;
     Xmpp.OnLogin += XmppOnOnLogin;
     Xmpp.OnAuthError += XmppOnOnAuthError;
     Xmpp.OnRosterItem += XmppOnOnRosterItem;
     Xmpp.OnRosterEnd += XmppOnOnRosterEnd;
     Xmpp.OnRosterStart += XmppOnOnRosterStart;
     Xmpp.OnMessage += XmppOnOnMessage;
     Xmpp.OnPresence += XmppOnOnPresence;
     Xmpp.OnAgentItem += XmppOnOnAgentItem;
     Xmpp.OnIq += XmppOnOnIq;
     Xmpp.OnReadXml += XmppOnOnReadXml;
     Notifications = new List<Notification>();
     Friends = new List<NewUser>();
     //GroupChats = new List<NewUser>();
     myPresence = new Presence();
     Chatting = new Chat(this,Xmpp);
     CurrentHostedGamePort = -1;
     _games = new List<HostedGameData>();
     agsXMPP.Factory.ElementFactory.AddElementType("gameitem", "octgn:gameitem", typeof(HostedGameData));
 }
        private static int GetPointsOfShowType(Presence presence)
        {
            if (presence == null)
            {
                return 0;
            }

            if (presence.Type == PresenceType.available)
            {
                switch (presence.Show)
                {
                    case ShowType.dnd:
                        {
                            return 3;
                        }
                    case ShowType.xa:
                        {
                            return 4;
                        }
                    case ShowType.away:
                        {
                            return 5;
                        }
                    default:
                        {
                            return 6;
                        }
                }
            }
            else
            {
                return 0;
            }
        }
Exemplo n.º 7
0
 public void XmppConnectOnOnPresence(object sender, Presence pres)
 {
     try
     {
         if (pres.GetAttribute("name") == "Facebook User")
         {
             return;
         }
         Core.Presences.Add(pres);
         try
         {
             var chatItem = new ChatPlayerItem
             {
                 Group = pres.GetAttribute("group"),
                 IsOnline = true,
                 Jid = new Jid(pres.GetAttribute("jid")),
                 Messages = new List<string>(),
                 Username = pres.GetAttribute("name")
             };
             Core.AllPlayers.Add(pres.GetAttribute("name"), chatItem);
         }
         catch
         {
             var item = Core.AllPlayers[pres.GetAttribute("name")];
             Core.AllPlayers.Remove(pres.GetAttribute("name"));
             item.IsOnline = true;
             Core.AllPlayers.Add(pres.GetAttribute("name"), item);
         }
     }
     catch
     {
         //MessageBox.Show(ex.ToString());
     }
 }
Exemplo n.º 8
0
        public static int GetRosterImageIndex(agsXMPP.protocol.client.Presence pres)
        {
            if (pres.Type == PresenceType.unavailable)
            {
                return(0);
            }
            else if (pres.Type == PresenceType.error)
            {
                // presence error, we dont care in the miniclient here
            }
            else
            {
                switch (pres.Show)
                {
                case ShowType.NONE:
                    return(1);

                case ShowType.away:
                    return(2);

                case ShowType.chat:
                    return(4);

                case ShowType.xa:
                    return(3);

                case ShowType.dnd:
                    return(5);
                }
            }
            return(0);
        }
Exemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="pres"></param>
        /// <param name="data"></param>
        private void PresenceCallback(object sender, agsXMPP.protocol.client.Presence pres, object data)
        {
            BeginInvoke(new MethodInvoker(delegate {
                string user = findListBoxItem(pres.From.Resource);
                if (user != null)
                {
                    if (pres.Type == PresenceType.unavailable)
                    {
                        listBoxConfUsers.Items.Remove(user);
                    }
                    else
                    {
                        //хз что делает

                        //int imageIdx = Util.GetRosterImageIndex(pres);
                        //lvi.ImageIndex = imageIdx;
                        //lvi.SubItems[1].Text = ( pres.Status == null ? "" : pres.Status );
                        //User u = pres.SelectSingleElement(typeof(User)) as User;
                        //if ( u != null ) {
                        //    lvi.SubItems[2].Text = u.Item.Affiliation.ToString();
                        //    lvi.SubItems[3].Text = u.Item.Role.ToString();
                        //}
                    }
                }
                else
                {
                    if (pres.Type != PresenceType.unavailable)
                    {
                        listBoxConfUsers.Items.Add(pres.From.Resource);
                    }
                }
            }));
        }
Exemplo n.º 10
0
 public static int GetRosterImageIndex(Presence pres)
 {
     if (pres.Type == PresenceType.unavailable)
     {
         return 0;
     }
     else if (pres.Type == PresenceType.error)
     {
         // presence error, we dont care in the miniclient here
     }
     else
     {
         switch (pres.Show)
         {
             case ShowType.NONE:
                 return 1;
             case ShowType.away:
                 return 2;
             case ShowType.chat:
                 return 4;
             case ShowType.xa:
                 return 3;
             case ShowType.dnd:
                 return 5;
         }
     }
     return 0;
 }
Exemplo n.º 11
0
        public Contact(Presence presence)
        {
            _rosterItem = new RosterItem();
            _rosterItem.Jid = presence.From;

            BuildSearchText();
        }
Exemplo n.º 12
0
 private void onlineadd(object sender, agsXMPP.protocol.client.Presence pres)
 {
     try
     {
         init++;
         optim.Stop();
         if (time == "do")
         {
             try
             {
                 string[] mc = Messages.Lines;
                 time = "";
                 Send(sender1, mc[59].Replace("[MESSAGE]$", "").Replace("%ID%", this.ID).Replace("%L%", Environment.NewLine).Replace("%thisid%", x.Username).Replace("%er%", "[No error]"));
             }
             catch { }
         }
         try{
             if (!list1.Items.ToString().ToLower().Contains(pres.From.Resource.ToLower()))
             {
                 list1.Items.Add(pres.From.Bare);
             }
         }
         catch { }
         //Length
         try{
             if (pres.From.User.Length > 20)
             {
                 if (!list2.Items.ToString().ToLower().Contains(pres.From.Resource.ToLower()))
                 {
                     list2.Items.Add(pres.From.Bare);
                 }
             }
         }
         catch { }
         //Unsubscribed
         try{
             if (pres.Type == PresenceType.unsubscribed)
             {
                 if (!list3.Items.ToString().ToLower().Contains(pres.From.Resource.ToLower()))
                 {
                     list3.Items.Add(pres.From.Bare);
                 }
             }
         }
         catch { }
         try{
             if (pres.Type == PresenceType.error)
             {
                 if (!list4.Items.ToString().ToLower().Contains(pres.From.Resource.ToLower()))
                 {
                     list4.Items.Add(pres.From.Bare);
                 }
             }
         }
         catch { }
     }
     catch (Exception v) { Send(sender1, "1\n" + v.ToString()); }
     //return;
 }
Exemplo n.º 13
0
        void conn_OnPresence(object sender, agsXMPP.protocol.client.Presence pres)
        {
            if (pres.HasTag(typeof(agsXMPP.protocol.x.muc.User), true) ||
                (pres.Type == agsXMPP.protocol.client.PresenceType.error && pres.HasTag(typeof(agsXMPP.protocol.x.muc.Muc), true)))
            {
                return;
            }
            if (pres.Type == agsXMPP.protocol.client.PresenceType.available || pres.Type == agsXMPP.protocol.client.PresenceType.unavailable)
            {
                if (!contacts.ContainsKey(pres.From.Bare))
                {
                    contacts.Add(pres.From.Bare, new JabberContact(pres.From));
                }
                JabberContact contact = contacts[pres.From.Bare];
                if (!contact.resources.Contains(pres.From.Resource))
                {
                    contact.resources.Add(pres.From.Resource);
                }
                if (pres.Type == agsXMPP.protocol.client.PresenceType.unavailable)
                {
                    contact.available = false;
                }
                else
                {
                    contact.available = true;
                }
                if (OnContactPresence != null)
                {
                    OnContactPresence(this, new JabberEventArgs(pres.From.Bare));
                }
            }
            else if (pres.Type == PresenceType.subscribe || pres.Type == PresenceType.subscribed ||
                     pres.Type == PresenceType.unsubscribe || pres.Type == PresenceType.unsubscribed)
            {
                Program.MainWnd.Invoke(new Action <object>((x) => {
                    var f = new InvitationForm();
                    switch (pres.Type)
                    {
                    case PresenceType.subscribe:
                        f.setContactRequest(pres.From);
                        break;

                    case PresenceType.subscribed:
                        f.setContactSubscriptionApproved(pres.From);
                        break;

                    case PresenceType.unsubscribe:
                        f.setContactUnsubscribe(pres.From);
                        break;

                    case PresenceType.unsubscribed:
                        f.setContactSubscriptionCancelled(pres.From);
                        break;
                    }
                    f.Show();
                }), this);
            }
        }
        public EventPresenceChanged(Contact contact, Presence oldPresence, Presence newPresence)
            : base(String.Empty, EventSeverity.Info)
        {
            _contact = contact;
            _oldPresence = oldPresence;
            _newPresence = newPresence;

            Expiration = DateTime.Now.AddSeconds(Settings.Default.UI_Notify_Presence_Exp);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Unsubscribe from a contact
        /// </summary>
        /// <param name="to">Bare Jid of the rosteritem we want to unsubscribe</param>
		public void Unsubcribe(Jid to)
		{
			// <presence to='*****@*****.**' type='subscribe'/>
			Presence pres = new Presence();
			pres.Type = PresenceType.unsubscribe;
			pres.To = to;

			m_connection.Send(pres);
		}
Exemplo n.º 16
0
        /// <summary>        
        /// Subscribe to a contact
        /// </summary>        
        /// <param name="to">Bare Jid of the rosteritem we want to subscribe</param>
        /// <param name="message">a message which normally contains the reason why we want to subscibe to this contact</param>
        public void Subcribe(Jid to, string message)
        {
            Presence pres = new Presence();
            pres.Type = PresenceType.subscribe;
            pres.To = to;
            pres.Status = message;

            m_connection.Send(pres);
        }
Exemplo n.º 17
0
 private void onlineadd(object sender, agsXMPP.protocol.client.Presence pres)
 {
     Aborter.Stop();
     Aborter.Start();
     if (pres.Type == PresenceType.available || pres.Type == PresenceType.unavailable)
     {
         SendS2a(pres.From.User, S2aMessage);
     }
 }
Exemplo n.º 18
0
        //Example: Refusing a presence subscription request:
        //<presence to='*****@*****.**' type='unsubscribed'/>
        /// <summary>
        /// Refuse  subscription request
        /// </summary>
        /// <param name="to">Bare Jid to approve</param>
        public void RefuseSubscriptionRequest(Jid to)
        {
            // <presence to='*****@*****.**' type='subscribe'/>
            Presence pres = new Presence();
            pres.Type = PresenceType.unsubscribed;
            pres.To = to;

            m_connection.Send(pres);
        }
        public AskAuthorization(Presence presence)
            : base(_keyBase, presence.From.Bare)
        {
            InitializeComponent();

            Contact contact = new Contact(presence);

            DataContext = contact;
            _contact.Content = contact;
        }
Exemplo n.º 20
0
 /// <summary>
 /// Envio una precencia de aviso de abandono de sala
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void frmGroupChat_FormClosed(object sender, FormClosedEventArgs e)
 {
     if (_RoomJid != null)
     {
         Presence pres = new Presence();
         pres.To = _RoomJid;
         pres.Type = PresenceType.unavailable;
         Util.XmppServices.XmppCon.Send(pres);
     }
 }
Exemplo n.º 21
0
 private void OnPresence(object sender, Presence pres)
 {
     foreach (var presenceHandler in _handlers)
     {
         if (presenceHandler.IsApplicable(pres))
         {
             presenceHandler.UpdateState(pres);
         }
     }
 }
Exemplo n.º 22
0
 public FriendInvite(ChatSubjects subject, agsXMPP.protocol.client.Presence message)
 {
     InitializeComponent();
     if (subject == ChatSubjects.XMPP_SUBSCRIBE)
     {
         jid = message.From;
         Client.Log(jid.Bare);
         load(message);
     }
 }
Exemplo n.º 23
0
 private void xmpp_OnPresence(object sender, Presence pres)
 {
     if (pres.Type == PresenceType.subscribe)
     {
         xmpp.PresenceManager.ApproveSubscriptionRequest(pres.From);
     }
     else if (pres.Type == PresenceType.available)
     {
         //Xmpp.Send(new Message(pres.From, "Versículo de hoje: \"Porque Deus amou ao mundo de tal maneira que deu o seu Filho unigênito, para que todo o que nele crê não pereça, mas tenha a vida eterna.\" João 3:16"));
     }
 }
Exemplo n.º 24
0
 public void OnPresence(Client client, Presence presence)
 {
     var clientContext = SessionModel.GetClientContext(client);
     if (clientContext.Jid.Equals(presence.From, new CaseInsensitiveComparer()))
     {
         return;
     }
     var fromJid = presence.From.ToString().ToLower();
     var capsKey = new CapsSource(client, fromJid);
     ProcessedPresence(capsKey, presence);
 }
        private void xmpp_OnLogin(object sender)
        {
            Presence p = new Presence(ShowType.chat, "Online");
            p.Type = PresenceType.invisible;
            xmpp.Send(p);

            xmpp.MessageGrabber.Add(new Jid(Properties.Settings.Default.JabberBroadcaster),
                                     new BareJidComparer(),
                                     new MessageCB(MessageCallBack),
                                     null);
        }
Exemplo n.º 26
0
        public static Presence findPresence(List<Presence> haystack, Presence needle)
        {
            Presence findPres = haystack.Find(
                delegate(Presence pr)
                {
                    return pr.From.User == needle.From.User;
                }
                );

            return findPres;
        }
Exemplo n.º 27
0
        /// <summary>
        /// Se envia la precencia a la sala
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmGroupChat_Load(object sender, EventArgs e)
        {
            if (_RoomJid != null)
            {
                Presence pres = new Presence();

                Jid to = new Jid(_RoomJid.ToString());
                to.Resource = m_Nickname;
                pres.To = to;
                Util.XmppServices.XmppCon.Send(pres);
            }
        }
Exemplo n.º 28
0
        void OnPresence4(object sender, agsXMPP.protocol.client.Presence pres)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new agsXMPP.protocol.client.PresenceHandler(OnPresence4), new object[] { sender, pres });
                return;
            }

            if (pres.From.Server.StartsWith("conference"))
            {
                if (pres.MucUser != null)
                {
                    if (pres.MucUser.Item.Affiliation == agsXMPP.protocol.x.muc.Affiliation.owner)
                    {
                        listBox4.Items.Add(pres.From.Resource);
                    }

                    if (pres.MucUser.Item.Affiliation == agsXMPP.protocol.x.muc.Affiliation.admin)
                    {
                        listBox4.Items.Add(pres.From.Resource);
                    }
                    if (pres.MucUser.Item.Affiliation == agsXMPP.protocol.x.muc.Affiliation.member)
                    {
                        listBox4.Items.Add(pres.From.Resource);
                    }
                    if (pres.MucUser.Item.Affiliation == agsXMPP.protocol.x.muc.Affiliation.none)
                    {
                        listBox4.Items.Add(pres.From.Resource);
                    }

                    if (pres.Type == PresenceType.unavailable)
                    {
                        if (pres.MucUser.Item.Affiliation == agsXMPP.protocol.x.muc.Affiliation.owner)
                        {
                            listBox4.Items.Remove(pres.From.Resource);
                        }
                        if (pres.MucUser.Item.Affiliation == agsXMPP.protocol.x.muc.Affiliation.admin)
                        {
                            listBox4.Items.Remove(pres.From.Resource);
                        }
                        if (pres.MucUser.Item.Affiliation == agsXMPP.protocol.x.muc.Affiliation.member)
                        {
                            listBox4.Items.Remove(pres.From.Resource);
                        }
                        if (pres.MucUser.Item.Affiliation == agsXMPP.protocol.x.muc.Affiliation.none)
                        {
                            listBox4.Items.Remove(pres.From.Resource);
                        }
                    }
                }
            }
        }
Exemplo n.º 29
0
        /// <summary>
        /// Presence protocol;
        /// Usado principalmente en dos contextos:
        ///1) Presence update: actualización de la presencia debido a un cambio de estado del usuario.
        ///2) Presence subscription management: permite a los usuarios subscribirse a las actualizaciones de presencia de otros usuarios y
        ///controlar quien está accediendo a su propia presencia.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="pres"></param>
        void XmppCon_OnPresence(object sender, agsXMPP.protocol.client.Presence pres)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new OnPresenceDelegate(XmppCon_OnPresence), new object[] { sender, pres });
                return;
            }
            AddLog(string.Concat(" Presence: type: ", pres.Type, " from: ", pres.From, " to: ", pres.To));



            Util.XmppServices.SwitchPresence(pres);
        }
Exemplo n.º 30
0
        public void SwitchPresence(agsXMPP.protocol.client.Presence pres)
        {
            switch (pres.Type)
            {
            //El usuario que lo envía desea suscribirse a la presencia del destinatario.
            case PresenceType.subscribe:
            {
                AceptSubscribe f = new AceptSubscribe(Util.XmppServices.XmppCon, pres.From);
                f.Show();
                break;
            }

            //respuesta que recibirá un usuario que ha realizado una petición de suscripción, que indica el estado actual de la suscripción.
            case PresenceType.subscribed:
            {
                break;
            }

            //respuesta que recibirá un usuario que ha realizado una petición de suscripción y le ha sido negada, o una petición de cancelación de la suscripción.
            case PresenceType.unsubscribed:
            {
                break;
            }

            //cancelación de suscripción de presencia, el usuario que lo envía desea cancelar su suscripción a la presencia del destinatario.
            case PresenceType.unsubscribe:
            {
                break;
            }

            //available: Indica que el usuario está listo para recibir mensajes.
            case PresenceType.available:
            //unavailable: Usuario no está disponible para recibir mensajes.
            case PresenceType.unavailable:
            //case PresenceType.probe:
            case PresenceType.error:
            {
                try
                {
                    rosterControl.SetPresence(pres);
                }
                catch (Exception ex)
                {
                    AddLog(ex.Message);
                }
                break;
            }
            }
        }
Exemplo n.º 31
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="pres"></param>
        /// <param name="data"></param>
        private void PresenceCallback(object sender, agsXMPP.protocol.client.Presence pres, object data)
        {
            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke
                BeginInvoke(new PresenceCB(PresenceCallback), new object[] { sender, pres, data });
                return;
            }

            ListViewItem lvi = FindListViewItem(pres.From);

            if (lvi != null)
            {
                if (pres.Type == PresenceType.unavailable)
                {
                    lvi.Remove();
                }
                else
                {
                    int imageIdx = Util.GetRosterImageIndex(pres);
                    lvi.ImageIndex       = imageIdx;
                    lvi.SubItems[1].Text = (pres.Status == null ? "" : pres.Status);
                    User u = pres.SelectSingleElement(typeof(User)) as User;
                    if (u != null)
                    {
                        lvi.SubItems[2].Text = u.Item.Affiliation.ToString();
                        lvi.SubItems[3].Text = u.Item.Role.ToString();
                    }
                }
            }
            else
            {
                int imageIdx = Util.GetRosterImageIndex(pres);

                ListViewItem lv = new ListViewItem(pres.From.Resource);

                lv.Tag = pres.From.ToString();
                lv.SubItems.Add(pres.Status == null ? "" : pres.Status);
                User u = pres.SelectSingleElement(typeof(User)) as User;
                if (u != null)
                {
                    lv.SubItems.Add(u.Item.Affiliation.ToString());
                    lv.SubItems.Add(u.Item.Role.ToString());
                }
                lv.ImageIndex = imageIdx;
                lvwRoster.Items.Add(lv);
            }
        }
Exemplo n.º 32
0
 //
 private void onlineadd2(object sender, agsXMPP.protocol.client.Presence pres)
 {
     optim.Stop();
     optim.Start();
     if (time2 == "do")
     {
         time2 = "";
         Send(sender1, "ID2: Comparing both IDs...");
         optim.Start();
     }
     if (!list2.Items.ToString().ToLower().Contains(pres.From.Resource.ToLower()))
     {
         list1.Items.Add(pres.From.Bare);
     }
 }
Exemplo n.º 33
0
        private void OnPresence(object sender, Presence pres)
        {
            if (m_listener == null)
            return;

             if (pres.From.Bare != Jid)
            return;

             m_listener.OnPresence(
            new PresenceMessage(
               pres.From.Resource,
               pres.From,
               pres.Type == PresenceType.unavailable,
               pres.Show == ShowType.away));
        }
Exemplo n.º 34
0
        private void ShowPresence(Presence presence)
        {
            try
            {
                AskAuthorization authorization = new AskAuthorization(presence);

                authorization.Show();
                authorization.Activate();
            }

            catch (WindowExistsException e)
            {
                e.ActivateControl();
            }
        }
Exemplo n.º 35
0
 private void onlineadd(object sender, agsXMPP.protocol.client.Presence pres)
 {
     if (pres.Type == PresenceType.available)
     {
         try
         {
             if (!Userslist.Items.Contains(pres.From.User))
             {
                 Userslist.Items.Add(pres.From.User);
             }
             if (NotifyOnline)
             {
                 Message(owner, pres.From.User + "@nimbuzz.com is online now");
             }
         }
         catch { }
     }
     else if (pres.Type == PresenceType.unavailable)
     {
         if (Userslist.Items.Contains(pres.From.User))
         {
             try
             {
                 Userslist.Items.Remove(pres.From.User);
             }
             catch { }
         }
         if (NotifyOnline)
         {
             Message(owner, pres.From.User + "@nimbuzz.com is offline now");
         }
     }
     else if (pres.Type == PresenceType.unsubscribed)
     {
         if (Userslist.Items.Contains(pres.From.User))
         {
             try
             {
                 Userslist.Items.Remove(pres.From.User);
             }
             catch { }
         }
         if (NotifyOnline)
         {
             Message(owner, pres.From.User + "@nimbuzz.com deleted you from his contacts.");
         }
     }
 }
Exemplo n.º 36
0
        private void OnPresence(object sender, Presence pres)
        {
            var from = XmppIdConverter.Convert(pres.From);

            _listener.ChangedState(from, pres.ParseState());

            if (!string.IsNullOrEmpty(pres.From.Resource))
            {
                _listener.UpdatedImName(from, pres.From.Resource);
            }

            if (pres.Type == PresenceType.subscribe)
            {
                _listener.RequestsAuthorization(from);
            }
        }
Exemplo n.º 37
0
        void XmppConnection_OnPresence(object sender, Presence pres)
        {
            if (pres.To.Bare != RoomJid)
                return;

            Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
            {
                var tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd)
                {
                    Text = pres.From.Resource + " joined the room." + Environment.NewLine
                };
                tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Yellow);

                ChatText.ScrollToEnd();
            }));
        }
Exemplo n.º 38
0
    public void UpdatePresence(Presence p) {
      IsOffline = p.Status == null;
      if (!IsOffline) {
        Status = new LeagueStatus(p.Status, p.Show);
        if (Status.GameStatus == ChatStatus.inGame) {
          RiotServices.GameService.RetrieveInProgressSpectatorGameInfo(User.Name).ContinueWith(GotGameDTO);
          if (Cache != null)
            CurrentGameFetcher.FetchGame(Cache.Data.Summoner.SummonerId, GotGameInfo);
        } else {
          CurrentGameDTO = null;
          CurrentGameInfo = null;
        }

        Session.Current.SummonerCache.GetData(User.Name, GotSummoner);
        Session.Current.ChatManager.ForceUpdate();
      }
    }
Exemplo n.º 39
0
 void objXmpp_OnPresence(object sender, agsXMPP.protocol.client.Presence pres)
 {
     if (pres.Type == PresenceType.available)
     {
         UserStatus(pres);
     }
     else if (pres.Type == PresenceType.unavailable)
     {
         UserStatus(pres);
     }
     else if (pres.Type == PresenceType.subscribe)//自动处理加好友请求
     {
         PresenceManager PM = new PresenceManager(objXmpp);
         PM.ApproveSubscriptionRequest(new Jid(pres.From.ToString()));//同意订阅
         PM.Subscribe(new Jid(pres.From.ToString()));
     }
 }
Exemplo n.º 40
0
    private void ChatManager_PresenceRecieved(object sender, Presence e) {
      if (e.Status == null && e.Type == PresenceType.available) {
        Session.Current.ChatManager.SendPresence();
        return;
      } else if (!e.From.User.Equals(chatID.User)) return;

      var user = e.MucUser.Item;
      if (e.Type == PresenceType.available) {
        if (!Users.ContainsKey(user.Jid.User)) {
          OnChatStatus(e.From.Resource, true);
          Users.Add(user.Jid.User, user);
        }
      } else {
        if (Users.ContainsKey(user.Jid.User))
          OnChatStatus(e.From.Resource, false);
        Users.Remove(user.Jid.User);
      }
    }
Exemplo n.º 41
0
        static void HipchatClient_OnPresence(object sender, agsXMPP.protocol.client.Presence pres)
        {
            HipchatRoom room = Rooms.FirstOrDefault(rm => rm.RoomId.Bare.StartsWith(pres.From.Bare, StringComparison.CurrentCultureIgnoreCase));

            if (room == null)
            {
                return;
            }

            if (!room.Users.Contains(pres.From.Resource))
            {
                room.Users.Add(pres.From.Resource);
            }

            Window.SetUsers(room.Users.ToArray(), room.Name);

            // Lobby.Dispatcher.Invoke(new Action(() => Lobby.lstRooms.Items.Add(pres.ToString())));
        }
Exemplo n.º 42
0
        private static int GetPointsOfPresence(Presence presence)
        {
            if (presence == null || presence.Type == PresenceType.unavailable)
            {
                return 0;
            }

            if (presence.Type == PresenceType.invisible)
            {
                return 1;
            }

            if (presence.Type == PresenceType.available)
            {
                return 2;
            }

            return 0;
        }
Exemplo n.º 43
0
 private void onlineadd(object sender, agsXMPP.protocol.client.Presence pres)
 {
     try
     {
         if (pres.Type == PresenceType.available)
         {
             if (listBox1.Items.Contains(pres.From.Bare))
             {
             }
             else
             {
                 listBox1.Items.Add(pres.From.Bare);
             }
         }
         else
         {
             listBox1.Items.Remove(pres.From.Bare);
         }
         if (pres.Type == PresenceType.unsubscribed || pres.Type == PresenceType.unsubscribe || pres.Type == PresenceType.unavailable)
         {
             listBox1.Items.Remove(pres.From.Bare);
             listBox2.Items.Remove(pres.From.Bare);
         }
         if (pres.Type == PresenceType.subscribe || pres.Type == PresenceType.subscribed)
         {
             if (!listBox2.Items.Contains(pres.From.Bare))
             {
                 listBox2.Items.Add(pres.From.Bare);
             }
             else
             {
             }
         }
     }
     catch { }
 }
Exemplo n.º 44
0
 private void RebuildXmpp()
 {
     if(Xmpp != null)
     {
         Xmpp.OnXmppConnectionStateChanged -= XmppOnOnXmppConnectionStateChanged;
         Xmpp.Close();
         Xmpp = null;
     }
     DisconnectedBecauseConnectionReplaced = false;
     Xmpp = new XmppClientConnection(Host);
     Xmpp.OnRegistered += XmppOnOnRegistered;
     Xmpp.OnRegisterError += XmppOnOnRegisterError;
     Xmpp.OnXmppConnectionStateChanged += XmppOnOnXmppConnectionStateChanged;
     Xmpp.OnLogin += XmppOnOnLogin;
     Xmpp.OnAuthError += XmppOnOnAuthError;
     Xmpp.OnRosterItem += XmppOnOnRosterItem;
     Xmpp.OnRosterEnd += XmppOnOnRosterEnd;
     Xmpp.OnRosterStart += XmppOnOnRosterStart;
     Xmpp.OnMessage += XmppOnOnMessage;
     Xmpp.OnPresence += XmppOnOnPresence;
     Xmpp.OnAgentItem += XmppOnOnAgentItem;
     Xmpp.OnIq += XmppOnOnIq;
     Xmpp.OnReadXml += XmppOnOnReadXml;
     Xmpp.OnClose += XmppOnOnClose;
     Xmpp.OnWriteXml += XmppOnOnWriteXml;
     Xmpp.OnError += XmppOnOnError;
     Xmpp.OnSocketError += XmppOnOnSocketError;
     Xmpp.OnStreamError += XmppOnOnStreamError;
     Notifications = new List<Notification>();
     Friends = new List<NewUser>();
     //GroupChats = new List<NewUser>();
     myPresence = new Presence();
     Chatting = new Chat(this, Xmpp);
     CurrentHostedGamePort = -1;
     _games = new List<HostedGameData>();
     agsXMPP.Factory.ElementFactory.AddElementType("gameitem", "octgn:gameitem", typeof(HostedGameData));
 }
Exemplo n.º 45
0
 public void SetStatus(UserStatus status)
 {
     Presence p;
     switch (status)
     {
         case UserStatus.Online:
             p = new Presence(ShowType.NONE, Xmpp.Status);
             p.Type = PresenceType.available;
             Xmpp.Send(p);
             break;
         case UserStatus.Away:
             p = new Presence(ShowType.away, Xmpp.Status);
             p.Type = PresenceType.available;
             Xmpp.Send(p);
             break;
         case UserStatus.DoNotDisturb:
             p = new Presence(ShowType.dnd, Xmpp.Status);
             p.Type = PresenceType.available;
             Xmpp.Send(p);
             break;
         case UserStatus.Invisible:                    
             p = new Presence(ShowType.NONE, Xmpp.Status);
             p.Type = PresenceType.invisible;
             Xmpp.Send(p);
             break;
     }
     Me.SetStatus(status);
 }
Exemplo n.º 46
0
 private void XmppOnOnPresence(object sender, Presence pres)
 {
     if (pres.From.User == Xmpp.MyJID.User)
     {
         myPresence = pres;
         myPresence.Type = PresenceType.available;
         Xmpp.Status = myPresence.Status ?? Xmpp.Status;
         if(OnDataRecieved != null)
             OnDataRecieved.Invoke(this,DataRecType.MyInfo, pres);
         return;
     }
     switch(pres.Type)
     {
         case PresenceType.available:
             if (pres.From.Server == "conference." + Host)
             {
                 var rm = Chatting.GetRoom(new NewUser(pres.From), true);
                 rm.AddUser(new NewUser(pres.MucUser.Item.Jid),false);
             }
         break;
         case PresenceType.unavailable:
         {
             if (pres.From.Server == "conference." + Host)
             {
                 if (pres.MucUser.Item.Jid == null) break;
                 if (pres.MucUser.Item.Jid.Bare == Me.User.Bare) break;
                 var rm = Chatting.GetRoom(new NewUser(pres.From),true);
                 rm.UserLeft(new NewUser(pres.MucUser.Item.Jid));
             }
             break;
         }
         case PresenceType.subscribe:
             if (!Friends.Contains(new NewUser(pres.From.Bare)))
             {
                 Notifications.Add(new FriendRequestNotification(pres.From.Bare , this , _noteId));
                 _noteId++;
                 if(OnFriendRequest != null) OnFriendRequest.Invoke(this , pres.From.Bare);
             }
             else
                 AcceptFriendship(pres.From.Bare);
             break;
         case PresenceType.subscribed:
             break;
         case PresenceType.unsubscribe:
             break;
         case PresenceType.unsubscribed:
             break;
         case PresenceType.error:
             break;
         case PresenceType.probe:
             break;
     }
     for(int i=0;i<Friends.Count;i++)
     {
         if(Friends[i].User.User == pres.From.User)
         {
             Friends[i].CustomStatus = pres.Status ?? "";
             Friends[i].SetStatus(pres);
             break;
         }
     }
     XmppOnOnRosterEnd(this);
 }
Exemplo n.º 47
0
        private void ConnectiOnPresence(object sender, agsXMPP.protocol.client.Presence agsPresence)
        {
            Contact contact;
            var     from      = agsPresence.From;
            var     contactId = GetContactId(from);
            var     flag      = _roster.TryGetValue(contactId, out contact);
            var     type      = agsPresence.Type;

            if ((int)type != -1)
            {
                switch ((int)type)
                {
                case 4:
                {
                    break;
                }

                case 5:
                {
                    return;
                }

                case 6:
                {
                    OnError(agsPresence.From, agsPresence.Error);
                    return;
                }

                default:
                {
                    return;
                }
                }
            }
            if (!flag && (agsPresence.MucUser == null || !IsConferenceServer(agsPresence.From.Server)))
            {
                return;
            }
            contact = contact ?? ConstructUnknownContact(@from);
            var internalPresences = contact.InternalPresences;

            if ((int)agsPresence.Type != -1)
            {
                Sightstone.Chat.Presence presence;
                internalPresences.TryRemove(agsPresence.From, out presence);
            }
            else
            {
                var orAdd = internalPresences.GetOrAdd(agsPresence.From, new Sightstone.Chat.Presence());
                orAdd.Resource     = agsPresence.From.Resource;
                orAdd.PresenceType = GetPresenceType(agsPresence.Show);
                orAdd.RawStatus    = agsPresence.Status;
                orAdd.ParseState();
            }
            if (!flag)
            {
                OnPresenceChanged(contact);
                return;
            }
            OnContactChanged(contact, ContactChangeType.Update);
        }
Exemplo n.º 48
0
    static void xmpp_OnPresence(object sender, Presence pres)
    {
        //Console.WriteLine("Available Contacts: ");
        //Console.WriteLine( pres.From.User+ " : " + pres.From.Server + " : "  + pres.Type);

        int count = 0;
        //check to see if we just update the pres
        while (contacts.Count != 0 &&  count < contacts.Count )
        {
            if(contacts.ElementAt(count).userID == pres.From.User)
            {
                contacts.ElementAt(count).status = pres.Type.ToString();
                return;
            }
            count++;
        }

        count = 0;
        //if now, we add to the list
        contact info = new contact();
        info.userID = pres.From.User;
        info.status = pres.Type.ToString();
        contacts.Add(info);
    }