Files
RobustToolbox/Robust.Shared/Network/IHWId.cs
83c2a1be11 [Dependency] source generator part 2 (#6550)
* [Dependency] source generator

No more reflection, no more codegen at runtime

Also various changes to Roslyn helpers to make this easier to write.

Requires all types with dependencies to be partial and not have readonly dependency fields. An analyzer enforces this at warning level, the previous injection strategies have remained in the code *for now* as a fallback.

No fallback is available for [field: Dependency] properties, due to a Roslyn bug.

Code Fixes exist. We love Roslyn

* Apply dependencies generator changes to all code

* Release notes

* Preprocessor got hands

* Handle nullable dependencies

These are bad but gotta deal with it.

* Apply suggestions from code review

Co-authored-by: Moony <moony@hellomouse.net>

* Fine, let's not use collection expressions

---------

Co-authored-by: Moony <moony@hellomouse.net>
2026-05-08 12:38:33 +02:00

68 lines
1.8 KiB
C#

using System;
using Robust.Shared.Console;
using Robust.Shared.IoC;
using Robust.Shared.Utility;
namespace Robust.Shared.Network;
/// <summary>
/// Fetches HWID (hardware ID) unique identifiers for the local system.
/// </summary>
internal interface IHWId
{
/// <summary>
/// Gets the "legacy" HWID.
/// </summary>
/// <remarks>
/// These are directly sent to servers and therefore susceptible to malicious spoofing.
/// They should not be relied on for the future.
/// </remarks>
/// <returns>
/// An opaque value that gets sent to the server to identify this computer,
/// or an empty array if legacy HWID is not supported on this platform.
/// </returns>
byte[] GetLegacy();
/// <summary>
/// Gets the "modern" HWID.
/// </summary>
/// <returns>
/// An opaque value that gets sent to the auth server to identify this computer,
/// or null if modern HWID is not supported on this platform.
/// </returns>
byte[]? GetModern();
}
/// <summary>
/// Implementation of <see cref="IHWId"/> that does nothing, always returning an empty result.
/// </summary>
internal sealed class DummyHWId : IHWId
{
public byte[] GetLegacy()
{
return [];
}
public byte[] GetModern()
{
return [];
}
}
#if DEBUG
internal sealed partial class HwidCommand : LocalizedCommands
{
[Dependency] private IHWId _hwId = default!;
public override string Command => "hwid";
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
shell.WriteLine($"""
legacy: {Convert.ToBase64String(_hwId.GetLegacy(), Base64FormattingOptions.None)}
modern: {Base64Helpers.ToBase64Nullable(_hwId.GetModern())}
""");
}
}
#endif