コード例 #1
0
        private void UpdateSteamGameServerValues()
        {
            if (Configuration.Instance.largeServer)
            {
                if (Provider.maxPlayers > 24)
                {
                    SteamGameServer.SetMaxPlayerCount(24);
                }
                else
                {
                    Logger.Log("Skipping large server due to server count being below 24 players");
                }
            }

            if (Configuration.Instance.gameName != null)
            {
                SteamGameServer.SetGameTags((!Provider.isPvP ? "PVE" : "PVP") + ",GAMEMODE:" + Configuration.Instance.gameName + ',' + (!Provider.hasCheats ? "STAEHC" : "CHEATS") + ',' + Provider.mode.ToString() + "," + Provider.cameraMode.ToString() + "," + (Provider.serverWorkshopFileIDs.Count <= 0 ? "KROW" : "WORK") + "," + (!Provider.isGold ? "YLNODLOG" : "GOLDONLY") + "," + (!Provider.configData.Server.BattlEye_Secure ? "BATTLEYE_OFF" : "BATTLEYE_ON"));
            }

            if (Configuration.Instance.hideWorkshop)
            {
                SteamGameServer.SetKeyValue("Browser_Workshop_Count", null);
            }

            if (Configuration.Instance.hideConfiguration)
            {
                SteamGameServer.SetKeyValue("Browser_Config_Count", null);
            }

            if (Configuration.Instance.rocketPlugins != null)
            {
                SteamGameServer.SetKeyValue("rocketplugins", string.Join(",", Configuration.Instance.rocketPlugins.ToArray()));
            }
        }
コード例 #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 += () =>
                    {
                        SteamGameServer.SetKeyValue("rocketplugins", String.Join(",", R.Plugins.GetPlugins().Select(p => p.Name).ToArray()));
                    };


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

                OnRocketImplementationInitialized.TryInvoke();
            }
            catch (Exception ex)
            {
                Core.Logging.Logger.LogException(ex);
            }
        }
コード例 #3
0
ファイル: CoopLobby.cs プロジェクト: DevZhav/The-Forest
 public void SetName(string name)
 {
     this.Info.Name = name;
     if (CoopPeerStarter.Dedicated)
     {
         SteamGameServer.SetKeyValue("name", name);
     }
     else
     {
         SteamMatchmaking.SetLobbyData(this.Info.LobbyId, "name", name);
     }
 }
コード例 #4
0
ファイル: CoopLobby.cs プロジェクト: DevZhav/The-Forest
 public void SetGuid(string guid)
 {
     CoopLobby.HostGuid = guid;
     this.Info.Guid     = guid;
     if (CoopPeerStarter.Dedicated)
     {
         SteamGameServer.SetKeyValue("guid", guid);
     }
     else
     {
         SteamMatchmaking.SetLobbyData(this.Info.LobbyId, "guid", guid);
     }
 }
コード例 #5
0
ファイル: CoopLobby.cs プロジェクト: DevZhav/The-Forest
 public void Destroy()
 {
     this.Info.Destroyed = true;
     SteamMatchmaking.SetLobbyJoinable(this.Info.LobbyId, false);
     if (CoopPeerStarter.Dedicated)
     {
         SteamGameServer.SetKeyValue("destroyed", "YES");
     }
     else
     {
         SteamMatchmaking.SetLobbyData(this.Info.LobbyId, "destroyed", "YES");
     }
 }
