From 9de9048a78653e8d86d96fb214eb23a68c722836 Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Sat, 24 Apr 2021 16:11:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E8=AE=A4=E5=AE=9A?= =?UTF-8?q?=E5=85=A8=E5=91=98=E5=87=86=E5=A4=87=E4=B8=89=E7=A7=92=E5=90=8E?= =?UTF-8?q?=E5=8F=96=E6=B6=88=E5=87=86=E5=A4=87=E6=8C=89=E9=92=AE=E6=B6=88?= =?UTF-8?q?=E5=A4=B1=EF=BC=8C=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parts/net.lua | 13 +++++++++---- parts/scenes/net_game.lua | 10 ++++------ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/parts/net.lua b/parts/net.lua index 90541bd9..92d89a3c 100644 --- a/parts/net.lua +++ b/parts/net.lua @@ -4,6 +4,7 @@ local WS,TIME=WS,TIME local NET={ connected=false, allow_online=false, + serverGaming=false, roomList={}, accessToken=false, rid=false, @@ -101,11 +102,13 @@ function NET.wsconn_play() end function NET.wsconn_stream() if NET.lock("wsc_stream",5)then + NET.serverGaming=true WS.connect("stream","/stream",JSON.encode{ uid=USER.uid, accessToken=NET.accessToken, rid=NET.rsid, }) + TASK.new(NET.updateWS_stream) end end @@ -113,7 +116,10 @@ end function NET.wsclose_app()WS.close("app")end function NET.wsclose_user()WS.close("user")end function NET.wsclose_play()WS.close("play")end -function NET.wsclose_stream()WS.close("stream")end +function NET.wsclose_stream() + NET.serverGaming=false + WS.close("stream") +end --Account & User function NET.register(username,email,password) @@ -192,7 +198,7 @@ function NET.checkPlayDisconn() return WS.status("play")~="running" end function NET.signal_ready(ready) - if NET.lock("ready",3)then + if NET.lock("ready",3)and not NET.serverGaming then WS.send("play",'{"action":6,"data":{"ready":'..tostring(ready)..'}}') end end @@ -421,12 +427,11 @@ function NET.updateWS_play() break end end - elseif res.action==7 then--Ready + elseif res.action==7 then--All Ready SFX.play("reach",.6) elseif res.action==8 then--Set NET.rsid=d.rid NET.wsconn_stream() - TASK.new(NET.updateWS_stream) elseif res.action==9 then--Game finished NET.wsclose_stream() if SCN.socketRead then SCN.socketRead("Finish",d)end diff --git a/parts/scenes/net_game.lua b/parts/scenes/net_game.lua index 97cd54b9..4b1f0a3d 100644 --- a/parts/scenes/net_game.lua +++ b/parts/scenes/net_game.lua @@ -1,10 +1,6 @@ -local gc=love.graphics -local tc=love.touch - +local gc,tc=love.graphics,love.touch local ins=table.insert - -local SCR=SCR -local VK=VK +local SCR,VK,NET=SCR,VK,NET local textBox=WIDGET.newTextBox{name="texts",x=340,y=80,w=600,h=550,hide=false} @@ -275,6 +271,7 @@ scene.widgetList={ hide=function() return playing or + NET.serverGaming or not textBox.hide or PLY_NET[1].ready or NET.getlock("ready") @@ -283,6 +280,7 @@ scene.widgetList={ hide=function() return playing or + NET.serverGaming or not textBox.hide or not PLY_NET[1].ready or NET.getlock("ready")