Change network functions
This commit is contained in:
@@ -282,6 +282,16 @@ SETTING={
|
||||
VKAlpha=.3,
|
||||
}
|
||||
|
||||
ACCOUNT={
|
||||
email=nil,
|
||||
auth_token=nil,
|
||||
access_token=nil,
|
||||
|
||||
username=nil,
|
||||
motto=nil,
|
||||
avatar=nil,
|
||||
}
|
||||
|
||||
STAT={
|
||||
version=VERSION_NAME,
|
||||
run=0,game=0,time=0,
|
||||
|
||||
@@ -117,6 +117,23 @@ function Tmr.load()
|
||||
SFX.play("welcome_sfx")
|
||||
VOC.play("welcome_voc")
|
||||
httpRequest(TICK.httpREQ_launch,"/tech/api/v1/app/info")
|
||||
if ACCOUNT.auth_token then
|
||||
local success,data=json.encode({
|
||||
email=ACCOUNT.email,
|
||||
auth_token=ACCOUNT.auth_token,
|
||||
})
|
||||
if not success then
|
||||
LOG.print(text.jsonError,"warn")
|
||||
else
|
||||
httpRequest(
|
||||
TICK.httpREQ_autoLogin,
|
||||
"/tech/api/v1/users",
|
||||
"GET",
|
||||
{["Content-Type"]="application/json"},
|
||||
data
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
if S.tar then
|
||||
S.cur=S.cur+1
|
||||
|
||||
@@ -16,7 +16,7 @@ function keyDown.login(key)
|
||||
return
|
||||
end
|
||||
httpRequest(
|
||||
TICK.httpREQ_login,
|
||||
TICK.httpREQ_newLogin,
|
||||
"/tech/api/v1/users",
|
||||
"GET",
|
||||
{["Content-Type"]="application/json"},
|
||||
|
||||
@@ -149,20 +149,54 @@ function Tick.httpREQ_register(data)
|
||||
return true
|
||||
end
|
||||
end
|
||||
function Tick.httpREQ_login(data)
|
||||
function Tick.httpREQ_newLogin(data)
|
||||
local response,request_error=client.poll(data.task)
|
||||
if response then
|
||||
if response.code==200 then
|
||||
LOGIN=true
|
||||
local success,content=json.decode(response.body)
|
||||
if success then
|
||||
LOG.print(text.loginSuccessed..": "..content.message)
|
||||
ACCOUNT.username=content.username
|
||||
local _success,_content=json.decode(data)
|
||||
ACCOUNT.email=_content.email
|
||||
ACCOUNT.auth_token=content.auth_token
|
||||
FILE.saveAccount()
|
||||
FILE.save(ACCOUNT,"account","")
|
||||
else
|
||||
LOG.print(text.jsonError,"warn")
|
||||
end
|
||||
else
|
||||
LOGIN=false
|
||||
local success,content=json.decode(response.body)
|
||||
if success then
|
||||
LOG.print(text.netErrorCode..response.code..": "..content.message,"warn")
|
||||
else
|
||||
LOG.print(text.netErrorCode..response.code,"warn")
|
||||
end
|
||||
end
|
||||
return true
|
||||
elseif request_error then
|
||||
LOG.print(text.registerFailed..": "..request_error,"warn")
|
||||
return true
|
||||
end
|
||||
data.time=data.time+1
|
||||
if data.time==360 then
|
||||
LOG.print(text.httpTimeout,"message")
|
||||
return true
|
||||
end
|
||||
end
|
||||
function Tick.httpREQ_autoLogin(data)
|
||||
local response,request_error=client.poll(data.task)
|
||||
if response then
|
||||
if response.code==200 then
|
||||
LOGIN=true
|
||||
local success,content=json.decode(response.body)
|
||||
if success then
|
||||
LOG.print(text.loginSuccessed..": "..content.message)
|
||||
else
|
||||
LOG.print(text.jsonError,"warn")
|
||||
end
|
||||
else
|
||||
LOGIN=false
|
||||
local success,content=json.decode(response.body)
|
||||
if success then
|
||||
LOG.print(text.netErrorCode..response.code..": "..content.message,"warn")
|
||||
|
||||
Reference in New Issue
Block a user