コード例 #6
0
        public static void SetModded()
        {
            try {
                using (TimeWarning.New("UpdateServerInformation", 0.1f)) {
                    SteamGameServer.SetServerName(ConVar.Server.hostname);
                    SteamGameServer.SetMaxPlayerCount(ConVar.Server.maxplayers);
                    SteamGameServer.SetPasswordProtected(false);
                    SteamGameServer.SetMapName(UnityEngine.SceneManagement.SceneManager.GetActiveScene().name);
                    string pchGameTags = string.Format("mp{0},cp{1},v{2}{3}{4}", new object[] {
                        ConVar.Server.maxplayers,
                        BasePlayer.activePlayerList.Count,
                        Rust.Protocol.network,
                        ConVar.Server.pve ? ",pve" : string.Empty,
                        pluton.enabled ? ",modded,pluton" : string.Empty
                    });

                    SteamGameServer.SetGameTags(pchGameTags);
                    string[] array = ConVar.Server.description.SplitToChunks(100).ToArray <string>();
                    for (int i = 0; i < 16; i++)
                    {
                        if (i < array.Length)
                        {
                            SteamGameServer.SetKeyValue(string.Format("description_{0:00}", i), array[i]);
                        }
                        else
                        {
                            SteamGameServer.SetKeyValue(string.Format("description_{0:00}", i), String.Empty);
                        }
                    }
                    SteamGameServer.SetKeyValue("country", SteamGameServerUtils.GetIPCountry());
                    SteamGameServer.SetKeyValue("world.seed", global::World.Seed.ToString());
                    SteamGameServer.SetKeyValue("world.size", global::World.Size.ToString());
                    SteamGameServer.SetKeyValue("official", ConVar.Server.official.ToString());
                    SteamGameServer.SetKeyValue("pve", ConVar.Server.pve.ToString());
                    SteamGameServer.SetKeyValue("headerimage", ConVar.Server.headerimage);
                    SteamGameServer.SetKeyValue("url", ConVar.Server.url);
                    SteamGameServer.SetKeyValue("uptime", ((int)Time.realtimeSinceStartup).ToString());
                    SteamGameServer.SetKeyValue("mem_ws", Performance.usedMemoryWorkingSetMB.ToString());
                    SteamGameServer.SetKeyValue("mem_pv", Performance.usedMemoryPrivateMB.ToString());
                    SteamGameServer.SetKeyValue("gc_mb", Performance.memoryAllocations.ToString());
                    SteamGameServer.SetKeyValue("gc_cl", Performance.memoryCollections.ToString());
                    SteamGameServer.SetKeyValue("fps", Performance.frameRate.ToString());
                    SteamGameServer.SetKeyValue("fps_avg", Performance.frameRateAverage.ToString("0.00"));
                    SteamGameServer.SetKeyValue("ent_cnt", BaseNetworkable.serverEntities.Count.ToString());
                    SteamGameServer.SetKeyValue("build", BuildInformation.VersionStampDays.ToString());
                }
            } catch (Exception ex) {
                Logger.LogError("[Hooks] Error while setting the server modded.");
                Logger.LogException(ex);
            }
        }
コード例 #7
0
        internal static void Init()
        {
            AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
            {
                if (Libraries.TryGetValue(args.Name, out var file))
                {
                    return(Assembly.LoadFrom(file));
                }

                Logger.LogError($"Could not find dependency: {args.Name}");
                return(null);
            };

            RegisterPlugins();

            var advertising = PluginAdvertising.Get();

            advertising.PluginFrameworkName = "rocket";
            advertising.AddPlugins(Plugins.Select(p => p.Name));

            SteamGameServer.SetKeyValue("unturned", Provider.APP_VERSION);
            SteamGameServer.SetKeyValue("rocket", "4.9.3.6");
        }
