예제 #1
0
        public virtual RegisteredSpawner CreateSpawner(IPeer peer, SpawnerOptions options)
        {
            var spawner = new RegisteredSpawner(GenerateSpawnerId(), peer, options);

            if (!(peer.GetProperty((int)PeerPropertyKeys.RegisteredSpawners) is Dictionary <int, RegisteredSpawner> peerSpawners))
            {
                // If this is the first time registering a spawners

                // Save the dictionary
                peerSpawners = new Dictionary <int, RegisteredSpawner>();
                peer.SetProperty((int)PeerPropertyKeys.RegisteredSpawners, peerSpawners);

                peer.Disconnected += OnRegisteredPeerDisconnect;
            }

            // Add a new spawner
            peerSpawners[spawner.SpawnerId] = spawner;

            // Add the spawner to a list of all spawners
            Spawners[spawner.SpawnerId] = spawner;

            // Invoke the event
            SpawnerRegistered?.Invoke(spawner);

            return(spawner);
        }
예제 #2
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);
                }
            });
        }
예제 #3
0
        public virtual RegisteredSpawner CreateSpawner(IPeer peer, SpawnerOptions options)
        {
            var spawner = new RegisteredSpawner(GenerateSpawnerId(), peer, options);

            var peerSpawners =
                peer.GetProperty((int)MsfPropCodes.RegisteredSpawners) as Dictionary <string, RegisteredSpawner>;

            if (peerSpawners == null)
            {
                // If this is the first time registering a spawners

                // Save the dictionary
                peerSpawners = new Dictionary <string, RegisteredSpawner>();
                peer.SetProperty((int)MsfPropCodes.RegisteredSpawners, peerSpawners);

                peer.Disconnected += OnRegisteredPeerDisconnect;
            }

            // Add a new spawner
            peerSpawners[spawner.SpawnerId] = spawner;

            // Add the spawner to a list of all spawners
            Spawners[spawner.SpawnerId] = spawner;

            // Invoke the event
            if (SpawnerRegistered != null)
            {
                SpawnerRegistered.Invoke(spawner);
            }

            return(spawner);
        }