public bool CreateNewBan(string hwid, string reason, BanCategory category, long ban, string socialClubName) { if (hwid.Length > MaxHwidLength) { throw new BanHwidTooLongException(hwid); } if (reason.Length > MaxBanReasonLength) { throw new BanReasonTooLongException(reason); } using (MySqlConnection connection = new MySqlConnection(ConnectionString)) { connection.Open(); using (MySqlCommand command = new MySqlCommand(string.Format(InsertBanSql, socialClubName, hwid, reason, (int)category, ban), connection)) { try { return(command.ExecuteNonQuery() > 0); } catch (MySqlException e) { if (e.Number == 1062) { Log.Warn("Cannot ban {0} - he is already banned.", socialClubName); return(true); } throw; } } } }
public Ban(BanCategory category, string socialClubName, string hwid, long banValue, string reason) { Category = category; SocialClubName = socialClubName; Hwid = hwid; BanValue = banValue; Reason = reason; }
public void IssuePermanentBan(Client player, string reason, BanCategory category) { string socialClubName = player.SocialClubName; if (BanRepo.CreateNewBan(player.Serial, reason, category, -1, socialClubName)) { Log.Info("{0} has been permanently banned by social club name & hwid. Reason: '{1}'; Category: {2}", socialClubName, reason, category); KickBannedPlayer(player, reason, category, -1); } else { throw new FailedToIssuePermanentBanException(socialClubName); } }
public void IssueTemporaryBan(Client player, string reason, BanCategory category, long unbanDate) { string socialClubName = player.SocialClubName; if (BanRepo.CreateNewBan(player.Serial, reason, category, unbanDate, socialClubName)) { Log.Info("{0} has been temporarily banned by social club name & hwid. Unban date: {1}; Reason: '{2}'; Category: {3}", socialClubName, DateTimeOffset.FromUnixTimeMilliseconds(unbanDate).ToLocalTime(), reason, category); KickBannedPlayer(player, reason, category, unbanDate); } else { throw new FailedToIssueTemporaryBanException(socialClubName); } }
private void KickBannedPlayer(Client player, String reason, BanCategory category, long unbanDate) { player.TriggerEvent("kickBrowser"); string unbanDateString; if (unbanDate == -1) { unbanDateString = "never"; } else { unbanDateString = DateTimeOffset.FromUnixTimeMilliseconds(unbanDate).ToLocalTime().ToString(); } player.Kick(string.Format("Permanent ban. Reason: {0}; Category: {1}; Unban date: {2}", reason, category, unbanDateString)); Log.Info("{0} has been kicked with the reason of ban.", player.SocialClubName); }
[Command("ban", GreedyArg = true)] // `/ban banany 1.10` public void CMD_ban(Client player, string targetSocialClubName, string reason, BanCategory category, string time) { try { Client target = GetPlayerBySocialClubName(targetSocialClubName); if (target != null) { Principal.IssueTemporaryBan(target, reason, category, ConvertTimeToEpoch(time)); } else { player.SendNotification("Target doesn't exist"); } } catch (BanReasonTooLongException) { player.SendNotification("Ban reason is too long!"); } catch (Exception e) { Log.Error(e); player.SendNotification(DefaultErrorMessage); } }