コード例 #8
0
        protected override void Load()
        {
            try
            {
                var stopwatch = Stopwatch.StartNew();

                Instance = this;

                R.Plugins.OnPluginsLoaded += OverrideCommands;

                TaskExecutor = new EssentialsTaskExecutor();

                SteamGameServer.SetKeyValue("essversion", PLUGIN_VERSION);

                Logger = new ConsoleLogger("[uEssentials] ");

                _consoleTraceListener = new EssentialsConsoleTraceListener();
                Debug.Listeners.Add(_consoleTraceListener);

                Provider.onServerDisconnected += PlayerDisconnectCallback;
                Provider.onServerConnected    += PlayerConnectCallback;

                Logger.LogInfo("Enabling uEssentials...");

                new[]
                {
                    "Plugin version: ~white~" + PLUGIN_VERSION + BUILD_INFO,
                    "Recommended Rocket version: ~white~" + ROCKET_VERSION,
                    "Recommended Unturned version: ~white~" + UNTURNED_VERSION,
                    "Author: ~white~leonardosnt",
                    "Wiki: ~white~uessentials.github.io",
                }.ForEach(text => Logger.LogInfo(text, true));

                if (Provider.clients.Count > 0)
                {
                    Provider.clients.ForEach(p =>
                    {
                        ConnectedPlayers.Add(p.playerID.steamID.m_SteamID,
                                             new UPlayer(UnturnedPlayer.FromSteamPlayer(p)));
                    });
                }

                _folder            = Rocket.Core.Environment.PluginsDirectory + "/uEssentials/";
                _translationFolder = Folder + "translations/";
                _dataFolder        = Folder + "data/";
                _modulesFolder     = Folder + "modules/";

                CommandOptions = new CommandOptions();
                Updater        = new GithubUpdater();
                EventManager   = new EventManager();
                CommandManager = new CommandManager();
                ModuleManager  = new ModuleManager();
                HookManager    = new HookManager();

                WebResources = new WebResources();
                Config       = new EssConfig();

                var webResourcesPath = Path.Combine(Folder, WebResources.FileName);
                var configPath       = Path.Combine(Folder, Config.FileName);

                WebResources.Load(webResourcesPath);

                // Sync web config with local config.json
                if (WebResources.Loaded.ContainsKey("Config"))
                {
                    File.WriteAllText(configPath, WebResources.Loaded["Config"]);
                }

                Config.Load(configPath);
                CommandOptions.Load(Path.Combine(Folder, CommandOptions.FileName));
                EssLang.Load();

                EventManager.RegisterAll(GetType().Assembly);

                // Register all commands from namespace Essentials.Commands
                CommandManager.RegisterAll("Essentials.Commands");

                HookManager.RegisterAll();
                HookManager.LoadAll();

                // Load after EventManager because we relies on it inside this routine.
                ConfigPostLoad();

                LoadNativeModules();

                Logger.LogInfo("Loading modules...");
                ModuleManager.LoadAll(ModulesFolder);
                Logger.LogInfo($"Loaded {ModuleManager.RunningModules.Count(t => !(t is NativeModule))} modules");

                // We log it here because the modules being loaded above can
                // register commands.
                Logger.LogInfo($"Loaded {CommandManager.Commands.Count()} commands");

#if EXPERIMENTAL
                Logger.LogWarning("THIS IS AN EXPERIMENTAL BUILD, IT CAN BE BUGGY.");
                Logger.LogWarning("THIS IS AN EXPERIMENTAL BUILD, IT CAN BE BUGGY.");
#endif

                // Delete useless files generated by Rocket
                Task.Create()
                .Id("Delete Xml Files")
                .Delay(TimeSpan.FromSeconds(1))
                .Async()
                .Action(() =>
                {
                    File.Delete($"{Folder}uEssentials.en.translation.xml");
                    File.Delete($"{Folder}uEssentials.configuration.xml");
                })
                .Submit();

                // If _wasLoadedBefore, then it means that uEssentials is
                // being reloaded, and it also means that R.Plugins.OnPluginsLoaded will not be called,
                // consequently OverrideCommands will not be called too
                // so we need to call it here.
                if (_wasLoadedBefore)
                {
                    OverrideCommands();
                }

                _wasLoadedBefore = true;
                CommandWindow.input.onInputText += ReloadCallback;
                Logger.LogInfo($"Enabled ({stopwatch.ElapsedMilliseconds} ms)");
            }
            catch (Exception e)
            {
                string[] messages =
                {
                    "An error occurred while enabling uEssentials.",
                    "If this error is not related with wrong configuration, please report",
                    "it here https://github.com/uEssentials/uEssentials/issues",
                    "Error: " + e
                };

                if (Logger == null)
                {
                    Console.BackgroundColor = ConsoleColor.Red;
                    messages.ForEach(Console.WriteLine);
                    Console.BackgroundColor = ConsoleColor.White;
                }
                else
                {
                    messages.ForEach(m => Logger.LogError(m));
                }
            }

#if !DEV
            Analytics.SendEvent($"ServerInit");
#endif

#if DEV
            Console.Title = "Unturned Server";
#else
            CheckUpdates();
#endif
        }
コード例 #9
0
 private void OnServerInitialized()
 {
     SteamGameServer.SetKeyValue("untured", Provider.APP_VERSION);
     SteamGameServer.SetKeyValue("pointblank", PointBlankInfo.Version);
 }
コード例 #10
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>();
                Events = new UnturnedEvents();
                Events.Awake();
                //gameObject.TryAddComponent<UnturnedPermissions>();
                //gameObject.TryAddComponent<UnturnedChat>();
                SDG.Unturned.ChatManager.onChatted += UnturnedChat.handleChat;
                //gameObject.TryAddComponent<UnturnedCommands>();
                foreach (Command vanillaCommand in Commander.commands)
                {
                    R.Commands.Register(new UnturnedCommands.UnturnedVanillaCommand(vanillaCommand), vanillaCommand.command.ToLower(), Core.Serialization.CommandPriority.Low);
                }
                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
                {
                    if (!Settings.Instance.HidePlugins)
                    {
                        R.Plugins.OnPluginsLoaded += () =>
                        {
                            var plugs = R.Plugins.GetPlugins();
                            var names = new string[plugs.Count];
                            for (int i = 0; i < names.Length; i++)
                            {
                                names[i] = plugs[i].Name;
                            }
                            SteamGameServer.SetKeyValue("rocketplugins", string.Join(",", names));
                        };
                    }
                    if (Settings.Instance.ClampMaxPlayers)
                    {
                        Level.onPreLevelLoaded += ClampMaxPlayers;
                    }

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

                OnRocketImplementationInitialized.TryInvoke();
            }
            catch (Exception ex)
            {
                Core.Logging.Logger.LogException(ex);
            }
        }
