Rewrite framework to use proper unicode delimiters
This commit is contained in:
@ -2,9 +2,8 @@ local debug = false
|
||||
|
||||
local CMH = {}
|
||||
local datacache = {}
|
||||
local delim = {"♠", "♥", "♚", "♛", "♜"}
|
||||
local emptyStr = "˽"
|
||||
local pck = {REQ = 1, DAT = 2}
|
||||
local delim = {"", "", "", "", ""}
|
||||
local pck = {REQ = "", DAT = ""}
|
||||
|
||||
-- HELPERS START
|
||||
local function debugOut(prefix, x, msg)
|
||||
@ -52,7 +51,7 @@ local function ParseMessage(str)
|
||||
local varType = typeTemp[k]
|
||||
if(varType == 2) then -- Strings
|
||||
-- Special case for empty string parsing
|
||||
if(v == emptyStr) then
|
||||
if(v == "") then
|
||||
v = ""
|
||||
end
|
||||
elseif(varType == 3) then -- Ints
|
||||
@ -76,11 +75,11 @@ local function ProcessVariables(reqId, ...)
|
||||
local arg = {...}
|
||||
local msg = ""
|
||||
|
||||
for _, v in pairs(arg) do
|
||||
for k, v in pairs(arg) do
|
||||
if(type(v) == "string") then
|
||||
-- Special case for empty string parsing
|
||||
if(#v == 0) then
|
||||
msg = msg .. emptyStr
|
||||
v = ""
|
||||
end
|
||||
msg = msg .. delim[2]
|
||||
elseif(type(v) == "number") then
|
||||
@ -116,16 +115,13 @@ function CMH.OnReceive(self, event, header, data, Type, sender)
|
||||
-- Ensure the sender and receiver is the same, the message is an addon message, and the message type is WHISPER
|
||||
if event == "CHAT_MSG_ADDON" and sender == UnitName("player") and Type == "WHISPER" then
|
||||
-- unpack and validate addon message structure
|
||||
local pfx, source, pckId = header:match("(...)(%u)(%d%d)")
|
||||
local pfx, source, pckId = header:match("(.)(%u)(.)")
|
||||
if not pfx or not source or not pckId then
|
||||
return
|
||||
end
|
||||
|
||||
-- Make sure we're only processing addon messages using our framework prefix character as well as client messages
|
||||
if(pfx == delim[1] and source == "S") then
|
||||
-- convert ID to number so we can compare with our packet list
|
||||
pckId = tonumber(pckId)
|
||||
|
||||
if(pckId == pck.REQ) then
|
||||
debugOut("REQ", "Rx", "REQ received, data: "..data)
|
||||
CMH.OnREQ(sender, data)
|
||||
@ -249,7 +245,7 @@ end
|
||||
-- Tx START
|
||||
|
||||
function CMH.SendREQ(functionId, linkCount, reqId, addon)
|
||||
local header = string.format("%01s%01s%02d", delim[1], "C", pck.REQ)
|
||||
local header = string.format("%01s%01s%01s", delim[1], "C", pck.REQ)
|
||||
local data = string.format("%02d%03d%06s%0"..tostring(#addon).."s", functionId, linkCount, reqId, addon)
|
||||
SendAddonMessage(header, data, "WHISPER", UnitName("player"))
|
||||
debugOut("REQ", "Tx", "Sent REQ with ID "..reqId..", sending DAT..")
|
||||
@ -257,7 +253,7 @@ end
|
||||
|
||||
function CMH.SendDAT(reqId)
|
||||
-- Build data message header
|
||||
local header = string.format("%01s%01s%02d", delim[1], "C", pck.DAT)
|
||||
local header = string.format("%01s%01s%01s", delim[1], "C", pck.DAT)
|
||||
|
||||
-- iterate all items in the message data cache and send
|
||||
-- functions can also be trigger functions without any data, only send header and no payload
|
||||
|
||||
Reference in New Issue
Block a user