bool InternalStartNewProcess(RequestSpawnStartMsg spawnProperties) { int thisPort = GetPort(); if (thisPort == -1) { return(false); } //If a UniqueID was not provided add one for GameResitration if (string.IsNullOrEmpty(spawnProperties.UniqueID)) { spawnProperties.UniqueID = Guid.NewGuid().ToString(); Debug.LogWarning("[ProcessSpawner] - UniqueID was not provided for spawn. Generating: " + spawnProperties.UniqueID); } Process p = new Process(); // Put the process path and the process name together. We use // Path.Combine for this, which will include correct directory // seperators on the OS we're running on (ie. C:\Game\ or /Game/ ) p.StartInfo.FileName = System.IO.Path.Combine(ProcessPath, ProcessName); //Args to pass: Port, Scene, UniqueID... p.StartInfo.Arguments = ArgsString() + " -NetworkAddress " + SpawnerNetworkAddress + " -NetworkPort " + (StartingNetworkPort + thisPort * allocatedPorts) + " -SceneName " + spawnProperties.SceneName + " -UniqueID " + spawnProperties.UniqueID; //What to do if the UniqueID or any other value is null?? if (p.Start()) { Debug.Log("[ProcessSpawner]: spawning: " + p.StartInfo.FileName + "; args=" + p.StartInfo.Arguments); } else { Debug.LogError("[ProcessSpawner] - Process Creation Failed."); return(false); } //Update the collection with newly started process spawnerProcesses[thisPort] = new RunningProcessContainer() { process = p, pid = p.Id, uniqueID = spawnProperties.UniqueID }; //If registered to a master. Notify it of the current thread utilization if (client != null) { client.Send(new SpawnerStatusMsg() { CurrentThreads = GetRunningProcessCount() }); } return(true); }
private void Start() { #if UNITY_EDITOR processPath = editorPath; #endif for (var i = 0; i < spawnerProcesses.Length; i++) { spawnerProcesses[i] = new RunningProcessContainer(); } }
bool InternalStartNewProcess(RequestSpawnStartMsg spawnProperties) { int thisPort = GetPort(); if (thisPort == -1) { return(false); } //If a UniqueID was not provided add one for GameResitration if (string.IsNullOrEmpty(spawnProperties.UniqueID)) { spawnProperties.UniqueID = Guid.NewGuid().ToString(); logger.LogWarning("[ProcessSpawner] - UniqueID was not provided for spawn. Generating: " + spawnProperties.UniqueID); } Process p = new Process(); p.StartInfo.FileName = ProcessPath + ProcessName; //Args to pass: Port, Scene, UniqueID... p.StartInfo.Arguments = ArgsString() + " -NetworkAddress " + SpawnerNetworkAddress + " -NetworkPort " + (StartingNetworkPort + thisPort) + " -SceneName " + spawnProperties.SceneName + " -UniqueID " + spawnProperties.UniqueID; //What to do if the UniqueID or any other value is null?? if (p.Start()) { logger.Log("[ProcessSpawner]: spawning: " + p.StartInfo.FileName + "; args=" + p.StartInfo.Arguments); } else { logger.LogError("[ProcessSpawner] - Process Createion Failed."); return(false); } //If registered to a master. Notify it of the current thread utilization if (client != null) { client.Send(new SpawnerStatusMsg() { CurrentThreads = GetRunningProcessCount() }); } spawnerProcesses[thisPort] = new RunningProcessContainer() { process = p, pid = p.Id, uniqueID = spawnProperties.UniqueID }; return(true); }
void Awake() { #if UNITY_EDITOR ProcessPath = EditorPath; #endif spawnerProcesses = new RunningProcessContainer[MaximumProcesses]; for (int i = 0; i < spawnerProcesses.Length; i++) { spawnerProcesses[i] = new RunningProcessContainer(); } InvokeRepeating("CheckSpawnedProcessHealth", HealthCheckPollRate, HealthCheckPollRate); }
private void HandleRequestSpawnStart(InsightMessage _insightMsg) { var message = (RequestSpawnStartToSpawnerMsg)_insightMsg.message; Debug.Log("[ProcessSpawner] - Received requesting game creation"); var successful = false; var thisPort = GetPort(); if (thisPort != -1) { //If a UniqueID was not provided add one for GameResitration if (string.IsNullOrEmpty(message.gameUniqueId)) { message.gameUniqueId = Guid.NewGuid().ToString(); Debug.LogWarning("[ProcessSpawner] - UniqueID was not provided for spawn. Generating: " + $"{message.gameUniqueId}"); } var args = ArgsString() + Space + ArgNames.UniqueId + Space + message.gameUniqueId + Space + ArgNames.NetworkAddress + Space + spawnerNetworkAddress + Space + ArgNames.NetworkPort + Space + (startingNetworkPort + thisPort) + Space + ArgNames.GameName + Space + message.gameName + Space + ArgNames.MinPlayers + Space + message.minPlayers + Space + ArgNames.MaxPlayers + Space + message.maxPlayers; var processInfo = new ProcessStartInfo { FileName = System.IO.Path.Combine(processPath, processName), Arguments = args, UseShellExecute = false }; var process = Process.Start(processInfo); if (process != null) { Debug.Log( $"[ProcessSpawner] - Spawning : {process.StartInfo.FileName}; args= {process.StartInfo.Arguments}"); process.EnableRaisingEvents = true; process.Exited += OnProcessExited; Send(new SpawnerStatusMsg { uniqueId = uniqueId, currentThreads = GetRunningProcessCount() }); spawnerProcesses[thisPort] = new RunningProcessContainer { process = process, uniqueId = message.gameUniqueId }; successful = true; } } if (_insightMsg.callbackId != 0) { if (successful) { var requestSpawnStartMsg = new RequestSpawnStartToSpawnerMsg { gameUniqueId = message.gameUniqueId, networkAddress = spawnerNetworkAddress, networkPort = (ushort)(startingNetworkPort + thisPort), }; var responseToSend = new InsightNetworkMessage(requestSpawnStartMsg) { callbackId = _insightMsg.callbackId, status = CallbackStatus.Success }; Reply(responseToSend); } else { var responseToSend = new InsightNetworkMessage(new RequestSpawnStartToSpawnerMsg()) { callbackId = _insightMsg.callbackId, status = CallbackStatus.Error }; Reply(responseToSend); } } }