Exemplo n.º 1
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);
            });
        }
Exemplo n.º 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, ErrorCallback errorCallback)
        {
            if (!Client.IsConnected)
            {
                errorCallback.Invoke("Not connected");
                return;
            }

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

            Client.SendMessage((ushort)OpCodes.ClientsSpawnRequest, packet, (status, response) =>
            {
                if (status != ResponseStatus.Success)
                {
                    errorCallback.Invoke(response.AsString("Unknown error"));
                    return;
                }

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

                var controller = new SpawnRequestController(this, spawnId, Client);

                _localSpawnRequests[controller.SpawnId] = controller;

                callback.Invoke(controller);
            });
        }
Exemplo n.º 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="region"></param>
 /// <param name="callback"></param>
 public void RequestSpawn(Dictionary <string, string> options, string region, ClientSpawnRequestCallback callback)
 {
     RequestSpawn(options, region, callback, Connection);
 }
Exemplo n.º 4
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);
            });
        }
 /// <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="region"></param>
 /// <param name="callback"></param>
 public void RequestSpawn(DictionaryOptions options, DictionaryOptions customOptions, string region, ClientSpawnRequestCallback callback)
 {
     RequestSpawn(options, customOptions, region, callback, Connection);
 }