Coder Social home page Coder Social logo

mertushka / haxball.js Goto Github PK

View Code? Open in Web Editor NEW
31.0 3.0 4.0 166 KB

🎉 A powerful NodeJS library for interacting with the Haxball Headless API

Home Page: https://github.com/haxball/haxball-issues/wiki/Headless-Host#api

JavaScript 100.00%
api haxball nodejs javascript headless

haxball.js's Introduction

haxball.js's People

Contributors

jakjus avatar mertushka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

haxball.js's Issues

DOMException [InvalidStateError]: RTCDataChannel.readyState is not 'open'

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.

App console looks like real time console

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.

setPlayerChatFilter don't work

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;
  });

GetPlayerList returning Promise

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

getAddrInfo

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.

haxball/haxball-issues#2091

Can't create a room with proxy

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?

DOMException [InvalidStateError]: RTCDataChannel.readyState is not 'open'

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.

using proxy ip/overcoming ip limitations

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?

Room never comes up when I add "proxy" parameter to HBInit

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!

Random SIGSEGV

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

Exceptions not outputted in some roomObject functions

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.

New Event/Function Added

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.

@mertushka

error when trying to up the room

\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'
}

New error

\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)
        }

    }
}

Connection Failed

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.

People are getting Game state timeout.

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

FetchError - ENOTFOUND

Hi,

After a certain time, it gives an error like this and terminates the application. What could be the reason for this?

Ekran Resmi 2023-03-01 17 54 20

File is not defined

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

Token error

Is there any way for the Invalid Token Error to terminate the client but not all of my code?

Type this error:
image

It finishes the client but not my code.

Close room

how can we close room without stopping the process. Is there a way

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.