using System.Collections.Generic; using Oxide.Core; using Oxide.Plugins; using Newtonsoft.Json; using System.Linq; using ConVar; using UnityEngine; using Oxide.Core.Plugins; namespace Oxide.Plugins { [Info("AutoBanFreeEdition", "Grejory", "0.1.3")] [Description("Bans users based on reports and reasons.")] class AutoBanFreeEdition : RustPlugin { private ConfigData configData; class ConfigData { // Max number of allowed reports per user (set in config) [JsonProperty(PropertyName = "Max reports till user gets banned")] public int maxReports; // Valid report reasons (set in config) [JsonProperty(PropertyName = "Valid reasons *searches subject title of the report* ")] public List validReasons = new List(); } StoredData storedData; class StoredData { public Dictionary> reportedUsers = new Dictionary>(); } private bool LoadConfigVariables() { try { configData = Config.ReadObject(); } catch { return false; } SaveConfig(configData); return true; } void Init() { if (!LoadConfigVariables()) { Puts("Config file issue detected. Please delete file, or check syntax and fix."); return; } } protected override void LoadDefaultConfig() { Puts("Creating new config file."); configData = new ConfigData(); // Set default config values configData.maxReports = 5; configData.validReasons = new List() { "cheating", "aimbot", "hacking", "esp", "cheat" }; SaveConfig(configData); } void SaveConfig(ConfigData config) { Config.WriteObject(config, true); } void SaveData() { Interface.Oxide.DataFileSystem.WriteObject("AutoBanFreeEdition", storedData); } void OnPlayerReported(BasePlayer reporter, string targetName, string targetId, string subject, string message, string type) { bool isReportValid = false; storedData = Interface.Oxide.DataFileSystem.ReadObject("AutoBanFreeEdition"); // Check if the report reason is valid for (int i = 0; i < configData.validReasons.Count; i++) { if (subject.Contains(configData.validReasons[i]) || type.Contains(configData.validReasons[i])) { // Add the reported user and the reporting user to the dictionary if (storedData.reportedUsers.ContainsKey(targetId)) { if (!storedData.reportedUsers[targetId].Contains(reporter.UserIDString)) { storedData.reportedUsers[targetId].Add(reporter.UserIDString); Puts($"AutoBan: report added, {reporter.UserIDString} reported {targetId}"); } else { Puts($"AutoBan: {reporter.UserIDString} already reported {targetId}"); break; } } else { storedData.reportedUsers.Add(targetId, new List() { reporter.UserIDString }); Puts($"AutoBan: new report added, {reporter.UserIDString} reported {targetId}"); } // Check if the reported user has reached the max number of allowed reports if (storedData.reportedUsers[targetId].Count >= configData.maxReports) { // Ban the reported user ConsoleSystem.Run(ConsoleSystem.Option.Server.Quiet(), $"ban {targetId} \"AutoBan detected too many reports.\""); } isReportValid = true; SaveData(); break; } else { continue; } } if (!isReportValid) { Puts($"AutoBan: No valid reason found in report: {subject}"); } return; } } }