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
- ~errorHandler(e) ⇒
Void
- ~who(ip, message) ⇒
Void
- ~getOldStatsList(month) ⇒
Promise.<Array>
- ~parseLogs() ⇒
Promise.<String>
- ~readableTime(ms) ⇒
String
- ~fourohfour(req, res) ⇒
HTML
- ~fiveHundred(req, res) ⇒
HTML
- ~/() ⇒
Void
- ~/() ⇒
JSON
- ~/status() ⇒
JSON
- ~/auth() ⇒
JSON
- ~/stats() ⇒
JSON
- ~/old-months() ⇒
JSON
|HTML
- ~/old-stats/:month/:year() ⇒
JSON
|HTML
- ~/playerList() ⇒
JSON
- ~/newPlayers/:date() ⇒
JSON
- ~/returnPlayer/:date() ⇒
Array
- ~/playerStats/:id() ⇒
JSON
|HTML
- ~/download/:file(file) ⇒
File
|HTML
- ~/download/logs-zip/:file(file) ⇒
File
|HTML
- ~/download/demos-zip/:file(file) ⇒
File
|HTML
- ~/demos() ⇒
JSON
- ~/cvarlist() ⇒
Text
- ~/testCleanup() ⇒
Text
- ~/dashboard() ⇒
JSON
- ~/admin() ⇒
HTML
- ~userConnected
- ~userDisconnected
- ~playerBan
- ~mapEnd
- ~mapStart
- ~rconStats
- ~statsLoop ⇒
Void
- ~logError(error) ⇒
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');
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);
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');
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
//]
});
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'
});
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);
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);
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);
redirect to admin
Kind: inner method of api
Returns: Void
- redirect
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/);
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
});
});
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}
});
});
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
});
});
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
});
});
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
});
});
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
});
});
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
});
});
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
});
});
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
});
});
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>
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>
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>
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
});
});
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
});
});
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'
});
});
stats dashboard websocket
Kind: inner method of api
Returns: JSON
- RCON stats
admin portal
Kind: inner method of api
Returns: HTML
- admin page
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, .., ..);
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, .., ..);
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, .., ..);
callback for when a round / map has ended
Kind: inner typedef of api
Example (Example usage of mapEnd() function.)
scanner(.., .., .., .., mapEnd, .., ..);
callback for when a round / map has started
Kind: inner typedef of api
Example (Example usage of mapStart() function.)
scanner(.., .., .., .., mapStart, .., ..);
callback server statistics
Kind: inner typedef of api
Example (Example usage of rconStats() function.)
new RconStats('127.0.0.1', 'supersecurepassword', rconStats).ping();
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