local addonName, ZLAUTO = ...

local ZL = ZLAUTO.mainFrame
local PlayerIsML = ZL.PlayerIsML
local pruneCrossRealm = ZL.pruneCrossRealm
local FetchDataFromItemId = ZL.FetchDataFromItemId
local Prefix = ZL.Prefix
local TransmitAddonInfo_Pro = ZL.TransmitAddonInfo_Pro
local tableSort = ZL.tableSort
local GetClassColorName = ZL.GetClassColorName
local ParseClassColorName = ZL.ParseClassColorName
local CheckWaVersion = ZL.CheckWaVersion
local cGetItemInfo, cGetItemIcon
if WOW_PROJECT_ID == 1 then
    cGetItemInfo = C_Item.GetItemInfo
    cGetItemIcon = C_Item.GetItemIconByID
else --WOW_PROJECT_ID == 11 then
    cGetItemInfo = GetItemInfo
    cGetItemIcon = GetItemIcon
end
-- 依赖库: AceAddon-3.0, AceComm-3.0, LibSerialize, LibDeflate
MyAddon = LibStub("AceAddon-3.0"):GetAddon("AutoAuction", true)
if MyAddon then
    -- print("已注册")
else
    MyAddon = LibStub("AceAddon-3.0"):NewAddon("AutoAuction", "AceComm-3.0")
end
local LibSerialize = LibStub("LibSerialize")
local LibDeflate = LibStub("LibDeflate")
local CHUNK_SIZE = 2500
local DATA_MAX = 25000
local receivedChunks = {}
local receivedIndex = {}
local totalChunksExpected = nil
-- 插件启用时的函数
function MyAddon:OnEnable()
    --因API限制，每个注册的前缀10秒内最多只能发送10条插件消息，每隔1秒增加1条消息额度，只能通过细分多注册前缀
    for i = 0, 15 do
        self:RegisterComm("AUTOAUC SYNC" .. i)
    end
    --同步超大数据用
    for i = 1, 15 do
        self:RegisterComm("AUTOAUC ALL" .. i)
    end
    --团队密语用
    for i = 1, 40 do
        self:RegisterComm("AUTOAUC WSP" .. i)
    end
    
    self:RegisterComm("AUTOAUC RETAKE")--申请流拍物品重拍用
    self:RegisterComm("AUTOAUC SYNC")
    self:RegisterComm("AUTOAUC TONGBU") --将ML数据同步给其他人
    self:RegisterComm("AUTOAUC RESET") --初始化全员拍卖插件
    self:RegisterComm("AUTOAUC REQ") --登录或重载UI时请求同步ML数据
    self:RegisterComm("AUTOAUC PRO") --同步全局配置参数
    self:RegisterComm("AUTOAUC REVOKE") --删除指定玩家的出价
    self:RegisterComm("AUTOAUC VER") --请求检测全团是否有安装插件及插件的版本并且处理反馈回的消息(data.type=request, requestback)
    self:RegisterComm("AUTOAUC SOUND") --发送语音
end