コード例 #11
0
        private void EditLobby()
        {
            string mode;
            string perspective;
            string thumbnail;
            bool   workshop = Provider.getServerWorkshopFileIDs().Count > 0;

            #region Plugins
            if (m_Configuration.GetSection("Hide:Rocket").Get <bool>())
            {
                SteamGameServer.SetBotPlayerCount(0);
            }

            if (!m_Configuration.GetSection("Hide:Plugins").Get <bool>())
            {
                if (m_Configuration.GetSection("Edit:Plugins").Get <bool>())
                {
                    SteamGameServer.SetKeyValue("rocketplugins", string.Join(",", m_Configuration.GetSection("PluginsOverride").Get <string[]>()));
                }
                else
                {
                    SteamGameServer.SetKeyValue("rocketplugins", string.Join(",", m_PluginActivator.ActivatedPlugins.ToList().Select(p => p.DisplayName).ToArray()));
                }
            }
            else
            {
                SteamGameServer.SetKeyValue("rocketplugins", "");
            }

            if (m_Configuration.GetSection("GameTags:Vanilla").Get <bool>())
            {
                SteamGameServer.SetBotPlayerCount(0);
                SteamGameServer.SetKeyValue("rocketplugins", "");
                SteamGameServer.SetKeyValue("rocket", "");
            }
            else
            {
                if (!m_Configuration.GetSection("Hide:Rocket").Get <bool>())
                {
                    SteamGameServer.SetBotPlayerCount(1);
                }

                if (!m_Configuration.GetSection("Hide:Plugins").Get <bool>() && !m_Configuration.GetSection("Edit:Plugins").Get <bool>())
                {
                    SteamGameServer.SetKeyValue("rocketplugins", string.Join(",", m_PluginActivator.ActivatedPlugins.ToList().Select(p => p.DisplayName).ToArray()));
                }

                string version = ModuleHook.modules.Find(a => a.config.Name == "Rocket.Unturned")?.config.Version ?? "4.9.3.3";
                SteamGameServer.SetKeyValue("rocket", version);
            }
            #endregion

            #region Workshops

            /*if (Configuration.Instance.HideWorkshop)
             * {
             *  workshop = false;
             *  SteamGameServer.SetKeyValue("Browser_Workshop_Count", "0");
             * }
             * else if (Configuration.Instance.EditWorkshop)
             * {
             *  workshop = true;
             *  string txt = string.Join(",", Configuration.Instance.Workshop);
             *  SteamGameServer.SetKeyValue("Browser_Workshop_Count", ((txt.Length - 1) / 120 + 1).ToString());
             *
             *  int line = 0;
             *  for (int i = 0; i < txt.Length; i += 120)
             *  {
             *      int num6 = 120;
             *
             *      if (i + num6 > txt.Length)
             *          num6 = txt.Length - i;
             *
             *      string pValue2 = txt.Substring(i, num6);
             *      SteamGameServer.SetKeyValue("Browser_Workshop_Line_" + line, pValue2);
             *      line++;
             *  }
             * }
             * else
             * {
             *  SteamGameServer.SetKeyValue("Browser_Workshop_Count", GetWorkshopCount().ToString());
             * }*/
            #endregion

            #region Configs
            if (m_Configuration.GetSection("Hide:Config").Get <bool>())
            {
                SteamGameServer.SetKeyValue("Browser_Config_Count", "0");
            }
            else
            {
                SteamGameServer.SetKeyValue("Browser_Config_Count", GetConfigurationCount().ToString());
            }

            switch (m_Configuration["GameTags:Mode"].ToLower().Trim())
            {
            case "easy":
                mode = "EZY";
                break;

            case "hard":
                mode = "HRD";
                break;

            default:
                mode = "NRM";
                break;
            }

            switch (m_Configuration["GameTags:Perspective"].ToLower().Trim())
            {
            case "first":
                perspective = "1Pp";
                break;

            case "third":
                perspective = "3Pp";
                break;

            case "vehicle":
                perspective = "4Pp";
                break;

            default:
                perspective = "2Pp";
                break;
            }
            #endregion

            #region Thumbnail
            if (!m_Configuration.GetSection("Hide:Thumbnail").Get <bool>())
            {
                switch (m_Configuration.GetSection("Edit:Thumbnail").Get <bool>())
                {
                case true:
                    thumbnail = m_Configuration["ThumbnailOverride"];
                    break;

                case false:
                    thumbnail = Provider.configData.Browser.Thumbnail;
                    break;

                default:
                    thumbnail = Provider.configData.Browser.Thumbnail;
                    break;
                }
            }
            else
            {
                thumbnail = "";
            }
            #endregion

            #region GameTags
            string tags = string.Concat(new string[]
            {
                m_Configuration.GetSection("GameTags:PVP").Get <bool>() ? "PVP" : "PVE",
                ",<gm>",
                m_Configuration["GameTags:GameMode"],
                "</gm>,",
                m_Configuration.GetSection("GameTags:Cheats").Get <bool>() ? "CHy" : "CHn",
                ",",
                mode,
                ",",
                perspective,
                ",",
                workshop ? "WSy" : "WSn",
                ",", m_Configuration.GetSection("GameTags:Gold").Get <bool>() ? "GLD" : "F2P",
                ",", m_Configuration.GetSection("GameTags:BattlEyeSecure").Get <bool>() ? "BEy" : "BEn",
                ",<tn>", thumbnail, "</tn>"
            });
            SteamGameServer.SetGameTags(tags);
            #endregion
        }
