示例#1
0
        /// <summary>
        /// This should be called from a process which is spawned.
        /// For example, it can be called from a game server, which is started by the spawner
        /// On successfull registration, callback contains <see cref="SpawnTaskController"/>, which
        /// has a dictionary of properties, that were given when requesting a process to be spawned
        /// </summary>
        public void RegisterSpawnedProcess(string spawnId, string spawnCode, RegisterSpawnedProcessCallback callback,
                                           IClientSocket connection)
        {
            if (!connection.IsConnected)
            {
                callback.Invoke(null, "Not connected");
                return;
            }

            //Debug.LogError("SPWn code: " + spawnCode);
            var packet = new RegisterSpawnedProcessPacket()
            {
                SpawnCode = spawnCode,
                SpawnId   = spawnId
            };

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

                var properties = new Dictionary <string, string>().FromBytes(response.AsBytes());

                var process = new SpawnTaskController(spawnId, properties, connection, spawnCode);

                callback.Invoke(process, null);
            });
        }
        /// <summary>
        /// This should be called from a process which is spawned.
        /// For example, it can be called from a game server, which is started by the spawner
        /// On successfull registration, callback contains <see cref="SpawnTaskController"/>, which
        /// has a dictionary of properties, that were given when requesting a process to be spawned
        /// </summary>
        public void RegisterSpawnedProcess(int spawnId, string spawnCode, RegisterSpawnedProcessCallback callback, IClientSocket connection)
        {
            if (!connection.IsConnected)
            {
                callback.Invoke(null, "Not connected");
                return;
            }

            var packet = new RegisterSpawnedProcessPacket()
            {
                SpawnCode = spawnCode,
                SpawnId   = spawnId
            };

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

                // Read spawn task options received from master server
                var options = new DictionaryOptions(new Dictionary <string, string>().FromBytes(response.AsBytes()));

                // Create spawn task controller
                var process = new SpawnTaskController(spawnId, options, connection);

                callback.Invoke(process, null);
            });
        }