EduNetworkBuilder/Web/network.js

72 lines
2.1 KiB
JavaScript

//This file contains the information about the puzzle (network)
//Each puzzle is stored in the allpuzzles variable. We need to select one and use it
var puzzle=networkFromName("Level0-Ping");
//var puzzle=networkFromName("Level0-NeedsLink");
//var puzzle=networkFromName("Level0_NetworkLoop");
//var puzzle=networkFromName("Level0_NetworkLoop2");
//var puzzle=networkFromName("Level0-SimpleDHCP");
//console.log(puzzle.name);
var device=deviceFromName("laptop0");
if(device !== null) {console.log("We found laptop0");}
else { console.log("Seems to be null"); }
function networkFromName(what)
{
let index=0;
while (index < allpuzzles.length) {
//console.log(allpuzzles[index].EduNetworkBuilder.Network.name);
if(allpuzzles[index].EduNetworkBuilder.Network.name == what)
{
console.log("Found " + what + " at index " + index);
return structuredClone(allpuzzles[index].EduNetworkBuilder.Network);
}
index++;
}
}
function networkNamesMatchingText(textToMatch)
{
var list = [];
var re = new RegExp(textToMatch);
let index=0;
while (index < allpuzzles.length) {
//console.log(allpuzzles[index].EduNetworkBuilder.Network.name);
if(re.test(allpuzzles[index].EduNetworkBuilder.Network.name))
{
//console.log("Found " + textToMatch + " at index " + index + " " + allpuzzles[index].EduNetworkBuilder.Network.name);
list.push(allpuzzles[index].EduNetworkBuilder.Network.name);
}
index++;
}
return list;
}
function deviceFromName(what)
{
if (puzzle == null) return null; //If the puzzle has not been set, return a null
let index=0;
while (index < puzzle.device.length) {
if (puzzle.device[index].hostname == what) return puzzle.device[index]; //return the device that matches
index++;
}
return null; //No match. return a null value
}
function deviceFromID(what)
{
if (puzzle == null) return null; //If the puzzle has not been set, return a null
let index=0;
while (index < puzzle.device.length) {
if (puzzle.device[index].uniqueidentifier == what) return puzzle.device[index]; //return the device that matches
index++;
}
return null; //No match. return a null value
}