@pilaf/backends 1.0.0 → 1.0.2
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 +141 -0
- package/package.json +6 -2
package/README.md
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# @pilaf/backends
|
|
2
|
+
|
|
3
|
+
Backend implementations for Pilaf testing framework.
|
|
4
|
+
|
|
5
|
+
This package provides RCON and Mineflayer backends for connecting to Minecraft PaperMC servers during testing.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @pilaf/backends
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Backends
|
|
14
|
+
|
|
15
|
+
### RCONBackend
|
|
16
|
+
|
|
17
|
+
Connects via RCON protocol to execute server commands.
|
|
18
|
+
|
|
19
|
+
```javascript
|
|
20
|
+
const { RconBackend } = require('@pilaf/backends');
|
|
21
|
+
|
|
22
|
+
const backend = new RconBackend().connect({
|
|
23
|
+
host: 'localhost',
|
|
24
|
+
port: 25575,
|
|
25
|
+
password: 'your_password'
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// Execute command
|
|
29
|
+
const response = await backend.send('op player1');
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### MineflayerBackend
|
|
33
|
+
|
|
34
|
+
Creates a real Minecraft player using Mineflayer for realistic player simulation.
|
|
35
|
+
|
|
36
|
+
```javascript
|
|
37
|
+
const { MineflayerBackend } = require('@pilaf/backends');
|
|
38
|
+
|
|
39
|
+
const backend = new MineflayerBackend().connect({
|
|
40
|
+
host: 'localhost',
|
|
41
|
+
port: 25565,
|
|
42
|
+
username: 'TestBot',
|
|
43
|
+
auth: 'offline' // or 'microsoft'
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Spawn bot player
|
|
47
|
+
await backend.spawn();
|
|
48
|
+
|
|
49
|
+
// Get player position
|
|
50
|
+
const pos = await backend.getPlayerPosition();
|
|
51
|
+
|
|
52
|
+
// Chat as player
|
|
53
|
+
await bot.chat('Hello world!');
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### PilafBackendFactory
|
|
57
|
+
|
|
58
|
+
Factory for creating backend instances.
|
|
59
|
+
|
|
60
|
+
```javascript
|
|
61
|
+
const { PilafBackendFactory } = require('@pilaf/backends');
|
|
62
|
+
|
|
63
|
+
// Create RCON backend
|
|
64
|
+
const rcon = PilafBackendFactory.create('rcon', {
|
|
65
|
+
host: 'localhost',
|
|
66
|
+
port: 25575,
|
|
67
|
+
password: 'password'
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// Create Mineflayer backend
|
|
71
|
+
const bot = PilafBackendFactory.create('mineflayer', {
|
|
72
|
+
host: 'localhost',
|
|
73
|
+
port: 25565,
|
|
74
|
+
username: 'TestBot',
|
|
75
|
+
auth: 'offline'
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## API
|
|
80
|
+
|
|
81
|
+
### ConnectionState
|
|
82
|
+
|
|
83
|
+
Connection states for backend lifecycle management:
|
|
84
|
+
|
|
85
|
+
```javascript
|
|
86
|
+
const { ConnectionState } = require('@pilaf/backends');
|
|
87
|
+
|
|
88
|
+
ConnectionState.DISCONNECTED // Initial state
|
|
89
|
+
ConnectionState.CONNECTING // Connecting to server
|
|
90
|
+
ConnectionState.CONNECTED // Connection established
|
|
91
|
+
ConnectionState.SPAWNING // Player spawning
|
|
92
|
+
ConnectionState.SPAWNED // Player ready
|
|
93
|
+
ConnectionState.ERROR // Error occurred
|
|
94
|
+
ConnectionState.DISCONNECTING // Disconnecting
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### BotPool
|
|
98
|
+
|
|
99
|
+
Manages a pool of Mineflayer bot instances.
|
|
100
|
+
|
|
101
|
+
```javascript
|
|
102
|
+
const { BotPool } = require('@pilaf/backends');
|
|
103
|
+
|
|
104
|
+
const pool = new BotPool({
|
|
105
|
+
maxBots: 5,
|
|
106
|
+
defaultConfig: {
|
|
107
|
+
host: 'localhost',
|
|
108
|
+
port: 25565,
|
|
109
|
+
auth: 'offline'
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// Acquire a bot
|
|
114
|
+
const bot = await pool.acquire('Bot1');
|
|
115
|
+
|
|
116
|
+
// Release when done
|
|
117
|
+
await pool.release('Bot1');
|
|
118
|
+
|
|
119
|
+
// Shutdown all
|
|
120
|
+
await pool.shutdownAll();
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### ServerHealthChecker
|
|
124
|
+
|
|
125
|
+
Monitors server health and availability.
|
|
126
|
+
|
|
127
|
+
```javascript
|
|
128
|
+
const { ServerHealthChecker } = require('@pilaf/backends');
|
|
129
|
+
|
|
130
|
+
const checker = new ServerHealthChecker({
|
|
131
|
+
rcon: { host: 'localhost', port: 25575, password: 'pass' }
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// Check health
|
|
135
|
+
const isHealthy = await checker.check();
|
|
136
|
+
console.log(isHealthy.status); // 'healthy' | 'unhealthy'
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## License
|
|
140
|
+
|
|
141
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pilaf/backends",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/cavarest/pilaf"
|
|
8
|
+
},
|
|
5
9
|
"files": [
|
|
6
10
|
"lib/*.js",
|
|
7
11
|
"lib/**/*.js",
|
|
@@ -17,4 +21,4 @@
|
|
|
17
21
|
"mineflayer": "^4.20.1",
|
|
18
22
|
"rcon-client": "^4.2.5"
|
|
19
23
|
}
|
|
20
|
-
}
|
|
24
|
+
}
|