【不能用】继续改联网,能登录了
框架跟进
This commit is contained in:
Submodule Zframework updated: d2ba89b7fc...e89e97ef90
@@ -574,12 +574,24 @@ do--Game data tables
|
|||||||
REPLAY={}--Replay objects (not include stream data)
|
REPLAY={}--Replay objects (not include stream data)
|
||||||
end
|
end
|
||||||
do--Userdata tables
|
do--Userdata tables
|
||||||
USER={--User infomation
|
USER=setmetatable({--User infomation
|
||||||
email=false,
|
__data={
|
||||||
password=false,
|
email=false,
|
||||||
rToken=false,
|
password=false,
|
||||||
aToken=false,
|
rToken=false,
|
||||||
}
|
aToken=false,
|
||||||
|
},
|
||||||
|
},{
|
||||||
|
__index=function(self,k)
|
||||||
|
return self.__data[k]
|
||||||
|
end,
|
||||||
|
__newindex=function(self,k,v)
|
||||||
|
if self.__data[k]~=nil and v~=nil then
|
||||||
|
self.__data[k]=v
|
||||||
|
saveFile(USER.__data,'conf/user')
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
SETTING={--Settings
|
SETTING={--Settings
|
||||||
--Tuning
|
--Tuning
|
||||||
das=10,arr=2,
|
das=10,arr=2,
|
||||||
|
|||||||
@@ -68,8 +68,11 @@ local function getMsg(request,timeout)
|
|||||||
while true do
|
while true do
|
||||||
local mes=HTTP.pollMsg(request.pool)
|
local mes=HTTP.pollMsg(request.pool)
|
||||||
if mes then
|
if mes then
|
||||||
if type(mes.body)=='string' then
|
if type(mes.body)=='string' and #mes.body>0 then
|
||||||
return JSON.decode(mes.body)
|
return JSON.decode(mes.body)
|
||||||
|
else
|
||||||
|
MES.new('info',"Oops! Server is down")
|
||||||
|
return
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
totalTime=totalTime+coroutine.yield()
|
totalTime=totalTime+coroutine.yield()
|
||||||
@@ -97,7 +100,7 @@ function NET.getCode(email)
|
|||||||
MES.new('error',res.message,5)
|
MES.new('error',res.message,5)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
MES.new('error',"Time out",5)
|
MES.new('warn',"Request failed",5)
|
||||||
end
|
end
|
||||||
|
|
||||||
WAIT.interrupt()
|
WAIT.interrupt()
|
||||||
@@ -127,17 +130,17 @@ function NET.codeLogin(code)
|
|||||||
USER.rToken=res.refreshToken
|
USER.rToken=res.refreshToken
|
||||||
USER.aToken=res.accessToken
|
USER.aToken=res.accessToken
|
||||||
-- TODO: connect WS
|
-- TODO: connect WS
|
||||||
SCN.go('net_game')
|
SCN.pop()SCN.go('net_menu')
|
||||||
elseif res.code==201 then
|
elseif res.code==201 then
|
||||||
USER.rToken=res.refreshToken
|
USER.rToken=res.refreshToken
|
||||||
USER.aToken=res.accessToken
|
USER.aToken=res.accessToken
|
||||||
SCN.fileDropped(3)-- Not designed for this, but it works and no side effects
|
SCN.pop()SCN.push('net_menu')
|
||||||
MES.new('info',"Please set your password",5)
|
SCN.fileDropped(3)
|
||||||
else
|
else
|
||||||
MES.new('error',res.message,5)
|
MES.new('error',res.message,5)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
MES.new('error',"Time out",5)
|
MES.new('warn',"Request failed",5)
|
||||||
end
|
end
|
||||||
|
|
||||||
WAIT.interrupt()
|
WAIT.interrupt()
|
||||||
@@ -168,13 +171,14 @@ function NET.setPW(code,pw)
|
|||||||
|
|
||||||
if res then
|
if res then
|
||||||
if res.code==200 then
|
if res.code==200 then
|
||||||
SCN.back()
|
USER.password=pw
|
||||||
MES.new('info',"Password set! Now you can login",5)
|
MES.new('info',"Password set! Now you can login",5)
|
||||||
|
SCN.back()
|
||||||
else
|
else
|
||||||
MES.new('error',res.message,5)
|
MES.new('error',res.message,5)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
MES.new('error',"Time out",5)
|
MES.new('warn',"Request failed",5)
|
||||||
end
|
end
|
||||||
|
|
||||||
WAIT.interrupt()
|
WAIT.interrupt()
|
||||||
@@ -204,11 +208,11 @@ function NET.autoLogin()
|
|||||||
if res then
|
if res then
|
||||||
if res.code==200 then
|
if res.code==200 then
|
||||||
-- TODO: connect WS
|
-- TODO: connect WS
|
||||||
SCN.go('net_game')
|
SCN.go('net_menu')
|
||||||
WAIT.interrupt()
|
WAIT.interrupt()
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
MES.new('warning',res.message,5)
|
MES.new('warn',res.message,5)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
WAIT.interrupt()
|
WAIT.interrupt()
|
||||||
@@ -228,11 +232,11 @@ function NET.autoLogin()
|
|||||||
USER.aToken=res.accessToken
|
USER.aToken=res.accessToken
|
||||||
-- TODO: connect WS
|
-- TODO: connect WS
|
||||||
MES.new('info',"Login successed",5)
|
MES.new('info',"Login successed",5)
|
||||||
SCN.go('net_game')
|
SCN.go('net_menu')
|
||||||
WAIT.interrupt()
|
WAIT.interrupt()
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
MES.new('warning',res.message,5)
|
MES.new('warn',res.message,5)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
WAIT.interrupt()
|
WAIT.interrupt()
|
||||||
@@ -254,11 +258,11 @@ function NET.autoLogin()
|
|||||||
USER.aToken=res.accessToken
|
USER.aToken=res.accessToken
|
||||||
-- TODO: connect WS
|
-- TODO: connect WS
|
||||||
MES.new('info',"Login successed",5)
|
MES.new('info',"Login successed",5)
|
||||||
SCN.go('net_game')
|
SCN.go('net_menu')
|
||||||
WAIT.interrupt()
|
WAIT.interrupt()
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
MES.new('warning',res.message,5)
|
MES.new('warn',res.message,5)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
WAIT.interrupt()
|
WAIT.interrupt()
|
||||||
@@ -279,7 +283,7 @@ end
|
|||||||
function NET.pwLogin(email,pw)
|
function NET.pwLogin(email,pw)
|
||||||
if not TASK.lock('pwLogin') then return end
|
if not TASK.lock('pwLogin') then return end
|
||||||
TASK.new(function()
|
TASK.new(function()
|
||||||
pw=STRING.digezt(pw)
|
pw=HASH.pbkdf2(HASH.sha3_256,pw,"salt",26000)
|
||||||
|
|
||||||
local res=getMsg({
|
local res=getMsg({
|
||||||
pool='pwLogin',
|
pool='pwLogin',
|
||||||
@@ -297,12 +301,12 @@ function NET.pwLogin(email,pw)
|
|||||||
USER.rToken=res.refreshToken
|
USER.rToken=res.refreshToken
|
||||||
USER.aToken=res.accessToken
|
USER.aToken=res.accessToken
|
||||||
-- TODO: connect WS
|
-- TODO: connect WS
|
||||||
SCN.go('net_game')
|
SCN.go('net_menu')
|
||||||
else
|
else
|
||||||
MES.new('error',res.message,5)
|
MES.new('error',res.message,5)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
MES.new('error',"Time out",5)
|
MES.new('warn',"Request failed",5)
|
||||||
end
|
end
|
||||||
|
|
||||||
WAIT.interrupt()
|
WAIT.interrupt()
|
||||||
@@ -349,7 +353,7 @@ end
|
|||||||
--Save
|
--Save
|
||||||
function NET.uploadSave()
|
function NET.uploadSave()
|
||||||
if TASK.lock('uploadSave',8)then
|
if TASK.lock('uploadSave',8)then
|
||||||
WS.send('game','{"action":2,"data":{"sections":'..JSON.encode{
|
WS.send('game',JSON.encode{action=2,data={sections={
|
||||||
{section=1,data=STRING.packTable(STAT)},
|
{section=1,data=STRING.packTable(STAT)},
|
||||||
{section=2,data=STRING.packTable(RANKS)},
|
{section=2,data=STRING.packTable(RANKS)},
|
||||||
{section=3,data=STRING.packTable(SETTING)},
|
{section=3,data=STRING.packTable(SETTING)},
|
||||||
@@ -357,13 +361,13 @@ function NET.uploadSave()
|
|||||||
{section=5,data=STRING.packTable(VK_ORG)},
|
{section=5,data=STRING.packTable(VK_ORG)},
|
||||||
{section=6,data=STRING.packTable(loadFile('conf/vkSave1','-canSkip')or{})},
|
{section=6,data=STRING.packTable(loadFile('conf/vkSave1','-canSkip')or{})},
|
||||||
{section=7,data=STRING.packTable(loadFile('conf/vkSave2','-canSkip')or{})},
|
{section=7,data=STRING.packTable(loadFile('conf/vkSave2','-canSkip')or{})},
|
||||||
}..'}}')
|
}}})
|
||||||
MES.new('info',"Uploading")
|
MES.new('info',"Uploading")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function NET.downloadSave()
|
function NET.downloadSave()
|
||||||
if TASK.lock('downloadSave',8)then
|
if TASK.lock('downloadSave',8)then
|
||||||
WS.send('game','{"action":3,"data":{"sections":[1,2,3,4,5,6,7]}}')
|
WS.send('game',JSON.encode{action=3,data={sections={1,2,3,4,5,6,7}}})
|
||||||
MES.new('info',"Downloading")
|
MES.new('info',"Downloading")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -466,25 +470,25 @@ function NET.checkPlayDisconn()
|
|||||||
end
|
end
|
||||||
function NET.signal_quit()
|
function NET.signal_quit()
|
||||||
if TASK.lock('quit',3)then
|
if TASK.lock('quit',3)then
|
||||||
WS.send('game','{"action":3}')
|
WS.send('game',JSON.encode{action=3})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function NET.sendMessage(mes)
|
function NET.sendMessage(mes)
|
||||||
WS.send('game','{"action":4,"data":'..JSON.encode{message=mes}..'}')
|
WS.send('game',JSON.encode{action=3,data={message=mes}})
|
||||||
end
|
end
|
||||||
function NET.changeConfig()
|
function NET.changeConfig()
|
||||||
WS.send('game','{"action":5,"data":'..JSON.encode({config=dumpBasicConfig()})..'}')
|
WS.send('game',JSON.encode{action=5,data={config=dumpBasicConfig()}})
|
||||||
end
|
end
|
||||||
function NET.signal_setMode(mode)
|
function NET.signal_setMode(mode)
|
||||||
if not NET.roomState.start and TASK.lock('ready',3)then
|
if not NET.roomState.start and TASK.lock('ready',3)then
|
||||||
WS.send('game','{"action":6,"data":'..JSON.encode{mode=mode}..'}')
|
WS.send('game',JSON.encode{action=6,data={mode=mode}})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function NET.signal_die()
|
function NET.signal_die()
|
||||||
WS.send('game','{"action":4,"data":{"score":0,"survivalTime":0}}')
|
WS.send('game',JSON.encode{action=4,data={score=0,survivalTime=0}})
|
||||||
end
|
end
|
||||||
function NET.uploadRecStream(stream)
|
function NET.uploadRecStream(stream)
|
||||||
WS.send('game','{"action":5,"data":{"stream":"'..loveEncode('string','base64',stream)..'"}}')
|
WS.send('game',JSON.encode{action=5,data={stream=loveEncode('string','base64',stream)}})
|
||||||
end
|
end
|
||||||
|
|
||||||
--Chat
|
--Chat
|
||||||
@@ -521,7 +525,6 @@ function NET.updateWS_user()
|
|||||||
if res.uid then
|
if res.uid then
|
||||||
USER.uid=res.uid
|
USER.uid=res.uid
|
||||||
USER.authToken=res.authToken
|
USER.authToken=res.authToken
|
||||||
saveFile(USER,'conf/user')
|
|
||||||
if SCN.cur=='login'then
|
if SCN.cur=='login'then
|
||||||
SCN.back()
|
SCN.back()
|
||||||
end
|
end
|
||||||
@@ -534,7 +537,7 @@ function NET.updateWS_user()
|
|||||||
elseif res.action==0 then--Get accessToken
|
elseif res.action==0 then--Get accessToken
|
||||||
NET.accessToken=res.accessToken
|
NET.accessToken=res.accessToken
|
||||||
MES.new('check',text.accessOK)
|
MES.new('check',text.accessOK)
|
||||||
NET.wsconn_play()
|
NET.wsconn()
|
||||||
elseif res.action==1 then--Get userInfo
|
elseif res.action==1 then--Get userInfo
|
||||||
USERS.updateUserData(res.data)
|
USERS.updateUserData(res.data)
|
||||||
elseif res.action==2 then--Upload successed
|
elseif res.action==2 then--Upload successed
|
||||||
|
|||||||
@@ -895,39 +895,26 @@ local commands={}do
|
|||||||
"Example: switchhost 127.0.0.1 26000 /sock",
|
"Example: switchhost 127.0.0.1 26000 /sock",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
function commands.manage()
|
|
||||||
if WS.status('manage')=='running'then
|
|
||||||
WS.close('manage')
|
|
||||||
log{C.Y,"Disconnected"}
|
|
||||||
else
|
|
||||||
if({[1]=0,[2]=0,[26]=0})[USER.uid]then
|
|
||||||
NET.wsconn_manage()
|
|
||||||
log{C.Y,"Connecting"}
|
|
||||||
else
|
|
||||||
log{C.R,"Permission denied"}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
function commands.m_broadcast(str)
|
function commands.m_broadcast(str)
|
||||||
if #str>0 then
|
if #str>0 then
|
||||||
WS.send('manage','{"action":0,"data":'..JSON.encode{message=str}..'}')
|
WS.send('game',JSON.encode{action=0,data={message=str}})
|
||||||
log{C.Y,"Request sent"}
|
log{C.Y,"Request sent"}
|
||||||
else
|
else
|
||||||
log{C.R,"Format error"}
|
log{C.R,"Format error"}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function commands.m_shutdown(sec)
|
function commands.m_shutdown(time)
|
||||||
sec=tonumber(sec)
|
time=tonumber(time)
|
||||||
if sec and sec>0 and sec~=math.floor(sec) then
|
if time and time>1 then
|
||||||
WS.send('manage','{"action":9,"data":'..JSON.encode{countdown=tonumber(sec)}..'}')
|
WS.send('game',JSON.encode{action=0,data={countdown=time}})
|
||||||
log{C.Y,"Request sent"}
|
log{C.Y,"Request sent"}
|
||||||
else
|
else
|
||||||
log{C.R,"Format error"}
|
log{C.R,"Format error"}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function commands.m_connInfo()WS.send('manage','{"action":10}')end
|
function commands.m_connInfo()WS.send('game',JSON.encode{action=10})end
|
||||||
function commands.m_playMgrInfo()WS.send('manage','{"action":11}')end
|
function commands.m_playMgrInfo()WS.send('game',JSON.encode{action=11})end
|
||||||
function commands.m_streamMgrInfo()WS.send('manage','{"action":12}')end
|
function commands.m_streamMgrInfo()WS.send('game',JSON.encode{action=12})end
|
||||||
|
|
||||||
for cmd,body in next,commands do
|
for cmd,body in next,commands do
|
||||||
if type(body)=='function'then
|
if type(body)=='function'then
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ local function _login()
|
|||||||
elseif #password==0 then
|
elseif #password==0 then
|
||||||
MES.new('error',text.noPassword)return
|
MES.new('error',text.noPassword)return
|
||||||
end
|
end
|
||||||
-- password=STRING.digezt(password)
|
|
||||||
NET.pwLogin(email,password)
|
NET.pwLogin(email,password)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -23,13 +22,18 @@ function scene.sceneInit()
|
|||||||
passwordBox:setText(USER.password)
|
passwordBox:setText(USER.password)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function scene.keyDown(key,rep)
|
||||||
|
if key~='return' or rep then return true end
|
||||||
|
_login()
|
||||||
|
end
|
||||||
|
|
||||||
scene.widgetList={
|
scene.widgetList={
|
||||||
WIDGET.newText{name='title', x=80, y=50,font=70,align='L'},
|
WIDGET.newText{name='title', x=80, y=50,font=70,align='L'},
|
||||||
WIDGET.newButton{name='register', x=1140,y=100,w=170,h=80,color='lY',code=function()SCN.swapTo('register','swipeR')end},
|
WIDGET.newButton{name='register', x=1140,y=100,w=170,h=80,color='lY',code=function()SCN.swapTo('register','swipeR')end},
|
||||||
emailBox,
|
emailBox,
|
||||||
passwordBox,
|
passwordBox,
|
||||||
WIDGET.newSwitch{name='showEmail',x=550, y=420,disp=function()return showEmail end,code=function()showEmail=not showEmail emailBox.secret=not showEmail end},
|
WIDGET.newSwitch{name='showEmail',x=550, y=420,disp=function()return showEmail end,code=function()showEmail=not showEmail emailBox.secret=not showEmail end},
|
||||||
WIDGET.newKey{name='login', x=1140,y=540,w=170,h=80,font=40,code=_login},
|
WIDGET.newKey{name='login', x=1140,y=540,w=170,h=80,font=40,code=pressKey'return'},
|
||||||
WIDGET.newButton{name='back', x=1140,y=640,w=170,h=80,sound='back',font=60,fText=CHAR.icon.back,code=backScene},
|
WIDGET.newButton{name='back', x=1140,y=640,w=170,h=80,sound='back',font=60,fText=CHAR.icon.back,code=backScene},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -232,7 +232,7 @@ end
|
|||||||
|
|
||||||
function scene.update(dt)
|
function scene.update(dt)
|
||||||
if NET.checkPlayDisconn()then
|
if NET.checkPlayDisconn()then
|
||||||
NET.wsclose_stream()
|
NET.wsclose()
|
||||||
SCN.back()
|
SCN.back()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ function scene.sceneInit()
|
|||||||
BG.set()
|
BG.set()
|
||||||
end
|
end
|
||||||
function scene.sceneBack()
|
function scene.sceneBack()
|
||||||
NET.wsclose_play()
|
NET.wsclose()
|
||||||
end
|
end
|
||||||
|
|
||||||
function scene.draw()
|
function scene.draw()
|
||||||
@@ -21,11 +21,9 @@ scene.widgetList={
|
|||||||
code=function()
|
code=function()
|
||||||
if tryBack()then
|
if tryBack()then
|
||||||
if USER.uid then
|
if USER.uid then
|
||||||
NET.wsclose_play()
|
NET.wsclose()
|
||||||
NET.wsclose_user()
|
|
||||||
USER.uid=false
|
USER.uid=false
|
||||||
USER.authToken=false
|
USER.authToken=false
|
||||||
saveFile(USER,'conf/user')
|
|
||||||
SCN.back()
|
SCN.back()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -34,16 +34,16 @@ local function _setPW()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function scene.sceneInit()
|
function scene.sceneInit()
|
||||||
state=1
|
state=SCN.args[1] or 1
|
||||||
scene.fileDropped(state)
|
scene.fileDropped(state)
|
||||||
end
|
end
|
||||||
|
|
||||||
function scene.keyDown(key,rep)
|
function scene.keyDown(key,rep)
|
||||||
if key=='escape' and not rep then
|
if key=='escape' and not rep then
|
||||||
if state==1 then
|
if state==2 then
|
||||||
SCN.back()
|
|
||||||
else
|
|
||||||
scene.fileDropped(state-1)
|
scene.fileDropped(state-1)
|
||||||
|
else
|
||||||
|
SCN.back()
|
||||||
end
|
end
|
||||||
elseif key=='return' then
|
elseif key=='return' then
|
||||||
if state==1 then
|
if state==1 then
|
||||||
@@ -68,6 +68,14 @@ function scene.fileDropped(arg)-- Not designed for this, but it works and no sid
|
|||||||
scene.widgetList.password. hide=arg~=3
|
scene.widgetList.password. hide=arg~=3
|
||||||
scene.widgetList.password2. hide=arg~=3
|
scene.widgetList.password2. hide=arg~=3
|
||||||
scene.widgetList.setPW. hide=arg~=3
|
scene.widgetList.setPW. hide=arg~=3
|
||||||
|
if arg==1 then
|
||||||
|
scene.widgetList.email:setText(USER.email or "")
|
||||||
|
elseif arg==2 then
|
||||||
|
scene.widgetList.code:clear()
|
||||||
|
elseif arg==3 then
|
||||||
|
scene.widgetList.password:clear()
|
||||||
|
scene.widgetList.password2:clear()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
scene.widgetList={
|
scene.widgetList={
|
||||||
|
|||||||
Reference in New Issue
Block a user