/// <summary> /// Enumerates over all the bans /// </summary> /// <returns></returns> public IEnumerable <Ban> GetBansEnumerable() { //Iterate over every IP ban. // If they dont have a ticket, return it // otherwise match it with its uuid ban foreach (var ipban in BannedIps) { if (!ipban.Ticket.HasValue) { yield return(ipban); } else { var uuidban = BannedIps.FirstOrDefault(b => b.Ticket.HasValue && b.Ticket.Value == ipban.Ticket.Value); yield return(ipban.Combine(uuidban)); } } //Iterate over every uuid ban for ones that dont have tickets foreach (var uuidban in BannedUuids) { if (!uuidban.Ticket.HasValue) { yield return(uuidban); } } }
public long AddBan(Ban ban) { if (ban.BanType == BanType.Invalid) { //Failed to add ban because it contained no IP or UUID return(-1); } //Increment the ban ticket if (!ban.Ticket.HasValue) { ban.Ticket = -1; } //Append the current time if (!ban.CreatedDate.HasValue) { ban.CreatedDate = DateTime.UtcNow; } //Make sure it has the ticket listed at least once. if (!ban.Reason.Contains("{ticket}")) { ban.Reason += "\n^orange;Ban Ticket: ^white;{ticket}"; } //Make sure it has the ticket listed at least once. ban.Reason = ban.GetFormattedReason(); //Add to the correct array var ipban = ban.GetIpBan(); var uuidban = ban.GetUuidBan(); if (ipban != null) { BannedIps.Add(ipban); } if (uuidban != null) { BannedUuids.Add(uuidban); } return(ban.Ticket.Value); }
/// <summary> /// Removes the ban from the ban list. /// </summary> /// <param name="ban">The ban to remove</param> /// <returns>True if successful</returns> public bool RemoveBan(Ban ban) { //Make sure its a valid ban to begin with if (ban.BanType == BanType.Invalid) { return(false); } //Store its success state then try to remove accounts from each state bool success = false; if (BannedIps.RemoveAll(b => b.Ticket == ban.Ticket) > 0) { success = true; } if (BannedUuids.RemoveAll(b => b.Ticket == ban.Ticket) > 0) { success = true; } return(success); }