@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
package/README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# @srvquery/protocol-fivem
|
|
2
|
+
|
|
3
|
+
 
|
|
4
|
+
|
|
5
|
+
Query FiveM and RedM (FXServer) game servers.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pnpm add @srvquery/core @srvquery/protocol-fivem
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { createFiveMProtocol } from "@srvquery/protocol-fivem";
|
|
17
|
+
|
|
18
|
+
const fivem = createFiveMProtocol({
|
|
19
|
+
host: "127.0.0.1",
|
|
20
|
+
port: 30120,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const info = await fivem.query({ opcode: "INFO" });
|
|
24
|
+
const players = await fivem.query({ opcode: "PLAYERS" });
|
|
25
|
+
const dynamic = await fivem.query({ opcode: "DYNAMIC" });
|
|
26
|
+
|
|
27
|
+
console.log(`${dynamic.hostname}: ${dynamic.clients}/${dynamic.sv_maxclients}`);
|
|
28
|
+
console.log({ info, players });
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Locating a server by Cfx.re id
|
|
32
|
+
|
|
33
|
+
Servers can also be located by their Cfx.re server id (the short code used in join links such as `https://cfx.re/join/<id>`) instead of a `host`/`port` pair. The id is resolved to the server's advertised connect endpoint on first use and cached for the lifetime of the returned client.
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { createFiveMProtocol } from "@srvquery/protocol-fivem";
|
|
37
|
+
|
|
38
|
+
const fivem = createFiveMProtocol({ id: "abcdef" });
|
|
39
|
+
|
|
40
|
+
const info = await fivem.query({ opcode: "INFO" });
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Query types
|
|
44
|
+
|
|
45
|
+
| Opcode | Endpoint | Description |
|
|
46
|
+
| --------- | --------------- | ----------------------------------------------------------------------------------------- |
|
|
47
|
+
| `INFO` | `/info.json` | Server version, icon, resources and `vars` convars |
|
|
48
|
+
| `PLAYERS` | `/players.json` | Connected players: id, name, ping, identifiers |
|
|
49
|
+
| `DYNAMIC` | `/dynamic.json` | Lightweight, server-browser-oriented summary (hostname, gametype, mapname, client counts) |
|
|
50
|
+
|
|
51
|
+
## Stripping formatting codes
|
|
52
|
+
|
|
53
|
+
FiveM/RedM allows `^`-prefixed color and formatting codes (e.g. `^1` for red) in strings such as hostnames and player names. Pass `stripFormattingCodes: true` to recursively strip them from every string in the response:
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
const info = await fivem.query({ opcode: "INFO", stripFormattingCodes: true });
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Reference: [Chat Formatting // Colors, Bold, Underline](https://forum.cfx.re/t/chat-formatting-colors-bold-underline/67641)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { resolveServerId } from "./net/server-id";
|
|
2
|
+
export { stripFiveMFormattingCodes } from "./packet/formatting";
|
|
3
|
+
export { type FiveMDynamic, type FiveMPlayer, type FiveMPlayers, type FiveMServerInfo, type FiveMVars, } from "./packet/schema";
|
|
4
|
+
export { createFiveMProtocol, type CreateFiveMProtocolParams, type FiveMProtocol, type FiveMProtocolRequestOpcode, type FiveMServerLocator, } from "./protocol";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,SAAS,GACf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,mBAAmB,EACnB,KAAK,yBAAyB,EAC9B,KAAK,aAAa,EAClB,KAAK,0BAA0B,EAC/B,KAAK,kBAAkB,GACxB,MAAM,YAAY,CAAC"}
|