Example #1
0
        protected override void InternalStart()
        {
            StopClient();
            _client = new XmppClient(_xmpp.Server, _xmpp.User, _xmpp.Password);

            _client.Message += OnClientMessage;
            _client.Error += OnError;
            _client.Connect();
        }
Example #2
0
        public void startLogin()
        {
            loginBtn.Enabled = false;
            Properties.Settings.Default.srv = serverFQDN.Text;
            Properties.Settings.Default.Save();
            serverName = serverFQDN.Text;
            var client = new XmppClient(serverName, 5222, false);
            try
            {
                client.Error += OnError;

                client.Connect();
            }
            catch (Exception ex)
            {
                msg("Error - Connection", ex.Message);
                //client.Close();
            }
            if (client.Connected == true)
            {
                try
                {
                    client.Authenticate(usernameTxt.Text, passwordTxt.Text);
                }
                catch (System.Security.Authentication.AuthenticationException ex)
                {
                    msg("Error - Authentication", ex.Message);
                    passwordTxt.Text = "";
                }

                if (client.Authenticated == true)
                {
                    usr = usernameTxt.Text;
                    client.Close();
                    Form rosFrm = new roster(usernameTxt.Text, passwordTxt.Text, serverName, useTLSCheck.Checked);
                    rosFrm.Show();
                    this.Hide();
                }
            }
            loginBtn.Enabled = true;
        }
Example #3
0
        static void Main(string[] args)
        {
            using (var client = new XmppClient("jabber.dk", "castoriadis", "georgina"))
            {
                var q = new Queue<string>();
                var ev = new AutoResetEvent(false);
                client.Message += new EventHandler<S22.Xmpp.Im.MessageEventArgs>((o,e) => {
                    lock(q) {
                        q.Enqueue(e.Message.Body);
                    }
                    ev.Set();
                });
                client.Connect();
                var admin = new S22.Xmpp.Jid("*****@*****.**");
                client.SendMessage(admin, "You're granted access to Castoriadis!");

                Console.MainClass._readCommand = () =>
                {
                    ev.WaitOne();
                    lock (q)
                    {
                        return q.Dequeue();
                    }
                };
                Console.MainClass._writeResult = s =>
                {
                    var msg = s == null ? "(null)" : s.ToString();
                    if (string.IsNullOrWhiteSpace(msg))
                    {
                        msg = "(empty string)";
                    }
                    client.SendMessage(admin, msg);
                };
                Console.MainClass.Main(args);
            }
        }
Example #4
0
        public roster(String username, String password, string domain, bool useTLS)
        {
            InitializeComponent();
            try
            {
                serverName = domain;
                friendView.Columns.Add("Avatar", 100);
                friendView.Columns.Add("Username", 100);
                if(useTLS == true)
                {
                    if(client.Connected == true)
                    {
                        client.Close();
                    }
                    client = new XmppClient(serverName, 5222, true, null);
                    client.Error += OnError;
                    client.Message += OnNewMessage;
                    client.RosterUpdated += OnRosterUpdate;
                    client.Connect();

                } else
                {
                    if (client.Connected == true)
                    {
                        client.Close();
                    }
                    client = new XmppClient(serverName, 5222, false, null);
                    client.Error += OnError;
                    client.Message += OnNewMessage;
                    client.RosterUpdated += OnRosterUpdate;
                    client.SubscriptionRequest += OnSubRequest;
                    client.Connect();
                }
                
                
            }
            catch (Exception ex)
            {
                msg("Error - Connection - RosterForm", ex.ToString());
                
            }
            try
            {
                if (client.Connected == true)
                {
                    try
                    {
                        client.Authenticate(username, password);
                    }
                    catch (System.Security.Authentication.AuthenticationException ex)
                    {
                        //This shouldn't happen but just to text...
                        msg("Error - Authentication - RosterForm", ex.ToString());

                    }

                    if (client.Authenticated == true)
                    {
                        //Set Username label to show we are logged in...
                        usernameLabel.Text = username;
                        //Grab roster...
                        foreach(var item in client.GetRoster())
                        {
                            String resID = item.Jid.Resource;
                            String domain2 = item.Jid.Domain;
                            String jid = item.Jid.ToString();
                            if(resID != null) { jid.Replace(resID, ""); jid = jid.Replace("@/", ""); }
                            if (jid.Contains("@")) { jid = jid.Replace("@", ""); }
                            jid = jid.Replace(domain2, "");
                            try
                            {
                                friendView.Items.Add(jid, 0);
                            }
                            catch
                            {
                                //Do Nothing, Move on.
                            }
                            
                        }
                        Status online = new Status(Availability.Online);
                        client.SetStatus(online);
                    }
                }
            }
            catch(Exception ex)
            {
                msg("Error - Auth - RosterForm", ex.ToString());
            }
            if(client.IsEncrypted == true)
            {
                monoFlat_ThemeContainer1.Text = "OpenMessage IM (TLS)";
            }
            friendView.SmallImageList = avatarList;
            friendView.LargeImageList = avatarList;
            
            //Set Avatar...
            avatarList.Images.Add(Properties.Resources.User);
            //friendView.Items.Add(new ListViewItem(usernameLabel.Text + "(You)", 0));
        }