@srvquery/protocol-openmp 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 +71 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5714 -0
- package/dist/packet/opcodes.d.ts +16 -0
- package/dist/packet/opcodes.d.ts.map +1 -0
- package/dist/packet/request.d.ts +21 -0
- package/dist/packet/request.d.ts.map +1 -0
- package/dist/packet/schema.d.ts +53 -0
- package/dist/packet/schema.d.ts.map +1 -0
- package/dist/packet/serde.d.ts +40 -0
- package/dist/packet/serde.d.ts.map +1 -0
- package/dist/protocol.d.ts +31 -0
- package/dist/protocol.d.ts.map +1 -0
- package/package.json +33 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenMP protocol request opcodes.
|
|
3
|
+
* @link https://open.mp/docs/tutorials/QueryMechanism#opcode
|
|
4
|
+
*/
|
|
5
|
+
export declare const requestOpcodes: {
|
|
6
|
+
readonly INFO: 105;
|
|
7
|
+
readonly RULES: 114;
|
|
8
|
+
readonly CLIENT_LIST: 99;
|
|
9
|
+
readonly PLAYERS: 100;
|
|
10
|
+
readonly PING: 112;
|
|
11
|
+
};
|
|
12
|
+
/** Symbolic opcode accepted by an open.mp query. */
|
|
13
|
+
export type OpenMPProtocolRequestOpcode = keyof typeof requestOpcodes;
|
|
14
|
+
/** Numeric wire value for an open.mp request opcode. */
|
|
15
|
+
export type OpenMPProtocolRequestOpcodeValue = (typeof requestOpcodes)[keyof typeof requestOpcodes];
|
|
16
|
+
//# sourceMappingURL=opcodes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opcodes.d.ts","sourceRoot":"","sources":["../../src/packet/opcodes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,cAAc;aACzB,IAAI,EAAE,GAAG;aACT,KAAK,EAAE,GAAG;aACV,WAAW,EAAE,EAAE;aACf,OAAO,EAAE,GAAG;aACZ,IAAI,EAAE,GAAG;CACD,CAAC;AAEX,oDAAoD;AACpD,MAAM,MAAM,2BAA2B,GAAG,MAAM,OAAO,cAAc,CAAC;AACtE,wDAAwD;AACxD,MAAM,MAAM,gCAAgC,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,OAAO,cAAc,CAAC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { OpenMPProtocolRequestOpcode } from "./opcodes";
|
|
2
|
+
/** Values encoded into an open.mp query request packet. */
|
|
3
|
+
export type BuildRequestPacketParams = {
|
|
4
|
+
/** Query opcode to encode. */
|
|
5
|
+
opcode: OpenMPProtocolRequestOpcode;
|
|
6
|
+
/** Target IPv4 address embedded in the packet header. */
|
|
7
|
+
ip: string;
|
|
8
|
+
/** Target port embedded in little-endian order. */
|
|
9
|
+
port: number;
|
|
10
|
+
};
|
|
11
|
+
/** Length in bytes of an open.mp query packet header. */
|
|
12
|
+
export declare const packetHeaderLength = 11;
|
|
13
|
+
/**
|
|
14
|
+
* Builds a request packet for the OpenMP protocol.
|
|
15
|
+
* @link https://open.mp/docs/tutorials/QueryMechanism#serialized-data
|
|
16
|
+
*
|
|
17
|
+
* @param param0 The parameters for building the packet header, including the opcode, IP address, and port number.
|
|
18
|
+
* @returns A Buffer containing the request packet.
|
|
19
|
+
*/
|
|
20
|
+
export declare const buildRequestPacket: ({ opcode, ip, port }: BuildRequestPacketParams) => Buffer;
|
|
21
|
+
//# sourceMappingURL=request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/packet/request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAkB,MAAM,WAAW,CAAC;AAExE,2DAA2D;AAC3D,MAAM,MAAM,wBAAwB,GAAG;IACrC,8BAA8B;IAC9B,MAAM,EAAE,2BAA2B,CAAC;IACpC,yDAAyD;IACzD,EAAE,EAAE,MAAM,CAAC;IACX,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,yDAAyD;AACzD,eAAO,MAAM,kBAAkB,KAAK,CAAC;AAErC;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,yBAA0B,wBAAwB,KAAG,MAUnF,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
/** Validates an open.mp `INFO` response. */
|
|
3
|
+
export declare const OpenMPServerInfoSchema: z.ZodObject<{
|
|
4
|
+
password: z.ZodUnion<readonly [z.ZodLiteral<0>, z.ZodLiteral<1>]>;
|
|
5
|
+
players: z.ZodNumber;
|
|
6
|
+
maxPlayers: z.ZodNumber;
|
|
7
|
+
hostname: z.ZodString;
|
|
8
|
+
gamemode: z.ZodString;
|
|
9
|
+
language: z.ZodString;
|
|
10
|
+
}, z.core.$strip>;
|
|
11
|
+
/** General server metadata returned by an open.mp `INFO` query. */
|
|
12
|
+
export type OpenMPServerInfo = z.infer<typeof OpenMPServerInfoSchema>;
|
|
13
|
+
/** Validates the string key-value map returned by an open.mp `RULES` query. */
|
|
14
|
+
export declare const OpenMPRulesSchema: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
15
|
+
/** Server rule names and values returned by an open.mp `RULES` query. */
|
|
16
|
+
export type OpenMPRules = z.infer<typeof OpenMPRulesSchema>;
|
|
17
|
+
/** Validates a compact client entry containing a name and score. */
|
|
18
|
+
export declare const OpenMPClientSchema: z.ZodObject<{
|
|
19
|
+
name: z.ZodString;
|
|
20
|
+
score: z.ZodNumber;
|
|
21
|
+
}, z.core.$strip>;
|
|
22
|
+
/** Validates the compact client list returned by a `CLIENT_LIST` query. */
|
|
23
|
+
export declare const OpenMPClientListSchema: z.ZodArray<z.ZodObject<{
|
|
24
|
+
name: z.ZodString;
|
|
25
|
+
score: z.ZodNumber;
|
|
26
|
+
}, z.core.$strip>>;
|
|
27
|
+
/** Compact open.mp client entry containing a name and score. */
|
|
28
|
+
export type OpenMPClient = z.infer<typeof OpenMPClientSchema>;
|
|
29
|
+
/** Compact client entries returned by an open.mp `CLIENT_LIST` query. */
|
|
30
|
+
export type OpenMPClientList = z.infer<typeof OpenMPClientListSchema>;
|
|
31
|
+
/** Validates a detailed open.mp player entry. */
|
|
32
|
+
export declare const OpenMPPlayerSchema: z.ZodObject<{
|
|
33
|
+
id: z.ZodNumber;
|
|
34
|
+
name: z.ZodString;
|
|
35
|
+
score: z.ZodNumber;
|
|
36
|
+
ping: z.ZodNumber;
|
|
37
|
+
}, z.core.$strip>;
|
|
38
|
+
/** Validates the detailed player list returned by a `PLAYERS` query. */
|
|
39
|
+
export declare const OpenMPPlayersSchema: z.ZodArray<z.ZodObject<{
|
|
40
|
+
id: z.ZodNumber;
|
|
41
|
+
name: z.ZodString;
|
|
42
|
+
score: z.ZodNumber;
|
|
43
|
+
ping: z.ZodNumber;
|
|
44
|
+
}, z.core.$strip>>;
|
|
45
|
+
/** Detailed open.mp player entry containing an ID, name, score, and ping. */
|
|
46
|
+
export type OpenMPPlayer = z.infer<typeof OpenMPPlayerSchema>;
|
|
47
|
+
/** Detailed player entries returned by an open.mp `PLAYERS` query. */
|
|
48
|
+
export type OpenMPPlayers = z.infer<typeof OpenMPPlayersSchema>;
|
|
49
|
+
/** Validates the non-negative round-trip latency returned by an open.mp `PING` query. */
|
|
50
|
+
export declare const OpenMPPingSchema: z.ZodNumber;
|
|
51
|
+
/** Round-trip latency in milliseconds measured by an open.mp `PING` query. */
|
|
52
|
+
export type OpenMPPing = z.infer<typeof OpenMPPingSchema>;
|
|
53
|
+
//# 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;AAMpB,4CAA4C;AAC5C,eAAO,MAAM,sBAAsB;;;;;;;iBAOjC,CAAC;AAEH,mEAAmE;AACnE,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEtE,+EAA+E;AAC/E,eAAO,MAAM,iBAAiB,uCAAmC,CAAC;AAElE,yEAAyE;AACzE,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE5D,oEAAoE;AACpE,eAAO,MAAM,kBAAkB;;;iBAG7B,CAAC;AAEH,2EAA2E;AAC3E,eAAO,MAAM,sBAAsB;;;kBAA8B,CAAC;AAElE,gEAAgE;AAChE,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAC9D,yEAAyE;AACzE,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEtE,iDAAiD;AACjD,eAAO,MAAM,kBAAkB;;;;;iBAK7B,CAAC;AAEH,wEAAwE;AACxE,eAAO,MAAM,mBAAmB;;;;;kBAA8B,CAAC;AAE/D,6EAA6E;AAC7E,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAC9D,sEAAsE;AACtE,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEhE,yFAAyF;AACzF,eAAO,MAAM,gBAAgB,aAA2B,CAAC;AAEzD,8EAA8E;AAC9E,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { BufferCursor } from "@srvquery/core";
|
|
2
|
+
/** Deserializes an open.mp response from a cursor positioned at its packet header. */
|
|
3
|
+
export type OpenMPTextDecoder = (buffer: Buffer) => string;
|
|
4
|
+
export type OpenMPPacketDeserializeFn = (cursor: BufferCursor, decodeText: OpenMPTextDecoder) => unknown;
|
|
5
|
+
/**
|
|
6
|
+
* Parses the server info from the given buffer cursor.
|
|
7
|
+
*
|
|
8
|
+
* @param cursor The buffer cursor pointing to the server info data.
|
|
9
|
+
* @returns The parsed server info object.
|
|
10
|
+
*/
|
|
11
|
+
export declare const deserializeInfoPacket: OpenMPPacketDeserializeFn;
|
|
12
|
+
/**
|
|
13
|
+
* Parses the ping value from the given buffer cursor.
|
|
14
|
+
*
|
|
15
|
+
* @param cursor The buffer cursor pointing to the ping data.
|
|
16
|
+
* @returns The parsed ping value as an OpenMPPing object.
|
|
17
|
+
*/
|
|
18
|
+
export declare const deserializePingPacket: OpenMPPacketDeserializeFn;
|
|
19
|
+
/**
|
|
20
|
+
* Parses the server rules from the given buffer cursor.
|
|
21
|
+
*
|
|
22
|
+
* @param cursor The buffer cursor pointing to the rules data.
|
|
23
|
+
* @returns The parsed rules object as an OpenMPRules instance.
|
|
24
|
+
*/
|
|
25
|
+
export declare const deserializeRulesPacket: OpenMPPacketDeserializeFn;
|
|
26
|
+
/**
|
|
27
|
+
* Parses the client list from the given buffer cursor.
|
|
28
|
+
*
|
|
29
|
+
* @param cursor The buffer cursor pointing to the client list data.
|
|
30
|
+
* @returns The parsed client list as an OpenMPClientList object.
|
|
31
|
+
*/
|
|
32
|
+
export declare const deserializeClientListPacket: OpenMPPacketDeserializeFn;
|
|
33
|
+
/**
|
|
34
|
+
* Parses the list of players from the given buffer cursor.
|
|
35
|
+
*
|
|
36
|
+
* @param cursor The buffer cursor pointing to the players data.
|
|
37
|
+
* @returns The parsed players list as an OpenMPPlayers object.
|
|
38
|
+
*/
|
|
39
|
+
export declare const deserializePlayersPacket: OpenMPPacketDeserializeFn;
|
|
40
|
+
//# sourceMappingURL=serde.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serde.d.ts","sourceRoot":"","sources":["../../src/packet/serde.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAc9C,sFAAsF;AACtF,MAAM,MAAM,iBAAiB,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;AAC3D,MAAM,MAAM,yBAAyB,GAAG,CACtC,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,iBAAiB,KAC1B,OAAO,CAAC;AASb;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,EAAE,yBAoBnC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,EAAE,yBAKnC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,EAAE,yBAepC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,EAAE,yBAazC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,EAAE,yBAetC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { CreateUdpSocketOptions, CreateUdpSocketParams } from "@srvquery/core";
|
|
2
|
+
import { OpenMPProtocolRequestOpcode } from "./packet/opcodes";
|
|
3
|
+
import { type OpenMPTextDecoder } from "./packet/serde";
|
|
4
|
+
import { OpenMPClientList, OpenMPPlayers, OpenMPRules, type OpenMPPing, type OpenMPServerInfo } from "./packet/schema";
|
|
5
|
+
/** Connection and retry settings used to create an open.mp protocol client. */
|
|
6
|
+
export type CreateOpenMPProtocolParams = CreateUdpSocketParams & CreateUdpSocketOptions;
|
|
7
|
+
type OpenMPProtocolQueryParams<Opcode extends OpenMPProtocolRequestOpcode> = {
|
|
8
|
+
opcode: Opcode;
|
|
9
|
+
/** Decodes text fields returned by the server. Defaults to UTF-8. */
|
|
10
|
+
decodeText?: OpenMPTextDecoder;
|
|
11
|
+
};
|
|
12
|
+
type OpenMPProtocolResponseMap = {
|
|
13
|
+
INFO: OpenMPServerInfo;
|
|
14
|
+
RULES: OpenMPRules;
|
|
15
|
+
CLIENT_LIST: OpenMPClientList;
|
|
16
|
+
PLAYERS: OpenMPPlayers;
|
|
17
|
+
PING: OpenMPPing;
|
|
18
|
+
};
|
|
19
|
+
/** Client for querying SA-MP and open.mp servers. */
|
|
20
|
+
export interface OpenMPProtocol {
|
|
21
|
+
/** Queries one open.mp opcode and resolves with its corresponding response model. */
|
|
22
|
+
query<Opcode extends OpenMPProtocolRequestOpcode>(params: OpenMPProtocolQueryParams<Opcode>): Promise<OpenMPProtocolResponseMap[Opcode]>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Creates a client for querying SA-MP and open.mp servers.
|
|
26
|
+
* @param params Target server and UDP transport settings.
|
|
27
|
+
* @returns A client whose `query` method returns the response type for the requested opcode.
|
|
28
|
+
*/
|
|
29
|
+
export declare const createOpenMPProtocol: ({ host, port, retry, timeout, ...socketOptions }: CreateOpenMPProtocolParams) => OpenMPProtocol;
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,sBAAsB,EACtB,qBAAqB,EAKtB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAOL,KAAK,iBAAiB,EACvB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,KAAK,UAAU,EACf,KAAK,gBAAgB,EACtB,MAAM,iBAAiB,CAAC;AAEzB,+EAA+E;AAC/E,MAAM,MAAM,0BAA0B,GAAG,qBAAqB,GAAG,sBAAsB,CAAC;AAWxF,KAAK,yBAAyB,CAAC,MAAM,SAAS,2BAA2B,IAAI;IAC3E,MAAM,EAAE,MAAM,CAAC;IACf,qEAAqE;IACrE,UAAU,CAAC,EAAE,iBAAiB,CAAC;CAChC,CAAC;AAEF,KAAK,yBAAyB,GAAG;IAC/B,IAAI,EAAE,gBAAgB,CAAC;IACvB,KAAK,EAAE,WAAW,CAAC;IACnB,WAAW,EAAE,gBAAgB,CAAC;IAC9B,OAAO,EAAE,aAAa,CAAC;IACvB,IAAI,EAAE,UAAU,CAAC;CAClB,CAAC;AAEF,qDAAqD;AACrD,MAAM,WAAW,cAAc;IAC7B,qFAAqF;IACrF,KAAK,CAAC,MAAM,SAAS,2BAA2B,EAC9C,MAAM,EAAE,yBAAyB,CAAC,MAAM,CAAC,GACxC,OAAO,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC,CAAC;CAC/C;AAUD;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,qDAM9B,0BAA0B,KAAG,cAgE/B,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@srvquery/protocol-openmp",
|
|
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
|
+
}
|