public override string Execute(int playerId) { IP targetIP = GetArgument(0); if (!targetIP.IsValid) { return($"Failed to resolve \"{GetArgument(0)}\".<br>" + $"WARNING: No targets were specified, so 0 hosts were scanned.<br>" + $"portscan done: 0 IP addresses (0 hosts up) scanned in 0.05 seconds"); } // TODO: ComputerComponent should be specified as an optional argument. PlayerComponent player = Game.Players.GetPlayer(playerId); ComputerComponent playerComputer = player.GetSiblingComponent <ComputerComponent>(); NetworkDeviceComponent playerNetworkDevice = player.GetSiblingComponent <NetworkDeviceComponent>(); IP playerIP = playerNetworkDevice.GetPublicInterface().IP; NetworkRoute networkRoute = Game.Internet.GetRoute(playerIP, targetIP); List <NetworkInterface> shortestRoute = networkRoute; if (shortestRoute == null) { return($"Timed out connecting to {targetIP}"); } PortScanApplication portscanComponent = ProcessPool <PortScanApplication> .RunApplication(playerComputer); portscanComponent.OriginEntityId = player.GetEntity(); portscanComponent.TargetEntityId = networkRoute.ToNode.HostDevice.GetEntity(); // TODO: Return "started" response. return(null); }
private const float Delay = 0.5f; // In seconds public override void Process( Entity originEntity, ProcessPool <PortScanApplication> processPool, ComputerComponent originComputer) { foreach (PortScanApplication process in processPool) { if (Process(originEntity, process, originComputer)) { continue; } // Clean up if application is finished. processPool.KillProcess(process.ProcessId); originComputer.RunningApplications.Remove(process.ProcessId); } }
public static T RunApplication(ComputerComponent computer) { Entity computerEntity = computer.GetEntity(); ProcessPool <T> processPool = computerEntity.GetComponent <ProcessPool <T> >(); if (processPool == null) { processPool = new ProcessPool <T>(); computerEntity.AddComponent(processPool); } T applicationInstance = new T(); ushort pid = computer.GetFreeProcessId(); applicationInstance.OriginEntityId = computerEntity.Id; applicationInstance.ProcessId = pid; processPool.processes.Add(applicationInstance); computer.RunningApplications.Add(pid, applicationInstance); return(applicationInstance); }