fix eslint errors
This commit is contained in:
+11
-9
@@ -1,17 +1,19 @@
|
||||
module.exports = {
|
||||
env: {
|
||||
browser: true,
|
||||
es2021: true
|
||||
es2021: true,
|
||||
},
|
||||
extends: 'standard-with-typescript',
|
||||
extends: "standard-with-typescript",
|
||||
overrides: [],
|
||||
parserOptions: {
|
||||
ecmaVersion: 'latest',
|
||||
sourceType: 'module',
|
||||
project: ['./tsconfig.json']
|
||||
ecmaVersion: "latest",
|
||||
sourceType: "module",
|
||||
project: ["./tsconfig.json"],
|
||||
},
|
||||
rules: {
|
||||
'@typescript-eslint/strict-boolean-expressions': 0,
|
||||
'@typescript-eslint/explicit-function-return-type': 'off'
|
||||
}
|
||||
}
|
||||
"@typescript-eslint/strict-boolean-expressions": 0,
|
||||
"@typescript-eslint/explicit-function-return-type": "off",
|
||||
},
|
||||
plugins: ["jest"],
|
||||
"jest/globals": true,
|
||||
};
|
||||
|
||||
Vendored
+2
-1
@@ -6,5 +6,6 @@
|
||||
"eslint.format.enable": true,
|
||||
"[typescript]": {
|
||||
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
||||
}
|
||||
},
|
||||
"typescript.tsdk": "node_modules\\typescript\\lib"
|
||||
}
|
||||
|
||||
Generated
+306
-410
File diff suppressed because it is too large
Load Diff
@@ -3,6 +3,7 @@
|
||||
"@types/ws": "^8.5.4",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^16.0.3",
|
||||
"eslint-plugin-jest": "^27.2.3",
|
||||
"express": "^4.18.2",
|
||||
"express-basic-auth": "^1.2.1",
|
||||
"express-validator": "^6.15.0",
|
||||
|
||||
@@ -43,7 +43,7 @@ router.get('/hosts', (_req, res) => {
|
||||
void (async () => {
|
||||
const result = await getHostList()
|
||||
const data: Record<number, string> = {}
|
||||
result.forEach((e) => (data[Number(e.id)] = e.name))
|
||||
result.forEach((e) => (data[Number(e.host_id)] = e.host_name))
|
||||
|
||||
const dataString = JSON.stringify(data)
|
||||
const buffer = Buffer.from(dataString)
|
||||
|
||||
+152
-143
@@ -1,6 +1,7 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { Router } from 'express'
|
||||
import { body, header } from 'express-validator'
|
||||
import { CreateKillRecord, CheckServerToken } from '../db/db'
|
||||
import { /* CreateKillRecord, */ CheckServerToken } from '../db/db'
|
||||
import { validateErrors } from '../common'
|
||||
|
||||
const router = Router()
|
||||
@@ -12,23 +13,33 @@ router.post(
|
||||
.exists({ checkFalsy: true })
|
||||
.withMessage('Missing Authorization Header')
|
||||
.bail()
|
||||
.custom(e => e.split(' ')[0].toLowerCase() == 'bearer')
|
||||
.custom((e) => e.split(' ')[0].toLowerCase() === 'bearer')
|
||||
.withMessage('Authorization Token is not Bearer'),
|
||||
validateErrors,
|
||||
async (req, res, next) => {
|
||||
(req, res, next) => {
|
||||
void (async () => {
|
||||
if (!req) return res.sendStatus(500)
|
||||
if (!req.headers.authorization) {
|
||||
console.error("no authorization header")
|
||||
console.error('no authorization header')
|
||||
return res.sendStatus(403)
|
||||
}
|
||||
const query = await CheckServerToken(req.headers.authorization.split(' ')[1])
|
||||
if (!query || !query.id) {
|
||||
console.error("incorrect token : " + req.headers.authorization.split(' ')[1] + " for " + req.body.servername + " with IP " + (req.headers['x-forwarded-for']?.toString() ||
|
||||
req.socket.remoteAddress?.toString() ||
|
||||
''))
|
||||
const query = await CheckServerToken(
|
||||
req.headers.authorization.split(' ')[1]
|
||||
)
|
||||
if (!query?.host_id) {
|
||||
console.error(
|
||||
`incorrect token : ${
|
||||
req.headers.authorization.split(' ')[1]
|
||||
} with IP ${
|
||||
req.headers['x-forwarded-for']?.toString() ??
|
||||
req.socket.remoteAddress?.toString() ??
|
||||
''
|
||||
}`
|
||||
)
|
||||
return res.sendStatus(403)
|
||||
}
|
||||
next()
|
||||
})()
|
||||
}
|
||||
)
|
||||
|
||||
@@ -37,8 +48,8 @@ router.post('/', (req, res) => {
|
||||
res.sendStatus(200)
|
||||
})
|
||||
|
||||
const serversCount: { [id: string]: number } = {}
|
||||
const serversTimeout: { [id: string]: NodeJS.Timeout } = {}
|
||||
// const serversCount: Record<string, number> = {}
|
||||
// const serversTimeout: Record<string, NodeJS.Timeout> = {}
|
||||
|
||||
// same rate limiting code as register. max 10 kills per server every 1 sec. should be enough.
|
||||
/* router.post('/kill', (req, res, next) => {
|
||||
@@ -134,9 +145,7 @@ router.post(
|
||||
.isString()
|
||||
.isLength({ max: 50 })
|
||||
.isAscii(),
|
||||
body('servername',).isString()
|
||||
.isLength({ max: 100 })
|
||||
.isAscii(),
|
||||
body('servername').isString().isLength({ max: 100 }).isAscii(),
|
||||
body(['distance', 'game_time'], 'must be postitive floats').isFloat({
|
||||
min: 0
|
||||
}),
|
||||
@@ -144,139 +153,139 @@ router.post(
|
||||
// do we need this ?
|
||||
// body('servername').customSanitizer(e => e.replace(/[^a-z0-9]/gi, '')),
|
||||
validateErrors,
|
||||
async (req, res) => {
|
||||
(req, res) => {
|
||||
void (async () => {
|
||||
// Do we check the same thing twice ?????
|
||||
if (!req.headers.authorization) return res.sendStatus(403)
|
||||
const headers = req.headers.authorization.split(' ')
|
||||
if (headers[0].toLowerCase() != "bearer") return res.status(403).send("authorization must be token bearer")
|
||||
const query = (await CheckServerToken(headers[1]))
|
||||
if (headers[0].toLowerCase() !== 'bearer') { return res.status(403).send('authorization must be token bearer') }
|
||||
const query = await CheckServerToken(headers[1])
|
||||
if (!query) return res.sendStatus(403)
|
||||
const host = query.id
|
||||
const {
|
||||
servername,
|
||||
killstat_version,
|
||||
match_id,
|
||||
game_mode,
|
||||
map,
|
||||
game_time,
|
||||
player_count,
|
||||
attacker_name,
|
||||
attacker_id,
|
||||
attacker_current_weapon,
|
||||
attacker_current_weapon_mods,
|
||||
attacker_weapon_1,
|
||||
attacker_weapon_1_mods,
|
||||
attacker_weapon_2,
|
||||
attacker_weapon_2_mods,
|
||||
attacker_weapon_3,
|
||||
attacker_weapon_3_mods,
|
||||
attacker_offhand_weapon_1,
|
||||
attacker_offhand_weapon_1_mods,
|
||||
attacker_offhand_weapon_2,
|
||||
attacker_offhand_weapon_2_mods,
|
||||
victim_name,
|
||||
victim_id,
|
||||
victim_current_weapon,
|
||||
victim_current_weapon_mods,
|
||||
victim_weapon_1,
|
||||
victim_weapon_1_mods,
|
||||
victim_weapon_2,
|
||||
victim_weapon_2_mods,
|
||||
victim_weapon_3,
|
||||
victim_weapon_3_mods,
|
||||
victim_offhand_weapon_1,
|
||||
victim_offhand_weapon_1_mods,
|
||||
victim_offhand_weapon_2,
|
||||
victim_offhand_weapon_2_mods,
|
||||
cause_of_death,
|
||||
distance
|
||||
} = req.body
|
||||
CreateKillRecord({
|
||||
killstat_version,
|
||||
servername,
|
||||
host,
|
||||
match_id,
|
||||
game_mode,
|
||||
map,
|
||||
game_time,
|
||||
player_count,
|
||||
attacker_name,
|
||||
attacker_id,
|
||||
attacker_current_weapon,
|
||||
attacker_current_weapon_mods,
|
||||
attacker_weapon_1,
|
||||
attacker_weapon_1_mods,
|
||||
attacker_weapon_2,
|
||||
attacker_weapon_2_mods,
|
||||
attacker_weapon_3,
|
||||
attacker_weapon_3_mods,
|
||||
attacker_offhand_weapon_1,
|
||||
attacker_offhand_weapon_1_mods,
|
||||
attacker_offhand_weapon_2,
|
||||
attacker_offhand_weapon_2_mods,
|
||||
victim_name,
|
||||
victim_id,
|
||||
victim_current_weapon,
|
||||
victim_current_weapon_mods,
|
||||
victim_weapon_1,
|
||||
victim_weapon_1_mods,
|
||||
victim_weapon_2,
|
||||
victim_weapon_2_mods,
|
||||
victim_weapon_3,
|
||||
victim_weapon_3_mods,
|
||||
victim_offhand_weapon_1,
|
||||
victim_offhand_weapon_1_mods,
|
||||
victim_offhand_weapon_2,
|
||||
victim_offhand_weapon_2_mods,
|
||||
cause_of_death,
|
||||
distance
|
||||
})
|
||||
.then((e) => {
|
||||
res.sendStatus(201)
|
||||
console.log(
|
||||
`[${new Date().toLocaleString()}] Kill submitted for server ${servername}, ${attacker_name} killed ${victim_name}`
|
||||
)
|
||||
})
|
||||
.catch((e) => {
|
||||
res.sendStatus(500)
|
||||
console.error({
|
||||
killstat_version,
|
||||
servername,
|
||||
host,
|
||||
match_id,
|
||||
game_mode,
|
||||
map,
|
||||
game_time,
|
||||
player_count,
|
||||
attacker_name,
|
||||
attacker_id,
|
||||
attacker_current_weapon,
|
||||
attacker_current_weapon_mods,
|
||||
attacker_weapon_1,
|
||||
attacker_weapon_1_mods,
|
||||
attacker_weapon_2,
|
||||
attacker_weapon_2_mods,
|
||||
attacker_weapon_3,
|
||||
attacker_weapon_3_mods,
|
||||
attacker_offhand_weapon_1,
|
||||
attacker_offhand_weapon_2,
|
||||
victim_name,
|
||||
victim_id,
|
||||
victim_current_weapon,
|
||||
victim_current_weapon_mods,
|
||||
victim_weapon_1,
|
||||
victim_weapon_1_mods,
|
||||
victim_weapon_2,
|
||||
victim_weapon_2_mods,
|
||||
victim_weapon_3,
|
||||
victim_weapon_3_mods,
|
||||
victim_offhand_weapon_1,
|
||||
victim_offhand_weapon_2,
|
||||
cause_of_death,
|
||||
distance
|
||||
})
|
||||
console.error(e)
|
||||
})
|
||||
// const host = query.id
|
||||
// const {
|
||||
// servername,
|
||||
// match_id,
|
||||
// game_mode,
|
||||
// map,
|
||||
// game_time,
|
||||
// player_count,
|
||||
// attacker_name,
|
||||
// attacker_id,
|
||||
// attacker_current_weapon,
|
||||
// attacker_current_weapon_mods,
|
||||
// attacker_weapon_1,
|
||||
// attacker_weapon_1_mods,
|
||||
// attacker_weapon_2,
|
||||
// attacker_weapon_2_mods,
|
||||
// attacker_weapon_3,
|
||||
// attacker_weapon_3_mods,
|
||||
// attacker_offhand_weapon_1,
|
||||
// attacker_offhand_weapon_1_mods,
|
||||
// attacker_offhand_weapon_2,
|
||||
// attacker_offhand_weapon_2_mods,
|
||||
// victim_name,
|
||||
// victim_id,
|
||||
// victim_current_weapon,
|
||||
// victim_current_weapon_mods,
|
||||
// victim_weapon_1,
|
||||
// victim_weapon_1_mods,
|
||||
// victim_weapon_2,
|
||||
// victim_weapon_2_mods,
|
||||
// victim_weapon_3,
|
||||
// victim_weapon_3_mods,
|
||||
// victim_offhand_weapon_1,
|
||||
// victim_offhand_weapon_1_mods,
|
||||
// victim_offhand_weapon_2,
|
||||
// victim_offhand_weapon_2_mods,
|
||||
// cause_of_death,
|
||||
// distance
|
||||
// } = req.body
|
||||
// CreateKillRecord({
|
||||
// servername,
|
||||
// host,
|
||||
// match_id,
|
||||
// game_mode,
|
||||
// map,
|
||||
// game_time,
|
||||
// player_count,
|
||||
// attacker_name,
|
||||
// attacker_id,
|
||||
// attacker_current_weapon,
|
||||
// attacker_current_weapon_mods,
|
||||
// attacker_weapon_1,
|
||||
// attacker_weapon_1_mods,
|
||||
// attacker_weapon_2,
|
||||
// attacker_weapon_2_mods,
|
||||
// attacker_weapon_3,
|
||||
// attacker_weapon_3_mods,
|
||||
// attacker_offhand_weapon_1,
|
||||
// attacker_offhand_weapon_1_mods,
|
||||
// attacker_offhand_weapon_2,
|
||||
// attacker_offhand_weapon_2_mods,
|
||||
// victim_name,
|
||||
// victim_id,
|
||||
// victim_current_weapon,
|
||||
// victim_current_weapon_mods,
|
||||
// victim_weapon_1,
|
||||
// victim_weapon_1_mods,
|
||||
// victim_weapon_2,
|
||||
// victim_weapon_2_mods,
|
||||
// victim_weapon_3,
|
||||
// victim_weapon_3_mods,
|
||||
// victim_offhand_weapon_1,
|
||||
// victim_offhand_weapon_1_mods,
|
||||
// victim_offhand_weapon_2,
|
||||
// victim_offhand_weapon_2_mods,
|
||||
// cause_of_death,
|
||||
// distance
|
||||
// })
|
||||
// .then((e) => {
|
||||
// res.sendStatus(201)
|
||||
// console.log(
|
||||
// `[${new Date().toLocaleString()}] Kill submitted for server ${servername}, ${attacker_name} killed ${victim_name}`
|
||||
// )
|
||||
// })
|
||||
// .catch((e) => {
|
||||
// res.sendStatus(500)
|
||||
// console.error({
|
||||
// killstat_version,
|
||||
// servername,
|
||||
// host,
|
||||
// match_id,
|
||||
// game_mode,
|
||||
// map,
|
||||
// game_time,
|
||||
// player_count,
|
||||
// attacker_name,
|
||||
// attacker_id,
|
||||
// attacker_current_weapon,
|
||||
// attacker_current_weapon_mods,
|
||||
// attacker_weapon_1,
|
||||
// attacker_weapon_1_mods,
|
||||
// attacker_weapon_2,
|
||||
// attacker_weapon_2_mods,
|
||||
// attacker_weapon_3,
|
||||
// attacker_weapon_3_mods,
|
||||
// attacker_offhand_weapon_1,
|
||||
// attacker_offhand_weapon_2,
|
||||
// victim_name,
|
||||
// victim_id,
|
||||
// victim_current_weapon,
|
||||
// victim_current_weapon_mods,
|
||||
// victim_weapon_1,
|
||||
// victim_weapon_1_mods,
|
||||
// victim_weapon_2,
|
||||
// victim_weapon_2_mods,
|
||||
// victim_weapon_3,
|
||||
// victim_weapon_3_mods,
|
||||
// victim_offhand_weapon_1,
|
||||
// victim_offhand_weapon_2,
|
||||
// cause_of_death,
|
||||
// distance
|
||||
// })
|
||||
// console.error(e)
|
||||
// })
|
||||
})()
|
||||
}
|
||||
)
|
||||
export default router
|
||||
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
import * as dotenv from 'dotenv'
|
||||
dotenv.config()
|
||||
import express from 'express'
|
||||
import cors from 'cors'
|
||||
import db, { dbReady } from './db/db'
|
||||
import { dbReady } from './db/db'
|
||||
import server from './server/server'
|
||||
dotenv.config()
|
||||
|
||||
const app = express()
|
||||
const port = 3001
|
||||
@@ -18,7 +18,7 @@ app.get('/', (req, res) => {
|
||||
app.use('/', server)
|
||||
|
||||
export default new Promise((resolve, reject) => {
|
||||
dbReady().then((e) => {
|
||||
void dbReady().then((e) => {
|
||||
const listenServer = app.listen(port, '0.0.0.0', () => {
|
||||
console.log(`Tone server api listening on port ${port}`)
|
||||
resolve(listenServer)
|
||||
|
||||
+34
-41
@@ -1,8 +1,8 @@
|
||||
import * as dotenv from 'dotenv'
|
||||
dotenv.config()
|
||||
import { Client } from 'pg'
|
||||
import { WebSocket, WebSocketServer } from 'ws'
|
||||
import { KillTable } from './db/model'
|
||||
import { type WebSocket, WebSocketServer } from 'ws'
|
||||
import { type KillTable } from './db/model'
|
||||
dotenv.config()
|
||||
|
||||
const port = 3002
|
||||
const wss = new WebSocketServer({ port })
|
||||
@@ -15,45 +15,38 @@ export const pgClient = new Client({
|
||||
})
|
||||
|
||||
wss.on('connection', function connection (ws: WebSocket & { isAlive: boolean }, req) {
|
||||
const ip =
|
||||
req?.headers['x-forwarded-for']?.toString().split(',')[0].trim() ||
|
||||
req.socket.remoteAddress
|
||||
console.log(
|
||||
new Date().toLocaleString() + ',' + ip + ',connect,' + wss.clients.size
|
||||
)
|
||||
const ip = req?.headers['x-forwarded-for']?.toString().split(',')[0].trim() ??
|
||||
req.socket.remoteAddress ?? 'ip_unknown'
|
||||
console.log(`${new Date().toLocaleString()},${ip},connect,${wss.clients.size}`)
|
||||
ws.onclose = function () {
|
||||
const ip =
|
||||
req?.headers['x-forwarded-for']?.toString().split(',')[0].trim() ||
|
||||
req.socket.remoteAddress
|
||||
console.log(
|
||||
new Date().toLocaleString() + ',' + ip + ',close,' + wss.clients.size
|
||||
)
|
||||
console.log(`${new Date().toLocaleString()},${ip},connect,${wss.clients.size}`)
|
||||
}
|
||||
ws.onmessage = function (msg) {
|
||||
if (msg.data === "pong") {
|
||||
return ws.isAlive = true
|
||||
if (msg.data === 'pong') {
|
||||
ws.isAlive = true
|
||||
return
|
||||
}
|
||||
if (msg.data === "ping") {
|
||||
return ws.send("pong")
|
||||
if (msg.data === 'ping') {
|
||||
ws.send('pong')
|
||||
}
|
||||
}
|
||||
ws.send("ping");
|
||||
ws.send('ping')
|
||||
})
|
||||
|
||||
const interval = setInterval(function ping () {
|
||||
wss.clients.forEach(function each (ws) {
|
||||
if ((ws as WebSocket & { isAlive: boolean }).isAlive === false) return ws.terminate();
|
||||
if (!(ws as WebSocket & { isAlive: boolean }).isAlive) { ws.terminate(); return }
|
||||
|
||||
(ws as WebSocket & { isAlive: boolean }).isAlive = false;
|
||||
ws.send("ping");
|
||||
});
|
||||
}, 30000);
|
||||
(ws as WebSocket & { isAlive: boolean }).isAlive = false
|
||||
ws.send('ping')
|
||||
})
|
||||
}, 30000)
|
||||
|
||||
wss.on('close', function close () {
|
||||
clearInterval(interval);
|
||||
});
|
||||
clearInterval(interval)
|
||||
})
|
||||
|
||||
export default new Promise(async (resolve, reject) => {
|
||||
export default async () => {
|
||||
await pgClient.connect()
|
||||
await pgClient.query('LISTEN new_kill')
|
||||
|
||||
@@ -65,21 +58,21 @@ export default new Promise(async (resolve, reject) => {
|
||||
client.send(
|
||||
JSON.stringify({
|
||||
match_id: payload.match_id,
|
||||
attacker_id: payload.attacker_id,
|
||||
attacker_name: payload.attacker_name,
|
||||
cause_of_death: payload.cause_of_death,
|
||||
victim_id: payload.victim_id,
|
||||
victim_name: payload.victim_name,
|
||||
attacker_current_weapon: payload.attacker_current_weapon,
|
||||
victim_current_weapon: payload.victim_current_weapon,
|
||||
distance: payload.distance,
|
||||
game_mode: payload.game_mode,
|
||||
servername: payload.servername,
|
||||
map: payload.map,
|
||||
host: payload.host
|
||||
attacker_id: payload.attacker_id
|
||||
// attacker_name: payload.attacker_name,
|
||||
// cause_of_death: payload.cause_of_death,
|
||||
// victim_id: payload.victim_id,
|
||||
// victim_name: payload.victim_name,
|
||||
// attacker_current_weapon: payload.attacker_current_weapon,
|
||||
// victim_current_weapon: payload.victim_current_weapon,
|
||||
// distance: payload.distance,
|
||||
// game_mode: payload.game_mode,
|
||||
// servername: payload.servername,
|
||||
// map: payload.map,
|
||||
// host: payload.host
|
||||
})
|
||||
)
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user