コード例 #12
0
        public void ModifyGameTags()
        {
            string tags = "";

            #region Workshop
            if (Configuration.Instance.HideWorkshop)
            {
                tags += "KROW"; // No workshop
                SteamGameServer.SetKeyValue("Browser_Workshop_Count", "0");
            }
            else if (Configuration.Instance.MessWorkshop)
            {
                tags += "WORK"; // Workshop

                string txt = "";
                foreach (string a in Configuration.Instance.Workshop)
                {
                    if (txt.Length > 0)
                    {
                        txt += ",";
                    }
                    txt += a;
                }
                SteamGameServer.SetKeyValue("Browser_Workshop_Count", ((txt.Length - 1) / 120 + 1).ToString());

                int num5 = 0;
                for (int m = 0; m < txt.Length; m += 120)
                {
                    int num6 = 120;
                    if (m + num6 > txt.Length)
                    {
                        num6 = txt.Length - m;
                    }
                    string pValue2 = txt.Substring(m, num6);
                    SteamGameServer.SetKeyValue("Browser_Workshop_Line_" + num5, pValue2);
                    num5++;
                }
            }
            else
            {
                if (Provider.serverWorkshopFileIDs.Count <= 0)
                {
                    tags += "KROW";
                }
                else
                {
                    tags += "WORK"; // Workshop
                    SteamGameServer.SetKeyValue("Browser_Workshop_Count", GetWorkshopCount().ToString());
                }
            }
            #endregion

            #region Gamemode
            if (Configuration.Instance.MessGamemode)
            {
                tags += ",GAMEMODE:" + Configuration.Instance.Gamemode;
            }
            else if (Provider.gameMode != null)
            {
                tags += ",GAMEMODE:" + Provider.gameMode.GetType().Name;
            }
            #endregion

            #region Config
            if (Configuration.Instance.MessConfig)
            {
                tags += ",";
                if (Configuration.Instance.IsPVP)
                {
                    tags += "PVP";
                }
                else
                {
                    tags += "PVE";
                }
                tags += ",";
                if (Configuration.Instance.HasCheats)
                {
                    tags += "CHEATS";
                }
                else
                {
                    tags += "STAEHC";
                }
                tags += ",";
                tags += Configuration.Instance.Difficulty;
                tags += ",";
                tags += Configuration.Instance.CameraMode;
                tags += ",";
                if (Configuration.Instance.GoldOnly)
                {
                    tags += "GOLDONLY";
                }
                else
                {
                    tags += "YLNODLOG";
                }
                tags += ",";
                if (Configuration.Instance.HasBattleye)
                {
                    tags += "BATTLEYE_ON";
                }
                else
                {
                    tags += "BATTLEYE_OFF";
                }
            }
            else
            {
                tags += ",";
                tags += (!Provider.isPvP) ? "PVE" : "PVP";
                tags += ",";
                tags += (!Provider.hasCheats) ? "STAEHC" : "CHEATS";
                tags += ",";
                tags += Provider.mode.ToString();
                tags += ",";
                tags += Provider.cameraMode.ToString();
                tags += ",";
                tags += (!Provider.isGold) ? "YLNODLOG" : "GOLDONLY";
                tags += ",";
                tags += (!Provider.configData.Server.BattlEye_Secure) ? "BATTLEYE_OFF" : "BATTLEYE_ON";
            }
            #endregion

            #region Configuration
            if (Configuration.Instance.HideConfig)
            {
                SteamGameServer.SetKeyValue("Browser_Config_Count", "0");
            }
            else
            {
                SteamGameServer.SetKeyValue("Browser_Config_Count", GetConfigurationCount().ToString());
            }
            #endregion

            SteamGameServer.SetGameTags(tags);

            #region Plugins
            if (Configuration.Instance.InvisibleRocket)
            {
                SteamGameServer.SetBotPlayerCount(0); // Bypasses unturned's filter for rocket <3
            }
            if (!Configuration.Instance.HidePlugins)
            {
                if (Configuration.Instance.MessPlugins)
                {
                    SteamGameServer.SetKeyValue("rocketplugins", string.Join(",", Configuration.Instance.Plugins));
                }
                else
                {
                    SteamGameServer.SetKeyValue("rocketplugins", string.Join(",", R.Plugins.GetPlugins().Select(p => p.Name).ToArray()));
                }
            }
            else
            {
                SteamGameServer.SetKeyValue("rocketplugins", "");
            }

            if (Configuration.Instance.IsVannila)
            {
                SteamGameServer.SetBotPlayerCount(0);
                SteamGameServer.SetKeyValue("rocketplugins", "");
                SteamGameServer.SetKeyValue("rocket", "");
            }
            else
            {
                if (!Configuration.Instance.InvisibleRocket)
                {
                    SteamGameServer.SetBotPlayerCount(1);
                }
                if (!Configuration.Instance.HidePlugins && !Configuration.Instance.MessPlugins)
                {
                    SteamGameServer.SetKeyValue("rocketplugins", string.Join(",", R.Plugins.GetPlugins().Select(p => p.Name).ToArray()));
                }
                SteamGameServer.SetKeyValue("rocket", ModuleHook.modules.FirstOrDefault(a => a.config.Name == "Rocket.Unturned").config.Version);
            }
            #endregion
        }
