将一些游戏相关socket消息处理移至场景外
This commit is contained in:
@@ -318,6 +318,7 @@ function NET.updateWS_play()
|
||||
else
|
||||
local res=_parse(message)
|
||||
if res then
|
||||
local d=res.data
|
||||
if res.type=="Connect"then
|
||||
SCN.go("net_menu")
|
||||
_unlock("wsc_play")
|
||||
@@ -327,7 +328,6 @@ function NET.updateWS_play()
|
||||
elseif res.action==1 then--Create room (not used)
|
||||
--?
|
||||
elseif res.action==2 then--Player join
|
||||
local d=res.data
|
||||
if res.type=="Self"then
|
||||
--Create room
|
||||
TABLE.clear(PLY_NET)
|
||||
@@ -363,7 +363,6 @@ function NET.updateWS_play()
|
||||
SCN.socketRead("Join",res.data)
|
||||
end
|
||||
elseif res.action==3 then--Player leave
|
||||
local d=res.data
|
||||
for i=1,#PLY_NET do
|
||||
if PLY_NET[i].uid==d.uid then
|
||||
rem(PLY_NET,i)
|
||||
@@ -386,14 +385,40 @@ function NET.updateWS_play()
|
||||
elseif res.action==4 then--Player talk
|
||||
SCN.socketRead("Talk",res.data)
|
||||
elseif res.action==5 then--Player change settings
|
||||
SCN.socketRead("Config",res.data)
|
||||
elseif res.action==6 then--Player ready
|
||||
SCN.socketRead("Ready",res.data)
|
||||
_unlock("ready")
|
||||
elseif res.action==7 then--All ready
|
||||
if tostring(USER.uid)~=d.uid then
|
||||
for i=1,#PLY_NET do
|
||||
if PLY_NET[i].uid==d.uid then
|
||||
PLY_NET[i].conf=d.config
|
||||
PLY_NET[i].p:setConf(d.config)
|
||||
return
|
||||
end
|
||||
end
|
||||
resetGameData("qn")
|
||||
end
|
||||
elseif res.action==6 then--One ready
|
||||
if d.uid==USER.uid then
|
||||
if PLAYERS[1].ready~=d.ready then
|
||||
PLAYERS[1].ready=d.ready
|
||||
SFX.play("reach",.6)
|
||||
end
|
||||
_unlock("ready")
|
||||
else
|
||||
for i=1,#PLAYERS do
|
||||
if PLAYERS[i].userID==d.uid then
|
||||
if PLAYERS[i].ready~=d.ready then
|
||||
PLAYERS[i].ready=d.ready
|
||||
SFX.play("reach",.6)
|
||||
end
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif res.action==7 then--Ready
|
||||
--?
|
||||
elseif res.action==8 then--Sure ready
|
||||
SCN.socketRead("Set",res.data)
|
||||
elseif res.action==8 then--Set
|
||||
NET.rsid=d.rid
|
||||
NET.wsconn_stream()
|
||||
TASK.new(NET.updateWS_stream)
|
||||
elseif res.action==9 then--Game finished
|
||||
SCN.socketRead("Finish",res.data)
|
||||
NET.wsclose_stream()
|
||||
@@ -425,7 +450,7 @@ function NET.updateWS_stream()
|
||||
if res.type=="Connect"then
|
||||
_unlock("wsc_stream")
|
||||
elseif res.action==0 then--Game start
|
||||
SCN.socketRead("Begin",res.data)
|
||||
SCN.socketRead("Go",res.data)
|
||||
elseif res.action==1 then--Game finished
|
||||
--?
|
||||
elseif res.action==2 then--Player join
|
||||
|
||||
@@ -135,11 +135,11 @@ function scene.gamepadUp(key)
|
||||
end
|
||||
end
|
||||
|
||||
function scene.socketRead(cmd,data)
|
||||
function scene.socketRead(cmd,d)
|
||||
if cmd=="Join"then
|
||||
textBox:push{
|
||||
COLOR.lR,data.username,
|
||||
COLOR.dY,"#"..data.uid.." ",
|
||||
COLOR.lR,d.username,
|
||||
COLOR.dY,"#"..d.uid.." ",
|
||||
COLOR.Y,text.joinRoom,
|
||||
}
|
||||
SFX.play("click")
|
||||
@@ -148,8 +148,8 @@ function scene.socketRead(cmd,data)
|
||||
end
|
||||
elseif cmd=="Leave"then
|
||||
textBox:push{
|
||||
COLOR.lR,data.username,
|
||||
COLOR.dY,"#"..data.uid.." ",
|
||||
COLOR.lR,d.username,
|
||||
COLOR.dY,"#"..d.uid.." ",
|
||||
COLOR.Y,text.leaveRoom,
|
||||
}
|
||||
if not playing then
|
||||
@@ -157,48 +157,16 @@ function scene.socketRead(cmd,data)
|
||||
end
|
||||
elseif cmd=="Talk"then
|
||||
textBox:push{
|
||||
COLOR.W,data.username,
|
||||
COLOR.dY,"#"..data.uid.." ",
|
||||
COLOR.sky,data.message or"[_]",
|
||||
COLOR.W,d.username,
|
||||
COLOR.dY,"#"..d.uid.." ",
|
||||
COLOR.sky,d.message or"[_]",
|
||||
}
|
||||
elseif cmd=="Config"then
|
||||
if tostring(USER.uid)~=data.uid then
|
||||
for i=1,#PLY_NET do
|
||||
if PLY_NET[i].uid==data.uid then
|
||||
PLY_NET[i].conf=data.config
|
||||
PLY_NET[i].p:setConf(data.config)
|
||||
return
|
||||
end
|
||||
end
|
||||
resetGameData("qn")
|
||||
end
|
||||
elseif cmd=="Ready"then
|
||||
if data.uid==USER.uid then
|
||||
if PLAYERS[1].ready~=data.ready then
|
||||
PLAYERS[1].ready=data.ready
|
||||
SFX.play("reach",.6)
|
||||
end
|
||||
else
|
||||
for i=1,#PLAYERS do
|
||||
if PLAYERS[i].userID==data.uid then
|
||||
if PLAYERS[i].ready~=data.ready then
|
||||
PLAYERS[i].ready=data.ready
|
||||
SFX.play("reach",.6)
|
||||
end
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif cmd=="Set"then
|
||||
NET.rsid=data.rid
|
||||
NET.wsconn_stream()
|
||||
TASK.new(NET.updateWS_stream)
|
||||
elseif cmd=="Begin"then
|
||||
elseif cmd=="Go"then
|
||||
if not playing then
|
||||
playing=true
|
||||
lastUpstreamTime=0
|
||||
upstreamProgress=1
|
||||
resetGameData("n",data.seed)
|
||||
resetGameData("n",d.seed)
|
||||
else
|
||||
LOG.print("Redundant signal: Begin",30,COLOR.green)
|
||||
end
|
||||
@@ -206,24 +174,24 @@ function scene.socketRead(cmd,data)
|
||||
playing=false
|
||||
resetGameData("n")
|
||||
local winnerUID
|
||||
for _,p in next,data.result do
|
||||
for _,p in next,d.result do
|
||||
if p.place==1 then
|
||||
winnerUID=p.uid
|
||||
break
|
||||
end
|
||||
end
|
||||
if not winnerUID then return end
|
||||
for _,d in next,PLY_NET do
|
||||
if d.uid==winnerUID then
|
||||
TEXT.show(text.champion:gsub("$1",d.username),640,260,80,"zoomout",.26)
|
||||
for _,p in next,PLY_NET do
|
||||
if p.uid==winnerUID then
|
||||
TEXT.show(text.champion:gsub("$1",p.username),640,260,80,"zoomout",.26)
|
||||
break
|
||||
end
|
||||
end
|
||||
elseif cmd=="Stream"then
|
||||
if data.uid~=USER.uid and playing then
|
||||
if d.uid~=USER.uid and playing then
|
||||
for _,P in next,PLAYERS do
|
||||
if P.userID==data.uid then
|
||||
local res,stream=pcall(love.data.decode,"string","base64",data.stream)
|
||||
if P.userID==d.uid then
|
||||
local res,stream=pcall(love.data.decode,"string","base64",d.stream)
|
||||
if res then
|
||||
pumpRecording(stream,P.stream)
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user