From 54e18378f7d8bab898af503b6dcf9318ddd083dd Mon Sep 17 00:00:00 2001 From: kompolompo Date: Sun, 30 Aug 2026 11:35:58 +0200 Subject: [PATCH] Initial commit of OctoLatency addon --- OctoLatency.lua | 75 +++++++++++++++++++++++++++++++++++++++++++++++++ OctoLatency.toc | 9 ++++++ OctoLatency.xml | 58 ++++++++++++++++++++++++++++++++++++++ README.md | 19 +++++++++++++ 4 files changed, 161 insertions(+) create mode 100644 OctoLatency.lua create mode 100644 OctoLatency.toc create mode 100644 OctoLatency.xml create mode 100644 README.md diff --git a/OctoLatency.lua b/OctoLatency.lua new file mode 100644 index 0000000..6da3ac7 --- /dev/null +++ b/OctoLatency.lua @@ -0,0 +1,75 @@ +-------------------------------------------------------------------------------- +-- OctoLatency for Vanilla WoW (1.12.1) - Author: Palladinpala +-------------------------------------------------------------------------------- + +-- Throttle timer to reduce CPU/performance overhead +local elapsedTimer = 0 +local UPDATE_INTERVAL = 2.0 -- update every 2 seconds + +function OctoLatency_OnLoad(self) + -- Register events + self:RegisterEvent("VARIABLES_LOADED") + + -- Tooltip on hover + self:SetScript("OnEnter", function() + GameTooltip:SetOwner(this, "ANCHOR_TOP") + GameTooltip:AddLine("OctoLatency", 0, 1, 1) + local bandwidth, latency, homeLatency, worldLatency = GetNetStats() + GameTooltip:AddLine("Home Latency: " .. homeLatency .. " ms", 1, 1, 1) + GameTooltip:AddLine("World Latency: " .. worldLatency .. " ms", 1, 1, 1) + GameTooltip:AddLine("Bandwidth: " .. string.format("%.2f", bandwidth) .. " KB/s", 1, 1, 1) + GameTooltip:AddLine("Left-click and drag to move.", 0.7, 0.7, 0.7) + GameTooltip:Show() + end) + + self:SetScript("OnLeave", function() + GameTooltip:Hide() + end) +end + +function OctoLatency_OnUpdate(elapsed) + elapsedTimer = elapsedTimer + elapsed + if (elapsedTimer < UPDATE_INTERVAL) then + return + end + elapsedTimer = 0 + + -- GetNetStats returns: bandwidth, latency, homeLatency, worldLatency + local _, _, homeLatency, worldLatency = GetNetStats() + + -- We'll display world latency (or max of home/world) + local latency = worldLatency or homeLatency or 0 + + -- Color thresholds: Green < 150ms, Yellow 150-350ms, Red > 350ms + local colorHex + if (latency < 150) then + colorHex = "|cff00ff00" -- Green + elseif (latency <= 350) then + colorHex = "|cffffff00" -- Yellow + else + colorHex = "|cffff0000" -- Red + end + + OctoLatencyText:SetText(colorHex .. latency .. " ms|r") +end + +function OctoLatency_SavePosition() + if (not OctoLatencyDB) then + OctoLatencyDB = {} + end + local point, relativeTo, relativePoint, xOfs, yOfs = OctoLatencyFrame:GetPoint() + OctoLatencyDB.point = point + OctoLatencyDB.relativePoint = relativePoint + OctoLatencyDB.xOfs = xOfs + OctoLatencyDB.yOfs = yOfs +end + +-- Load saved position if available on PLAYER_LOGIN or VARIABLES_LOADED +local loadFrame = CreateFrame("Frame") +loadFrame:RegisterEvent("PLAYER_LOGIN") +loadFrame:SetScript("OnEvent", function() + if (OctoLatencyDB and OctoLatencyDB.point) then + OctoLatencyFrame:ClearAllPoints() + OctoLatencyFrame:SetPoint(OctoLatencyDB.point, UIParent, OctoLatencyDB.relativePoint, OctoLatencyDB.xOfs, OctoLatencyDB.yOfs) + end +end) diff --git a/OctoLatency.toc b/OctoLatency.toc new file mode 100644 index 0000000..a64bab0 --- /dev/null +++ b/OctoLatency.toc @@ -0,0 +1,9 @@ +## Interface: 11200 +## Title: OctoLatency +## Notes: Lightweight latency monitor with color-coding for Vanilla WoW (1.12.1) +## Author: Palladinpala +## Version: 1.0 +## SavedVariables: OctoLatencyDB + +OctoLatency.xml +OctoLatency.lua diff --git a/OctoLatency.xml b/OctoLatency.xml new file mode 100644 index 0000000..7ecf9bf --- /dev/null +++ b/OctoLatency.xml @@ -0,0 +1,58 @@ + +