Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static class Program
- {
- public static Form1 mainForm;
- [STAThread]
- static void Main()
- {
- Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
- AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- mainForm = new Form1();
- Application.Run(mainForm);
- }
- static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
- {
- CrashReporter ErrorDlg = new CrashReporter((Exception)e.ExceptionObject);
- ErrorDlg.ShowDialog();
- }
- static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
- {
- CrashReporter ErrorDlg = new CrashReporter(e.Exception);
- ErrorDlg.ShowDialog();
- }
- }
- void connect(string user, string password)
- {
- if (!_conn)
- {
- conn = true;
- user = user;
- pass = password;
- tcpThread = new Thread(new ThreadStart(SetupConn));
- tcpThread.Start();
- imUsername = user;
- }
- }
- void SetupConn()
- {
- client = new TcpClient(Server, Port); // Connect to the server.
- netStream = client.GetStream();
- ssl = new SslStream(netStream, false, new RemoteCertificateValidationCallback(ValidateCert));
- ssl.AuthenticateAsClient("AppNameHere");
- br = new BinaryReader(ssl, Encoding.UTF8);
- bw = new BinaryWriter(ssl, Encoding.UTF8);
- int connectiong = br.ReadInt32();
- if (connectiong == IM_Connecting)
- {
- WebClient client = new WebClient();
- string ipadresa = Base64Encode(client.DownloadString("http://-deleted-for-public-"));
- bw.Write(IM_Connecting);
- bw.Write(IM_Login);
- bw.Write(UserName);
- bw.Write(Password);
- bw.Write(ipadresa);
- bw.Flush();
- byte ans = br.ReadByte();
- if (ans == IM_OK)
- {
- OnLoginOK();
- Receiver();
- }
- else
- {
- IMErrorEventArgs err = new IMErrorEventArgs((IMError)ans);
- OnLoginFailed(err);
- }
- }
- if (_conn)
- CloseConn();
- }
- public void ImOnline(string user)
- {
- if (conn) {
- if(logged == true) {
- bw.Write(IM_Online);
- bw.Write(user);
- bw.Flush();
- }
- }
- }
- public void Receiver()
- {
- logged = true;
- try
- {
- while (client.Connected)
- {
- byte type = br.ReadByte();
- if (type == IM_Here) {
- string f_online = br.ReadString();
- string f_username = br.ReadString();
- if (f_online == "True") {
- friendOnline(true, f_username, "-");
- } else {
- friendOnline(false, f_username, "-");
- }
- }
- }
- }
- catch (IOException ex)
- {
- //MessageBox.Show(ex.ToString());
- return;
- }
- logged = false;
- }
- new Thread(() =>
- {
- TalkForm a = new TalkForm(im, username, dname, mydisplayname);
- a.sendTo = username;
- chats.Add(a); // Add form to the list of chat forms so it can be found if is already open so it can be 'BringToFront'
- a.ShowDialog();
- }).Start();
Add Comment
Please, Sign In to add comment