repaired vieux, and done some modif for team creation

This commit is contained in:
catvayor 2023-06-10 13:53:20 +02:00
parent f6aa56310c
commit 8114129037
2 changed files with 62 additions and 11 deletions

View file

@ -33,7 +33,22 @@
<div id="map"></div><br/>
<div id="below">
<input type="number" id="color" min="-1" value="0"/><button id="setColor">Set color</button><br/>
<form id="state">
<input type="checkbox" id="shown" name="shown" onclick='sendState()' />
<label for="shown">Visible</label></br>
<input type="radio" id="npc0" name="npc" value=0 onclick='sendState()' />
<label for="npc0">Traqueur</label>
<input type="radio" id="npc1" name="npc" value=1 checked onclick='sendState()' />
<label for="npc1">NPC Violet</label>
<input type="radio" id="npc2" name="npc" value=2 onclick='sendState()' />
<label for="npc2">NPC Vert</label>
<input type="radio" id="npc3" name="npc" value=3 onclick='sendState()' />
<label for="npc3">NPC Orange</label>
</form>
</div>
<script type="text/javascript">
@ -52,6 +67,25 @@
//////////////////////////////////////////////////////////////////////////////
// SETTINGS -- State
var form = document.querySelector("#state");
function sendState(){
const data = new FormData(form);
var nState = {};
for(entry of data)
nState[entry[0]] = entry[1];
nState.shown = "shown" in nState;
nState.tracker = nState.npc == 0;
socket.emit('changeState', nState);
}
socket.on('newState', function(state){
document.querySelector("#shown").checked = state.shown;
document.querySelector("#npc0").checked = state.npc == 0;
document.querySelector("#npc1").checked = state.npc == 1;
document.querySelector("#npc2").checked = state.npc == 2;
document.querySelector("#npc3").checked = state.npc == 3;
});
//////////////////////////////////////////////////////////////////////////////
// GEOLOCALISATION

View file

@ -69,10 +69,11 @@ var server = http.createServer(option, function(req, res){
//position logging
console.log("team " + q.query.id + " moved to (" + q.query.lat + "," + q.query.lon + ")");
if(!(q.query.id in equipes))
equipes[q.query.id] = default_team(q.query.id);
equipes[q.query.id].pos = [q.query.lat, q.query.lon];
emit_update(q.query.id);
var id = q.query.id;
if(id in equipes){
equipes[id].pos = [q.query.lat, q.query.lon];
emit_update(id);
}
//return empty page
res.writeHead(200, {'Content-Type': 'text/html'});
@ -94,6 +95,24 @@ console.log("Setup io server");
const { Server } = require("socket.io");
var io = new Server(server);
io.use(function(socket, next){
var id = socket.handshake.auth.id;
var type = socket.handshake.auth.type;
if(type == "Admin")
next();
else{
var valid = config.validator(id);
if(valid == 0 && type == "conscrit" ||
valid == 1 && type == "vieux"){
if(!(id in equipes))
equipes[id] = default_team(id, valid);
next();
} else
next(new Error("invalid"));
}
});
/////////////////
// Tracking room
//
@ -124,7 +143,7 @@ var admin = io.to("Admin");
function color(team){
if(!team.state.shown) return 2;
if(team.state.tracker) return 1;
if(team.state.npc != 0) return 2 + team.state.npc;
if(team.state.npc != 0) return team.state.npc - 0 + 2;
return 0;
}
@ -145,12 +164,12 @@ function emit_update(team_id) {
}
// produces a team object populated with default values
function default_team(team_id) {
function default_team(team_id, valid) {
var equipe = {};
var state = {};
state.shown = true;
state.shown = valid == 0;
state.tracker = false;
state.npc = 0;
state.npc = valid;
equipe.state = state;
equipe.pos = [0,0];
equipe.id = team_id;
@ -176,8 +195,6 @@ io.on('connection', function(socket){
console.log("connection of " + id + " !");
socket.join("Tracking");
if(!(id in equipes))
equipes[id] = default_team(id);
var equipe = equipes[id]
team_join(equipe, socket);