-- WarbandCamp/Core/Warband.lua -- Warband Camp state: parse the server's CHAT_MSG_SYSTEM replies to `.camp` -- commands into a small session-cached state table the tab renders from. local addonName, WBC = ... local W = { probed = false, -- have we heard ANY .camp status yet this session enabled = nil, -- false only after the literal not-enabled line hasCamp = nil, zone = nil, privacy = nil, count = nil, -- props placed cap = nil, -- prop cap; nil = unlimited (MaxProps=0) or unknown } WBC.Warband = W -- UI refresh hooks (the tab registers one). local callbacks = {} function W.OnChange(fn) table.insert(callbacks, fn) end local function notify() for _, fn in ipairs(callbacks) do pcall(fn) end end local function strip(msg) return (msg:gsub("|c%x%x%x%x%x%x%x%x", ""):gsub("|r", "")) end -- Silent probe (no history entry). Delay lets claim/leave settle server-side. function W.Probe(delay) WBC.After(delay or 0, function() SendChatMessage(".camp", "SAY") end) end -- Parse one system line. Returns true if it was a Warband line. function W.ParseSystem(msg) if type(msg) ~= "string" then return false end msg = strip(msg) if msg:find("Warband Camps are not enabled", 1, true) then W.probed, W.enabled = true, false notify(); return true end if msg:find("You have no Warband Camp yet", 1, true) or msg:find("You have no camp%.", 1) then W.probed, W.enabled, W.hasCamp = true, true, false W.zone, W.count, W.cap, W.privacy = nil, nil, nil, nil notify(); return true end -- Camp status with privacy & cap local zoneP, privP, nP, mP = msg:match("Your Warband Camp is in (.-) %(Privacy: (.-)%), with (%d+) of (%d+) things set up") if zoneP then W.probed, W.enabled, W.hasCamp = true, true, true W.zone, W.privacy, W.count, W.cap = zoneP, privP, tonumber(nP), tonumber(mP) notify(); return true end -- Camp status with privacy unlimited local zonePU, privPU, nPU = msg:match("Your Warband Camp is in (.-) %(Privacy: (.-)%), with (%d+) things set up") if zonePU then W.probed, W.enabled, W.hasCamp = true, true, true W.zone, W.privacy, W.count, W.cap = zonePU, privPU, tonumber(nPU), nil notify(); return true end local zone, n, m = msg:match("Your Warband Camp is in (.-), with (%d+) of (%d+) things set up") if zone then W.probed, W.enabled, W.hasCamp = true, true, true W.zone, W.count, W.cap = zone, tonumber(n), tonumber(m) notify(); return true end local zone2, n2 = msg:match("Your Warband Camp is in (.-), with (%d+) things set up") if zone2 then W.probed, W.enabled, W.hasCamp = true, true, true W.zone, W.count, W.cap = zone2, tonumber(n2), nil notify(); return true end -- Place success: "