From eb0adfc2e0451f70d3019efb7404c6921712ca0e Mon Sep 17 00:00:00 2001 From: HenryDu8133 <813367384@qq.com> Date: Sat, 1 Aug 2026 11:10:17 +0800 Subject: [PATCH] feat: handle line.txt and train arrival/departure events --- CloudServer/server.js | 61 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/CloudServer/server.js b/CloudServer/server.js index f0c2fc2..2f3a4e1 100644 --- a/CloudServer/server.js +++ b/CloudServer/server.js @@ -838,6 +838,10 @@ function resolveManagedPath(inputPath) { return { logicalPath: 'list.txt', fullPath: listFilePath }; } + if (normalized === 'Audio/general/line.txt' || normalized === 'uploads/audio/general/line.txt') { + return { logicalPath: 'Audio/general/line.txt', fullPath: path.join(audioGeneralDir, 'line.txt') }; + } + const prefixes = [ { prefix: 'Audio/music/', baseDir: audioMusicDir, logicalPrefix: 'Audio/music/' }, { prefix: 'Audio/voice/', baseDir: audioVoiceDir, logicalPrefix: 'Audio/voice/' }, @@ -923,7 +927,7 @@ function getManagedFiles() { files.push({ name: file, path: `Audio/general/${file}`, - type: 'beep', + type: file === 'line.txt' ? 'config' : 'beep', size: stats.size, mtime: stats.mtimeMs }); @@ -1587,7 +1591,11 @@ function handleMessage(ws, data) { handleStationRegister(ws, data); break; case 'train_arrival': + handleTrainArrival(ws, data); + break; case 'train_departure': + handleTrainDeparture(ws, data); + break; case 'play_sequence': break; case 'request_station_time': @@ -1752,6 +1760,57 @@ function findStationByFlexibleName(targetName) { return null; } +function handleTrainArrival(ws, data) { + const trainId = data.trainId; + const stationName = getCorrectStationName(data.stationName); + + const existingIndex = activeTrains.findIndex(t => t.trainId === trainId); + const trainData = { + trainId, + stationName, + status: 'arrived', + lastUpdated: Date.now() + }; + + if (existingIndex >= 0) { + activeTrains[existingIndex] = trainData; + } else { + activeTrains.push(trainData); + } + + log('INFO', `Train ${trainId} arrived at ${stationName}`); + saveData(); + broadcastUpdate(); + + ws.send(JSON.stringify({ + type: 'train_arrival_ack', + success: true, + message: 'Train arrival processed successfully', + trainId + })); +} + +function handleTrainDeparture(ws, data) { + const trainId = data.trainId; + const stationName = getCorrectStationName(data.stationName); + + const existingIndex = activeTrains.findIndex(t => t.trainId === trainId); + if (existingIndex >= 0) { + activeTrains.splice(existingIndex, 1); + } + + log('INFO', `Train ${trainId} departed from ${stationName}`); + saveData(); + broadcastUpdate(); + + ws.send(JSON.stringify({ + type: 'train_departure_ack', + success: true, + message: 'Train departure processed successfully', + trainId + })); +} + function handleStationTimeRequest(ws, data) { // Simple logic: default to 60s or lookup schedule const stationTime = 60;