C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Oxide.Core.Libraries.Covalence;
namespace Oxide.Plugins
{
[Info("Whitelist", "Wulf/lukespragg", "2.2.2", ResourceId = 1932)]
[Description("Restricts server access to whitelisted players and Steam group members")]
class Whitelist : CovalencePlugin
{
// Do NOT edit this file, instead edit Whitelist.json in oxide/config and Whitelist.en.json in the oxide/lang directory,
// or create a new language file for another language using the 'en' file as a default
#region Initialization
const string permWhitelist = "whitelist.allowed";
void Init()
{
LoadDefaultConfig();
LoadDefaultMessages();
permission.RegisterPermission(permWhitelist, this);
GroupMembers();
timer.Every(updateInterval, GroupMembers);
}
#endregion
#region Configuration
bool adminExcluded;
string steamGroup;
int updateInterval;
protected override void LoadDefaultConfig()
{
Config["AdminExcluded"] = adminExcluded = GetConfig("AdminExcluded", true);
Config["SteamGroup"] = steamGroup = GetConfig("SteamGroup", "OxideMod");
Config["UpdateInterval"] = updateInterval = GetConfig("UpdateInterval", 300);
SaveConfig();
}
#endregion
#region Localization
void LoadDefaultMessages()
{
var messages = new Dictionary<string, string> { { "NotWhitelisted", "You are not whitelisted" } };
lang.RegisterMessages(messages, this);
}
#endregion
#region Steam Members
static readonly Regex IdPattern = new Regex(@"<steamID64>(?<steamid>.+)</steamID64>");
readonly HashSet<string> members = new HashSet<string>();
void GroupMembers()
{
if (string.IsNullOrEmpty(steamGroup))
{
PrintWarning("Plugin is not configured, please check the config");
return;
}
// Get Steam group members
var url = $"http://steamcommunity.com/groups/{steamGroup}/memberslistxml/?xml=1";
webrequest.EnqueueGet(url, (code, response) =>
{
if (code != 200 || response == null)
{
Puts($"Checking for Steam group members failed! ({code})");
Puts("Retrying in 5 seconds...");
timer.Once(5f, GroupMembers);
return;
}
foreach (Match match in IdPattern.Matches(response))
{
var id = match.Groups["steamid"].Value;
// Check if list contains Steam ID, else add
if (!members.Contains(id))
{
members.Add(id);
Puts($"{id} added to whitelist");
}
}
}, this);
}
[Command("whitelist")]
void UpdateCommand(IPlayer player, string command, string[] args) => GroupMembers();
#endregion
#region Whitelist Check
object CanUserLogin(string name, string id) => !IsWhitelisted(id) ? Lang("NotWhitelisted", id) : null;
bool IsWhitelisted(string id) => adminExcluded && IsAdmin(id) || members.Contains(id) || HasPermission(id, permWhitelist);
#endregion
#region Helpers
T GetConfig<T>(string name, T value) => Config[name] == null ? value : (T)Convert.ChangeType(Config[name], typeof(T));
string Lang(string key, string id = null, params object[] args) => string.Format(lang.GetMessage(key, this, id), args);
bool HasPermission(string id, string perm) => permission.UserHasPermission(id, perm);
bool IsAdmin(string id) => permission.UserHasGroup(id, "admin");
#endregion
}
}