From 543aed035084b10d30639d779c15f63e5dabacd6 Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Thu, 19 Aug 2021 20:43:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A7=E5=88=B6=E5=8F=B0sudo=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E5=BC=80=E5=90=AF=E5=90=8E=E7=94=A8#=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E5=91=BD=E4=BB=A4=E5=B0=B1=E5=8F=AF=E4=BB=A5=EF=BC=8C?= =?UTF-8?q?=E4=B8=8D=E9=9C=80=E8=A6=81=E4=B8=80=E7=9B=B4=E8=BE=93=E5=85=A5?= =?UTF-8?q?sudo=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parts/scenes/app_console.lua | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/parts/scenes/app_console.lua b/parts/scenes/app_console.lua index 6a0cca2d..ec8e7202 100644 --- a/parts/scenes/app_console.lua +++ b/parts/scenes/app_console.lua @@ -638,24 +638,8 @@ local commands={}do commands.sudo={ code=function(code) if sudomode then - --Filter "" - if #code==0 then log{C.R,"Usage: sudo [Lua code]"}return end - - --Check Syntax error - local func,errmsg=loadstring(code) - if errmsg then log{C.R,errmsg}return end - - --Run code - local success,result=pcall(func) - if success then - if result~=nil then - log{C.lG,">> "..tostring(result)} - else - log{C.lG,"done"} - end - else - log{C.R,result} - end + log{C.Y,"You are already in the sudo mode, use # to run any lua code"} + log{C.Y,"已经进入最高权限模式了, 请使用 # 执行任意lua代码"} elseif code=="7126"then sudomode=true log{C.Y,"* SUDO MODE ON, DO NOT RUN ANY CODE YOU DON'T UNDERSTAND *"} @@ -912,13 +896,19 @@ function scene.keyDown(key) log{C.lC,"> "..input} local code,err=loadstring(input:sub(2)) if code then - setfenv(code,userG) - code,err=pcall(code) - if not code then - log{C.R,"[ERR] ",C.Z,err} + if not sudomode then setfenv(code,userG)end + local success,result=pcall(code) + if success then + if result~=nil then + log{C.lG,">> "..tostring(result)} + else + log{C.lG,"done"} + end + else + log{C.R,result} end else - log{C.R,"[SYNTAX ERR] ",C.Z,err} + log{C.R,"[SyntaxErr] ",C.R,err} end else --Execute builtin command