public async Task <bool> DoBan(BanningEventArgs ev) { string banned_user_id = ev.Target.UserId; string banned_nickname = ev.Target.Nickname; string banned_ip_address = ev.Target.IPAddress; int banduration = ev.Duration; Player adminHub = ev.Issuer; Log.Info("--------------------------------------"); Log.Info("Ban detected, plugin taking over:"); Log.Info($"Banned Name: {banned_nickname}"); Log.Info($"Banned ID: {banned_user_id}"); Log.Info($"Banned IP: {banned_ip_address}"); Log.Info($"Admin Name: {adminHub.Nickname}"); Log.Info($"Admin ID: {adminHub.UserId}"); Log.Info($"Duration: {banduration}"); if (banduration.ToString().Contains("1576800000")) { banduration = 0; Log.Info($"Duration: UPDATED TO PERM!"); } string reason = ev.Reason; if (reason == "") { reason = "No reason provided. Please contact a Head Administrator for further details."; } if (await WebTask.IssueBan(plugin.Config.APIKey, banned_user_id, banned_nickname, banned_ip_address, adminHub.UserId, banduration, reason, ev.Target.ReferenceHub.serverRoles.DoNotTrack)) { Log.Info($"Successfully pushed ban for {banned_user_id} ({banned_ip_address}) to the web API!"); Log.Info("--------------------------------------"); SendClientToServer(ev.Target, 7790); // We can safely remove the ban since the web client will handle it from here. //BanHandler.RemoveBan(ev.Target.UserId, ev.); return(true); } else { // Error out to requesting admin adminHub.Broadcast(15, $"ERROR while adding ban to web API for: {banned_nickname}({banned_user_id})"); Log.Error($"FATAL BANNING ERROR! WebTask.IssueBan() Failed to push to web API"); // Actually ban them since the webapi decided to do the funny... BanDetails ban = new BanDetails { OriginalName = ev.Target.Nickname, Id = ev.Target.UserId, IssuanceTime = TimeBehaviour.CurrentTimestamp(), Expires = DateTime.UtcNow.AddMinutes((double)ev.Duration).Ticks, Reason = ev.Reason, Issuer = ev.Issuer.UserId }; BanHandler.IssueBan(ban, BanHandler.BanType.UserId); Log.Info("Pushed manual server-side ban."); Log.Info("--------------------------------------"); return(false); } return(false); }
public void cmd_oban(CommandInfo info) { CommandSender sender = info.commandSender; string[] arg = info.commandArgs; if (arg.Count() < 4) { sender.RaReply(arg[0].ToUpper() + "#Command expects 3 or more arguments ([UserID], [Minutes], [Reason])", false, true, ""); return; } else if (!arg[1].Contains('@')) { sender.RaReply(arg[0].ToUpper() + "#Invalid UserID given", false, true, ""); return; } char unit = arg[2].ToString().Where(Char.IsLetter).ToArray()[0]; if (!int.TryParse(new string(arg[2].Where(Char.IsDigit).ToArray()), out int amount) || !CustomInternalCommands.validUnits.Contains(unit) || amount < 1) { sender.RaReply(arg[0].ToUpper() + "#Invalid duration", false, true, ""); return; } TimeSpan duration = CustomInternalCommands.GetBanDuration(unit, amount); string reason = string.Join(" ", arg.Skip(3)); if (duration.Minutes > 60 && !CustomInternalCommands.CheckPermissions(sender, arg[0], PlayerPermissions.KickingAndShortTermBanning)) { return; } else if (duration.Minutes > 1440 && !CustomInternalCommands.CheckPermissions(sender, arg[0], PlayerPermissions.BanningUpToDay)) { return; } BanHandler.IssueBan(new BanDetails { OriginalName = "Offline player", Id = arg[1], Issuer = sender.Nickname, IssuanceTime = DateTime.UtcNow.Ticks, Expires = DateTime.UtcNow.Add(duration).Ticks, Reason = reason.Replace(Environment.NewLine, "") }, BanHandler.BanType.UserId); sender.RaReply(arg[0].ToUpper() + $"#{arg[1]} was offline banned for {arg[2]}", true, true, ""); }
public void Ban(int duration, string reason = "No reason provided", string issuer = "SERVER", bool banIP = true) { BanHandler.IssueBan(new BanDetails { OriginalName = name, Id = userId, Issuer = issuer, IssuanceTime = DateTime.UtcNow.Ticks, Expires = DateTimeOffset.UtcNow.AddMinutes(duration).Ticks, Reason = reason }, BanHandler.BanType.UserId); BanHandler.IssueBan(new BanDetails { OriginalName = name, Id = ipAddress, Issuer = issuer, IssuanceTime = DateTime.UtcNow.Ticks, Expires = DateTimeOffset.UtcNow.AddMinutes(duration).Ticks, Reason = reason }, BanHandler.BanType.IP); }
private void HandlePunishments(GameObject go, string reason) { if (_banDurationOne < 0) { return; } Base.Disconnect(go, $"You have been automatically disconnected from the server by SmartGuard.\nReason: {reason}"); Base.SmartGuard($"{go.GetComponent<NicknameSync>().MyNick} was {(_banDurationOne > 0 ? "banned" : "kicked")}: {reason}"); if (_banDurationOne > 0) { Base.Disconnect(go, $"You have been automatically disconnected from the server by SmartGuard.\nReason: {reason}\nNote: This action was performed automatically by a server modification!"); BanHandler.IssueBan(new BanDetails { OriginalName = go.GetComponent <NicknameSync>().MyNick, Id = go.GetComponent <CharacterClassManager>().UserId, Expires = DateTime.UtcNow.AddMinutes(_banDurationOne).Ticks, Reason = $"SMARTGUARD - {reason}", Issuer = "SMARTGUARD", IssuanceTime = DateTime.UtcNow.Ticks }, BanHandler.BanType.UserId); BanHandler.IssueBan(new BanDetails { OriginalName = go.GetComponent <NicknameSync>().MyNick, Id = go.GetComponent <NetworkIdentity>().connectionToClient.address, Expires = DateTime.UtcNow.AddMinutes(_banDurationOne).Ticks, Reason = $"SMARTGUARD - {reason}", Issuer = "SMARTGUARD", IssuanceTime = DateTime.UtcNow.Ticks }, BanHandler.BanType.IP); Base.SmartGuard($"{go.GetComponent<NicknameSync>().MyNick} was banned for: {reason}"); } }
private static bool Prefix(GameObject user, int duration, string reason, string issuer, bool isGlobalBan) { try { if (isGlobalBan && ConfigFile.ServerConfig.GetBool("gban_ban_ip", false)) { duration = int.MaxValue; } string userId = null; string address = user.GetComponent <NetworkIdentity>().connectionToClient.address; API.Features.Player targetPlayer = API.Features.Player.Get(user); API.Features.Player issuerPlayer = API.Features.Player.Get(issuer) ?? API.Features.Server.Host; try { if (ConfigFile.ServerConfig.GetBool("online_mode", false)) { userId = targetPlayer.UserId; } } catch { ServerConsole.AddLog("Failed during issue of User ID ban (1)!"); return(false); } string message = $"You have been {((duration > 0) ? "banned" : "kicked")}. "; if (!string.IsNullOrEmpty(reason)) { message = message + "Reason: " + reason; } if (!ServerStatic.PermissionsHandler.IsVerified || !targetPlayer.IsStaffBypassEnabled) { if (duration > 0) { var ev = new BanningEventArgs(targetPlayer, issuerPlayer, duration, reason, message); Player.OnBanning(ev); duration = ev.Duration; reason = ev.Reason; message = ev.FullMessage; if (!ev.IsAllowed) { return(false); } string originalName = string.IsNullOrEmpty(targetPlayer.Nickname) ? "(no nick)" : targetPlayer.Nickname; long issuanceTime = TimeBehaviour.CurrentTimestamp(); long banExpieryTime = TimeBehaviour.GetBanExpirationTime((uint)duration); try { if (userId != null && !isGlobalBan) { BanHandler.IssueBan( new BanDetails { OriginalName = originalName, Id = userId, IssuanceTime = issuanceTime, Expires = banExpieryTime, Reason = reason, Issuer = issuer, }, BanHandler.BanType.UserId); if (!string.IsNullOrEmpty(targetPlayer.CustomUserId)) { BanHandler.IssueBan( new BanDetails { OriginalName = originalName, Id = targetPlayer.CustomUserId, IssuanceTime = issuanceTime, Expires = banExpieryTime, Reason = reason, Issuer = issuer, }, BanHandler.BanType.UserId); } } } catch { ServerConsole.AddLog("Failed during issue of User ID ban (2)!"); return(false); } try { if (ConfigFile.ServerConfig.GetBool("ip_banning", false) || isGlobalBan) { BanHandler.IssueBan( new BanDetails { OriginalName = originalName, Id = address, IssuanceTime = issuanceTime, Expires = banExpieryTime, Reason = reason, Issuer = issuer, }, BanHandler.BanType.IP); } } catch { ServerConsole.AddLog("Failed during issue of IP ban!"); return(false); } } else if (duration == 0) { var ev = new KickingEventArgs(targetPlayer, issuerPlayer, reason, message); Player.OnKicking(ev); reason = ev.Reason; message = ev.FullMessage; if (!ev.IsAllowed) { return(false); } } } ServerConsole.Disconnect(targetPlayer.ReferenceHub.gameObject, message); return(false); } catch (Exception e) { Exiled.API.Features.Log.Error($"Exiled.Events.Patches.Events.Player.BanningAndKicking: {e}\n{e.StackTrace}"); return(true); } }
private string BanCommand(string[] arg, JObject jObject) { if (arg.Count() < 5) { return($"```{arg[1]} [UserID/Ip] [Duration] [Reason]```"); } bool validUID = arg[2].Contains('@'); bool validIP = IPAddress.TryParse(arg[2], out IPAddress ip); //BanDetails details; if (!validIP && !validUID) { return($"```diff\n- Invalid UserID or IP given```"); } char unit = arg[3].ToString().Where(Char.IsLetter).ToArray()[0]; if (!int.TryParse(new string(arg[3].Where(Char.IsDigit).ToArray()), out int amount) || !validUnits.Contains(unit) || amount < 1) { return("```diff\n- Invalid duration```"); } TimeSpan duration = GetBanDuration(unit, amount); string reason = string.Join(" ", arg.Skip(4)); int index; if (validUID) { index = PlayerManager.players.FindIndex(p => p.GetComponent <CharacterClassManager>().UserId == arg[2]); } else { index = PlayerManager.players.FindIndex(p => p.GetComponent <CharacterClassManager>().connectionToClient.address == arg[2]); } if (index > -1) { PheggPlayer player = new PheggPlayer(PlayerManager.players[index]); player.Ban(duration.Minutes, reason, jObject["Staff"].ToString(), true); player.Kick(reason); } else { BanHandler.IssueBan(new BanDetails { OriginalName = "Offline player", Id = arg[2], Issuer = jObject["Staff"].ToString(), IssuanceTime = DateTime.UtcNow.Ticks, Expires = DateTime.UtcNow.Add(duration).Ticks, Reason = reason }, (validUID ? BanHandler.BanType.UserId : BanHandler.BanType.IP)); } return($"`{arg[2]}` was banned for {arg[3]} with reason {reason}!"); }
public static void HandleCommand(JObject o) { try { string type = (string)o["type"]; if (type == "IDENT") { if ((string)o["data"] == "PASS") { Log.Debug($"Server {ServerConsole.Port} passed identification."); } else if ((string)o["data"] == "FAIL") { Log.Warn($"Server {ServerConsole.Port} failed identification."); } } else if (type == "UPDATE") { EventHandlers.tcp.SendData(new Update()); } else if (type == "ROLESYNC") { Log.Warn(o); string userid = (string)o["userid"]; if (o["group"] == null) { Log.Debug($"No role sync found for {userid}"); SCPDiscord.VerifyReservedSlot(userid); return; } string group = (string)o["group"]; UserGroup userGroup = ServerStatic.PermissionsHandler.GetGroup(group); if (userGroup == null) { Log.Error($"Attempted to assign invalid user group {group} to {userid}"); return; } Player player = Player.Get(userid); if (player == null) { Log.Error($"Error assigning user group to {userid}, player not found."); return; } if (SCPDiscord.setRoleGroups.Contains(group)) { Log.Debug($"Assigning role: {userGroup} to {userid}."); player.Group = userGroup; } string tag = (string)o["tag"]; if (SCPDiscord.setTagGroups.Contains(group) && tag != null) { Log.Debug($"Changing tag of {userid} to {tag}."); player.RankName = tag; } if (SCPDiscord.reservedSlotGroups.Contains(group)) { // grant reserved slot Log.Debug("Player has necessary rank for reserved slot, checking..."); List <string> lines = File.ReadAllLines(SCPDiscord.reservedSlots).ToList(); if (!lines.Contains(userid)) { Log.Debug("Reserved slot not found, adding player..."); lines.Add(userid); File.WriteAllLines(SCPDiscord.reservedSlots, lines); // This only reloads the slots on the current server, change this to reload on every server? // Might not work ReservedSlot.Reload(); } } else { SCPDiscord.VerifyReservedSlot(userid); } } else if (type == "COMMAND") { GameCore.Console.singleton.TypeCommand((string)o["command"]); } else if (type == "BAN") { bool isuid = false; string uid = (string)o["user"]; if (!uid.Contains("@steam") && !uid.Contains("@discord")) { if (!uid.Contains(".")) { isuid = true; uid += "@steam"; } } else { isuid = true; } Player player = Player.Get(uid); int min = (int)o["min"]; string reason = (string)o["reason"]; Ban ban = new Ban { player = null, duration = min, success = true, offline = false }; if (player != null) { PlayerManager.localPlayer.GetComponent <BanPlayer>().BanUser(player.GameObject, min, reason, "Server"); ban.player = new User { name = player.Nickname, userid = player.UserId }; } else { if (isuid) { ban.offline = true; ban.player = new User { name = "Offline Player", userid = uid }; if (SCPDiscord.instance.Config.SteamApiKey != string.Empty) { string data = null; try { data = webclient.DownloadString($"https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v2/?key={SCPDiscord.instance.Config.SteamApiKey}&format=json&steamids={uid.Replace("@steam", "")}"); } catch { Log.Debug("Failed to get profile data from SteamAPI."); } JObject o2 = JObject.Parse(data); if (o2 != null) { ban.player.name = (string)o2["response"]["players"][0]["personaname"]; } } BanHandler.IssueBan(new BanDetails() { OriginalName = ban.player.name, Id = uid, IssuanceTime = TimeBehaviour.CurrentTimestamp(), Expires = DateTime.UtcNow.AddMinutes((double)min).Ticks, Reason = reason, Issuer = "Server" }, BanHandler.BanType.UserId); } else if (uid.Contains(".")) { ban.offline = true; BanHandler.IssueBan(new BanDetails() { OriginalName = "IP Address", Id = uid, IssuanceTime = TimeBehaviour.CurrentTimestamp(), Expires = DateTime.UtcNow.AddMinutes((double)min).Ticks, Reason = reason, Issuer = "Server" }, BanHandler.BanType.IP); } else { ban.success = false; } } EventHandlers.tcp.SendData(ban); } else if (type == "KICK") { string uid = (string)o["user"]; if (!uid.Contains("@steam") && !uid.Contains("@discord")) { uid += "@steam"; } Player player = Player.Get(uid); Kick kick = new Kick { player = null }; if (player != null) { kick.player = new User { name = player.Nickname, userid = player.UserId }; ServerConsole.Disconnect(player.GameObject, (string)o["reason"]); } EventHandlers.tcp.SendData(kick); } else if (type == "UNBAN") { Unban unban = new Unban(); List <string> ipBans = File.ReadAllLines(SCPDiscord.ipBans).ToList(); List <string> userIDBans = File.ReadAllLines(SCPDiscord.useridBans).ToList(); string id = (string)o["user"]; if (!id.Contains(".")) { if (!id.Contains("@steam") && !id.Contains("@discord")) { id += "@steam"; } } List <string> matchingIPBans = ipBans.FindAll(s => s.Contains(id)); List <string> matchingSteamIDBans = userIDBans.FindAll(s => s.Contains(id)); if (matchingIPBans.Count == 0 && matchingSteamIDBans.Count == 0) { unban.success = false; EventHandlers.tcp.SendData(unban); return; } ipBans.RemoveAll(s => s.Contains(id)); userIDBans.RemoveAll(s => s.Contains(id)); foreach (var row in matchingIPBans) { userIDBans.RemoveAll(s => s.Contains(row.Split(';').Last())); } foreach (var row in matchingSteamIDBans) { ipBans.RemoveAll(s => s.Contains(row.Split(';').Last())); } File.WriteAllLines(SCPDiscord.ipBans, ipBans); File.WriteAllLines(SCPDiscord.useridBans, userIDBans); EventHandlers.tcp.SendData(unban); } } catch (Exception x) { Log.Error("SCPDiscord handle command error: " + x.Message); } }
private string BanCommand(string[] arg, JObject jObject) { try { if (arg.Count() < 5) { return($"```{arg[1]} [UserID/Ip] [Duration] [Reason]```"); } bool validUID = arg[2].Contains('@'); bool validIP = IPAddress.TryParse(arg[2], out IPAddress ip); if (!validIP && !validUID) { return($"```diff\n- Invalid UserID or IP given```"); } var chars = arg[3].Where(Char.IsLetter).ToArray(); //return string.Join(" ", chars); if (chars.Length < 1 || !int.TryParse(new string(arg[3].Where(Char.IsDigit).ToArray()), out int amount) || !validUnits.Contains(chars[0]) || amount < 1) { return("```diff\n- Invalid duration```"); } TimeSpan duration = GetBanDuration(chars[0], amount); string reason = string.Join(" ", arg.Skip(4)); ReferenceHub player = null; if (validIP) { var list = ReferenceHub.GetAllHubs().Where(p => p.Value.characterClassManager.connectionToClient.address == arg[2]); if (list.Count() > 0) { player = list.First().Value; } } else { var list = ReferenceHub.GetAllHubs().Where(p => p.Value.characterClassManager.UserId == arg[2]); if (list.Count() > 0) { player = list.First().Value; } } if (player != null) { BanHandler.IssueBan(new BanDetails { OriginalName = player.nicknameSync.MyNick, Id = player.characterClassManager.UserId, Issuer = jObject["Staff"].ToString(), IssuanceTime = DateTime.UtcNow.Ticks, Expires = DateTime.UtcNow.Add(duration).Ticks, Reason = reason }, BanHandler.BanType.UserId); BanHandler.IssueBan(new BanDetails { OriginalName = player.nicknameSync.MyNick, Id = player.characterClassManager.connectionToClient.address, Issuer = jObject["Staff"].ToString(), IssuanceTime = DateTime.UtcNow.Ticks, Expires = DateTime.UtcNow.Add(duration).Ticks, Reason = reason }, BanHandler.BanType.IP); ServerConsole.Disconnect(player.gameObject, reason); return($"`{player.nicknameSync.MyNick} ({player.characterClassManager.UserId})` was banned for {arg[3]} with reason: {reason}"); } else { BanHandler.IssueBan(new BanDetails { OriginalName = "Offline player", Id = arg[2], Issuer = jObject["Staff"].ToString(), IssuanceTime = DateTime.UtcNow.Ticks, Expires = DateTime.UtcNow.Add(duration).Ticks, Reason = reason }, (validUID ? BanHandler.BanType.UserId : BanHandler.BanType.IP)); return($"`{arg[2]}` was banned for {arg[3]} with reason {reason}!"); } } catch (Exception e) { return(e.ToString()); } }
public static bool Prefix(GameObject user, int duration, string reason, string issuer, bool isGlobalBan) { if (isGlobalBan && ConfigFile.ServerConfig.GetBool("gban_ban_ip", false)) { duration = int.MaxValue; } string userId = null; string address = user.GetComponent <NetworkIdentity>().connectionToClient.address; CharacterClassManager characterClassManager = null; ReferenceHub userHub = Extensions.Player.GetPlayer(user); try { if (ConfigFile.ServerConfig.GetBool("online_mode", false)) { characterClassManager = userHub.characterClassManager; userId = characterClassManager.UserId; } } catch { ServerConsole.AddLog("Failed during issue of User ID ban (1)!"); return(false); } string message = $"You have been {((duration > 0) ? "banned" : "kicked")}. "; if (!string.IsNullOrEmpty(reason)) { message = message + "Reason: " + reason; } try { bool allow = true; Events.InvokePlayerBan(ref userHub, ref userId, ref duration, ref allow, ref message, ref reason); if (!allow) { return(false); } } catch (Exception ex) { Log.Error($"Error in OnBanPlayer event: {ex.ToString()}"); } if (duration > 0 && (!ServerStatic.PermissionsHandler.IsVerified || !userHub.serverRoles.BypassStaff)) { string originalName = string.IsNullOrEmpty(userHub.nicknameSync.MyNick) ? "(no nick)" : userHub.nicknameSync.MyNick; long issuanceTime = TimeBehaviour.CurrentTimestamp(); long banExpieryTime = TimeBehaviour.GetBanExpieryTime((uint)duration); try { if (userId != null && !isGlobalBan) { BanHandler.IssueBan(new BanDetails { OriginalName = originalName, Id = userId, IssuanceTime = issuanceTime, Expires = banExpieryTime, Reason = reason, Issuer = issuer }, BanHandler.BanType.UserId); if (!string.IsNullOrEmpty(characterClassManager.UserId2)) { BanHandler.IssueBan(new BanDetails { OriginalName = originalName, Id = characterClassManager.UserId2, IssuanceTime = issuanceTime, Expires = banExpieryTime, Reason = reason, Issuer = issuer }, BanHandler.BanType.UserId); } } } catch { ServerConsole.AddLog("Failed during issue of User ID ban (2)!"); return(false); } try { if (ConfigFile.ServerConfig.GetBool("ip_banning", false) || isGlobalBan) { BanHandler.IssueBan(new BanDetails { OriginalName = originalName, Id = address, IssuanceTime = issuanceTime, Expires = banExpieryTime, Reason = reason, Issuer = issuer }, BanHandler.BanType.IP); } } catch { ServerConsole.AddLog("Failed during issue of IP ban!"); return(false); } } List <GameObject> playersToBan = new List <GameObject>(); foreach (GameObject gameObject in PlayerManager.players) { characterClassManager = gameObject.GetComponent <CharacterClassManager>(); if ((userId != null && characterClassManager.UserId == userId) || (address != null && characterClassManager.connectionToClient.address == address)) { playersToBan.Add(characterClassManager.gameObject); } } foreach (GameObject player in playersToBan) { ServerConsole.Disconnect(player, message); } return(false); }