|
|
|
|
@ -33,6 +33,13 @@ local strbyte = string.byte
|
|
|
|
|
local libS = LibStub:GetLibrary("AceSerializer-3.0") |
|
|
|
|
local libD = LibStub("LibDeflate", true) |
|
|
|
|
local warnedNoDeflate |
|
|
|
|
local debugEnabled = true |
|
|
|
|
|
|
|
|
|
local function DebugPrint(msg) |
|
|
|
|
if debugEnabled then |
|
|
|
|
TSM:Print("ChannelSync: " .. msg) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
local function CanEncode() |
|
|
|
|
if libD then return true end |
|
|
|
|
@ -89,19 +96,35 @@ end
|
|
|
|
|
local function EncodePayload(payload) |
|
|
|
|
if not CanEncode() then return end |
|
|
|
|
local serialized = libS:Serialize(payload) |
|
|
|
|
if not serialized then |
|
|
|
|
DebugPrint("Serialize failed.") |
|
|
|
|
return |
|
|
|
|
end |
|
|
|
|
local compressed = libD:CompressDeflate(serialized, { level = 9 }) |
|
|
|
|
if not compressed then return end |
|
|
|
|
if not compressed then |
|
|
|
|
DebugPrint("CompressDeflate failed.") |
|
|
|
|
return |
|
|
|
|
end |
|
|
|
|
return libD:EncodeForPrint(compressed) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
local function DecodePayload(encoded) |
|
|
|
|
if not CanEncode() then return end |
|
|
|
|
local decoded = libD:DecodeForPrint(encoded) |
|
|
|
|
if not decoded then return end |
|
|
|
|
if not decoded then |
|
|
|
|
DebugPrint("DecodeForPrint failed.") |
|
|
|
|
return |
|
|
|
|
end |
|
|
|
|
local decompressed = libD:DecompressDeflate(decoded) |
|
|
|
|
if not decompressed then return end |
|
|
|
|
if not decompressed then |
|
|
|
|
DebugPrint("DecompressDeflate failed.") |
|
|
|
|
return |
|
|
|
|
end |
|
|
|
|
local ok, payload = libS:Deserialize(decompressed) |
|
|
|
|
if not ok then return end |
|
|
|
|
if not ok then |
|
|
|
|
DebugPrint("Deserialize failed.") |
|
|
|
|
return |
|
|
|
|
end |
|
|
|
|
return payload |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@ -264,7 +287,9 @@ local function MergeIncomingData(payload, sender)
|
|
|
|
|
|
|
|
|
|
TSM:Serialize() |
|
|
|
|
|
|
|
|
|
if updated > 0 and sender then |
|
|
|
|
if updated == 0 and sender then |
|
|
|
|
DebugPrint("No items updated from " .. sender .. ".") |
|
|
|
|
elseif updated > 0 and sender then |
|
|
|
|
if updated == 1 and lastItemID then |
|
|
|
|
local link = select(2, GetItemInfo(lastItemID)) or ("item:" .. tostring(lastItemID)) |
|
|
|
|
TSM:Printf("AuctionDB updated %s from %s.", link, sender) |
|
|
|
|
@ -295,11 +320,15 @@ function ChannelSync:OnChannelMessage(_, msg, source, _, _, _, _, _, channelName
|
|
|
|
|
|
|
|
|
|
local bundle = private.incoming[hash] |
|
|
|
|
if not bundle or (time() - bundle.time) > BUNDLE_TIMEOUT then |
|
|
|
|
if bundle then |
|
|
|
|
DebugPrint("Bundle timeout " .. format("%08x", hash) .. " (" .. bundle.received .. "/" .. bundle.total .. ").") |
|
|
|
|
end |
|
|
|
|
bundle = {time = time(), total = total, chunks = {}, received = 0} |
|
|
|
|
private.incoming[hash] = bundle |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
if bundle.total ~= total then |
|
|
|
|
DebugPrint("Bundle total mismatch for " .. format("%08x", hash) .. ". Resetting.") |
|
|
|
|
private.incoming[hash] = {time = time(), total = total, chunks = {}, received = 0} |
|
|
|
|
bundle = private.incoming[hash] |
|
|
|
|
end |
|
|
|
|
@ -319,7 +348,10 @@ function ChannelSync:OnChannelMessage(_, msg, source, _, _, _, _, _, channelName
|
|
|
|
|
private.incoming[hash] = nil |
|
|
|
|
|
|
|
|
|
local payload = DecodePayload(table.concat(parts)) |
|
|
|
|
if not payload then return end |
|
|
|
|
if not payload then |
|
|
|
|
DebugPrint("Payload decode failed for bundle " .. format("%08x", hash)) |
|
|
|
|
return |
|
|
|
|
end |
|
|
|
|
MergeIncomingData(payload, source) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@ -332,6 +364,7 @@ function ChannelSync:SendQueueThread()
|
|
|
|
|
SendChatMessage(msg, "CHANNEL", nil, private.channelId) |
|
|
|
|
self:Sleep(SEND_INTERVAL) |
|
|
|
|
end |
|
|
|
|
DebugPrint("Sent bundle " .. format("%08x", job.hash) .. " (" .. job.total .. " chunks).") |
|
|
|
|
tremove(private.sendQueue, 1) |
|
|
|
|
end |
|
|
|
|
private.isSending = false |
|
|
|
|
|