id validator

This commit is contained in:
catvayor 2023-06-10 09:46:04 +02:00
parent 81355eddf9
commit f6aa56310c
6 changed files with 34 additions and 21 deletions

View file

@ -1,7 +1,18 @@
// Configuration file for the server
conscrits = ["team00", "team01"];
vieux = ["npc0", "npc1"];
// return 0 for conscrit, 1 for vieux, 2 otherwise
function validator(id){
if(conscrits.includes(id)) return 0;
if(vieux.includes(id)) return 1;
return 2;
}
module.exports = {
"port": 9000,
"key": "certif/server.key",
"cert": "certif/server.crt"
}
"cert": "certif/server.crt",
"validator": validator
}

View file

@ -46,8 +46,7 @@
// SOCKET
id = "%ID"; // %ID will be replaced by the real id.
type = "conscrit";
setup_socket_not_admin();
socket = io({rejectUnauthorized: false, auth: {id: id, type:"conscrit"}});
setup_socket_common();
//////////////////////////////////////////////////////////////////////////////

View file

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title> Équipe %ID inconnue ! </title>
</head>
<body>
<h1> Équipe %ID inconnue ! </h1>
Utilise bien les urls qu'on te donne petit conscrit.
</body>
</html>

View file

@ -27,7 +27,7 @@
}
</style>
<script type="text/javascript" src="utils.js"></script>
<script type="text/javascript" src="/utils.js"></script>
</head>
<body>
<div id="map"></div><br/>
@ -45,17 +45,12 @@
//////////////////////////////////////////////////////////////////////////////
// UPDATE MAP
setup_socket_not_admin();
id = "%ID"; // %ID will be replaced by the real id.
socket = io({rejectUnauthorized: false, auth: {id: id, type:"vieux"}});
setup_socket_common();
//////////////////////////////////////////////////////////////////////////////
// SETTINGS -- NAME AND COLOR
document.querySelector('#setColor').addEventListener('click', function(){
const input = document.querySelector('#color');
socket.emit("changeColor", {"color": input.value});
});
// SETTINGS -- State
//////////////////////////////////////////////////////////////////////////////
// GEOLOCALISATION

View file

@ -3,7 +3,6 @@ var server = location.hostname;
var port = location.port;
var socket;
var id;
var type;
var markers = {};
var CircleIcon = L.Icon.extend({
@ -82,10 +81,6 @@ function setup_socket_common(){
});
}
function setup_socket_not_admin(){
socket = io({rejectUnauthorized: false, auth: {id: id, type:type}});
}
//////////////////////////////////////////////////////////////////////////////
// GEOLOCALISATION

View file

@ -53,10 +53,11 @@ var server = http.createServer(option, function(req, res){
if(q.pathname.startsWith("/tracking/")){
id = q.pathname.substring("/tracking/".length);
//TODO validator for the id
return fs.readFile("static/tracking/conscrit.html", 'utf8', function(err, data){
var end_path = ["conscrit.html", "vieux.html", "invalid.html"][config.validator(id)];
filename = "static/tracking/" + end_path;
return fs.readFile(filename, 'utf8', function(err, data){
if(err)
throw new Error("where conscrit.html is !?");
throw new Error("where " + end_path + " is !?");
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(data.replaceAll("%ID", id));