【不能用】继续改联网
框架跟进
This commit is contained in:
Submodule Zframework updated: 2ba3ffea4c...79455c6fc7
@@ -881,7 +881,7 @@ function drawOnlinePlayerCount()
|
|||||||
gc_setColor(1,1,1)
|
gc_setColor(1,1,1)
|
||||||
gc_push('transform')
|
gc_push('transform')
|
||||||
gc_replaceTransform(SCR.xOy_ur)
|
gc_replaceTransform(SCR.xOy_ur)
|
||||||
gc_printf(("%s: %s/%s/%s"):format(text.onlinePlayerCount,NET.UserCount,NET.PlayCount,NET.StreamCount),-600,80,594,'right')
|
gc_printf(text.onlinePlayerCount..":"..NET.onlineCount,-600,80,594,'right')
|
||||||
gc_pop()
|
gc_pop()
|
||||||
end
|
end
|
||||||
function drawWarning()
|
function drawWarning()
|
||||||
|
|||||||
110
parts/net.lua
110
parts/net.lua
@@ -1,7 +1,6 @@
|
|||||||
local loveEncode,loveDecode=love.data.encode,love.data.decode
|
local loveEncode,loveDecode=love.data.encode,love.data.decode
|
||||||
local rem=table.remove
|
|
||||||
|
|
||||||
local WS,TIME=WS,TIME
|
local WS=WS
|
||||||
local yield=YIELD
|
local yield=YIELD
|
||||||
local PLAYERS=PLAYERS
|
local PLAYERS=PLAYERS
|
||||||
|
|
||||||
@@ -28,9 +27,7 @@ local NET={
|
|||||||
|
|
||||||
roomReadyState=false,
|
roomReadyState=false,
|
||||||
|
|
||||||
UserCount="_",
|
onlineCount="_",
|
||||||
PlayCount="_",
|
|
||||||
StreamCount="_",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
local mesType={
|
local mesType={
|
||||||
@@ -41,29 +38,6 @@ local mesType={
|
|||||||
Server=true,
|
Server=true,
|
||||||
}
|
}
|
||||||
|
|
||||||
--Lock & Unlock submodule
|
|
||||||
local locks do
|
|
||||||
local rawset=rawset
|
|
||||||
locks=setmetatable({},{
|
|
||||||
__index=function(self,k)rawset(self,k,-1e99)return -1e99 end,
|
|
||||||
__newindex=function(self,k)rawset(self,k,-1e99)end,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
function NET.lock(name,T)
|
|
||||||
if TIME()>=locks[name]then
|
|
||||||
locks[name]=TIME()+(T or 1e99)
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
function NET.unlock(name)
|
|
||||||
locks[name]=-1e99
|
|
||||||
end
|
|
||||||
function NET.getlock(name)
|
|
||||||
return TIME()<locks[name]
|
|
||||||
end
|
|
||||||
|
|
||||||
--Parse json message
|
--Parse json message
|
||||||
local function _parse(res)
|
local function _parse(res)
|
||||||
res=JSON.decode(res)
|
res=JSON.decode(res)
|
||||||
@@ -107,7 +81,7 @@ local function getMsg(request,timeout)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
function NET.getCode(email)
|
function NET.getCode(email)
|
||||||
if not NET.lock('getCode') then return end
|
if not TASK.lock('getCode') then return end
|
||||||
TASK.new(function()
|
TASK.new(function()
|
||||||
local res=getMsg({
|
local res=getMsg({
|
||||||
pool='getCode',
|
pool='getCode',
|
||||||
@@ -131,14 +105,14 @@ function NET.getCode(email)
|
|||||||
end)
|
end)
|
||||||
WAIT{
|
WAIT{
|
||||||
quit=function()
|
quit=function()
|
||||||
NET.unlock('getCode')
|
TASK.unlock('getCode')
|
||||||
HTTP.deletePool('getCode')
|
HTTP.deletePool('getCode')
|
||||||
end,
|
end,
|
||||||
timeout=12.6,
|
timeout=12.6,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
function NET.codeLogin(code)
|
function NET.codeLogin(code)
|
||||||
if not NET.lock('codeLogin') then return end
|
if not TASK.lock('codeLogin') then return end
|
||||||
TASK.new(function()
|
TASK.new(function()
|
||||||
local res=getMsg({
|
local res=getMsg({
|
||||||
pool='codeLogin',
|
pool='codeLogin',
|
||||||
@@ -171,14 +145,14 @@ function NET.codeLogin(code)
|
|||||||
end)
|
end)
|
||||||
WAIT{
|
WAIT{
|
||||||
quit=function()
|
quit=function()
|
||||||
NET.unlock('codeLogin')
|
TASK.unlock('codeLogin')
|
||||||
HTTP.deletePool('codeLogin')
|
HTTP.deletePool('codeLogin')
|
||||||
end,
|
end,
|
||||||
timeout=6.26,
|
timeout=6.26,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
function NET.setPW(code,pw)
|
function NET.setPW(code,pw)
|
||||||
if not NET.lock('setPW') then return end
|
if not TASK.lock('setPW') then return end
|
||||||
TASK.new(function()
|
TASK.new(function()
|
||||||
pw=HASH.hmac()
|
pw=HASH.hmac()
|
||||||
|
|
||||||
@@ -208,7 +182,7 @@ function NET.setPW(code,pw)
|
|||||||
end)
|
end)
|
||||||
WAIT{
|
WAIT{
|
||||||
quit=function()
|
quit=function()
|
||||||
NET.unlock('setPW')
|
TASK.unlock('setPW')
|
||||||
HTTP.deletePool('setPW')
|
HTTP.deletePool('setPW')
|
||||||
end,
|
end,
|
||||||
timeout=6.26,
|
timeout=6.26,
|
||||||
@@ -219,7 +193,7 @@ function NET.autoLogin()
|
|||||||
SCN.go('login')
|
SCN.go('login')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if not NET.lock('autoLogin') then return end
|
if not TASK.lock('autoLogin') then return end
|
||||||
TASK.new(function()
|
TASK.new(function()
|
||||||
if USER.aToken then
|
if USER.aToken then
|
||||||
local res=getMsg({
|
local res=getMsg({
|
||||||
@@ -297,14 +271,14 @@ function NET.autoLogin()
|
|||||||
end)
|
end)
|
||||||
WAIT{
|
WAIT{
|
||||||
quit=function()
|
quit=function()
|
||||||
NET.unlock('autoLogin')
|
TASK.unlock('autoLogin')
|
||||||
HTTP.deletePool('autoLogin')
|
HTTP.deletePool('autoLogin')
|
||||||
end,
|
end,
|
||||||
timeout=12.6,
|
timeout=12.6,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
function NET.pwLogin(email,pw)
|
function NET.pwLogin(email,pw)
|
||||||
if not NET.lock('pwLogin') then return end
|
if not TASK.lock('pwLogin') then return end
|
||||||
TASK.new(function()
|
TASK.new(function()
|
||||||
pw=STRING.digezt(pw)
|
pw=STRING.digezt(pw)
|
||||||
|
|
||||||
@@ -336,7 +310,7 @@ function NET.pwLogin(email,pw)
|
|||||||
end)
|
end)
|
||||||
WAIT{
|
WAIT{
|
||||||
quit=function()
|
quit=function()
|
||||||
NET.unlock('pwLogin')
|
TASK.unlock('pwLogin')
|
||||||
HTTP.deletePool('pwLogin')
|
HTTP.deletePool('pwLogin')
|
||||||
end,
|
end,
|
||||||
timeout=12.6,
|
timeout=12.6,
|
||||||
@@ -348,7 +322,7 @@ end
|
|||||||
|
|
||||||
--Connect
|
--Connect
|
||||||
function NET.wsconn()
|
function NET.wsconn()
|
||||||
if WS.status('stream')=='dead'then
|
if WS.status('game')=='dead'then
|
||||||
NET.roomState.start=true
|
NET.roomState.start=true
|
||||||
WS.connect('stream','/stream',JSON.encode{
|
WS.connect('stream','/stream',JSON.encode{
|
||||||
accessToken=USER.aToken,
|
accessToken=USER.aToken,
|
||||||
@@ -364,7 +338,7 @@ end
|
|||||||
|
|
||||||
--Account & User
|
--Account & User
|
||||||
function NET.getUserInfo(uid)
|
function NET.getUserInfo(uid)
|
||||||
WS.send('user',JSON.encode{
|
WS.send('game',JSON.encode{
|
||||||
action=1,
|
action=1,
|
||||||
data={
|
data={
|
||||||
uid=uid,
|
uid=uid,
|
||||||
@@ -375,8 +349,8 @@ end
|
|||||||
|
|
||||||
--Save
|
--Save
|
||||||
function NET.uploadSave()
|
function NET.uploadSave()
|
||||||
if NET.lock('uploadSave',8)then
|
if TASK.lock('uploadSave',8)then
|
||||||
WS.send('user','{"action":2,"data":{"sections":'..JSON.encode{
|
WS.send('game','{"action":2,"data":{"sections":'..JSON.encode{
|
||||||
{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)},
|
||||||
@@ -389,8 +363,8 @@ function NET.uploadSave()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
function NET.downloadSave()
|
function NET.downloadSave()
|
||||||
if NET.lock('downloadSave',8)then
|
if TASK.lock('downloadSave',8)then
|
||||||
WS.send('user','{"action":3,"data":{"sections":[1,2,3,4,5,6,7]}}')
|
WS.send('game','{"action":3,"data":{"sections":[1,2,3,4,5,6,7]}}')
|
||||||
MES.new('info',"Downloading")
|
MES.new('info',"Downloading")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -440,8 +414,8 @@ end
|
|||||||
|
|
||||||
--Room
|
--Room
|
||||||
function NET.fetchRoom()
|
function NET.fetchRoom()
|
||||||
if NET.lock('fetchRoom',3)then
|
if TASK.lock('fetchRoom',3)then
|
||||||
WS.send('play',JSON.encode{
|
WS.send('game',JSON.encode{
|
||||||
action=0,
|
action=0,
|
||||||
data={
|
data={
|
||||||
type=nil,
|
type=nil,
|
||||||
@@ -452,10 +426,10 @@ function NET.fetchRoom()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
function NET.createRoom(roomName,description,capacity,roomType,roomData,password)
|
function NET.createRoom(roomName,description,capacity,roomType,roomData,password)
|
||||||
if NET.lock('enterRoom',2)then
|
if TASK.lock('enterRoom',2)then
|
||||||
NET.roomState.private=not not password
|
NET.roomState.private=not not password
|
||||||
NET.roomState.capacity=capacity
|
NET.roomState.capacity=capacity
|
||||||
WS.send('play',JSON.encode{
|
WS.send('game',JSON.encode{
|
||||||
action=1,
|
action=1,
|
||||||
data={
|
data={
|
||||||
capacity=capacity,
|
capacity=capacity,
|
||||||
@@ -474,9 +448,9 @@ function NET.createRoom(roomName,description,capacity,roomType,roomData,password
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
function NET.enterRoom(room,password)
|
function NET.enterRoom(room,password)
|
||||||
if NET.lock('enterRoom',6)then
|
if TASK.lock('enterRoom',6)then
|
||||||
SFX.play('reach',.6)
|
SFX.play('reach',.6)
|
||||||
WS.send('play',JSON.encode{
|
WS.send('game',JSON.encode{
|
||||||
action=2,
|
action=2,
|
||||||
data={
|
data={
|
||||||
rid=room.rid,
|
rid=room.rid,
|
||||||
@@ -489,50 +463,50 @@ end
|
|||||||
|
|
||||||
--Play
|
--Play
|
||||||
function NET.checkPlayDisconn()
|
function NET.checkPlayDisconn()
|
||||||
return WS.status('play')~='running'
|
return WS.status('game')~='running'
|
||||||
end
|
end
|
||||||
function NET.signal_quit()
|
function NET.signal_quit()
|
||||||
if NET.lock('quit',3)then
|
if TASK.lock('quit',3)then
|
||||||
WS.send('play','{"action":3}')
|
WS.send('game','{"action":3}')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function NET.sendMessage(mes)
|
function NET.sendMessage(mes)
|
||||||
WS.send('play','{"action":4,"data":'..JSON.encode{message=mes}..'}')
|
WS.send('game','{"action":4,"data":'..JSON.encode{message=mes}..'}')
|
||||||
end
|
end
|
||||||
function NET.changeConfig()
|
function NET.changeConfig()
|
||||||
WS.send('play','{"action":5,"data":'..JSON.encode({config=dumpBasicConfig()})..'}')
|
WS.send('game','{"action":5,"data":'..JSON.encode({config=dumpBasicConfig()})..'}')
|
||||||
end
|
end
|
||||||
function NET.signal_setMode(mode)
|
function NET.signal_setMode(mode)
|
||||||
if not NET.roomState.start and NET.lock('ready',3)then
|
if not NET.roomState.start and TASK.lock('ready',3)then
|
||||||
WS.send('play','{"action":6,"data":'..JSON.encode{mode=mode}..'}')
|
WS.send('game','{"action":6,"data":'..JSON.encode{mode=mode}..'}')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function NET.signal_die()
|
function NET.signal_die()
|
||||||
WS.send('stream','{"action":4,"data":{"score":0,"survivalTime":0}}')
|
WS.send('game','{"action":4,"data":{"score":0,"survivalTime":0}}')
|
||||||
end
|
end
|
||||||
function NET.uploadRecStream(stream)
|
function NET.uploadRecStream(stream)
|
||||||
WS.send('stream','{"action":5,"data":{"stream":"'..loveEncode('string','base64',stream)..'"}}')
|
WS.send('game','{"action":5,"data":{"stream":"'..loveEncode('string','base64',stream)..'"}}')
|
||||||
end
|
end
|
||||||
|
|
||||||
--Chat
|
--Chat
|
||||||
function NET.sendChatMes(mes)
|
function NET.sendChatMes(mes)
|
||||||
WS.send('chat',"T"..loveEncode('string','base64',mes))
|
WS.send('game',"T"..loveEncode('string','base64',mes))
|
||||||
end
|
end
|
||||||
function NET.quitChat()
|
function NET.quitChat()
|
||||||
WS.send('chat','q')
|
WS.send('game','q')
|
||||||
end
|
end
|
||||||
|
|
||||||
--WS task funcs
|
--WS task funcs
|
||||||
function NET.freshPlayerCount()
|
function NET.freshPlayerCount()
|
||||||
while WS.status('app')=='running'do
|
while WS.status('game')=='running'do
|
||||||
for _=1,260 do yield()end
|
for _=1,260 do yield()end
|
||||||
if NET.lock('freshPlayerCount',10)then
|
if TASK.lock('freshPlayerCount',10)then
|
||||||
WS.send('app',JSON.encode{action=3})
|
WS.send('game',JSON.encode{action=3})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function NET.updateWS_user()
|
function NET.updateWS_user()
|
||||||
while WS.status('user')~='dead'do
|
while WS.status('game')~='dead'do
|
||||||
yield()
|
yield()
|
||||||
local message,op=WS.read('user')
|
local message,op=WS.read('user')
|
||||||
if message then
|
if message then
|
||||||
@@ -557,7 +531,7 @@ function NET.updateWS_user()
|
|||||||
|
|
||||||
--Get self infos
|
--Get self infos
|
||||||
NET.getUserInfo(USER.uid)
|
NET.getUserInfo(USER.uid)
|
||||||
NET.unlock('wsc_user')
|
TASK.unlock('wsc_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)
|
||||||
@@ -565,10 +539,10 @@ function NET.updateWS_user()
|
|||||||
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
|
||||||
NET.unlock('uploadSave')
|
TASK.unlock('uploadSave')
|
||||||
MES.new('check',text.exportSuccess)
|
MES.new('check',text.exportSuccess)
|
||||||
elseif res.action==3 then--Download successed
|
elseif res.action==3 then--Download successed
|
||||||
NET.unlock('downloadSave')
|
TASK.unlock('downloadSave')
|
||||||
NET.loadSavedData(res.data.sections)
|
NET.loadSavedData(res.data.sections)
|
||||||
MES.new('check',text.importSuccess)
|
MES.new('check',text.importSuccess)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ function NETPLY.setJoinMode(uid,ready)
|
|||||||
if ready==0 then NET.roomReadyState=false end
|
if ready==0 then NET.roomReadyState=false end
|
||||||
SFX.play('spin_0',.6)
|
SFX.play('spin_0',.6)
|
||||||
if p.uid==USER.uid then
|
if p.uid==USER.uid then
|
||||||
NET.unlock('ready')
|
TASK.unlock('ready')
|
||||||
elseif PLYmap[USER.uid].mode==0 then
|
elseif PLYmap[USER.uid].mode==0 then
|
||||||
for j=1,#PLYlist do
|
for j=1,#PLYlist do
|
||||||
if not p.uid==USER.uid and PLYlist[j].mode==0 then
|
if not p.uid==USER.uid and PLYlist[j].mode==0 then
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ local function _hideReadyUI()
|
|||||||
return
|
return
|
||||||
playing or
|
playing or
|
||||||
NET.roomState.start or
|
NET.roomState.start or
|
||||||
NET.getlock('ready')
|
TASK.getLock('ready')
|
||||||
end
|
end
|
||||||
|
|
||||||
local function _setCancel()NET.signal_setMode(0)end
|
local function _setCancel()NET.signal_setMode(0)end
|
||||||
|
|||||||
@@ -61,14 +61,14 @@ function scene.sceneInit()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function scene.keyDown(key)
|
function scene.keyDown(key)
|
||||||
if NET.getlock('enterRoom')then return true end
|
if TASK.getLock('enterRoom')then return true end
|
||||||
if key=='r'then
|
if key=='r'then
|
||||||
if fetchTimer<=7 then
|
if fetchTimer<=7 then
|
||||||
_fetchRoom()
|
_fetchRoom()
|
||||||
end
|
end
|
||||||
elseif roomList:getLen()>0 and(key=='join'or key=='return'and love.keyboard.isDown('lctrl','rctrl'))then
|
elseif roomList:getLen()>0 and(key=='join'or key=='return'and love.keyboard.isDown('lctrl','rctrl'))then
|
||||||
local R=roomList:getSel()
|
local R=roomList:getSel()
|
||||||
if NET.getlock('fetchRoom')or not R then return end
|
if TASK.getLock('fetchRoom')or not R then return end
|
||||||
if R.roomInfo.version==VERSION.room then
|
if R.roomInfo.version==VERSION.room then
|
||||||
NET.enterRoom(R,passwordBox.value)
|
NET.enterRoom(R,passwordBox.value)
|
||||||
else
|
else
|
||||||
@@ -80,7 +80,7 @@ function scene.keyDown(key)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function scene.update(dt)
|
function scene.update(dt)
|
||||||
if not NET.getlock('fetchRoom')and _hidePW()then
|
if not TASK.getLock('fetchRoom')and _hidePW()then
|
||||||
fetchTimer=fetchTimer-dt
|
fetchTimer=fetchTimer-dt
|
||||||
if fetchTimer<=0 then
|
if fetchTimer<=0 then
|
||||||
_fetchRoom()
|
_fetchRoom()
|
||||||
@@ -94,7 +94,7 @@ function scene.draw()
|
|||||||
gc_arc('fill','pie',250,630,40,-1.5708,-1.5708-.6283*fetchTimer)
|
gc_arc('fill','pie',250,630,40,-1.5708,-1.5708-.6283*fetchTimer)
|
||||||
|
|
||||||
--Joining mark
|
--Joining mark
|
||||||
if NET.getlock('enterRoom')then
|
if TASK.getLock('enterRoom')then
|
||||||
gc.setColor(COLOR.Z)
|
gc.setColor(COLOR.Z)
|
||||||
gc.setLineWidth(15)
|
gc.setLineWidth(15)
|
||||||
local t=TIME()*6.26%6.2832
|
local t=TIME()*6.26%6.2832
|
||||||
@@ -135,11 +135,11 @@ scene.widgetList={
|
|||||||
roomList,
|
roomList,
|
||||||
passwordBox,
|
passwordBox,
|
||||||
WIDGET.newKey{name='setting', x=1200,y=160,w=90,h=90,font=60,fText=CHAR.icon.settings,code=goScene'setting_game'},
|
WIDGET.newKey{name='setting', x=1200,y=160,w=90,h=90,font=60,fText=CHAR.icon.settings,code=goScene'setting_game'},
|
||||||
WIDGET.newText{name='refreshing',x=450,y=240,font=45,hideF=function()return not NET.getlock('fetchRoom')end},
|
WIDGET.newText{name='refreshing',x=450,y=240,font=45,hideF=function()return not TASK.getLock('fetchRoom')end},
|
||||||
WIDGET.newText{name='noRoom', x=450,y=245,font=40,hideF=function()return roomList:getLen()>0 or NET.getlock('fetchRoom')end},
|
WIDGET.newText{name='noRoom', x=450,y=245,font=40,hideF=function()return roomList:getLen()>0 or TASK.getLock('fetchRoom')end},
|
||||||
WIDGET.newKey{name='refresh', x=250,y=630,w=140,h=120,code=_fetchRoom,hideF=function()return fetchTimer>7 end},
|
WIDGET.newKey{name='refresh', x=250,y=630,w=140,h=120,code=_fetchRoom,hideF=function()return fetchTimer>7 end},
|
||||||
WIDGET.newKey{name='new', x=510,y=630,w=260,h=120,code=goScene'net_newRoom'},
|
WIDGET.newKey{name='new', x=510,y=630,w=260,h=120,code=goScene'net_newRoom'},
|
||||||
WIDGET.newKey{name='join', x=780,y=630,w=140,h=120,code=pressKey'join',hideF=function()return roomList:getLen()==0 or NET.getlock('enterRoom')end},
|
WIDGET.newKey{name='join', x=780,y=630,w=140,h=120,code=pressKey'join',hideF=function()return roomList:getLen()==0 or TASK.getLock('enterRoom')end},
|
||||||
WIDGET.newButton{name='back', x=1140,y=640,w=170,h=80,sound='back',font=60,fText=CHAR.icon.back,code=pressKey'escape'},
|
WIDGET.newButton{name='back', x=1140,y=640,w=170,h=80,sound='back',font=60,fText=CHAR.icon.back,code=pressKey'escape'},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user