@srvquery/protocol-fivem 0.0.1-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5235 -0
- package/dist/net/server-id.d.ts +14 -0
- package/dist/net/server-id.d.ts.map +1 -0
- package/dist/packet/formatting.d.ts +5 -0
- package/dist/packet/formatting.d.ts.map +1 -0
- package/dist/packet/schema.d.ts +67 -0
- package/dist/packet/schema.d.ts.map +1 -0
- package/dist/protocol.d.ts +45 -0
- package/dist/protocol.d.ts.map +1 -0
- package/package.json +33 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type CreateHttpClientParams } from "@srvquery/core";
|
|
2
|
+
/**
|
|
3
|
+
* Resolves a Cfx.re server id (the short code used in join links such as
|
|
4
|
+
* `https://cfx.re/join/<join>`) to a host and port pair, by querying the public Cfx.re server
|
|
5
|
+
* list API for the server's advertised connect endpoints.
|
|
6
|
+
*
|
|
7
|
+
* @param id The Cfx.re server id.
|
|
8
|
+
* @param timeout Time in milliseconds to wait for the lookup before aborting.
|
|
9
|
+
* @returns The resolved host and port pair for the server's HTTP query endpoints.
|
|
10
|
+
* @throws {QueryTransportError} If the id is unknown, the lookup times out, or it resolves to no
|
|
11
|
+
* usable IPv4 endpoint.
|
|
12
|
+
*/
|
|
13
|
+
export declare const resolveServerId: (id: string, timeout?: number) => Promise<CreateHttpClientParams>;
|
|
14
|
+
//# sourceMappingURL=server-id.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-id.d.ts","sourceRoot":"","sources":["../../src/net/server-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuC,KAAK,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAQlG;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,OACtB,MAAM,uBAET,OAAO,CAAC,sBAAsB,CAuDhC,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Strips FiveM/RedM `^`-prefixed color and formatting codes from a string. */
|
|
2
|
+
export declare const stripFiveMFormattingCodes: (value: string) => string;
|
|
3
|
+
/** Recursively strips FiveM/RedM formatting codes from every string found in `value`. */
|
|
4
|
+
export declare const deepStripFiveMFormattingCodes: <T>(value: T) => T;
|
|
5
|
+
//# sourceMappingURL=formatting.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatting.d.ts","sourceRoot":"","sources":["../../src/packet/formatting.ts"],"names":[],"mappings":"AAMA,+EAA+E;AAC/E,eAAO,MAAM,yBAAyB,UAAW,MAAM,KAAG,MACd,CAAC;AAE7C,yFAAyF;AACzF,eAAO,MAAM,6BAA6B,GAAI,CAAC,SAAS,CAAC,KAAG,CAS3D,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Validates the `vars` map returned by a FiveM/RedM `info.json` query.
|
|
4
|
+
*
|
|
5
|
+
* `vars` mirrors whatever `set`/`sets` convars a server operator has defined, so there is no fixed, documented set of keys. The fields below are commonly present across public servers (surfaced by the Cfx server list and/or txAdmin) and are typed for convenience; any other convar is still preserved via the catch-all.
|
|
6
|
+
*/
|
|
7
|
+
export declare const FiveMVarsSchema: z.ZodObject<{
|
|
8
|
+
sv_projectName: z.ZodOptional<z.ZodString>;
|
|
9
|
+
sv_projectDesc: z.ZodOptional<z.ZodString>;
|
|
10
|
+
sv_maxClients: z.ZodOptional<z.ZodString>;
|
|
11
|
+
locale: z.ZodOptional<z.ZodString>;
|
|
12
|
+
tags: z.ZodOptional<z.ZodString>;
|
|
13
|
+
banner_connecting: z.ZodOptional<z.ZodString>;
|
|
14
|
+
banner_detail: z.ZodOptional<z.ZodString>;
|
|
15
|
+
}, z.core.$catchall<z.ZodString>>;
|
|
16
|
+
/** Convar-style key/value pairs (`sv_hostname`, `sv_maxClients`, ...) reported by the server. */
|
|
17
|
+
export type FiveMVars = z.infer<typeof FiveMVarsSchema>;
|
|
18
|
+
/** Validates a FiveM/RedM `info.json` response. */
|
|
19
|
+
export declare const FiveMServerInfoSchema: z.ZodObject<{
|
|
20
|
+
version: z.ZodNumber;
|
|
21
|
+
icon: z.ZodOptional<z.ZodString>;
|
|
22
|
+
vars: z.ZodOptional<z.ZodObject<{
|
|
23
|
+
sv_projectName: z.ZodOptional<z.ZodString>;
|
|
24
|
+
sv_projectDesc: z.ZodOptional<z.ZodString>;
|
|
25
|
+
sv_maxClients: z.ZodOptional<z.ZodString>;
|
|
26
|
+
locale: z.ZodOptional<z.ZodString>;
|
|
27
|
+
tags: z.ZodOptional<z.ZodString>;
|
|
28
|
+
banner_connecting: z.ZodOptional<z.ZodString>;
|
|
29
|
+
banner_detail: z.ZodOptional<z.ZodString>;
|
|
30
|
+
}, z.core.$catchall<z.ZodString>>>;
|
|
31
|
+
resources: z.ZodArray<z.ZodString>;
|
|
32
|
+
server: z.ZodString;
|
|
33
|
+
}, z.core.$strip>;
|
|
34
|
+
/** General server metadata, resources and convars returned by an `INFO` query. */
|
|
35
|
+
export type FiveMServerInfo = z.infer<typeof FiveMServerInfoSchema>;
|
|
36
|
+
/** Validates a single connected player entry returned by a `players.json` query. */
|
|
37
|
+
export declare const FiveMPlayerSchema: z.ZodObject<{
|
|
38
|
+
id: z.ZodNumber;
|
|
39
|
+
name: z.ZodString;
|
|
40
|
+
ping: z.ZodNumber;
|
|
41
|
+
identifiers: z.ZodArray<z.ZodString>;
|
|
42
|
+
endpoint: z.ZodOptional<z.ZodString>;
|
|
43
|
+
}, z.core.$strip>;
|
|
44
|
+
/** Validates the player list returned by a FiveM/RedM `players.json` query. */
|
|
45
|
+
export declare const FiveMPlayersSchema: z.ZodArray<z.ZodObject<{
|
|
46
|
+
id: z.ZodNumber;
|
|
47
|
+
name: z.ZodString;
|
|
48
|
+
ping: z.ZodNumber;
|
|
49
|
+
identifiers: z.ZodArray<z.ZodString>;
|
|
50
|
+
endpoint: z.ZodOptional<z.ZodString>;
|
|
51
|
+
}, z.core.$strip>>;
|
|
52
|
+
/** Connected player entry containing an ID, name, ping and identifiers. */
|
|
53
|
+
export type FiveMPlayer = z.infer<typeof FiveMPlayerSchema>;
|
|
54
|
+
/** Connected player entries returned by a FiveM/RedM `PLAYERS` query. */
|
|
55
|
+
export type FiveMPlayers = z.infer<typeof FiveMPlayersSchema>;
|
|
56
|
+
/** Validates a FiveM/RedM `dynamic.json` response. */
|
|
57
|
+
export declare const FiveMDynamicSchema: z.ZodObject<{
|
|
58
|
+
hostname: z.ZodString;
|
|
59
|
+
gametype: z.ZodString;
|
|
60
|
+
mapname: z.ZodString;
|
|
61
|
+
clients: z.ZodCoercedNumber<unknown>;
|
|
62
|
+
sv_maxclients: z.ZodCoercedNumber<unknown>;
|
|
63
|
+
iv: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
64
|
+
}, z.core.$strip>;
|
|
65
|
+
/** Lightweight, server-browser-oriented summary returned by a `DYNAMIC` query. */
|
|
66
|
+
export type FiveMDynamic = z.infer<typeof FiveMDynamicSchema>;
|
|
67
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/packet/schema.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AAEpB;;;;GAIG;AACH,eAAO,MAAM,eAAe;;;;;;;;iCAUL,CAAC;AAExB,iGAAiG;AACjG,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAExD,mDAAmD;AACnD,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;iBAMhC,CAAC;AAEH,kFAAkF;AAClF,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEpE,oFAAoF;AACpF,eAAO,MAAM,iBAAiB;;;;;;iBAM5B,CAAC;AAEH,+EAA+E;AAC/E,eAAO,MAAM,kBAAkB;;;;;;kBAA6B,CAAC;AAE7D,2EAA2E;AAC3E,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAC5D,yEAAyE;AACzE,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE9D,sDAAsD;AACtD,eAAO,MAAM,kBAAkB;;;;;;;iBAO7B,CAAC;AAEH,kFAAkF;AAClF,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { CreateHttpClientOptions, CreateHttpClientParams } from "@srvquery/core";
|
|
2
|
+
import { type FiveMDynamic, type FiveMPlayers, type FiveMServerInfo } from "./packet/schema";
|
|
3
|
+
/**
|
|
4
|
+
* Locates a FiveM/RedM server, either directly by `host`/`port` or by its Cfx.re server id (the
|
|
5
|
+
* short code used in join links such as `https://cfx.re/join/<id>`).
|
|
6
|
+
*/
|
|
7
|
+
export type FiveMServerLocator = (CreateHttpClientParams & {
|
|
8
|
+
id?: never;
|
|
9
|
+
}) | {
|
|
10
|
+
id: string;
|
|
11
|
+
host?: never;
|
|
12
|
+
port?: never;
|
|
13
|
+
};
|
|
14
|
+
/** Connection and retry settings used to create a FiveM/RedM protocol client. */
|
|
15
|
+
export type CreateFiveMProtocolParams = FiveMServerLocator & CreateHttpClientOptions;
|
|
16
|
+
/** Endpoints exposed by an FXServer, keyed by their public `.json` path. */
|
|
17
|
+
export type FiveMProtocolRequestOpcode = "INFO" | "PLAYERS" | "DYNAMIC";
|
|
18
|
+
type FiveMProtocolQueryParams<Opcode extends FiveMProtocolRequestOpcode> = {
|
|
19
|
+
opcode: Opcode;
|
|
20
|
+
/** Strip FiveM/RedM `^`-prefixed color/formatting codes from every string in the response. */
|
|
21
|
+
stripFormattingCodes?: boolean;
|
|
22
|
+
};
|
|
23
|
+
type FiveMProtocolResponseMap = {
|
|
24
|
+
INFO: FiveMServerInfo;
|
|
25
|
+
PLAYERS: FiveMPlayers;
|
|
26
|
+
DYNAMIC: FiveMDynamic;
|
|
27
|
+
};
|
|
28
|
+
/** Client for querying FiveM and RedM (FXServer) servers. */
|
|
29
|
+
export interface FiveMProtocol {
|
|
30
|
+
/** Queries one FXServer endpoint and resolves with its corresponding response model. */
|
|
31
|
+
query<Opcode extends FiveMProtocolRequestOpcode>(params: FiveMProtocolQueryParams<Opcode>): Promise<FiveMProtocolResponseMap[Opcode]>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Creates a client for querying FiveM and RedM (FXServer) servers.
|
|
35
|
+
*
|
|
36
|
+
* The server can be located either by `host`/`port` or by its Cfx.re server id; when an id is
|
|
37
|
+
* given it is resolved to a host and port pair on first use and cached for the lifetime of the
|
|
38
|
+
* returned client.
|
|
39
|
+
*
|
|
40
|
+
* @param params Target server (by `host`/`port` or `id`) and HTTP transport settings.
|
|
41
|
+
* @returns A client whose `query` method returns the response type for the requested opcode.
|
|
42
|
+
*/
|
|
43
|
+
export declare const createFiveMProtocol: ({ protocol, timeout, retry, ...locator }: CreateFiveMProtocolParams) => FiveMProtocol;
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EAKvB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,eAAe,EACrB,MAAM,iBAAiB,CAAC;AAEzB;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAC1B,CAAC,sBAAsB,GAAG;IAAE,EAAE,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC,GACzC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,KAAK,CAAC;IAAC,IAAI,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC;AAE/C,iFAAiF;AACjF,MAAM,MAAM,yBAAyB,GAAG,kBAAkB,GAAG,uBAAuB,CAAC;AAErF,4EAA4E;AAC5E,MAAM,MAAM,0BAA0B,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,CAAC;AAExE,KAAK,wBAAwB,CAAC,MAAM,SAAS,0BAA0B,IAAI;IACzE,MAAM,EAAE,MAAM,CAAC;IACf,8FAA8F;IAC9F,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC,CAAC;AAEF,KAAK,wBAAwB,GAAG;IAC9B,IAAI,EAAE,eAAe,CAAC;IACtB,OAAO,EAAE,YAAY,CAAC;IACtB,OAAO,EAAE,YAAY,CAAC;CACvB,CAAC;AAEF,6DAA6D;AAC7D,MAAM,WAAW,aAAa;IAC5B,wFAAwF;IACxF,KAAK,CAAC,MAAM,SAAS,0BAA0B,EAC7C,MAAM,EAAE,wBAAwB,CAAC,MAAM,CAAC,GACvC,OAAO,CAAC,wBAAwB,CAAC,MAAM,CAAC,CAAC,CAAC;CAC9C;AAcD;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,6CAK7B,yBAAyB,KAAG,aA8B9B,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@srvquery/protocol-fivem",
|
|
3
|
+
"version": "0.0.1-next.0",
|
|
4
|
+
"files": [
|
|
5
|
+
"dist"
|
|
6
|
+
],
|
|
7
|
+
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"zod": "^4.5.4"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@internal/typescript-config": "0.0.0",
|
|
19
|
+
"@srvquery/core": "0.0.1-next.0",
|
|
20
|
+
"@types/node": "^26.4.1",
|
|
21
|
+
"rolldown": "^1.2.7",
|
|
22
|
+
"typescript": "^7.0.2",
|
|
23
|
+
"vitest": "^5.0.0"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"@srvquery/core": "0.0.1-next.0"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "rolldown -c rolldown.config.ts && tsc -p tsconfig.json",
|
|
30
|
+
"test": "vitest run",
|
|
31
|
+
"test:watch": "vitest"
|
|
32
|
+
}
|
|
33
|
+
}
|