public static string Create(int playerId) { Entity playerEntity = Game.World.GetEntityById(playerId); if (playerEntity == null) { return(null); } PlayerStateMessage message = new PlayerStateMessage(); message.PlayerIP = Game.Internet.GetIP(playerEntity); ComputerComponent playerComputer = playerEntity.GetComponent <ComputerComponent>(); List <ProcessInfo> runningProcesses = new List <ProcessInfo>(); foreach (IApplication application in playerComputer.RunningApplications.Values) { ProcessInfo processInfo = new ProcessInfo(application); runningProcesses.Add(processInfo); } message.RunningProcesses = runningProcesses; return(JsonConvert.SerializeObject(message)); }
/// <summary> /// Process each porstcan application. /// </summary> /// <returns>Whether system should continue processing after this iteration.</returns> public bool Process( Entity originEntity, PortScanApplication portScan, ComputerComponent originComputer) { if (portScan.SecondsSinceLastUpdate < Delay) { portScan.SecondsSinceLastUpdate += Game.Time.ElapsedSeconds; return(true); } PlayerComponent player = originEntity.GetComponent <PlayerComponent>(); ComputerComponent targetComputer = Game.World.GetEntityById(portScan.TargetEntityId)? .GetComponent <ComputerComponent>(); if (!ValidateHost( targetComputer: targetComputer, player: player)) { return(false); } ScanCurrentPort( portScan: portScan, targetComputer: targetComputer, player: player); if (!IncrementCurrentPort(portScan)) { return(false); } return(true); }
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 static bool ValidateHost( ComputerComponent targetComputer, PlayerComponent player) { if (targetComputer == null) { Game.SendMessageToClient( player.Id, new TerminalUpdateMessage($"Timed out connecting to host.").ToJson()); return(false); } return(true); }
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); }
private static void ScanCurrentPort( PortScanApplication portScan, ComputerComponent targetComputer, PlayerComponent player) { foreach ( IApplication application in targetComputer.RunningApplications.Values) { IServerApplication serverApplication = application as IServerApplication; if (serverApplication != null && serverApplication.Port == portScan.CurrentPort) { portScan.OpenPorts.Add(serverApplication.Port); SendPlayerUpdate( portScan: portScan, player: player, serverApplication: serverApplication); break; } } }
public override string Execute(int playerId) { ComputerComponent playerComputer = Game.World .GetEntityById(playerId) .GetComponent <ComputerComponent>(); // TODO: This should be an ongoing process/application. StringBuilder result = new StringBuilder(); result.Append("<table><tr><th>PID</th><th>USER</th><th>RAM</th><th>COMMAND</th></tr>"); foreach (var process in playerComputer.RunningApplications.Values) { result.Append($"<tr>" + $"<td>{process.ProcessId}</td>" + $"<td>root</td>" + $"<td>{process.RamUse}</td>" + $"<td>{process.Name}</td>" + $"</tr>"); } result.Append("</table>"); return(result.ToString()); }