Skip to content

Latest commit

 

History

History
executable file
·
564 lines (454 loc) · 19.5 KB

api-doc.md

File metadata and controls

executable file
·
564 lines (454 loc) · 19.5 KB

api

API backend for HL2DM game server stats. Reads log files generated by the server as well as rcon log port stream to generate player stats.

Requires: module:fs, module:readline, module:compression, module:express, module:node-schedule, module:path, module:url, module:srcds-log-receiver, module:expresss-ws, module:express-validator, module:colors, module:pug
Author: Jimmy Doughten https://github.com/dough10

api~logError(error) ⇒ Void

logs srror string to console w/ colors

Kind: inner method of api
Returns: Void - nothing

Param Type Description
error String error message

Example (Example usage of logError() function.)

logError('Shit is broke');

api~errorHandler(e) ⇒ Void

prints error message to console

Kind: inner method of api
Returns: Void - nothing

Param Type Description
e Object error object

Example (Example usage of errorHandler() function.)

doStuff().then(doMoreStuff).catch(errorHandler);

api~who(ip, message) ⇒ Void

prints out the players name when a known ip views a page or makes a request

Kind: inner method of api
Returns: Void - nothing
See: modules data-model-doc.md

Param Type Description
ip String ip addres of the user viewing a page or making a request
message String the rest of the message

Example (Example usage of who() function.)

who(req, 'is online');

api~getOldStatsList(month) ⇒ Promise.<Array>

grabs stats object from json file for a given month

Kind: inner method of api
Returns: Promise.<Array> - list of months. / players stats for the passed in month

Param Type Description
month Number number of the month 0 - 11 optional

Example (Example usage of getOldStatsList() function.)

getOldStatsList().then(months => {
// console.log(months); = [1609123414390.json]
});
getOldStatsList(11).then(month => {
// console.log(month); = [
//   [ over 100 kills sorted by KDR ],
//   [ weapon data ],
//   212, // player count
//   [ banned players ],
//   1609123414390 // time stats were generated
//]
});

api~parseLogs() ⇒ Promise.<String>

parse folder of logs 1 line @ a time. dumping each line into the scanner

Kind: inner method of api
Returns: Promise.<String> - duration for task to complete
See: lineScanner.js
Example (Example usage of parseLogs() function.)

parseLogs().then(seconds => {
//  print(`Log parser complete in ` + `${seconds} seconds`); = '12/28/2020, 9:28:55 PM - Log parser complete in 1.768 seconds'
});

api~readableTime(ms) ⇒ String

convert milliseconds to readable time string

Kind: inner method of api
Returns: String - readable time string

Param Type Description
ms Number time in milliseconds

Example (Example usage of readableTime() function.)

let string = readableTime(67541983);

api~fourohfour(req, res) ⇒ HTML

404 page

Kind: inner method of api
Returns: HTML - 404

Param Type Description
req Object express request object
res Object express response object

Example (Example usage of fourohfour() function.)

fourohfour(req, res);

api~fiveHundred(req, res) ⇒ HTML

500 page

Kind: inner method of api
Returns: HTML - 500

Param Type Description
req Object express request object
res Object express response object

Example (Example usage of fiveHundred() function.)

fiveHundred(req, res);

api~/() ⇒ Void

redirect to admin

Kind: inner method of api
Returns: Void - redirect

api~/() ⇒ JSON

route for WebSocket

Kind: inner method of api
Returns: JSON - websocket pipeline
Example (Example usage of / api endpoint.)

