Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Add "timed out" parameter #29

Open
R4to0 opened this issue Nov 27, 2019 · 0 comments
Open

Feature Request: Add "timed out" parameter #29

R4to0 opened this issue Nov 27, 2019 · 0 comments

Comments

@R4to0
Copy link

R4to0 commented Nov 27, 2019

Hello!

Been using your library with my Discord bot and works like a charm!

The only issue I'm getting is if I try to rcon a server that is down (or changing map for example), it doesn't report any kind of timed out (at least when using UDP because of how the protocol works) and I have to handle that by myself with a timer or something (haven't tried yet).

Since there's no param for this in the library, it would be nice to have one :)

Here's how I'm using. If the server is up, everything works as expected.

async SendMsgRcon(target, msg) {
    return new Promise((resolve, reject) => {
        // max rcon data we can send is 509
        const maxrcondatasize = 509;
        const basesize = 16 + target.rcon.length; // rcon challenge and rcon length
        const basecomm = `some command here `;
        let conn = new Rcon(target.serverip, target.serverport, target.rcon, { tcp: false });

        conn.on('auth', () => {
            //console.log("Authed!");
            conn.send(basecomm + `"${msg.slice(0, (maxrcondatasize - basesize - basecomm.length - 2))}"`);

        }).on('response', (str) => {
            //console.dir("Got response: " + str);
            conn.disconnect();

            // handle status
            const status = str.replace(/\n|\0/g, "");
            if (status == 'OK')
                resolve(true);
            else /*if(status == 'BADMSG')*/
                resolve(false);
        }).on('end', () => {
            console.log("Rcon socket closed!");
        }).on('error', (error) => {
            console.log("error");
            conn.disconnect();
            reject(null);
        });
        conn.connect();
    });
}```

Thank you for your time.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant