联网api略微调整,http请求处理规范化
This commit is contained in:
@@ -817,7 +817,7 @@ function TICK_httpREQ_getAccessToken(task)
|
|||||||
if response then
|
if response then
|
||||||
if response.code==200 then
|
if response.code==200 then
|
||||||
local res=json.decode(response.body)
|
local res=json.decode(response.body)
|
||||||
if res then
|
if res.message=="OK"then
|
||||||
LOG.print(text.accessSuccessed)
|
LOG.print(text.accessSuccessed)
|
||||||
USER.access_token=res.access_token
|
USER.access_token=res.access_token
|
||||||
FILE.save(USER,"conf/user")
|
FILE.save(USER,"conf/user")
|
||||||
|
|||||||
@@ -243,10 +243,14 @@ GAME={--Global game data
|
|||||||
--Userdata tables
|
--Userdata tables
|
||||||
RANKS=FILE.load("conf/unlock")or{sprint_10l=0}--Ranks of modes
|
RANKS=FILE.load("conf/unlock")or{sprint_10l=0}--Ranks of modes
|
||||||
USER=FILE.load("conf/user")or{--User infomation
|
USER=FILE.load("conf/user")or{--User infomation
|
||||||
|
--Network infos
|
||||||
|
name=false,
|
||||||
|
id=false,
|
||||||
email=false,
|
email=false,
|
||||||
auth_token=false,
|
auth_token=false,
|
||||||
access_token=false,
|
access_token=false,
|
||||||
|
|
||||||
|
--Local data
|
||||||
username=false,
|
username=false,
|
||||||
motto=false,
|
motto=false,
|
||||||
avatar=false,
|
avatar=false,
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ local function tick_httpREQ_launch(task)
|
|||||||
local response,request_error=client.poll(task)
|
local response,request_error=client.poll(task)
|
||||||
if response then
|
if response then
|
||||||
local res=json.decode(response.body)
|
local res=json.decode(response.body)
|
||||||
if res then
|
if res.message=="OK"then
|
||||||
if response.code==200 then
|
if response.code==200 then
|
||||||
LOG.print(res.notice,360,COLOR.sky)
|
LOG.print(res.notice,360,COLOR.sky)
|
||||||
if VERSION_CODE>=res.version_code then
|
if VERSION_CODE>=res.version_code then
|
||||||
@@ -41,10 +41,12 @@ local function tick_httpREQ_autoLogin(task)
|
|||||||
local response,request_error=client.poll(task)
|
local response,request_error=client.poll(task)
|
||||||
if response then
|
if response then
|
||||||
if response.code==200 then
|
if response.code==200 then
|
||||||
LOGIN=true
|
|
||||||
local res=json.decode(response.body)
|
local res=json.decode(response.body)
|
||||||
if res then
|
if res.message=="OK"then
|
||||||
|
LOGIN=true
|
||||||
LOG.print(text.loginSuccessed)
|
LOG.print(text.loginSuccessed)
|
||||||
|
else
|
||||||
|
LOG.print(text.netErrorCode..response.code..": "..res.message,"warn")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
LOGIN=false
|
LOGIN=false
|
||||||
@@ -213,6 +215,10 @@ function scene.update()
|
|||||||
LOG.print("==============",COLOR.red)
|
LOG.print("==============",COLOR.red)
|
||||||
LOG.print("Merry Christmas!",COLOR.white)
|
LOG.print("Merry Christmas!",COLOR.white)
|
||||||
LOG.print("==============",COLOR.red)
|
LOG.print("==============",COLOR.red)
|
||||||
|
elseif FESTIVAL=="sprFes"then
|
||||||
|
LOG.print("=======",COLOR.red)
|
||||||
|
LOG.print("新年快乐!",COLOR.white)
|
||||||
|
LOG.print("=======",COLOR.red)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if loadTar then
|
if loadTar then
|
||||||
|
|||||||
@@ -4,14 +4,18 @@ local function tick_httpREQ_newLogin(task)
|
|||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
local response,request_error=client.poll(task)
|
local response,request_error=client.poll(task)
|
||||||
if response then
|
if response then
|
||||||
local res=json.decode(response.body)
|
if response.code==200 then
|
||||||
LOGIN=response.code==200
|
local res=json.decode(response.body)
|
||||||
if res then
|
if res.message=="OK"then
|
||||||
if LOGIN then
|
LOGIN=true
|
||||||
LOG.print(text.loginSuccessed)
|
|
||||||
USER.email=res.email
|
USER.email=res.email
|
||||||
USER.auth_token=res.auth_token
|
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")
|
FILE.save(USER,"conf/user","q")
|
||||||
|
LOG.print(text.loginSuccessed)
|
||||||
|
|
||||||
httpRequest(
|
httpRequest(
|
||||||
TICK_httpREQ_getAccessToken,
|
TICK_httpREQ_getAccessToken,
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ local function task_fetchRooms(task)
|
|||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
local response,request_error=client.poll(task)
|
local response,request_error=client.poll(task)
|
||||||
if response then
|
if response then
|
||||||
local res=json.decode(response.body)
|
if response.code==200 then
|
||||||
if res then
|
local res=json.decode(response.body)
|
||||||
if response.code==200 then
|
if res.message=="OK"then
|
||||||
rooms=res.room_list
|
rooms=res.room_list
|
||||||
else
|
else
|
||||||
LOG.print(text.netErrorCode..response.code..": "..res.message,"warn")
|
LOG.print(text.netErrorCode..response.code..": "..res.message,"warn")
|
||||||
|
|||||||
@@ -4,9 +4,15 @@ local function tick_httpREQ_register(task)
|
|||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
local response,request_error=client.poll(task)
|
local response,request_error=client.poll(task)
|
||||||
if response then
|
if response then
|
||||||
local res=json.decode(response.body)
|
if response.code==200 then
|
||||||
if res then
|
local res=json.decode(response.body)
|
||||||
if response.code==200 then
|
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)
|
LOG.print(text.registerSuccessed..": "..res.message)
|
||||||
else
|
else
|
||||||
LOG.print(text.netErrorCode..response.code..": "..res.message,"warn")
|
LOG.print(text.netErrorCode..response.code..": "..res.message,"warn")
|
||||||
|
|||||||
Reference in New Issue
Block a user