Ejemplo n.º 1
0
        public override void Connect(FrontendManager fm, ServerModel server)
        {
            Trace.Call(fm, server);

            if (fm == null)
            {
                throw new ArgumentNullException("fm");
            }
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            _FrontendManager = fm;
            Host             = server.Hostname;
            Port             = server.Port;

            // TODO: use config for single network chat or once per network manager
            _NetworkChat = Session.CreateChat <ProtocolChatModel>(
                NetworkID, "Jabber " + Host, this
                );
            Session.AddChat(_NetworkChat);
            Session.SyncChat(_NetworkChat);

            ApplyConfig(Session.UserConfig, server);

            _JabberClient.Connect();
        }
Ejemplo n.º 2
0
        private static void Jnet()
        {
            using (var j = new JabberClient())
            {
                // what user/pass to log in as
                j.User         = username;
                j.Server       = hostname; // use gmail.com for GoogleTalk
                j.Password     = password;
                j.AutoStartTLS = true;
                j.RequiresSASL = true;
                j.SSL          = true;

                // don't do extra stuff, please.
                j.AutoPresence  = false;
                j.AutoRoster    = false;
                j.AutoReconnect = -1;

                // listen for errors.  Always do this!
                j.OnError += j_OnError;

                // what to do when login completes
                j.OnAuthenticate += j_OnAuthenticate;

                // listen for XMPP wire protocol
                if (VERBOSE)
                {
                    j.OnReadText  += j_OnReadText;
                    j.OnWriteText += j_OnWriteText;
                    j.OnMessage   += j_OnMessage;
                    j.OnProtocol  += J_OnProtocol;
                }

                j.Resource     = "myComp";
                j.UseAnonymous = false;

                // Set everything in motion
                j.Connect();

                while (true)
                {
                    System.Console.Write("> ");
                    string s = System.Console.ReadLine();
                    if (!string.Equals("quit", s))
                    {
                        /*Match m = Regex.Match(s, @"^send\s(?<jid>[^\s]+)\s(?<message>.+)$");
                         * if (!m.Success)
                         *  continue;
                         * string recipient = m.Groups["jid"].Value, message = m.Groups["message"].Value;
                         * // Send the chat-message.*/

                        j.Message(TARGET, s);
                    }

                    if (s == "quit")
                    {
                        return;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        static string serverKey = ""; //replace with your server key
        //static string testDeviceId =
        static void Main(string[] args)
        {
            JabberClient jabberClient1 = new JabberClient();

            jabberClient1.Server      = "gcm.googleapis.com";
            jabberClient1.NetworkHost = "fcm-xmpp.googleapis.com";
            jabberClient1.Port        = 5236;

            jabberClient1.SSL = true;
            //xmppClient.OldStyleSsl = true;

            jabberClient1.User     = senderId;  // your sender id
            jabberClient1.Password = serverKey; // your server key

            jabberClient1.AutoRoster   = false;
            jabberClient1.AutoPresence = false;

            jabberClient1.OnMessage    += new MessageHandler(jabberClient1_OnMessage);
            jabberClient1.OnDisconnect += new bedrock.ObjectHandler(jabberClient1_OnDisconnect);
            jabberClient1.OnError      += new bedrock.ExceptionHandler(jabberClient1_OnError);
            jabberClient1.OnAuthError  += new jabber.protocol.ProtocolHandler(jabberClient1_OnAuthError);
            jabberClient1.OnReadText   += new bedrock.TextHandler(jc_OnReadText);
            jabberClient1.OnWriteText  += new bedrock.TextHandler(jc_OnWriteText);

            jabberClient1.Connect();

            Console.WriteLine("Press return key to exit the application");
            Console.ReadLine();

            jabberClient1.Close();
        }
Ejemplo n.º 4
0
        public void Initialize(string username, string password, int server, ISynchronizeInvoke si)
        {
            c.InvokeControl = si;
            c.User          = username;
            c.Password      = "******" + password;
            c.Port          = 5223;
            c.SSL           = true;
            c.AutoRoster    = true;
            c.AutoLogin     = true;
            c.AutoPresence  = true;

            if (server == 0)
            {
                c.NetworkHost = "chat.na.lol.riotgames.com";
            }
            else if (server == 1)
            {
                c.NetworkHost = "chat.eu.lol.riotgames.com";
            }
            else
            {
                c.NetworkHost = "chat.eun1.lol.riotgames.com";
            }
            c.Server = "pvp.net";
            k.Stream = c;

            users.Clear();
            theUsers.Clear();

            c.Connect();
        }
Ejemplo n.º 5
0
        private void button1_Click(object sender, EventArgs e)
        {
            client             = new jabber.client.JabberClient();
            client.Password    = txtPassword.Text.Trim();
            client.User        = txtUsername.Text.Trim();
            client.Server      = txtServer.Text.Trim();
            client.OnReadText += (ss, ee) => {
                var ll = "";
            };
            client.OnMessage += (ss, ee) =>
            {
                _sync.Send(x => {
                    var txt = $"Pesan dari <{ee.From}> {ee.Body}\n";
                    rtf.AppendText(txt);
                }, null);
            };


            client.Connect();
            client.Login();
            //client.SetStatus(new Status(Availability.Online, "kiosgamer",priority: 127));
            var txt2 = $"Terkoneksi ke <{client.JID}>\n";

            rtf.AppendText(txt2);

            btnConnect.Enabled    = false;
            btnDisconnect.Enabled = true;
        }
Ejemplo n.º 6
0
Archivo: Bot.cs Proyecto: mbsky/bugx
        /// <summary>
        /// Initializes a module and prepares it to handle requests.
        /// </summary>
        /// <param name="context">An <see cref="T:System.Web.HttpApplication"></see> that provides access to the methods, properties, and events common to all application objects within an ASP.NET application</param>
        public void Init(HttpApplication context)
        {
            if (ErrorModule.IsReBug || _Initialized)
            {//Disable bot when it's a ReBug or if module is already initialized
                return;
            }
            _Initialized = true;
            SubscriptionCollection.LoadSettings();
            _Bot = new JabberClient();
            _Bot.AutoReconnect   = 0;
            _Bot.AutoPresence    = false;
            _Bot.OnMessage      += new MessageHandler(Bot_OnMessage);
            _Bot.OnAuthenticate += new bedrock.ObjectHandler(Bot_OnAuthenticate);
            _Bot.OnPresence     += new PresenceHandler(_Bot_OnPresence);

            AsyncSocket.UntrustedRootOK    = true;
            ErrorModule.ErrorComplete     += new EventHandler <BugEventArgs>(ErrorModule_ErrorComplete);
            ErrorModule.ApplicationUnload += new EventHandler <ApplicationUnloadEventArgs>(ErrorModule_ApplicationUnload);

            SubscriptionCollection settings = SubscriptionCollection.Instance;

            _Bot.User         = settings.User;
            _Bot.Password     = settings.Password;
            _Bot.Server       = settings.Server;
            _Bot.NetworkHost  = settings.NetworkHost;
            _Bot.Resource     = "Bugx Talk (bot)";
            _Bot.AutoStartTLS = true;

            _Bot.Connect();
        }
Ejemplo n.º 7
0
        public void Connect()
        {
            ManualResetEvent authenticatedEvent = new ManualResetEvent(false);

            _jc.OnAuthenticate += new bedrock.ObjectHandler(sender =>
            {
                authenticatedEvent.Set();
            });

            _jc.Connect();

            authenticatedEvent.WaitOne();
        }
Ejemplo n.º 8
0
        public void Connect(string user, string password)
        {
            Disconnect();
            _jc = new JabberClient();

            _jc.AutoReconnect = _reconnect;
            _user             = new JID(user + "@" + _serverName);
            _jc.User          = _user.User;
            _jc.Server        = _user.Server;
            _jc.NetworkHost   = _networkHost;
            _jc.Port          = _port;
            _jc.Resource      = _resource;
            _jc.Password      = password;
            _jc.AutoStartTLS  = _TLS;
            _jc.AutoPresence  = _initialPresence;
            _jc.AutoRoster    = _autoRoster;
            _jc.AutoLogin     = _loging;

            if (!string.IsNullOrEmpty(_certificateFile))
            {
                _jc.SetCertificateFile(_certificateFile, _certificatePass);
                Console.WriteLine(_jc.LocalCertificate.ToString(true));
            }

            if (!string.IsNullOrEmpty(_boshURL))
            {
                _jc[Options.POLL_URL]        = _boshURL;
                _jc[Options.CONNECTION_TYPE] = ConnectionType.HTTP_Binding;
            }

            if (_register)
            {
                _jc.AutoLogin = false;
                _register     = false;
            }

            _conference        = new ConferenceManager();
            _conference.Stream = _jc;

            _roster               = new RosterManager();
            _roster.AutoAllow     = jabber.client.AutoSubscriptionHanding.AllowIfSubscribed;
            _roster.AutoSubscribe = true;
            _roster.Stream        = _jc;

            _disco        = new DiscoManager();
            _disco.Stream = _jc;

            Subscribe();

            _jc.Connect();
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            if (DEBUG)
            {
                Console.Title = "[DEBUG] " + BOTNAME + " by Entropy";
            }
            else
            {
                Console.Title = BOTNAME + " by Entropy";
            }
            bool   firstrun = true;
            string hostname = "xmpp.livecoding.tv";
            JID    jid      = new JID(username + "@livecoding.tv");

            client              = new JabberClient();
            client.User         = jid.User;
            client.Password     = password;
            client.Server       = jid.Server;
            client.NetworkHost  = hostname;
            client.Resource     = BOTNAME;
            client.AutoPresence = true;
            client.Connect();
            client.Login();
            client.OnConnect      += Client_OnConnect;
            client.OnAuthenticate += Client_OnAuthenticate;
            while (true)
            {
                if (firstrun)
                {
                    Thread.Sleep(5000);
                    firstrun = false;
                }
                else
                {
                    Thread.Sleep(500);
                }
                if (messages.Count > 0)
                {
                    Message latestMsg = messages[messages.Count - 1];
                    if (latestMsg.ID != lastId)
                    {
                        processMessage(latestMsg);
                        if (DEBUG)
                        {
                            Console.WriteLine("{message: \"" + latestMsg.Body + "\", ID: " + latestMsg.ID + "}");
                        }
                    }
                    lastId = latestMsg.ID;
                }
            }
        }
Ejemplo n.º 10
0
        private void JoinAuction(JabberClient inConnection, string inItemId)
        {
            mAuction = new XMPPAuction(
                new Chat(this.ToJid(inItemId, inConnection), inConnection), new SniperStateDisplayer()
                );

            if (this.BeginJoining != null)
            {
                this.BeginJoining(inConnection);
            }

            inConnection.Connect();
            ConsoleAppHelper.WaitConnectingTo(inConnection);

            mAuction.Join();
        }
Ejemplo n.º 11
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            JabberClient jc = new JabberClient();

            jc.OnAuthenticate += new bedrock.ObjectHandler(jc_OnAuthenticate);
            jc.OnAuthError    += new jabber.protocol.ProtocolHandler(jc_OnAuthError);

            jc.User       = "******";
            jc.Password   = "******";
            jc.Port       = 4502;
            jc.Server     = "142.222.45.108";
            jc.Connection = ConnectionType.Socket;

            jc.Connect();
            jc.Presence(jabber.protocol.client.PresenceType.available, "Test", "Test", 0);
        }
Ejemplo n.º 12
0
        public void Connect(string server, int port, string user, string password, float autoreconnect)
        {
            JabberClient jc = new JabberClient();

            jc.User     = user;
            jc.Server   = server;
            jc.Port     = port;
            jc.Password = password;

            // don't do extra stuff, please.

            jc.AutoPresence  = false;
            jc.AutoRoster    = false;
            jc.AutoReconnect = autoreconnect;

            jc.OnInvalidCertificate += new System.Net.Security.RemoteCertificateValidationCallback(OnInvalidCertificate);

            jc.OnDisconnect += new bedrock.ObjectHandler(OnDisconnect);

            jc.OnConnect += OnConnect;

            // listen for errors.  Always do this!
            jc.OnError += new bedrock.ExceptionHandler(OnError);

            // what to do when login completes
            jc.OnAuthenticate += new bedrock.ObjectHandler(OnAuthenticate);
            //jc.OnAuthError += new ProtocolHandler(OnAuthError);

            //jc.OnConnect += new jabber.connection.StanzaStreamHandler(OnConnect);


            jc.OnReadText  += new bedrock.TextHandler(OnReadText);
            jc.OnWriteText += new bedrock.TextHandler(OnWriteText);

            jc.Connect();


            jabberClient = jc;

            //done.WaitOne();
        }
Ejemplo n.º 13
0
        public void Connect()
        {
            Logger.Info(string.Format("Connecting to '{0}'", _jabberClient.Server));
            _jabberClient.Connect();

            //Continue to retry connecting
            int retryCountLimit = 10;

            while (!_jabberClient.IsAuthenticated && retryCountLimit > 0)
            {
                retryCountLimit--;
                Thread.Sleep(1000);
            }

            //Successfully authenticated
            if (_jabberClient.IsAuthenticated)
            {
                Logger.Info(string.Format("Authenticated as '{0}'", _jabberClient.User));
                _serviceStarted = true;
                _thread.Start();
            }
        }
Ejemplo n.º 14
0
        public Class1(string[] args)
        {
            JabberClient jc = new JabberClient();

            jc.OnReadText    += new bedrock.TextHandler(jc_OnReadText);
            jc.OnWriteText   += new bedrock.TextHandler(jc_OnWriteText);
            jc.OnError       += new bedrock.ExceptionHandler(jc_OnError);
            jc.OnStreamError += new jabber.protocol.ProtocolHandler(jc_OnStreamError);

            jc.AutoReconnect = 3f;

            GetOpt go = new GetOpt(this);

            try
            {
                go.Process(args);
            }
            catch (ArgumentException)
            {
                go.UsageExit();
            }

            if (untrustedOK)
            {
                jc.OnInvalidCertificate += new System.Net.Security.RemoteCertificateValidationCallback(jc_OnInvalidCertificate);
            }

            JID j = new JID(jid);

            jc.User         = j.User;
            jc.Server       = j.Server;
            jc.NetworkHost  = networkHost;
            jc.Port         = port;
            jc.Resource     = "Jabber.Net Console Client";
            jc.Password     = pass;
            jc.AutoStartTLS = TLS;
            jc.AutoPresence = initialPresence;

            if (certificateFile != null)
            {
                jc.SetCertificateFile(certificateFile, certificatePass);
                Console.WriteLine(jc.LocalCertificate.ToString(true));
            }

            if (boshURL != null)
            {
                jc[Options.POLL_URL]        = boshURL;
                jc[Options.CONNECTION_TYPE] = ConnectionType.HTTP_Binding;
            }

            if (register)
            {
                jc.AutoLogin        = false;
                jc.OnLoginRequired +=
                    new bedrock.ObjectHandler(jc_OnLoginRequired);
                jc.OnRegisterInfo += new RegisterInfoHandler(this.jc_OnRegisterInfo);
                jc.OnRegistered   += new IQHandler(jc_OnRegistered);
            }

            CapsManager cm = new CapsManager();

            cm.Stream = jc;
            cm.Node   = "http://cursive.net/clients/ConsoleClient";

            Console.WriteLine("Connecting");
            jc.Connect();
            Console.WriteLine("Connected");

            string line;

            while ((line = Console.ReadLine()) != null)
            {
                if (line == "/clear")
                {
                    // Hm.... I wonder if this works on windows.
                    Console.Write("\x1b[H\x1b[2J");
                    continue;
                }
                if ((line == "/q") || (line == "/quit"))
                {
                    jc.Close();
                    break;
                }
                if (line.Trim() == "")
                {
                    continue;
                }
                try
                {
                    if (line == "</stream:stream>")
                    {
                        jc.Write(line);
                    }
                    else
                    {
                        // TODO: deal with stanzas that span lines... keep
                        // parsing until we have a full "doc".
                        XmlDocument doc = new XmlDocument();
                        doc.LoadXml(line);
                        XmlElement elem = doc.DocumentElement;
                        if (elem != null)
                        {
                            jc.Write(elem);
                        }
                    }
                }
                catch (XmlException ex)
                {
                    Console.WriteLine("Invalid XML: " + ex.Message);
                }
            }
        }
Ejemplo n.º 15
0
        public void Connect()
        {
            if (String.IsNullOrEmpty(m_Info.Password))
            {
                throw new Exception("No password");
            }

            if (ConnectionState != AccountConnectionState.Disconnected)
            {
                throw new InvalidOperationException("Already connected");
            }

            m_UserPresenceCache.Clear();

            m_NetworkDisconnected = false;

            // Store this, server might assign us something else.
            m_RequestedResource = m_Info.Resource;

            m_Client.User        = m_Info.User;
            m_Client.Server      = m_Info.Domain;
            m_Client.Resource    = m_Info.Resource;
            m_Client.NetworkHost = m_Info.ConnectServer;
            m_Client.Port        = m_Info.ConnectPort;
            m_Client.Password    = m_Info.Password;

            if (m_Info.ProxyType == Synapse.Xmpp.Services.ProxyType.System)
            {
                // FIXME: Figure out what's wrong with libproxy
                m_Client.Proxy = jabber.connection.ProxyType.None;

                /*
                 * try {
                 *      var factory = new libproxy.ProxyFactory();
                 *      // FIXME: This isn't good enough because m_Info.Domain might have an SRV record.
                 *      string server = !String.IsNullOrEmpty(m_Info.ConnectServer) ? m_Info.ConnectServer : m_Info.Domain;
                 *      var proxies = factory.GetProxy(String.Format("xmpp://{0}", server));
                 *      if (proxies.Length > 0) {
                 *              var proxy = new System.Uri(proxies[0]);
                 *              if (proxy.Scheme == "direct") {
                 *                      m_Client.Proxy = jabber.connection.ProxyType.None;
                 *              } else {
                 *                      // FIXME: Use the detected proxy!
                 *                      Console.WriteLine("Auto-detected proxy: " + proxy);
                 *              }
                 *      } else {
                 *              m_Client.Proxy = jabber.connection.ProxyType.None;
                 *      }
                 * } catch (Exception ex) {
                 *      // FIXME: Show error window?
                 *      Console.Error.WriteLine("Proxy autodetection failed: " + ex);
                 *      m_Client.Proxy = jabber.connection.ProxyType.None;
                 * }*/
            }
            else
            {
                m_Client.ProxyHost     = m_Info.ProxyHost;
                m_Client.ProxyPort     = m_Info.ProxyPort;
                m_Client.ProxyUsername = m_Info.ProxyUsername;
                m_Client.ProxyPassword = m_Info.ProxyPassword;
                switch (m_Info.ProxyType)
                {
                case Synapse.Xmpp.Services.ProxyType.None:
                    m_Client.Proxy = jabber.connection.ProxyType.None;
                    break;

                case Synapse.Xmpp.Services.ProxyType.HTTP:
                    m_Client.Proxy = jabber.connection.ProxyType.HTTP;
                    break;

                case Synapse.Xmpp.Services.ProxyType.SOCKS4:
                    m_Client.Proxy = jabber.connection.ProxyType.Socks4;
                    break;

                case Synapse.Xmpp.Services.ProxyType.SOCKS5:
                    m_Client.Proxy = jabber.connection.ProxyType.Socks5;
                    break;
                }
            }

            // FIXME: Calling this in a separate thread so DNS doesn't block the UI.
            // This should be fixed inside jabber-net.
            ThreadPool.QueueUserWorkItem(delegate {
                // Check that connection state hasn't changed by the time this executes.
                // Might need to lock on something to avoid race condition...
                if (ConnectionState == AccountConnectionState.Disconnected)
                {
                    ConnectionState = AccountConnectionState.Connecting;
                    m_Client.Connect();
                }
            });
        }
Ejemplo n.º 16
0
 private void Callback(object sender, EventArgs e)
 {
     _jabberClient.Connect();
 }
Ejemplo n.º 17
0
 /// <summary>Connect to the Xmpp Server.</summary>
 public void Connect()
 {
     _jc.Connect();
 }