コード例 #13
0
 private void OnLevelLoaded(int level)
 {
     SteamGameServer.SetKeyValue("Browser_Config_Count", "0");
 }
コード例 #14
0
ファイル: Plugin.cs プロジェクト: TrueThat/ServerSettings
 public void OnServerLoad()
 {
     if (Configuration.Instance.Enabled)
     {
         if (Configuration.Instance.ResetToDefault)
         {
             SteamGameServer.SetKeyValue("rocketplugins", string.Join(",", R.Plugins.GetPlugins().Select(p => p.Name).ToArray()));
         }
         else
         {
             if (Configuration.Instance.HideRocketPlugins)
             {
                 SteamGameServer.SetKeyValue("rocketplugins", "");
                 Logger.Log("SS - Hidden Rocket Plugins! :^) ");
             }
             if (Configuration.Instance.ReplaceRocketPlugins)
             {
                 SteamGameServer.SetKeyValue("rocketplugins", Configuration.Instance.CustomRocketPluginsText);
                 Logger.Log("SS - Replaced Rocket Plugins Text! :^) ");
             }
             if (Configuration.Instance.HideWorkshopItems)
             {
                 SteamGameServer.SetKeyValue("Browser_Workshop_Count", "0");
                 Logger.Log("SS - Hidden Workshop Items! :^) ");
             }
             if (Configuration.Instance.ReplaceWorkshopItems)
             {
                 SteamGameServer.SetKeyValue("Browser_Workshop_Count", Configuration.Instance.WorkshopLinesCount.ToString());
                 SteamGameServer.SetKeyValue("Browser_Workshop_Line", Configuration.Instance.CustomWorkshopItemsText);
                 Logger.Log("SS - Replaced Workshop Items Text! :^) ");
             }
             if (Configuration.Instance.HideConfigItems)
             {
                 SteamGameServer.SetKeyValue("Browser_Config_Count", "0");
                 Logger.Log("SS - Hidden Config Items! :^) ");
             }
             if (Configuration.Instance.ReplaceConfigItems)
             {
                 SteamGameServer.SetKeyValue("Browser_Config_Count", Configuration.Instance.ConfigLinesCount.ToString());
                 SteamGameServer.SetKeyValue("Browser_Config_Line", Configuration.Instance.CustomConfigItemsText);
                 Logger.Log("SS - Replace Config Items Text! :^) ");
             }
             if (Configuration.Instance.EnableCustomMapName)
             {
                 SteamGameServer.SetMapName(Configuration.Instance.MapCustomName);
                 Logger.Log("SS - Set Map Name to (" + Configuration.Instance.MapCustomName + ") ! :^) ");
             }
             if (Configuration.Instance.EnableMaxPlayers)
             {
                 SteamGameServer.SetMaxPlayerCount(Configuration.Instance.MaxServerPlayers);
                 Logger.Log("SS - Set Max players count to (" + Configuration.Instance.MaxServerPlayers + ") ! :^) ");
             }
             if (Configuration.Instance.EnableCustomServerName)
             {
                 SteamGameServer.SetServerName(Configuration.Instance.ServerName);
                 Logger.Log("SS - Set Server Name to (" + Configuration.Instance.ServerName + ") ! :^) ");
             }
             Logger.Log("SS - Done!");
         }
     }
     else
     {
         Logger.Log("SS - Please Enable me in the Configuration in order for me to work :D!");
         Unload();
     }
 }
