diff --git a/CloudServer/server.js b/CloudServer/server.js index 2501e6e..0c9f809 100644 --- a/CloudServer/server.js +++ b/CloudServer/server.js @@ -2213,14 +2213,24 @@ function handleTrainDeparture(ws, data) { const trainId = data.trainId; const stationName = getCorrectStationName(data.stationName); const stationCode = data.stationCode; + const platform = data.stationPlatform || data.platform || '1'; + const cleanPlatform = String(platform).replace(/\D/g, ''); + const finalPlatform = cleanPlatform || '1'; const beep = data.departureBeep || data.beep || 'fc1'; + const lineCode = data.lineCode || (stationCode ? stationCode.split('-')[0] : 'UNK'); + const destCode = data.destCode || getStationCodeFromName(data.destination) || 'UNK'; + const nextStationRaw = data.nextStation ? String(data.nextStation).trim() : ''; + const nextCodeRaw = data.nextCode ? String(data.nextCode).trim() : (nextStationRaw ? getStationCodeFromName(nextStationRaw) : ''); + const hasNextStation = nextStationRaw && nextStationRaw !== '' && nextCodeRaw && nextCodeRaw !== 'UNK' && nextCodeRaw !== ''; + const finalNextCode = hasNextStation ? nextCodeRaw : null; + const existingIndex = activeTrains.findIndex(t => t.trainId === trainId); if (existingIndex >= 0) { activeTrains.splice(existingIndex, 1); } - log('INFO', `Train ${trainId} departing from ${stationName}. Broadcasting departure...`); + log('INFO', `Train ${trainId} departing from ${stationName}. Broadcasting departure... nextStation=${nextStationRaw || '(none/terminal)'} nextCode=${finalNextCode || '(none)'}`); saveData(); broadcastUpdate(); @@ -2232,11 +2242,19 @@ function handleTrainDeparture(ws, data) { })); // Departure Audio Logic - const seq = [ - beep, - 'ja-doorwarn', - 'ch-doorwarn' - ]; + const seq = [beep, 'ja-doorwarn', 'ch-doorwarn']; + + if (finalNextCode) { + seq.push( + 'ja-fc1', `ja-${finalPlatform}`, 'ja-fc2', `ja-${destCode}`, 'ja-fc3', 'ja-nextsta', `ja-${finalNextCode}`, + 'ch-fc1', `ch-${finalPlatform}`, 'ch-fc2', 'ch-fc3', `ch-${destCode}`, 'ch-nextsta', `ch-${finalNextCode}` + ); + } else { + seq.push( + 'ja-fc1', `ja-${finalPlatform}`, 'ja-fc2', `ja-${destCode}`, 'ja-fc3', + 'ch-fc1', `ch-${finalPlatform}`, 'ch-fc2', 'ch-fc3', `ch-${destCode}` + ); + } enqueueHlsPush(stationName, seq); diff --git a/station_broadcast.lua b/station_broadcast.lua index 941e216..84bde65 100644 --- a/station_broadcast.lua +++ b/station_broadcast.lua @@ -1,6 +1,6 @@ -- 1. Configuration & Constants -local APP_VERSION_TEXT = "v1.0.70" +local APP_VERSION_TEXT = "v1.0.71" local CONFIG = { CLOUD_URL = "ws://stabadmin.fse-media.group", @@ -3529,6 +3529,13 @@ function Main.loop() local nextStation = Utils.getNextStation(schedule, State.stationName) local now = os.epoch("utc") / 1000 local stationTime = Utils.getStopTime(schedule, State.stationName) or 60 + local lineCode = Utils.getStationCode(State.stationCode or State.stationName) + if lineCode then + local dash = lineCode:find("-") + if dash then lineCode = lineCode:sub(1, dash - 1) end + end + local destCode = Utils.getStationCode(dest) + local nextCode = Utils.getStationCode(nextStation) State.currentTrain = { id = id, @@ -3536,6 +3543,9 @@ function Main.loop() schedule = schedule, dest = dest, nextStation = nextStation, + lineCode = lineCode, + destCode = destCode, + nextCode = nextCode, arrivalTime = now, departureTime = now + stationTime, platform = Utils.getPlatformNumber(State.stationName, "1"), @@ -3549,7 +3559,10 @@ function Main.loop() stationPlatform = State.stationPlatform, trainId = id, destination = dest, + destCode = destCode, nextStation = nextStation, + nextCode = nextCode, + lineCode = lineCode, departureTime = State.currentTrain.departureTime, departureBeep = State.departureBeep }) @@ -3566,7 +3579,10 @@ function Main.loop() stationPlatform = State.stationPlatform, trainId = State.currentTrain.id, destination = State.currentTrain.dest, + destCode = State.currentTrain.destCode, nextStation = State.currentTrain.nextStation, + nextCode = State.currentTrain.nextCode, + lineCode = State.currentTrain.lineCode, departureBeep = State.departureBeep }) end