Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
mrogaski committed Dec 20, 2015
2 parents c2b12d6 + d05b3a1 commit e123f5c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

This project uses [Semantic Versioning](http://semver.org/).


## [0.1.0] -- 2015-12-18
### Fixed
- Now blocking our own requests and responses.
- Corrected `MinMax` return values.
- Only calculate stats if responses have been received.

### Added
- Checking for GreenWall version with API support.
- Readme and luadoc.

## 0.1.0-dev -- 2015-12-18
Expand Down
31 changes: 26 additions & 5 deletions GWSonar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ end

--- Minimum/maximum values from a table.
-- @param t A table of numeric values.
-- @return (min, max) - Minimum value, maximum value.
--
-- Taken from http://lua-users.org/wiki/SimpleStats .
--
Expand All @@ -68,7 +69,7 @@ function MinMax(t)
end
end

return max, min
return min, max
end


Expand All @@ -92,17 +93,27 @@ function Mean(t)
end


--[[-----------------------------------------------------------------------
API Functions
--]]-----------------------------------------------------------------------
--
--- Send a ping request.
local function Ping()

GWSonar.serial = GWSonar.serial + 1
GWSonar.sample = {}
local guid = UnitGUID('player')
local token = string.format('REQUEST/%s/%04X', guid, GWSonar.serial)

GWSonar.timestamp = GetTime()
GreenWallAPI.SendMessage('GWSonar', token)
return token

end


--- Generate and process ping responses.
-- @param addon The sending addon
-- @param sender The sending player
Expand All @@ -121,6 +132,7 @@ local function PingHandler(addon, sender, echo, message)

elseif op == 'RESPONSE' then

-- Record response times
local delta = GetTime() - GWSonar.timestamp
table.insert(GWSonar.sample, delta)
Write('ping response received from %s, %.3f second(s).', sender, delta)
Expand Down Expand Up @@ -152,9 +164,13 @@ function GWSonar_OnLoad(self)
elseif msg == 'stats' then

local n = #GWSonar.sample
local min, max = MinMax(GWSonar.sample)
local avg = Mean(GWSonar.sample)
Write('%d response(s); min/avg/max = %.3f/%.3f/%.3f', n, min, avg, max)
if n > 0 then
local min, max = MinMax(GWSonar.sample)
local avg = Mean(GWSonar.sample)
Write('%d response(s); min/avg/max = %.3f/%.3f/%.3f', n, min, avg, max)
else
Write('No responses')
end

end

Expand All @@ -174,7 +190,12 @@ function GWSonar_OnEvent(self, event, ...)

elseif event == 'PLAYER_ENTERING_WORLD' then

GreenWallAPI.AddMessageHandler(PingHandler, 'GWSonar', 0)
-- Check to ensure GreenWall is loaded and the installed version
-- supports the API.
if IsAddOnLoaded('GreenWall') and GreenWallAPI ~= nil then
GreenWallAPI.AddMessageHandler(PingHandler, 'GWSonar', 0)
Write('installed ping handler.')
end

end

Expand Down
4 changes: 2 additions & 2 deletions GWSonar.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
## Title: GWSonar
## Notes: A demonstration of the GreenWall add-on communication API.
## Author: Mark Rogaski <stigg@aie-guild.org>
## Version: 0.1.0-alpha
## Version: 0.1.0
## URL: https://github.com/AIE-Guild/GWSonar
## DefaultState: enabled
## X-Category: Guild
## X-Date: 2015-12-18
## X-Date: 2015-12-20

GWSonar.lua
GWSonar.xml

0 comments on commit e123f5c

Please sign in to comment.