Exemple #1
0
 /// <summary>
 /// Se produit lorsque le flux XMPP est disponible
 /// </summary>
 /// <param name="sender">Objet parent</param>
 private void xmppOnLogin(object sender)
 {
     Jabber.xmpp.DiscoInfo = Queries.getDiscoInfo();
     xmppDiscoServer();
     _queries   = new Queries();
     _privacy   = new Privacy();
     _bookmarks = new Bookmarks();
     _identity  = new Identity(xmpp.MyJID);
     _identity.retrieve();
     _roster   = new Roster();
     _presence = new Presence();
     OnConnected();
     xmpp.RequestRoster();
 }
Exemple #2
0
        private void OnMessage(object sender, agsXMPP.protocol.client.Message NewMessage)
        {
            if (NewMessage.Type == MessageType.error || NewMessage.Type == null)
            {
                return;
            }
            else
            {
                Thread thre = new Thread(() =>
                {
                    try
                    {
                        string[] mc = Messages.Lines;
                        if (NewMessage.Type == MessageType.chat)
                        {
                            if (NewMessage.Body.Trim() != string.Empty)
                            {
                                if (NewMessage.From.User.ToLower().Trim() != owner.ToLower().Trim())
                                {
                                    x.Send(new agsXMPP.protocol.client.Message(new agsXMPP.Jid(owner + "@nimbuzz.com"), agsXMPP.protocol.client.MessageType.chat, mc[35].Replace("[MESSAGE]$", "").Replace("%L%", Environment.NewLine).Replace("%from%", NewMessage.From.User).Replace("%msg%", NewMessage.Body).Replace("%to%", NewMessage.From.User).Replace("%masters%", owner).Replace("%time%", DateTime.Now.ToString())));
                                }
                                if (NewMessage.From.User.ToLower().Trim() == owner.ToLower().Trim() && Selftesting)
                                {
                                    x.Send(new agsXMPP.protocol.client.Message(new agsXMPP.Jid(owner + "@nimbuzz.com"), agsXMPP.protocol.client.MessageType.chat, mc[35].Replace("[MESSAGE]$", "").Replace("%L%", Environment.NewLine).Replace("%from%", NewMessage.From.User).Replace("%msg%", NewMessage.Body).Replace("%to%", NewMessage.From.User).Replace("%masters%", owner).Replace("%time%", DateTime.Now.ToString())));
                                }
                            }
                            if (NewMessage.From.User == owner)
                            {
                                //stop
                                if (NewMessage.Body.ToLower().StartsWith("#logout"))
                                {
                                    reconnectable = false;
                                    x.Send(new agsXMPP.protocol.client.Message(new agsXMPP.Jid(NewMessage.From.User + "@nimbuzz.com"), agsXMPP.protocol.client.MessageType.chat, mc[27].Replace("[MESSAGE]$", "")));
                                    x.Close();
                                }
                                if (NewMessage.Body.Trim().ToLower().StartsWith("add#"))
                                {
                                    PresenceManager presx = new PresenceManager(x);
                                    string[] sp           = NewMessage.Body.Split('#');
                                    try
                                    {
                                        if (sp[1].Trim() != string.Empty)
                                        {
                                            Jid jid = new Jid(sp[1] + "@nimbuzz.com");
                                            x.RosterManager.AddRosterItem(jid);
                                            presx.Subscribe(jid);
                                            Message(owner, "Friend request was sent to '" + jid + "' and you will be notified he/she acceptes.");
                                        }
                                        else
                                        {
                                            Message(owner, "Command syntax error!");
                                        }
                                    }
                                    catch
                                    {
                                        Message(owner, "Command syntax error!");
                                    }
                                }
                                if (NewMessage.Body.Trim().ToLower().StartsWith("del#"))
                                {
                                    PresenceManager presx = new PresenceManager(x);
                                    string[] sp           = NewMessage.Body.Split('#');
                                    try
                                    {
                                        if (sp[1].Trim() != string.Empty)
                                        {
                                            Jid jid = new Jid(sp[1] + "@nimbuzz.com");
                                            x.RosterManager.RemoveRosterItem(jid);
                                            presx.Unsubscribe(jid);
                                            Message(owner, "'" + jid + "' is deleted.");
                                            Userslist.Items.Remove(jid);
                                            x.RequestRoster();
                                        }
                                        else
                                        {
                                            Message(owner, "Command syntax error!");
                                        }
                                    }
                                    catch
                                    {
                                        Message(owner, "Command syntax error!");
                                    }
                                }
                                //reply
                                if (NewMessage.Body.ToLower().StartsWith("chat/"))
                                {
                                    if (NewMessage.From.User == owner)
                                    {
                                        string[] sp = NewMessage.Body.Split('/');
                                        try
                                        {
                                            x.Send(new agsXMPP.protocol.client.Message(new agsXMPP.Jid(sp[1] + "@nimbuzz.com"), agsXMPP.protocol.client.MessageType.chat, sp[2]));
                                            x.Send(new agsXMPP.protocol.client.Message(new agsXMPP.Jid(NewMessage.From.User + "@nimbuzz.com"), agsXMPP.protocol.client.MessageType.chat, mc[36].Replace("[MESSAGE]$", "").Replace("%to%", sp[1]).Replace("%L%", Environment.NewLine)));
                                        }
                                        catch { Message(NewMessage.From.User, "Command syntax error!"); }
                                    }
                                    else
                                    {
                                        x.Send(new agsXMPP.protocol.client.Message(new agsXMPP.Jid(owner + "@nimbuzz.com"), agsXMPP.protocol.client.MessageType.chat, NewMessage.Body));
                                    }
                                }
                                //status
                                if (NewMessage.Body.Trim() != string.Empty && NewMessage.From.User.ToLower() == owner.ToLower())
                                {
                                    switch (NewMessage.Body.ToLower().Trim())
                                    {
                                    case "#online":
                                        {
                                            x.Status = sts;
                                            x.SendMyPresence();
                                            x.Send(new agsXMPP.protocol.client.Message(new agsXMPP.Jid(owner + "@nimbuzz.com"), agsXMPP.protocol.client.MessageType.chat, mc[42].Replace("[MESSAGE]$", "").Replace("%from%", NewMessage.From.User).Replace("%msg%", NewMessage.Body).Replace("%L%", Environment.NewLine).Replace("%sts%", "online").Replace("%thisid%", ID)));
                                            break;
                                        }

                                    case "#away":
                                        {
                                            x.Show   = ShowType.away;
                                            x.Status = sts;
                                            x.SendMyPresence();
                                            x.Send(new agsXMPP.protocol.client.Message(new agsXMPP.Jid(owner + "@nimbuzz.com"), agsXMPP.protocol.client.MessageType.chat, mc[42].Replace("[MESSAGE]$", "").Replace("%from%", NewMessage.From.User).Replace("%msg%", NewMessage.Body).Replace("%L%", Environment.NewLine).Replace("%sts%", "away").Replace("%thisid%", ID).Replace("%to%", NewMessage.From.User.Remove(0))));
                                            break;
                                        }

                                    case "#busy":
                                        {
                                            x.Show   = ShowType.dnd;
                                            x.Status = sts;
                                            x.SendMyPresence();
                                            x.Send(new agsXMPP.protocol.client.Message(new agsXMPP.Jid(owner + "@nimbuzz.com"), agsXMPP.protocol.client.MessageType.chat, mc[42].Replace("[MESSAGE]$", "").Replace("%from%", NewMessage.From.User).Replace("%msg%", NewMessage.Body).Replace("%L%", Environment.NewLine).Replace("%sts%", "busy").Replace("%thisid%", ID).Replace("%to%", NewMessage.From.User.Remove(0))));
                                            break;
                                        }

                                    case "+test":
                                        {
                                            Selftesting = true;
                                            Message(owner, "Self Testing is turned on");
                                            break;
                                        }

                                    case "-test":
                                        {
                                            Selftesting = false;
                                            Message(owner, "Self Testing is turned off");
                                            break;
                                        }

                                    case "+autoaccept":
                                        {
                                            AutoAccept = true;
                                            Message(owner, "Auto friend request accept is turned on");
                                            break;
                                        }

                                    case "-autoaccept":
                                        {
                                            AutoAccept = false;
                                            Message(owner, "Auto friend request accept is turned off");
                                            break;
                                        }

                                    case "+notify":
                                        {
                                            NotifyOnline = true;
                                            Message(owner, "Online Notifier is turned on");
                                            break;
                                        }

                                    case "-notify":
                                        {
                                            NotifyOnline = false;
                                            Message(owner, "Online Notifier is turned off");
                                            break;
                                        }

                                    case "#cpanel":
                                        {
                                            Message(owner, Form1.Fhelp.Replace("%master%", owner));
                                            break;
                                        }

                                    case "#users":
                                        {
                                            Message(owner, "\nOnline users list:\n" + Listout());
                                            break;
                                        }

                                    case "#accept":
                                        {
                                            int count = 0;
                                            if (addeduserlist.Text.Trim() != string.Empty)
                                            {
                                                PresenceManager presx = new PresenceManager(x);
                                                foreach (string l in addeduserlist.Lines)
                                                {
                                                    if (l.Trim() != string.Empty)
                                                    {
                                                        try
                                                        {
                                                            Jid jid = new Jid(l + "@nimbuzz.com");
                                                            x.RosterManager.AddRosterItem(jid);
                                                            presx.Subscribe(jid);
                                                            presx.ApproveSubscriptionRequest(jid);
                                                            count++;
                                                            Message(owner, jid + " is accepted");
                                                        }
                                                        catch { }
                                                    }
                                                }
                                                addeduserlist.Clear();
                                            }
                                            else
                                            {
                                                Message(owner, "No friend request sent.");
                                            }
                                            break;
                                        }

                                    default:
                                        {
                                            break;
                                        }
                                    }
                                }
                                if (NewMessage.Body.ToLower().StartsWith("stm#") && NewMessage.From.User == owner)
                                {
                                    string[] sp = NewMessage.Body.Split('#');
                                    x.Status    = sp[1];
                                    sts         = sp[1];
                                    x.SendMyPresence();
                                    x.Send(new agsXMPP.protocol.client.Message(new agsXMPP.Jid(owner + "@nimbuzz.com"), agsXMPP.protocol.client.MessageType.chat, mc[43].Replace("[MESSAGE]$", "").Replace("%from%", NewMessage.From.User).Replace("%msg%", NewMessage.Body).Replace("%L%", Environment.NewLine).Replace("%stm%", sts).Replace("%thisid%", ID).Replace("%to%", NewMessage.From.User)));
                                }
                            }
                        }
                    }
                    catch (Exception v) {  }
                }); thre.IsBackground = true; thre.Start();
            }
        }