Integrate Modern HWID into content
This should be the primary changes for the future-proof "Modern HWID" system implemented into Robust and the auth server. HWIDs in the database have been given an additional column representing their version, legacy or modern. This is implemented via an EF Core owned entity. By manually setting the column name of the main value column, we can keep DB compatibility and the migration is just adding some type columns. This new HWID type has to be plumbed through everywhere, resulting in some breaking changes for the DB layer and such. New bans and player records are placed with the new modern HWID. Old bans are still checked against legacy HWIDs. Modern HWIDs are presented with a "V2-" prefix to admins, to allow distinguishing them. This is also integrated into the parsing logic for placing new bans. There's also some code cleanup to reduce copy pasting around the place from my changes. Requires latest engine to support ImmutableArray<byte> in NetSerializer.
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text.Json;
|
||||
@@ -327,6 +329,47 @@ namespace Content.Server.Database
|
||||
.HasForeignKey(w => w.PlayerUserId)
|
||||
.HasPrincipalKey(p => p.UserId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
// Changes for modern HWID integration
|
||||
modelBuilder.Entity<Player>()
|
||||
.OwnsOne(p => p.LastSeenHWId)
|
||||
.Property(p => p.Hwid)
|
||||
.HasColumnName("last_seen_hwid");
|
||||
|
||||
modelBuilder.Entity<Player>()
|
||||
.OwnsOne(p => p.LastSeenHWId)
|
||||
.Property(p => p.Type)
|
||||
.HasDefaultValue(HwidType.Legacy);
|
||||
|
||||
modelBuilder.Entity<ServerBan>()
|
||||
.OwnsOne(p => p.HWId)
|
||||
.Property(p => p.Hwid)
|
||||
.HasColumnName("hwid");
|
||||
|
||||
modelBuilder.Entity<ServerBan>()
|
||||
.OwnsOne(p => p.HWId)
|
||||
.Property(p => p.Type)
|
||||
.HasDefaultValue(HwidType.Legacy);
|
||||
|
||||
modelBuilder.Entity<ServerRoleBan>()
|
||||
.OwnsOne(p => p.HWId)
|
||||
.Property(p => p.Hwid)
|
||||
.HasColumnName("hwid");
|
||||
|
||||
modelBuilder.Entity<ServerRoleBan>()
|
||||
.OwnsOne(p => p.HWId)
|
||||
.Property(p => p.Type)
|
||||
.HasDefaultValue(HwidType.Legacy);
|
||||
|
||||
modelBuilder.Entity<ConnectionLog>()
|
||||
.OwnsOne(p => p.HWId)
|
||||
.Property(p => p.Hwid)
|
||||
.HasColumnName("hwid");
|
||||
|
||||
modelBuilder.Entity<ConnectionLog>()
|
||||
.OwnsOne(p => p.HWId)
|
||||
.Property(p => p.Type)
|
||||
.HasDefaultValue(HwidType.Legacy);
|
||||
}
|
||||
|
||||
public virtual IQueryable<AdminLog> SearchLogs(IQueryable<AdminLog> query, string searchText)
|
||||
@@ -519,7 +562,7 @@ namespace Content.Server.Database
|
||||
public string LastSeenUserName { get; set; } = null!;
|
||||
public DateTime LastSeenTime { get; set; }
|
||||
public IPAddress LastSeenAddress { get; set; } = null!;
|
||||
public byte[]? LastSeenHWId { get; set; }
|
||||
public TypedHwid? LastSeenHWId { get; set; }
|
||||
|
||||
// Data that changes with each round
|
||||
public List<Round> Rounds { get; set; } = null!;
|
||||
@@ -668,7 +711,7 @@ namespace Content.Server.Database
|
||||
int Id { get; set; }
|
||||
Guid? PlayerUserId { get; set; }
|
||||
NpgsqlInet? Address { get; set; }
|
||||
byte[]? HWId { get; set; }
|
||||
TypedHwid? HWId { get; set; }
|
||||
DateTime BanTime { get; set; }
|
||||
DateTime? ExpirationTime { get; set; }
|
||||
string Reason { get; set; }
|
||||
@@ -753,7 +796,7 @@ namespace Content.Server.Database
|
||||
/// <summary>
|
||||
/// Hardware ID of the banned player.
|
||||
/// </summary>
|
||||
public byte[]? HWId { get; set; }
|
||||
public TypedHwid? HWId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The time when the ban was applied by an administrator.
|
||||
@@ -891,7 +934,7 @@ namespace Content.Server.Database
|
||||
public DateTime Time { get; set; }
|
||||
|
||||
public IPAddress Address { get; set; } = null!;
|
||||
public byte[]? HWId { get; set; }
|
||||
public TypedHwid? HWId { get; set; }
|
||||
|
||||
public ConnectionDenyReason? Denied { get; set; }
|
||||
|
||||
@@ -908,6 +951,8 @@ namespace Content.Server.Database
|
||||
|
||||
public List<ServerBanHit> BanHits { get; set; } = null!;
|
||||
public Server Server { get; set; } = null!;
|
||||
|
||||
public float Trust { get; set; }
|
||||
}
|
||||
|
||||
public enum ConnectionDenyReason : byte
|
||||
@@ -945,7 +990,7 @@ namespace Content.Server.Database
|
||||
public Guid? PlayerUserId { get; set; }
|
||||
[Required] public TimeSpan PlaytimeAtNote { get; set; }
|
||||
public NpgsqlInet? Address { get; set; }
|
||||
public byte[]? HWId { get; set; }
|
||||
public TypedHwid? HWId { get; set; }
|
||||
|
||||
public DateTime BanTime { get; set; }
|
||||
|
||||
@@ -1206,4 +1251,37 @@ namespace Content.Server.Database
|
||||
/// <seealso cref="ServerBan.Hidden"/>
|
||||
public bool Hidden { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A hardware ID value together with its <see cref="HwidType"/>.
|
||||
/// </summary>
|
||||
/// <seealso cref="ImmutableTypedHwid"/>
|
||||
[Owned]
|
||||
public sealed class TypedHwid
|
||||
{
|
||||
public byte[] Hwid { get; set; } = default!;
|
||||
public HwidType Type { get; set; }
|
||||
|
||||
[return: NotNullIfNotNull(nameof(immutable))]
|
||||
public static implicit operator TypedHwid?(ImmutableTypedHwid? immutable)
|
||||
{
|
||||
if (immutable == null)
|
||||
return null;
|
||||
|
||||
return new TypedHwid
|
||||
{
|
||||
Hwid = immutable.Hwid.ToArray(),
|
||||
Type = immutable.Type,
|
||||
};
|
||||
}
|
||||
|
||||
[return: NotNullIfNotNull(nameof(hwid))]
|
||||
public static implicit operator ImmutableTypedHwid?(TypedHwid? hwid)
|
||||
{
|
||||
if (hwid == null)
|
||||
return null;
|
||||
|
||||
return new ImmutableTypedHwid(hwid.Hwid.ToImmutableArray(), hwid.Type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user