/// <summary> /// Get all the watchlist or <see cref="Collections.Player"/> watchlist. /// </summary> /// <param name="player">The <see cref="Collections.Player"/> player, but can be null.</param> /// <returns> the watchlist.</returns> public static string GetWatchList([CanBeNull] Collections.Player player) { StringBuilder text = StringBuilderPool.Shared.Rent().AppendLine(); if (player == null) { text.AppendLine($"WatchList ({WatchListCollection.Count()})").AppendLine(); foreach (WatchList wl in WatchListCollection.FindAll().ToList()) { text.AppendLine($"Target: {wl.Target.Name} ({wl.Target.Id}@{wl.Target.Authentication})") .AppendLine($"Issuer: {wl.Issuer.Name} ({wl.Issuer.Id}@{wl.Issuer.Authentication})") .AppendLine($"Reason: {wl.Reason}").AppendLine($"ID: {wl.WatchListId}") .AppendLine($"Date: {wl.Date}").AppendLine($"Server sender Port: {wl.Server}").AppendLine(); } return(StringBuilderPool.Shared.ToStringReturn(text)); } text.AppendLine($"WatchList ({player.Name} - {player.Id}@{player.Authentication})").AppendLine(); foreach (WatchList wl in WatchListCollection.Find(wl => wl.Target.Id == player.Id).ToList()) { text.AppendLine($"Target: {wl.Target.Name} ({wl.Target.Id}@{wl.Target.Authentication})") .AppendLine($"Issuer: {wl.Issuer.Name} ({wl.Issuer.Id}@{wl.Issuer.Authentication})") .AppendLine($"Reason: {wl.Reason}").AppendLine($"ID: {wl.WatchListId}") .AppendLine($"Date: {wl.Date}").AppendLine($"Server sender Port: {wl.Server}").AppendLine(); } return(StringBuilderPool.Shared.ToStringReturn(text)); }
/// <summary> /// Check if exists a specified punish. /// </summary> /// <param name="player">The <see cref="Collections.Player"/> player.</param> /// <param name="type"> the <see cref="Enums.PunishType"/>.</param> /// <param name="id"> the punish id.</param> /// <param name="server"> the server port.</param> /// <returns> true if the punish exists, false if not.</returns> public static bool CheckId(Collections.Player player, PunishType?type, int id, int server) { switch (type) { case PunishType.Ban: return(BanCollection.Exists(ban => ban.Target == player && ban.BanId == id && ban.Server == server)); case PunishType.Kick: return(KickCollection.Exists(kick => kick.Target == player && kick.KickId == id && kick.Server == server)); case PunishType.Mute: return(MuteCollection.Exists(mute => mute.Target == player && mute.MuteId == id && mute.Server == server)); case PunishType.Warn: return(WarnCollection.Exists(warn => warn.Target == player && warn.WarnId == id && warn.Server == server)); case PunishType.SoftWarn: return(SoftWarnCollection.Exists(sw => sw.Target == player && sw.SoftWarnId == id && sw.Server == server)); case PunishType.SoftBan: return(SoftBanCollection.Exists(sb => sb.Target == player && sb.SoftBanId == id && sb.Server == server)); case PunishType.WatchList: return(WatchListCollection.Exists(wl => wl.Target == player && wl.WatchListId == id && wl.Server == server)); default: return(false); } }
/// <summary> /// Clear all punishment from player <see cref="Player"/>. /// </summary> /// <param name="player">The <see cref="Collections.Player"/> player.</param> public static void Clear(this Collections.Player player) { BanCollection.DeleteMany(p => p.Target == player); MuteCollection.DeleteMany(p => p.Target == player); KickCollection.DeleteMany(p => p.Target == player); WarnCollection.DeleteMany(p => p.Target == player); SoftBanCollection.DeleteMany(p => p.Target == player); SoftWarnCollection.DeleteMany(p => p.Target == player); WatchListCollection.DeleteMany(p => p.Target == player); JsonManager.PunishToCache(PunishType.All, JsonConvert.SerializeObject(player), player, ActionType.Remove); }
public bool Execute(ArraySegment <string> arguments, ICommandSender sender, out string response) { MuteTranslation muteTranslation = Plugin.Singleton.Config.Translation.MuteTranslation; if (!sender.CheckPermission("ms.mute")) { response = muteTranslation.InvalidPermission.Replace("{permission}", "ms.mute"); return(false); } if (arguments.Count < 2) { response = muteTranslation.WrongUsage; return(false); } HashSet <Collections.Player> targets = new(); if (arguments.At(0).Split(',').Length > 1) { foreach (var player in arguments.At(0).Split(',')) { Collections.Player target = player.GetPlayer(); if (target is null) { response = muteTranslation.PlayerNotFound.Replace("{target}", player); continue; } if (targets.Contains(target)) { continue; } targets.Add(target); } } else { Collections.Player dPlayer = arguments.At(0).GetPlayer(); if (dPlayer == null) { response = muteTranslation.PlayerNotFound.Replace("{player}", arguments.At(0)); return(false); } if (!targets.Contains(dPlayer)) { targets.Add(dPlayer); } } DateTime?duration = ModerationSystemAPI.ConvertToDateTime(arguments.At(1)); if (duration == null) { response = muteTranslation.InvalidDuration.Replace("{duration}", arguments.At(1)); return(false); } string reason = string.Join(" ", arguments.Skip(2).Take(arguments.Count - 2)); if (string.IsNullOrEmpty(reason)) { response = muteTranslation.ReasonNull; return(false); } if (!ModerationSystemAPI.MaxDuration(arguments.At(1), Player.Get(sender))) { response = "You can't do this duration"; return(false); } foreach (var dPlayer in targets) { if (dPlayer.IsMuted()) { response = muteTranslation.PlayerAlreadyMuted; return(false); } ModerationSystemAPI.ApplyPunish(Player.Get($"{dPlayer.Id}@{dPlayer.Authentication}"), ((CommandSender)sender).GetStaffer(), dPlayer, PunishType.Mute, reason, arguments.At(1)); ModerationSystemAPI.SendBroadcast(new Exiled.API.Features.Broadcast(Plugin.Singleton.Config.Translation.StaffTranslation.StaffMuteMessage.Content.Replace("{staffer}", sender.LogName).Replace("{target}", $"{dPlayer.Name} {dPlayer.Id}{dPlayer.Authentication}").Replace("{reason}", reason).Replace("{time}", duration.ToString()))); response = muteTranslation.PlayerMuted.Replace("{player.name}", dPlayer.Name).Replace("{player.userid}", $"{dPlayer.Id}@{dPlayer.Authentication}").Replace("{duration}", duration.ToString()).Replace("{reason}", reason); } response = ""; return(true); }
public bool Execute(ArraySegment <string> arguments, ICommandSender sender, out string response) { WatchListTranslation watchListTranslation = Plugin.Singleton.Config.Translation.WatchListTranslation; if (!sender.CheckPermission("ms.watchlist")) { response = watchListTranslation.InvalidPermission.Replace("{duration}", "ms.watchlist"); return(false); } if (arguments.Count == 0 || (arguments.Count == 1 && arguments.At(0) == "add")) { response = watchListTranslation.WrongUsage; return(false); } switch (arguments.At(0)) { case "add": string reason = string.Join(" ", arguments.Skip(2).Take(arguments.Count - 1)); if (string.IsNullOrEmpty(reason)) { response = watchListTranslation.ReasonNull; return(false); } HashSet <Collections.Player> targets = new(); if (arguments.At(0).Split(',').Length > 1) { foreach (var player in arguments.At(0).Split(',')) { Collections.Player dPlayer = player.GetPlayer(); if (dPlayer is null) { response = watchListTranslation.PlayerNotFound.Replace("{target}", player); continue; } if (targets.Contains(dPlayer)) { continue; } targets.Add(dPlayer); } } else { Collections.Player dPlayer = arguments.At(0).GetPlayer(); if (dPlayer == null) { response = watchListTranslation.PlayerNotFound.Replace("{player}", arguments.At(0)); return(false); } if (!targets.Contains(dPlayer)) { targets.Add(dPlayer); } } foreach (var player in targets) { ModerationSystemAPI.ApplyPunish(Player.Get(arguments.At(1)), ((CommandSender)sender).GetStaffer(), player, PunishType.WatchList, reason, DateTime.MinValue.ToString(CultureInfo.InvariantCulture)); response = watchListTranslation.PlayerAddedWatchlist.Replace("{player.name}", player.Name) .Replace("{player.userid}", $"{player.Id}@{player.Authentication}"); } break; case "list": if (arguments.Count == 1) { response = ModerationSystemAPI.GetWatchList(null); return(true); } Collections.Player target = arguments.At(1).GetPlayer(); if (target == null) { response = watchListTranslation.PlayerNotFound; return(false); } response = ModerationSystemAPI.GetWatchList(target); return(true); default: response = watchListTranslation.ActionNotFounded; return(false); } response = ""; return(true); }
public bool Execute(ArraySegment <string> arguments, ICommandSender sender, out string response) { WarnTranslation warnTranslation = Plugin.Singleton.Config.Translation.WarnTranslation; if (!sender.CheckPermission("ms.warn")) { response = warnTranslation.InvalidPermission.Replace("{permission}", "ms.warn"); return(false); } if (arguments.Count < 1) { response = warnTranslation.WrongUsage; return(false); } List <Collections.Player> targets = new(); if (arguments.At(0).Split(',').Length > 1) { foreach (var player in arguments.At(0).Split(',')) { Collections.Player target = player.GetPlayer(); if (target is null) { response = warnTranslation.PlayerNotFound.Replace("{target}", player); return(false); } if (targets.Contains(target)) { continue; } targets.Add(target); } } else { Collections.Player dPlayer = arguments.At(0).GetPlayer(); if (dPlayer == null) { response = warnTranslation.PlayerNotFound.Replace("{player}", arguments.At(0)); return(false); } if (!targets.Contains(dPlayer)) { targets.Add(dPlayer); } } string reason = string.Join(" ", arguments.Skip(1).Take(arguments.Count - 1)); if (string.IsNullOrEmpty(reason)) { response = warnTranslation.ReasonNull; return(false); } foreach (var target in targets) { ModerationSystemAPI.ApplyPunish(Player.Get($"{target.Id}@{target.Authentication}"), ((CommandSender)sender).GetStaffer(), target, PunishType.Warn, reason, DateTime.MinValue.ToString(CultureInfo.InvariantCulture)); ModerationSystemAPI.SendBroadcast(new Exiled.API.Features.Broadcast(Plugin.Singleton.Config.Translation.StaffTranslation.StaffWarnMessage.Content.Replace("{staffer}", sender.LogName).Replace("{target}", $"{target.Name} {target.Id}{target.Authentication}").Replace("{reason}", reason))); } response = warnTranslation.PlayerWarned; return(true); }
/// <summary> /// Gets a value indicating wherever or not the specified <see cref="Collections.Player"/> is soft-banned. /// </summary> /// <param name="dPlayer"> the specified <see cref="Collections.Player"/>.</param> /// <returns> true if is soft-banned, false if not.</returns> public static bool IsSoftBanned(this Collections.Player dPlayer) => SoftBanCollection.Exists(sb => sb.Target.Id == dPlayer.Id && sb.Expire > DateTime.Now);
/// <summary> /// Gets a value indicating wherever or not the specified <see cref="Collections.Player"/> is banned. /// </summary> /// <param name="dPlayer"> the specified <see cref="Collections.Player"/>.</param> /// <returns> true if is banned, false if not.</returns> public static bool IsBanned(this Collections.Player dPlayer) => BanCollection.Exists(ban => ban.Target.Id == dPlayer.Id && ban.Expire > DateTime.Now);
/// <summary> /// Gets a value indicating wherever or not the specified <see cref="Collections.Player"/> is muted. /// </summary> /// <param name="dPlayer"> the specified <see cref="Collections.Player"/>.</param> /// <returns> true if is muted, false if not.</returns> public static bool IsMuted(this Collections.Player dPlayer) => MuteCollection.Exists(mute => mute.Target.Id == dPlayer.Id && mute.Expire > DateTime.Now);
/// <summary> /// Apply a punish to the specified <see cref="Player"/>. /// </summary> /// <param name="target">The <see cref="Exiled.API.Features.Player"/> player.</param> /// <param name="issuer">The <see cref="Collections.Player"/> staffer.</param> /// <param name="dPlayer">The <see cref="Collections.Player"/> player.</param> /// <param name="punishType">The <see cref="Enums.PunishType"/> punish.</param> /// <param name="reason">The reason of the punish.</param> /// <param name="duration">The <see cref="DateTime"/> duration.</param> public static void ApplyPunish(Player target, Collections.Player issuer, Collections.Player dPlayer, PunishType punishType, string reason, string duration) { switch (punishType) { case PunishType.Warn: Warn warn = new Warn(dPlayer, issuer, reason, DateTime.Now, WarnCollection.Find(w => w.Target.Id == dPlayer.Id).Count(), Server.Port, false); warn.Save(); target?.Broadcast(Plugin.Singleton.Config.Translation.WarnTranslation.PlayerWarnedMessage.Duration, Plugin.Singleton.Config.Translation.WarnTranslation.PlayerWarnedMessage.Content.Replace( "{reason}", reason), global::Broadcast.BroadcastFlags.Normal, true); JsonManager.PunishToCache(punishType, JsonConvert.SerializeObject(warn), dPlayer, ActionType.Add); break; case PunishType.Mute: Mute mute = new Mute(dPlayer, issuer, reason, GetDate(duration), DateTime.Now, DateTime.Now.AddSeconds(GetTotalSeconds(duration).TotalSeconds), MuteCollection.Find(m => m.Target == dPlayer).Count(), Server.Port, false); mute.Save(); MuteHandler.IssuePersistentMute(dPlayer.Id + dPlayer.Authentication); target?.Broadcast(Plugin.Singleton.Config.Translation.MuteTranslation.PlayerMuteMessage.Duration, Plugin.Singleton.Config.Translation.WarnTranslation.PlayerWarnedMessage.Content .Replace("{duration}", GetDate(duration)).Replace("{reason}", reason)); JsonManager.PunishToCache(punishType, JsonConvert.SerializeObject(mute), dPlayer, ActionType.Add); break; case PunishType.Kick: Kick kick = new Kick(dPlayer, issuer, reason, DateTime.Now, KickCollection.Find(x => x.Target.Id == dPlayer.Id).Count(), Server.Port, false); kick.Save(); target?.Kick(Plugin.Singleton.Config.Translation.KickTranslation.PlayerKickedMessage.Replace("{reason}", reason)); JsonManager.PunishToCache(punishType, JsonConvert.SerializeObject(kick), dPlayer, ActionType.Add); break; case PunishType.Ban: Ban ban = new Ban(dPlayer, issuer, reason, GetDate(duration, true), DateTime.Now, DateTime.Now.AddSeconds(GetTotalSeconds(duration, true).TotalSeconds), BanCollection.Find(x => x.Target.Id == dPlayer.Id).Count(), Server.Port, false); ban.Save(); target?.Disconnect(Plugin.Singleton.Config.Translation.BanTranslation.PlayerBanMessage.Replace("{reason}", reason)); JsonManager.PunishToCache(punishType, JsonConvert.SerializeObject(ban), dPlayer, ActionType.Add); break; case PunishType.SoftWarn: SoftWarn softWarn = new SoftWarn(dPlayer, issuer, reason, DateTime.Now, SoftWarnCollection.Find(sw => sw.Target.Id == dPlayer.Id).Count(), Server.Port, false); softWarn.Save(); target?.Broadcast( Plugin.Singleton.Config.Translation.SoftWarnTranslation.PlayerSoftWarnedMessage.Duration, Plugin.Singleton.Config.Translation.SoftWarnTranslation.PlayerSoftWarnedMessage.Content.Replace( "{reason}", reason)); JsonManager.PunishToCache(punishType, JsonConvert.SerializeObject(softWarn), dPlayer, ActionType.Add); break; case PunishType.SoftBan: SoftBan softBan = new SoftBan(dPlayer, issuer, reason, GetDate(duration), DateTime.Now, DateTime.Now.AddSeconds(GetTotalSeconds(duration).TotalSeconds), SoftBanCollection.Find(sb => sb.Target.Id == dPlayer.Id).Count(), Server.Port, false); softBan.Save(); target?.Broadcast( Plugin.Singleton.Config.Translation.SoftBanTranslation.PlayerSoftBanMessage.Duration, Plugin.Singleton.Config.Translation.StaffTranslation.StaffSoftBanMessage.Content.Replace( "{duration}", GetDate(duration).Replace("{reason}", reason))); if (target != null && target.Role != RoleType.Spectator) { target.Role.Type = RoleType.Spectator; } JsonManager.PunishToCache(punishType, JsonConvert.SerializeObject(softBan), dPlayer, ActionType.Add); break; case PunishType.WatchList: WatchList watchList = new WatchList(dPlayer, issuer, reason, DateTime.Now, WatchListCollection.Find(wl => wl.Target.Id == dPlayer.Id).Count(), Server.Port, false); watchList.Save(); JsonManager.PunishToCache(punishType, JsonConvert.SerializeObject(watchList), dPlayer, ActionType.Add); break; } if (punishType is PunishType.WatchList) { Timing.RunCoroutine(DiscordHandler.SendMessage(Plugin.Singleton.Config.Translation.DiscordTranslation.MessageContentWatchlist.Replace("{target}", $"{dPlayer.Name} ({dPlayer.Id}@{dPlayer.Authentication})").Replace("{reason}", reason).Replace("{issuer}", $"{issuer.Name} ({issuer.Id}@{issuer.Authentication})"), Plugin.Singleton.Config.Translation.DiscordTranslation.WebhookUrlWatchlist)); } Timing.RunCoroutine(DiscordHandler.SendMessage(Plugin.Singleton.Config.Translation.DiscordTranslation.MessageContent.Replace("{target}", $"{dPlayer.Name} ({dPlayer.Id}@{dPlayer.Authentication})").Replace("{reason}", reason).Replace("{action}", punishType.ToString()).Replace("{issuer}", $"{issuer.Name} ({issuer.Id}@{issuer.Authentication})").Replace("{duration}", GetDate(duration, true)), Plugin.Singleton.Config.Translation.DiscordTranslation.WebhookUrl)); }
/// <summary> /// Clear a punish to the specified <see cref="Player"/>. /// </summary> /// <param name="player">The <see cref="Collections.Player"/> player.</param> /// <param name="type"> the <see cref="Enums.PunishType"/>.</param> /// <param name="id"> the punish id.</param> /// <param name="server"> the server port.</param> public static void ClearPunishment(Collections.Player player, PunishType?type, int id, int server) { switch (type) { case PunishType.Ban: Ban ban = BanCollection.FindOne(b => b.Target == player && b.BanId == id && b.Server == server); JsonManager.PunishToCache(type, JsonConvert.SerializeObject(ban), player, ActionType.Remove); if (player.IsBanned()) { BanHandler.RemoveBan($"{player.Id}@{player.Authentication}", BanHandler.BanType.IP); } BanCollection.Delete(ban.Id); break; case PunishType.Kick: Kick kick = KickCollection.FindOne(k => k.Target == player && k.KickId == id && k.Server == server); JsonManager.PunishToCache(type, JsonConvert.SerializeObject(kick), player, ActionType.Remove); KickCollection.Delete(kick.Id); break; case PunishType.Mute: Mute mute = MuteCollection.FindOne(m => m.Target == player && m.MuteId == id && m.Server == server); JsonManager.PunishToCache(type, JsonConvert.SerializeObject(mute), player, ActionType.Remove); if (player.IsMuted()) { MuteHandler.RevokePersistentMute($"{player.Id}@{player.Authentication}"); } MuteCollection.Delete(mute.Id); break; case PunishType.Warn: Warn warn = WarnCollection.FindOne(w => w.Target == player && w.WarnId == id && w.Server == server); JsonManager.PunishToCache(type, JsonConvert.SerializeObject(warn), player, ActionType.Remove); WarnCollection.Delete(warn.Id); break; case PunishType.SoftWarn: SoftWarn softWarn = SoftWarnCollection.FindOne(sw => sw.Target == player && sw.SoftWarnId == id && sw.Server == server); JsonManager.PunishToCache(type, JsonConvert.SerializeObject(softWarn), player, ActionType.Remove); SoftWarnCollection.Delete(softWarn.Id); break; case PunishType.SoftBan: SoftBan softBan = SoftBanCollection.FindOne(sb => sb.Target == player && sb.SoftBanId == id && sb.Server == server); JsonManager.PunishToCache(type, JsonConvert.SerializeObject(softBan), player, ActionType.Remove); SoftBanCollection.Delete(softBan.Id); break; case PunishType.WatchList: WatchList watchList = WatchListCollection.FindOne(wl => wl.Target == player && wl.WatchListId == id && wl.Server == server); JsonManager.PunishToCache(type, JsonConvert.SerializeObject(watchList), player, ActionType.Remove); WatchListCollection.Delete(watchList.Id); break; } }