From a73aa8b4617a8dfab76f26395cc17979abb088aa Mon Sep 17 00:00:00 2001 From: wancat Date: Tue, 8 Aug 2023 18:30:59 +0800 Subject: [PATCH] fix: prevent execute command twice --- server/quests/helloworld/home/.zshrc | 4 ++-- server/src/game/commandHandler.js | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/server/quests/helloworld/home/.zshrc b/server/quests/helloworld/home/.zshrc index 9369e80..d8275fd 100644 --- a/server/quests/helloworld/home/.zshrc +++ b/server/quests/helloworld/home/.zshrc @@ -15,10 +15,10 @@ preexec() { # Check if the command is in the list of interactive commands if [[ " ${interactive_commands[@]} " =~ " $1 " ]]; then # If it is, just execute it normally - eval $1 + exec else # If it's not, execute it and redirect its output to a file - eval $1 > /tmp/cmd.out 2>/tmp/cmd.error + exec > >(tee /tmp/cmd.out) 2> >(tee /tmp/cmd.error >&2) fi } diff --git a/server/src/game/commandHandler.js b/server/src/game/commandHandler.js index ca99dff..d2ce5f0 100644 --- a/server/src/game/commandHandler.js +++ b/server/src/game/commandHandler.js @@ -17,14 +17,10 @@ const commandHandler = async (session, commandInput) => { return {} } - console.log(stage.condition) - const commandMatch = checkMatch(stage.condition.command, commandInput.command) const outputMatch = checkMatch(stage.condition.output, commandInput.output) const errorMatch = checkMatch(stage.condition.error, commandInput.output) - console.log(commandMatch, outputMatch, errorMatch) - if (!commandMatch || !outputMatch || !errorMatch) return {} session.completion.push(session.progress)