Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- using System.IO;
- using jabber.client;
- namespace JabbR
- {
- class MainClass
- { public static string username,password,server;
- public static string[] beolv;
- public static bool beolvasva,verbose;
- static string TARGET="bkotsis";
- static ManualResetEvent done = new ManualResetEvent(false);
- public static void Main (string[] args)
- {
- try
- {
- beolv = File.ReadAllLines("JabbR.cfg");
- }
- catch (System.IO.FileNotFoundException)
- {
- Console.WriteLine("Enter your username");
- username=Console.ReadLine().ToString();
- Console.WriteLine("Enter your password");
- password=Console.ReadLine().ToString();
- Console.WriteLine("Enter the server you want to use");
- server=Console.ReadLine();
- File.WriteAllText("JabbR.cfg",username+'\n'+password+'\n'+server);
- beolvasva=true;
- }
- if(beolvasva==false)
- {
- username=beolv[0];
- password=beolv[1];
- server=beolv[2];
- }
- //Client serialisation and settings
- JabberClient client =new JabberClient();
- client.User=username;
- client.Server=server;
- client.Password=password;
- client.AutoPresence = false;
- client.AutoRoster = false;
- client.AutoReconnect = -1;
- //Event handlers
- client.OnError += new bedrock.ExceptionHandler(client_OnError);
- client.OnAuthenticate+=new bedrock.ObjectHandler(client_OnAuthenticate);
- // listen for XMPP wire protocol
- if (verbose)
- client.OnReadText += new bedrock.TextHandler(client_OnReadText);
- client.OnWriteText+=new bedrock.TextHandler(client_OnWriteText);
- client.Connect();
- done.WaitOne();
- //client.Close();
- }
- static void client_OnWriteText(object sender, string txt)
- {
- if (txt == " ") return;
- Console.WriteLine("SEND: " + txt);
- }
- static void client_OnReadText(object sender, string txt)
- {
- if (txt == " ") return; // ignore keep-alive spaces
- Console.WriteLine("RECV: " + txt);
- }
- static void client_OnAuthenticate(object sender)
- {
- // Sender is always the JabberClient.
- JabberClient client = (JabberClient)sender;
- client.Message(TARGET, "this is a test");
- // Finished sending. Shut down.
- done.Set();
- }
- static void client_OnError(object sender, Exception ex)
- {
- // There was an error!
- Console.WriteLine("Error: " + ex.ToString());
- // Shut down.
- done.Set();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement