72 lines
2.0 KiB
JavaScript
72 lines
2.0 KiB
JavaScript
const { Telidon } = require("telidon");
|
|
const fs = require("fs");
|
|
|
|
const curdir = process.cwd();
|
|
|
|
function invalidate(file) {
|
|
if(require.cache[require.resolve(file)]) {
|
|
require.cache[require.resolve(file)].children.forEach(c=>{
|
|
if(c.filename.startsWith(curdir))
|
|
invalidate(c.filename);
|
|
});
|
|
delete require.cache[require.resolve(file)];
|
|
}
|
|
}
|
|
|
|
function watch(file) {
|
|
return fs.watch(file, { recursive: true }, (eventType, filename) => {
|
|
if(eventType == 'change') invalidate(file+filename);
|
|
});
|
|
}
|
|
|
|
watch("./helpers/");
|
|
watch("./views/");
|
|
|
|
var server = new Telidon({}, c=>{
|
|
var current = null;
|
|
var currentPage = "./views/mainmenu.js";
|
|
var prevPage = null;
|
|
|
|
c.debug = true;
|
|
c.options.multiLength = 5;
|
|
c.init();
|
|
|
|
c.on("error", (err) => {
|
|
console.error(`Caught exception: ${err.stack}\n`)
|
|
c.cancel();
|
|
if(current != null)
|
|
current.leave();
|
|
current = null;
|
|
c.uninit();
|
|
c.write("\r\n\x1b[44m ÉCRAN DE LA MORT QUI TUE \x1b[0m\r\n\r\n");
|
|
c.write("Le serveur a rencontré une erreur fatale :(\r\n\r\n");
|
|
c.write("Vous pouvez nous aider en rapportant l'erreur suivante à nos admins:\r\n\r\n");
|
|
c.write((err.stack||"").split("\n").flatMap(a=>a.match(/.{1,80}/g)||[]).join("\r\n"));
|
|
c.write("\r\n\r\nVous pouvez maintenant vous déconnecter et vous reconnecter de nouveau.\r\nBonne journée!\r\n");
|
|
});
|
|
|
|
var goto = (page, save = true)=>{
|
|
if(save) prevPage = currentPage;
|
|
if(!page) page = currentPage;
|
|
currentPage = page;
|
|
if(current != null)
|
|
{
|
|
c.cancel();
|
|
current.leave();
|
|
}
|
|
var pg = require(page);
|
|
current = new pg(c);
|
|
current.goto = goto;
|
|
current.gotoPrev = gotoPrev;
|
|
}
|
|
var gotoPrev = () => {
|
|
if(prevPage) goto(prevPage);
|
|
}
|
|
goto();
|
|
c.on("data", d=>{
|
|
if(current != null)
|
|
current.data(d)
|
|
});
|
|
});
|
|
|
|
server.listen(8354); |