Beispiel #1
0
        /// <summary>
        /// Sends a request to master server, to register an existing spawner with given options
        /// </summary>
        public void RegisterSpawner(SpawnerOptions options, RegisterSpawnerCallback callback, IClientSocket connection)
        {
            if (!connection.IsConnected)
            {
                callback.Invoke(null, "Not connected");
                return;
            }

            connection.SendMessage((short)MsfOpCodes.RegisterSpawner, options, (status, response) =>
            {
                if (status != ResponseStatus.Success)
                {
                    callback.Invoke(null, response.AsString("Unknown Error"));
                    return;
                }

                var spawnerId = response.AsString();

                var controller = new SpawnerController(spawnerId, connection, options);

                // Save reference
                _locallyCreatedSpawners[spawnerId] = controller;

                callback.Invoke(controller, null);

                // Invoke the event
                if (SpawnerRegistered != null)
                {
                    SpawnerRegistered.Invoke(controller);
                }
            });
        }
Beispiel #2
0
 protected virtual void OnApplicationQuit()
 {
     if (killProcessesWhenAppQuits)
     {
         SpawnerController.KillProcessesSpawnedWithDefaultHandler();
     }
 }
Beispiel #3
0
 private void OnSpawnersCountChange(SpawnerController obj)
 {
     UpdateSpawnersView();
 }
Beispiel #4
0
        public virtual void StartSpawner()
        {
            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;
            }

            IsSpawnerStarted = true;

            var spawnerOptions = new SpawnerOptions
            {
                // If MaxProcesses count defined in cmd args
                MaxProcesses = Msf.Args.IsProvided(Msf.Args.Names.MaxProcesses) ? Msf.Args.MaxProcesses : maxProcesses
            };

            // 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, (spawnerController, error) =>
            {
                if (!string.IsNullOrEmpty(error))
                {
                    logger.Error($"Failed to create spawner: {error}");
                    return;
                }

                this.spawnerController = spawnerController;
                this.spawnerController.Logger.LogLevel = spawnerLogLevel;

                spawnerController.DefaultSpawnerSettings.UseWebSockets = Msf.Args.IsProvided(Msf.Args.Names.UseWebSockets)
                    ? Msf.Args.WebGl
                    : spawnWebSocketServers;

                // Set to run in batchmode
                if (spawnInBatchmode && !Msf.Args.DontSpawnInBatchmode)
                {
                    spawnerController.DefaultSpawnerSettings.SpawnInBatchmode = true;
                }

                // 2. Set the default executable path
                spawnerController.DefaultSpawnerSettings.ExecutablePath = Msf.Args.IsProvided(Msf.Args.Names.RoomExecutablePath) ?
                                                                          Msf.Args.RoomExecutablePath : executableFilePath;

                // 3. Set the machine IP
                spawnerController.DefaultSpawnerSettings.MachineIp = Msf.Args.IsProvided(Msf.Args.Names.RoomIp) ?
                                                                     Msf.Args.RoomIp : machineIp;

                // 4. (Optional) Set the method which does the spawning, if you want to
                // fully control how processes are spawned
                spawnerController.SetSpawnRequestHandler(SpawnRequestHandler);

                // 5. (Optional) Set the method, which kills processes when kill request is received
                spawnerController.SetKillRequestHandler(KillRequestHandler);

                logger.Info("Spawner successfully created. Id: " + spawnerController.SpawnerId);
            });
        }
Beispiel #5
0
 protected virtual void OnDisconnectedFromMasterEventHandler()
 {
     SpawnerController.KillProcessesSpawnedWithDefaultHandler();
 }