简化接收网络消息的task函数,不再永久停留于任务队列中
This commit is contained in:
@@ -126,6 +126,8 @@ end
|
|||||||
--Connect
|
--Connect
|
||||||
function NET.wsconn_app()
|
function NET.wsconn_app()
|
||||||
WS.connect('app','/app')
|
WS.connect('app','/app')
|
||||||
|
TASK.new(NET.updateWS_app)
|
||||||
|
TASK.new(NET.freshPlayerCount)
|
||||||
end
|
end
|
||||||
function NET.wsconn_user_pswd(email,password)
|
function NET.wsconn_user_pswd(email,password)
|
||||||
if WS.status('wsc_user')=='dead'then NET.unlock('wsc_user')end
|
if WS.status('wsc_user')=='dead'then NET.unlock('wsc_user')end
|
||||||
@@ -134,6 +136,7 @@ function NET.wsconn_user_pswd(email,password)
|
|||||||
email=email,
|
email=email,
|
||||||
password=password,
|
password=password,
|
||||||
},6)
|
},6)
|
||||||
|
TASK.new(NET.updateWS_user)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function NET.wsconn_user_token(uid,authToken)
|
function NET.wsconn_user_token(uid,authToken)
|
||||||
@@ -143,6 +146,7 @@ function NET.wsconn_user_token(uid,authToken)
|
|||||||
uid=uid,
|
uid=uid,
|
||||||
authToken=authToken,
|
authToken=authToken,
|
||||||
},6)
|
},6)
|
||||||
|
TASK.new(NET.updateWS_user)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function NET.wsconn_play()
|
function NET.wsconn_play()
|
||||||
@@ -152,6 +156,7 @@ function NET.wsconn_play()
|
|||||||
uid=USER.uid,
|
uid=USER.uid,
|
||||||
accessToken=NET.accessToken,
|
accessToken=NET.accessToken,
|
||||||
},6)
|
},6)
|
||||||
|
TASK.new(NET.updateWS_play)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function NET.wsconn_stream(srid)
|
function NET.wsconn_stream(srid)
|
||||||
@@ -228,14 +233,6 @@ function NET.getUserInfo(uid)
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
function NET.freshPlayerCount()
|
|
||||||
while true do
|
|
||||||
for _=1,260 do yield()end
|
|
||||||
if WS.status('app')=='running'then
|
|
||||||
WS.send('app',JSON.encode{action=3})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--Save
|
--Save
|
||||||
function NET.uploadSave()
|
function NET.uploadSave()
|
||||||
@@ -383,10 +380,15 @@ function NET.quitChat()
|
|||||||
end
|
end
|
||||||
|
|
||||||
--WS tick funcs
|
--WS tick funcs
|
||||||
|
function NET.freshPlayerCount()
|
||||||
|
while WS.status('app')~='dead'do
|
||||||
|
for _=1,260 do yield()end
|
||||||
|
WS.send('app',JSON.encode{action=3})
|
||||||
|
end
|
||||||
|
end
|
||||||
function NET.updateWS_app()
|
function NET.updateWS_app()
|
||||||
while true do
|
while WS.status('app')~='dead'do
|
||||||
yield()
|
yield()
|
||||||
if WS.status('app')=='running'then
|
|
||||||
local message,op=WS.read('app')
|
local message,op=WS.read('app')
|
||||||
if message then
|
if message then
|
||||||
if op=='ping'then
|
if op=='ping'then
|
||||||
@@ -439,11 +441,9 @@ function NET.updateWS_app()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
function NET.updateWS_user()
|
function NET.updateWS_user()
|
||||||
while true do
|
while WS.status('user')~='dead'do
|
||||||
yield()
|
yield()
|
||||||
if WS.status('user')=='running'then
|
|
||||||
local message,op=WS.read('user')
|
local message,op=WS.read('user')
|
||||||
if message then
|
if message then
|
||||||
if op=='ping'then
|
if op=='ping'then
|
||||||
@@ -488,11 +488,9 @@ function NET.updateWS_user()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
function NET.updateWS_play()
|
function NET.updateWS_play()
|
||||||
while true do
|
while WS.status('play')~='dead'do
|
||||||
yield()
|
yield()
|
||||||
if WS.status('play')=='running'then
|
|
||||||
local message,op=WS.read('play')
|
local message,op=WS.read('play')
|
||||||
if message then
|
if message then
|
||||||
if op=='ping'then
|
if op=='ping'then
|
||||||
@@ -614,11 +612,9 @@ function NET.updateWS_play()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
function NET.updateWS_stream()
|
function NET.updateWS_stream()
|
||||||
while true do
|
while WS.status('stream')~='dead'do
|
||||||
yield()
|
yield()
|
||||||
if WS.status('stream')=='running'then
|
|
||||||
local message,op=WS.read('stream')
|
local message,op=WS.read('stream')
|
||||||
if message then
|
if message then
|
||||||
if op=='ping'then
|
if op=='ping'then
|
||||||
@@ -687,11 +683,9 @@ function NET.updateWS_stream()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
function NET.updateWS_chat()
|
function NET.updateWS_chat()
|
||||||
while true do
|
while WS.status('chat')~='dead'do
|
||||||
yield()
|
yield()
|
||||||
if WS.status('chat')=='running'then
|
|
||||||
local message,op=WS.read('chat')
|
local message,op=WS.read('chat')
|
||||||
if message then
|
if message then
|
||||||
if op=='ping'then
|
if op=='ping'then
|
||||||
@@ -711,11 +705,9 @@ function NET.updateWS_chat()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
function NET.updateWS_manage()
|
function NET.updateWS_manage()
|
||||||
while true do
|
while WS.status('manage')~='dead'do
|
||||||
yield()
|
yield()
|
||||||
if WS.status('manage')=='running'then
|
|
||||||
local message,op=WS.read('manage')
|
local message,op=WS.read('manage')
|
||||||
if message then
|
if message then
|
||||||
if op=='ping'then
|
if op=='ping'then
|
||||||
@@ -747,6 +739,5 @@ function NET.updateWS_manage()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
return NET
|
return NET
|
||||||
@@ -184,11 +184,7 @@ local loadingThread=coroutine.wrap(function()
|
|||||||
STAT.run=STAT.run+1
|
STAT.run=STAT.run+1
|
||||||
|
|
||||||
--Connect to server
|
--Connect to server
|
||||||
TASK.new(NET.updateWS_app)
|
|
||||||
TASK.new(NET.updateWS_user)
|
|
||||||
TASK.new(NET.updateWS_play)
|
|
||||||
NET.wsconn_app()
|
NET.wsconn_app()
|
||||||
TASK.new(NET.freshPlayerCount)
|
|
||||||
YIELD()
|
YIELD()
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
|
|||||||
Reference in New Issue
Block a user