assert( oRA, "oRA not found!") ------------------------------ -- Are you local? -- ------------------------------ local L = AceLibrary("AceLocale-2.2"):new("oRAOLatency") ---------------------------- -- Localization -- ---------------------------- L:RegisterTranslations("enUS", function() return { ["Latency"] = true, ["Options for latency checks."] = true, ["Checks Disabled"] = true, ["Refresh"] = true, ["Close"] = true, ["Unknown"] = true, ["Name"] = true, ["Optional/Latency"] = true, ["Perform latency check"] = true, ["Check the raid's latency."] = true, ["n/a"] = true, ["ms"] = true, } end ) ---------------------------------- -- Module Declaration -- ---------------------------------- local mod = oRA:NewModule("OptionalLatency") mod.defaults = { latencydisable = false, } mod.participant = true mod.name = L["Optional/Latency"] mod.consoleCmd = "latency" mod.consoleOptions = { type = "execute", name = L["Perform latency check"], desc = L["Check the raid's latency."], handler = mod, func = "PerformLatencyCheck", disabled = function() return not oRA:IsModuleActive(mod) end, } ------------------------------ -- Initialization -- ------------------------------ local latency = nil function mod:OnEnable() self:RegisterShorthand("ralag", "PerformLatencyCheck") self:RegisterShorthand("ralatency", "PerformLatencyCheck") self:RegisterCheck("LAGC", "oRA_LatencyCheck") self:RegisterCheck("LAG", "oRA_LatencyResponse") end ------------------------- -- Event Handlers -- ------------------------- function mod:oRA_LatencyCheck( msg, author) if not oRA:IsValidRequest(author) then return end if self.db.profile.latencydisable then oRA:SendMessage("LAG -1 "..author) else local _, _, latencyms = GetNetStats() oRA:SendMessage("LAG "..latencyms.." "..author) end end function mod:oRA_LatencyResponse( msg, author) local latencyms, requestby = select(3, msg:find("^LAG ([-%d]+) (.+)")) if latencyms and requestby and requestby == UnitName("player") then latencyms = tonumber(latencyms) if latencyms == -1 then self:AddPlayer( author, L["Checks Disabled"] ) else self:AddPlayer( author, latencyms..L["ms"] ) end oRA:UpdateWindow() end end --------------------------- -- Utility Functions -- --------------------------- function mod:AddPlayer( nick, latencyms ) table.insert(latency, self:new(self.coloredNames[nick], latencyms)) end ----------------------- -- Command Handlers -- ----------------------- local function RefreshLatency() mod:PerformLatencyCheck() end local paintchips = nil function mod:PerformLatencyCheck() if not oRA:IsPromoted() then return end latency = self:del(latency) latency = self:new() oRA:SendMessage( "LAGC" ) oRA:OpenWindow( L["Latency"], latency, RefreshLatency, L["Name"], 150, L["Latency"], 130 ) end