From c8f4faaa951f09708032b065dcb4cec7a3ba9171 Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Fri, 29 Jan 2021 00:45:35 +0800 Subject: [PATCH] =?UTF-8?q?=E8=81=94=E7=BD=91api=E7=95=A5=E5=BE=AE?= =?UTF-8?q?=E8=B0=83=E6=95=B4=EF=BC=8Chttp=E8=AF=B7=E6=B1=82=E5=A4=84?= =?UTF-8?q?=E7=90=86=E8=A7=84=E8=8C=83=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parts/gametoolfunc.lua | 2 +- parts/globalTables.lua | 4 ++++ parts/scenes/load.lua | 12 +++++++++--- parts/scenes/login.lua | 14 +++++++++----- parts/scenes/net_rooms.lua | 6 +++--- parts/scenes/register.lua | 12 +++++++++--- 6 files changed, 35 insertions(+), 15 deletions(-) diff --git a/parts/gametoolfunc.lua b/parts/gametoolfunc.lua index 0dd51b22..22f81764 100644 --- a/parts/gametoolfunc.lua +++ b/parts/gametoolfunc.lua @@ -817,7 +817,7 @@ function TICK_httpREQ_getAccessToken(task) if response then if response.code==200 then local res=json.decode(response.body) - if res then + if res.message=="OK"then LOG.print(text.accessSuccessed) USER.access_token=res.access_token FILE.save(USER,"conf/user") diff --git a/parts/globalTables.lua b/parts/globalTables.lua index 02e060b5..179e6c21 100644 --- a/parts/globalTables.lua +++ b/parts/globalTables.lua @@ -243,10 +243,14 @@ GAME={--Global game data --Userdata tables RANKS=FILE.load("conf/unlock")or{sprint_10l=0}--Ranks of modes USER=FILE.load("conf/user")or{--User infomation + --Network infos + name=false, + id=false, email=false, auth_token=false, access_token=false, + --Local data username=false, motto=false, avatar=false, diff --git a/parts/scenes/load.lua b/parts/scenes/load.lua index 46160c24..322c42ac 100644 --- a/parts/scenes/load.lua +++ b/parts/scenes/load.lua @@ -10,7 +10,7 @@ local function tick_httpREQ_launch(task) local response,request_error=client.poll(task) if response then local res=json.decode(response.body) - if res then + if res.message=="OK"then if response.code==200 then LOG.print(res.notice,360,COLOR.sky) if VERSION_CODE>=res.version_code then @@ -41,10 +41,12 @@ local function tick_httpREQ_autoLogin(task) local response,request_error=client.poll(task) if response then if response.code==200 then - LOGIN=true local res=json.decode(response.body) - if res then + if res.message=="OK"then + LOGIN=true LOG.print(text.loginSuccessed) + else + LOG.print(text.netErrorCode..response.code..": "..res.message,"warn") end else LOGIN=false @@ -213,6 +215,10 @@ function scene.update() LOG.print("==============",COLOR.red) LOG.print("Merry Christmas!",COLOR.white) LOG.print("==============",COLOR.red) + elseif FESTIVAL=="sprFes"then + LOG.print("=======",COLOR.red) + LOG.print("新年快乐!",COLOR.white) + LOG.print("=======",COLOR.red) end end if loadTar then diff --git a/parts/scenes/login.lua b/parts/scenes/login.lua index 975e9229..d0a2bad8 100644 --- a/parts/scenes/login.lua +++ b/parts/scenes/login.lua @@ -4,14 +4,18 @@ local function tick_httpREQ_newLogin(task) coroutine.yield() local response,request_error=client.poll(task) if response then - local res=json.decode(response.body) - LOGIN=response.code==200 - if res then - if LOGIN then - LOG.print(text.loginSuccessed) + if response.code==200 then + local res=json.decode(response.body) + if res.message=="OK"then + LOGIN=true USER.email=res.email USER.auth_token=res.auth_token + USER.name=res.name + USER.id=res.id + USER.motto=res.motto + USER.avatar=res.avatar FILE.save(USER,"conf/user","q") + LOG.print(text.loginSuccessed) httpRequest( TICK_httpREQ_getAccessToken, diff --git a/parts/scenes/net_rooms.lua b/parts/scenes/net_rooms.lua index 60ac279d..1578de98 100644 --- a/parts/scenes/net_rooms.lua +++ b/parts/scenes/net_rooms.lua @@ -11,9 +11,9 @@ local function task_fetchRooms(task) coroutine.yield() local response,request_error=client.poll(task) if response then - local res=json.decode(response.body) - if res then - if response.code==200 then + if response.code==200 then + local res=json.decode(response.body) + if res.message=="OK"then rooms=res.room_list else LOG.print(text.netErrorCode..response.code..": "..res.message,"warn") diff --git a/parts/scenes/register.lua b/parts/scenes/register.lua index fdc63996..155de174 100644 --- a/parts/scenes/register.lua +++ b/parts/scenes/register.lua @@ -4,9 +4,15 @@ local function tick_httpREQ_register(task) coroutine.yield() local response,request_error=client.poll(task) if response then - local res=json.decode(response.body) - if res then - if response.code==200 then + if response.code==200 then + local res=json.decode(response.body) + if res.message=="OK"then + LOGIN=true + USER.name=res.name + USER.id=res.id + USER.motto=res.motto + USER.avatar=res.avatar + FILE.save(USER,"conf/user","q") LOG.print(text.registerSuccessed..": "..res.message) else LOG.print(text.netErrorCode..response.code..": "..res.message,"warn")