C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Oxide.Core.Libraries.Covalence;
namespace Oxide.Plugins
{
[Info("AntiAds", "Wulf/lukespragg", "3.0.1", ResourceId = 1987)]
[Description("Blocks advertising not allowed servers and optionally kick or ban")]
class AntiAds : CovalencePlugin
{
// Do NOT edit this file, instead edit AntiAds.json in oxide/config and AntiAds.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 permBypass = "antiads.bypass";
void Loaded()
{
LoadDefaultConfig();
LoadDefaultMessages();
permission.RegisterPermission(permBypass, this);
}
#endregion
#region Configuration
List<object> allowedAds;
bool banInstantly;
bool kickInstantly;
protected override void LoadDefaultConfig()
{
Config["AllowedAds"] = allowedAds = GetConfig("AllowedAds", new List<object> { "8.8.8.8", "google.com", "oxidemod.org" });
Config["BanInstantly"] = banInstantly = GetConfig("BanInstantly", false);
Config["KickInstantly"] = kickInstantly = GetConfig("KickInstantly", false);
SaveConfig();
}
#endregion
#region Localization
void LoadDefaultMessages()
{
lang.RegisterMessages(new Dictionary<string, string>
{
["NotAllowed"] = "Advertising is not allowed on this server"
}, this);
}
#endregion
#region Ad Check
object OnUserChat(IPlayer player, string message)
{
if (!IsAdvertisement(message) || HasPermission(player.Id, permBypass)) return null;
player.Reply(Lang("NotAllowed", player.Id));
if (banInstantly) player.Ban(Lang("NotAllowed", player.Id));
else if (kickInstantly) player.Kick(Lang("NotAllowed", player.Id));
return true;
}
bool IsAdvertisement(string message)
{
if (allowedAds.Contains(message)) return false;
var ip = Regex.Match(message, @"(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})");
var domain = Regex.Match(message, @"(\w{2,}\.\w{2,3}\.\w{2,3}|\w{2,}\.\w{2,3})$");
return ip.Success || domain.Success;
}
#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
}
}