Skip to content

Commit

Permalink
Merge branch 'release/1.11'
Browse files Browse the repository at this point in the history
Conflicts:
	GreenWall.lua
  • Loading branch information
mrogaski committed Mar 29, 2020
2 parents b4f1161 + 3cea4ca commit a5fa8bd
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 121 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 22 additions & 5 deletions API.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -109,7 +111,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
Expand All @@ -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.
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
Expand All @@ -144,3 +159,5 @@ function gw.APIDispatcher(addon, sender, guild_id, message)
end
end
end


12 changes: 12 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ This project uses [Semantic Versioning](http://semver.org/).
The `SendChatMessage` function was made partially protected in 8.2.5, and
events that are not triggered by hardware events cannot use the function.

### 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

### Changed
- Updated the TOC for WoW 8.3.0.
- Refactored CHAT_MSG_SYSTEM handling to use an abstract factory and added
Expand Down
5 changes: 0 additions & 5 deletions Channel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
94 changes: 4 additions & 90 deletions Chat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,18 @@ 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
if v == event then
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
Expand All @@ -129,90 +130,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

2 changes: 0 additions & 2 deletions Globals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ gw.usage = [[
-- Toggle output logging to the GreenWall.lua file.
logsize <length>
-- Specify the maximum number of log entries to keep.
admin reload
-- (officer only) Force a reload of the configuration by all online guild members.
]]

19 changes: 0 additions & 19 deletions GreenWall.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -301,13 +289,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_CHANNEL_JOIN' then

local _, player, _, _, _, _, _, number = select(1, ...)
Expand Down
1 change: 1 addition & 0 deletions run_tests.bat
Original file line number Diff line number Diff line change
@@ -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
51 changes: 51 additions & 0 deletions tests/TestAPI.lua
Original file line number Diff line number Diff line change
@@ -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())

0 comments on commit a5fa8bd

Please sign in to comment.