From ebaed7e301acc60f580a96b897928b965f155939 Mon Sep 17 00:00:00 2001 From: Foereaper Date: Tue, 2 Aug 2022 17:30:50 +0200 Subject: [PATCH] Fix empty string parsing --- Client/CMH.lua | 12 +++++++++++- Server/SMH.lua | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Client/CMH.lua b/Client/CMH.lua index 7faea58..8a0f27c 100644 --- a/Client/CMH.lua +++ b/Client/CMH.lua @@ -3,6 +3,7 @@ local debug = false local CMH = {} local datacache = {} local delim = {"♠", "♥", "♚", "♛", "♜"} +local emptyStr = "♝" local pck = {REQ = 1, DAT = 2} -- HELPERS START @@ -49,7 +50,12 @@ local function ParseMessage(str) -- Convert value to correct type for k, v in pairs(valTemp) do local varType = typeTemp[k] - if(varType == 3) then -- Ints + if(varType == 2) then -- Strings + -- Special case for empty string parsing + if(v == emptyStr) then + v = "" + end + elseif(varType == 3) then -- Ints v = tonumber(v) elseif(varType == 4) then -- Tables v = Smallfolk.loads(v, #v) @@ -72,6 +78,10 @@ local function ProcessVariables(reqId, ...) for _, v in pairs(arg) do if(type(v) == "string") then + -- Special case for empty string parsing + if(#v == 0) then + msg = msg .. emptyStr + end msg = msg .. delim[2] elseif(type(v) == "number") then msg = msg .. delim[3] diff --git a/Server/SMH.lua b/Server/SMH.lua index 71ec340..7d67efd 100644 --- a/Server/SMH.lua +++ b/Server/SMH.lua @@ -5,6 +5,7 @@ local debug = false local SMH = {} local datacache = {} local delim = {"♠", "♥", "♚", "♛", "♜"} +local emptyStr = "♝" local pck = {REQ = 1, DAT = 2} -- HELPERS START @@ -51,7 +52,12 @@ local function ParseMessage(str) -- Convert value to correct type for k, v in pairs(valTemp) do local varType = typeTemp[k] - if(varType == 3) then -- Ints + if(varType == 2) then -- strings + -- special case for empty string parsing + if(v == emptyStr) then + v = "" + end + elseif(varType == 3) then -- Ints v = tonumber(v) elseif(varType == 4) then -- Tables v = smallfolk.loads(v) @@ -74,6 +80,10 @@ local function ProcessVariables(sender, reqId, ...) for _, v in pairs(arg) do if(type(v) == "string") then + -- Special case for empty string parsing + if(#v == 0) then + msg = msg .. emptyStr + end msg = msg .. delim[2] elseif(type(v) == "number") then msg = msg .. delim[3]