示例#1
0
        public void initialize()
        {
            if (Dedicator.isDedicated)
            {
                rocketGameObject = new GameObject("Rocket");
                DontDestroyOnLoad(rocketGameObject);

                if (System.Environment.OSVersion.Platform == PlatformID.Unix || System.Environment.OSVersion.Platform == PlatformID.MacOSX)
#pragma warning disable CS0618
                {
                    Console = rocketGameObject.AddComponent <UnturnedConsole>();
                }
#pragma warning restore CS0618

                CommandWindow.Log("Rocket Unturned v" + Assembly.GetExecutingAssembly().GetName().Version.ToString() + " for Unturned v" + Provider.APP_VERSION);

                IPluginAdvertising pluginAdvertising = PluginAdvertising.Get();
                pluginAdvertising.PluginFrameworkName = "rocket";

                R.OnRockedInitialized += () =>
                {
                    Instance.Initialize();
                };

                Provider.onServerHosted += () =>
                {
                    rocketGameObject.TryAddComponent <U>();
                    rocketGameObject.TryAddComponent <R>();
                };
            }
        }
示例#2
0
        internal void Initialize()
        {
            try
            {
                Settings    = new XMLFileAsset <UnturnedSettings>(Environment.SettingsFile);
                Translation = new XMLFileAsset <TranslationList>(String.Format(Environment.TranslationFile, Core.R.Settings.Instance.LanguageCode), new Type[] { typeof(TranslationList), typeof(TranslationListEntry) }, defaultTranslations);
                defaultTranslations.AddUnknownEntries(Translation);
                Events = gameObject.TryAddComponent <UnturnedEvents>();

                gameObject.TryAddComponent <UnturnedPermissions>();
                gameObject.TryAddComponent <UnturnedChat>();
                gameObject.TryAddComponent <UnturnedCommands>();

                gameObject.TryAddComponent <AutomaticSaveWatchdog>();

                bindDelegates();

                RocketPlugin.OnPluginLoading += (IRocketPlugin plugin, ref bool cancelLoading) =>
                {
                    try
                    {
                        plugin.TryAddComponent <PluginUnturnedPlayerComponentManager>();
                    }
                    catch (Exception ex)
                    {
                        Core.Logging.Logger.LogException(ex, "Failed to load plugin " + plugin.Name + ".");
                        cancelLoading = true;
                    }
                };

                RocketPlugin.OnPluginUnloading += (IRocketPlugin plugin) =>
                {
                    plugin.TryRemoveComponent <PluginUnturnedPlayerComponentManager>();
                };

                R.Commands.RegisterFromAssembly(Assembly.GetExecutingAssembly());

                try
                {
                    R.Plugins.OnPluginsLoaded += () =>
                    {
                        IPluginAdvertising   pluginAdvertising = PluginAdvertising.Get();
                        List <IRocketPlugin> rocketPlugins     = R.Plugins.GetPlugins();
                        List <string>        pluginNames       = new List <string>(rocketPlugins.Count);
                        foreach (IRocketPlugin plugin in rocketPlugins)
                        {
                            if (plugin != null && !string.IsNullOrEmpty(plugin.Name))
                            {
                                pluginNames.Add(plugin.Name);
                            }
                        }
                        pluginAdvertising.AddPlugins(pluginNames);
                    };

                    SteamGameServer.SetKeyValue("unturned", Provider.APP_VERSION);
                    SteamGameServer.SetKeyValue("rocket", Assembly.GetExecutingAssembly().GetName().Version.ToString());
                }
                catch (Exception ex)
                {
                    Core.Logging.Logger.LogError("Steam can not be initialized: " + ex.Message);
                }

                OnRocketImplementationInitialized.TryInvoke();
            }
            catch (Exception ex)
            {
                Core.Logging.Logger.LogException(ex);
            }
        }