|
|
|
@ -13,14 +13,18 @@ local ChannelSync = TSM:NewModule("ChannelSync", "AceEvent-3.0") |
|
|
|
|
|
|
|
|
|
|
|
local CHANNEL_NAME = "TSM_AuctionDB" |
|
|
|
local CHANNEL_NAME = "TSM_AuctionDB" |
|
|
|
local COMM_PREFIX = "TSMADB1" |
|
|
|
local COMM_PREFIX = "TSMADB1" |
|
|
|
local CHUNK_SIZE = 200 |
|
|
|
local CHUNK_SIZE = 220 |
|
|
|
local BUNDLE_TIMEOUT = 45 |
|
|
|
local BUNDLE_TIMEOUT = 45 |
|
|
|
|
|
|
|
local SEND_INTERVAL = 0.08 |
|
|
|
|
|
|
|
local MAX_TOTAL_CHUNKS = 800 |
|
|
|
|
|
|
|
|
|
|
|
local private = { |
|
|
|
local private = { |
|
|
|
channelId = nil, |
|
|
|
channelId = nil, |
|
|
|
channelName = nil, |
|
|
|
channelName = nil, |
|
|
|
lastBroadcastHash = nil, |
|
|
|
lastBroadcastHash = nil, |
|
|
|
incoming = {}, |
|
|
|
incoming = {}, |
|
|
|
|
|
|
|
sendQueue = {}, |
|
|
|
|
|
|
|
isSending = false, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
local strbyte = string.byte |
|
|
|
local strbyte = string.byte |
|
|
|
@ -84,7 +88,7 @@ end |
|
|
|
local function EncodePayload(payload) |
|
|
|
local function EncodePayload(payload) |
|
|
|
if not CanEncode() then return end |
|
|
|
if not CanEncode() then return end |
|
|
|
local serialized = libS:Serialize(payload) |
|
|
|
local serialized = libS:Serialize(payload) |
|
|
|
local compressed = libD:CompressDeflate(serialized, { level = 7 }) |
|
|
|
local compressed = libD:CompressDeflate(serialized, { level = 9 }) |
|
|
|
if not compressed then return end |
|
|
|
if not compressed then return end |
|
|
|
return libD:EncodeForPrint(compressed) |
|
|
|
return libD:EncodeForPrint(compressed) |
|
|
|
end |
|
|
|
end |
|
|
|
@ -125,11 +129,15 @@ function ChannelSync:BroadcastScanData(scanType) |
|
|
|
if hash == private.lastBroadcastHash then return end |
|
|
|
if hash == private.lastBroadcastHash then return end |
|
|
|
private.lastBroadcastHash = hash |
|
|
|
private.lastBroadcastHash = hash |
|
|
|
local total = ceil(#encoded / CHUNK_SIZE) |
|
|
|
local total = ceil(#encoded / CHUNK_SIZE) |
|
|
|
if total > 65535 then return end |
|
|
|
if total > MAX_TOTAL_CHUNKS then |
|
|
|
for i = 1, total do |
|
|
|
TSM:Print("AuctionDB channel sync payload too large; skipping broadcast.") |
|
|
|
local chunk = strsub(encoded, (i - 1) * CHUNK_SIZE + 1, i * CHUNK_SIZE) |
|
|
|
return |
|
|
|
local msg = COMM_PREFIX .. string.format("%08x%04x%04x", tonumber(hash), i, total) .. chunk |
|
|
|
end |
|
|
|
SendChatMessage(msg, "CHANNEL", nil, private.channelId) |
|
|
|
|
|
|
|
|
|
|
|
tinsert(private.sendQueue, {hash = hash, encoded = encoded, total = total}) |
|
|
|
|
|
|
|
if not private.isSending then |
|
|
|
|
|
|
|
private.isSending = true |
|
|
|
|
|
|
|
TSMAPI.Threading:Start(ChannelSync.SendQueueThread, 0.3) |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@ -205,3 +213,17 @@ function ChannelSync:OnChannelMessage(_, msg, source, _, _, _, _, _, channelName |
|
|
|
if not payload then return end |
|
|
|
if not payload then return end |
|
|
|
MergeIncomingData(payload) |
|
|
|
MergeIncomingData(payload) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function ChannelSync:SendQueueThread() |
|
|
|
|
|
|
|
while #private.sendQueue > 0 do |
|
|
|
|
|
|
|
local job = private.sendQueue[1] |
|
|
|
|
|
|
|
for i = 1, job.total do |
|
|
|
|
|
|
|
local chunk = strsub(job.encoded, (i - 1) * CHUNK_SIZE + 1, i * CHUNK_SIZE) |
|
|
|
|
|
|
|
local msg = COMM_PREFIX .. string.format("%08x%04x%04x", job.hash, i, job.total) .. chunk |
|
|
|
|
|
|
|
SendChatMessage(msg, "CHANNEL", nil, private.channelId) |
|
|
|
|
|
|
|
self:Sleep(SEND_INTERVAL) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
tremove(private.sendQueue, 1) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
private.isSending = false |
|
|
|
|
|
|
|
end |
|
|
|
|