@srvquery/protocol-valve 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 +78 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6261 -0
- package/dist/packet/opcodes.d.ts +37 -0
- package/dist/packet/opcodes.d.ts.map +1 -0
- package/dist/packet/reassembly.d.ts +8 -0
- package/dist/packet/reassembly.d.ts.map +1 -0
- package/dist/packet/request.d.ts +16 -0
- package/dist/packet/request.d.ts.map +1 -0
- package/dist/packet/schema.d.ts +77 -0
- package/dist/packet/schema.d.ts.map +1 -0
- package/dist/packet/serde.d.ts +32 -0
- package/dist/packet/serde.d.ts.map +1 -0
- package/dist/protocol.d.ts +44 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/rules/errors.d.ts +42 -0
- package/dist/rules/errors.d.ts.map +1 -0
- package/dist/rules/server-browser-protocol-2-parser.d.ts +30 -0
- package/dist/rules/server-browser-protocol-2-parser.d.ts.map +1 -0
- package/dist/rules/server-browser-protocol-3-parser.d.ts +48 -0
- package/dist/rules/server-browser-protocol-3-parser.d.ts.map +1 -0
- package/dist/rules/server-browser-protocol-reassembly.d.ts +51 -0
- package/dist/rules/server-browser-protocol-reassembly.d.ts.map +1 -0
- package/dist/rules/valve-rule-parser.d.ts +16 -0
- package/dist/rules/valve-rule-parser.d.ts.map +1 -0
- package/package.json +33 -0
package/README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# @srvquery/protocol-valve
|
|
2
|
+
|
|
3
|
+
 
|
|
4
|
+
|
|
5
|
+
Query game servers that implement the Valve server query protocol.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pnpm add @srvquery/protocol-valve
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { createValveProtocol } from "@srvquery/protocol-valve";
|
|
17
|
+
|
|
18
|
+
const valve = createValveProtocol({
|
|
19
|
+
host: "127.0.0.1",
|
|
20
|
+
port: 27015,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const info = await valve.query({ opcode: "INFO" });
|
|
24
|
+
const players = await valve.query({ opcode: "PLAYERS" });
|
|
25
|
+
|
|
26
|
+
console.log(`${info.name}: ${info.players}/${info.maxPlayers}`);
|
|
27
|
+
console.log({ players });
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## DayZ and Arma 3 `RULES`
|
|
31
|
+
|
|
32
|
+
DayZ and Arma 3 embed an additional, nested protocol inside the raw `A2S_RULES` response, sometimes called the "Server Browser Protocol": key=value rule pairs are used to carry paged, escaped chunks of a binary message describing DLCs, mods, signatures, and (for DayZ) a server description. The default `RULES` query only decodes the raw string pairs; use one of the parsers below via the `parser` option to decode that nested message instead.
|
|
33
|
+
|
|
34
|
+
- DayZ responds with protocol version `2`. Use `serverBrowserProtocol2RulesParser`.
|
|
35
|
+
- Arma 3 responds with protocol version `3`, which additionally carries difficulty settings and Creator DLC entries. Use `serverBrowserProtocol3RulesParser`.
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { createValveProtocol, serverBrowserProtocol2RulesParser } from "@srvquery/protocol-valve";
|
|
39
|
+
|
|
40
|
+
const dayz = createValveProtocol({
|
|
41
|
+
host: "127.0.0.1",
|
|
42
|
+
port: 2302,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const rules = await dayz.query({
|
|
46
|
+
opcode: "RULES",
|
|
47
|
+
parser: serverBrowserProtocol2RulesParser,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
console.log(rules.mods);
|
|
51
|
+
console.log(rules.description);
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { createValveProtocol, serverBrowserProtocol3RulesParser } from "@srvquery/protocol-valve";
|
|
56
|
+
|
|
57
|
+
const arma3 = createValveProtocol({
|
|
58
|
+
host: "127.0.0.1",
|
|
59
|
+
port: 2302,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const rules = await arma3.query({
|
|
63
|
+
opcode: "RULES",
|
|
64
|
+
parser: serverBrowserProtocol3RulesParser,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
console.log(rules.dlcs);
|
|
68
|
+
console.log(rules.creatorDlcs);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Both parsers throw a version-specific error (see [`rules/errors.ts`](src/rules/errors.ts)) if the
|
|
72
|
+
response doesn't match the expected protocol version.
|
|
73
|
+
|
|
74
|
+
Background and wire-format references:
|
|
75
|
+
|
|
76
|
+
- [Arma 3: ServerBrowserProtocol3](https://community.bistudio.com/wiki/Arma_3:_ServerBrowserProtocol3)
|
|
77
|
+
- [Arma 3: ServerBrowserProtocol2](https://community.bistudio.com/wiki/Arma_3:_ServerBrowserProtocol2)
|
|
78
|
+
- [WoozyMasta/a2s `pkg/a3sb`](https://github.com/WoozyMasta/a2s/tree/master/pkg/a3sb): a Go implementation this package's parsers were cross-checked against
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createValveProtocol, type CreateValveProtocolParams, type ValveProtocol, type ValveProtocolQueryParams, type ValveRulesQueryParams, } from "./protocol";
|
|
2
|
+
export { type ValveChallenge, type ValvePing, type ValveBinaryRule, type ValvePlayer, type ValvePlayers, type ValveServerInfo, } from "./packet/schema";
|
|
3
|
+
export { valveRulesParser, type ValveRules } from "./rules/valve-rule-parser";
|
|
4
|
+
export { serverBrowserProtocol2RulesParser, type ServerBrowserProtocol2Message, } from "./rules/server-browser-protocol-2-parser";
|
|
5
|
+
export { serverBrowserProtocol3RulesParser, type ServerBrowserProtocol3Message, } from "./rules/server-browser-protocol-3-parser";
|
|
6
|
+
export { type ServerBrowserProtocolDlc, type ServerBrowserProtocolMod, type ServerBrowserProtocolCreatorDlc, } from "./rules/server-browser-protocol-reassembly";
|
|
7
|
+
//# 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,mBAAmB,EACnB,KAAK,yBAAyB,EAC9B,KAAK,aAAa,EAClB,KAAK,wBAAwB,EAC7B,KAAK,qBAAqB,GAC3B,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,eAAe,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,gBAAgB,EAAE,KAAK,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC9E,OAAO,EACL,iCAAiC,EACjC,KAAK,6BAA6B,GACnC,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACL,iCAAiC,EACjC,KAAK,6BAA6B,GACnC,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACL,KAAK,wBAAwB,EAC7B,KAAK,wBAAwB,EAC7B,KAAK,+BAA+B,GACrC,MAAM,4CAA4C,CAAC"}
|