再次整理/简化网络请求相关代码
This commit is contained in:
@@ -816,26 +816,17 @@ function TICK_httpREQ_getAccessToken(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
|
||||||
if response.code==200 then
|
local res=json.decode(response.body)
|
||||||
local res=json.decode(response.body)
|
if response.code==200 and res.message=="OK"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")
|
SCN.swapTo("net_menu")
|
||||||
SCN.swapTo("net_menu")
|
|
||||||
else
|
|
||||||
LOG.print(text.netErrorCode..response.code..": "..res.message,"warn")
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
LOGIN=false
|
LOGIN=false
|
||||||
USER.access_token=false
|
USER.access_token=false
|
||||||
USER.auth_token=false
|
USER.auth_token=false
|
||||||
local err=json.decode(response.body)
|
LOG.print(text.loginFailed..": "..text.httpCode..response.code.."-"..res.message,"warn")
|
||||||
if err then
|
|
||||||
LOG.print(text.loginFailed..": "..text.netErrorCode..response.code.."-"..err.message,"warn")
|
|
||||||
else
|
|
||||||
LOG.print(text.loginFailed..": "..text.netErrorCode,"warn")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
elseif request_error then
|
elseif request_error then
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ return{
|
|||||||
versionIsNew="You are now on the latest version.",
|
versionIsNew="You are now on the latest version.",
|
||||||
versionIsOld="Version $1 is available now!",
|
versionIsOld="Version $1 is available now!",
|
||||||
|
|
||||||
netErrorCode="Network error code",
|
httpCode="Http status code",
|
||||||
jsonError="Json error",
|
jsonError="Json error",
|
||||||
|
|
||||||
noUsername="Please enter your username",
|
noUsername="Please enter your username",
|
||||||
@@ -101,6 +101,7 @@ return{
|
|||||||
chatHistory="------New messages below------",
|
chatHistory="------New messages below------",
|
||||||
|
|
||||||
noRooms="No Rooms Now",
|
noRooms="No Rooms Now",
|
||||||
|
roomsCreateFailed="Failed to create room",
|
||||||
roomsFetchFailed="Failed to fetch rooms",
|
roomsFetchFailed="Failed to fetch rooms",
|
||||||
|
|
||||||
errorMsg="An error has occurred and Techmino needs to restart.\nError info has been created, and you can send it to the author.",
|
errorMsg="An error has occurred and Techmino needs to restart.\nError info has been created, and you can send it to the author.",
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ return{
|
|||||||
versionIsNew="Vous êtes sur la dernière version",
|
versionIsNew="Vous êtes sur la dernière version",
|
||||||
versionIsOld="La version $1 est disponible !",
|
versionIsOld="La version $1 est disponible !",
|
||||||
|
|
||||||
netErrorCode="Code d'erreur réseau",
|
-- httpCode="Http status code",
|
||||||
jsonError="Erreur json",
|
jsonError="Erreur json",
|
||||||
|
|
||||||
noUsername="Entrez votre nom d'utilisateur",
|
noUsername="Entrez votre nom d'utilisateur",
|
||||||
@@ -103,6 +103,7 @@ return{
|
|||||||
-- chatHistory="------New messages below------",
|
-- chatHistory="------New messages below------",
|
||||||
|
|
||||||
-- noRooms="No Rooms Now",
|
-- noRooms="No Rooms Now",
|
||||||
|
-- roomsCreateFailed="Failed to create room",
|
||||||
-- roomsFetchFailed="Failed to fetch rooms",
|
-- roomsFetchFailed="Failed to fetch rooms",
|
||||||
|
|
||||||
errorMsg="Une erreur est survenue et Techmino doit redémarrer.\nDes informations concernant l'erreur ont été créées, et vous pouvez les envoyer au créateur.",
|
errorMsg="Une erreur est survenue et Techmino doit redémarrer.\nDes informations concernant l'erreur ont été créées, et vous pouvez les envoyer au créateur.",
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ return{
|
|||||||
versionIsNew="Você esta na versão mais nova.",
|
versionIsNew="Você esta na versão mais nova.",
|
||||||
versionIsOld="Versão $1 esta disponível agora!",
|
versionIsOld="Versão $1 esta disponível agora!",
|
||||||
|
|
||||||
netErrorCode="Network error code",
|
-- httpCode="Http status code",
|
||||||
jsonError="Json error",
|
jsonError="Json error",
|
||||||
|
|
||||||
noUsername="Insira seu nome de usuário",
|
noUsername="Insira seu nome de usuário",
|
||||||
@@ -101,6 +101,7 @@ return{
|
|||||||
chatHistory="------Novas mensagens abaixo------",
|
chatHistory="------Novas mensagens abaixo------",
|
||||||
|
|
||||||
noRooms="Nenhuma sala agora",
|
noRooms="Nenhuma sala agora",
|
||||||
|
-- roomsCreateFailed="Failed to create room",
|
||||||
roomsFetchFailed="Falha ao buscar salas",
|
roomsFetchFailed="Falha ao buscar salas",
|
||||||
|
|
||||||
errorMsg="Um erro ocorreu e Techmino precisa reiniciar.\nInformação do erro foi criada, e você pode mandar ao autor.",
|
errorMsg="Um erro ocorreu e Techmino precisa reiniciar.\nInformação do erro foi criada, e você pode mandar ao autor.",
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ return{
|
|||||||
versionIsNew="Esta es la versión más reciente disponible.",
|
versionIsNew="Esta es la versión más reciente disponible.",
|
||||||
versionIsOld="¡Está disponible la nueva versión $1!",
|
versionIsOld="¡Está disponible la nueva versión $1!",
|
||||||
|
|
||||||
netErrorCode="Código de error de conexión",
|
-- httpCode="Http status code",
|
||||||
-- jsonError="Json error",
|
-- jsonError="Json error",
|
||||||
|
|
||||||
noUsername="Por favor ingresa un nombre de usuario",
|
noUsername="Por favor ingresa un nombre de usuario",
|
||||||
@@ -104,6 +104,7 @@ return{
|
|||||||
-- chatHistory="------New messages below------",
|
-- chatHistory="------New messages below------",
|
||||||
|
|
||||||
-- noRooms="No Rooms Now",
|
-- noRooms="No Rooms Now",
|
||||||
|
-- roomsCreateFailed="Failed to create room",
|
||||||
-- roomsFetchFailed="Failed to fetch rooms",
|
-- roomsFetchFailed="Failed to fetch rooms",
|
||||||
|
|
||||||
errorMsg="Ha ocurrido un error y Techmino necesita reiniciarse.\nSe creó un registro de error, puedes enviarlo al autor.",
|
errorMsg="Ha ocurrido un error y Techmino necesita reiniciarse.\nSe creó un registro de error, puedes enviarlo al autor.",
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ return{
|
|||||||
versionIsNew="游戏已是最新版本",
|
versionIsNew="游戏已是最新版本",
|
||||||
versionIsOld="最新版本$1可以下载了!",
|
versionIsOld="最新版本$1可以下载了!",
|
||||||
|
|
||||||
netErrorCode="网络错误码",
|
httpCode="Http码",
|
||||||
jsonError="json错误",
|
jsonError="json错误",
|
||||||
|
|
||||||
noUsername="请填写用户名",
|
noUsername="请填写用户名",
|
||||||
@@ -102,6 +102,7 @@ return{
|
|||||||
chatHistory="------以上是历史消息------",
|
chatHistory="------以上是历史消息------",
|
||||||
|
|
||||||
noRooms="一个房间都没有哎...",
|
noRooms="一个房间都没有哎...",
|
||||||
|
roomsCreateFailed="创建房间失败",
|
||||||
roomsFetchFailed="拉取房间列表失败",
|
roomsFetchFailed="拉取房间列表失败",
|
||||||
|
|
||||||
errorMsg="Techmino遭受了雷击,需要重新启动.\n我们已收集了一些错误信息,你可以向作者进行反馈.",
|
errorMsg="Techmino遭受了雷击,需要重新启动.\n我们已收集了一些错误信息,你可以向作者进行反馈.",
|
||||||
|
|||||||
@@ -10,17 +10,15 @@ 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.message=="OK"then
|
if res.message=="OK"and 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
|
LOG.print(text.versionIsNew,360,COLOR.sky)
|
||||||
LOG.print(text.versionIsNew,360,COLOR.sky)
|
|
||||||
else
|
|
||||||
LOG.print(string.gsub(text.versionIsOld,"$1",res.version_name),"warn")
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
LOG.print(text.netErrorCode..response.code..": "..res.message,"warn")
|
LOG.print(string.gsub(text.versionIsOld,"$1",res.version_name),"warn")
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
LOG.print(text.httpCode..response.code..": "..res.message,"warn")
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
elseif request_error then
|
elseif request_error then
|
||||||
@@ -40,20 +38,13 @@ local function tick_httpREQ_autoLogin(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
|
||||||
if response.code==200 then
|
local res=json.decode(response.body)
|
||||||
local res=json.decode(response.body)
|
if response.code==200 and res.message=="OK"then
|
||||||
if res.message=="OK"then
|
LOGIN=true
|
||||||
LOGIN=true
|
LOG.print(text.loginSuccessed)
|
||||||
LOG.print(text.loginSuccessed)
|
|
||||||
else
|
|
||||||
LOG.print(text.netErrorCode..response.code..": "..res.message,"warn")
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
LOGIN=false
|
LOGIN=false
|
||||||
local err=json.decode(response.body)
|
LOG.print(text.loginFailed..": "..text.httpCode..response.code.."-"..res.message,"warn")
|
||||||
if err then
|
|
||||||
LOG.print(text.loginFailed..": "..text.netErrorCode..response.code.."-"..err.message,"warn")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
elseif request_error then
|
elseif request_error then
|
||||||
|
|||||||
@@ -4,32 +4,30 @@ 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
|
||||||
if response.code==200 then
|
local res=json.decode(response.body)
|
||||||
local res=json.decode(response.body)
|
if response.code==200 and res.message=="OK"then
|
||||||
if res.message=="OK"then
|
LOGIN=true
|
||||||
LOGIN=true
|
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.name=res.name
|
USER.id=res.id
|
||||||
USER.id=res.id
|
USER.motto=res.motto
|
||||||
USER.motto=res.motto
|
USER.avatar=res.avatar
|
||||||
USER.avatar=res.avatar
|
FILE.save(USER,"conf/user","q")
|
||||||
FILE.save(USER,"conf/user","q")
|
LOG.print(text.loginSuccessed)
|
||||||
LOG.print(text.loginSuccessed)
|
|
||||||
|
|
||||||
httpRequest(
|
httpRequest(
|
||||||
TICK_httpREQ_getAccessToken,
|
TICK_httpREQ_getAccessToken,
|
||||||
PATH.api..PATH.access,
|
PATH.api..PATH.access,
|
||||||
"POST",
|
"POST",
|
||||||
{["Content-Type"]="application/json"},
|
{["Content-Type"]="application/json"},
|
||||||
json.encode{
|
json.encode{
|
||||||
email=USER.email,
|
email=USER.email,
|
||||||
auth_token=USER.auth_token,
|
auth_token=USER.auth_token,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
LOG.print(text.netErrorCode..response.code..": "..res.message,"warn")
|
LOG.print(text.httpCode..response.code..": "..res.message,"warn")
|
||||||
end
|
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
elseif request_error then
|
elseif request_error then
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
local gc=love.graphics
|
local gc=love.graphics
|
||||||
|
|
||||||
local function tick_httpREQ_checkAccessToken(task)
|
local function tick_httpREQ_manualAutoLogin(task)
|
||||||
local time=0
|
local time=0
|
||||||
while true do
|
while true do
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
@@ -23,7 +23,7 @@ local function tick_httpREQ_checkAccessToken(task)
|
|||||||
else
|
else
|
||||||
local err=json.decode(response.body)
|
local err=json.decode(response.body)
|
||||||
if err then
|
if err then
|
||||||
LOG.print(text.netErrorCode..response.code..": "..err.message,"warn")
|
LOG.print(text.httpCode..response.code..": "..err.message,"warn")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
@@ -111,7 +111,7 @@ scene.widgetList={
|
|||||||
if LOGIN then
|
if LOGIN then
|
||||||
if USER.access_token then
|
if USER.access_token then
|
||||||
httpRequest(
|
httpRequest(
|
||||||
tick_httpREQ_checkAccessToken,
|
tick_httpREQ_manualAutoLogin,
|
||||||
PATH.api..PATH.access,
|
PATH.api..PATH.access,
|
||||||
"GET",
|
"GET",
|
||||||
{["Content-Type"]="application/json"},
|
{["Content-Type"]="application/json"},
|
||||||
|
|||||||
@@ -11,13 +11,11 @@ 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
|
||||||
if response.code==200 then
|
local res=json.decode(response.body)
|
||||||
local res=json.decode(response.body)
|
if response.code==200 and res.message=="OK"then
|
||||||
if res.message=="OK"then
|
rooms=res.room_list
|
||||||
rooms=res.room_list
|
else
|
||||||
else
|
LOG.print(text.httpCode..response.code..": "..res.message,"warn")
|
||||||
LOG.print(text.netErrorCode..response.code..": "..res.message,"warn")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
elseif request_error then
|
elseif request_error then
|
||||||
|
|||||||
@@ -4,19 +4,17 @@ 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
|
||||||
if response.code==200 then
|
local res=json.decode(response.body)
|
||||||
local res=json.decode(response.body)
|
if response.code==200 and res.message=="OK"then
|
||||||
if res.message=="OK"then
|
LOGIN=true
|
||||||
LOGIN=true
|
USER.name=res.name
|
||||||
USER.name=res.name
|
USER.id=res.id
|
||||||
USER.id=res.id
|
USER.motto=res.motto
|
||||||
USER.motto=res.motto
|
USER.avatar=res.avatar
|
||||||
USER.avatar=res.avatar
|
FILE.save(USER,"conf/user","q")
|
||||||
FILE.save(USER,"conf/user","q")
|
LOG.print(text.registerSuccessed..": "..res.message)
|
||||||
LOG.print(text.registerSuccessed..": "..res.message)
|
else
|
||||||
else
|
LOG.print(text.httpCode..response.code..": "..res.message,"warn")
|
||||||
LOG.print(text.netErrorCode..response.code..": "..res.message,"warn")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
elseif request_error then
|
elseif request_error then
|
||||||
|
|||||||
Reference in New Issue
Block a user