Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit verified IPs to 3 #676

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Refresh.GameServer/Database/GameDatabaseContext.Tokens.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,22 @@ public void AddIpVerificationRequest(GameUser user, string ipAddress)

public void AddVerifiedIp(GameUser user, string ipAddress, IDateTimeProvider timeProvider)
{
const int maxVerifiedIps = 3;

int count = this.GameUserVerifiedIpRelations.Count(r => r.User == user);
int toRemove = count >= maxVerifiedIps ? count - maxVerifiedIps + 1 : 0;

this.Write(() =>
{
// Remove the oldest verified IPs if the user has too many (or will have too many after this one)
if (toRemove > 0)
this.GameUserVerifiedIpRelations.RemoveRange(
this.GameUserVerifiedIpRelations
.Where(r => r.User == user)
.OrderBy(r => r.VerifiedAt)
.AsEnumerable()
.Take(toRemove));

this.GameUserVerifiedIpRelations.Add(new GameUserVerifiedIpRelation
{
User = user,
Expand Down
6 changes: 6 additions & 0 deletions Refresh.GameServer/Database/RealmDbSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public void RemoveRange(IQueryable<T> objs)
{
this._realm.RemoveRange(objs);
}

public void RemoveRange(IEnumerable<T> objs)
{
foreach (T obj in objs)
this._realm.Remove(obj);
}
Comment on lines +47 to +51
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a note but this will likely break source compatibility with EF as I don't believe this exists on a DbSet. Not too hard to fix when we get there.


public void RemoveRange(Expression<Func<T, bool>> predicate)
{
Expand Down
Loading