コード例 #15
0
        protected override void Load()
        {
            try {
                var stopwatch = Stopwatch.StartNew();

                Instance = this;

                try {
                    var essPermProvider = new EssentialsPermissionsProvider();
                    R.Permissions = essPermProvider;
                } catch (Exception ex) {
                    Console.Error.WriteLine(ex);
                }

                R.Plugins.OnPluginsLoaded += OverrideCommands;

                TaskExecutor = new EssentialsTaskExecutor();

                SteamGameServer.SetKeyValue("essversion", PLUGIN_VERSION);

                Logger           = new ConsoleLogger("[uEssentials] ");
                ConnectedPlayers = new Dictionary <ulong, UPlayer>();
                Debug.Listeners.Add(new EssentialsConsoleTraceListener());

                Provider.onServerDisconnected += PlayerDisconnectCallback;
                Provider.onServerConnected    += PlayerConnectCallback;

                Logger.LogInfo("Enabling uEssentials...");

                if (Provider.clients.Count > 0)
                {
                    Provider.clients.ForEach(p => {
                        ConnectedPlayers.Add(p.playerID.steamID.m_SteamID,
                                             new UPlayer(UnturnedPlayer.FromSteamPlayer(p)));
                    });
                }

                _folder            = Rocket.Core.Environment.PluginsDirectory + "/uEssentials/";
                _translationFolder = Folder + "translations/";
                _dataFolder        = Folder + "data/";
                _modulesFolder     = Folder + "modules/";

                WebResources = new WebResources();
                Config       = new EssConfig();

                var webResourcesPath = Path.Combine(Folder, WebResources.FileName);
                var configPath       = Path.Combine(Folder, Config.FileName);

                WebResources.Load(webResourcesPath);

                // Sync web config with local config.json
                if (WebResources.Loaded.ContainsKey("Config"))
                {
                    File.WriteAllText(configPath, WebResources.Loaded["Config"]);
                }

                Config.Load(configPath);

                CommandOptions = new CommandOptions();
                CommandOptions.Load(Path.Combine(Folder, CommandOptions.FileName));

                Updater        = new GithubUpdater();
                EventManager   = new EventManager();
                CommandManager = new CommandManager();
                ModuleManager  = new ModuleManager();
                HookManager    = new HookManager();

                EssLang.Load();

                new [] {
                    "Plugin version: ~white~" + PLUGIN_VERSION + BUILD_INFO,
                    "Recommended Rocket version: ~white~" + ROCKET_VERSION,
                    "Recommended Unturned version: ~white~" + UNTURNED_VERSION,
                    "Author: ~white~leonardosnt",
                    "Wiki: ~white~uessentials.github.io",
                }.ForEach(text => Logger.LogInfo(text, true));

                EventManager.RegisterAll(GetType().Assembly);

                if (!Config.EnableJoinLeaveMessage)
                {
                    EventManager.Unregister <EssentialsEventHandler>("JoinMessage");
                    EventManager.Unregister <EssentialsEventHandler>("LeaveMessage");
                }

                // Register all commands from namespace Essentials.Commands
                CommandManager.RegisterAll("Essentials.Commands");

                HookManager.RegisterAll();
                HookManager.LoadAll();

                if (Config.Economy.UseXp)
                {
                    EconomyProvider = Optional <IEconomyProvider> .Of(new ExpEconomyProvider());
                }
                else if (HookManager.GetActiveByType <AviEconomyHook>().IsPresent)
                {
                    EconomyProvider = Optional <IEconomyProvider> .Of(HookManager.GetActiveByType <AviEconomyHook>().Value);
                }
                else if (HookManager.GetActiveByType <UconomyHook>().IsPresent)
                {
                    EconomyProvider = Optional <IEconomyProvider> .Of(HookManager.GetActiveByType <UconomyHook>().Value);
                }
                else
                {
                    EconomyProvider = Optional <IEconomyProvider> .Empty();
                }

                LoadNativeModules();

                Logger.LogInfo($"Loaded {CommandManager.Commands.Count()} commands");

                Logger.LogInfo("Loading modules...");
                ModuleManager.LoadAll(ModulesFolder);
                Logger.LogInfo($"Loaded {ModuleManager.RunningModules.Count(t => !(t is NativeModule))} modules");

                if (Config.AutoAnnouncer.Enabled)
                {
                    Config.AutoAnnouncer.Start();
                }

                if (Config.AutoCommands.Enabled)
                {
                    Config.AutoCommands.Start();
                }

                if (!Config.Updater.AlertOnJoin)
                {
                    EventManager.Unregister <EssentialsEventHandler>("UpdateAlert");
                }

                if (Config.ServerFrameRate != -1)
                {
                    var frameRate = Config.ServerFrameRate;

                    if (Config.ServerFrameRate < -1)
                    {
                        frameRate = -1; // Set to default
                    }

                    UnityEngine.Application.targetFrameRate = frameRate;
                }

                if (Config.DisabledCommands.Count != 0)
                {
                    Config.DisabledCommands.ForEach(cmdName => {
                        var command = CommandManager.GetByName(cmdName);

                        if (command == null || command is CommandEssentials)
                        {
                            Logger.LogWarning($"There is no command named '{cmdName}' to disable.");
                        }
                        else
                        {
                            CommandManager.Unregister(command);
                            Logger.LogInfo($"Disabled command: '{command.Name}'");
                        }
                    });
                }

                if (Config.EnableTextCommands)
                {
                    TextCommands = new TextCommands();

                    var textCommandsFile = Path.Combine(Folder, TextCommands.FileName);

                    TextCommands.Load(textCommandsFile);

                    TextCommands.Commands.ForEach(txtCommand => {
                        CommandManager.Register(new TextCommand(txtCommand));
                    });
                }

                if (!Config.EnableDeathMessages)
                {
                    EventManager.Unregister <EssentialsEventHandler>("DeathMessages");
                }

#if EXPERIMENTAL
                Logger.LogWarning("THIS IS AN EXPERIMENTAL BUILD, CAN BE BUGGY.");
                Logger.LogWarning("THIS IS AN EXPERIMENTAL BUILD, CAN BE BUGGY.");
#endif

                // Delete useless files generated by Rocket
                Task.Create()
                .Id("Delete Xml Files")
                .Delay(TimeSpan.FromSeconds(1))
                .Async()
                .Action(() => {
                    File.Delete($"{Folder}uEssentials.en.translation.xml");
                    File.Delete($"{Folder}uEssentials.configuration.xml");
                })
                .Submit();

                CommandWindow.input.onInputText += ReloadCallback;
                Logger.LogInfo($"Enabled ({stopwatch.ElapsedMilliseconds} ms)");
            } catch (Exception e) {
                var msg = new List <string>()
                {
                    "An error occurred while enabling uEssentials.",
                    "If this error is not related with wrong configuration please report",
                    "immediatly here https://github.com/uEssentials/uEssentials/issues",
                    "Error: " + e
                };

                if (!Provider.APP_VERSION.EqualsIgnoreCase(UNTURNED_VERSION))
                {
                    msg.Add("I detected that you are using a different version of the recommended, " +
                            "please update your uEssentials/Unturned.");
                    msg.Add("If you are using the latest uEssentials release, please wait for update.");
                }

                if (Logger == null)
                {
                    Console.BackgroundColor = ConsoleColor.Red;
                    msg.ForEach(Console.WriteLine);
                    Console.BackgroundColor = ConsoleColor.White;
                }
                else
                {
                    msg.ForEach(Logger.LogError);
                }
            }

#if !DEV
            Analytics.SendEvent($"ServerInit");
#endif

#if DEV
            Console.Title = "Unturned Server";
#else
            CheckUpdates();
#endif
        }
コード例 #16
0
 protected override void Load() => Rocket.Core.R.Plugins.OnPluginsLoaded += () =>
 {
     SteamGameServer.SetKeyValue("Browser_Workshop_Count", "0");
     SteamGameServer.SetKeyValue("rocketplugins", "");
     SteamGameServer.SetKeyValue("Browser_Config_Count", "0");
 };
コード例 #17
0
        private void OnPluginsLoaded()
        {
            string plugins = string.Join(",", PM.LoadedPlugins.Select(a => PM.GetPluginName(a)).ToArray());

            SteamGameServer.SetKeyValue("pointblankplugins", plugins);
        }
コード例 #18
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);
            }
        }
コード例 #19
0
 private void OnLevelLoaded(int level)
 {
     //HIDE SERVER CONFIG CHANGES
     SteamGameServer.SetKeyValue("Browser_Config_Count", null);
 }