Skip to content

Commit

Permalink
Allow multiple authentication tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaunLWM committed May 11, 2019
1 parent fcd4504 commit 64f9c3d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ or

``` js
const CSGOGSI = require("node-csgo-gsi");
let gsi = new CSGOGSI({options});
let gsi = new CSGOGSI({ options });
gsi.on("event", function("optional data") {

});
Expand All @@ -36,7 +36,8 @@ A sample script is in the `example` folder.

## Options
- ```port``` - Set the server port (default: 3000)
- ``` authToken``` - authToken to accept from client. Make sure all clients have the same authToken (default: "" - no authentication needed)
- ``` authToken``` - An array of authentication token to accept from client. You can have multiple tokens (default: [] - no authentication needed)
- Example: Team 1 can have "token1". Team 2 can have "token2". Team1's sub team can have "token1sub" etc.

# Events

Expand Down Expand Up @@ -101,15 +102,13 @@ A sample script is in the `example` folder.
#### bombTimeLeft (returns Float)
- Returns planted C4 time left.

---

## To-do
- Multi-player authentication code
## Todo
- None for now. Open an issue!

## Credits
- [Double0negative/CSGO-HUD](https://github.com/Double0negative/CSGO-HUD)

---

# License

Expand Down
4 changes: 2 additions & 2 deletions example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const CSGOGSI = require("../index"); // const CSGOGSI = require("node-csgo-gsi")

let gsi = new CSGOGSI({
port: 3000,
authToken: "Q79v5tcxVQ8u" // this must match the cfg auth token
authToken: ["Q79v5tcxVQ8u", "Team2Token", "Team2SubToken"] // this must match the cfg auth token
});

gsi.on("all", function (data) {
Expand All @@ -22,4 +22,4 @@ gsi.on("roundPhase", function (data) {
if (data === "over") {
console.log("round over");
}
});
});
11 changes: 8 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ const bodyParser = require("body-parser");
const EventEmitter = require("events");

class CSGOGSI extends EventEmitter {
constructor({ port = 3000, authToken = "" }) {
constructor({ port = 3000, authToken = [] }) {
super();
this.authToken = authToken;
let tokens = authToken;
if (!Array.isArray(tokens)) {
tokens = [];
}

this.authToken = tokens;
this.app = express();

this.bombTime = 40;
Expand Down Expand Up @@ -33,7 +38,7 @@ class CSGOGSI extends EventEmitter {
}

isAuthenticated(data) {
if (this.authToken.length < 1 || (typeof data["auth"]["token"] !== "undefined" && this.authToken.length > 0 && data["auth"]["token"] === this.authToken)) {
if (this.authToken.length < 1 || (typeof data["auth"]["token"] !== "undefined" && this.authToken.length > 0 && this.authToken.includes(data["auth"]["token"]))) {
return true;
}

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": "node-csgo-gsi",
"version": "0.0.2",
"version": "0.0.3",
"description": "Counter-Strike: Global Offensive Game State Integration for nodejs. https://developer.valvesoftware.com/wiki/Counter-Strike:_Global_Offensive_Game_State_Integration",
"main": "index.js",
"repository": {
Expand Down

0 comments on commit 64f9c3d

Please sign in to comment.