Skip to content

Commit

Permalink
code & readme cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
MBR-0001 committed Apr 20, 2021
1 parent 9dbbd1c commit 5b01e27
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ Example usage:
```js
const SourceQuery = require('sourcequery');

const query = new SourceQuery('127.0.0.1', 28015, 1000, true); // 1000ms timeout, automatically close connection after last request [last 2 options are optional]
const query = new SourceQuery('127.0.0.1', 28015]);
//you can also provide timeout in ms [default 1000]
//and the option to automatically close the socket after the last request [default true]

query.getInfo().then(info => console.log('Server Info:', info));
query.getPlayers().then(players => console.log('Online Players:', players));
query.getRules().then(rules => console.log('Server Rules:', rules));
//if autoclose is false this method has to be called to stop the query from preventing the process from exiting
query.close();
//if autoclose is false this method has to be called to close the socket
//query.close();


//in case you only want to check if the server is "alive" you can do the following
//to check if the server is "there" you can do the following
SourceQuery.preflightCheck('127.0.0.1', 28015).then(() => console.log("server is alive!")).catch(() => console.log("server is down!"));
```

Expand Down Expand Up @@ -60,6 +62,4 @@ x | All HL1/HL2 games and mods |
892970 | [Valheim](https://store.steampowered.com/app/892970/) | Server does not send rules

## Notes
- Compression is not supported, I don't know of any games that use it
- ~~Player list gets fucked up if people put weird shit in their names (emojis and other weird shit)~~ FIXED IN 1.1.0
- Since 1.0.5 steamID and gameID in getInfo are strings (they are BigInt and it cannot be JSON.stringify-d)
- Compression is not supported, I don't know of any games that use it
7 changes: 3 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,10 @@ class SourceQuery {
* @param {boolean} autoclose
*/
constructor(address, port, timeout = 1000, autoclose = true) {
if (!address) throw new Error("Invalid address");

let _port = Number(port);

if (_port == undefined || _port <= 0 || _port >= 65535 || isNaN(_port)) throw new Error("Invalid port");
if (!address || typeof address != "string") throw new Error("Invalid address");
if (_port <= 0 || _port >= 65535 || isNaN(_port)) throw new Error("Invalid port");

this.address = String(address);
this.port = _port;
Expand Down Expand Up @@ -247,7 +246,7 @@ class SourceQuery {
static preflightCheck(address, port) {
return new Promise((resolve, reject) => {
let query = new SourceQuery(address, port);
query.send(Util.createInfoChallenge(ids.A2S_INFO), [ids.S2A_INFO, ids.S2A_SERVERQUERY_GETCHALLENGE]).then(() => resolve()).catch(() => reject("Preflight failed"));
query.send(Util.createInfoChallenge(ids.A2S_INFO), [ids.S2A_INFO, ids.S2A_SERVERQUERY_GETCHALLENGE]).then(() => resolve()).catch(() => reject());
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sourcequery",
"version": "1.1.3",
"version": "1.1.4",
"description": "https://www.npmjs.com/package/sourcequery but it doesn't suck",
"main": "./index.js",
"module": "./index.mjs",
Expand Down

0 comments on commit 5b01e27

Please sign in to comment.