【不能用】继续改联网,更新ws相关,完善断开后的行为与提示
框架跟进
This commit is contained in:
Submodule Zframework updated: 325168c2c1...503bba44a4
5
main.lua
5
main.lua
@@ -177,6 +177,11 @@ Z.setOnFnKeys({
|
|||||||
function()for k,v in next,_G do print(k,v)end end,
|
function()for k,v in next,_G do print(k,v)end end,
|
||||||
function()if love['_openConsole']then love['_openConsole']()end end,
|
function()if love['_openConsole']then love['_openConsole']()end end,
|
||||||
})
|
})
|
||||||
|
Z.setOnGlobalKey('f11',function()
|
||||||
|
SETTING.fullscreen=not SETTING.fullscreen
|
||||||
|
applySettings()
|
||||||
|
saveSettings()
|
||||||
|
end)
|
||||||
Z.setVersionText(VERSION.string)
|
Z.setVersionText(VERSION.string)
|
||||||
Z.setDebugInfo{
|
Z.setDebugInfo{
|
||||||
{"Cache",gcinfo},
|
{"Cache",gcinfo},
|
||||||
|
|||||||
@@ -121,10 +121,10 @@ return{
|
|||||||
loginOK="You are now logged in!",
|
loginOK="You are now logged in!",
|
||||||
accessOK="Access granted",
|
accessOK="Access granted",
|
||||||
|
|
||||||
wsConnecting="Websocket connecting…",
|
|
||||||
wsFailed="WebSocket connection failed",
|
wsFailed="WebSocket connection failed",
|
||||||
wsClose="WebSocket closed:",
|
wsClose="WebSocket closed:",
|
||||||
netTimeout="Connection timed out",
|
netTimeout="Connection timed out",
|
||||||
|
serverDown="Oops! Server is down",
|
||||||
|
|
||||||
onlinePlayerCount="Online",
|
onlinePlayerCount="Online",
|
||||||
createRoomSuccessed="Room created",
|
createRoomSuccessed="Room created",
|
||||||
|
|||||||
@@ -120,10 +120,10 @@ return{
|
|||||||
loginOK="¡Ingreso con éxito!",
|
loginOK="¡Ingreso con éxito!",
|
||||||
accessOK="¡Autorizado exitoso!",
|
accessOK="¡Autorizado exitoso!",
|
||||||
|
|
||||||
wsConnecting="Websocket Conectando",
|
|
||||||
wsFailed="WebSocket conexión fallida",
|
wsFailed="WebSocket conexión fallida",
|
||||||
wsClose="WebSocket cerrado:",
|
wsClose="WebSocket cerrado:",
|
||||||
netTimeout="Tiempo de conexión agotado",
|
netTimeout="Tiempo de conexión agotado",
|
||||||
|
-- serverDown="Oops! Server is down",
|
||||||
|
|
||||||
onlinePlayerCount="En línea",
|
onlinePlayerCount="En línea",
|
||||||
createRoomSuccessed="¡Sala creada con éxito!",
|
createRoomSuccessed="¡Sala creada con éxito!",
|
||||||
|
|||||||
@@ -111,10 +111,10 @@ return{
|
|||||||
loginOK="Connecté avec succès !",
|
loginOK="Connecté avec succès !",
|
||||||
accessOK="Autorisé avec succès !",
|
accessOK="Autorisé avec succès !",
|
||||||
|
|
||||||
-- wsConnecting="Websocket Connecting",
|
|
||||||
wsFailed="WebSocket connection échouée",
|
wsFailed="WebSocket connection échouée",
|
||||||
-- wsClose="WebSocket Closed:",
|
-- wsClose="WebSocket Closed:",
|
||||||
-- netTimeout="Network connection timeout",
|
-- netTimeout="Network connection timeout",
|
||||||
|
-- serverDown="Oops! Server is down",
|
||||||
|
|
||||||
-- onlinePlayerCount="Online",
|
-- onlinePlayerCount="Online",
|
||||||
createRoomSuccessed="Salon créé avec succès !",
|
createRoomSuccessed="Salon créé avec succès !",
|
||||||
|
|||||||
@@ -122,10 +122,10 @@ return{
|
|||||||
loginOK="Anda telah gabung!",
|
loginOK="Anda telah gabung!",
|
||||||
accessOK="Akses diberikan",
|
accessOK="Akses diberikan",
|
||||||
|
|
||||||
wsConnecting="Menghubungkan websocket…",
|
|
||||||
wsFailed="Koneksi websocket gagal",
|
wsFailed="Koneksi websocket gagal",
|
||||||
wsClose="Websocket tertutup:",
|
wsClose="Websocket tertutup:",
|
||||||
netTimeout="Koneksi waktu habis",
|
netTimeout="Koneksi waktu habis",
|
||||||
|
-- serverDown="Oops! Server is down",
|
||||||
|
|
||||||
onlinePlayerCount="Online",
|
onlinePlayerCount="Online",
|
||||||
createRoomSuccessed="Ruang terbuat",
|
createRoomSuccessed="Ruang terbuat",
|
||||||
|
|||||||
@@ -122,10 +122,10 @@ return{
|
|||||||
loginOK="ログインしています!",
|
loginOK="ログインしています!",
|
||||||
accessOK="アクセス権限を取得しました!",
|
accessOK="アクセス権限を取得しました!",
|
||||||
|
|
||||||
wsConnecting="ウェブソケットに接続中…",
|
|
||||||
wsFailed="ウェブソケットとの通信に失敗しました",
|
wsFailed="ウェブソケットとの通信に失敗しました",
|
||||||
wsClose="ウェブソケットとの通信を終了:",
|
wsClose="ウェブソケットとの通信を終了:",
|
||||||
netTimeout="接続がタイムアウトしました",
|
netTimeout="接続がタイムアウトしました",
|
||||||
|
-- serverDown="Oops! Server is down",
|
||||||
|
|
||||||
onlinePlayerCount="オンライン人数",
|
onlinePlayerCount="オンライン人数",
|
||||||
createRoomSuccessed="部屋を建てました",
|
createRoomSuccessed="部屋を建てました",
|
||||||
|
|||||||
@@ -109,10 +109,10 @@ return{
|
|||||||
loginOK="Logado com sucesso!",
|
loginOK="Logado com sucesso!",
|
||||||
accessOK="Autorizado com sucesso!",
|
accessOK="Autorizado com sucesso!",
|
||||||
|
|
||||||
-- wsConnecting="Websocket Connecting",
|
|
||||||
wsFailed="WebSocket falha na conexão",
|
wsFailed="WebSocket falha na conexão",
|
||||||
wsClose="WebSocket closed:",
|
wsClose="WebSocket closed:",
|
||||||
-- netTimeout="Network connection timeout",
|
-- netTimeout="Network connection timeout",
|
||||||
|
-- serverDown="Oops! Server is down",
|
||||||
|
|
||||||
-- onlinePlayerCount="Online",
|
-- onlinePlayerCount="Online",
|
||||||
-- createRoomSuccessed="Room successfully created!",
|
-- createRoomSuccessed="Room successfully created!",
|
||||||
|
|||||||
@@ -121,10 +121,10 @@ return{
|
|||||||
loginOK="登录成功",
|
loginOK="登录成功",
|
||||||
accessOK="身份验证成功",
|
accessOK="身份验证成功",
|
||||||
|
|
||||||
wsConnecting="正在连接",
|
|
||||||
wsFailed="连接失败",
|
wsFailed="连接失败",
|
||||||
wsClose="连接被断开:",
|
wsClose="连接被断开:",
|
||||||
netTimeout="连接超时",
|
netTimeout="连接超时",
|
||||||
|
serverDown="唉哟!服务器不在线",
|
||||||
|
|
||||||
onlinePlayerCount="在线人数",
|
onlinePlayerCount="在线人数",
|
||||||
createRoomSuccessed="创建房间成功!",
|
createRoomSuccessed="创建房间成功!",
|
||||||
|
|||||||
@@ -121,10 +121,10 @@ return{
|
|||||||
loginOK="login.Success=true",
|
loginOK="login.Success=true",
|
||||||
accessOK="Access.Granted=true",
|
accessOK="Access.Granted=true",
|
||||||
|
|
||||||
wsConnecting="Websocket.Connect();",
|
|
||||||
wsFailed="Error.Websocket.Failed();",
|
wsFailed="Error.Websocket.Failed();",
|
||||||
wsClose="Error.Websocket.Close=",
|
wsClose="Error.Websocket.Close=",
|
||||||
netTimeout="Error.ConnectTimeOut();",
|
netTimeout="Error.ConnectTimeOut();",
|
||||||
|
serverDown="Error.ServerDown();",
|
||||||
|
|
||||||
onlinePlayerCount="OnlinePlayerCount",
|
onlinePlayerCount="OnlinePlayerCount",
|
||||||
createRoomSuccessed="CreateRoom.Successs=true",
|
createRoomSuccessed="CreateRoom.Successs=true",
|
||||||
|
|||||||
@@ -121,10 +121,10 @@ return{
|
|||||||
loginOK="登錄成功",
|
loginOK="登錄成功",
|
||||||
accessOK="身份認證成功",
|
accessOK="身份認證成功",
|
||||||
|
|
||||||
wsConnecting="正在連接……",
|
|
||||||
wsFailed="連接失敗",
|
wsFailed="連接失敗",
|
||||||
wsClose="連接斷開:",
|
wsClose="連接斷開:",
|
||||||
netTimeout="連接超時",
|
netTimeout="連接超時",
|
||||||
|
serverDown="哎唷!服務器不在线",
|
||||||
|
|
||||||
onlinePlayerCount="在線用戶數",
|
onlinePlayerCount="在線用戶數",
|
||||||
createRoomSuccessed="房間已創建!",
|
createRoomSuccessed="房間已創建!",
|
||||||
|
|||||||
@@ -27,36 +27,6 @@ local NET={
|
|||||||
onlineCount="_",
|
onlineCount="_",
|
||||||
}
|
}
|
||||||
|
|
||||||
local mesType={
|
|
||||||
Connect=true,
|
|
||||||
Self=true,
|
|
||||||
Broadcast=true,
|
|
||||||
Private=true,
|
|
||||||
Server=true,
|
|
||||||
}
|
|
||||||
|
|
||||||
--Parse json message
|
|
||||||
local function _parse(res)
|
|
||||||
res=JSON.decode(res)
|
|
||||||
if res then
|
|
||||||
if mesType[res.type]then
|
|
||||||
return res
|
|
||||||
else
|
|
||||||
MES.new('warn',("[%s] %s"):format(res.type or"?",res.reason or"[NO Message]"))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--WS close message
|
|
||||||
local function _closeMessage(message)
|
|
||||||
local mes=JSON.decode(message)
|
|
||||||
if mes then
|
|
||||||
MES.new('info',("%s %s|%s"):format(text.wsClose,mes.type or"",mes.reason or""))
|
|
||||||
else
|
|
||||||
MES.new('info',("%s %s"):format(text.wsClose,message))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--------------------------<NEW HTTP API>
|
--------------------------<NEW HTTP API>
|
||||||
@@ -69,7 +39,7 @@ local function getMsg(request,timeout)
|
|||||||
if type(mes.body)=='string' and #mes.body>0 then
|
if type(mes.body)=='string' and #mes.body>0 then
|
||||||
return JSON.decode(mes.body)
|
return JSON.decode(mes.body)
|
||||||
else
|
else
|
||||||
MES.new('info',"Oops! Server is down")
|
MES.new('info',text.serverDown)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@@ -98,7 +68,7 @@ function NET.getCode(email)
|
|||||||
MES.new('error',res.message,5)
|
MES.new('error',res.message,5)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
MES.new('warn',"Request failed",5)
|
MES.new('warn',text.requestFailed,5)
|
||||||
end
|
end
|
||||||
|
|
||||||
WAIT.interrupt()
|
WAIT.interrupt()
|
||||||
@@ -138,7 +108,7 @@ function NET.codeLogin(code)
|
|||||||
MES.new('error',res.message,5)
|
MES.new('error',res.message,5)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
MES.new('warn',"Request failed",5)
|
MES.new('warn',text.requestFailed,5)
|
||||||
end
|
end
|
||||||
|
|
||||||
WAIT.interrupt()
|
WAIT.interrupt()
|
||||||
@@ -176,7 +146,7 @@ function NET.setPW(code,pw)
|
|||||||
MES.new('error',res.message,5)
|
MES.new('error',res.message,5)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
MES.new('warn',"Request failed",5)
|
MES.new('warn',text.requestFailed,5)
|
||||||
end
|
end
|
||||||
|
|
||||||
WAIT.interrupt()
|
WAIT.interrupt()
|
||||||
@@ -229,7 +199,6 @@ function NET.autoLogin()
|
|||||||
USER.rToken=res.data.refreshToken
|
USER.rToken=res.data.refreshToken
|
||||||
USER.aToken=res.data.accessToken
|
USER.aToken=res.data.accessToken
|
||||||
NET.connectWS()
|
NET.connectWS()
|
||||||
MES.new('info',"Login successed",5)
|
|
||||||
SCN.go('net_menu')
|
SCN.go('net_menu')
|
||||||
WAIT.interrupt()
|
WAIT.interrupt()
|
||||||
return
|
return
|
||||||
@@ -251,7 +220,6 @@ function NET.autoLogin()
|
|||||||
},
|
},
|
||||||
},6.26)
|
},6.26)
|
||||||
if res then
|
if res then
|
||||||
print(TABLE.dump(res))
|
|
||||||
if res.code==200 then
|
if res.code==200 then
|
||||||
USER.rToken=res.data.refreshToken
|
USER.rToken=res.data.refreshToken
|
||||||
USER.aToken=res.data.accessToken
|
USER.aToken=res.data.accessToken
|
||||||
@@ -305,7 +273,7 @@ function NET.pwLogin(email,pw)
|
|||||||
MES.new('error',res.message,5)
|
MES.new('error',res.message,5)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
MES.new('warn',"Request failed",5)
|
MES.new('warn',text.requestFailed,5)
|
||||||
end
|
end
|
||||||
|
|
||||||
WAIT.interrupt()
|
WAIT.interrupt()
|
||||||
@@ -321,6 +289,7 @@ end
|
|||||||
|
|
||||||
--------------------------<NEW WS API>
|
--------------------------<NEW WS API>
|
||||||
local function wsSend(act,data)
|
local function wsSend(act,data)
|
||||||
|
-- print("SEND ACT: "..act)
|
||||||
WS.send('game',JSON.encode{
|
WS.send('game',JSON.encode{
|
||||||
action=act,
|
action=act,
|
||||||
data=data,
|
data=data,
|
||||||
@@ -454,9 +423,7 @@ end
|
|||||||
--WS
|
--WS
|
||||||
function NET.connectWS()
|
function NET.connectWS()
|
||||||
if WS.status('game')=='dead'then
|
if WS.status('game')=='dead'then
|
||||||
WS.connect('game','',{
|
WS.connect('game','',{['x-access-token']=USER.aToken},6)
|
||||||
['x-access-token']=USER.aToken,
|
|
||||||
},6)
|
|
||||||
TASK.new(NET.updateWS)
|
TASK.new(NET.updateWS)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -471,13 +438,19 @@ function NET.updateWS()
|
|||||||
if op=='ping'then
|
if op=='ping'then
|
||||||
elseif op=='pong'then
|
elseif op=='pong'then
|
||||||
elseif op=='close'then
|
elseif op=='close'then
|
||||||
_closeMessage(message)
|
local res=JSON.decode(message)
|
||||||
|
MES.new('info',("$1 $2"):repD(text.wsClose,res and res.message or message))
|
||||||
|
if res and res.message then LOG(res.message) end
|
||||||
|
TEST.yieldUntilNextScene()
|
||||||
|
while SCN.stack[#SCN.stack-1]~='main' do SCN.pop() end
|
||||||
|
SCN.back()
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
local res=_parse(message)
|
local res=JSON.decode(message)
|
||||||
if res then
|
if res then
|
||||||
if res.type=='Connect'then
|
-- print(("RECV ACT: $1 ($2)"):repD(res.action,res.type))
|
||||||
MES.new('info','Connected!')
|
if res.type=='Failed' then
|
||||||
|
MES.new('warn',"Request failed: "..(res.reason or "/"))
|
||||||
elseif res.action==1100 then-- TODO
|
elseif res.action==1100 then-- TODO
|
||||||
elseif res.action==1101 then-- TODO
|
elseif res.action==1101 then-- TODO
|
||||||
elseif res.action==1102 then-- TODO
|
elseif res.action==1102 then-- TODO
|
||||||
|
|||||||
Reference in New Issue
Block a user