id validator
This commit is contained in:
parent
81355eddf9
commit
f6aa56310c
6 changed files with 34 additions and 21 deletions
|
@ -1,7 +1,18 @@
|
||||||
// Configuration file for the server
|
// 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 = {
|
module.exports = {
|
||||||
"port": 9000,
|
"port": 9000,
|
||||||
"key": "certif/server.key",
|
"key": "certif/server.key",
|
||||||
"cert": "certif/server.crt"
|
"cert": "certif/server.crt",
|
||||||
}
|
"validator": validator
|
||||||
|
}
|
||||||
|
|
|
@ -46,8 +46,7 @@
|
||||||
// SOCKET
|
// SOCKET
|
||||||
|
|
||||||
id = "%ID"; // %ID will be replaced by the real id.
|
id = "%ID"; // %ID will be replaced by the real id.
|
||||||
type = "conscrit";
|
socket = io({rejectUnauthorized: false, auth: {id: id, type:"conscrit"}});
|
||||||
setup_socket_not_admin();
|
|
||||||
setup_socket_common();
|
setup_socket_common();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
12
static/tracking/invalid.html
Normal file
12
static/tracking/invalid.html
Normal 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>
|
|
@ -27,7 +27,7 @@
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script type="text/javascript" src="utils.js"></script>
|
<script type="text/javascript" src="/utils.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="map"></div><br/>
|
<div id="map"></div><br/>
|
||||||
|
@ -45,17 +45,12 @@
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
// UPDATE MAP
|
// 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();
|
setup_socket_common();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
// SETTINGS -- NAME AND COLOR
|
// SETTINGS -- State
|
||||||
|
|
||||||
document.querySelector('#setColor').addEventListener('click', function(){
|
|
||||||
const input = document.querySelector('#color');
|
|
||||||
|
|
||||||
socket.emit("changeColor", {"color": input.value});
|
|
||||||
});
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
// GEOLOCALISATION
|
// GEOLOCALISATION
|
||||||
|
|
|
@ -3,7 +3,6 @@ var server = location.hostname;
|
||||||
var port = location.port;
|
var port = location.port;
|
||||||
var socket;
|
var socket;
|
||||||
var id;
|
var id;
|
||||||
var type;
|
|
||||||
var markers = {};
|
var markers = {};
|
||||||
|
|
||||||
var CircleIcon = L.Icon.extend({
|
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
|
// GEOLOCALISATION
|
||||||
|
|
||||||
|
|
|
@ -53,10 +53,11 @@ var server = http.createServer(option, function(req, res){
|
||||||
|
|
||||||
if(q.pathname.startsWith("/tracking/")){
|
if(q.pathname.startsWith("/tracking/")){
|
||||||
id = q.pathname.substring("/tracking/".length);
|
id = q.pathname.substring("/tracking/".length);
|
||||||
//TODO validator for the id
|
var end_path = ["conscrit.html", "vieux.html", "invalid.html"][config.validator(id)];
|
||||||
return fs.readFile("static/tracking/conscrit.html", 'utf8', function(err, data){
|
filename = "static/tracking/" + end_path;
|
||||||
|
return fs.readFile(filename, 'utf8', function(err, data){
|
||||||
if(err)
|
if(err)
|
||||||
throw new Error("where conscrit.html is !?");
|
throw new Error("where " + end_path + " is !?");
|
||||||
|
|
||||||
res.writeHead(200, {'Content-Type': 'text/html'});
|
res.writeHead(200, {'Content-Type': 'text/html'});
|
||||||
res.write(data.replaceAll("%ID", id));
|
res.write(data.replaceAll("%ID", id));
|
||||||
|
|
Loading…
Reference in a new issue