Browse Source

Add AuctionDB channel sync options and controls.

💘 Generated with Crush

Assisted-by: GPT-5.2-Codex via Crush <crush@charm.land>
dev
Jørgen Lien Sellæg 3 months ago
parent
commit
efff9329fa
  1. 11
      TradeSkillMaster_AuctionDB/Locale/enUS.lua
  2. 47
      TradeSkillMaster_AuctionDB/Modules/ChannelSync.lua
  3. 62
      TradeSkillMaster_AuctionDB/Modules/config.lua
  4. 4
      TradeSkillMaster_AuctionDB/TradeSkillMaster_AuctionDB.lua

11
TradeSkillMaster_AuctionDB/Locale/enUS.lua

@ -23,12 +23,20 @@ L["AuctionDB - Market Value"] = true
L["AuctionDB - Minimum Buyout"] = true L["AuctionDB - Minimum Buyout"] = true
L["Descending"] = true L["Descending"] = true
L["Display lowest buyout value seen in the last scan in tooltip."] = true L["Display lowest buyout value seen in the last scan in tooltip."] = true
L["Channel Sync"] = true
L["Channel sync name"] = true
L["Display market value in tooltip."] = true L["Display market value in tooltip."] = true
L["Enable channel sync"] = true
L["Done Scanning"] = true L["Done Scanning"] = true
L["Download the FREE TSM desktop application which will automatically update your TSM_AuctionDB prices using Blizzard's online APIs (and does MUCH more). Visit %s for more info and never scan the AH again! This is the best way to update your AuctionDB prices."] = true L["Download the FREE TSM desktop application which will automatically update your TSM_AuctionDB prices using Blizzard's online APIs (and does MUCH more). Visit %s for more info and never scan the AH again! This is the best way to update your AuctionDB prices."] = true
L["Enable channel sync debug messages"] = true
L["Enable display of AuctionDB data in tooltip."] = true L["Enable display of AuctionDB data in tooltip."] = true
L["The channel name used to share AuctionDB data."] = true
L["Hide poor quality items"] = true L["Hide poor quality items"] = true
L["If checked, AuctionDB will add a tab to the AH to allow for in-game scans. If you are using the TSM app exclusively for your scans, you may want to hide it by unchecking this option. This option requires a reload to take effect."] = true L["If checked, AuctionDB will add a tab to the AH to allow for in-game scans. If you are using the TSM app exclusively for your scans, you may want to hide it by unchecking this option. This option requires a reload to take effect."] = true
L["If checked, AuctionDB will print channel sync debug messages to chat."] = true
L["If checked, AuctionDB will sync scan data over the configured channel."] = true
L["If checked, AuctionDB will only receive channel sync data and will not broadcast scan data."] = true
L["If checked, poor quality items won't be shown in the search results."] = true L["If checked, poor quality items won't be shown in the search results."] = true
L["If checked, the lowest buyout value seen in the last scan of the item will be displayed."] = true L["If checked, the lowest buyout value seen in the last scan of the item will be displayed."] = true
L["If checked, the market value of the item will be displayed"] = true L["If checked, the market value of the item will be displayed"] = true
@ -66,6 +74,9 @@ L["Refreshes the current search results."] = true
L["Removed %s from AuctionDB."] = true L["Removed %s from AuctionDB."] = true
L["Reset Data"] = true L["Reset Data"] = true
L["Resets AuctionDB's scan data"] = true L["Resets AuctionDB's scan data"] = true
L["Reset"] = true
L["Resets the channel name to the default."] = true
L["Receive-only mode"] = true
L["Resume"] = true L["Resume"] = true
L["Resuming Scan..."] = true L["Resuming Scan..."] = true
L["Result Order:"] = true L["Result Order:"] = true

47
TradeSkillMaster_AuctionDB/Modules/ChannelSync.lua

