diff --git a/LANG/lang_en.lua b/LANG/lang_en.lua index 5cf0efd5..6963e8e0 100644 --- a/LANG/lang_en.lua +++ b/LANG/lang_en.lua @@ -68,6 +68,7 @@ return{ registerSuccessed="Registered!", registerFailed="Registration failed", netErrorCode="Network error code", + jsonError="Json error", noUsername="Please enter your username", wrongEmail="Wrong email address", noPassword="Please enter your password", diff --git a/LANG/lang_symbol.lua b/LANG/lang_symbol.lua index 6bf2dec4..88a22550 100644 --- a/LANG/lang_symbol.lua +++ b/LANG/lang_symbol.lua @@ -68,6 +68,7 @@ return{ registerSuccessed="Register successed!", registerFailed="Register failed", netErrorCode="Network error code", + jsonError="Json error", noUsername="Input username", wrongEmail="Wrong email address", noPassword="Input password", diff --git a/LANG/lang_zh.lua b/LANG/lang_zh.lua index 07f951cc..dfe5d287 100644 --- a/LANG/lang_zh.lua +++ b/LANG/lang_zh.lua @@ -68,6 +68,7 @@ return{ registerSuccessed="注册成功!", registerFailed="注册失败", netErrorCode="网络错误码", + jsonError="json错误", noUsername="请填写用户名", wrongEmail="邮箱格式错误", noPassword="请填写密码", diff --git a/Zframework/toolfunc.lua b/Zframework/toolfunc.lua index 88672fd1..36531272 100644 --- a/Zframework/toolfunc.lua +++ b/Zframework/toolfunc.lua @@ -300,7 +300,9 @@ do--json error("unexpected type '" .. t .. "'") end - function json.encode(val) return encode(val) end + function json.encode(val) + return pcall(encode,val) + end ------------------------------------------------------------------------------- -- Decode @@ -516,7 +518,7 @@ do--json decode_error(str, idx, "unexpected character '" .. chr .. "'") end - function json.decode(str) + local function decode(str) if type(str) ~= "string" then error("expected argument of type string, got " .. type(str)) end @@ -525,6 +527,9 @@ do--json if idx <= #str then decode_error(str, idx, "trailing garbage") end return res end + function json.decode(str) + return pcall(decode,str) + end end function copyList(org) local L={} diff --git a/parts/tick.lua b/parts/tick.lua index d5fd8be1..71c72bcf 100644 --- a/parts/tick.lua +++ b/parts/tick.lua @@ -78,12 +78,16 @@ function Tick.httpREQ_launch(data) local res,err=client.poll(data.task) if res then if res.code==200 then - res=json.decode(res.body) - LOG.print(res.notice,360,color.sky) - if gameVersion==res.version then - LOG.print(text.versionIsNew,360,color.sky) + err,res=json.decode(res.body) + if res then + LOG.print(res.notice,360,color.sky) + if gameVersion==res.version then + LOG.print(text.versionIsNew,360,color.sky) + else + LOG.print(string.gsub(text.versionIsOld,"$1",res.version),"warn") + end else - LOG.print(string.gsub(text.versionIsOld,"$1",res.version),"warn") + LOG.print(text.jsonError..": "..err,"warn") end else LOG.print(text.netErrorCode..res.code,"warn") @@ -103,11 +107,15 @@ function Tick.httpREQ_register(data) local res,err=client.poll(data.task) if res then if res.code==200 then - res=json.decode(res.body) - if res.status then - LOG.print(text.registerSuccessed) + err,res=json.decode(res.body) + if res then + if res.status then + LOG.print(text.registerSuccessed) + else + LOG.print(text.registerFailed..": "..res.msg) + end else - LOG.print(text.registerFailed..": "..res.msg) + LOG.print(text.jsonError..": "..err,"warn") end else LOG.print(text.netErrorCode..res.code,"warn")