diff --git a/sample_config.js b/sample_config.js index 269b485..d262b62 100644 --- a/sample_config.js +++ b/sample_config.js @@ -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" -} \ No newline at end of file + "cert": "certif/server.crt", + "validator": validator +} diff --git a/static/tracking/conscrit.html b/static/tracking/conscrit.html index b624ca7..d949e29 100644 --- a/static/tracking/conscrit.html +++ b/static/tracking/conscrit.html @@ -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(); ////////////////////////////////////////////////////////////////////////////// diff --git a/static/tracking/invalid.html b/static/tracking/invalid.html new file mode 100644 index 0000000..e7faa4b --- /dev/null +++ b/static/tracking/invalid.html @@ -0,0 +1,12 @@ + + + + + + Équipe %ID inconnue ! + + +

Équipe %ID inconnue !

+ Utilise bien les urls qu'on te donne petit conscrit. + + diff --git a/static/tracking/vieux.html b/static/tracking/vieux.html index c248541..9d5ff1d 100644 --- a/static/tracking/vieux.html +++ b/static/tracking/vieux.html @@ -27,7 +27,7 @@ } - +

@@ -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 diff --git a/static/utils.js b/static/utils.js index 5286bef..fefd1fd 100644 --- a/static/utils.js +++ b/static/utils.js @@ -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 diff --git a/traque.js b/traque.js index fc0ea82..bd4a241 100644 --- a/traque.js +++ b/traque.js @@ -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));