【不能用】继续改联网,更新ws相关,完善断开后的行为与提示

框架跟进
This commit is contained in:
MrZ_26
2022-09-29 10:07:39 +08:00
parent 2491a436c2
commit d259e05ca7
12 changed files with 32 additions and 54 deletions

View File

@@ -177,6 +177,11 @@ Z.setOnFnKeys({
function()for k,v in next,_G do print(k,v)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.setDebugInfo{
{"Cache",gcinfo},

View File

@@ -121,10 +121,10 @@ return{
loginOK="You are now logged in!",
accessOK="Access granted",
wsConnecting="Websocket connecting…",
wsFailed="WebSocket connection failed",
wsClose="WebSocket closed:",
netTimeout="Connection timed out",
serverDown="Oops! Server is down",
onlinePlayerCount="Online",
createRoomSuccessed="Room created",

View File

@@ -120,10 +120,10 @@ return{
loginOK="¡Ingreso con éxito!",
accessOK="¡Autorizado exitoso!",
wsConnecting="Websocket Conectando",
wsFailed="WebSocket conexión fallida",
wsClose="WebSocket cerrado:",
netTimeout="Tiempo de conexión agotado",
-- serverDown="Oops! Server is down",
onlinePlayerCount="En línea",
createRoomSuccessed="¡Sala creada con éxito!",

View File

@@ -111,10 +111,10 @@ return{
loginOK="Connecté avec succès !",
accessOK="Autorisé avec succès !",
-- wsConnecting="Websocket Connecting",
wsFailed="WebSocket connection échouée",
-- wsClose="WebSocket Closed:",
-- netTimeout="Network connection timeout",
-- serverDown="Oops! Server is down",
-- onlinePlayerCount="Online",
createRoomSuccessed="Salon créé avec succès !",

View File

@@ -122,10 +122,10 @@ return{
loginOK="Anda telah gabung!",
accessOK="Akses diberikan",
wsConnecting="Menghubungkan websocket…",
wsFailed="Koneksi websocket gagal",
wsClose="Websocket tertutup:",
netTimeout="Koneksi waktu habis",
-- serverDown="Oops! Server is down",
onlinePlayerCount="Online",
createRoomSuccessed="Ruang terbuat",

View File

@@ -122,10 +122,10 @@ return{
loginOK="ログインしています!",
accessOK="アクセス権限を取得しました!",
wsConnecting="ウェブソケットに接続中…",
wsFailed="ウェブソケットとの通信に失敗しました",
wsClose="ウェブソケットとの通信を終了:",
netTimeout="接続がタイムアウトしました",
-- serverDown="Oops! Server is down",
onlinePlayerCount="オンライン人数",
createRoomSuccessed="部屋を建てました",

View File

@@ -109,10 +109,10 @@ return{
loginOK="Logado com sucesso!",
accessOK="Autorizado com sucesso!",
-- wsConnecting="Websocket Connecting",
wsFailed="WebSocket falha na conexão",
wsClose="WebSocket closed:",
-- netTimeout="Network connection timeout",
-- serverDown="Oops! Server is down",
-- onlinePlayerCount="Online",
-- createRoomSuccessed="Room successfully created!",

View File

@@ -121,10 +121,10 @@ return{
loginOK="登录成功",
accessOK="身份验证成功",
wsConnecting="正在连接",
wsFailed="连接失败",
wsClose="连接被断开:",
netTimeout="连接超时",
serverDown="唉哟!服务器不在线",
onlinePlayerCount="在线人数",
createRoomSuccessed="创建房间成功!",

View File

@@ -121,10 +121,10 @@ return{
loginOK="login.Success=true",
accessOK="Access.Granted=true",
wsConnecting="Websocket.Connect();",
wsFailed="Error.Websocket.Failed();",
wsClose="Error.Websocket.Close=",
netTimeout="Error.ConnectTimeOut();",
serverDown="Error.ServerDown();",
onlinePlayerCount="OnlinePlayerCount",
createRoomSuccessed="CreateRoom.Successs=true",

View File

@@ -121,10 +121,10 @@ return{
loginOK="登錄成功",
accessOK="身份認證成功",
wsConnecting="正在連接……",
wsFailed="連接失敗",
wsClose="連接斷開:",
netTimeout="連接超時",
serverDown="哎唷!服務器不在线",
onlinePlayerCount="在線用戶數",
createRoomSuccessed="房間已創建!",

View File

@@ -27,36 +27,6 @@ local NET={
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>
@@ -69,7 +39,7 @@ local function getMsg(request,timeout)
if type(mes.body)=='string' and #mes.body>0 then
return JSON.decode(mes.body)
else
MES.new('info',"Oops! Server is down")
MES.new('info',text.serverDown)
return
end
else
@@ -98,7 +68,7 @@ function NET.getCode(email)
MES.new('error',res.message,5)
end
else
MES.new('warn',"Request failed",5)
MES.new('warn',text.requestFailed,5)
end
WAIT.interrupt()
@@ -138,7 +108,7 @@ function NET.codeLogin(code)
MES.new('error',res.message,5)
end
else
MES.new('warn',"Request failed",5)
MES.new('warn',text.requestFailed,5)
end
WAIT.interrupt()
@@ -176,7 +146,7 @@ function NET.setPW(code,pw)
MES.new('error',res.message,5)
end
else
MES.new('warn',"Request failed",5)
MES.new('warn',text.requestFailed,5)
end
WAIT.interrupt()
@@ -229,7 +199,6 @@ function NET.autoLogin()
USER.rToken=res.data.refreshToken
USER.aToken=res.data.accessToken
NET.connectWS()
MES.new('info',"Login successed",5)
SCN.go('net_menu')
WAIT.interrupt()
return
@@ -251,7 +220,6 @@ function NET.autoLogin()
},
},6.26)
if res then
print(TABLE.dump(res))
if res.code==200 then
USER.rToken=res.data.refreshToken
USER.aToken=res.data.accessToken
@@ -305,7 +273,7 @@ function NET.pwLogin(email,pw)
MES.new('error',res.message,5)
end
else
MES.new('warn',"Request failed",5)
MES.new('warn',text.requestFailed,5)
end
WAIT.interrupt()
@@ -321,6 +289,7 @@ end
--------------------------<NEW WS API>
local function wsSend(act,data)
-- print("SEND ACT: "..act)
WS.send('game',JSON.encode{
action=act,
data=data,
@@ -454,9 +423,7 @@ end
--WS
function NET.connectWS()
if WS.status('game')=='dead'then
WS.connect('game','',{
['x-access-token']=USER.aToken,
},6)
WS.connect('game','',{['x-access-token']=USER.aToken},6)
TASK.new(NET.updateWS)
end
end
@@ -471,13 +438,19 @@ function NET.updateWS()
if op=='ping'then
elseif op=='pong'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
else
local res=_parse(message)
local res=JSON.decode(message)
if res then
if res.type=='Connect'then
MES.new('info','Connected!')
-- print(("RECV ACT: $1 ($2)"):repD(res.action,res.type))
if res.type=='Failed' then
MES.new('warn',"Request failed: "..(res.reason or "/"))
elseif res.action==1100 then-- TODO
elseif res.action==1101 then-- TODO
elseif res.action==1102 then-- TODO