diff --git a/AMNet.Server/Config.cs b/AMNet.Server/Config.cs
index 954fd87..506cf2c 100644
--- a/AMNet.Server/Config.cs
+++ b/AMNet.Server/Config.cs
@@ -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";
+ ///
+ /// 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.
+ ///
+ 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; }
diff --git a/AMNet.Server/WebServer.cs b/AMNet.Server/WebServer.cs
index e238f5b..18a0fc9 100644
--- a/AMNet.Server/WebServer.cs
+++ b/AMNet.Server/WebServer.cs
@@ -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);
}
diff --git a/amnet-shared/dist/index.d.mts b/amnet-shared/dist/index.d.mts
index ad11302..167d216 100644
--- a/amnet-shared/dist/index.d.mts
+++ b/amnet-shared/dist/index.d.mts
@@ -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 };
diff --git a/amnet-shared/dist/index.d.ts b/amnet-shared/dist/index.d.ts
index ad11302..167d216 100644
--- a/amnet-shared/dist/index.d.ts
+++ b/amnet-shared/dist/index.d.ts
@@ -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 };
diff --git a/amnet-shared/dist/index.js.map b/amnet-shared/dist/index.js.map
index 8db7e48..9359f8f 100644
--- a/amnet-shared/dist/index.js.map
+++ b/amnet-shared/dist/index.js.map
@@ -1 +1 @@
-{"version":3,"sources":["../src/index.ts","../src/api.ts","../src/card.ts","../src/gameIds.ts"],"sourcesContent":["export * from './api';\nexport * from './card';\nexport * from './gameIds';","/**\n * The latest version of the AMNet API this library supports\n */\nexport const AMNET_API_VERSION = 1;\n\n/**\n * The minimum version of the AMNet API this library supports\n */\nexport const MIN_AMNET_API_VERSION = 1;\n\nexport interface AMCardInRequest {\n cardId: string;\n}\n\n/**\n * Server connection info (api version, address, etc.)\n */\nexport interface AMServerConnectionInfo {\n apiVersion: number;\n serverAddress: string;\n}\n\n/**\n * User-definable server metadata\n */\nexport interface AMServerMetadata {\n serverName: string;\n gameId?: string | null | undefined;\n}\n\n/**\n * Metrics about the current game session\n */\nexport interface AMServerInstanceMetrics {\n timeSinceLastPoll?: number;\n sessionUptime?: number;\n}\n\n/**\n * The response from an AMNet server's info endpoint\n */\nexport type AMServerInfo = AMServerMetadata & AMServerConnectionInfo & AMServerInstanceMetrics;\n\n/**\n * Performs the card-in request to the specified server\n * @param server The server to perform the request against\n * @param request The card-in request to send\n * @param signal The abort signal to use for the request\n */\nexport async function performCardIn(server: AMServerConnectionInfo, request: AMCardInRequest, signal: AbortSignal): Promise {\n if (server.apiVersion < MIN_AMNET_API_VERSION || server.apiVersion > AMNET_API_VERSION) {\n throw new Error(\"Unsupported server API version\");\n }\n \n try {\n const response = await fetch(`${new URL(server.serverAddress).origin}/amnet/signin`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\"\n },\n body: JSON.stringify(request),\n signal: signal\n });\n\n return response.ok;\n } catch {\n return false;\n }\n}\n\n/**\n * Attempts to connect to the specified server and fetch its info\n * @param serverAddress The origin address of the server to connect to\n * @param abort The abort signal to use for the request (for cancellation)\n */\nexport async function fetchServerInfo(serverAddress: string, abort: AbortSignal): Promise {\n try {\n const response = await fetch(`${new URL(serverAddress).origin}/amnet/info`, {\n signal: abort\n });\n \n if (!response.ok) {\n return null;\n }\n\n return {\n ...await response.json(),\n serverAddress: serverAddress\n } satisfies AMServerMetadata;\n } catch {\n return null;\n }\n}\n","export const CARD_ID_REGEX = /^(?:[0-9]{4} ?){5}$/i;\n\nexport function generateCardNumber(): string {\n let cardId = '';\n\n while (true) {\n // don't start with a 3\n const firstDigit = Math.floor(Math.random() * 10);\n\n if (firstDigit !== 3) {\n cardId = firstDigit.toString();\n break;\n }\n }\n\n for (let i = 0; i < 19; i++) {\n cardId += Math.floor(Math.random() * 10).toString();\n }\n\n return cardId;\n}\n\n/**\n * Validates the provided card id by known parameters\n * @param id The card id to validate\n */\nexport function validateCardId(id: string): boolean {\n return id[0] !== '3' && CARD_ID_REGEX.test(id);\n}\n","/**\n * Get the game name from the game identifier (4-letter code)\n * @param id\n */\nexport function getGameName(id: string): string | null {\n switch (id?.toUpperCase()) {\n case \"SDGT\":\n return \"Initial D The Arcade\";\n case \"SDHD\":\n case \"SDBT\":\n return \"CHUNITHM\";\n case \"SDDT\":\n return \"O.N.G.E.K.I.\";\n case \"SDEZ\":\n return \"maimai DX\";\n case \"SBZV\":\n return \"Project DIVA Future Tone\";\n \n default:\n return null;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,IAAM,oBAAoB;AAK1B,IAAM,wBAAwB;AAyCrC,SAAsB,cAAc,QAAgC,SAA0B,QAAuC;AAAA;AACjI,QAAI,OAAO,aAAa,yBAAyB,OAAO,aAAa,mBAAmB;AACpF,YAAM,IAAI,MAAM,gCAAgC;AAAA,IACpD;AAEA,QAAI;AACA,YAAM,WAAW,MAAM,MAAM,GAAG,IAAI,IAAI,OAAO,aAAa,EAAE,MAAM,iBAAiB;AAAA,QACjF,QAAQ;AAAA,QACR,SAAS;AAAA,UACL,gBAAgB;AAAA,QACpB;AAAA,QACA,MAAM,KAAK,UAAU,OAAO;AAAA,QAC5B;AAAA,MACJ,CAAC;AAED,aAAO,SAAS;AAAA,IACpB,SAAQ;AACJ,aAAO;AAAA,IACX;AAAA,EACJ;AAAA;AAOA,SAAsB,gBAAgB,eAAuB,OAAkD;AAAA;AAC3G,QAAI;AACA,YAAM,WAAW,MAAM,MAAM,GAAG,IAAI,IAAI,aAAa,EAAE,MAAM,eAAe;AAAA,QACxE,QAAQ;AAAA,MACZ,CAAC;AAED,UAAI,CAAC,SAAS,IAAI;AACd,eAAO;AAAA,MACX;AAEA,aAAO,iCACA,MAAM,SAAS,KAAK,IADpB;AAAA,QAEH;AAAA,MACJ;AAAA,IACJ,SAAQ;AACJ,aAAO;AAAA,IACX;AAAA,EACJ;AAAA;;;AC5FO,IAAM,gBAAgB;AAEtB,SAAS,qBAA6B;AACzC,MAAI,SAAS;AAEb,SAAO,MAAM;AAET,UAAM,aAAa,KAAK,MAAM,KAAK,OAAO,IAAI,EAAE;AAEhD,QAAI,eAAe,GAAG;AAClB,eAAS,WAAW,SAAS;AAC7B;AAAA,IACJ;AAAA,EACJ;AAEA,WAAS,IAAI,GAAG,IAAI,IAAI,KAAK;AACzB,cAAU,KAAK,MAAM,KAAK,OAAO,IAAI,EAAE,EAAE,SAAS;AAAA,EACtD;AAEA,SAAO;AACX;AAMO,SAAS,eAAe,IAAqB;AAChD,SAAO,GAAG,CAAC,MAAM,OAAO,cAAc,KAAK,EAAE;AACjD;;;ACxBO,SAAS,YAAY,IAA2B;AACnD,UAAQ,yBAAI,eAAe;AAAA,IACvB,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AAAA,IACL,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IAEX;AACI,aAAO;AAAA,EACf;AACJ;","names":[]}
\ No newline at end of file
+{"version":3,"sources":["../src/index.ts","../src/api.ts","../src/card.ts","../src/gameIds.ts"],"sourcesContent":["export * from './api';\nexport * from './card';\nexport * from './gameIds';","/**\n * The latest version of the AMNet API this library supports\n */\nexport const AMNET_API_VERSION = 1;\n\n/**\n * The minimum version of the AMNet API this library supports\n */\nexport const MIN_AMNET_API_VERSION = 1;\n\nexport interface AMCardInRequest {\n cardId: string;\n}\n\n/**\n * Server connection info (api version, address, etc.)\n */\nexport interface AMServerConnectionInfo {\n apiVersion: number;\n serverAddress: string;\n}\n\n/**\n * User-definable server metadata\n */\nexport interface AMServerMetadata {\n serverName: string;\n gameId?: string | null | undefined;\n}\n\n/**\n * Metrics about the current game session\n */\nexport interface AMServerInstanceMetrics {\n timeSinceLastPoll?: number;\n sessionUptime?: number;\n}\n\nexport interface AMServerPhysicalCardPreferences {\n preferredCardIdFormat?: \"idm\" | \"access\" | null;\n}\n\n/**\n * The response from an AMNet server's info endpoint\n */\nexport type AMServerInfo = AMServerMetadata & AMServerConnectionInfo & AMServerInstanceMetrics & AMServerPhysicalCardPreferences;\n\n/**\n * Performs the card-in request to the specified server\n * @param server The server to perform the request against\n * @param request The card-in request to send\n * @param signal The abort signal to use for the request\n */\nexport async function performCardIn(server: AMServerConnectionInfo, request: AMCardInRequest, signal: AbortSignal): Promise {\n if (server.apiVersion < MIN_AMNET_API_VERSION || server.apiVersion > AMNET_API_VERSION) {\n throw new Error(\"Unsupported server API version\");\n }\n \n try {\n const response = await fetch(`${new URL(server.serverAddress).origin}/amnet/signin`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\"\n },\n body: JSON.stringify(request),\n signal: signal\n });\n\n return response.ok;\n } catch {\n return false;\n }\n}\n\n/**\n * Attempts to connect to the specified server and fetch its info\n * @param serverAddress The origin address of the server to connect to\n * @param abort The abort signal to use for the request (for cancellation)\n */\nexport async function fetchServerInfo(serverAddress: string, abort: AbortSignal): Promise {\n try {\n const response = await fetch(`${new URL(serverAddress).origin}/amnet/info`, {\n signal: abort\n });\n \n if (!response.ok) {\n return null;\n }\n\n return {\n ...await response.json(),\n serverAddress: serverAddress\n } satisfies AMServerMetadata;\n } catch {\n return null;\n }\n}\n","export const CARD_ID_REGEX = /^(?:[0-9]{4} ?){5}$/i;\n\nexport function generateCardNumber(): string {\n let cardId = '';\n\n while (true) {\n // don't start with a 3\n const firstDigit = Math.floor(Math.random() * 10);\n\n if (firstDigit !== 3) {\n cardId = firstDigit.toString();\n break;\n }\n }\n\n for (let i = 0; i < 19; i++) {\n cardId += Math.floor(Math.random() * 10).toString();\n }\n\n return cardId;\n}\n\n/**\n * Validates the provided card id by known parameters\n * @param id The card id to validate\n */\nexport function validateCardId(id: string): boolean {\n return id[0] !== '3' && CARD_ID_REGEX.test(id);\n}\n","/**\n * Get the game name from the game identifier (4-letter code)\n * @param id\n */\nexport function getGameName(id: string): string | null {\n switch (id?.toUpperCase()) {\n case \"SDGT\":\n return \"Initial D The Arcade\";\n case \"SDHD\":\n case \"SDBT\":\n return \"CHUNITHM\";\n case \"SDDT\":\n return \"O.N.G.E.K.I.\";\n case \"SDEZ\":\n return \"maimai DX\";\n case \"SBZV\":\n return \"Project DIVA Future Tone\";\n \n default:\n return null;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,IAAM,oBAAoB;AAK1B,IAAM,wBAAwB;AA6CrC,SAAsB,cAAc,QAAgC,SAA0B,QAAuC;AAAA;AACjI,QAAI,OAAO,aAAa,yBAAyB,OAAO,aAAa,mBAAmB;AACpF,YAAM,IAAI,MAAM,gCAAgC;AAAA,IACpD;AAEA,QAAI;AACA,YAAM,WAAW,MAAM,MAAM,GAAG,IAAI,IAAI,OAAO,aAAa,EAAE,MAAM,iBAAiB;AAAA,QACjF,QAAQ;AAAA,QACR,SAAS;AAAA,UACL,gBAAgB;AAAA,QACpB;AAAA,QACA,MAAM,KAAK,UAAU,OAAO;AAAA,QAC5B;AAAA,MACJ,CAAC;AAED,aAAO,SAAS;AAAA,IACpB,SAAQ;AACJ,aAAO;AAAA,IACX;AAAA,EACJ;AAAA;AAOA,SAAsB,gBAAgB,eAAuB,OAAkD;AAAA;AAC3G,QAAI;AACA,YAAM,WAAW,MAAM,MAAM,GAAG,IAAI,IAAI,aAAa,EAAE,MAAM,eAAe;AAAA,QACxE,QAAQ;AAAA,MACZ,CAAC;AAED,UAAI,CAAC,SAAS,IAAI;AACd,eAAO;AAAA,MACX;AAEA,aAAO,iCACA,MAAM,SAAS,KAAK,IADpB;AAAA,QAEH;AAAA,MACJ;AAAA,IACJ,SAAQ;AACJ,aAAO;AAAA,IACX;AAAA,EACJ;AAAA;;;AChGO,IAAM,gBAAgB;AAEtB,SAAS,qBAA6B;AACzC,MAAI,SAAS;AAEb,SAAO,MAAM;AAET,UAAM,aAAa,KAAK,MAAM,KAAK,OAAO,IAAI,EAAE;AAEhD,QAAI,eAAe,GAAG;AAClB,eAAS,WAAW,SAAS;AAC7B;AAAA,IACJ;AAAA,EACJ;AAEA,WAAS,IAAI,GAAG,IAAI,IAAI,KAAK;AACzB,cAAU,KAAK,MAAM,KAAK,OAAO,IAAI,EAAE,EAAE,SAAS;AAAA,EACtD;AAEA,SAAO;AACX;AAMO,SAAS,eAAe,IAAqB;AAChD,SAAO,GAAG,CAAC,MAAM,OAAO,cAAc,KAAK,EAAE;AACjD;;;ACxBO,SAAS,YAAY,IAA2B;AACnD,UAAQ,yBAAI,eAAe;AAAA,IACvB,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AAAA,IACL,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IAEX;AACI,aAAO;AAAA,EACf;AACJ;","names":[]}
\ No newline at end of file
diff --git a/amnet-shared/dist/index.mjs.map b/amnet-shared/dist/index.mjs.map
index be11df6..697ec06 100644
--- a/amnet-shared/dist/index.mjs.map
+++ b/amnet-shared/dist/index.mjs.map
@@ -1 +1 @@
-{"version":3,"sources":["../src/api.ts","../src/card.ts","../src/gameIds.ts"],"sourcesContent":["/**\n * The latest version of the AMNet API this library supports\n */\nexport const AMNET_API_VERSION = 1;\n\n/**\n * The minimum version of the AMNet API this library supports\n */\nexport const MIN_AMNET_API_VERSION = 1;\n\nexport interface AMCardInRequest {\n cardId: string;\n}\n\n/**\n * Server connection info (api version, address, etc.)\n */\nexport interface AMServerConnectionInfo {\n apiVersion: number;\n serverAddress: string;\n}\n\n/**\n * User-definable server metadata\n */\nexport interface AMServerMetadata {\n serverName: string;\n gameId?: string | null | undefined;\n}\n\n/**\n * Metrics about the current game session\n */\nexport interface AMServerInstanceMetrics {\n timeSinceLastPoll?: number;\n sessionUptime?: number;\n}\n\n/**\n * The response from an AMNet server's info endpoint\n */\nexport type AMServerInfo = AMServerMetadata & AMServerConnectionInfo & AMServerInstanceMetrics;\n\n/**\n * Performs the card-in request to the specified server\n * @param server The server to perform the request against\n * @param request The card-in request to send\n * @param signal The abort signal to use for the request\n */\nexport async function performCardIn(server: AMServerConnectionInfo, request: AMCardInRequest, signal: AbortSignal): Promise {\n if (server.apiVersion < MIN_AMNET_API_VERSION || server.apiVersion > AMNET_API_VERSION) {\n throw new Error(\"Unsupported server API version\");\n }\n \n try {\n const response = await fetch(`${new URL(server.serverAddress).origin}/amnet/signin`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\"\n },\n body: JSON.stringify(request),\n signal: signal\n });\n\n return response.ok;\n } catch {\n return false;\n }\n}\n\n/**\n * Attempts to connect to the specified server and fetch its info\n * @param serverAddress The origin address of the server to connect to\n * @param abort The abort signal to use for the request (for cancellation)\n */\nexport async function fetchServerInfo(serverAddress: string, abort: AbortSignal): Promise {\n try {\n const response = await fetch(`${new URL(serverAddress).origin}/amnet/info`, {\n signal: abort\n });\n \n if (!response.ok) {\n return null;\n }\n\n return {\n ...await response.json(),\n serverAddress: serverAddress\n } satisfies AMServerMetadata;\n } catch {\n return null;\n }\n}\n","export const CARD_ID_REGEX = /^(?:[0-9]{4} ?){5}$/i;\n\nexport function generateCardNumber(): string {\n let cardId = '';\n\n while (true) {\n // don't start with a 3\n const firstDigit = Math.floor(Math.random() * 10);\n\n if (firstDigit !== 3) {\n cardId = firstDigit.toString();\n break;\n }\n }\n\n for (let i = 0; i < 19; i++) {\n cardId += Math.floor(Math.random() * 10).toString();\n }\n\n return cardId;\n}\n\n/**\n * Validates the provided card id by known parameters\n * @param id The card id to validate\n */\nexport function validateCardId(id: string): boolean {\n return id[0] !== '3' && CARD_ID_REGEX.test(id);\n}\n","/**\n * Get the game name from the game identifier (4-letter code)\n * @param id\n */\nexport function getGameName(id: string): string | null {\n switch (id?.toUpperCase()) {\n case \"SDGT\":\n return \"Initial D The Arcade\";\n case \"SDHD\":\n case \"SDBT\":\n return \"CHUNITHM\";\n case \"SDDT\":\n return \"O.N.G.E.K.I.\";\n case \"SDEZ\":\n return \"maimai DX\";\n case \"SBZV\":\n return \"Project DIVA Future Tone\";\n \n default:\n return null;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGO,IAAM,oBAAoB;AAK1B,IAAM,wBAAwB;AAyCrC,SAAsB,cAAc,QAAgC,SAA0B,QAAuC;AAAA;AACjI,QAAI,OAAO,aAAa,yBAAyB,OAAO,aAAa,mBAAmB;AACpF,YAAM,IAAI,MAAM,gCAAgC;AAAA,IACpD;AAEA,QAAI;AACA,YAAM,WAAW,MAAM,MAAM,GAAG,IAAI,IAAI,OAAO,aAAa,EAAE,MAAM,iBAAiB;AAAA,QACjF,QAAQ;AAAA,QACR,SAAS;AAAA,UACL,gBAAgB;AAAA,QACpB;AAAA,QACA,MAAM,KAAK,UAAU,OAAO;AAAA,QAC5B;AAAA,MACJ,CAAC;AAED,aAAO,SAAS;AAAA,IACpB,SAAQ;AACJ,aAAO;AAAA,IACX;AAAA,EACJ;AAAA;AAOA,SAAsB,gBAAgB,eAAuB,OAAkD;AAAA;AAC3G,QAAI;AACA,YAAM,WAAW,MAAM,MAAM,GAAG,IAAI,IAAI,aAAa,EAAE,MAAM,eAAe;AAAA,QACxE,QAAQ;AAAA,MACZ,CAAC;AAED,UAAI,CAAC,SAAS,IAAI;AACd,eAAO;AAAA,MACX;AAEA,aAAO,iCACA,MAAM,SAAS,KAAK,IADpB;AAAA,QAEH;AAAA,MACJ;AAAA,IACJ,SAAQ;AACJ,aAAO;AAAA,IACX;AAAA,EACJ;AAAA;;;AC5FO,IAAM,gBAAgB;AAEtB,SAAS,qBAA6B;AACzC,MAAI,SAAS;AAEb,SAAO,MAAM;AAET,UAAM,aAAa,KAAK,MAAM,KAAK,OAAO,IAAI,EAAE;AAEhD,QAAI,eAAe,GAAG;AAClB,eAAS,WAAW,SAAS;AAC7B;AAAA,IACJ;AAAA,EACJ;AAEA,WAAS,IAAI,GAAG,IAAI,IAAI,KAAK;AACzB,cAAU,KAAK,MAAM,KAAK,OAAO,IAAI,EAAE,EAAE,SAAS;AAAA,EACtD;AAEA,SAAO;AACX;AAMO,SAAS,eAAe,IAAqB;AAChD,SAAO,GAAG,CAAC,MAAM,OAAO,cAAc,KAAK,EAAE;AACjD;;;ACxBO,SAAS,YAAY,IAA2B;AACnD,UAAQ,yBAAI,eAAe;AAAA,IACvB,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AAAA,IACL,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IAEX;AACI,aAAO;AAAA,EACf;AACJ;","names":[]}
\ No newline at end of file
+{"version":3,"sources":["../src/api.ts","../src/card.ts","../src/gameIds.ts"],"sourcesContent":["/**\n * The latest version of the AMNet API this library supports\n */\nexport const AMNET_API_VERSION = 1;\n\n/**\n * The minimum version of the AMNet API this library supports\n */\nexport const MIN_AMNET_API_VERSION = 1;\n\nexport interface AMCardInRequest {\n cardId: string;\n}\n\n/**\n * Server connection info (api version, address, etc.)\n */\nexport interface AMServerConnectionInfo {\n apiVersion: number;\n serverAddress: string;\n}\n\n/**\n * User-definable server metadata\n */\nexport interface AMServerMetadata {\n serverName: string;\n gameId?: string | null | undefined;\n}\n\n/**\n * Metrics about the current game session\n */\nexport interface AMServerInstanceMetrics {\n timeSinceLastPoll?: number;\n sessionUptime?: number;\n}\n\nexport interface AMServerPhysicalCardPreferences {\n preferredCardIdFormat?: \"idm\" | \"access\" | null;\n}\n\n/**\n * The response from an AMNet server's info endpoint\n */\nexport type AMServerInfo = AMServerMetadata & AMServerConnectionInfo & AMServerInstanceMetrics & AMServerPhysicalCardPreferences;\n\n/**\n * Performs the card-in request to the specified server\n * @param server The server to perform the request against\n * @param request The card-in request to send\n * @param signal The abort signal to use for the request\n */\nexport async function performCardIn(server: AMServerConnectionInfo, request: AMCardInRequest, signal: AbortSignal): Promise {\n if (server.apiVersion < MIN_AMNET_API_VERSION || server.apiVersion > AMNET_API_VERSION) {\n throw new Error(\"Unsupported server API version\");\n }\n \n try {\n const response = await fetch(`${new URL(server.serverAddress).origin}/amnet/signin`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\"\n },\n body: JSON.stringify(request),\n signal: signal\n });\n\n return response.ok;\n } catch {\n return false;\n }\n}\n\n/**\n * Attempts to connect to the specified server and fetch its info\n * @param serverAddress The origin address of the server to connect to\n * @param abort The abort signal to use for the request (for cancellation)\n */\nexport async function fetchServerInfo(serverAddress: string, abort: AbortSignal): Promise {\n try {\n const response = await fetch(`${new URL(serverAddress).origin}/amnet/info`, {\n signal: abort\n });\n \n if (!response.ok) {\n return null;\n }\n\n return {\n ...await response.json(),\n serverAddress: serverAddress\n } satisfies AMServerMetadata;\n } catch {\n return null;\n }\n}\n","export const CARD_ID_REGEX = /^(?:[0-9]{4} ?){5}$/i;\n\nexport function generateCardNumber(): string {\n let cardId = '';\n\n while (true) {\n // don't start with a 3\n const firstDigit = Math.floor(Math.random() * 10);\n\n if (firstDigit !== 3) {\n cardId = firstDigit.toString();\n break;\n }\n }\n\n for (let i = 0; i < 19; i++) {\n cardId += Math.floor(Math.random() * 10).toString();\n }\n\n return cardId;\n}\n\n/**\n * Validates the provided card id by known parameters\n * @param id The card id to validate\n */\nexport function validateCardId(id: string): boolean {\n return id[0] !== '3' && CARD_ID_REGEX.test(id);\n}\n","/**\n * Get the game name from the game identifier (4-letter code)\n * @param id\n */\nexport function getGameName(id: string): string | null {\n switch (id?.toUpperCase()) {\n case \"SDGT\":\n return \"Initial D The Arcade\";\n case \"SDHD\":\n case \"SDBT\":\n return \"CHUNITHM\";\n case \"SDDT\":\n return \"O.N.G.E.K.I.\";\n case \"SDEZ\":\n return \"maimai DX\";\n case \"SBZV\":\n return \"Project DIVA Future Tone\";\n \n default:\n return null;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGO,IAAM,oBAAoB;AAK1B,IAAM,wBAAwB;AA6CrC,SAAsB,cAAc,QAAgC,SAA0B,QAAuC;AAAA;AACjI,QAAI,OAAO,aAAa,yBAAyB,OAAO,aAAa,mBAAmB;AACpF,YAAM,IAAI,MAAM,gCAAgC;AAAA,IACpD;AAEA,QAAI;AACA,YAAM,WAAW,MAAM,MAAM,GAAG,IAAI,IAAI,OAAO,aAAa,EAAE,MAAM,iBAAiB;AAAA,QACjF,QAAQ;AAAA,QACR,SAAS;AAAA,UACL,gBAAgB;AAAA,QACpB;AAAA,QACA,MAAM,KAAK,UAAU,OAAO;AAAA,QAC5B;AAAA,MACJ,CAAC;AAED,aAAO,SAAS;AAAA,IACpB,SAAQ;AACJ,aAAO;AAAA,IACX;AAAA,EACJ;AAAA;AAOA,SAAsB,gBAAgB,eAAuB,OAAkD;AAAA;AAC3G,QAAI;AACA,YAAM,WAAW,MAAM,MAAM,GAAG,IAAI,IAAI,aAAa,EAAE,MAAM,eAAe;AAAA,QACxE,QAAQ;AAAA,MACZ,CAAC;AAED,UAAI,CAAC,SAAS,IAAI;AACd,eAAO;AAAA,MACX;AAEA,aAAO,iCACA,MAAM,SAAS,KAAK,IADpB;AAAA,QAEH;AAAA,MACJ;AAAA,IACJ,SAAQ;AACJ,aAAO;AAAA,IACX;AAAA,EACJ;AAAA;;;AChGO,IAAM,gBAAgB;AAEtB,SAAS,qBAA6B;AACzC,MAAI,SAAS;AAEb,SAAO,MAAM;AAET,UAAM,aAAa,KAAK,MAAM,KAAK,OAAO,IAAI,EAAE;AAEhD,QAAI,eAAe,GAAG;AAClB,eAAS,WAAW,SAAS;AAC7B;AAAA,IACJ;AAAA,EACJ;AAEA,WAAS,IAAI,GAAG,IAAI,IAAI,KAAK;AACzB,cAAU,KAAK,MAAM,KAAK,OAAO,IAAI,EAAE,EAAE,SAAS;AAAA,EACtD;AAEA,SAAO;AACX;AAMO,SAAS,eAAe,IAAqB;AAChD,SAAO,GAAG,CAAC,MAAM,OAAO,cAAc,KAAK,EAAE;AACjD;;;ACxBO,SAAS,YAAY,IAA2B;AACnD,UAAQ,yBAAI,eAAe;AAAA,IACvB,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AAAA,IACL,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IAEX;AACI,aAAO;AAAA,EACf;AACJ;","names":[]}
\ No newline at end of file
diff --git a/amnet-shared/src/api.ts b/amnet-shared/src/api.ts
index 1b90f75..acfb88c 100644
--- a/amnet-shared/src/api.ts
+++ b/amnet-shared/src/api.ts
@@ -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