Beispiel #1
0
 private string GetLoginTokenConfig(WorkerConfigurationData data)
 {
     return(GetCommandLineValue(EditableConfigNames.LoginToken, data.SpatialOsApplication.LoginToken));
 }
Beispiel #2
0
        /// <summary>
        ///     Constructs a new instance of <c>WorkerConfiguration</c>.
        /// </summary>
        /// <param name="data">User-configured data used to configure the worker.</param>
        /// <param name="commandLineArguments">
        ///     A list of arguments specified on the command line.
        ///     If null, defaults to
        ///     <example>global::System.Environment.GetCommandLineArgs()</example>
        /// </param>
        public WorkerConfiguration(WorkerConfigurationData data, IList <string> commandLineArguments = null)
        {
            if (commandLineArguments == null)
            {
                commandLineArguments = global::System.Environment.GetCommandLineArgs();
            }

            Debug.LogFormat("Command line {0}", string.Join(" ", commandLineArguments.ToArray()));

            commandLineDictionary = CommandLineUtil.ParseCommandLineArgs(commandLineArguments);

            ProjectName = string.Empty;

            if (Application.isEditor)
            {
                // Read ProjectName from the spatialos.json file, if not already specified.
                // This is only done in Editor mode, as we do not expect spatialos.json to exist outside of dev environment.

                if (!commandLineDictionary.ContainsKey(CommandLineConfigNames.ProjectName) && !commandLineDictionary.ContainsKey(CommandLineConfigNames.AppName))
                {
                    try
                    {
                        ProjectName = ProjectDescriptor.Load().Name;
                    }
                    catch (Exception e)
                    {
                        Debug.LogErrorFormat("Cannot read project name from '{0}'. You will not be able to connect to a deployment. Underlying error: {1}", ProjectDescriptor.ProjectDescriptorPath, e);
                    }
                }
            }

            var defaultWorkerPlatform = data.SpatialOsApplication.WorkerPlatform;

#pragma warning disable 618
            var workerPlatformString = GetObsoleteAndCurrentCommandLineValue(EditableConfigNames.WorkerType, EditableConfigNames.EngineType, string.Empty);
#pragma warning restore 618
            if (!string.IsNullOrEmpty(workerPlatformString))
            {
                defaultWorkerPlatform = WorkerTypeUtils.FromWorkerName(workerPlatformString);
            }

            var workerName = WorkerTypeUtils.ToWorkerName(data.SpatialOsApplication.WorkerPlatform);

            appName       = GetCommandLineValue(CommandLineConfigNames.AppName, string.Empty);
            ProjectName   = GetCommandLineValue(CommandLineConfigNames.ProjectName, ProjectName);
            AssemblyName  = GetCommandLineValue(EditableConfigNames.AssemblyName, data.SpatialOsApplication.AssemblyName);
            DeploymentId  = GetCommandLineValue(EditableConfigNames.DeploymentId, data.SpatialOsApplication.DeploymentId);
            DeploymentTag = GetCommandLineValue(EditableConfigNames.DeploymentTag, data.SpatialOsApplication.DeploymentTag);
#pragma warning disable 618
            WorkerId = GetObsoleteAndCurrentCommandLineValue(EditableConfigNames.WorkerId, EditableConfigNames.EngineId, workerName + Guid.NewGuid());
#pragma warning restore 618
            WorkerPlatform = defaultWorkerPlatform;
#pragma warning disable 618
            EntityCreationLimitPerFrame = GetCommandLineValue(EditableConfigNames.EntityCreationLimitPerFrame, data.Unity.EntityCreationLimitPerFrame);
#pragma warning restore 618
            InfraServiceUrl              = GetCommandLineValue(EditableConfigNames.InfraServiceUrl, data.Debugging.InfraServiceUrl);
            ReceptionistHost             = GetCommandLineValue(EditableConfigNames.ReceptionistHost, data.Networking.ReceptionistHost);
            ReceptionistPort             = GetCommandLineValue(EditableConfigNames.ReceptionistPort, data.Networking.ReceptionistPort);
            LinkProtocol                 = GetCommandLineValue(EditableConfigNames.LinkProtocol, data.Networking.LinkProtocol);
            LocatorHost                  = GetCommandLineValue(EditableConfigNames.LocatorHost, data.Networking.LocatorHost);
            LoginToken                   = GetLoginTokenConfig(data);
            ProtocolLogPrefix            = GetCommandLineValue(EditableConfigNames.ProtocolLogPrefix, data.Debugging.ProtocolLogPrefix);
            ProtocolLoggingOnStartup     = GetCommandLineValue(EditableConfigNames.ProtocolLoggingOnStartup, data.Debugging.ProtocolLoggingOnStartup);
            ProtocolLogMaxFileBytes      = GetCommandLineValue(EditableConfigNames.ProtocolLogMaxFileBytes, data.Debugging.ProtocolLogMaxFileBytes);
            RaknetHeartbeatTimeoutMillis = GetCommandLineValue(EditableConfigNames.RaknetHeartbeatTimeoutMillis, data.Networking.RaknetHeartbeatTimeoutMillis);
            ReceiveQueueCapacity         = data.Networking.ReceiveQueueCapacity;
            SendQueueCapacity            = data.Networking.SendQueueCapacity;
            SteamToken                   = GetCommandLineValue(EditableConfigNames.SteamToken, data.Networking.SteamToken);
            TcpMultiplexLevel            = GetCommandLineValue(EditableConfigNames.TcpMultiplexLevel, data.Networking.TcpMultiplexLevel);
            UseExternalIp                = GetCommandLineValue(CommandLineConfigNames.UseExternalIpForBridge, Defaults.UseExternalIp) == false; // DEV-1120: The flag is flipped for legacy reasons.
            UseInstrumentation           = GetCommandLineValue(EditableConfigNames.UseInstrumentation, data.Debugging.UseInstrumentation);
            UsePrefabPooling             = GetCommandLineValue(EditableConfigNames.UsePrefabPooling, data.Unity.UsePrefabPooling);

            LogDebugToSpatialOs     = GetCommandLineValue(EditableConfigNames.LogDebugToSpatialOs, data.Debugging.LogDebugToSpatialOs);
            LogAssertToSpatialOs    = GetCommandLineValue(EditableConfigNames.LogAssertToSpatialOs, data.Debugging.LogAssertToSpatialOs);
            LogWarningToSpatialOs   = GetCommandLineValue(EditableConfigNames.LogWarningToSpatialOs, data.Debugging.LogWarningToSpatialOs);
            LogErrorToSpatialOs     = GetCommandLineValue(EditableConfigNames.LogErrorToSpatialOs, data.Debugging.LogErrorToSpatialOs);
            LogExceptionToSpatialOs = GetCommandLineValue(EditableConfigNames.LogExceptionToSpatialOs, data.Debugging.LogExceptionToSpatialOs);

            if (string.IsNullOrEmpty(ProjectName))
            {
                throw new ArgumentException(string.Format("The ProjectName must be set with {0}, or via command-line argument +{1}",
                                                          Path.GetFileName(ProjectDescriptor.ProjectDescriptorPath),
                                                          CommandLineConfigNames.ProjectName));
            }

            if (Application.isEditor == false)
            {
                PrintWorkerConfigurationSettings();
            }
        }