-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from bobbahbrown/v1.0.6
Version 1.0.6
- Loading branch information
Showing
19 changed files
with
449 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace CentCom.Common.Models.Equality | ||
{ | ||
public class BanEqualityComparer : IEqualityComparer<Ban> | ||
{ | ||
public static readonly BanEqualityComparer Instance = new BanEqualityComparer(); | ||
|
||
public bool Equals(Ban x, Ban y) | ||
{ | ||
if (x is null || y is null) return x == y; | ||
else if (x.BanID != null || y.BanID != null) | ||
{ | ||
return x.Source == y.Source | ||
&& x.BanID == y.BanID; | ||
} | ||
else | ||
{ | ||
return x.Source == y.Source | ||
&& x.BannedOn == y.BannedOn | ||
&& x.BanType == y.BanType | ||
&& x.CKey == y.CKey | ||
&& x.BannedBy == y.BannedBy | ||
&& x.Reason == y.Reason | ||
&& x.Expires == y.Expires | ||
&& x.UnbannedBy == y.UnbannedBy | ||
&& (x.IP == null || x.IP.Equals(y.IP)) | ||
&& x.CID == y.CID | ||
&& (x.BanType == BanType.Server | ||
|| (x.JobBans != null && y.JobBans != null && x.JobBans.SetEquals(y.JobBans))); | ||
} | ||
} | ||
|
||
public int GetHashCode(Ban obj) | ||
{ | ||
var hash = new HashCode(); | ||
if (obj.BanID != null) | ||
{ | ||
hash.Add(obj.BanID); | ||
hash.Add(obj.Source); | ||
} | ||
else | ||
{ | ||
hash.Add(obj.Source); | ||
hash.Add(obj.BannedOn); | ||
hash.Add(obj.BanType); | ||
hash.Add(obj.CKey); | ||
hash.Add(obj.BannedBy); | ||
hash.Add(obj.Reason); | ||
hash.Add(obj.Expires); | ||
hash.Add(obj.UnbannedBy); | ||
hash.Add(obj.IP); | ||
hash.Add(obj.CID); | ||
if (obj.JobBans != null) | ||
{ | ||
foreach (var job in obj.JobBans.OrderBy(x => x.Job)) | ||
{ | ||
hash.Add(job.Job); | ||
} | ||
} | ||
} | ||
return hash.ToHashCode(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace CentCom.Common.Models.Equality | ||
{ | ||
public class JobBanEqualityComparer : IEqualityComparer<JobBan> | ||
{ | ||
public static readonly JobBanEqualityComparer Instance = new JobBanEqualityComparer(); | ||
|
||
public bool Equals(JobBan x, JobBan y) | ||
{ | ||
return (x is null || y is null) ? x == y : x.Job == y.Job; | ||
} | ||
|
||
public int GetHashCode(JobBan obj) | ||
{ | ||
return HashCode.Combine(obj.Job); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using CentCom.Common.Data; | ||
using CentCom.Common.Models; | ||
using CentCom.Server.Services; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Logging; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace CentCom.Server.BanSources | ||
{ | ||
public class TGMCBanParser : BanParser | ||
{ | ||
public override Dictionary<string, BanSource> Sources => new Dictionary<string, BanSource>() | ||
{ | ||
{ "tgmc", new BanSource() | ||
{ | ||
Display = "TGMC", | ||
Name = "tgmc", | ||
RoleplayLevel = RoleplayLevel.Medium | ||
} } | ||
}; | ||
public override bool SourceSupportsBanIDs => true; | ||
private TGMCBanService _banService; | ||
private const int PAGES_PER_BATCH = 3; | ||
|
||
public TGMCBanParser(DatabaseContext dbContext, TGMCBanService banService, ILogger<TGMCBanParser> logger) : base(dbContext, logger) | ||
{ | ||
_banService = banService; | ||
} | ||
|
||
public override async Task<IEnumerable<Ban>> FetchAllBansAsync() | ||
{ | ||
_logger.LogInformation("Getting all bans for TGMC..."); | ||
return await _banService.GetBansBatchedAsync(); | ||
} | ||
|
||
public override async Task<IEnumerable<Ban>> FetchNewBansAsync() | ||
{ | ||
_logger.LogInformation("Getting new bans for TGMC..."); | ||
var recent = await _dbContext.Bans | ||
.Where(x => Sources.Keys.Contains(x.SourceNavigation.Name)) | ||
.OrderByDescending(x => x.BannedOn) | ||
.Take(5) | ||
.Include(x => x.JobBans) | ||
.Include(x => x.SourceNavigation) | ||
.ToListAsync(); | ||
var foundBans = new List<Ban>(); | ||
var page = 1; | ||
|
||
while (true) | ||
{ | ||
var batch = await _banService.GetBansBatchedAsync(page, PAGES_PER_BATCH); | ||
foundBans.AddRange(batch); | ||
if (batch.Count() == 0 || batch.Any(x => recent.Any(y => y.BannedOn == x.BannedOn && y.CKey == y.CKey))) | ||
{ | ||
break; | ||
} | ||
} | ||
|
||
return foundBans; | ||
} | ||
} | ||
} |
Oops, something went wrong.