private void SendToSpawner(int _connectionId, RequestSpawnStartMsg _message, CallbackHandler _callback = null) { var message = new RequestSpawnStartToSpawnerMsg(_message); if (_connectionId == 0) { server.InternalSend(message, _callback); } else { server.NetworkSend(_connectionId, message, _callback); } }
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); } } }