@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 ADDED
@@ -0,0 +1,71 @@
1
+ # @srvquery/protocol-openmp
2
+
3
+ ![npm Version](https://shieldcn.dev/npm/@srvquery/protocol-openmp.svg?variant=secondary) ![npm Weekly Downloads](https://shieldcn.dev/npm/@srvquery/protocol-openmp/downloads.svg)
4
+
5
+ Query GTA:SA multiplayer (SA-MP / open.mp) game servers.
6
+
7
+ ## Installation
8
+
9
+ ```sh
10
+ pnpm add @srvquery/protocol-openmp
11
+ ```
12
+
13
+ Install `iconv-lite` separately when querying servers that return Cyrillic text using a legacy
14
+ encoding such as Windows-1251:
15
+
16
+ ```sh
17
+ pnpm add iconv-lite
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ```ts
23
+ import { createOpenMPProtocol } from "@srvquery/protocol-openmp";
24
+
25
+ const host = "127.0.0.1";
26
+ const port = 7777;
27
+
28
+ const openmp = createOpenMPProtocol({ host, port });
29
+
30
+ const info = await openmp.query({ opcode: "INFO" });
31
+ const rules = await openmp.query({ opcode: "RULES" });
32
+ const clients = await openmp.query({ opcode: "CLIENT_LIST" });
33
+ const players = await openmp.query({ opcode: "PLAYERS" });
34
+ const ping = await openmp.query({ opcode: "PING" });
35
+
36
+ console.log(`${info.hostname}: ${info.players}/${info.maxPlayers}`);
37
+ console.log({ rules, clients, players, ping });
38
+ ```
39
+
40
+ ## Query types
41
+
42
+ | Opcode | Wire value | Description |
43
+ | ------------- | ---------- | ----------------------------------------------------- |
44
+ | `INFO` | `i` | Hostname, gamemode, language, player counts, password |
45
+ | `RULES` | `r` | Server rules (gravity, weather, weburl, etc.) |
46
+ | `CLIENT_LIST` | `c` | Player names and scores |
47
+ | `PLAYERS` | `d` | Detailed player info: id, name, score, ping |
48
+ | `PING` | `p` | Round-trip latency to the server |
49
+
50
+ Reference: [open.mp SA:MP Query Mechanism](https://open.mp/docs/tutorials/QueryMechanism)
51
+
52
+ ## Text encoding
53
+
54
+ SA-MP servers do not identify the encoding of text fields in query responses. UTF-8 is used by
55
+ default. For servers that use a legacy encoding such as Windows-1251, pass a decoder for the
56
+ returned byte strings:
57
+
58
+ ```ts
59
+ import iconv from "iconv-lite";
60
+ import { createOpenMPProtocol } from "@srvquery/protocol-openmp";
61
+
62
+ const openmp = createOpenMPProtocol({
63
+ host: "127.0.0.1",
64
+ port: 7777,
65
+ });
66
+
67
+ const info = await openmp.query({
68
+ opcode: "INFO",
69
+ decodeText: (buffer) => iconv.decode(buffer, "win1251"),
70
+ });
71
+ ```
@@ -0,0 +1,4 @@
1
+ export { createOpenMPProtocol, type OpenMPProtocol, type CreateOpenMPProtocolParams, } from "./protocol";
2
+ export { type OpenMPClient, type OpenMPClientList, type OpenMPPing, type OpenMPPlayer, type OpenMPPlayers, type OpenMPRules, type OpenMPServerInfo, } from "./packet/schema";
3
+ export type { OpenMPTextDecoder } from "./packet/serde";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,KAAK,cAAc,EACnB,KAAK,0BAA0B,GAChC,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,gBAAgB,GACtB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC"}