haxball.js 2.1.3 → 2.2.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 +12 -47
- package/package.json +13 -10
- package/scripts/nodeify.js +19 -6
- package/src/index.js +4 -1
- package/test/build.js +2 -1
- package/test/room.js +2 -1
package/README.md
CHANGED
|
@@ -57,9 +57,11 @@ HaxballJS.then((HBInit) => {
|
|
|
57
57
|
```
|
|
58
58
|
|
|
59
59
|
#### 💻 (Optional) Proxy
|
|
60
|
+
|
|
60
61
|
Haxball has a limit of 2 rooms per IP. Therefore, you can use proxy with adding `proxy: "<YOUR_PROXY_IP>"` in your RoomConfig.
|
|
61
62
|
|
|
62
63
|
Example:
|
|
64
|
+
|
|
63
65
|
```js
|
|
64
66
|
HBInit({
|
|
65
67
|
...
|
|
@@ -68,17 +70,20 @@ HBInit({
|
|
|
68
70
|
```
|
|
69
71
|
|
|
70
72
|
#### 💻 (Optional) TypeScript
|
|
73
|
+
|
|
71
74
|
From v2.1.0, the package has basic typings included. Typings are automatically imported alongside `haxball.js` package.
|
|
72
75
|
|
|
73
76
|
Install TypeScript and ts-node in your project:
|
|
77
|
+
|
|
74
78
|
```bash
|
|
75
79
|
npm install typescript --save-dev
|
|
76
80
|
npm install ts-node --save-dev
|
|
77
81
|
```
|
|
78
82
|
|
|
79
|
-
Name the file `room.ts` instead of `room.js` and use example room code from the previous section.
|
|
83
|
+
Name the file `room.ts` instead of `room.js` and use example room code from the previous section.
|
|
80
84
|
|
|
81
85
|
You may run the server with `ts-node room.ts` instead of `node room.js`. To make it runnable with `npm start`, add the alias to `package.json`:
|
|
86
|
+
|
|
82
87
|
```json
|
|
83
88
|
// package.json
|
|
84
89
|
|
|
@@ -89,58 +94,18 @@ You may run the server with `ts-node room.ts` instead of `node room.js`. To make
|
|
|
89
94
|
//...
|
|
90
95
|
```
|
|
91
96
|
|
|
92
|
-
#### 💻 (Optional) Modularize Room Script
|
|
93
|
-
You can build full room scripts as NPM packages, that export `roomBuilder` function. These functions can be easily imported by another packages (launchers, remote orchestrators, etc.).
|
|
94
|
-
|
|
95
|
-
```ts
|
|
96
|
-
// super-futsal-room/index.ts
|
|
97
|
-
|
|
98
|
-
import { Headless } from "haxball.js"
|
|
99
|
-
|
|
100
|
-
// Every user installing the package will have to
|
|
101
|
-
// implement this interface in order to run it.
|
|
102
|
-
interface RoomArgs {
|
|
103
|
-
token: string
|
|
104
|
-
timeLimit: number
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const roomBuilder = (HBInit: Headless, args: RoomArgs) => {
|
|
108
|
-
let room = HBInit({
|
|
109
|
-
roomName: "Hello TypeScript!",
|
|
110
|
-
token: args.token
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
room.setTimeLimit(args.timeLimit)
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export default roomBuilder;
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
```ts
|
|
120
|
-
// room-launcher/index.ts
|
|
121
|
-
|
|
122
|
-
// Local path as example, but may refer to installed npm package
|
|
123
|
-
import roomBuilder from "../super-futsal-room";
|
|
124
|
-
import HaxballJS from "haxball.js";
|
|
125
|
-
|
|
126
|
-
HaxballJS.then((HBInit => roomBuilder(HBInit, {
|
|
127
|
-
// Interface for config arguments is provided by the room script author
|
|
128
|
-
// Not defining them results in TypeScript error
|
|
129
|
-
token: "YOUR_TOKEN_HERE",
|
|
130
|
-
timeLimit: 3
|
|
131
|
-
})))
|
|
132
|
-
```
|
|
133
|
-
|
|
134
97
|
---
|
|
135
98
|
|
|
136
99
|
<h2 id="technologies">🚀 Technologies</h2>
|
|
137
100
|
|
|
138
101
|
- wrtc - WebRTC implementation for NodeJS
|
|
139
102
|
- ws - Websocket Connection
|
|
140
|
-
-
|
|
103
|
+
- json5 - JSON Helper Module
|
|
141
104
|
- @peculiar/webcrypto - Webcrypto implementation for NodeJS
|
|
142
|
-
- pako -
|
|
143
|
-
-
|
|
105
|
+
- pako - ZLIB port for NodeJS
|
|
106
|
+
- xhr2 - W3C XMLHttpRequest implementation for NodeJS
|
|
107
|
+
- http-proxy-agent - Websocket Proxy Support
|
|
108
|
+
- @types/haxball-headless-browser - Type definitions
|
|
144
109
|
|
|
145
110
|
[Back To The Top](#title)
|
|
146
111
|
|
|
@@ -149,7 +114,7 @@ HaxballJS.then((HBInit => roomBuilder(HBInit, {
|
|
|
149
114
|
<h2 id="minimal-requirements">🌱 Minimal Requirements</h2>
|
|
150
115
|
|
|
151
116
|
- NPM
|
|
152
|
-
-
|
|
117
|
+
- NodeJS Version >=18
|
|
153
118
|
|
|
154
119
|
[Back To The Top](#title)
|
|
155
120
|
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "haxball.js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "A powerful library for interacting with the Haxball Headless API",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=18"
|
|
9
|
+
},
|
|
7
10
|
"scripts": {
|
|
8
11
|
"test": "mocha --recursive --exit",
|
|
9
12
|
"build": "node scripts/nodeify.js"
|
|
@@ -17,18 +20,18 @@
|
|
|
17
20
|
"author": "mertushka",
|
|
18
21
|
"license": "MIT",
|
|
19
22
|
"dependencies": {
|
|
20
|
-
"@
|
|
21
|
-
"@
|
|
22
|
-
"@types/haxball-headless-browser": "
|
|
23
|
-
"http-proxy-agent": "^
|
|
24
|
-
"json5": "^2.2.
|
|
25
|
-
"pako": "^2.0
|
|
26
|
-
"ws": "^8.
|
|
23
|
+
"@peculiar/webcrypto": "^1.5.0",
|
|
24
|
+
"@roamhq/wrtc": "^0.8.0",
|
|
25
|
+
"@types/haxball-headless-browser": ">=0.3.0",
|
|
26
|
+
"http-proxy-agent": "^7.0.2",
|
|
27
|
+
"json5": "^2.2.3",
|
|
28
|
+
"pako": "^2.1.0",
|
|
29
|
+
"ws": "^8.18.0",
|
|
27
30
|
"xhr2": "^0.2.1"
|
|
28
31
|
},
|
|
29
32
|
"devDependencies": {
|
|
30
|
-
"@mapbox/node-pre-gyp": "^1.0.
|
|
31
|
-
"mocha": "^
|
|
33
|
+
"@mapbox/node-pre-gyp": "^1.0.11",
|
|
34
|
+
"mocha": "^10.7.3"
|
|
32
35
|
},
|
|
33
36
|
"repository": {
|
|
34
37
|
"type": "git",
|
package/scripts/nodeify.js
CHANGED
|
@@ -40,7 +40,7 @@ fetch("https://www.haxball.com/cache_hash.json")
|
|
|
40
40
|
throw new Error("No HBInit matches found!");
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
// Fix Websocket (Regex)
|
|
43
|
+
// Fix Websocket & Add Proxy Support (Regex)
|
|
44
44
|
|
|
45
45
|
const WebsocketRegex = /new WebSocket\([^)]+\);/; // Match the pattern "new WebSocket(f+"?token="+e);"
|
|
46
46
|
const WebsocketMatch = source.match(WebsocketRegex)[0];
|
|
@@ -72,25 +72,38 @@ fetch("https://www.haxball.com/cache_hash.json")
|
|
|
72
72
|
throw new Error("No Recaptcha matches found!");
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
console.log(
|
|
76
|
+
"RoomConfigLookup function:" + source.match(/(\w+)\("noPlayer",/)[1]
|
|
77
|
+
);
|
|
78
|
+
|
|
75
79
|
// Add proxy support & other things manually because too hard to string manipulate with minified code
|
|
76
80
|
// Also these things are not included in Headless Host Source originally so you can create ur own build without these things
|
|
77
81
|
/*
|
|
78
82
|
|
|
79
|
-
RoomConfigLookup: This is
|
|
83
|
+
RoomConfigLookup: This is an example name for mimic minified function.
|
|
80
84
|
|
|
81
|
-
Example getting minified function:
|
|
85
|
+
Example getting minified function:
|
|
86
|
+
source.match(/(\w+)\("noPlayer",/)[1] -> this regex gets minified function's name from code
|
|
82
87
|
k("noPlayer", !1) -> in this example regex gets function's name as "k"
|
|
83
|
-
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
Implemented code to add proxy support to the module:
|
|
91
|
+
|
|
84
92
|
proxyAgent = RoomConfigLookup("proxy", null)
|
|
85
93
|
? new HttpsProxyAgent(url.parse(RoomConfigLookup("proxy", null)))
|
|
86
94
|
: null;
|
|
87
95
|
debug = RoomConfigLookup("debug", null) == true;
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
Websocket On Error Debug -> debug && console.error(e);
|
|
100
|
+
|
|
101
|
+
I will implement these manually with the help of the regex, as you can check manually added codes by searching @mertushka on the code
|
|
88
102
|
|
|
89
103
|
*/
|
|
90
|
-
// Websocket On Error Debug -> debug && console.error(e);
|
|
91
104
|
|
|
92
105
|
// Modules
|
|
93
|
-
target.write(`const wrtc = require("@
|
|
106
|
+
target.write(`const wrtc = require("@roamhq/wrtc");
|
|
94
107
|
const XMLHttpRequest = require('xhr2');
|
|
95
108
|
const WebSocket = require("ws");
|
|
96
109
|
const url = require("url");
|
package/src/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const wrtc = require("@
|
|
1
|
+
const wrtc = require("@roamhq/wrtc");
|
|
2
2
|
const XMLHttpRequest = require("xhr2");
|
|
3
3
|
const WebSocket = require("ws");
|
|
4
4
|
const url = require("url");
|
|
@@ -206,6 +206,7 @@ const onHBLoaded = function (cb) {
|
|
|
206
206
|
if (E.Gf) throw t.s("Can't init twice");
|
|
207
207
|
E.Gf = !0;
|
|
208
208
|
|
|
209
|
+
// Manually added for proxy support by @mertushka
|
|
209
210
|
proxyAgent = k("proxy", null)
|
|
210
211
|
? new HttpsProxyAgent(url.parse(k("proxy", null)))
|
|
211
212
|
: null;
|
|
@@ -3510,7 +3511,9 @@ const onHBLoaded = function (cb) {
|
|
|
3510
3511
|
d.Ed(4001 != g.code);
|
|
3511
3512
|
};
|
|
3512
3513
|
d.ua.onerror = function () {
|
|
3514
|
+
// Manually added for proxy support by @mertushka
|
|
3513
3515
|
debug && console.error(e);
|
|
3516
|
+
|
|
3514
3517
|
d.Ed(!0);
|
|
3515
3518
|
};
|
|
3516
3519
|
d.ua.onmessage = hb(d, d.dh);
|
package/test/build.js
CHANGED
|
@@ -9,7 +9,8 @@ describe("Build Tests", function () {
|
|
|
9
9
|
maxPlayers: 16,
|
|
10
10
|
public: true,
|
|
11
11
|
noPlayer: true,
|
|
12
|
-
|
|
12
|
+
debug: true,
|
|
13
|
+
token: "thr1.AAAAAGbJ6DKbFCpW73t1YQ.AcXcCi-Ak-w", // Make sure update here before testing
|
|
13
14
|
});
|
|
14
15
|
|
|
15
16
|
room.onRoomLink = function () {
|
package/test/room.js
CHANGED
|
@@ -9,7 +9,8 @@ describe("HBInit Tests", function () {
|
|
|
9
9
|
maxPlayers: 16,
|
|
10
10
|
public: true,
|
|
11
11
|
noPlayer: true,
|
|
12
|
-
|
|
12
|
+
debug: true,
|
|
13
|
+
token: "thr1.AAAAAGbJ6DKbFCpW73t1YQ.AcXcCi-Ak-w", // Make sure update here before testing
|
|
13
14
|
});
|
|
14
15
|
|
|
15
16
|
room.onRoomLink = function () {
|