整理代码习惯,常量字符串改用单引号,可能有遗漏

This commit is contained in:
MrZ626
2021-04-30 01:00:22 +08:00
parent 7676f32cf2
commit eda6c0d746
213 changed files with 2503 additions and 2499 deletions

View File

@@ -58,7 +58,7 @@ local function _parse(res)
)or
"[NO Message]"
),
"warn")
'warn')
end
end
end
@@ -67,44 +67,44 @@ end
local function wsCloseMessage(message)
local mes=JSON.decode(message)
if mes then
LOG.print(("%s [%s] %s"):format(text.wsClose,mes.type or"unknown type",mes.reason or""),"warn")
LOG.print(("%s [%s] %s"):format(text.wsClose,mes.type or"unknown type",mes.reason or""),'warn')
else
LOG.print(text.wsClose.."","warn")
LOG.print(text.wsClose.."",'warn')
end
end
--Connect
function NET.wsconn_app()
WS.connect("app","/app")
WS.connect('app','/app')
end
function NET.wsconn_user_pswd(email,password)
if NET.lock("wsc_user",5)then
WS.connect("user","/user",JSON.encode{
if NET.lock('wsc_user',5)then
WS.connect('user','/user',JSON.encode{
email=email,
password=password,
})
end
end
function NET.wsconn_user_token(uid,authToken)
if NET.lock("wsc_user",5)then
WS.connect("user","/user",JSON.encode{
if NET.lock('wsc_user',5)then
WS.connect('user','/user',JSON.encode{
uid=uid,
authToken=authToken,
})
end
end
function NET.wsconn_play()
if NET.lock("wsc_play",5)then
WS.connect("play","/play",JSON.encode{
if NET.lock('wsc_play',5)then
WS.connect('play','/play',JSON.encode{
uid=USER.uid,
accessToken=NET.accessToken,
})
end
end
function NET.wsconn_stream()
if NET.lock("wsc_stream",5)then
if NET.lock('wsc_stream',5)then
NET.serverGaming=true
WS.connect("stream","/stream",JSON.encode{
WS.connect('stream','/stream',JSON.encode{
uid=USER.uid,
accessToken=NET.accessToken,
rid=NET.rsid,
@@ -114,18 +114,18 @@ function NET.wsconn_stream()
end
--Disconnect
function NET.wsclose_app()WS.close("app")end
function NET.wsclose_user()WS.close("user")end
function NET.wsclose_play()WS.close("play")end
function NET.wsclose_app()WS.close('app')end
function NET.wsclose_user()WS.close('user')end
function NET.wsclose_play()WS.close('play')end
function NET.wsclose_stream()
NET.serverGaming=false
WS.close("stream")
WS.close('stream')
end
--Account & User
function NET.register(username,email,password)
if NET.lock("register")then
WS.send("app",JSON.encode{
if NET.lock('register')then
WS.send('app',JSON.encode{
action=2,
data={
username=username,
@@ -136,16 +136,16 @@ function NET.register(username,email,password)
end
end
function NET.pong(wsName,message)
WS.send(wsName,type(message)=="string"and message or"","pong")
WS.send(wsName,type(message)=='string'and message or"",'pong')
end
function NET.getAccessToken()
if NET.lock("access_and_login",10)then
WS.send("user",JSON.encode{action=0})
if NET.lock('access_and_login',10)then
WS.send('user',JSON.encode{action=0})
end
end
function NET.getUserInfo(uid)
local hash=(not SETTING.dataSaving or nil)and USERS.getHash(uid)
WS.send("user",JSON.encode{
WS.send('user',JSON.encode{
action=1,
data={
uid=uid,
@@ -156,8 +156,8 @@ end
--Room
function NET.fetchRoom()
if NET.lock("fetchRoom",3)then
WS.send("play",JSON.encode{
if NET.lock('fetchRoom',3)then
WS.send('play',JSON.encode{
action=0,
data={
type=nil,
@@ -168,8 +168,8 @@ function NET.fetchRoom()
end
end
function NET.createRoom(roomType,name)
if NET.lock("enterRoom",1.26)then
WS.send("play",JSON.encode{
if NET.lock('enterRoom',1.26)then
WS.send('play',JSON.encode{
action=1,
data={
type=roomType,
@@ -181,10 +181,10 @@ function NET.createRoom(roomType,name)
end
end
function NET.enterRoom(roomID,password)
if NET.lock("enterRoom",1.26)then
SFX.play("reach",.6)
if NET.lock('enterRoom',1.26)then
SFX.play('reach',.6)
NET.rid=roomID
WS.send("play",JSON.encode{
WS.send('play',JSON.encode{
action=2,
data={
rid=roomID,
@@ -197,56 +197,56 @@ end
--Play
function NET.checkPlayDisconn()
return WS.status("play")~="running"
return WS.status('play')~='running'
end
function NET.signal_quit()
if NET.lock("quit",3)then
WS.send("play",'{"action":3}')
if NET.lock('quit',3)then
WS.send('play','{"action":3}')
end
end
function NET.sendMessage(mes)
WS.send("play",'{"action":4,"data":{"message":'..mes..'}}')
WS.send('play','{"action":4,"data":{"message":'..mes..'}}')
end
function NET.changeConfig()
WS.send("play",'{"action":5,"data":'..JSON.encode({config=dumpBasicConfig()})..'}')
WS.send('play','{"action":5,"data":'..JSON.encode({config=dumpBasicConfig()})..'}')
end
function NET.signal_ready(ready)
if NET.lock("ready",3)and not NET.serverGaming then
WS.send("play",'{"action":6,"data":{"ready":'..tostring(ready)..'}}')
if NET.lock('ready',3)and not NET.serverGaming then
WS.send('play','{"action":6,"data":{"ready":'..tostring(ready)..'}}')
end
end
function NET.signal_die()
WS.send("stream",'{"action":4,"data":{"score":0,"survivalTime":0}}')
WS.send('stream','{"action":4,"data":{"score":0,"survivalTime":0}}')
end
function NET.uploadRecStream(stream)
WS.send("stream",'{"action":5,"data":{"stream":"'..data.encode("string","base64",stream)..'"}}')
WS.send('stream','{"action":5,"data":{"stream":"'..data.encode('string','base64',stream)..'"}}')
end
--Chat
function NET.sendChatMes(mes)
WS.send("chat","T"..data.encode("string","base64",mes))
WS.send('chat',"T"..data.encode('string','base64',mes))
end
function NET.quitChat()
WS.send("chat","Q")
WS.send('chat','q')
end
--WS tick funcs
function NET.updateWS_app()
while true do
YIELD()
if WS.status("app")=="running"then
local message,op=WS.read("app")
if WS.status('app')=='running'then
local message,op=WS.read('app')
if message then
if op=="ping"then
NET.pong("app",message)
elseif op=="pong"then
elseif op=="close"then
if op=='ping'then
NET.pong('app',message)
elseif op=='pong'then
elseif op=='close'then
wsCloseMessage(message)
return
else
local res=_parse(message)
if res then
if res.type=="Connect"then
if res.type=='Connect'then
NET.connected=true
if VERSION.code>=res.lowest then
NET.allow_online=true
@@ -263,18 +263,18 @@ function NET.updateWS_app()
elseif res.action==1 then--Get notice
--?
elseif res.action==2 then--Register
if res.type=="Self"or res.type=="Server"then
if res.type=='Self'or res.type=='Server'then
LOG.print(res.data.message,300,COLOR.N)
if SCN.cur=="register"then
if SCN.cur=='register'then
SCN.back()
end
else
LOG.print(res.reason or"Registration failed",300,COLOR.N)
end
NET.unlock("register")
NET.unlock('register')
end
else
WS.alert("app")
WS.alert('app')
end
end
end
@@ -284,30 +284,30 @@ end
function NET.updateWS_user()
while true do
YIELD()
if WS.status("user")=="running"then
local message,op=WS.read("user")
if WS.status('user')=='running'then
local message,op=WS.read('user')
if message then
if op=="ping"then
NET.pong("user",message)
elseif op=="pong"then
elseif op=="close"then
if op=='ping'then
NET.pong('user',message)
elseif op=='pong'then
elseif op=='close'then
wsCloseMessage(message)
return
else
local res=_parse(message)
if res then
if res.type=="Connect"then
if res.type=='Connect'then
if res.uid then
USER.uid=res.uid
USER.authToken=res.authToken
FILE.save(USER,"conf/user","q")
if SCN.cur=="login"then SCN.back()end
FILE.save(USER,"conf/user",'q')
if SCN.cur=='login'then SCN.back()end
end
LOG.print(text.loginSuccessed)
--Get self infos
NET.getUserInfo(USER.uid)
NET.unlock("wsc_user")
NET.unlock('wsc_user')
elseif res.action==0 then--Get accessToken
NET.accessToken=res.accessToken
LOG.print(text.accessSuccessed)
@@ -316,7 +316,7 @@ function NET.updateWS_user()
USERS.updateUserData(res.data)
end
else
WS.alert("user")
WS.alert('user')
end
end
end
@@ -326,30 +326,30 @@ end
function NET.updateWS_play()
while true do
YIELD()
if WS.status("play")=="running"then
local message,op=WS.read("play")
if WS.status('play')=='running'then
local message,op=WS.read('play')
if message then
if op=="ping"then
NET.pong("play",message)
elseif op=="pong"then
elseif op=="close"then
if op=='ping'then
NET.pong('play',message)
elseif op=='pong'then
elseif op=='close'then
wsCloseMessage(message)
return
else
local res=_parse(message)
if res then
local d=res.data
if res.type=="Connect"then
SCN.go("net_menu")
NET.unlock("wsc_play")
NET.unlock("access_and_login")
if res.type=='Connect'then
SCN.go('net_menu')
NET.unlock('wsc_play')
NET.unlock('access_and_login')
elseif res.action==0 then--Fetch rooms
NET.roomList=res.roomList
NET.unlock("fetchRoom")
NET.unlock('fetchRoom')
elseif res.action==1 then--Create room (not used)
--?
elseif res.action==2 then--Player join
if res.type=="Self"then
if res.type=='Self'then
--Create room
TABLE.cut(PLY_NET)
if d.players then
@@ -363,7 +363,7 @@ function NET.updateWS_play()
})
end
end
loadGame("netBattle",true,true)
loadGame('netBattle',true,true)
else
--Load other players
ins(PLY_NET,{
@@ -379,7 +379,7 @@ function NET.updateWS_play()
if not d.uid then
NET.wsclose_stream()
SCN.back()
NET.unlock("quit")
NET.unlock('quit')
else
for i=1,#PLY_NET do
if PLY_NET[i].sid==d.sid then
@@ -418,16 +418,16 @@ function NET.updateWS_play()
if p.ready~=d.ready then
p.ready=d.ready
if not d.ready then NET.allReady=false end
SFX.play("spin_0",.6)
SFX.play('spin_0',.6)
if i==1 then
NET.unlock("ready")
NET.unlock('ready')
elseif not PLY_NET[1].ready then
for j=2,#PLY_NET do
if not PLY_NET[j].ready then
goto BREAK_notAllReady
end
end
SFX.play("blip_2",.5)
SFX.play('blip_2',.5)
::BREAK_notAllReady::
end
end
@@ -435,7 +435,7 @@ function NET.updateWS_play()
end
end
elseif res.action==7 then--All Ready
SFX.play("reach",.6)
SFX.play('reach',.6)
NET.allReady=true
elseif res.action==8 then--Set
NET.rsid=d.rid
@@ -446,7 +446,7 @@ function NET.updateWS_play()
if SCN.socketRead then SCN.socketRead("Finish",d)end
end
else
WS.alert("play")
WS.alert('play')
end
end
end
@@ -456,21 +456,21 @@ end
function NET.updateWS_stream()
while true do
YIELD()
if WS.status("stream")=="running"then
local message,op=WS.read("stream")
if WS.status('stream')=='running'then
local message,op=WS.read('stream')
if message then
if op=="ping"then
NET.pong("stream",message)
elseif op=="pong"then
elseif op=="close"then
if op=='ping'then
NET.pong('stream',message)
elseif op=='pong'then
elseif op=='close'then
wsCloseMessage(message)
return
else
local res=_parse(message)
if res then
local d=res.data
if res.type=="Connect"then
NET.unlock("wsc_stream")
if res.type=='Connect'then
NET.unlock('wsc_stream')
elseif res.action==0 then--Game start
SCN.socketRead("Go",d)
elseif res.action==1 then--Game finished
@@ -490,7 +490,7 @@ function NET.updateWS_stream()
SCN.socketRead("Stream",d)
end
else
WS.alert("stream")
WS.alert('stream')
end
end
end
@@ -500,13 +500,13 @@ end
function NET.updateWS_chat()
while true do
YIELD()
if WS.status("chat")=="running"then
local message,op=WS.read("chat")
if WS.status('chat')=='running'then
local message,op=WS.read('chat')
if message then
if op=="ping"then
NET.pong("chat",message)
elseif op=="pong"then
elseif op=="close"then
if op=='ping'then
NET.pong('chat',message)
elseif op=='pong'then
elseif op=='close'then
wsCloseMessage(message)
return
else
@@ -514,7 +514,7 @@ function NET.updateWS_chat()
if res then
--TODO
else
WS.alert("chat")
WS.alert('chat')
end
end
end