From 336abb39680e702adaf5cf39fb7959dfe8e8e44c Mon Sep 17 00:00:00 2001 From: Mark Rogaski Date: Sat, 28 Mar 2020 17:53:18 -0400 Subject: [PATCH 1/4] Fixed typos in comments. (#174) --- API.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/API.lua b/API.lua index cf15386..2d422dc 100644 --- a/API.lua +++ b/API.lua @@ -51,7 +51,7 @@ end --- Insert a handler for addon messages from the guild confederation. -- @param handler A callback function. --- @param addon The name of the addon that you want to receive meaasges from +-- @param addon The name of the addon that you want to receive messages from -- (the same one used for the name of the TOC file). If the value '*' is -- supplied, messages from all addons will be handled. -- @param priority A signed integer indicating relative priority, lower value @@ -109,7 +109,7 @@ end -- all table entries will be removed. -- -- Note: A '*' value passed as addon is not a wildcard in this context, --- it will only matche instances where the handler was installed with +-- it will only match instances where the handler was installed with -- '*' as the addon. function GreenWallAPI.ClearMessageHandlers(addon) if addon == nil then From 65ef1949424ad3465f1f92acd0dc1d89b150d88f Mon Sep 17 00:00:00 2001 From: Mark Rogaski Date: Sat, 28 Mar 2020 19:10:24 -0400 Subject: [PATCH 2/4] Added GetChannelNumbers API function. (#174) --- .travis.yml | 1 + API.lua | 23 ++++++++++++++++++--- run_tests.bat | 1 + tests/TestAPI.lua | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 tests/TestAPI.lua diff --git a/.travis.yml b/.travis.yml index 60ac6b1..30c4566 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,7 @@ install: - luarocks install luacov-coveralls script: + - lua -lluacov tests/TestAPI.lua -v - lua -lluacov tests/TestUtility.lua -v - lua -lluacov tests/TestSettings.lua -v - lua -lluacov tests/TestSystemEventHandler.lua -v diff --git a/API.lua b/API.lua index 2d422dc..15b47a8 100644 --- a/API.lua +++ b/API.lua @@ -77,8 +77,10 @@ function GreenWallAPI.AddMessageHandler(handler, addon, priority) local id = generate_id(handler) gw.Debug(GW_LOG_INFO, 'add API handler; id=%s, addon=%s, priority=%d', id, addon, priority) - table.insert(gw.api_table, {id, addon, priority, handler}) - table.sort(gw.api_table, function (a, b) return a[2] < b[2] end) + table.insert(gw.api_table, { id, addon, priority, handler }) + table.sort(gw.api_table, function(a, b) + return a[2] < b[2] + end) return id end @@ -91,7 +93,7 @@ function GreenWallAPI.RemoveMessageHandler(id) rv = false if addon ~= '*' then addon = GetAddOnInfo(addon) - assert(addon ~=nil) + assert(addon ~= nil) end for i, e in ipairs(gw.api_table) do if id == e[1] then @@ -129,6 +131,19 @@ function GreenWallAPI.ClearMessageHandlers(addon) end +--- Query the hidden channels used by Greenwall. +-- @return An array of integer values for the channels in use.return +function GreenWallAPI.GetChannelNumbers() + local rv = {} + if gw.config.channel.guild ~= nil then + table.insert(rv, gw.config.channel.guild.number) + end + if gw.config.channel.officer ~= nil then + table.insert(rv, gw.config.channel.officer.number) + end + return rv +end + --- The API handler dispatcher -- @param addon The sending addon -- @param sender The sending player @@ -144,3 +159,5 @@ function gw.APIDispatcher(addon, sender, guild_id, message) end end end + + diff --git a/run_tests.bat b/run_tests.bat index 0af3c6e..21092cc 100644 --- a/run_tests.bat +++ b/run_tests.bat @@ -1,4 +1,5 @@ set LUA_PATH="tests/?;tests/?.lua;;" +lua -lluacov tests/TestAPI.lua -v lua -lluacov tests/TestUtility.lua -v lua -lluacov tests/TestSettings.lua -v lua -lluacov tests/TestSystemEventHandler.lua -v diff --git a/tests/TestAPI.lua b/tests/TestAPI.lua new file mode 100644 index 0000000..46a2dc1 --- /dev/null +++ b/tests/TestAPI.lua @@ -0,0 +1,51 @@ +--[[-------------------------------------------------------------------------- +The MIT License (MIT) +Copyright (c) 2010-2017 Mark Rogaski +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +--]]-------------------------------------------------------------------------- + +-- +-- Includes +-- + +lu = require('luaunit') +require('Loader') + + +-- +-- Test Cases +-- + +TestAPI = {} + +function TestAPI:test_get_channel_numbers() + gw.config = { + channel = { + guild = { number = 5 }, + officer = { number = 6 } + } + } + local c = GreenWallAPI.GetChannelNumbers() + lu.assertEquals(c, { 5, 6 }) +end + + +-- +-- Run the tests +-- + +os.exit(lu.run()) From 3cc489262789ff9e070c73121297342aa76e8839 Mon Sep 17 00:00:00 2001 From: Mark Rogaski Date: Sat, 28 Mar 2020 19:57:35 -0400 Subject: [PATCH 3/4] Updated documentation. (#174) --- API.lua | 2 +- API.md | 12 ++++++++++++ CHANGELOG.md | 4 ++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/API.lua b/API.lua index 15b47a8..3867535 100644 --- a/API.lua +++ b/API.lua @@ -132,7 +132,7 @@ end --- Query the hidden channels used by Greenwall. --- @return An array of integer values for the channels in use.return +-- @return An array of integer values for the channels in use. function GreenWallAPI.GetChannelNumbers() local rv = {} if gw.config.channel.guild ~= nil then diff --git a/API.md b/API.md index e5ea20a..b733cd9 100644 --- a/API.md +++ b/API.md @@ -145,3 +145,15 @@ Arguments: > Note: A `*` value passed as add-on is not a wildcard in this context, it will only matched instances where the handler was installed with `*` as the add-on. +### Get channel information + +Query the hidden channels used by Greenwall. + +```lua +GreenWallAPI.GetChannelNumbers() +``` + +Returns: + +- An array of integer values for the channels in use. + diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d5ac14..b86f489 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ This project uses [Semantic Versioning](http://semver.org/). ### Fixed - Updated debug message call stack parsing for 8.3. +### Added +- `GreenWallAPI.GetChannelNumbers` function to query the custom chat channels in + use by GreenWall + ### Changed - Updated the TOC for WoW 8.3.0. - Refactored CHAT_MSG_SYSTEM handling to use an abstract factory and added From b19370b83929873ac6a2dea4e522d3e28b9e03ed Mon Sep 17 00:00:00 2001 From: Mark Rogaski Date: Sat, 28 Mar 2020 22:13:12 -0400 Subject: [PATCH 4/4] Removed unnecessary local co-guild use of the addon communication channel. (#173) --- CHANGELOG.md | 3 ++ Channel.lua | 5 --- Chat.lua | 94 +++------------------------------------------------ Globals.lua | 2 -- GreenWall.lua | 19 ----------- 5 files changed, 7 insertions(+), 116 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b86f489..b894884 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ This project uses [Semantic Versioning](http://semver.org/). ### Fixed - Updated debug message call stack parsing for 8.3. +### Removed +- Removed unnecessary local co-guild use of the addon communication channel. + ### Added - `GreenWallAPI.GetChannelNumbers` function to query the custom chat channels in use by GreenWall diff --git a/Channel.lua b/Channel.lua index cabcf35..d0aa353 100644 --- a/Channel.lua +++ b/Channel.lua @@ -206,11 +206,6 @@ function GwChannel:join() end end - -- Gratuitous officer announcement, veracity of the claim should be verified by the receiver. - if gw.IsOfficer() then - gw.SendLocal(GW_MTYPE_RESPONSE, 'officer') - end - return true end diff --git a/Chat.lua b/Chat.lua index d97ed79..805b0cd 100644 --- a/Chat.lua +++ b/Chat.lua @@ -119,7 +119,8 @@ function gw.ReplicateMessage(event, message, guild_id, arglist) local i for i = 1, NUM_CHAT_WINDOWS do - if i ~= 2 then -- skip combat log + if i ~= 2 then + -- skip combat log gw.frame_table = { GetChatWindowMessages(i) } local v for _, v in ipairs(gw.frame_table) do @@ -127,9 +128,9 @@ function gw.ReplicateMessage(event, message, guild_id, arglist) local frame = 'ChatFrame' .. i if _G[frame] then gw.Debug(GW_LOG_DEBUG, 'frame=%s, event=%s, sender=%s, message=%q', - frame, event, sender, message) + frame, event, sender, message) gw.ChatFrame_MessageEventHandler(_G[frame], 'CHAT_MSG_' .. event, message, - sender, language, '', target, flags, 0, 0, '', 0, line, guid) + sender, language, '', target, flags, 0, 0, '', 0, line, guid) end break end @@ -139,90 +140,3 @@ function gw.ReplicateMessage(event, message, guild_id, arglist) end ---- Sends an encoded message to the rest of the same container on the add-on channel. --- @param type The message type: GW_MTYPE_CONTROL, GW_MTYPE_REQUEST, or GW_MTYPE_RESPONSE. --- @param message Text of the message. -function gw.SendLocal(type, message) - - gw.Debug(GW_LOG_INFO, 'type=%s, message=%q', type, message) - - local opcode - if type == nil then - gw.Debug(GW_LOG_ERROR, 'cont_msg: missing arguments.') - return - elseif type == GW_MTYPE_CONTROL then - opcode = 'I' - elseif type == GW_MTYPE_REQUEST then - opcode = 'C' - elseif type == GW_MTYPE_RESPONSE then - opcode = 'R' - else - gw.Debug(GW_LOG_ERROR, 'unknown message type: %s', type) - return - end - - local payload = strsub(strjoin('#', opcode, message), 1, 255) - gw.Debug(GW_LOG_DEBUG, 'message=%q', payload) - C_ChatInfo.SendAddonMessage('GreenWall', payload, 'GUILD') -end - ---- Parses and handles an encoded message from the add-on channel. --- @param sender The sender of the message. --- @param message The encoded message. --- @return True on successful handling, false on failure. -function gw.ReceiveLocal(sender, message) - - gw.Debug(GW_LOG_INFO, 'sender=%s, message=%q', sender, message) - - if not gw.iCmp(gw.GlobalName(sender), gw.player) then - - local opcode, payload = strsplit('#', message) - payload = payload or '' - gw.Debug(GW_LOG_DEBUG, 'opcode=%s, payload=%s', opcode, payload) - - if opcode == 'I' then - - if message == 'reload' then - if gw.IsOfficer(sender) then - if gw.config.timer.reload:hold() then - gw.Write('Received configuration reload request from %s; hold-down in effect, skipping.', sender) - else - gw.Write('Received configuration reload request from %s.', sender) - gw.config:reload() - gw.config.timer.reload:start() - end - end - end - - elseif opcode == 'C' then - - if message == 'officer' then - -- A query for officers - if gw.IsOfficer() then - gw.SendLocal(GW_MTYPE_RESPONSE, 'officer') - end - end - - elseif opcode == 'R' then - - if message == 'officer' then - -- A response to the officer query - if gw.IsOfficer(sender) then - if gw.IsOfficer() then - gw.Debug(GW_LOG_NOTICE, 'giving %s moderator status', sender) - ChannelModerator(gw.config.channel.guild.name, sender) - else - gw.Debug(GW_LOG_NOTICE, 'giving %s owner status', sender) - SetChannelOwner(gw.config.channel.guild.name, sender) - ChannelUnmoderator(gw.config.channel.guild.name, gw.player) - end - else - gw.Debug(GW_LOG_WARNING, 'officer spoofing attempt from %s', sender) - end - end - end - end - - return true -end - diff --git a/Globals.lua b/Globals.lua index fa6c61a..915f9c1 100644 --- a/Globals.lua +++ b/Globals.lua @@ -92,8 +92,6 @@ gw.usage = [[ -- Toggle output logging to the GreenWall.lua file. logsize -- Specify the maximum number of log entries to keep. - admin reload - -- (officer only) Force a reload of the configuration by all online guild members. ]] diff --git a/GreenWall.lua b/GreenWall.lua index cba4df3..9f512d7 100644 --- a/GreenWall.lua +++ b/GreenWall.lua @@ -109,17 +109,6 @@ local function GwSlashCmd(message, editbox) GwSettingCmd(command, argstr) - elseif command == 'admin' then - - if gw.IsOfficer() then - if argstr == 'reload' then - gw.SendLocal(GW_MTYPE_CONTROL, 'reload') - gw.Write('Broadcast configuration reload request.') - end - else - gw.Error('The admin command may only be issued by an officer.') - end - elseif command == 'reload' or command == 'refresh' then gw.Write('Reloading configuration.') @@ -170,7 +159,6 @@ function GreenWall_OnLoad(self) -- self:RegisterEvent('ADDON_LOADED') self:RegisterEvent('CHANNEL_UI_UPDATE') - self:RegisterEvent('CHAT_MSG_ADDON') self:RegisterEvent('CHAT_MSG_CHANNEL') self:RegisterEvent('CHAT_MSG_CHANNEL_JOIN') self:RegisterEvent('CHAT_MSG_CHANNEL_LEAVE') @@ -315,13 +303,6 @@ function GreenWall_OnEvent(self, event, ...) local message, sender, language, _, _, flags, _, chanNum = select(1, ...) gw.Debug(GW_LOG_DEBUG, 'event=%s, sender=%s, message=%q', event, sender, message) - elseif event == 'CHAT_MSG_ADDON' then - - local prefix, payload, dist, sender = select(1, ...) - if prefix == 'GreenWall' and dist == 'GUILD' then - gw.ReceiveLocal(gw.GlobalName(sender), payload) - end - elseif event == 'CHAT_MSG_GUILD_ACHIEVEMENT' then local message, sender, _, _, _, flags, _, chanNum = select(1, ...)