handle registration
This commit is contained in:
+15
-5
@@ -10,6 +10,7 @@ const router = Router()
|
|||||||
|
|
||||||
const hostsCount: { [id: string]: number } = {}
|
const hostsCount: { [id: string]: number } = {}
|
||||||
const hostsTimeout: { [id: string]: NodeJS.Timeout } = {}
|
const hostsTimeout: { [id: string]: NodeJS.Timeout } = {}
|
||||||
|
|
||||||
//Very simple rate limiting. max 2 registers per IP every 5 mins. Maybe 2 is a bit few ?
|
//Very simple rate limiting. max 2 registers per IP every 5 mins. Maybe 2 is a bit few ?
|
||||||
router.post('/servers/register', (req, res, next) => {
|
router.post('/servers/register', (req, res, next) => {
|
||||||
let ip =
|
let ip =
|
||||||
@@ -31,12 +32,15 @@ router.post('/servers/register', (req, res, next) => {
|
|||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
'/servers/register',
|
'/servers/register',
|
||||||
body(['name', 'description']).isString(),
|
body(['name', 'description']).isString().withMessage('must be strings'),
|
||||||
body('auth_endpoint').isURL(),
|
body('auth_port')
|
||||||
|
.toInt()
|
||||||
|
.isInt({ min: 1, max: 65535 })
|
||||||
|
.withMessage('must be between 1 and 65535'),
|
||||||
async (req, res, next) => {
|
async (req, res, next) => {
|
||||||
const errors = validationResult(req)
|
const errors = validationResult(req)
|
||||||
|
console.log(req.body)
|
||||||
if (!errors.isEmpty()) {
|
if (!errors.isEmpty()) {
|
||||||
console.log(JSON.stringify(errors))
|
|
||||||
return res.status(400).json({ errors: errors.array() })
|
return res.status(400).json({ errors: errors.array() })
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -59,9 +63,15 @@ router.post(
|
|||||||
|
|
||||||
//Send request to verify server. Not very useful for now, but maybe a future method for auth ?
|
//Send request to verify server. Not very useful for now, but maybe a future method for auth ?
|
||||||
//Maybe should set a blacklist here for local domain ?
|
//Maybe should set a blacklist here for local domain ?
|
||||||
if ((await GetRequest(req.body.auth_endpoint)) != verificationString) {
|
const endpoint =
|
||||||
|
'http://' +
|
||||||
|
(req.header('x-forwarded-for') || req.socket.remoteAddress) +
|
||||||
|
':' +
|
||||||
|
req.body.auth_port +
|
||||||
|
'/verify'
|
||||||
|
if ((await GetRequest(endpoint)) != verificationString) {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
error: "Couldn't reach gameserver at " + req.body.auth_endpoint
|
error: "Couldn't reach gameserver at " + endpoint
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Router } from 'express'
|
import { NextFunction, Router } from 'express'
|
||||||
import expressBasicAuth from 'express-basic-auth'
|
import expressBasicAuth from 'express-basic-auth'
|
||||||
import { body, header, validationResult } from 'express-validator'
|
import { body, header, validationResult } from 'express-validator'
|
||||||
import register from './register'
|
import register from './register'
|
||||||
@@ -10,7 +10,7 @@ router.use('/', register)
|
|||||||
|
|
||||||
//auth middleware
|
//auth middleware
|
||||||
router.post(
|
router.post(
|
||||||
'/servers/:serverId/kill',
|
'/servers/:serverId/*',
|
||||||
header('authorization')
|
header('authorization')
|
||||||
.exists({ checkFalsy: true })
|
.exists({ checkFalsy: true })
|
||||||
.withMessage('Missing Authorization Header')
|
.withMessage('Missing Authorization Header')
|
||||||
@@ -36,6 +36,10 @@ router.post(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
router.post('/servers/:serverId', (req, res) => {
|
||||||
|
res.send(200)
|
||||||
|
})
|
||||||
|
|
||||||
const serversCount: { [id: string]: number } = {}
|
const serversCount: { [id: string]: number } = {}
|
||||||
const serversTimeout: { [id: string]: NodeJS.Timeout } = {}
|
const serversTimeout: { [id: string]: NodeJS.Timeout } = {}
|
||||||
|
|
||||||
@@ -116,7 +120,6 @@ router.post(
|
|||||||
console.log(JSON.stringify(errors))
|
console.log(JSON.stringify(errors))
|
||||||
return res.status(400).json({ errors: errors.array() })
|
return res.status(400).json({ errors: errors.array() })
|
||||||
}
|
}
|
||||||
const server = 1 // set server ID here
|
|
||||||
const {
|
const {
|
||||||
killstat_version,
|
killstat_version,
|
||||||
match_id,
|
match_id,
|
||||||
@@ -153,7 +156,7 @@ router.post(
|
|||||||
} = req.body
|
} = req.body
|
||||||
CreateKillRecord({
|
CreateKillRecord({
|
||||||
killstat_version,
|
killstat_version,
|
||||||
server,
|
server: req.body.serverId,
|
||||||
match_id,
|
match_id,
|
||||||
game_mode,
|
game_mode,
|
||||||
map,
|
map,
|
||||||
|
|||||||
Reference in New Issue
Block a user