Skip to content

Commit

Permalink
luacheck'ed and ...
Browse files Browse the repository at this point in the history
    - DynBoxer.enabled boolean to turn off dynboxer even if loaded/running (optional/no use yet)
    - Luacheck'ed and some reformatting to 120 columns
    - Ensure `/dbox j` always sends the sync message
  • Loading branch information
mooreatv committed Jun 11, 2019
1 parent 7c58345 commit 518808a
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 32 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.txt
Expand Up @@ -2,6 +2,9 @@ ChangeLog for DynamicBoxer by MooreaTv (moorea@ymail.com)

0.1.6 June 11th 2019
- Limit maximum number of times we'll try sending/syncing (to 20 times/20s after channel join or /dbox m command)
- DynBoxer.enabled boolean to turn off dynboxer even if loaded/running (optional/no use yet)
- Luacheck'ed and some reformatting to 120 columns
- Ensure `/dbox j` always sends the sync message
0.1.5 June 10th 2019
- Fix for lua error when not running in multiboxing setup (Issue #3)
- Fix duplicate join event/messages
Expand Down
23 changes: 23 additions & 0 deletions DynamicBoxer/.luacheckrc
@@ -0,0 +1,23 @@
globals = {
"isboxer",
"DynBoxer",
"dynamicBoxerSaved",
"BNGetInfo",
"CreateFrame",
"C_ChatInfo",
"C_Timer",
"GetChannelName",
"JoinTemporaryChannel",
"EMAApi",
"GetBindingAction",
"GetUnitName",
"SetOverrideBindingClick",
"SlashCmdList",
"SLASH_DynamicBoxer_Slash_Command1",
"SLASH_DynamicBoxer_Slash_Command2",
"UIParent",
}
max_line_length = 132
ignore = {
"212/_.*"
}
4 changes: 2 additions & 2 deletions DynamicBoxer/DBoxInit.lua
@@ -1,4 +1,4 @@
--[[
--[[
Initialization needed before loading ISBoxer patches
]] --
--
Expand All @@ -16,4 +16,4 @@ CreateFrame("frame", shortName, UIParent)

local DB = DynBoxer

DynamicBoxer.MoLibInstallInto(DB, shortName)
_G[addon].MoLibInstallInto(DB, shortName)
62 changes: 34 additions & 28 deletions DynamicBoxer/DynamicBoxer.lua
@@ -1,4 +1,4 @@
--[[
--[[
Proof of concept of Dynamic Team by MooreaTV moorea@ymail.com
How it currently works:
Expand All @@ -7,8 +7,8 @@
Send our slot id and name and whether this is a reload which requires getting everyone else's data again
Anytime someone joins the channel or we get a message we first flag, resend our info(*)
*: the send is smart as it's not actually sending right away but just renabling a periodic send within the next interval
that way we don't send 4 times the same thing in short sequence when everyone first logs
*: the send is smart as it's not actually sending right away but just renabling a periodic send within the
next interval, that way we don't send 4 times the same thing in short sequence when everyone first logs
We could also:
Broadcast periodically slot # and name for a while (or until all acked)
Expand Down Expand Up @@ -45,10 +45,11 @@ DB.maxRetries = 20 -- after 20s we stop/give up

DB.chatPrefix = "dbox0" -- protocol version in prefix
DB.channelId = nil
DB.enabled = true -- in case we need a variable to disable the addon

-- Returns if we should be operating (basically if isboxer has a static team defined)
function DB:IsActive()
return isboxer.Character_LoadBinds
return self.enabled and isboxer.Character_LoadBinds
end

-- Replace team members in original macro text by the dynamic one.
Expand All @@ -59,7 +60,7 @@ function DB:Replace(macro)
local o = v.orig
local n = v.new
-- TODO: probably should do this local/remote determination once when setting the value instead of each time
local s, r = DB:SplitFullname(n)
local s, r = DB.SplitFullname(n)
if r == DB.myRealm then
n = s -- use the short name without realm when on same realm, using full name breaks (!)
end
Expand Down Expand Up @@ -118,27 +119,28 @@ for k, v in pairs(DB.ISBH) do
isboxer[k] = v
end

function DB:SplitFullname(fullname)
function DB.SplitFullname(fullname)
return fullname:match("(.+)-(.+)")
end

-- Reverse engineer what isboxer will hopefully be providing more directly soon
-- (isboxer.CharacterSet.Members isn't always set when making teams without realm)
function DB:ReconstructTeam()
function DB.ReconstructTeam()
if DB.ISBTeam then
DB:Debug("Already know team to be % and my index % (isb members %)", DB.ISBTeam, DB.ISBIndex, isboxer.CharacterSet.Members)
DB:Debug("Already know team to be % and my index % (isb members %)", DB.ISBTeam, DB.ISBIndex,
isboxer.CharacterSet.Members)
return
end
if not DB:IsActive() then
DB:Print("DynamicBoxer skipping team reconstruction as there is no static isboxer team (not running under innerspace).")
DB:Print("DynamicBoxer skipping team reconstruction as there is no isboxer team (not running under innerspace).")
return
end
DB.fullName = DB:GetMyFQN()
DB.shortName, DB.myRealm = DB:SplitFullname(DB.fullName)
DB.shortName, DB.myRealm = DB.SplitFullname(DB.fullName)
local prev = isboxer.SetMacro
DB.ISBTeam = {}
-- parse the text which looks like (note the ]xxx; delimiters for most but \n at the end)
-- "/assist [nomod:alt,mod:lshift,nomod:ctrl]FIRST;[nomod:alt,mod:rshift,nomod:ctrl]SECOND;...[nomod:alt,mod:lshift,mod:lctrl]LAST\n""
-- "/assist [nomod:alt,mod:lshift,nomod:ctrl]FIRST;[nomod:alt,mod:rshift,nomod:ctrl]SECOND;...[nomod:alt...,mod:lctrl]LAST\n""
isboxer.SetMacro = function(macro, _key, text)
if macro ~= "FTLAssist" then
return
Expand All @@ -152,7 +154,8 @@ function DB:ReconstructTeam()
end
isboxer.Character_LoadBinds()
isboxer.SetMacro = prev
DB:Debug("Found team to be % and my index % (while isb members is %)", DB.ISBTeam, DB.ISBIndex, isboxer.CharacterSet.Members)
DB:Debug("Found team to be % and my index % (while isb members is %)", DB.ISBTeam, DB.ISBIndex,
isboxer.CharacterSet.Members)
DB.Team[DB.ISBIndex] = {orig = DB.ISBTeam[DB.ISBIndex], new = DB.fullName}
DB:Debug("Team map initial value = %", DB.Team)
end
Expand All @@ -176,8 +179,8 @@ function DB.Sync()
DB:Debug("We don't know our slot/actual yet")
return
end
local payload = tostring(DB.ISBIndex) .. " " .. DB.fullName .. " " .. DB.ISBTeam[DB.ISBIndex] .. " " .. DB.firstMsg .. " msg " ..
tostring(DB.maxIter)
local payload = tostring(DB.ISBIndex) .. " " .. DB.fullName .. " " .. DB.ISBTeam[DB.ISBIndex] .. " " .. DB.firstMsg ..
" msg " .. tostring(DB.maxIter)
local ret = C_ChatInfo.SendAddonMessage(DB.chatPrefix, payload, "CHANNEL", DB.channelId)
DB:Debug("Message success % on chanId %", ret, DB.channelId)
if ret then
Expand Down Expand Up @@ -230,15 +233,15 @@ function DB:ProcessMessage(from, data)
EMAApi.AddMember(realname)
end
isboxer.NextButton = 1 -- reset the buttons
DB.ISBO.LoadBinds() -- call normal LoadBinds (with output/warning hooked). TODO: maybe wait/batch/don't do it 5 times in small amount of time
-- call normal LoadBinds (with output/warning hooked). TODO: maybe wait/batch/don't do it 5 times in small amount of time
self.ISBO.LoadBinds()
DB:Print(DB.format("New mapping for slot %, dynamically set ISBoxer character to %", idx, realname), 0, 1, 1)
end

DB.EventD = {

CHAT_MSG_ADDON = function(self, event, prefix, data, channel, sender, zoneChannelID, localID, name, instanceID)
self:Debug(7, "OnChatEvent called for % e=% channel=% p=% data=% from % z=%, lid=%, name=%, instance=%", self:GetName(), event,
channel, prefix, data, sender, zoneChannelID, localID, name, instanceID)
self:Debug(7, "OnChatEvent called for % e=% channel=% p=% data=% from % z=%, lid=%, name=%, instance=%",
self:GetName(), event, channel, prefix, data, sender, zoneChannelID, localID, name, instanceID)
if channel ~= "CHANNEL" or instanceID ~= DB.Channel then
self:Debug(9, "wrong channel % or instance % vs %, skipping!", channel, instanceID, DB.Channel)
return -- not our message(s)
Expand All @@ -255,8 +258,8 @@ DB.EventD = {
self:Debug("OnChannelCountUpdate didx=%, count=%", displayIndex, count)
end,

CHAT_MSG_CHANNEL_JOIN = function(self, _event, _text, playerName, _languageName, _channelName, _playerName2, _specialFlags,
_zoneChannelID, _channelIndex, channelBaseName)
CHAT_MSG_CHANNEL_JOIN = function(self, _event, _text, playerName, _languageName, _channelName, _playerName2,
_specialFlags, _zoneChannelID, _channelIndex, channelBaseName)
if channelBaseName == self["Channel"] then
self:Debug("Join on our channel by %", playerName)
self["maxIter"] = 1
Expand All @@ -279,7 +282,6 @@ DB.EventD = {
dynamicBoxerSaved = {}
end
end

}

function DB:OnEvent(event, first, ...)
Expand All @@ -303,7 +305,7 @@ end

DB.joinDone = false -- because we reschedule the join from multiple place, lets do that only once

-- note: 2 sources of retry, the dynamic init and
-- note: 2 sources of retry, the dynamic init and
function DB.Join()
-- First check if we have joined the last std channel and reschedule if not
-- (so our channel doesn't end up as first one, and /1, /2 etc are normal)
Expand All @@ -319,21 +321,25 @@ function DB.Join()
end
DB.joinDone = true
DB.totalRetries = 0 -- try at most maxRetries (20) times after this point
if DB.maxIter <= 0 then
DB.maxIter = 1
end
DB.ReconstructTeam()
local ret = C_ChatInfo.RegisterAddonMessagePrefix(DB.chatPrefix)
DB:Debug("Prefix register success % in dynamic setup", ret)
local t, n = JoinTemporaryChannel(DB.Channel, DB.Secret)
DB.channelId = GetChannelName(DB.Channel)
DB:Debug("Joined channel % / % type % name % id %", DB.Channel, DB.Secret, t, n, DB.channelId)
DB:Print(DB.format("Joined DynBoxer secure channel. This is slot % and dynamically setting ISBoxer character to %", DB.ISBIndex,
DB.fullName), 0, 1, 1)
DB:Print(DB.format("Joined DynBoxer secure channel. This is slot % and dynamically setting ISBoxer character to %",
DB.ISBIndex, DB.fullName), 0, 1, 1)
return DB.channelId
end

function DB.Help(msg)
DB:Print("DynamicBoxer: " .. msg .. "\n" .. "/dbox c channel -- to change channel.\n" ..
"/dbox s secret -- to change the secret.\n" .. "/dbox m -- send mapping again\n" .. "/dbox join -- (re)join channel.\n" ..
"/dbox debug on/off/level -- for debugging on at level or off.\n" .. "/dbox dump global -- to dump a global.")
"/dbox s secret -- to change the secret.\n" .. "/dbox m -- send mapping again\n" ..
"/dbox join -- (re)join channel.\n" .. "/dbox debug on/off/level -- for debugging on at level or off.\n" ..
"/dbox dump global -- to dump a global.")
end

function DB:SetSaved(name, value)
Expand Down Expand Up @@ -364,7 +370,7 @@ function DB.Slash(arg)
DB.totalRetries = 0
DB.Sync()
elseif cmd == "c" then
-- change channel
-- change channel
DB.SetSaved("Channel", rest)
elseif cmd == "s" then
-- change secret
Expand All @@ -385,7 +391,7 @@ function DB.Slash(arg)
-- dump
DB:Print(DB.format("DynBoxer dump of % = " .. DB.Dump(_G[rest]), rest), .7, .7, .9)
else
DB.Help("unknown command \"" .. arg .. "\", usage:")
DB.Help('unknown command "' .. arg .. '", usage:')
end
end

Expand Down
2 changes: 1 addition & 1 deletion DynamicBoxer/ISBoxerPatches.lua
Expand Up @@ -2,7 +2,7 @@
-- for behavior we can't change just with the hooks.
-- This assumes ISBoxer is already loaded per our toc deps
--
--Created by DBoxInit
-- Created by DBoxInit
local DB = DynBoxer

-- We need to fix isboxer.SetMacro so it can update buttons instead
Expand Down
2 changes: 1 addition & 1 deletion DynamicBoxer/luaformat.cfg
@@ -1,4 +1,4 @@
indent_width: 2
continuation_indent_width: 2
keep_simple_block_one_line: false
column_limit: 132
column_limit: 120
1 change: 1 addition & 0 deletions pkgmeta.yaml
Expand Up @@ -7,6 +7,7 @@ ignore:
- MoLib/installmolib.bat
- MoLib/MoLib.toc
- MoLib/luaformat.cfg
- MoLib/README.md

manual-changelog: ChangeLog.txt

Expand Down

0 comments on commit 518808a

Please sign in to comment.