public void Display(SpawnRequestController request)
        {
            if (Request != null)
            {
                Request.StatusChanged -= OnStatusChange;
            }

            if (request == null)
            {
                return;
            }

            request.StatusChanged += OnStatusChange;

            Request = request;
            gameObject.SetActive(true);

            // Disable abort, and enable it after some time
            AbortButton.interactable = false;
            StartCoroutine(EnableAbortDelayed(EnableAbortAfterSeconds, request.SpawnId));

            if (StatusText != null)
            {
                StatusText.text = PleaseWaitText;
            }
        }
示例#2
0
        /// <summary>
        /// Sends a request to master server, to spawn a process in a given region, and with given options
        /// </summary>
        public void RequestSpawn(Dictionary <string, string> options, string region, ClientSpawnRequestCallback callback, IClientSocket connection)
        {
            if (!connection.IsConnected)
            {
                callback.Invoke(null, "Not connected");
                return;
            }

            var packet = new ClientsSpawnRequestPacket()
            {
                Options = options,
                Region  = region
            };

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

                // Spawn id
                var spawnId = response.AsInt();

                var controller = new SpawnRequestController(spawnId, connection, options);

                _localSpawnRequests[controller.SpawnId] = controller;

                callback.Invoke(controller, null);
            });
        }
示例#3
0
        /// <summary>
        /// Sends a request to master server, to spawn a process in a given region, and with given options
        /// </summary>
        /// <param name="options"></param>
        /// <param name="customArgs"></param>
        /// <param name="region"></param>
        /// <param name="callback"></param>
        public void RequestSpawn(Dictionary <string, string> options, Dictionary <string, string> customArgs, string region, ClientSpawnRequestCallback callback, IClientSocket connection)
        {
            if (!connection.IsConnected)
            {
                callback?.Invoke(null, "Not connected");
                return;
            }

            // Create spawn request message packet
            var packet = new ClientsSpawnRequestPacket()
            {
                Options = options,
                Region  = region
            };

            if (customArgs != null && customArgs.Count > 0)
            {
                var customArgsSb = new StringBuilder();

                foreach (var kvp in customArgs)
                {
                    customArgsSb.Append($"{kvp.Key} {kvp.Value} ");
                }

                packet.CustomArgs = customArgsSb.ToString();
            }
            else
            {
                packet.CustomArgs = string.Empty;
            }

            // Send request to Master Server SpawnerModule
            connection.SendMessage((short)MsfMessageCodes.ClientsSpawnRequest, packet, (status, response) =>
            {
                if (status != ResponseStatus.Success)
                {
                    callback?.Invoke(null, response.AsString("Unknown error"));
                    return;
                }

                Logs.Debug($"Room [{options[MsfDictKeys.roomName]}] was successfuly started");

                // Spawn id
                var spawnId    = response.AsInt();
                var controller = new SpawnRequestController(spawnId, connection, options);

                _localSpawnRequests[controller.SpawnId] = controller;

                callback?.Invoke(controller, null);
            });
        }
        /// <summary>
        /// Sends a request to master server, to spawn a process in a given region, and with given options
        /// </summary>
        /// <param name="options"></param>
        /// <param name="customOptions"></param>
        /// <param name="region"></param>
        /// <param name="callback"></param>
        public void RequestSpawn(DictionaryOptions options, DictionaryOptions customOptions, string region, ClientSpawnRequestCallback callback, IClientSocket connection)
        {
            // If we are not connected
            if (!connection.IsConnected)
            {
                callback?.Invoke(null, "Not connected");
                return;
            }

            // Set region to room by filter. If region is empty the room will be international
            options.Set(MsfDictKeys.region, string.IsNullOrEmpty(region) ? string.Empty : region);

            // Create spawn request message packet
            var data = new ClientsSpawnRequestPacket()
            {
                // Options for spawners module
                Options = options,

                // Options that will be send to room
                CustomOptions = customOptions
            };

            // Send request to Master Server SpawnerModule
            connection.SendMessage((short)MsfMessageCodes.ClientsSpawnRequest, data, (status, response) =>
            {
                // If spawn request failed
                if (status != ResponseStatus.Success)
                {
                    Logs.Error($"An error occurred when spawn request [{response.AsString()}]");
                    callback?.Invoke(null, response.AsString());
                    return;
                }

                // Create new spawn request controller
                var controller = new SpawnRequestController(response.AsInt(), connection, options);

                // List controler by spawn task id
                _localSpawnRequests[controller.SpawnTaskId] = controller;

                Logs.Debug($"Room was successfuly started with client options: {data.Options.ToReadableString()}, {data.CustomOptions.ToReadableString()}");

                callback?.Invoke(controller, null);
            });
        }
示例#5
0
        //Set up the Request variable to run OnStatusChange() when the status of our spawn request is changed
        public void TrackRequest(SpawnRequestController request)
        {
            if (Request != null)
            {
                Request.StatusChanged -= OnStatusChange;
            }

            if (request == null)
            {
                return;
            }

            request.StatusChanged += OnStatusChange;

            Request = request;
            gameObject.SetActive(true);

            //Typically we'd include an "abort" option, but in the spirit of keeping things simple,
            //we're leaving it out for this tutorial
        }
示例#6
0
 /// <summary>
 /// Retrieves a specific spawn request controller
 /// </summary>
 /// <param name="spawnId"></param>
 /// <returns></returns>
 public bool TryGetRequestController(int spawnId, out SpawnRequestController controller)
 {
     controller = GetRequestController(spawnId);
     return(controller != null);
 }