mertushka / haxball.js Goto Github PK
View Code? Open in Web Editor NEW🎉 A powerful NodeJS library for interacting with the Haxball Headless API
Home Page: https://github.com/haxball/haxball-issues/wiki/Headless-Host#api
🎉 A powerful NodeJS library for interacting with the Haxball Headless API
Home Page: https://github.com/haxball/haxball-issues/wiki/Headless-Host#api
Hi, I'm trying to create a room with a private proxy but I'm failing, here is my code and the error:
var room = HBInit({
roomName: 'Test Room',
maxPlayers: 16,
debug: true,
proxy: 'http://209.99.129.239:6227:login:password'
});
I get the following error:
Error: connect ECONNREFUSED 209.99.129.239:80
The port I specified (6227) is not the same as the port in the error message (80), what should I do?
how can we close room without stopping the process. Is there a way
I'm running a 24/7 room with haxball.js and once in a while I get this error when a player leaves the room.
DOMException [InvalidStateError]: RTCDataChannel.readyState is not 'open'
0|index | 2023-02-12T14:57:40: at RTCDataChannel.send (/home/dznunleashed/SimpleHaxballFutsal/node_modules/@koush/wrtc/lib/index.js:49:8)
0|index | 2023-02-12T14:57:40: at Na.mb (/home/dznunleashed/SimpleHaxballFutsal/node_modules/haxball.js/src/index.js:981:17)
0|index | 2023-02-12T14:57:40: at Ja.mb (/home/dznunleashed/SimpleHaxballFutsal/node_modules/haxball.js/src/index.js:1846:17)
0|index | 2023-02-12T14:57:40: at Fa.ad (/home/dznunleashed/SimpleHaxballFutsal/node_modules/haxball.js/src/index.js:1727:21)
0|index | 2023-02-12T14:57:40: at Fa.zh (/home/dznunleashed/SimpleHaxballFutsal/node_modules/haxball.js/src/index.js:1838:44)
0|index | 2023-02-12T14:57:40: at Fa.wh (/home/dznunleashed/SimpleHaxballFutsal/node_modules/haxball.js/src/index.js:1793:22)
0|index | 2023-02-12T14:57:40: at a.$e (/home/dznunleashed/SimpleHaxballFutsal/node_modules/haxball.js/src/index.js:1685:15)
0|index | 2023-02-12T14:57:40: at Na.e.onmessage (/home/dznunleashed/SimpleHaxballFutsal/node_modules/haxball.js/src/index.js:392:66)
0|index | 2023-02-12T14:57:40: at /home/dznunleashed/SimpleHaxballFutsal/node_modules/@koush/wrtc/lib/eventtarget.js:37:18
0|index | 2023-02-12T14:57:40: at Set.forEach (<anonymous>)
I've also encountered this error without the last line (at Set.forEach (<anonymous>)
).
I want to say it has had an impact on the server once, introducing some bugs related to moving players to teams, but I'm not 100% sure as I can't recreate the error message.
Exceptions are not outputted in some roomObject functions.
Example of correct exception output (room.onRoomLink
):
const HaxballJS = require("haxball.js");
HaxballJS.then((HBInit) => {
const room = HBInit({
public: false,
token: "thr1.AAAAAGRnQzBMDYP3KqP38w.-sErfHVd6Pw"
});
room.onRoomLink = function (link) {
console.log(link);
throw('test')
};
});
Output:
/Users/jjuszk/projects/recreate/room.js:13
throw('test')
^
test
Example of incorrect exception output (room.onPlayerChat
):
const HaxballJS = require("haxball.js");
HaxballJS.then((HBInit) => {
const room = HBInit({
public: false,
token: "thr1.AAAAAGRnQzBMDYP3KqP38w.-sErfHVd6Pw"
});
room.onPlayerChat = (player, msg) => {
throw('test')
}
room.onRoomLink = function (link) {
console.log(link);
};
});
Result:
<when typing in the room, getting Disconnected: Connection Closed>
<nothing logged in console>
It's also not working correctly for room.onPlayerJoin
, did not test others, but will do, to find discrepancies.
Env:
$ node --version
v18.16.0
Tested on node16, node18, node19, node20.
People are getting Game state timeout when connecting.
From server perspective it looks like this:
"<player> has joined."
<player has 0 ping for 2 seconds>
"<player> has left."
Specs:
NAME="Amazon Linux"
VERSION="2"
ID="amzn"
ID_LIKE="centos rhel fedora"
VERSION_ID="2"
PRETTY_NAME="Amazon Linux 2"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
HOME_URL="https://amazonlinux.com/"
I'll try ubuntu later
I think this function is necessary to prevent indiscriminate access.
Is there a way to access this function?
As the title suggests, the room never gets created after I add proxy parameter to HBInit as it is mentioned in the docs. I've tried multiple proxy IPs. To be more precise, I don't receive any errors or anything after running node room.js
there's just a blank output, waiting for something to happen, but nothing does (I've waited for more than 10 mins, or more).
Please note that if I remove just the proxy parameter, then the room comes up online and everything works perfectly. Well done creating this package by the way!
Hi, i saw that on the other post, but for example i want to edit variables and it always says error.
References: #30
\node_modules\node-fetch\lib\index.js:273
return Body.Promise.reject(new FetchError(invalid json response body at ${_this2.url} reason: ${err.message}
, 'invalid-json'));
^
FetchError: invalid json response body at https://www.haxball.com/rs/api/host reason: Unexpected token < in JSON at position 0
at C:\Users\moises\Documents\mxm\node_modules\node-fetch\lib\index.js:273:32
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async C:\Users\moises\Documents\mxm\node_modules\haxball.js\src\index.js:1877:26 {
type: 'invalid-json'
}
Hello, can we receive data from an input in the application running on the operating system console and send it to the game console?
Actually, what I really want is for the system console to work just like the Google Chrome console.
hey mertushka,
as you know, there is limitation of 2 rooms per ip.
i'm running 9 rooms now and I use proxy ip's assigned to browser (old style using selenium) and I run 2 rooms per ip.
i'm wordering, how can i achieve running more than 2 rooms with haxball.js?
is IP discovered during webrtc connection init?
maybe there is a way to spoof the IP in headless script so that we can overcome this restriction? or at least make a way for webrtc to use proxy IP?
\node_modules\haxball.js\src\index.js:2172
throw l.vi(ab instanceof l ? ab.Db : ab);
^
SyntaxError: JSON5: invalid character ',' at 1:8943
at syntaxError (C:\Users\moises\Documents\mxm\node_modules\json5\lib\parse.js:1110:17)
at invalidChar (C:\Users\moises\Documents\mxm\node_modules\json5\lib\parse.js:1055:12)
at Object.end (C:\Users\moises\Documents\mxm\node_modules\json5\lib\parse.js:704:15)
at Object.default (C:\Users\moises\Documents\mxm\node_modules\json5\lib\parse.js:168:37)
at lex (C:\Users\moises\Documents\mxm\node_modules\json5\lib\parse.js:100:42)
at Object.parse (C:\Users\moises\Documents\mxm\node_modules\json5\lib\parse.js:25:17)
at n.Xg (C:\Users\moises\Documents\mxm\node_modules\haxball.js\src\index.js:3198:21)
at Object.setCustomStadium (C:\Users\moises\Documents\mxm\node_modules\haxball.js\src\index.js:2170:17)
at startGame (C:\Users\moises\Documents\mxm\index.js:833:22)
at Timeout._onTimeout (C:\Users\moises\Documents\mxm\index.js:1032:30) {
lineNumber: 1,
columnNumber: 8943
}
Node.js v18.16.0
Do you know what this error could be? Happens when I call this function in onPlayerJoin:
function startGame(victory, player) { // Serve para Mover os players para os times corretos
const players = room.getPlayerList()
if (victory) {
room.stopGame()
if (players.length >= 6) {
const playersSpec = room.getPlayerList().filter(p => p.team === 0)
const playersPlaying = room.getPlayerList().filter(p => p.team !== 0)
for (let i = 0; i < playersSpec.length; i++) {
if (playersPlaying.length === 0) {
if (i <= 9) {
const team = (i % 2) + 1
room.setPlayerTeam(playersSpec[i].id, team)
}
} else if (playersPlaying.length === 1) {
if (i <= 8) {
const team = (i % 2) + 1
room.setPlayerTeam(playersSpec[i].id, team)
}
}
}
room.startGame()
} else {
room.stopGame()
centralizedMessages(`❌ Players insuficientes para começar um novo jogo.`, undefined, colors.red, "bold", 2)
centralizedMessages(`🔄 Iniciando mapa de treinamento...`, undefined, colors.cu, "bold", 2)
setTrainningMap()
}
} else {
if (players.length >= 6 && gameStage.ranked === false) {
room.stopGame()
setAutoTeam('all')
centralizedMessages(`🔁 Batemos 6/10 players! Iniciado a partida...`, undefined, colors.green, "bold", 2)
room.setCustomStadium(map)
gameStage.ranked = true
setTimeout(() => room.startGame(), 2000)
}
else if (players.length < 6 && gameStage.ranked === false) {
if (!gameStage.playing) room.startGame()
gameStage.ranked = false
centralizedMessages(`😒 Estamos em fase de aquecimento... Aguarde mais ${6 - players.length} players para começar o jogo.`, undefined, colors.cu, "bold", 2)
room.setPlayerTeam(player.id, 1)
}
}
}
Hi, i wanted to know if is possible to add something about to edit variables or functions when the room is opened, without close the room always. On the headless host website is possible to do it @mertushka
Is there a function where I can close my room?
I am trying to implement this, which this does is filtering every message starting with ! but I can't do that due to the function not being recognized, is there any other way to do this?
room.setPlayerChatFilter((player: any, message: string) => {
// If the message starts with !, filter it out of the global chat
if (message.startsWith("!")) {
return "";
}
// Otherwise, allow the message to be shown in the global chat
return message;
});
Hi,
I had opened a topic before, but since I was on break, I couldn't respond clearly. I opened a topic again in the attachment. After a while, the rooms I open with the module give the attached error and explode.
Hello,
Basro has included a new function in the Headless API, namely the onTeamsLockChange function I suggested.
I tried to use it in my script in haxball.js but it doesn't work, while with the code directly launched in the browser console it works, so I guess there needs to be a little update on that for haxball.js too.
Hi bro, can you solve this problem?
form.append(null, new File([room.stopRecording()], `HBReplay-${RecSistem.getCustomDate()}.hbr2`, { type: "text/plain" }));
^
ReferenceError: File is not defined
I added var File = require('fs'); after then but says;
form.append(null, new File([room.stopRecording()], `HBReplay-${RecSistem.getCustomDate()}.hbr2`, { type: "text/plain" }));
TypeError: File is not a constructor
I'm having the same issue as in #17 .
DOMException [InvalidStateError]: RTCDataChannel.readyState is not 'open'
at RTCDataChannel.send (/home/facundocachuzumba/node_modules/�[4m@koush�[24m/wrtc/lib/index.js:49:8)
at Na.mb (/home/facundocachuzumba/node_modules/�[4mhaxball.js�[24m/src/index.js:981:17)
at Ja.mb (/home/facundocachuzumba/node_modules/�[4mhaxball.js�[24m/src/index.js:1846:17)
at Fa.ad (/home/facundocachuzumba/node_modules/�[4mhaxball.js�[24m/src/index.js:1727:21)
at Fa.zh (/home/facundocachuzumba/node_modules/�[4mhaxball.js�[24m/src/index.js:1838:44)
at Fa.wh (/home/facundocachuzumba/node_modules/�[4mhaxball.js�[24m/src/index.js:1793:22)
at a.$e (/home/facundocachuzumba/node_modules/�[4mhaxball.js�[24m/src/index.js:1685:15)
at Na.e.onmessage (/home/facundocachuzumba/node_modules/�[4mhaxball.js�[24m/src/index.js:392:66)
at /home/facundocachuzumba/node_modules/�[4m@koush�[24m/wrtc/lib/eventtarget.js:37:18
at Set.forEach ()
Don't know how to reproduce it.
Hey,
First of all thanks for this package! I used to use haxball-server-nodejs which just simply made it possible to run my room on NodeJS but sadly they stopped developing their package and it sometimes causes my rooms to crash. So now I'm trying this one, but I'm not sure I understand it all correctly. Excuse my possible bad understanding of it, but I'm not a native js developer ^^
So I tried to convert my code to the way your package works, which means instead of
room.onPlayerChat = function(player, message) { blabla }
I now have
room.on("onPlayerChat", = function(player, message) { blabla });
That all seems to work fine.
But in my old code I used to loop over the players like this:
players = room.getPlayerList();
for(let player of players) { blabla }
But I'm not sure how to do that with your package. Tried some things but I think the problem is it returns a Promise? Does this mean this simple loop is no longer possible? Hope I'm missing something!
Thanks in advance,
Immers
Every time I start a server and want to get in I get the following error:
Connection Failed
Failed to connect to room host.
If this problem persists please see the troubleshooting guide.
This problem is old, and I don't really want to investigate it and try some time consuming things to fix it because I'm not really bothered of it.
Around a half of a year ago I've launched a room with the haxball.js
under the hood and the app was crashing randomly, and some time later I've noticed by accident the "SIGSEGV" error inside a logs of my apps launcher, pm2
.
Specifically:
"/home/username/.pm2/pm2.log"
2023-02-25T18:07:02: PM2 log: App [hax-host:4] exited with code [0] via signal [SIGSEGV]
Then from this article I've found the problem is probably because of this module that is being used by haxball.js
, and since I was using nodejs v16
I've switched to nodejs v14
because it's listed here. Sadly this did not fix the problem, but it seems to be better
Approximately, with a nodejs 16.15.0
I had 4 crashes in 4 months, and with a nodejs 14.21.3
I had 2 crashes in 3.5 months. The crashes are seems to be happening only when the room is being played, not when the room is empty.
The room activity, approximately, is 10+ people, 6+ hours a day, and the last months activity is definitely higher than it was in first months, so I guess if I'll switch back to node v16
I'll probably get more crashes than it was when there was less activity. Maybe, or maybe not, idk
I think that I could try to use another versions of node, or maybe try another JavaScript runtimes (deno, bun), or another linux build or distribution, but this crashes are so rare, this might take a years to debug this problem in that way. The problem is still annoying though
cat /etc/os-release
output:
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.