using Newtonsoft.Json; using Oxide.Core; using System.Collections.Generic; namespace Oxide.Plugins { [Info("SimpleWhitelist", "Bubbafett,由可狼插件网_Rustnm.xyz提供汉化支持", "1.0.2")] [Description("允许白名单玩家进入服务器.")] public class SimpleWhitelist : RustPlugin { #region Config public Configuration PluginConfig; private static string _permAllow = "SimpleWhitelist.Allow"; public class Configuration { [JsonProperty(PropertyName = "可狼插件网提供汉化支持", Order = 0)] public string BaseSettingsNote = "https://rustnm.xyz/"; [JsonProperty(PropertyName = "版本号(禁止修改)", Order = int.MaxValue)] public VersionNumber Version = new VersionNumber(1, 0, 0); [JsonProperty(PropertyName = "启用白名单功能", Order = 1)] public bool Enabled = true; [JsonProperty(PropertyName = "使用权限系统", Order = 2)] public bool PermEnabled = false; [JsonProperty(PropertyName = "踢出提示信息", Order = 3)] public string KickMessage = "您未被列入本服务器的白名单,无法加入游戏"; [JsonProperty(PropertyName = "白名单Steam ID列表", Order = 10, ObjectCreationHandling = ObjectCreationHandling.Replace)] public List SteamIDs = new List { 0, 1 }; // 修改为传统初始化方式 } protected override void LoadConfig() { base.LoadConfig(); PluginConfig = Config.ReadObject(); if (PluginConfig == null) { PluginConfig = new Configuration(); SaveConfig(); return; } if (PluginConfig.Version >= Version) return; PrintWarning("可狼提示:检测到过时的配置文件,正在更新..."); UpdateConfig(); SaveConfig(); } private void UpdateConfig() { if (PluginConfig.Version >= Version) return; if (PluginConfig.Version <= new VersionNumber(1, 0, 0)) { } PluginConfig.Version = Version; SaveConfig(); } protected override void LoadDefaultConfig() => PluginConfig = new Configuration(); protected override void SaveConfig() => Config.WriteObject(PluginConfig, true); #endregion void Init() { permission.RegisterPermission(_permAllow, this); } object CanUserLogin(string name, string id, string ipAddress) { if (!PluginConfig.Enabled) return null; if (PluginConfig.PermEnabled && permission.UserHasPermission(id, _permAllow)) return null; if (ulong.TryParse(id, out ulong steamId) && PluginConfig.SteamIDs.Contains(steamId)) return null; return PluginConfig.KickMessage; } } }