Map socket comm

This commit is contained in:
2025-06-12 11:15:28 +02:00
parent de15de87a9
commit 5fe201182a
5 changed files with 151 additions and 48 deletions
+5 -6
View File
@@ -6,6 +6,7 @@ const express = require('express');
const app_conf = require("../config/app.conf.js");
const map_conf = require("../config/map.conf.js");
const messages = require("../config/messages.conf.js");
const socket = require("../utils/socket.util.js");
const map = require("../utils/map.util.js");
@@ -29,6 +30,7 @@ router.get("/disable", async (req, res) => {
logger.info(`${req.method}: "${req.url}" => ${req.get("User-Agent")}`);
fs.writeFileSync(path.join(path.dirname(require.main.filename), map_conf.map_storage_path, "selected"), "");
socket.broadcastMap(null);
res.status(200).send();
});
@@ -41,6 +43,7 @@ router.get("/enable", async (req, res) => {
if (requested_map && map.mapExists(requested_map)) {
fs.writeFileSync(path.join(path.dirname(require.main.filename), map_conf.map_storage_path, "selected"), requested_map);
socket.broadcastMap(requested_map);
res.status(200).send();
} else {
@@ -62,6 +65,7 @@ router.delete("/remove", async (req, res) => {
selected_map_name = fs.readFileSync(path.join(path.dirname(require.main.filename), map_conf.map_storage_path, "selected"), "utf-8");
if (selected_map_name == element) {
fs.writeFileSync(path.join(path.dirname(require.main.filename), map_conf.map_storage_path, "selected"), "");
socket.broadcastMap(null);
}
}
res.status(200).send();
@@ -195,12 +199,7 @@ router.get("/", async (req, res) => {
try {
const maps = await map.getAvailableMaps();
var selected_map_name = "";
// Check if a map has been selected to show it
if (fs.existsSync(path.join(path.dirname(require.main.filename), map_conf.map_storage_path, "selected"))) {
selected_map_name = fs.readFileSync(path.join(path.dirname(require.main.filename), map_conf.map_storage_path, "selected"), "utf-8");
}
var selected_map_name = map.getSelectedMap();
// Construct the maps table
var table_data = "";