魔改json库,最后套一层pcall防止致命错误
This commit is contained in:
@@ -68,6 +68,7 @@ return{
|
|||||||
registerSuccessed="Registered!",
|
registerSuccessed="Registered!",
|
||||||
registerFailed="Registration failed",
|
registerFailed="Registration failed",
|
||||||
netErrorCode="Network error code",
|
netErrorCode="Network error code",
|
||||||
|
jsonError="Json error",
|
||||||
noUsername="Please enter your username",
|
noUsername="Please enter your username",
|
||||||
wrongEmail="Wrong email address",
|
wrongEmail="Wrong email address",
|
||||||
noPassword="Please enter your password",
|
noPassword="Please enter your password",
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ return{
|
|||||||
registerSuccessed="Register successed!",
|
registerSuccessed="Register successed!",
|
||||||
registerFailed="Register failed",
|
registerFailed="Register failed",
|
||||||
netErrorCode="Network error code",
|
netErrorCode="Network error code",
|
||||||
|
jsonError="Json error",
|
||||||
noUsername="Input username",
|
noUsername="Input username",
|
||||||
wrongEmail="Wrong email address",
|
wrongEmail="Wrong email address",
|
||||||
noPassword="Input password",
|
noPassword="Input password",
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ return{
|
|||||||
registerSuccessed="注册成功!",
|
registerSuccessed="注册成功!",
|
||||||
registerFailed="注册失败",
|
registerFailed="注册失败",
|
||||||
netErrorCode="网络错误码",
|
netErrorCode="网络错误码",
|
||||||
|
jsonError="json错误",
|
||||||
noUsername="请填写用户名",
|
noUsername="请填写用户名",
|
||||||
wrongEmail="邮箱格式错误",
|
wrongEmail="邮箱格式错误",
|
||||||
noPassword="请填写密码",
|
noPassword="请填写密码",
|
||||||
|
|||||||
@@ -300,7 +300,9 @@ do--json
|
|||||||
error("unexpected type '" .. t .. "'")
|
error("unexpected type '" .. t .. "'")
|
||||||
end
|
end
|
||||||
|
|
||||||
function json.encode(val) return encode(val) end
|
function json.encode(val)
|
||||||
|
return pcall(encode,val)
|
||||||
|
end
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
-- Decode
|
-- Decode
|
||||||
@@ -516,7 +518,7 @@ do--json
|
|||||||
decode_error(str, idx, "unexpected character '" .. chr .. "'")
|
decode_error(str, idx, "unexpected character '" .. chr .. "'")
|
||||||
end
|
end
|
||||||
|
|
||||||
function json.decode(str)
|
local function decode(str)
|
||||||
if type(str) ~= "string" then
|
if type(str) ~= "string" then
|
||||||
error("expected argument of type string, got " .. type(str))
|
error("expected argument of type string, got " .. type(str))
|
||||||
end
|
end
|
||||||
@@ -525,6 +527,9 @@ do--json
|
|||||||
if idx <= #str then decode_error(str, idx, "trailing garbage") end
|
if idx <= #str then decode_error(str, idx, "trailing garbage") end
|
||||||
return res
|
return res
|
||||||
end
|
end
|
||||||
|
function json.decode(str)
|
||||||
|
return pcall(decode,str)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
function copyList(org)
|
function copyList(org)
|
||||||
local L={}
|
local L={}
|
||||||
|
|||||||
@@ -78,13 +78,17 @@ function Tick.httpREQ_launch(data)
|
|||||||
local res,err=client.poll(data.task)
|
local res,err=client.poll(data.task)
|
||||||
if res then
|
if res then
|
||||||
if res.code==200 then
|
if res.code==200 then
|
||||||
res=json.decode(res.body)
|
err,res=json.decode(res.body)
|
||||||
|
if res then
|
||||||
LOG.print(res.notice,360,color.sky)
|
LOG.print(res.notice,360,color.sky)
|
||||||
if gameVersion==res.version then
|
if gameVersion==res.version then
|
||||||
LOG.print(text.versionIsNew,360,color.sky)
|
LOG.print(text.versionIsNew,360,color.sky)
|
||||||
else
|
else
|
||||||
LOG.print(string.gsub(text.versionIsOld,"$1",res.version),"warn")
|
LOG.print(string.gsub(text.versionIsOld,"$1",res.version),"warn")
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
LOG.print(text.jsonError..": "..err,"warn")
|
||||||
|
end
|
||||||
else
|
else
|
||||||
LOG.print(text.netErrorCode..res.code,"warn")
|
LOG.print(text.netErrorCode..res.code,"warn")
|
||||||
end
|
end
|
||||||
@@ -103,12 +107,16 @@ function Tick.httpREQ_register(data)
|
|||||||
local res,err=client.poll(data.task)
|
local res,err=client.poll(data.task)
|
||||||
if res then
|
if res then
|
||||||
if res.code==200 then
|
if res.code==200 then
|
||||||
res=json.decode(res.body)
|
err,res=json.decode(res.body)
|
||||||
|
if res then
|
||||||
if res.status then
|
if res.status then
|
||||||
LOG.print(text.registerSuccessed)
|
LOG.print(text.registerSuccessed)
|
||||||
else
|
else
|
||||||
LOG.print(text.registerFailed..": "..res.msg)
|
LOG.print(text.registerFailed..": "..res.msg)
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
LOG.print(text.jsonError..": "..err,"warn")
|
||||||
|
end
|
||||||
else
|
else
|
||||||
LOG.print(text.netErrorCode..res.code,"warn")
|
LOG.print(text.netErrorCode..res.code,"warn")
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user