function MyAddon:TransmitAddonInfo(prefix, data)
    if PlayerIsML() and data then
        local serialized = LibSerialize:Serialize(data)
        local compressed = LibDeflate:CompressDeflate(serialized)
        local encoded = LibDeflate:EncodeForWoWAddonChannel(compressed)
        -- print(Prefix("数据大小：" .. #encoded .. "字节"))
        self:SendCommMessage(prefix, encoded, "RAID")
    end
end

function MyAddon:TransmitAddonInfo2(prefix, data, chatType, targetName)
    if data then
        local serialized = LibSerialize:Serialize(data)
        local compressed = LibDeflate:CompressDeflate(serialized)
        local encoded = LibDeflate:EncodeForWoWAddonChannel(compressed)
        -- print(Prefix("数据大小：" .. #encoded .. "字节"))
        if chatType == "WHISPER" then
            self:SendCommMessage(prefix, encoded, chatType, targetName)
        else
            self:SendCommMessage(prefix, encoded, chatType)
        end
    end
end
--发送同步当前所有数据
function MyAddon:SYNCALL(data, chatType, targetName)
    if PlayerIsML() and data then
        local serialized = LibSerialize:Serialize(data)
        -- print(#serialized)
        local compressed = LibDeflate:CompressDeflate(serialized)
        local encoded = LibDeflate:EncodeForWoWAddonChannel(compressed)
        -- print(Prefix("数据大小：" .. #encoded .. "字节"))
        if #encoded > DATA_MAX then
            print(Prefix("文件数据过大，同步失败！"))
            return
        end
        local totalChunks = math.ceil(#encoded / CHUNK_SIZE) -- 计算需要多少片段
        for i = 1, totalChunks do
            -- 获取当前片段
            local startByte = (i - 1) * CHUNK_SIZE + 1
            local endByte = math.min(i * CHUNK_SIZE, #encoded)
            local chunk = encoded:sub(startByte, endByte)
            -- 构造发送内容：包含片段编号和总片段数
            local chunkMessage = string.format("%d:%d:%s", i, totalChunks, chunk)
            -- 发送消息
            chatType = chatType or "RAID"
            if chatType == "WHISPER" then
                if targetName then
                    self:SendCommMessage("AUTOAUC ALL" .. i, chunkMessage , chatType, targetName)
                else
                    print(Prefix("缺少目标名字"))
                end
            else
                self:SendCommMessage("AUTOAUC ALL" .. i, chunkMessage , chatType)
            end
        end
    end
end
function MyAddon:OnCommReceived(prefix, payload, distribution, sender)
    local AuctionFrame = ZL.AuctionFrame2
    sender = pruneCrossRealm(sender)
    local senderColorName = ZL.GetClassColorName(sender)
    if prefix:match("^AUTOAUC ALL%d+$") then
        if PlayerIsML(sender) then
            --接收当前所有拍卖数据
            -- 解析片段编号、总片段数和实际数据
            local chunkIndex, totalChunks, chunkData = payload:match("^(%d+):(%d+):(.+)$")
            chunkIndex = tonumber(chunkIndex)
            totalChunks = tonumber(totalChunks)
            -- 如果是第一次接收到片段，记录总片段数
            if not totalChunksExpected then
                totalChunksExpected = totalChunks
            end
            -- 保存片段
            receivedChunks[chunkIndex] = chunkData
            table.insert(receivedIndex, chunkIndex)
            if #receivedIndex == totalChunksExpected then
                -- 所有片段已接收，开始重组
                local completeData = table.concat(receivedChunks)
                -- 解码、解压缩、反序列化
                local decodedData = LibDeflate:DecodeForWoWAddonChannel(completeData)
                local decompressedData = LibDeflate:DecompressDeflate(decodedData)
                local success, myReceivedData = LibSerialize:Deserialize(decompressedData)

                if success then
                    local msgStr
                    if myReceivedData.type == "all" then --全部同步
                        if (not PlayerIsML()) then
                            ZL_CURRENT = myReceivedData.data
                        end
                    elseif myReceivedData.type == "bathFailed" then --批量流拍
                        local fdata = myReceivedData.data
                        for _, _data in ipairs(fdata) do
                            local data, index = FetchDataFromItemId(_data.itemlink, _data.itemindex)
                            if data then
                                local lgnore = ZL_CURRENT.auctionlist[index].lgnore
                                ZL_CURRENT.auctionlist[index] = _data
                                ZL_CURRENT.auctionlist[index].lgnore = lgnore
                            else
                                ZL.CreateAuctionList()
                                table.insert(ZL_CURRENT.auctionlist, _data)
                                index = #ZL_CURRENT.auctionlist
                                ZL_CURRENT.auctionlist[index].lgnore = false
                            end
                            ZL_CURRENT.auctionlist[index].state = "failed"
                        end
                        msgStr = "有批量流拍物品，请注意查看团队信息\n如有需要的，请在团队频道发|cffff0000物品链接+出价|r"
                        ZL.ScrollingMessageFrame:AddMessage(msgStr)
                        if ZL.opt.IsVoiceReminder then
                            local soundName = "批量流拍.mp3"
                            PlaySoundFile("Interface\\AddOns\\" .. addonName .. "\\sound\\" .. ZL.SoundType .. "\\" .. soundName, "Master")
                        end
                    end
                    AuctionFrame:Update()
                else
                print(Prefix("数据解压缩或反序列化失败"))
                end
                -- 清空存储的片段，准备下一次接收
                receivedChunks = {}
                receivedIndex = {}
                totalChunksExpected = nil
            end
        end
    else
        -- if (not ZL_CURRENT.OnCommReceivedError) then ZL_CURRENT.OnCommReceivedError = {} end
        -- if (not ZL_CURRENT.OnCommReceivedError[prefix]) then ZL_CURRENT.OnCommReceivedError[prefix] = {} end
        local tryCounts = 0
        local success, fdata
        local function Deserialize()
            tryCounts = tryCounts + 1
            local isSuccessed = true
            local decoded = LibDeflate:DecodeForWoWAddonChannel(payload)
            if (not decoded) then
                -- table.insert(ZL_CURRENT.OnCommReceivedError[prefix], {time=date("%Y-%m-%d %H:%M:%S", time()), type="解码失败"})
                isSuccessed = false
            end
            local decompressed = LibDeflate:DecompressDeflate(decoded)
            if (not decompressed) then
                -- table.insert(ZL_CURRENT.OnCommReceivedError[prefix], {time=date("%Y-%m-%d %H:%M:%S", time()), type="解压失败"})
                isSuccessed = false
            end
            success, fdata = LibSerialize:Deserialize(decompressed)
            if (not success) then
                -- table.insert(ZL_CURRENT.OnCommReceivedError[prefix], {time=date("%Y-%m-%d %H:%M:%S", time()), type="转换失败"})
                isSuccessed = false
            end
            if isSuccessed then
                return
            end
            if tryCounts >= 10 then
                -- table.insert(ZL_CURRENT.OnCommReceivedError[prefix], {time=date("%Y-%m-%d %H:%M:%S", time()), tryCounts="超过尝试次数"})
                return
            end
            C_Timer.After(0.3, Deserialize)
        end
        Deserialize()
        if (not success) then return end
        if (prefix == "AUTOAUC SYNC") then
            --已弃用
            if PlayerIsML(sender) then
                if fdata.type == "开始拍卖" then
                    local isRestart = fdata.isRestart
                    local tradeId = fdata.tradeId
                    if isRestart == "重拍" and tradeId and ZL_CURRENT.IncomeList and #ZL_CURRENT.IncomeList > 0 then
                        for i = #ZL_CURRENT.IncomeList, 1, -1 do
                            local _tradeId = ZL_CURRENT.IncomeList[i].tradeId
                            if _tradeId and _tradeId == tradeId then
                                table.remove(ZL_CURRENT.IncomeList, i)
                            end
                        end
                    end
                    local ffdata = fdata.data2
                    local data, index = FetchDataFromItemId(ffdata.itemlink, ffdata.itemindex)
                    if (not data) then
                        data = {
                            ["type"] = ffdata.type,
                            ["itemId"] = ffdata.itemId,
                            ["itemlink"] = ffdata.itemlink,
                            ["itemindex"] = ffdata.itemindex,
                            ["itemCount"] = ffdata.itemCount,
                            ["itemLevel"] = ffdata.itemLevel,
                            ["bindType"] = ffdata.bindType,
                            ["startbidamount"] = ffdata.startbidamount,
                            ["bidIncrement"] = ffdata.bidIncrement,
                            ["state"] = ffdata.state,
                            ["countdownremaining"] = ffdata.countdownremaining,
                            ["isPaused"] = ffdata.isPaused,
                            ["stackCount"] = ffdata.stackCount,
                            ["itemGUID"] = ffdata.itemGUID,
                            ["bidderlist"] = ffdata.bidderlist,
                            ["sourceGUID"] = ffdata.sourceGUID,
                            ["tradeId"] = nil,
                            ["Frame1IsShown"] = true, --开始拍卖强制显示
                            ["lgnore"] = false, --第一次创建不忽略
                        }
                        ZL.CreateAuctionList()
                        table.insert(ZL_CURRENT.auctionlist, data)
                        index = #ZL_CURRENT.auctionlist
                    else
                        ZL_CURRENT.auctionlist[index].type = ffdata.type
                        ZL_CURRENT.auctionlist[index].itemId = ffdata.itemId
                        ZL_CURRENT.auctionlist[index].itemlink = ffdata.itemlink
                        ZL_CURRENT.auctionlist[index].itemindex = ffdata.itemindex
                        ZL_CURRENT.auctionlist[index].itemCount = ffdata.itemCount
                        ZL_CURRENT.auctionlist[index].itemLevel = ffdata.itemLevel
                        ZL_CURRENT.auctionlist[index].bindType = ffdata.bindType
                        ZL_CURRENT.auctionlist[index].startbidamount = ffdata.startbidamount
                        ZL_CURRENT.auctionlist[index].bidIncrement = ffdata.bidIncrement
                        ZL_CURRENT.auctionlist[index].state = ffdata.state
                        ZL_CURRENT.auctionlist[index].countdownremaining = ffdata.countdownremaining
                        ZL_CURRENT.auctionlist[index].auctionTimerRefresh = ffdata.auctionTimerRefresh
                        ZL_CURRENT.auctionlist[index].isPaused = ffdata.isPaused
                        ZL_CURRENT.auctionlist[index].stackCount = ffdata.stackCount
                        ZL_CURRENT.auctionlist[index].itemGUID = ffdata.itemGUID
                        ZL_CURRENT.auctionlist[index].bidderlist = ffdata.bidderlist
                        ZL_CURRENT.auctionlist[index].sourceGUID = ffdata.sourceGUID
                        ZL_CURRENT.auctionlist[index].tradeId = nil
                        ZL_CURRENT.auctionlist[index].Frame1IsShown = true --开始拍卖强制显示
                        --ZL_CURRENT.auctionlist[index].lgnore 是否忽略不需要同步
                    end
                    ZL.AuctionListSort()
                elseif fdata.type == "取消拍卖" then
                    local data, index = FetchDataFromItemId(fdata.itemlink, fdata.itemindex)
                    if data then
                        local f = AuctionFrame.entries[index]
                        ZL_CURRENT.auctionlist[index].state = "waiting"
                        ZL_CURRENT.auctionlist[index].countdownremaining = 0
                        ZL_CURRENT.auctionlist[index].isPaused = false
                        ZL_CURRENT.auctionlist[index].bidderlist = {}
                        if not PlayerIsML() then
                            ZL_CURRENT.auctionlist[index].Frame1IsShown = false
                        end
                        f:SetValues(index)
                        AuctionFrame:Update()
                    end
                elseif fdata.type == "暂停拍卖" then
                    local data, index = FetchDataFromItemId(fdata.itemlink, fdata.itemindex)
                    if data then
                        local f = AuctionFrame.entries[index]
                        ZL_CURRENT.auctionlist[index].isPaused = true
                        f:SetValues(index)
                    end
                elseif fdata.type == "继续拍卖" then
                    local data, index = FetchDataFromItemId(fdata.itemlink, fdata.itemindex)
                    if data then
                        ZL_CURRENT.auctionlist[index].isPaused = false
                        local f = AuctionFrame.entries[index]
                        f:SetValues(index)
                    end
                elseif fdata.type == "数量更新" then
                    if not PlayerIsML() then
                        local data, index = FetchDataFromItemId(fdata.itemlink, fdata.itemindex)
                        if data then
                            ZL_CURRENT.auctionlist[index].itemCount = fdata.itemCount
                            ZL_CURRENT.auctionlist[index].countdownremaining = fdata.countdownremaining
                            local f = AuctionFrame.entries[index]
                            f:SetValues(index)
                        end
                    end
                elseif fdata.type == "手动倒计时" then
                    if not PlayerIsML() then
                        local data, index = FetchDataFromItemId(fdata.itemlink, fdata.itemindex)
                        if data then
                            local f = AuctionFrame.entries[index]
                            f.daoShuStart = GetTime()
                            ZL_CURRENT.auctionlist[index].isPaused = false
                            ZL_CURRENT.auctionlist[index].countdownremaining = fdata.countdownremaining
                            f:SetValues(index)
                        end
                    end
                elseif fdata.type == "拍卖成功" then
                    local data, index = FetchDataFromItemId(fdata.itemlink, fdata.itemindex)
                    if data then
                        local f = AuctionFrame.entries[index]
                        ZL_CURRENT.auctionlist[index].state = "success"
                        ZL_CURRENT.auctionlist[index].countdownremaining = 0
                        ZL_CURRENT.auctionlist[index].Frame1IsShown = false
                        ZL_CURRENT.auctionlist[index].itemGUID = fdata.itemGUID
                        f:SetValues(index)
                        AuctionFrame:Update()
                    end
                elseif fdata.type == "流拍" then
                    local data, index = FetchDataFromItemId(fdata.itemlink, fdata.itemindex)
                    if data then
                        local f = AuctionFrame.entries[index]
                        ZL_CURRENT.auctionlist[index].state = "failed"
                        ZL_CURRENT.auctionlist[index].countdownremaining = 0
                        ZL_CURRENT.auctionlist[index].Frame1IsShown = false
                        f:SetValues(index)
                        AuctionFrame:Update()
                    end
                elseif fdata.type == "创建拍卖" then
                    if not PlayerIsML() then
                        ZL.CreateAuctionList()
                        local data = {
                            ["itemId"] = fdata.itemId,
                            ["itemlink"] = fdata.itemlink,
                            ["itemindex"] = fdata.itemindex,
                            ["startbidamount"] = fdata.startbidamount,
                            ["bidIncrement"] = fdata.bidIncrement,
                            ["state"] = fdata.state,
                            ["lgnore"] = fdata.lgnore,
                            ["countdownremaining"] = fdata.countdownremaining, --可以不用赋值，在启动拍卖的时候已经默认为ZL.opt.auctionTimer
                            ["isPaused"] = fdata.isPaused,
                            ["bidderlist"] = fdata.bidderlist,
                            ["itemCount"] = fdata.itemCount,
                            ["sourceGUID"] = fdata.sourceGUID,
                            ["itemGUID"] = fdata.itemGUID,
                            ["Frame1IsShown"] = fdata.Frame1IsShown,
                            stackCount = fdata.stackCount,
                        }
                        table.insert(ZL_CURRENT.auctionlist, data)
                        local index = #ZL_CURRENT.auctionlist
                        ZL.AuctionListSort()
                    end
                elseif fdata.type == "拾取创建" then
                    if not PlayerIsML() then
                        for _, data2 in ipairs(fdata.data) do
                            if data2.type == "创建拍卖" then
                                ZL.CreateAuctionList()
                                local data = {
                                    ["itemId"] = data2.itemId,
                                    ["itemlink"] = data2.itemlink,
                                    ["itemindex"] = data2.itemindex,
                                    ["startbidamount"] = data2.startbidamount,
                                    ["bidIncrement"] = data2.bidIncrement,
                                    ["state"] = data2.state,
                                    ["lgnore"] = data2.lgnore,
                                    ["countdownremaining"] = data2.countdownremaining, --可以不用赋值，在启动拍卖的时候已经默认为ZL.opt.auctionTimer
                                    ["auctionTimerRefresh"] = data2.auctionTimerRefresh,
                                    ["isPaused"] = data2.isPaused,
                                    ["bidderlist"] = data2.bidderlist,
                                    ["itemCount"] = data2.itemCount,
                                    ["sourceGUID"] = data2.sourceGUID,
                                    ["itemGUID"] = data2.itemGUID,
                                    ["Frame1IsShown"] = data2.Frame1IsShown,
                                    stackCount = data2.stackCount,
                                }
                                table.insert(ZL_CURRENT.auctionlist, data)
                                local index = #ZL_CURRENT.auctionlist
                                ZL.AuctionListSort()
                            elseif data2.type == "数量更新" then
                                local data, index = FetchDataFromItemId(data2.itemlink, data2.itemindex)
                                if data then
                                    ZL_CURRENT.auctionlist[index].itemCount = data2.itemCount
                                    ZL_CURRENT.auctionlist[index].countdownremaining = data2.countdownremaining
                                    local f = AuctionFrame.entries[index]
                                    f:SetValues(index)
                                end
                            end
                        end
                        AuctionFrame:Update()
                    end
                elseif fdata.type == "添加收支" then
                    if not PlayerIsML() then
                        local player = GetClassColorName(fdata.player)
                        local amount = fdata.amount
                        local notes = fdata.notes
                        if not ZL_CURRENT.IncomeList then ZL_CURRENT.IncomeList = {} end
                        table.insert(ZL_CURRENT.IncomeList, {
                            player = player,
                            amount = amount,
                            notes = notes,
                        })
                        ZL.AuctionRecordFrame.currentIncomeFrame:Update()
                        ZL.AuctionRecordFrame.playerBalanceFrame:Update()
                    end
                elseif fdata.type == "删除拍卖记录" then
                    local v = fdata.index
                    table.remove(ZL_CURRENT["IncomeList"], v)
                    ZL.AuctionRecordFrame.currentIncomeFrame:Update()
                    ZL.AuctionRecordFrame.playerBalanceFrame:Update()
                elseif fdata.type == "删除拍卖物品" then
                    local data, index = FetchDataFromItemId(fdata.itemlink, fdata.itemindex)
                    if data then
                        local itemlink = ZL_CURRENT.auctionlist[index].itemlink
                        table.remove(ZL_CURRENT.auctionlist, index)
                        if ZL_CURRENT.auctionlist and (#ZL_CURRENT.auctionlist > 0) then
                            for num, _ in ipairs(ZL_CURRENT.auctionlist) do
                                local f = ZL.AuctionFrame2.entries[num]
                                f:SetValues(num)
                            end
                        end
                        AuctionFrame:Update()
                        print(Prefix("注意：ML已删除拍卖物品" .. itemlink))
                    end
                elseif fdata.type == "" then

                end
            end
        elseif (prefix == "AUTOAUC SYNC0") then--拾取创建
            if (PlayerIsML(sender)) and (not PlayerIsML()) then
                for _, data3 in ipairs(fdata.data) do
                    if data3.type == "创建拍卖" then
                        local data2 = data3.data2
                        local data, index = FetchDataFromItemId(data2.itemlink, data2.itemindex)
                        if data then
                            --首次拾取创建，不管是否有记录都同步ML状态
                            ZL_CURRENT.auctionlist[index] = data2
                        else
                            ZL.CreateAuctionList()
                            table.insert(ZL_CURRENT.auctionlist, data2)
                            index = #ZL_CURRENT.auctionlist
                            ZL_CURRENT.auctionlist[index].lgnore = false
                        end
                        ZL.AuctionListSort()
                    elseif data3.type == "数量更新" then
                        local data2 = data3.data2
                        local data, index = FetchDataFromItemId(data2.itemlink, data2.itemindex)
                        if data then
                            local lgnore = ZL_CURRENT.auctionlist[index].lgnore
                            local Frame1IsShown = ZL_CURRENT.auctionlist[index].Frame1IsShown
                            ZL_CURRENT.auctionlist[index] = data2
                            ZL_CURRENT.auctionlist[index].lgnore = lgnore
                            ZL_CURRENT.auctionlist[index].Frame1IsShown = Frame1IsShown
                        else
                            ZL.CreateAuctionList()
                            table.insert(ZL_CURRENT.auctionlist, data2)
                            index = #ZL_CURRENT.auctionlist
                            ZL_CURRENT.auctionlist[index].lgnore = false
                        end
                        ZL.AuctionListSort()
                    end
                end
                AuctionFrame:Update()
            end
        elseif (prefix == "AUTOAUC SYNC1") then--开始拍卖
            local isRestart = fdata.isRestart
            local tradeId = fdata.tradeId
            if isRestart == "重拍" and tradeId and ZL_CURRENT.IncomeList and #ZL_CURRENT.IncomeList > 0 then
                for i = #ZL_CURRENT.IncomeList, 1, -1 do
                    local _tradeId = ZL_CURRENT.IncomeList[i].tradeId
                    if _tradeId and _tradeId == tradeId then
                        table.remove(ZL_CURRENT.IncomeList, i)
                    end
                end
            end
            local ffdata = fdata.data2
            local _, index = FetchDataFromItemId(ffdata.itemlink, ffdata.itemindex)
            if (not index) then
                --如未查询到拍卖物品直接全部同步ML的
                ZL.CreateAuctionList()
                table.insert(ZL_CURRENT.auctionlist, ffdata)
                index = #ZL_CURRENT.auctionlist
                ZL_CURRENT.auctionlist[index].lgnore = false
            else
                --除了lgnore不同步，其他都同步ML
                local lgnore = ZL_CURRENT.auctionlist[index].lgnore
                ZL_CURRENT.auctionlist[index] = ffdata
                ZL_CURRENT.auctionlist[index].lgnore = lgnore
            end
            local curAuctionList = ZL_CURRENT.auctionlist[index]
            local itemLink = curAuctionList.itemlink
            local itemId = curAuctionList.itemId
            local countdownremaining = curAuctionList.countdownremaining
            local bindType = curAuctionList.bindType
            local bidIncrement = curAuctionList.bidIncrement
            local startbidamount = curAuctionList.startbidamount
            local msgStr = ""
            if ZL_CURRENT.globalConfig.intervalBidIncrement then
                if startbidamount < ZL_CURRENT.globalConfig.baseAmount1 then
                    bidIncrement = bidIncrement
                elseif startbidamount < ZL_CURRENT.globalConfig.baseAmount2 then
                    bidIncrement = math.max(ZL_CURRENT.globalConfig.bidIncrement1, bidIncrement)
                elseif startbidamount < ZL_CURRENT.globalConfig.baseAmount3 then
                    bidIncrement = math.max(ZL_CURRENT.globalConfig.bidIncrement2, bidIncrement)
                else
                    bidIncrement = math.max(ZL_CURRENT.globalConfig.bidIncrement3, bidIncrement)
                end
            end
            if countdownremaining > 1 then
                if curAuctionList.itemCount == 1 then
                    if bindType == 2 then
                        msgStr = ("装绑%s起拍价：%d，加价幅度：%d"):format(curAuctionList.itemlink, startbidamount, bidIncrement)
                        ZL.ScrollingMessageFrame:AddMessage(msgStr)
                    else
                        if curAuctionList.itemlink == "[打包拍卖]" then
                            local itemList = curAuctionList["itemList"]
                            if itemList and next(itemList, nil) then
                                msgStr = "打包拍卖清单："
                                ZL.ScrollingMessageFrame:AddMessage(msgStr)
                                C_Timer.After(0.3, function ()
                                    for _itemlink, data in pairs(itemList) do
                                        msgStr = _itemlink .. "x" .. data.itemCount
                                        ZL.ScrollingMessageFrame:AddMessage(msgStr)
                                    end
                                    C_Timer.After(0.3, function ()
                                        msgStr = ("以上%s，起拍价：%d，加价幅度：%d"):format(curAuctionList.itemlink, startbidamount, bidIncrement)
                                        ZL.ScrollingMessageFrame:AddMessage(msgStr)
                                    end)
                                end)
                            end
                        else
                            msgStr = ("%s起拍价：%d，加价幅度：%d"):format(curAuctionList.itemlink, startbidamount, bidIncrement)
                            ZL.ScrollingMessageFrame:AddMessage(msgStr)
                        end
                    end
                else
                    if bindType == 2 then
                        msgStr = ("装绑%sx%d，起拍价：%d，加价幅度：%d"):format(curAuctionList.itemlink, curAuctionList.itemCount, startbidamount, bidIncrement)
                        ZL.ScrollingMessageFrame:AddMessage(msgStr)
                    else
                        msgStr = ("%sx%d，起拍价：%d，加价幅度：%d"):format(curAuctionList.itemlink, curAuctionList.itemCount, startbidamount, bidIncrement)
                        ZL.ScrollingMessageFrame:AddMessage(msgStr)
                    end
                end
            end
            ZL.AuctionListSort()
            if countdownremaining > 1 then
                local soundName = ""
                if ZL.opt.concern and ZL.opt.concern[tostring(itemId)] then --关注的物品
                    if not ZL.AuctionFrame2:IsShown() then
                        ZL.maxFrame.maxBtn:Click()
                        _G["ZL_NewAuctionFrameTab1"]:Click()
                    end
                    soundName = "关注物品拍卖.mp3"
                    PlaySoundFile("Interface\\AddOns\\" .. addonName .. "\\sound\\" .. ZL.SoundType .. "\\" .. soundName, "Master")
                else
                    if ZL.opt.IsVoiceReminder and countdownremaining > 2 then
                        if ZL.opt.startAuctionSound then
                            local function linshi()
                                soundName = "开始拍卖" .. ZL.GetAuctionSoundText(itemLink)
                                C_VoiceChat.SpeakText(C_TTSSettings.GetVoiceOptionID(0), soundName, 1, 3, 100)
                            end
                            if itemId ~= 0 then
                                ZL.LoadItemDataByID(itemId, linshi) --先缓存物品信息
                            else
                                linshi()
                            end
                        else
                            soundName = "开始拍卖.mp3"
                            PlaySoundFile("Interface\\AddOns\\" .. addonName .. "\\sound\\" .. ZL.SoundType .. "\\" .. soundName, "Master")
                        end
                    end
                end
            end
        elseif (prefix == "AUTOAUC SYNC2") or (prefix == "AUTOAUC SYNC6") or (prefix == "AUTOAUC SYNC8") then
            --取消拍卖 or 拍卖成功 or 流拍
            local ffdata = fdata.data2
            local data, index = FetchDataFromItemId(ffdata.itemlink, ffdata.itemindex)
            if data then
                local lgnore = ZL_CURRENT.auctionlist[index].lgnore
                ZL_CURRENT.auctionlist[index] = ffdata
                ZL_CURRENT.auctionlist[index].lgnore = lgnore
                if (prefix == "AUTOAUC SYNC2") and PlayerIsML() then
                    ZL_CURRENT.auctionlist[index].Frame1IsShown = true
                    for _index, _data in ipairs(ZL_CURRENT.auctionlist) do
                        if _data.Frame1IsShown and (_data.state == ZL_CURRENT.auctionlist[index].state) and (not _data.lgnore) and _index ~= index then
                            ZL_CURRENT.auctionlist[_index].Frame1IsShown = false
                        end
                    end
                else
                    ZL_CURRENT.auctionlist[index].Frame1IsShown = false
                end
            else
                ZL.CreateAuctionList()
                table.insert(ZL_CURRENT.auctionlist, ffdata)
                index = #ZL_CURRENT.auctionlist
                ZL_CURRENT.auctionlist[index].Frame1IsShown =false
                ZL_CURRENT.auctionlist[index].lgnore = false
            end
            local itemLink = ZL_CURRENT.auctionlist[index].itemlink
            ZL.AuctionListSort()
            if ZL.opt.IsVoiceReminder then
                local soundName = ""
                if prefix == "AUTOAUC SYNC2" then
                    soundName = "拍卖已取消.mp3"
                    PlaySoundFile("Interface\\AddOns\\" .. addonName .. "\\sound\\" .. ZL.SoundType .. "\\" .. soundName, "Master")
                elseif prefix == "AUTOAUC SYNC6" then
                    soundName = "拍卖成功.mp3"
                    PlaySoundFile("Interface\\AddOns\\" .. addonName .. "\\sound\\" .. ZL.SoundType .. "\\" .. soundName, "Master")
                end
            end
        elseif (prefix == "AUTOAUC SYNC3") or (prefix == "AUTOAUC SYNC4") or (prefix == "AUTOAUC SYNC5") or (prefix == "AUTOAUC SYNC13") then
            --暂停拍卖 or 继续拍卖 or 手动倒数 or 取消倒数 or 同步单个
            local ffdata = fdata.data2
            local data, index = FetchDataFromItemId(ffdata.itemlink, ffdata.itemindex)
            if data then
                local lgnore = ZL_CURRENT.auctionlist[index].lgnore
                local Frame1IsShown = ZL_CURRENT.auctionlist[index].Frame1IsShown
                ZL_CURRENT.auctionlist[index] = ffdata
                ZL_CURRENT.auctionlist[index].lgnore = lgnore
                ZL_CURRENT.auctionlist[index].Frame1IsShown = Frame1IsShown
            else
                ZL.CreateAuctionList()
                table.insert(ZL_CURRENT.auctionlist, ffdata)
                index = #ZL_CURRENT.auctionlist
                ZL_CURRENT.auctionlist[index].lgnore = false
            end
            if ZL_CURRENT.auctionlist[index].Frame1IsShown then
                for _index, _data in ipairs(ZL_CURRENT.auctionlist) do
                    if _data.Frame1IsShown and (_data.state == ZL_CURRENT.auctionlist[index].state) and (not _data.lgnore) and _index ~= index then
                        ZL_CURRENT.auctionlist[_index].Frame1IsShown = false
                    end
                end
            end
            local itemLink = ZL_CURRENT.auctionlist[index].itemlink
            ZL.AuctionListSort()
            if ZL.opt.IsVoiceReminder then
                local soundName = ""
                if prefix == "AUTOAUC SYNC3" then
                    -- if ZL.SoundType == "系统语音" then
                    --     soundName = itemLink .. "拍卖已暂停"
                    --     C_VoiceChat.SpeakText(C_TTSSettings.GetVoiceOptionID(0), soundName, 1, 3, 100)
                    -- else
                    --     PlaySoundFile("Interface\\AddOns\\" .. addonName .. "\\sound\\" .. ZL.SoundType .. "\\拍卖已暂停.mp3", "Master")
                    -- end
                    PlaySoundFile("Interface\\AddOns\\" .. addonName .. "\\sound\\" .. ZL.SoundType .. "\\拍卖已暂停.mp3", "Master")
                elseif prefix == "AUTOAUC SYNC4" then
                    -- if ZL.SoundType == "系统语音" then
                    --     soundName = itemLink .. "拍卖已恢复"
                    --     C_VoiceChat.SpeakText(C_TTSSettings.GetVoiceOptionID(0), soundName, 1, 3, 100)
                    -- else
                    --     PlaySoundFile("Interface\\AddOns\\" .. addonName .. "\\sound\\" .. ZL.SoundType .. "\\拍卖已恢复.mp3", "Master")
                    -- end
                    PlaySoundFile("Interface\\AddOns\\" .. addonName .. "\\sound\\" .. ZL.SoundType .. "\\拍卖已恢复.mp3", "Master")
                end
            end
        elseif (prefix == "AUTOAUC SYNC7") then--拍卖拆单
            if (PlayerIsML(sender)) and (not PlayerIsML()) then
                for _, data3 in ipairs(fdata.data) do
                    if data3.type == "拍卖成功" then
                        local data2 = data3.data2
                        local data, index = FetchDataFromItemId(data2.itemlink, data2.itemindex)
                        if data then
                            local lgnore = ZL_CURRENT.auctionlist[index].lgnore
                            ZL_CURRENT.auctionlist[index] = data2
                            ZL_CURRENT.auctionlist[index].lgnore = lgnore
                            ZL_CURRENT.auctionlist[index].Frame1IsShown = false
                        else
                            ZL.CreateAuctionList()
                            table.insert(ZL_CURRENT.auctionlist, data2)
                            index = #ZL_CURRENT.auctionlist
                            ZL_CURRENT.auctionlist[index].lgnore = false
                        end
                        ZL.AuctionListSort()
                    elseif data3.type == "流拍" then
                        local data2 = data3.data2
                        local data, index = FetchDataFromItemId(data2.itemlink, data2.itemindex)
                        if data then
                            --拆单流拍物品属于首次创建，保持跟ML同步
                            ZL_CURRENT.auctionlist[index] = data2
                        else
                            ZL.CreateAuctionList()
                            table.insert(ZL_CURRENT.auctionlist, data2)
                            index = #ZL_CURRENT.auctionlist
                            ZL_CURRENT.auctionlist[index].lgnore = false
                        end
                        ZL.AuctionListSort()
                    end
                end
                AuctionFrame:Update()
            end
            if ZL.opt.IsVoiceReminder and (PlayerIsML(sender)) then
                local soundName = "拍卖成功.mp3"
                PlaySoundFile("Interface\\AddOns\\" .. addonName .. "\\sound\\" .. ZL.SoundType .. "\\" .. soundName, "Master")
            end
        elseif (prefix == "AUTOAUC SYNC9") then--手动创建
            if (PlayerIsML(sender)) and (not PlayerIsML()) then
                local ffdata = fdata.data2
                local data, index = FetchDataFromItemId(ffdata.itemlink, ffdata.itemindex)
                if data then
                    --手动创建拍卖强制跟ML同步
                    ZL_CURRENT.auctionlist[index] = ffdata
                else
                    ZL.CreateAuctionList()
                    table.insert(ZL_CURRENT.auctionlist, ffdata)
                    index = #ZL_CURRENT.auctionlist
                    ZL_CURRENT.auctionlist[index].lgnore = false
                end
                ZL.AuctionListSort()
            end
        elseif (prefix == "AUTOAUC SYNC10") then--删除拍卖物品
            if (PlayerIsML(sender)) and (not PlayerIsML()) then
                local data, index = FetchDataFromItemId(fdata.itemlink, fdata.itemindex)
                if data then
                    local curAuctionList = ZL_CURRENT.auctionlist[index]
                    local itemlink = curAuctionList.itemlink
                    if curAuctionList.itemGUID and next(curAuctionList.itemGUID, nil) then
                        for itemGUID, _ in pairs(curAuctionList.itemGUID) do
                            if ZL_CURRENT.itemGUIDUsed then
                                ZL_CURRENT.itemGUIDUsed[itemGUID] = nil
                            end
                        end
                    end
                    if itemlink == "[打包拍卖]" then
                        local itemList = curAuctionList["itemList"]
                        if itemList and next(itemList, nil) then
                            for _itemlink, _data in pairs(itemList) do
                                for _, __itemindex in ipairs (_data.itemindex) do
                                    local _, __index = ZL.FetchDataFromItemId(_itemlink, __itemindex)
                                    if __index then ZL_CURRENT.auctionlist[__index].isPackage = nil end
                                end
                            end
                        end
                    end
                    table.remove(ZL_CURRENT.auctionlist, index)
                    if ZL_CURRENT.auctionlist and (#ZL_CURRENT.auctionlist > 0) then
                        for num, _ in ipairs(ZL_CURRENT.auctionlist) do
                            local f = ZL.AuctionFrame2.entries[num]
                            f:SetValues(num)
                        end
                    end
                    AuctionFrame:Update()
                    print(Prefix("注意：ML已删除拍卖物品" .. fdata.itemlink))
                    ZL.ScrollingMessageFrame:AddMessage("注意：已删除拍卖物品" .. itemlink)
                end
            end
        elseif (prefix == "AUTOAUC SYNC11") then--添加收支
            if (PlayerIsML(sender)) and (not PlayerIsML()) then
                ZL_CURRENT.IncomeList = fdata.data
                ZL.AuctionRecordFrame.currentIncomeFrame:Update()
                ZL.AuctionRecordFrame.playerBalanceFrame:Update()
            end
        elseif (prefix == "AUTOAUC SYNC12") then--删除收支记录
            if (PlayerIsML(sender)) and (not PlayerIsML()) then
                local v = fdata.index
                table.remove(ZL_CURRENT["IncomeList"], v)
                ZL.AuctionRecordFrame.currentIncomeFrame:Update()
                ZL.AuctionRecordFrame.playerBalanceFrame:Update()
            end
        elseif (prefix == "AUTOAUC SYNC14") then --添加打包拍卖
            if (PlayerIsML(sender)) and (not PlayerIsML()) then
                do
                    local ffdata = fdata.data1
                    local data, index = FetchDataFromItemId(ffdata.itemlink, ffdata.itemindex)
                    if not data then
                        ZL.CreateAuctionList()
                        table.insert(ZL_CURRENT.auctionlist, ffdata)
                        index = #ZL_CURRENT.auctionlist
                        ZL_CURRENT.auctionlist[index].lgnore = false
                    end
                    ZL_CURRENT.auctionlist[index].isPackage = true
                end
                do
                    local ffdata = fdata.data2
                    local data, index = FetchDataFromItemId(ffdata.itemlink, ffdata.itemindex)
                    if not data then
                        ZL.CreateAuctionList()
                        table.insert(ZL_CURRENT.auctionlist, ffdata)
                        index = #ZL_CURRENT.auctionlist
                        ZL_CURRENT.auctionlist[index].lgnore = false
                    else
                        local lgnore = ZL_CURRENT.auctionlist[index].lgnore
                        local Frame1IsShown = ZL_CURRENT.auctionlist[index].Frame1IsShown
                        ZL_CURRENT.auctionlist[index] = ffdata
                        ZL_CURRENT.auctionlist[index].lgnore = lgnore
                        ZL_CURRENT.auctionlist[index].Frame1IsShown = Frame1IsShown
                    end
                end
                ZL.AuctionListSort()
            end
        elseif (prefix == "AUTOAUC SYNC15") then --剔除打包拍卖
            if (PlayerIsML(sender)) and (not PlayerIsML()) then
                local _, __index = FetchDataFromItemId("[打包拍卖]", 1)
                if __index then
                    local itemLink = fdata.itemLink
                    local itemindexList = ZL_CURRENT.auctionlist[__index]["itemList"][itemLink]["itemindex"]
                    --先把需要剔除的物品isPackage清楚
                    if itemindexList and #itemindexList > 0 then
                        for _, _itemindex in ipairs(itemindexList) do
                            local _, index = ZL.FetchDataFromItemId(itemLink, _itemindex)
                            if index then
                                ZL_CURRENT.auctionlist[index]["isPackage"] = nil
                            end
                        end
                    end
                    ZL_CURRENT.auctionlist[__index]["itemList"][itemLink] = nil
                    ZL.PackageListFrame:Update(__index)
                    AuctionFrame:Update()
                end
            end
        elseif (prefix == "AUTOAUC REQ") then --登录或重载UI时请求同步ML数据
            if (not PlayerIsML(sender)) and PlayerIsML() then
                TransmitAddonInfo_Pro()
                if ZL_CURRENT.auctionlist and #ZL_CURRENT.auctionlist > 0 then
                    local raidIndex = UnitInRaid(sender)
                    if raidIndex then
                        MyAddon:TransmitAddonInfo2("AUTOAUC WSP" .. raidIndex, ZL_CURRENT.auctionlist, "WHISPER", sender)
                    end
                else
                    SendChatMessage("没有拍卖数据需要同步", "WHISPER", nil ,sender)
                end
            end
        elseif prefix:match("^AUTOAUC WSP%d+$") then
            if PlayerIsML(sender) and (not PlayerIsML()) then
                if ZL_CURRENT["auctionlist"] and (#ZL_CURRENT["auctionlist"] > 0) then
                    for num, data in ipairs(ZL_CURRENT["auctionlist"]) do
                        local f = AuctionFrame.entries[num]
                        if data.state == "auctioning" then
                            ZL_CURRENT.auctionlist[num].state = "waiting"
                            ZL_CURRENT.auctionlist[num].countdownremaining = 0
                            ZL_CURRENT.auctionlist[num].isPaused = false
                            ZL_CURRENT.auctionlist[num].bidderlist = {}
                            f:SetValues(num)
                        end
                        f:Hide()
                    end
                end
                ZL_CURRENT["auctionlist"] = fdata
                ZL.AuctionListSort()
                local msgStr = "拍卖数据已同步！"
                print(Prefix(msgStr))
                ZL.ScrollingMessageFrame:AddMessage(msgStr)
            end
        elseif (prefix == "AUTOAUC RETAKE") then --申请重拍
            if (not PlayerIsML(sender)) and PlayerIsML() then
                local msgStr = ""
                local AuctioningCount = ZL.GetAuctioningCount()
                if (not ZL_CURRENT.globalConfig.allowMultipleAuctions) and AuctioningCount > 0 then
                    msgStr = "当前为单拍模式，有物品正在拍卖中，请结束后再提交重拍申请"
                    SendChatMessage(msgStr, "WHISPER", nil, sender)
                else
                    local data = FetchDataFromItemId(fdata.itemlink, fdata.itemindex)
                    if data and data.state == "failed" then
                        local isExist
                        local isSelf
                        if ZL.retake and #ZL.retake > 0 then
                            for _, value in ipairs(ZL.retake) do
                                if value.itemlink == fdata.itemlink and value.itemindex == fdata.itemindex then
                                    isExist = true
                                    if value.sender == sender then
                                        isSelf = true
                                    end
                                    break
                                end
                            end
                        end
                        if isExist then
                            if isSelf then
                                msgStr = fdata.itemlink .. "你已提交过重拍申请，请勿重复提交"
                            else
                                msgStr = fdata.itemlink .. "已有人提交过重拍申请，请等待ML响应"
                            end
                            SendChatMessage(msgStr, "WHISPER", nil, sender)
                        else
                            if ZL.IsCanAuction(data, senderColorName) then
                                msgStr = ">>>" .. senderColorName .. "<<<请求重拍流拍物品：" .. fdata.itemlink .. "请确认是否重拍？"
                                fdata.sender = sender
                                if not ZL.retake then ZL.retake = {} end
                                tinsert(ZL.retake, fdata)
                                if not StaticPopup1:IsShown() then
                                    StaticPopup_Show("ZL_RETAKE", msgStr)
                                else
                                    StaticPopup1Text:SetText(msgStr)
                                end
                            else
                                msgStr = fdata.itemlink.. "无法申请重拍，原因可能是：已分解或无法交易"
                                SendChatMessage(msgStr, "WHISPER", nil, sender)
                            end
                        end
                    else
                        msgStr = "未找到流拍物品：" .. fdata.itemlink
                        SendChatMessage(msgStr, "WHISPER", nil, sender)
                    end
                end
            end
        elseif (prefix == "AUTOAUC TONGBU") then
            if (PlayerIsML(sender)) then
                if fdata.type == "同步所有" then
                    if (not PlayerIsML()) then
                        local lgnoreList = {}
                        if ZL_CURRENT["auctionlist"] and (#ZL_CURRENT["auctionlist"] > 0) then
                            for num, data in ipairs(ZL_CURRENT["auctionlist"]) do
                                local f = AuctionFrame.entries[num]
                                if data.state == "auctioning" then
                                    f.Frame1.timer.updateframe:Hide()
                                    f.Frame1.statetext:SetText("拍卖已取消，等待重新拍卖")
                                    f.Frame1.curbidamounttext:SetText("有效出价：")
                                    f.Frame1.curbiddertext:SetText("当前无人出价！")
                                    if f.Frame1.timer:IsPaused() then
                                        f.Frame1.timer:Resume()
                                        f.Frame1.MLframe.PauseBtn:SetText("暂停")
                                    end
                                    f.Frame1.timer:SetCooldown(0, 0)
                                    f.Frame1.bidbox:Disable()
                                    f.Frame1.bidBtn:Disable()
                                    f.Frame1.autobidBtn:Disable()
                                    f.Frame1.MLframe.PauseBtn:Disable()
                                    f.Frame1.MLframe.CountDownBtn:Disable()
                                    f.Frame1.MLframe.reverseBidBtn:Disable()
                                end
                                if data.lgnore then
                                    table.insert(lgnoreList, {itemId=data.itemId, itemindex=data.itemindex})
                                end
                                f:Hide()
                            end
                        end
                        ZL_CURRENT = fdata.current
                        if ZL_CURRENT.auctionlist and (#ZL_CURRENT.auctionlist > 0) then
                            for num, data in ipairs(ZL_CURRENT.auctionlist) do
                                ZL_CURRENT.auctionlist[num].lgnore = false
                                if #lgnoreList > 0 then
                                    for _, data2 in ipairs(lgnoreList) do
                                        if data2.itemId == data.itemId and data2.itemindex == data.itemindex then
                                            ZL_CURRENT.auctionlist[num].lgnore = true
                                        end
                                    end
                                end
                                local f = AuctionFrame.entries[num]
                                f:SetValues(num)
                            end
                        end
                        AuctionFrame:Update()
                    end
                    if ZL_CURRENT["auctionlist"] and #ZL_CURRENT["auctionlist"] > 0 then
                        for index, data in ipairs(ZL_CURRENT["auctionlist"]) do
                            if data.state == "auctioning" and data.isPaused and data.isPausedLinshi then
                                data["isPaused"] = false
                                data.isPausedLinshi = false
                                local f = AuctionFrame.entries[index]
                                f.Frame1.timer:Resume()
                                if ZL.IsCandidate(index) then
                                    f.Frame1.statetext:SetText("拍卖中...")
                                    if f.maxAutoBid then
                                        f.Frame1.bidbox:Disable()
                                        f.Frame1.bidBtn:Disable()
                                        f.Frame1.lgnoreBtn:Disable()
                                    else
                                        f.Frame1.bidbox:Enable()
                                        f.Frame1.bidBtn:Enable()
                                        f.Frame1.lgnoreBtn:Enable()
                                    end
                                    f.Frame1.autobidBtn:Enable()
                                else
                                    f.Frame1.statetext:SetText("你不是装备候选人，无法竞拍")
                                    f.Frame1.bidbox:Disable()
                                    f.Frame1.bidBtn:Disable()
                                    f.Frame1.autobidBtn:Disable()
                                    f.Frame1.lgnoreBtn:Enable()
                                end
                            end
                        end
                    end
                elseif fdata.type == "同步单个" then
                    local itemlink = fdata.curAuction.itemlink
                    local itemindex = fdata.curAuction.itemindex
                    local data, index = FetchDataFromItemId(itemlink, itemindex)
                    if (not data) then
                        ZL.CreateAuctionList()
                        table.insert(ZL_CURRENT.auctionlist, fdata.curAuction)
                        index = #ZL_CURRENT.auctionlist
                    else
                        ZL_CURRENT.auctionlist[index].startbidamount = fdata.curAuction.startbidamount
                        ZL_CURRENT.auctionlist[index].bidIncrement = fdata.curAuction.bidIncrement
                        ZL_CURRENT.auctionlist[index].state = fdata.curAuction.state
                        ZL_CURRENT.auctionlist[index].countdownremaining = fdata.curAuction.countdownremaining
                        ZL_CURRENT.auctionlist[index].auctionTimerRefresh = fdata.curAuction.auctionTimerRefresh
                        ZL_CURRENT.auctionlist[index].isPaused = fdata.curAuction.isPaused
                        ZL_CURRENT.auctionlist[index].bidderlist = fdata.curAuction.bidderlist
                        ZL_CURRENT.auctionlist[index].itemCount = fdata.curAuction.itemCount
                        ZL_CURRENT.auctionlist[index].isPausedLinshi = fdata.curAuction.isPausedLinshi
                        ZL_CURRENT.auctionlist[index].candidates = fdata.curAuction.candidates
                    end
                    local f = AuctionFrame.entries[index]
                    f:SetValues(index)
                    if ZL_CURRENT.auctionlist[index].state == "auctioning" and ZL_CURRENT.auctionlist[index]["isPaused"]
                            and ZL_CURRENT.auctionlist[index].isPausedLinshi then
                        ZL_CURRENT.auctionlist[index]["isPaused"] = false
                        ZL_CURRENT.auctionlist[index]["isPausedLinshi"] = false
                        f = AuctionFrame.entries[index]
                        f.Frame1.timer:Resume()
                        if ZL.IsCandidate(index) then
                            f.Frame1.statetext:SetText("拍卖中...")
                            if f.maxAutoBid then
                                f.Frame1.bidbox:Disable()
                                f.Frame1.bidBtn:Disable()
                                f.Frame1.lgnoreBtn:Disable()
                            else
                                f.Frame1.bidbox:Enable()
                                f.Frame1.bidBtn:Enable()
                                f.Frame1.lgnoreBtn:Enable()
                            end
                            f.Frame1.autobidBtn:Enable()
                        else
                            f.Frame1.statetext:SetText("你不是装备候选人，无法竞拍")
                            f.Frame1.bidbox:Disable()
                            f.Frame1.bidBtn:Disable()
                            f.Frame1.autobidBtn:Disable()
                            f.Frame1.lgnoreBtn:Enable()
                        end
                    end
                    ZL.AuctionListSort()
                end
            end
        elseif (prefix == "AUTOAUC RESET") then --重置其它成员的
            if (not PlayerIsML()) and PlayerIsML(sender) then
                if ZL_CURRENT["auctionlist"] and (#ZL_CURRENT["auctionlist"] > 0) then
                    for num, data in ipairs(ZL_CURRENT["auctionlist"]) do
                        local f = AuctionFrame.entries[num]
                        if data.state == "auctioning" then
                            ZL_CURRENT.auctionlist[num].state = "waiting"
                            ZL_CURRENT.auctionlist[num].countdownremaining = 0
                            ZL_CURRENT.auctionlist[num].isPaused = false
                            ZL_CURRENT.auctionlist[num].bidderlist = {}
                            f:SetValues(num)
                        end
                        f:Hide()
                    end
                    local totalincome = 0
                    if ZL_CURRENT.IncomeList and #ZL_CURRENT.IncomeList > 0 then
                        for _, data in ipairs(ZL_CURRENT.IncomeList) do
                            totalincome = totalincome + data.amount
                        end
                    end
                    ZL_CURRENT.totalincome = totalincome
                    if (not ZL_CURRENT.name) then ZL_CURRENT.name = GetInstanceInfo() end
                    if (not ZL_CURRENT.auctiondate) then ZL_CURRENT.auctiondate = date("%Y-%m-%d %H:%M:%S", time()) end
                    table.insert(ZL_HISTORY, ZL_CURRENT)
                    ZL_CURRENT = {}
                    AuctionFrame:Update()
                    ZL.AuctionRecordFrame.historyFrame:Update()
                    ZL.AuctionRecordFrame.currentIncomeFrame:Update()
                    ZL.AuctionRecordFrame.playerBalanceFrame:Update()
                else
                    ZL_CURRENT = {}
                end
            end
            if PlayerIsML(sender) then
                ZL.TransmitAddonInfo_Pro()
            end
        elseif (prefix == "AUTOAUC PRO") then --同步配置文件全局参数
            if PlayerIsML(sender) then
                if not ZL_CURRENT.globalConfig then ZL_CURRENT.globalConfig = {} end
                ZL_CURRENT.globalConfig = fdata
            end
        elseif (prefix == "AUTOAUC REVOKE") then --撤销指定玩家出价
            if (PlayerIsML(sender)) then
                local itemlink = fdata.itemlink
                local itemindex = fdata.itemindex
                local sdata, index = FetchDataFromItemId(itemlink, itemindex)
                if sdata then
                    local playerName = fdata.playerName
                    local bidderlist = ZL_CURRENT.auctionlist[index].bidderlist
                    if bidderlist and #bidderlist then
                        for num, data in ipairs(bidderlist) do
                            if data.bidder == playerName then
                                table.remove(ZL_CURRENT.auctionlist[index].bidderlist, num)
                                tableSort(ZL_CURRENT.auctionlist[index].bidderlist)
                                bidderlist = ZL_CURRENT.auctionlist[index].bidderlist
                                ZL_CURRENT.auctionlist[index].countdownremaining = ZL_CURRENT.auctionlist[index].auctionTimerRefresh--更新了出价，重新倒计时
                                local Frame1 = ZL.AuctionFrame2.entries[index]
                                Frame1:SetValues(index)
                                if PlayerIsML() then
                                    local msgStr = ""
                                    local curAuctionList = ZL_CURRENT.auctionlist[index]
                                    local _, _, tarbidamount, bidCount = ZL.GetNewBidAmount(index)
                                    bidderlist = ZL_CURRENT.auctionlist[index].bidderlist
                                    if #bidderlist > 0 then
                                        local totalBidCount = 0
                                        for _, bidData in ipairs(bidderlist) do
                                            if totalBidCount < curAuctionList.itemCount then
                                                local count = bidData["bidCount"] or 1
                                                local newTotalBidCount = totalBidCount + count
                                                if newTotalBidCount > curAuctionList.itemCount then
                                                    count = curAuctionList.itemCount - totalBidCount
                                                end
                                                if count  > 1 then
                                                    msgStr = msgStr .. ParseClassColorName(bidData.bidder) .. "(" .. bidData.bidamount .. "x" .. count .. ")，"
                                                else
                                                    msgStr = msgStr .. ParseClassColorName(bidData.bidder) .. "(" .. bidData.bidamount .. ")，"
                                                end
                                                totalBidCount = newTotalBidCount
                                            else
                                                break
                                            end
                                        end
                                        msgStr = ("%s已撤销>>>%s<<<的出价，当前出价：%s下次最低出价：%d，对应最大数量%d"):format(
                                            curAuctionList.itemlink, ParseClassColorName(playerName), msgStr, tarbidamount, bidCount
                                        )
                                        SendChatMessage(msgStr, ZL.MsgChannel())
                                    else
                                        SendChatMessage(("%s已撤销>>>%s<<<的出价，当前无人出价，下次最低出价：%d，对应最大数量%d"):format(
                                            curAuctionList.itemlink, ParseClassColorName(playerName), tarbidamount, bidCount), ZL.MsgChannel()
                                        )
                                    end
                                end
                                break
                            end
                        end
                    end
                end
            end
        elseif (prefix == "AUTOAUC VER") then
            if fdata.type == "request" then
                local data = {type="requestback", ver=ZL.addonVersion}
                MyAddon:TransmitAddonInfo2("AUTOAUC VER", data, "WHISPER", sender)
            elseif fdata.type == "requestback" then
                if (not ZL_CURRENT.GroupMembersVersion) then ZL_CURRENT.GroupMembersVersion = {} end
                ZL_CURRENT.GroupMembersVersion[sender] = fdata.ver
            elseif fdata.type == "requestWA" then
                local dataID = "[AutoAuction]金团拍卖助手"
                local sendVer, msgStr = CheckWaVersion(dataID)
                print(msgStr)
                if not sendVer then
                    SendChatMessage("M L拍卖WA不存在或版本过低，暂时无法同步！", "WHISPER", nil ,sender)
                else
                    local sendVerNum
                    sendVerNum = sendVer:gsub("V", ""):gsub("%.", "")
                    sendVerNum = tonumber(sendVerNum)
                    local targetVer = fdata.ver
                    targetVer = targetVer:gsub("WA%-V", ""):gsub("%.", "")
                    targetVer = tonumber(targetVer)
                    if sendVerNum > targetVer then
                        --开始发送WA字符串
                        local function ObfuscateName(name)
                            if (GetCurrentRegion() == 5) then
                                local result = ""
                                for i = 1, #name do
                                    local b = name:byte(i)
                                    if (b >= 196 and i ~= 1) then
                                    -- UTF8 Start byte
                                    result = result .. string.char(46, b)
                                    else
                                    result = result .. string.char(b)
                                    end
                                end
                                return result
                            else
                                return name
                            end
                        end
                        local fullName
                        if (not fullName) then
                            local name, realm = UnitFullName("player")
                            if realm then
                                fullName = name.."-".. ObfuscateName(realm)
                            else
                                fullName = name
                            end
                        end
                        local text = "[WeakAuras: " .. fullName .. " - " .. dataID .. " " .. sendVer .. "]"
                        SendChatMessage(text, "WHISPER", nil ,sender)
                    elseif sendVerNum == targetVer then
                        SendChatMessage("你目前是最新版本，不需要更新", "WHISPER", nil ,sender)
                    else
                        SendChatMessage("M L拍卖WA版本过低，不需要同步！", "WHISPER", nil ,sender)
                    end
                end
            end
        elseif (prefix == "AUTOAUC SOUND") then
            if ZL.opt.IsVoiceReminder then
                -- local soundName = ""
                -- if ZL.SoundType == "系统语音" then
                --     if fdata == "拍卖提醒.mp3" then
                --         soundName = "拍卖提醒，请注意及时出价"
                --     elseif fdata == "倒数已取消.mp3" then
                --         soundName = "倒数已取消，请继续出价"
                --     elseif fdata == "拍卖倒数.mp3" then
                --         soundName = "拍卖倒数"
                --     end
                --     C_VoiceChat.SpeakText(C_TTSSettings.GetVoiceOptionID(0), soundName, 1, 3, 100)
                -- else
                --     PlaySoundFile("Interface\\AddOns\\" .. addonName .. "\\sound\\" .. ZL.SoundType .. "\\" .. fdata, "Master")
                -- end
                if fdata.type == "录制" then
                    PlaySoundFile("Interface\\AddOns\\" .. addonName .. "\\sound\\" .. ZL.SoundType .. "\\" .. fdata.soundName, "Master")
                elseif fdata.type == "系统" then
                    C_VoiceChat.SpeakText(C_TTSSettings.GetVoiceOptionID(0), fdata.soundName, 1, 3, 100)
                end
            end
        elseif (prefix == "WeakAuras") then
            -- print(fdata, fdata.m, fdata.d)
        end
    end
end
