add idm/access code preference for physical cards (server)

This commit is contained in:
ppc
2025-01-12 20:19:46 +00:00
parent 297ad685a7
commit 42cb241487
7 changed files with 33 additions and 10 deletions
+12 -1
View File
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using Windows.Win32;
using Windows.Win32.Foundation;
@@ -6,21 +7,31 @@ namespace AMNet.Server;
internal static class Config
{
internal const string IOSection = "aimeio";
private const string ConfigFileName = @".\segatools.ini";
internal const string IOSection = "aimeio";
/// <summary>
/// Valid physical card identification methods.
/// IDm - uses the idm of the card to generate a 20-digit identifier (also known as the 0008 number)
/// Access - prefer the real access code of the card. if not available (i.e. Suica card), fallback to the IDm.
/// </summary>
private static readonly string[] ValidPhysicalCardIdentifiers = ["idm", "access"];
static Config()
{
GameId = ReadKey(IOSection, "gameId", 4);
ServerName = ReadKey(IOSection, "serverName", 26, Environment.MachineName);
var physicalCardIdentifierPreference = ReadKey(IOSection, "physicalCardIdentifier", 10);
PhysicalCardIdentifierPreference = ValidPhysicalCardIdentifiers.Contains(physicalCardIdentifierPreference) ? physicalCardIdentifierPreference : ValidPhysicalCardIdentifiers[^1];
EnableAimeTxt = PInvoke.GetPrivateProfileInt(IOSection, "enableKeyboardMode", 1, ConfigFileName) > 0;
AimeTxtPath = ReadKey("aime", "aimePath", PInvoke.MAX_PATH, @"DEVICE\aime.txt");
}
public static string GameId { get; }
public static string ServerName { get; }
public static string PhysicalCardIdentifierPreference { get; }
public static bool EnableAimeTxt { get; }
public static string AimeTxtPath { get; }
+4 -2
View File
@@ -21,7 +21,8 @@ internal static partial class WebServer
[property: JsonPropertyName("gameId")] string GameId,
[property: JsonPropertyName("serverName")] string ServerName,
[property: JsonPropertyName("sessionUptime")] long SessionUptime,
[property: JsonPropertyName("timeSinceLastPoll")] long? TimeSinceLastPoll);
[property: JsonPropertyName("timeSinceLastPoll")] long? TimeSinceLastPoll,
[property: JsonPropertyName("physicalCardIdentifierPreference")] string PhysicalCardIdentifierPreference);
public record CardReadRequest(
[property: JsonPropertyName("cardId")] string MatrixCode);
@@ -82,7 +83,8 @@ internal static partial class WebServer
Config.GameId,
Config.ServerName,
Environment.TickCount64 - startedAt,
lastPollAt < 0 ? null : Environment.TickCount64 - lastPollAt);
lastPollAt < 0 ? null : Environment.TickCount64 - lastPollAt,
Config.PhysicalCardIdentifierPreference);
return Results.Ok(state);
}
+5 -2
View File
@@ -30,10 +30,13 @@ interface AMServerInstanceMetrics {
timeSinceLastPoll?: number;
sessionUptime?: number;
}
interface AMServerPhysicalCardPreferences {
preferredCardIdFormat?: "idm" | "access" | null;
}
/**
* The response from an AMNet server's info endpoint
*/
type AMServerInfo = AMServerMetadata & AMServerConnectionInfo & AMServerInstanceMetrics;
type AMServerInfo = AMServerMetadata & AMServerConnectionInfo & AMServerInstanceMetrics & AMServerPhysicalCardPreferences;
/**
* Performs the card-in request to the specified server
* @param server The server to perform the request against
@@ -62,4 +65,4 @@ declare function validateCardId(id: string): boolean;
*/
declare function getGameName(id: string): string | null;
export { type AMCardInRequest, AMNET_API_VERSION, type AMServerConnectionInfo, type AMServerInfo, type AMServerInstanceMetrics, type AMServerMetadata, CARD_ID_REGEX, MIN_AMNET_API_VERSION, fetchServerInfo, generateCardNumber, getGameName, performCardIn, validateCardId };
export { type AMCardInRequest, AMNET_API_VERSION, type AMServerConnectionInfo, type AMServerInfo, type AMServerInstanceMetrics, type AMServerMetadata, type AMServerPhysicalCardPreferences, CARD_ID_REGEX, MIN_AMNET_API_VERSION, fetchServerInfo, generateCardNumber, getGameName, performCardIn, validateCardId };
+5 -2
View File
@@ -30,10 +30,13 @@ interface AMServerInstanceMetrics {
timeSinceLastPoll?: number;
sessionUptime?: number;
}
interface AMServerPhysicalCardPreferences {
preferredCardIdFormat?: "idm" | "access" | null;
}
/**
* The response from an AMNet server's info endpoint
*/
type AMServerInfo = AMServerMetadata & AMServerConnectionInfo & AMServerInstanceMetrics;
type AMServerInfo = AMServerMetadata & AMServerConnectionInfo & AMServerInstanceMetrics & AMServerPhysicalCardPreferences;
/**
* Performs the card-in request to the specified server
* @param server The server to perform the request against
@@ -62,4 +65,4 @@ declare function validateCardId(id: string): boolean;
*/
declare function getGameName(id: string): string | null;
export { type AMCardInRequest, AMNET_API_VERSION, type AMServerConnectionInfo, type AMServerInfo, type AMServerInstanceMetrics, type AMServerMetadata, CARD_ID_REGEX, MIN_AMNET_API_VERSION, fetchServerInfo, generateCardNumber, getGameName, performCardIn, validateCardId };
export { type AMCardInRequest, AMNET_API_VERSION, type AMServerConnectionInfo, type AMServerInfo, type AMServerInstanceMetrics, type AMServerMetadata, type AMServerPhysicalCardPreferences, CARD_ID_REGEX, MIN_AMNET_API_VERSION, fetchServerInfo, generateCardNumber, getGameName, performCardIn, validateCardId };
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+5 -1
View File
@@ -36,10 +36,14 @@ export interface AMServerInstanceMetrics {
sessionUptime?: number;
}
export interface AMServerPhysicalCardPreferences {
preferredCardIdFormat?: "idm" | "access" | null;
}
/**
* The response from an AMNet server's info endpoint
*/
export type AMServerInfo = AMServerMetadata & AMServerConnectionInfo & AMServerInstanceMetrics;
export type AMServerInfo = AMServerMetadata & AMServerConnectionInfo & AMServerInstanceMetrics & AMServerPhysicalCardPreferences;
/**
* Performs the card-in request to the specified server