/// <summary> /// Stops spawner processes /// </summary> public virtual void StopSpawner() { // Kill all the processes of spawner controller if (killProcessesWhenStop) { spawnerController?.KillProcesses(); } // Set spawn behaviour as not started IsSpawnerStarted = false; if (spawnerController != null) { logger.Info($"Spawner stopped. Id: {spawnerController.SpawnerId}"); } // Destroy spawner spawnerController = null; OnSpawnerStoppedEvent?.Invoke(); }
/// <summary> /// Starts spawner. But before start we are required to be connected /// </summary> public virtual void StartSpawner() { // Stop if no connection if (!Mst.Connection.IsConnected) { logger.Error("Spawner cannot be started because of the lack of connection to the master."); return; } // In case we went from one scene to another, but we've already started the spawner if (IsSpawnerStarted) { return; } // If machine IP is defined in cmd machineIp = Mst.Args.AsString(Mst.Args.Names.RoomIp, machineIp); // If room region is defined in cmd region = Mst.Args.AsString(Mst.Args.Names.RoomRegion, region); IsSpawnerStarted = true; // Create spawner options var spawnerOptions = new SpawnerOptions { // If MaxProcesses count defined in cmd args MaxProcesses = Mst.Args.AsInt(Mst.Args.Names.MaxProcesses, maxProcesses), MachineIp = machineIp, Region = region }; // If we're running in editor, and we want to override the executable path if (Mst.Runtime.IsEditor && overrideExePathInEditor) { executableFilePath = exePathFromEditor; } logger.Info($"Registering as a spawner with options: \n{spawnerOptions}"); // 1. Register the spawner Mst.Server.Spawners.RegisterSpawner(spawnerOptions, (controller, error) => { if (!string.IsNullOrEmpty(error)) { logger.Error($"Failed to create spawner: {error}"); return; } // 2. Save spawner controller spawnerController = controller; // 3. Set its log level spawnerController.Logger.LogLevel = spawnerLogLevel; // 4. Set use web sockets if required spawnerController.SpawnSettings.UseWebSockets = Mst.Args.AsBool(Mst.Args.Names.UseWebSockets, spawnWebSocketServers); // 5. Set the default executable path spawnerController.SpawnSettings.ExecutablePath = Mst.Args.AsString(Mst.Args.Names.RoomExecutablePath, executableFilePath); // 6. Set the machine IP spawnerController.SpawnSettings.MachineIp = machineIp; // 7. Set region spawnerController.SpawnSettings.Region = spawnerOptions.Region; logger.Info($"Spawner successfully created. Id: {controller.SpawnerId}"); // 8. Inform listeners OnSpawnerStartedEvent?.Invoke(); OnSpawnerStarted(); }); }
/// <summary> /// Start spawner. But before start we are required to be connected /// </summary> public virtual void StartSpawner() { // Stop if no connection if (!Msf.Connection.IsConnected) { logger.Error("Spawner cannot be started because of the lack of connection to the master."); return; } // In case we went from one scene to another, but we've already started the spawner if (IsSpawnerStarted) { return; } // We do not want to use public IP if (!usePublicIp) { // If machine IP is defined in cmd machineIp = Msf.Args.ExtractValue(Msf.Args.Names.RoomIp, machineIp); } // If room region is defined in cmd region = Msf.Args.ExtractValue(Msf.Args.Names.RoomRegion, region); IsSpawnerStarted = true; // Create spawner options var spawnerOptions = new SpawnerOptions { // If MaxProcesses count defined in cmd args MaxProcesses = Msf.Args.ExtractValueInt(Msf.Args.Names.MaxProcesses, maxProcesses), MachineIp = machineIp, Region = region }; // If we're running in editor, and we want to override the executable path if (Msf.Runtime.IsEditor && overrideExePathInEditor) { executableFilePath = exePathFromEditor; } logger.Info("Registering as a spawner with options: \n" + spawnerOptions); // 1. Register the spawner Msf.Server.Spawners.RegisterSpawner(spawnerOptions, (controller, error) => { if (!string.IsNullOrEmpty(error)) { logger.Error($"Failed to create spawner: {error}"); return; } spawnerController = controller; spawnerController.Logger.LogLevel = spawnerLogLevel; spawnerController.SpawnSettings.UseWebSockets = Msf.Args.IsProvided(Msf.Args.Names.UseWebSockets) ? Msf.Args.WebGl : spawnWebSocketServers; // Set to run in batchmode if (spawnInBatchmode && !Msf.Args.DontSpawnInBatchmode) { spawnerController.SpawnSettings.SpawnInBatchmode = true; } // 2. Set the default executable path spawnerController.SpawnSettings.ExecutablePath = Msf.Args.ExtractValue(Msf.Args.Names.RoomExecutablePath, executableFilePath); // 3. Set the machine IP spawnerController.SpawnSettings.MachineIp = machineIp; // 4. Set region spawnerController.SpawnSettings.Region = spawnerOptions.Region; logger.Info("Spawner successfully created. Id: " + controller.SpawnerId); OnSpawnerRegistered(); }); }