mirror of
https://gitea.tendokyu.moe/ppc/amnet.git
synced 2026-09-27 17:27:55 +03:00
75 lines
2.5 KiB
TypeScript
75 lines
2.5 KiB
TypeScript
/**
|
|
* The latest version of the AMNet API this library supports
|
|
*/
|
|
declare const AMNET_API_VERSION = 1;
|
|
/**
|
|
* The minimum version of the AMNet API this library supports
|
|
*/
|
|
declare const MIN_AMNET_API_VERSION = 1;
|
|
interface AMCardInRequest {
|
|
cardId: string;
|
|
physicalCardIDm?: string;
|
|
}
|
|
/**
|
|
* Server connection info (api version, address, etc.)
|
|
*/
|
|
interface AMServerConnectionInfo {
|
|
apiVersion: number;
|
|
serverAddress: string;
|
|
}
|
|
/**
|
|
* User-definable server metadata
|
|
*/
|
|
interface AMServerMetadata {
|
|
serverName: string;
|
|
gameId?: string | null | undefined;
|
|
}
|
|
/**
|
|
* Metrics about the current game session
|
|
*/
|
|
interface AMServerInstanceMetrics {
|
|
timeSinceLastPoll?: number;
|
|
sessionUptime?: number;
|
|
}
|
|
/**
|
|
* The response from an AMNet server's info endpoint
|
|
*/
|
|
type AMServerInfo = AMServerMetadata & AMServerConnectionInfo & AMServerInstanceMetrics;
|
|
/**
|
|
* Performs the card-in request to the specified server
|
|
* @param server The server to perform the request against
|
|
* @param request The card-in request to send
|
|
* @param signal The abort signal to use for the request
|
|
*/
|
|
declare function performCardIn(server: AMServerConnectionInfo, request: AMCardInRequest, signal: AbortSignal): Promise<boolean>;
|
|
/**
|
|
* Attempts to connect to the specified server and fetch its info
|
|
* @param serverAddress The origin address of the server to connect to
|
|
* @param abort The abort signal to use for the request (for cancellation)
|
|
*/
|
|
declare function fetchServerInfo(serverAddress: string, abort: AbortSignal): Promise<AMServerInfo | null>;
|
|
|
|
declare const CARD_ID_REGEX: RegExp;
|
|
declare const AMNET_COMPANY_ID = 597;
|
|
declare function generateCardNumber(): string;
|
|
/**
|
|
* Validates the provided card id by known parameters
|
|
* @param id The card id to validate
|
|
*/
|
|
declare function validateCardId(id: string): boolean;
|
|
|
|
/**
|
|
* Get the game name from the game identifier (4-letter code)
|
|
* @param id
|
|
*/
|
|
declare function getGameName(id: string): string | null;
|
|
|
|
type DecodedAccessCode = {
|
|
revision: number;
|
|
serial: number;
|
|
};
|
|
declare function decodeAccessCode(code: string): DecodedAccessCode | null;
|
|
declare function encodeAccessCode(company: number, serial: number, rev?: number): string;
|
|
|
|
export { type AMCardInRequest, AMNET_API_VERSION, AMNET_COMPANY_ID, type AMServerConnectionInfo, type AMServerInfo, type AMServerInstanceMetrics, type AMServerMetadata, CARD_ID_REGEX, decodeAccessCode as DecodeAMAccessCode, encodeAccessCode as EncodeAMAccessCode, MIN_AMNET_API_VERSION, fetchServerInfo, generateCardNumber, getGameName, performCardIn, validateCardId };
|