public XmppProtocolManager(Session session) : base(session) { Trace.Call(session); _JabberClient = new JabberClient(); _JabberClient.Resource = Engine.VersionString; _JabberClient.AutoLogin = true; _JabberClient.AutoPresence = false; _JabberClient.OnStreamInit += OnStreamInit; _JabberClient.OnMessage += OnMessage; _JabberClient.OnConnect += OnConnect; _JabberClient.OnDisconnect += OnDisconnect; _JabberClient.OnAuthenticate += OnAuthenticate; _JabberClient.OnError += OnError; _JabberClient.OnProtocol += OnProtocol; _JabberClient.OnWriteText += OnWriteText; _JabberClient.OnIQ += OnIQ; _RosterManager = new RosterManager(); _RosterManager.Stream = _JabberClient; _ConferenceManager = new ConferenceManager(); _ConferenceManager.Stream = _JabberClient; _ConferenceManager.OnJoin += OnJoin; _ConferenceManager.OnLeave += OnLeave; _ConferenceManager.OnParticipantJoin += OnParticipantJoin; _ConferenceManager.OnParticipantLeave += OnParticipantLeave; }
private void InitializeJabberClient() { try { _jabberClient = new JabberClient(); _jabberClient.OnMessage += JabberClientOnMessage; _jabberClient.OnDisconnect += JabberClientOnDisconnect; _jabberClient.OnError += JabberClientOnError; _jabberClient.OnAuthError += JabberClientOnAuthError; _jabberClient.OnPresence += OnPresence; _jabberClient.AutoStartCompression = true; _jabberClient.AutoStartTLS = false; _jabberClient.AutoStartCompression = true; _jabberClient.PlaintextAuth = true; _jabberClient.RequiresSASL = true; _jabberClient.LocalCertificate = null; _jabberClient.AutoPresence = true; _jabberClient.AutoRoster = true; _jabberClient.AutoReconnect = -1f; var manager = new RosterManager { Stream = _jabberClient, AutoSubscribe = true, AutoAllow = AutoSubscriptionHanding.AllowAll }; manager.OnRosterBegin += RosterManagerOnRosterBegin; manager.OnRosterEnd += RosterManagerOnRosterEnd; manager.OnRosterItem += RosterManagerOnRosterItem; _jabberClient.OnAuthenticate += JabberClientOnAuthenticate; } catch (Exception exception) { _log.Error(exception); } }
private void SendMessage() { try { if ((JabberClient != null) && JabberClient.IsAuthenticated) { var elem = new Message(JabberClient.Document); var range = new TextRange(sendTextBox.Document.ContentStart, sendTextBox.Document.ContentEnd); if ((range.Text != @"\n") && (range.Text != " ")) { elem.Body = range.Text.TrimEnd(new[] { '\n', '\r' }); if (elem.Body != "") { elem.To = User.Bare; JabberClient.Write(elem); var text = range.Text.TrimEnd(new[] { '\n', '\r' }); AppendConversation(JabberClient.User, text, JabberClient.JID.Bare); range.Text = ""; } } } } catch (Exception exception) { _log.Error(exception); } }
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; }
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(); }
static void j_OnAuthenticate(object sender) { // Sender is always the JabberClient. JabberClient j = (JabberClient)sender; j.Message(TARGET, "test"); }
private void jc_OnLoginRequired(object sender) { Console.WriteLine("Registering"); JabberClient jc = (JabberClient)sender; jc.Register(new JID(jc.User, jc.Server, null)); }
public static void WaitConnectingTo(JabberClient inClient) { if (inClient.IsAuthenticated) { return; } var locker = new object(); var connected = false; inClient.OnAuthenticate += (s) => { lock (locker) { connected = true; Monitor.PulseAll(locker); } }; while (true) { lock (locker) { Monitor.Wait(locker, TimeSpan.FromMilliseconds(100)); if (connected) { break; } } } }
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; } } } }
private void BotClient_OnPresence(object sender, jabber.protocol.client.Presence pres) { Console.WriteLine("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); Console.WriteLine(pres.ToString()); Console.WriteLine("***********************************"); Console.WriteLine(pres.Type.ToString()); // Available/Unavailable Console.WriteLine(pres.Value); Console.WriteLine(pres.Show); // dnd / away / "" Console.WriteLine("------------------------"); Console.WriteLine(pres.HasAttribute("type") ? pres.GetAttribute("type").ToString() : ""); Console.WriteLine("***********************************"); JabberClient temp = (JabberClient)sender; ApplicationUser usr; string usrname = string.Format("{0}@{1}", pres.From.User.ToString(), pres.From.Server.ToString()); if (this.AppMan.AppUsers.TryGetValue(usrname, out usr)) { PresenceEventArgs presenceArgs = new PresenceEventArgs(usr.UserId, pres.Show, pres.Type.ToString()); usr.Presence = presenceArgs.Presence; usr.OnPresenceEvent(presenceArgs); } else { if (!string.IsNullOrEmpty(this.AppMan.DefaultApplication)) { var app = this.AppMan.Apps[this.AppMan.DefaultApplication]; var method = app.AppType.GetMethod("InitiateConversation"); if (method != null && (bool)method.Invoke(null, new object[] { usrname })) { usr = this.AppMan.AddUser(usrname); usr.SystemReply += new SystemReplyHandler(usr_SystemReply); usr.TriggerApplicationEvent += new TriggerApplicationEventHandler(usr_TriggerApplicationEvent); usr.Tag = pres.From.ToString(); PresenceEventArgs presenceArgs = new PresenceEventArgs(usr.UserId, pres.Show, pres.Type.ToString()); usr.Presence = presenceArgs.Presence; } } } // SHOW VALUE //* nil (Available, no <show/> element) //* :away //* :chat (Free for chat) //* :dnd (Do not disturb) //* :xa (Extended away) //Type Values //* :error //* :probe (Servers send this to request presence information) //* :subscribe (Subscription request) //* :subscribed (Subscription approval) //* :unavailable (User has gone offline) //* :unsubscribe (Unsubscription request) //* :unsubscribed (Unsubscription approval) //* [nil] (available) }
/// <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(); }
private void OnListViewSelectedItemClick(object sender, MouseButtonEventArgs e) { try { var item = (ListViewItem)sender; if (item != null) { var content = (JabberStatus)item.Content; if (content != null) { if (!((JabberClient != null) && JabberClient.IsAuthenticated)) { TryToConnect(); } if ((JabberClient != null) && JabberClient.IsAuthenticated) { JabberClient.Presence(content.PresenceType, content.Name, "HelperChat", 0); } popup.IsOpen = false; } } } catch (Exception exception) { _log.Error(exception); } }
public void Setup() { mocks = new MockRepository(); stream = mocks.DynamicMock <JabberClient>(); doc = new XmlDocument(); }
private JID ToJid(string inItemId, JabberClient inConnection) { return(new JID( string.Format(ItemIdAsLogin, inItemId), inConnection.Server, inConnection.Resource )); }
public ArchiveUsersList(JabberClient jabberClient) { _jabberClient = jabberClient; InitializeComponent(); _users = new ObservableCollection<ChatUser>(); _filterUsers = new ObservableCollection<ChatUser>(); usersListView.ItemsSource = _filterUsers; _viewChatUsers = new ObservableCollection<ViewChatUser>(); _allViewChatUsers = new Dictionary<string, ViewChatUser>(); }
void OnAuthenticate(object sender) { // Sender is always the JabberClient. JabberClient j = (JabberClient)sender; Logger.Info(String.Format("Authentication (User:{0})", j.User)); //done.Set(); j.Presence(PresenceType.available, "Рассылка", "Online", 0); }
public KrakenNetConnection(JabberClient client, string remote) { Client = client; Remote = remote; ProcessingThread = new Thread(ProcessingFunc); ProcessingThread.Name = "XMPP: '" + remote + "' Connection"; ProcessingThread.Start(); }
public void AssignEvents(JabberClient inConn) { inConn.OnMessage += (s, msg) => { lock (mLock) { mMessages.Enqueue(msg); Monitor.PulseAll(mLock); } }; }
private void jc_OnRegistered(object sender, IQ iq) { JabberClient jc = (JabberClient)sender; if (iq.Type == IQType.result) { jc.Login(); } }
public BotEngine() { _jabberClient = new JabberClient { Server = ConfigurationManager.AppSettings["HipChatServer"], User = ConfigurationManager.AppSettings["HipChatUsername"], Password = ConfigurationManager.AppSettings["HipChatPassword"], Resource = ConfigurationManager.AppSettings["HipChatResource"], AutoStartTLS = true, PlaintextAuth = true, AutoPresence = true, AutoRoster = false, AutoReconnect = 1, AutoLogin = true, KeepAlive = 10 }; _jabberClient.OnConnect += jabber_OnConnect; _jabberClient.OnAuthenticate += jabber_OnAuthenticate; _jabberClient.OnInvalidCertificate += jabber_OnInvalidCertificate; _jabberClient.OnError += jabber_OnError; _jabberClient.OnReadText += jabber_OnReadText; _jabberClient.OnWriteText += jabber_OnWriteText; _jabberClient.OnStreamInit += jabber_OnStreamInit; _jabberClient.OnDisconnect += jabber_OnDisconnect; _jabberClient.OnRegistered += jabber_OnRegistered; _jabberClient.OnRegisterInfo += jabber_OnRegisterInfo; _jabberClient.OnMessage += jabber_OnMessage; OnMessageReceived += Session_OnMessageReceived; _presenceManager = new PresenceManager { Stream = _jabberClient }; _presenceManager.OnPrimarySessionChange += presenceManager_OnPrimarySessionChange; _conferenceManager = new ConferenceManager(); _discoManager = new DiscoManager(); _mentionName = ConfigurationManager.AppSettings["HipChatBotMentionName"]; _subscribedRooms = ConfigurationManager.AppSettings["HipChatRooms"]; _powershellRunner = new PowerShellRunner(); _thread = new Thread(delegate() { while (_serviceStarted) { //TODO Add background task implementation here Thread.Sleep(1000); } Thread.CurrentThread.Abort(); } ); }
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; } } }
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(); }
public XmppService(string jid, string password, string host) { _jc = new JabberClient(); _jc.Resource = XMPP_RESOURCE; _jc.AutoStartTLS = false; _jc.SSL = false; JID j = new JID(jid); _jc.User = j.User; _jc.Server = j.Server; _jc.Password = password; _jc.NetworkHost = host; }
private void CapsManager_OnStreamChanged(object sender) { m_disco.JID = m_stream.JID; JabberClient jc = m_stream as JabberClient; if (jc == null) { return; } jc.OnBeforePresenceOut += new PresenceHandler(jc_OnBeforePresenceOut); jc.OnIQ += new IQHandler(jc_OnIQ); jc.OnPresence += new PresenceHandler(jc_OnPresence); }
private JabberClient Connection(string inHostName, AuctionCredencial inCredencial) { var connection = new JabberClient(); connection.AutoLogin = true; connection.AutoStartTLS = false; connection.User = inCredencial.Id.User; connection.Server = inCredencial.Id.Server; connection.Resource = inCredencial.Id.Resource; connection.Password = inCredencial.Password; connection.Port = 5222; connection.NetworkHost = inHostName; return(connection); }
public override bool Connect() { if (Connected) { return(true); } ConnectionThread = new Thread(() => { if (Connected) { try { if (Client != null) { Log.AddMessage("Jabber", " [W] Closing unclosed XMPP connection. Should not happen"); Client.Logout(); } } catch (Exception ex) { } } try { Log.AddMessage("Jabber", " [i] Connecting..."); Client = new JabberClient(Server, ServerPort); Client.MessageHandler = new MessageHandlerDelegate(JabberMessageHandler); Client.PresenceHandler = new PresenceHandlerDelegate(JabberPresenceHandler); Client.ConnectionStatusHandler = new ConnectionStatusHandlerDelegate(JabberConnectionStatusHandler); if (!Client.Login(Jid, Password, Resource)) { Log.AddMessage("Jabber", " [E] Failed to log in. Wrong username/password?"); Disconnect(); return; } } catch (Exception ex) { Log.AddMessage("Jabber", "Exception: " + ex.ToString()); } }); ConnectionThread.Start(); return(true); }
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(); }
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); }
private void JabberClientOnAuthenticate(object sender) { try { Application.Current.Dispatcher.Invoke(() => { if (_dispatcherTimer != null) { _dispatcherTimer.Stop(); } JabberClient.Presence(PresenceType.available, PresenceType.available.ToString(), "", 1); statusListView.SelectedIndex = 0; userTextBlock.GetBindingExpression(TextBlock.TextProperty).UpdateTarget(); }); } catch (Exception exception) { _log.Error(exception); } }
public override void Disconnect() { /* 'this' is locked here and in RequestResult */ lock (this) { /* shut down discover thread */ if (DiscoverThread != null) { DiscoverThread.Abort(); } /* close connection thread */ if (ConnectionThread != null) { ConnectionThread.Abort(); } InKrakenNet = false; /* close all open connection */ foreach (KrakenNetConnection conn in Connections.Values) { conn.CloseConnection(); } Connections.Clear(); /* clear all found kraken hosts */ KrakenNodes.Clear(); /* close XMPP connection */ try { if (Client != null) { Client.Logout(); } } catch { } /* null these as last step */ Client = null; DiscoverThread = null; ConnectionThread = null; } }
internal JabberContact(JabberBuddy contact, JabberClient client) { this.contact = contact; this.client = client; }