From 76070d195ea3f05a095dcc0ff1584fa14a2b4390 Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Wed, 17 Feb 2021 02:44:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E8=A7=A3=E7=A0=81=E4=BF=9D?= =?UTF-8?q?=E6=8A=A4=EF=BC=8C=E8=81=94=E7=BD=91=E6=94=B6=E5=88=B0=E9=9D=9E?= =?UTF-8?q?=E6=B3=95=E6=B6=88=E6=81=AF=E4=B8=8D=E4=BC=9A=E7=88=86=E7=82=B8?= =?UTF-8?q?=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parts/player/init.lua | 11 +++++++++-- parts/player/player.lua | 14 +++++++++----- parts/scenes/net_chat.lua | 4 +++- parts/scenes/net_game.lua | 11 +++++++++-- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/parts/player/init.lua b/parts/player/init.lua index 4299fb9f..ab1e76b4 100644 --- a/parts/player/init.lua +++ b/parts/player/init.lua @@ -212,8 +212,15 @@ local function loadGameEnv(P)--Load gameEnv end end end -local function loadRemoteEnv(P,conf)--Load gameEnv - conf=conf and json.decode(love.data.decode("string","base64",conf))or{} +local function loadRemoteEnv(P,confStr)--Load gameEnv + local _,conf=pcall(love.data.decode,"string","base64",confStr) + if _ then + conf=json.decode(conf) + else + conf={} + LOG.print("Bad conf from "..P.userName.."#"..P.userID) + end + P.gameEnv={}--Current game setting environment local ENV=P.gameEnv local GAME,SETTING=GAME,SETTING diff --git a/parts/player/player.lua b/parts/player/player.lua index f35a5177..1391847a 100644 --- a/parts/player/player.lua +++ b/parts/player/player.lua @@ -215,12 +215,16 @@ function Player.setRS(P,RSname) P.RS=kickList[RSname] end -function Player.setConf(P,conf) - conf=json.decode(love.data.decode("string","base64",conf)) - for k,v in next,conf do - if not GAME.modeEnv[k]then - P.gameEnv[k]=v +function Player.setConf(P,confStr) + local _,conf=pcall(love.data.decode,"string","base64",confStr) + if _ then + for k,v in next,conf do + if not GAME.modeEnv[k]then + P.gameEnv[k]=v + end end + else + LOG.print("Bad conf from "..P.userName.."#"..P.userID) end end diff --git a/parts/scenes/net_chat.lua b/parts/scenes/net_chat.lua index 2d90b607..bd3cde29 100644 --- a/parts/scenes/net_chat.lua +++ b/parts/scenes/net_chat.lua @@ -73,10 +73,12 @@ function scene.socketRead(mes) } remain=tonumber(args[3]) elseif cmd=="T"then + local _,text=pcall(data.decode,"string","base64",args[3]) + if not _ then text=args[3]end textBox:push{ COLOR.W,args[1], COLOR.dY,"#"..args[2].." ", - COLOR.sky,data.decode("string","base64",args[3]) + COLOR.sky,text } else LOG.print("Illegal message: "..mes,30,COLOR.green) diff --git a/parts/scenes/net_game.lua b/parts/scenes/net_game.lua index 1c5da0a4..e717d4fc 100644 --- a/parts/scenes/net_game.lua +++ b/parts/scenes/net_game.lua @@ -198,10 +198,12 @@ function scene.socketRead(mes) end initPlayerPosition(true) elseif cmd=="T"then + local _,text=pcall(data.decode,"string","base64",args[3]) + if not _ then text=args[3]end textBox:push{ COLOR.W,args[1], COLOR.dY,"#"..args[2].." ", - COLOR.sky,data.decode("string","base64",args[3]) + COLOR.sky,text } elseif cmd=="C"then if tostring(USER.id)~=args[2]then @@ -218,7 +220,12 @@ function scene.socketRead(mes) if playing and args[1]~=PLAYERS[1].subID then for _,P in next,PLAYERS do if P.subID==args[1]then - pumpRecording(data.decode("string","base64",args[2]),P.stream) + local _,stream=pcall(data.decode,"string","base64",args[2]) + if _ then + pumpRecording(stream,P.stream) + else + LOG.print("Bad stream from "..P.userName.."#"..P.userID) + end end end end