let socket = new WebSocket('http://localhost:3000/);

api~/status() ⇒ JSON

route for gettings the status of the game server

Kind: inner method of api
Returns: JSON - game server rcon status response
Example (Example usage of /status api endpoint.)

fetch('http://localhost:3000/status').then(response => {
  response.json().then(json => {
    console.log(json); // game server status
  });
});

api~/auth() ⇒ JSON

login system

Kind: inner method of api
Returns: JSON - ok: authorized, fail: failed to authorize
See: auth-doc.md

Param Type Description
req.query.name String the name of the stream
req.query.k String the streams auth key

Example (Example usage of /auth api endpoint.)

fetch('http://localhost:3000/auth?name=stream1&k=supersecurepassword').then(response => {
  response.json().then(json => {
    console.log(json);  = {staus: 200 | 401, authorized: true | false}
  });
});

api~/stats() ⇒ JSON

route for gettings player stats

Kind: inner method of api
Returns: JSON - stats top players list, server wide weapons list, # of total players, list of banned players, time of generation
Example (Example usage of /stats api endpoint.)

fetch('http://localhost:3000/stats').then(response => {
  response.json().then(json => {
    console.log(json); // player statistics
  });
});

api~/old-months() ⇒ JSON | HTML

route for getting a list of avaliable data for prevoius months

Kind: inner method of api
Returns: JSON | HTML - list of months with stats history | 500
Example (Example usage of /old-months api endpoint.)

fetch('http://localhost:3000/old-months').then(response => {
  response.json().then(json => {
    console.log(json); // list of previous months that have player statistics
  });
}); 

api~/old-stats/:month/:year() ⇒ JSON | HTML

route for getting a old months stats data

Kind: inner method of api
Returns: JSON | HTML - statistics from a previous month | 500

Param Type Description
req.query.month Number index number of the months data
req.params.year Number year

Example (Example usage of /old-stats/:month api endpoint.)

fetch('http://localhost:3000/old-stats/11/2020').then(response => {
  response.json().then(json => {
    console.log(json); // statistics for the month of December
  });
});

api~/playerList() ⇒ JSON

route for getting list of all players who has played in server

Kind: inner method of api
Returns: JSON - list of all players to join server
Example (Example usage of /playerList api endpoint.)

fetch('http://localhost:3000/playerList').then(response => {
  response.json().then(json => {
    console.log(json); // list of plyaers that have joined the server
  });
});

api~/newPlayers/:date() ⇒ JSON

return array of new users

Kind: inner method of api
Returns: JSON - list of players from the given date

Param Type Description
req.params.date Number date of the month you want to view users for 0 = today

Example (Example usage of /newPlayer/:date api endpoint.)

fetch('http://localhost:3000/newPlayer/1').then(response => {
  response.json().then(json => {
    console.log(json); // list of players that played in the server for the first time on the first of the month
  });
});

api~/returnPlayer/:date() ⇒ Array

return array of return users

Kind: inner method of api
Returns: Array - list of players from the given date

Param Type Description
req.params.date Number date of this month you want to view user for 0 = today

Example (Example usage of /returnPlayer/:date api endpoint.)

fetch('http://localhost:3000/returnPlayer/1').then(response => {
  response.json().then(json => {
    console.log(json); // list of returning players that played in the server on the first of the month
  });
});

api~/playerStats/:id() ⇒ JSON | HTML

route for gettings a individual players stats

Kind: inner method of api
Returns: JSON | HTML - players stat data | 404

Param Type Description
req.params.id Number steamid3 of the player

Example (Example usage of /playerStats/:id api endpoint.)

fetch('http://localhost:3000/playerStats/1025678454').then(response => {
  response.json().then(json => {
    console.log(json); // player statistics for player with the id 1025678454
  });
});

api~/download/:file(file) ⇒ File | HTML

route for downloading a demo file

Kind: inner method of api
Returns: File | HTML - .dem file | 404

Param Type Description
file String file name requested for download

Example (Example usage of /download/:file api endpoint.)

<a href="localhost:3000/download/auto-20210101-0649-dm_bellas_room_d1.dem"></a>

api~/download/logs-zip/:file(file) ⇒ File | HTML

route for downloading a previous months logs zip files

Kind: inner method of api
Returns: File | HTML - .zip file | 404

Param Type Description
file String filename requested for download

Example (Example usage of /download/logs-zip/:file api endpoint.)

<a href="localhost:3000/download/logs-zip/1609123414390.zip"></a>

api~/download/demos-zip/:file(file) ⇒ File | HTML

route for downloading a previous months demo zip files

Kind: inner method of api
Returns: File | HTML - .zip file | 404

Param Type Description
file String filename requested for download

Example (Example usage of /download/demos-zip/:file api endpoint.)

<a href="localhost:3000/download/demos-zip/1609123414390.zip"></a>

api~/demos() ⇒ JSON

route to get list of demo recording on the server

Kind: inner method of api
Returns: JSON - list of demo files
Example (Example usage of /demos api endpoint.)

fetch('http://localhost:3000/demos').then(response => {
  response.json().then(json => {
    console.log(json); // list of demo files that can be downloaded
  });
});

api~/cvarlist() ⇒ Text

route to get list of hl2dm server cvar's

Kind: inner method of api
Returns: Text - list of cvar commands
Example (Example usage of /cvarlist api endpoint.)

fetch('http://localhost:3000/cvarlist').then(response => {
  response.text().then(text => {
    console.log(text); // list of srcds conosle commands
  });
});

api~/testCleanup() ⇒ Text

tests the file cleanup function that runs every month on the first @ 5 am

Kind: inner method of api
Returns: Text - test start confirmation string
Example (Example usage of /testCleanup api endpoint.)

fetch('http://localhost:3000/testCleanup').then(response => {
  response.text().then(text => {
    console.log(text); // 'cleanup test started'
  });
});

api~/dashboard() ⇒ JSON

stats dashboard websocket

Kind: inner method of api
Returns: JSON - RCON stats

api~/admin() ⇒ HTML

admin portal

Kind: inner method of api
Returns: HTML - admin page

api~userConnected

callback for when a player joins server

Kind: inner typedef of api

Param Type Description
u Object user object with name, id, time, date, month, year, and if user is new to server

Example (Example usage of userConnected() function.)

scanner(.., .., .., .., userConnected, .., ..);

api~userDisconnected

callback for when a player leaves server

Kind: inner typedef of api

Param Type Description
u Object user object with name, id, time, date, month, year, and if user is new to server

Example (Example usage of userDisconnected() function.)

scanner(.., .., .., .., userDisconnected, .., ..);

api~playerBan

callback for when a player is banned

Kind: inner typedef of api

Param Type Description
player Object user object of the banned player

Example (Example usage of playerBan() function.)

scanner(.., .., .., .., playerBan, .., ..);

api~mapEnd

callback for when a round / map has ended

Kind: inner typedef of api
Example (Example usage of mapEnd() function.)

scanner(.., .., .., .., mapEnd, .., ..);

api~mapStart

callback for when a round / map has started

Kind: inner typedef of api
Example (Example usage of mapStart() function.)

scanner(.., .., .., .., mapStart, .., ..);

api~rconStats

callback server statistics

Kind: inner typedef of api
Example (Example usage of rconStats() function.)

new RconStats('127.0.0.1', 'supersecurepassword', rconStats).ping();

api~statsLoop ⇒ Void

loops to get Gamedig data for game server

Kind: inner typedef of api
Returns: Void - nothing
See

Example (Example usage of statsLoop() function.)

statsLoop(); // it will run every 5 seconds after being called