From d1e074c1ca0a190fdd6fb11dbb25920e320b0ecb Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Mon, 29 Mar 2021 14:11:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81=EF=BC=8C?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0ws-app=E9=83=A8=E5=88=86=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=BC=BAws-user?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parts/gametoolfunc.lua | 151 +++++++++++++++++++---------------------- 1 file changed, 69 insertions(+), 82 deletions(-) diff --git a/parts/gametoolfunc.lua b/parts/gametoolfunc.lua index aa461149..51046fb6 100644 --- a/parts/gametoolfunc.lua +++ b/parts/gametoolfunc.lua @@ -1087,29 +1087,6 @@ do else LOG.print(text.wsFailed..": "..connErr,"warn") end - - fetchRooms: - if res.message=="OK"then - rooms=res.room_list - else - LOG.print(text.httpCode..response.code..": "..res.message,"warn") - end - - createRoom: - if res.message=="OK"then - LOG.print(text.createRoomSuccessed) - enterRoom(res.room.id) - else - LOG.print(text.httpCode..res.code..": "..res.message,"warn") - end - - enterRoom: - if res.message=="OK"then - loadGame("netBattle",true,true) - LOG.print(text.wsSuccessed,"warn") - else - LOG.print(text.wsFailed..": "..connErr,"warn") - end ]] function TICK_WS_app() @@ -1183,15 +1160,19 @@ do --Get self infos NET.getSelfInfo() - elseif res.action==0 then + elseif res.action==0 then--Get accessToken USER.accessToken=res.accessToken LOG.print(text.accessSuccessed) NET.wsConnectPlay() - elseif res.action==1 then - USER.name=res.username - USER.motto=res.motto - USER.avatar=res.avatar - FILE.save(USER,"conf/user") + 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") + else--Others + LOG.print("Get user info: "..USER.id) + end end else WS.alert("user") @@ -1201,6 +1182,65 @@ do end end end + function TICK_WS_play() + while true do + YIELD() + local status=WS.status("play") + if status=="running"then + local message,op=WS.read("play") + if message then + if op=="ping"then + NET.pong("play",message) + elseif op=="pong"then + elseif op=="close"then + message=JSON.decode(message) + if message then + LOG.print(text.wsClose..message.message,"warn") + end + return + else + local res=JSON.decode(message) + if res then + if res.message=="Connected"then + 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) + elseif res.action==3 then--Leave room + SCN.back() + end + else + WS.alert("play") + end + end + end + end + end + end + function TICK_WS_stream() + while true do + YIELD() + local status=WS.status("stream") + if status=="running"then + local message,op=WS.read("stream") + if message then + if op=="ping"then + NET.pong("stream",message) + elseif op=="pong"then + elseif op=="close"then + message=JSON.decode(message) + if message then + LOG.print(text.wsClose..message.message,"warn") + end + return + else + --TODO + end + end + end + end + end function TICK_WS_chat() while true do YIELD() @@ -1229,57 +1269,4 @@ do end end end - function TICK_WS_play() - while true do - YIELD() - local status=WS.status("play") - if status=="running"then - local message,op=WS.read("play") - if message then - if op=="ping"then - NET.pong("play",message) - elseif op=="pong"then - elseif op=="close"then - message=JSON.decode(message) - if message then - LOG.print(text.wsClose..message.message,"warn") - end - return - else - local res=JSON.decode(message) - if res then - if res.message=="Connected"then - SCN.go("net_menu") - end - else - WS.alert("play") - end - end - end - end - end - end - function TICK_WS_stream() - while true do - YIELD() - local status=WS.status("stream") - if status=="running"then - local message,op=WS.read("stream") - if message then - if op=="ping"then - NET.pong("stream",message) - elseif op=="pong"then - elseif op=="close"then - message=JSON.decode(message) - if message then - LOG.print(text.wsClose..message.message,"warn") - end - return - else - --TODO - end - end - end - end - end end \ No newline at end of file