From d37802185b4828e0e2f7b7e9f89b15bba221dfac Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Mon, 29 Mar 2021 15:16:23 +0800 Subject: [PATCH] =?UTF-8?q?NET=E6=B7=BB=E5=8A=A0=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E9=94=81=E4=BF=9D=E8=AF=81=E4=BB=BB=E5=8A=A1=E5=94=AF=E4=B8=80?= =?UTF-8?q?=EF=BC=8C=E5=BA=94=E7=94=A8=E7=BB=99=E9=83=A8=E5=88=86=E6=93=8D?= =?UTF-8?q?=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parts/gametoolfunc.lua | 6 ++++ parts/net.lua | 62 ++++++++++++++++++++++++++++-------------- 2 files changed, 48 insertions(+), 20 deletions(-) diff --git a/parts/gametoolfunc.lua b/parts/gametoolfunc.lua index 51046fb6..e4475c93 100644 --- a/parts/gametoolfunc.lua +++ b/parts/gametoolfunc.lua @@ -1154,6 +1154,8 @@ do USER.id=res.id USER.authToken=res.authToken NET.getAccessToken() + else + SCN.back() end FILE.save(USER,"conf/user","q") LOG.print(text.loginSuccessed) @@ -1164,12 +1166,14 @@ do USER.accessToken=res.accessToken LOG.print(text.accessSuccessed) NET.wsConnectPlay() + NET.unlock("accessToken") elseif res.action==1 then--Get userInfo if res.id==USER.id then--Own USER.name=res.username USER.motto=res.motto USER.avatar=res.avatar FILE.save(USER,"conf/user") + NET.unlock("getSelfInfo") else--Others LOG.print("Get user info: "..USER.id) end @@ -1202,11 +1206,13 @@ do local res=JSON.decode(message) if res then if res.message=="Connected"then + NET.unlock("connectPlay") SCN.go("net_menu") elseif res.action==0 then--Fetch rooms NET.roomList=res.roomList elseif res.action==2 then--Join room loadGame("netBattle",true,true) + NET.unlock("enterRoom") elseif res.action==3 then--Leave room SCN.back() end diff --git a/parts/net.lua b/parts/net.lua index bd51566e..3883b3c3 100644 --- a/parts/net.lua +++ b/parts/net.lua @@ -5,28 +5,48 @@ local NET={ roomList=false, } +--Lock & Unlock submodule +local locks={} +function NET.lock(name,T) + if locks[name]and TIME()