@ -12,7 +12,14 @@ local TSM = select(2, ...)
local ChannelSync = TSM:NewModule("ChannelSync", "AceEvent-3.0") local ChannelSync = TSM:NewModule("ChannelSync", "AceEvent-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale("TradeSkillMaster_AuctionDB") local L = LibStub("AceLocale-3.0"):GetLocale("TradeSkillMaster_AuctionDB")
local CHANNEL_NAME = "TSM_AuctionDB" local DEFAULT_CHANNEL_NAME = "TSM_AuctionDB"
local function GetChannelConfigName()
if TSM.db and TSM.db.profile and TSM.db.profile.channelSyncName and TSM.db.profile.channelSyncName ~= "" then
return TSM.db.profile.channelSyncName
end
return DEFAULT_CHANNEL_NAME
end
local COMM_PREFIX = "TSMADB1" local COMM_PREFIX = "TSMADB1"
local CHUNK_SIZE = 220 local CHUNK_SIZE = 220
local BUNDLE_TIMEOUT = 45 local BUNDLE_TIMEOUT = 45
@ -36,7 +43,6 @@ local strbyte = string.byte
local libS = LibStub:GetLibrary("AceSerializer-3.0") local libS = LibStub:GetLibrary("AceSerializer-3.0")
local libD = LibStub("LibDeflate", true) local libD = LibStub("LibDeflate", true)
local warnedNoDeflate local warnedNoDeflate
local debugEnabled = true
local function GetAddonVersion() local function GetAddonVersion()
local version = GetAddOnMetadata("TradeSkillMaster_AuctionDB", "X-Curse-Packaged-Version") local version = GetAddOnMetadata("TradeSkillMaster_AuctionDB", "X-Curse-Packaged-Version")
@ -59,7 +65,7 @@ private.addonVersion = GetAddonVersion()
private.addonVersionKey = VersionKey(private.addonVersion) private.addonVersionKey = VersionKey(private.addonVersion)
local function DebugPrint(msg) local function DebugPrint(msg)
if debugEnabled then if TSM.db and TSM.db.profile and TSM.db.profile.channelSyncDebug then
TSM:Print("ChannelSync: " .. msg) TSM:Print("ChannelSync: " .. msg)
end end
end end
@ -82,13 +88,24 @@ local function HashString(str)
end end
local function EnsureChannel() local function EnsureChannel()
local channelId = GetChannelName(CHANNEL_NAME) if private.channelId and private.channelName and private.channelName ~= GetChannelConfigName() then
LeaveChannelByName(private.channelName)
private.channelId = nil
private.channelName = nil
end
if not TSM.db or not TSM.db.profile or not TSM.db.profile.channelSyncEnabled then
private.channelId = nil
private.channelName = nil
return
end
local channelName = GetChannelConfigName()
local channelId = GetChannelName(channelName)
if channelId == 0 then if channelId == 0 then
JoinChannelByName(CHANNEL_NAME) JoinChannelByName(channelName)
channelId = GetChannelName(CHANNEL_NAME) channelId = GetChannelName(channelName)
end end
private.channelId = channelId > 0 and channelId or nil private.channelId = channelId > 0 and channelId or nil
private.channelName = private.channelId and CHANNEL_NAME or nil private.channelName = private.channelId and channelName or nil
end end
local function GetChannelDisplayName(channelName, channelString, channelNumber, channelBaseName) local function GetChannelDisplayName(channelName, channelString, channelNumber, channelBaseName)
@ -111,8 +128,9 @@ local function GetChannelDisplayName(channelName, channelString, channelNumber,
end end
local function ChatFilter(_, _, msg, _, channelString, _, channelNumber, channelName, channelBaseName) local function ChatFilter(_, _, msg, _, channelString, _, channelNumber, channelName, channelBaseName)
local channelNameKey = GetChannelConfigName()
local displayName = GetChannelDisplayName(channelName, channelString, channelNumber, channelBaseName) local displayName = GetChannelDisplayName(channelName, channelString, channelNumber, channelBaseName)
if displayName ~= CHANNEL_NAME then return end if displayName ~= channelNameKey then return end
if strsub(msg, 1, #COMM_PREFIX) == COMM_PREFIX then if strsub(msg, 1, #COMM_PREFIX) == COMM_PREFIX then
return true return true
end end
@ -136,6 +154,10 @@ function ChannelSync:OnChannelNotice()
EnsureChannel() EnsureChannel()
end end
function ChannelSync:ReloadConfig()
EnsureChannel()
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)
@ -192,6 +214,8 @@ function ChannelSync:BroadcastScanData(scanType, items)
return return
end end
EnsureChannel() EnsureChannel()
if not TSM.db or not TSM.db.profile or not TSM.db.profile.channelSyncEnabled then return end
if TSM.db.profile.channelSyncReceiveOnly then return end
if not private.channelName or not private.channelId then return end if not private.channelName or not private.channelId then return end
local itemIDs = ChannelSync:CollectItemIDs(items) local itemIDs = ChannelSync:CollectItemIDs(items)
@ -228,7 +252,9 @@ function ChannelSync:BroadcastScanData(scanType, items)
return return
end end
if total > MAX_TOTAL_CHUNKS then if total > MAX_TOTAL_CHUNKS then
if TSM.db and TSM.db.profile and TSM.db.profile.channelSyncDebug then
TSM:Print("AuctionDB channel sync payload too large; skipping batch.") TSM:Print("AuctionDB channel sync payload too large; skipping batch.")
end
return return
end end
QueueEncoded(encoded) QueueEncoded(encoded)
@ -349,6 +375,7 @@ local function MergeIncomingData(payload, sender)
if updated == 0 and sender then if updated == 0 and sender then
DebugPrint("No items updated from " .. sender .. ".") DebugPrint("No items updated from " .. sender .. ".")
elseif updated > 0 and sender then elseif updated > 0 and sender then
if TSM.db and TSM.db.profile and TSM.db.profile.channelSyncDebug then
if updated == 1 and lastItemID then if updated == 1 and lastItemID then
local link = select(2, GetItemInfo(lastItemID)) or ("item:" .. tostring(lastItemID)) local link = select(2, GetItemInfo(lastItemID)) or ("item:" .. tostring(lastItemID))
TSM:Printf("AuctionDB updated %s from %s.", link, sender) TSM:Printf("AuctionDB updated %s from %s.", link, sender)
@ -357,10 +384,12 @@ local function MergeIncomingData(payload, sender)
end end
end end
end end
end
function ChannelSync:OnChannelMessage(_, msg, source, _, channelString, _, channelNumber, channelName, channelBaseName) function ChannelSync:OnChannelMessage(_, msg, source, _, channelString, _, channelNumber, channelName, channelBaseName)
local channelNameKey = GetChannelConfigName()
local displayName = GetChannelDisplayName(channelName, channelString, channelNumber, channelBaseName) local displayName = GetChannelDisplayName(channelName, channelString, channelNumber, channelBaseName)
if displayName ~= CHANNEL_NAME then if displayName ~= channelNameKey then
if strsub(msg or "", 1, #COMM_PREFIX) == COMM_PREFIX then if strsub(msg or "", 1, #COMM_PREFIX) == COMM_PREFIX then
DebugPrint("Prefix received; displayName=" .. tostring(displayName) .. " channelNumber=" .. tostring(channelNumber) .. " channelString=" .. tostring(channelString) .. " channelName=" .. tostring(channelName) .. " channelBaseName=" .. tostring(channelBaseName)) DebugPrint("Prefix received; displayName=" .. tostring(displayName) .. " channelNumber=" .. tostring(channelNumber) .. " channelString=" .. tostring(channelString) .. " channelName=" .. tostring(channelName) .. " channelBaseName=" .. tostring(channelBaseName))
end end

62
TradeSkillMaster_AuctionDB/Modules/config.lua

@ -392,6 +392,68 @@ function Config:LoadOptions(container)
}, },
}, },
}, },
{
type = "InlineGroup",
title = L["Channel Sync"],
layout = "Flow",
children = {
{
type = "CheckBox",
label = L["Enable channel sync"],
settingInfo = { TSM.db.profile, "channelSyncEnabled" },
relativeWidth = 1,
callback = function() TSM.ChannelSync:ReloadConfig() container:ReloadTab() end,
tooltip = L["If checked, AuctionDB will sync scan data over the configured channel."],
},
{
type = "EditBox",
label = L["Channel sync name"],
settingInfo = { TSM.db.profile, "channelSyncName" },
relativeWidth = 0.5,
disabled = not TSM.db.profile.channelSyncEnabled,
callback = function(_, _, value)
value = strtrim(value or "")
if value == "" then
TSM.db.profile.channelSyncName = "TSM_AuctionDB"
else
TSM.db.profile.channelSyncName = value
end
TSM.ChannelSync:ReloadConfig()
container:ReloadTab()
end,
tooltip = L["The channel name used to share AuctionDB data."],
},
{
type = "Button",
text = L["Reset"],
relativeWidth = 0.2,
disabled = not TSM.db.profile.channelSyncEnabled,
callback = function()
TSM.db.profile.channelSyncName = "TSM_AuctionDB"
TSM.ChannelSync:ReloadConfig()
container:ReloadTab()
end,
tooltip = L["Resets the channel name to the default."],
},
{
type = "CheckBox",
label = L["Receive-only mode"],
settingInfo = { TSM.db.profile, "channelSyncReceiveOnly" },
relativeWidth = 1,
disabled = not TSM.db.profile.channelSyncEnabled,
callback = function() TSM.ChannelSync:ReloadConfig() end,
tooltip = L["If checked, AuctionDB will only receive channel sync data and will not broadcast scan data."],
},
{
type = "CheckBox",
label = L["Enable channel sync debug messages"],
settingInfo = { TSM.db.profile, "channelSyncDebug" },
relativeWidth = 1,
disabled = not TSM.db.profile.channelSyncEnabled,
tooltip = L["If checked, AuctionDB will print channel sync debug messages to chat."],
},
},
},
{ {
type = "InlineGroup", type = "InlineGroup",
title = L["Search Options"], title = L["Search Options"],

4
TradeSkillMaster_AuctionDB/TradeSkillMaster_AuctionDB.lua

@ -36,6 +36,10 @@ local savedDBDefaults = {
marketValueTooltip = true, marketValueTooltip = true,
minBuyoutTooltip = true, minBuyoutTooltip = true,
showAHTab = true, showAHTab = true,
channelSyncEnabled = true,
channelSyncName = "TSM_AuctionDB",
channelSyncReceiveOnly = false,
channelSyncDebug = false,
}, },
} }

Loading…
Cancel
Save