From 25ad789e61afc109f7d8a2a742f322948fe823a8 Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Sun, 30 May 2021 16:21:03 +0800 Subject: [PATCH] =?UTF-8?q?console=E6=B7=BB=E5=8A=A0=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E7=9A=84=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zframework/websocket.lua | 9 +++++++++ parts/scenes/app_console.lua | 26 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/Zframework/websocket.lua b/Zframework/websocket.lua index ab36c69e..2cf5af08 100644 --- a/Zframework/websocket.lua +++ b/Zframework/websocket.lua @@ -233,6 +233,15 @@ local wsList=setmetatable({},{ end }) +function WS.switchHost(_1,_2,_3) + for k in next,wsList do + WS.close(k) + end + host=_1 + port=_2 or port + path=_3 or path +end + function WS.connect(name,subPath,body,timeout) local ws={ real=true, diff --git a/parts/scenes/app_console.lua b/parts/scenes/app_console.lua index 73bcf490..5a6ce217 100644 --- a/parts/scenes/app_console.lua +++ b/parts/scenes/app_console.lua @@ -236,6 +236,18 @@ do--commands.help(arg) "Usage: test", }, }, + switchhost={ + description="Switch another host", + details={ + "Disconnect all connections and switch to another host", + "", + "Usage:", + "switchhost [host]", + "switchhost [host] [port]", + "switchhost [host] [port] [path]", + "Example: switchhost 127.0.0.1 26000 /sock", + }, + }, applet={ description="Go to an applet scene", details={ @@ -275,6 +287,7 @@ do--commands.help(arg) "setbg", "theme", "test", + "switchhost", "applet", } function commands.help(arg) @@ -583,6 +596,19 @@ end function commands.test() SCN.go('test','none') end +function commands.switchhost(arg) + arg=STRING.split(arg," ") + if arg[1]and #arg<=3 then + WS.switchHost(unpack(arg)) + log{C.Y,"Host switched"} + else + log{C.A,"Usage:"} + log{C.A,"switchhost [host]"} + log{C.A,"switchhost [host] [port]"} + log{C.A,"switchhost [host] [port] [path]"} + log{C.A,"Example: switchhost 127.0.0.1 26000 /sock"} + end +end do--commands.applet(name) local appList={"15p","grid","pong","atoz","uttt","cube","2048","ten","tap","dtw","cannon","dropper","calc","reflect","polyforge"} local appScene={'app_15p','app_schulteG','app_pong','app_AtoZ','app_UTTT','app_cubefield','app_2048','app_ten','app_tap','app_dtw','app_cannon','app_dropper','app_calc','app_reflect','app_polyforge'}