【不能用】继续改联网,能登录了
框架跟进
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)
|
||||
end
|
||||
do--Userdata tables
|
||||
USER={--User infomation
|
||||
email=false,
|
||||
password=false,
|
||||
rToken=false,
|
||||
aToken=false,
|
||||
}
|
||||
USER=setmetatable({--User infomation
|
||||
__data={
|
||||
email=false,
|
||||
password=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
|
||||
--Tuning
|
||||
das=10,arr=2,
|
||||
|
||||
@@ -68,8 +68,11 @@ local function getMsg(request,timeout)
|
||||
while true do
|
||||
local mes=HTTP.pollMsg(request.pool)
|
||||
if mes then
|
||||
if type(mes.body)=='string' then
|
||||
if type(mes.body)=='string' and #mes.body>0 then
|
||||
return JSON.decode(mes.body)
|
||||
else
|
||||
MES.new('info',"Oops! Server is down")
|
||||
return
|
||||
end
|
||||
else
|
||||
totalTime=totalTime+coroutine.yield()
|
||||
@@ -97,7 +100,7 @@ function NET.getCode(email)
|
||||
MES.new('error',res.message,5)
|
||||
end
|
||||
else
|
||||
MES.new('error',"Time out",5)
|
||||
MES.new('warn',"Request failed",5)
|
||||
end
|
||||
|
||||
WAIT.interrupt()
|
||||
@@ -127,17 +130,17 @@ function NET.codeLogin(code)
|
||||
USER.rToken=res.refreshToken
|
||||
USER.aToken=res.accessToken
|
||||
-- TODO: connect WS
|
||||
SCN.go('net_game')
|
||||
SCN.pop()SCN.go('net_menu')
|
||||
elseif res.code==201 then
|
||||
USER.rToken=res.refreshToken
|
||||
USER.aToken=res.accessToken
|
||||
SCN.fileDropped(3)-- Not designed for this, but it works and no side effects
|
||||
MES.new('info',"Please set your password",5)
|
||||
SCN.pop()SCN.push('net_menu')
|
||||
SCN.fileDropped(3)
|
||||
else
|
||||
MES.new('error',res.message,5)
|
||||
end
|
||||
else
|
||||
MES.new('error',"Time out",5)
|
||||
MES.new('warn',"Request failed",5)
|
||||
end
|
||||
|
||||
WAIT.interrupt()
|
||||
@@ -168,13 +171,14 @@ function NET.setPW(code,pw)
|
||||
|
||||
if res then
|
||||
if res.code==200 then
|
||||
SCN.back()
|
||||
USER.password=pw
|
||||
MES.new('info',"Password set! Now you can login",5)
|
||||
SCN.back()
|
||||
else
|
||||
MES.new('error',res.message,5)
|
||||
end
|
||||
else
|
||||
MES.new('error',"Time out",5)
|
||||
MES.new('warn',"Request failed",5)
|
||||
end
|
||||
|
||||
WAIT.interrupt()
|
||||
@@ -204,11 +208,11 @@ function NET.autoLogin()
|
||||
if res then
|
||||
if res.code==200 then
|
||||
-- TODO: connect WS
|
||||
SCN.go('net_game')
|
||||
SCN.go('net_menu')
|
||||
WAIT.interrupt()
|
||||
return
|
||||
else
|
||||
MES.new('warning',res.message,5)
|
||||
MES.new('warn',res.message,5)
|
||||
end
|
||||
else
|
||||
WAIT.interrupt()
|
||||
@@ -228,11 +232,11 @@ function NET.autoLogin()
|
||||
USER.aToken=res.accessToken
|
||||
-- TODO: connect WS
|
||||
MES.new('info',"Login successed",5)
|
||||
SCN.go('net_game')
|
||||
SCN.go('net_menu')
|
||||
WAIT.interrupt()
|
||||
return
|
||||
else
|
||||
MES.new('warning',res.message,5)
|
||||
MES.new('warn',res.message,5)
|
||||
end
|
||||
else
|
||||
WAIT.interrupt()
|
||||
@@ -254,11 +258,11 @@ function NET.autoLogin()
|
||||
USER.aToken=res.accessToken
|
||||
-- TODO: connect WS
|
||||
MES.new('info',"Login successed",5)
|
||||
SCN.go('net_game')
|
||||
SCN.go('net_menu')
|
||||
WAIT.interrupt()
|
||||
return
|
||||
else
|
||||
MES.new('warning',res.message,5)
|
||||
MES.new('warn',res.message,5)
|
||||
end
|
||||
else
|
||||
WAIT.interrupt()
|
||||
@@ -279,7 +283,7 @@ end
|
||||
function NET.pwLogin(email,pw)
|
||||
if not TASK.lock('pwLogin') then return end
|
||||
TASK.new(function()
|
||||
pw=STRING.digezt(pw)
|
||||
pw=HASH.pbkdf2(HASH.sha3_256,pw,"salt",26000)
|
||||
|
||||
local res=getMsg({
|
||||
pool='pwLogin',
|
||||
@@ -297,12 +301,12 @@ function NET.pwLogin(email,pw)
|
||||
USER.rToken=res.refreshToken
|
||||
USER.aToken=res.accessToken
|
||||
-- TODO: connect WS
|
||||
SCN.go('net_game')
|
||||
SCN.go('net_menu')
|
||||
else
|
||||
MES.new('error',res.message,5)
|
||||
end
|
||||
else
|
||||
MES.new('error',"Time out",5)
|
||||
MES.new('warn',"Request failed",5)
|
||||
end
|
||||
|
||||
WAIT.interrupt()
|
||||
@@ -349,7 +353,7 @@ end
|
||||
--Save
|
||||
function NET.uploadSave()
|
||||
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=2,data=STRING.packTable(RANKS)},
|
||||
{section=3,data=STRING.packTable(SETTING)},
|
||||
@@ -357,13 +361,13 @@ function NET.uploadSave()
|
||||
{section=5,data=STRING.packTable(VK_ORG)},
|
||||
{section=6,data=STRING.packTable(loadFile('conf/vkSave1','-canSkip')or{})},
|
||||
{section=7,data=STRING.packTable(loadFile('conf/vkSave2','-canSkip')or{})},
|
||||
}..'}}')
|
||||
}}})
|
||||
MES.new('info',"Uploading")
|
||||
end
|
||||
end
|
||||
function NET.downloadSave()
|
||||
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")
|
||||
end
|
||||
end
|
||||
@@ -466,25 +470,25 @@ function NET.checkPlayDisconn()
|
||||
end
|
||||
function NET.signal_quit()
|
||||
if TASK.lock('quit',3)then
|
||||
WS.send('game','{"action":3}')
|
||||
WS.send('game',JSON.encode{action=3})
|
||||
end
|
||||
end
|
||||
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
|
||||
function NET.changeConfig()
|
||||
WS.send('game','{"action":5,"data":'..JSON.encode({config=dumpBasicConfig()})..'}')
|
||||
WS.send('game',JSON.encode{action=5,data={config=dumpBasicConfig()}})
|
||||
end
|
||||
function NET.signal_setMode(mode)
|
||||
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
|
||||
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
|
||||
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
|
||||
|
||||
--Chat
|
||||
@@ -521,7 +525,6 @@ function NET.updateWS_user()
|
||||
if res.uid then
|
||||
USER.uid=res.uid
|
||||
USER.authToken=res.authToken
|
||||
saveFile(USER,'conf/user')
|
||||
if SCN.cur=='login'then
|
||||
SCN.back()
|
||||
end
|
||||
@@ -534,7 +537,7 @@ function NET.updateWS_user()
|
||||
elseif res.action==0 then--Get accessToken
|
||||
NET.accessToken=res.accessToken
|
||||
MES.new('check',text.accessOK)
|
||||
NET.wsconn_play()
|
||||
NET.wsconn()
|
||||
elseif res.action==1 then--Get userInfo
|
||||
USERS.updateUserData(res.data)
|
||||
elseif res.action==2 then--Upload successed
|
||||
|
||||
@@ -895,39 +895,26 @@ local commands={}do
|
||||
"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)
|
||||
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"}
|
||||
else
|
||||
log{C.R,"Format error"}
|
||||
end
|
||||
end
|
||||
function commands.m_shutdown(sec)
|
||||
sec=tonumber(sec)
|
||||
if sec and sec>0 and sec~=math.floor(sec) then
|
||||
WS.send('manage','{"action":9,"data":'..JSON.encode{countdown=tonumber(sec)}..'}')
|
||||
function commands.m_shutdown(time)
|
||||
time=tonumber(time)
|
||||
if time and time>1 then
|
||||
WS.send('game',JSON.encode{action=0,data={countdown=time}})
|
||||
log{C.Y,"Request sent"}
|
||||
else
|
||||
log{C.R,"Format error"}
|
||||
end
|
||||
end
|
||||
function commands.m_connInfo()WS.send('manage','{"action":10}')end
|
||||
function commands.m_playMgrInfo()WS.send('manage','{"action":11}')end
|
||||
function commands.m_streamMgrInfo()WS.send('manage','{"action":12}')end
|
||||
function commands.m_connInfo()WS.send('game',JSON.encode{action=10})end
|
||||
function commands.m_playMgrInfo()WS.send('game',JSON.encode{action=11})end
|
||||
function commands.m_streamMgrInfo()WS.send('game',JSON.encode{action=12})end
|
||||
|
||||
for cmd,body in next,commands do
|
||||
if type(body)=='function'then
|
||||
|
||||
@@ -10,7 +10,6 @@ local function _login()
|
||||
elseif #password==0 then
|
||||
MES.new('error',text.noPassword)return
|
||||
end
|
||||
-- password=STRING.digezt(password)
|
||||
NET.pwLogin(email,password)
|
||||
end
|
||||
|
||||
@@ -23,13 +22,18 @@ function scene.sceneInit()
|
||||
passwordBox:setText(USER.password)
|
||||
end
|
||||
|
||||
function scene.keyDown(key,rep)
|
||||
if key~='return' or rep then return true end
|
||||
_login()
|
||||
end
|
||||
|
||||
scene.widgetList={
|
||||
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},
|
||||
emailBox,
|
||||
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.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},
|
||||
}
|
||||
|
||||
|
||||
@@ -232,7 +232,7 @@ end
|
||||
|
||||
function scene.update(dt)
|
||||
if NET.checkPlayDisconn()then
|
||||
NET.wsclose_stream()
|
||||
NET.wsclose()
|
||||
SCN.back()
|
||||
return
|
||||
end
|
||||
|
||||
@@ -4,7 +4,7 @@ function scene.sceneInit()
|
||||
BG.set()
|
||||
end
|
||||
function scene.sceneBack()
|
||||
NET.wsclose_play()
|
||||
NET.wsclose()
|
||||
end
|
||||
|
||||
function scene.draw()
|
||||
@@ -21,11 +21,9 @@ scene.widgetList={
|
||||
code=function()
|
||||
if tryBack()then
|
||||
if USER.uid then
|
||||
NET.wsclose_play()
|
||||
NET.wsclose_user()
|
||||
NET.wsclose()
|
||||
USER.uid=false
|
||||
USER.authToken=false
|
||||
saveFile(USER,'conf/user')
|
||||
SCN.back()
|
||||
end
|
||||
end
|
||||
|
||||
@@ -34,16 +34,16 @@ local function _setPW()
|
||||
end
|
||||
|
||||
function scene.sceneInit()
|
||||
state=1
|
||||
state=SCN.args[1] or 1
|
||||
scene.fileDropped(state)
|
||||
end
|
||||
|
||||
function scene.keyDown(key,rep)
|
||||
if key=='escape' and not rep then
|
||||
if state==1 then
|
||||
SCN.back()
|
||||
else
|
||||
if state==2 then
|
||||
scene.fileDropped(state-1)
|
||||
else
|
||||
SCN.back()
|
||||
end
|
||||
elseif key=='return' 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.password2. 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
|
||||
|
||||
scene.widgetList={
|
||||
|
||||
Reference in New Issue
Block a user