From edd7f28ffeb00f26708185af9da72125f591cc80 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 30 Jan 2015 14:21:51 +0000 Subject: util.statistics: Return 0 as percentile if data out of range --- util/statistics.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/statistics.lua b/util/statistics.lua index 08c765ae..a05a1f91 100644 --- a/util/statistics.lua +++ b/util/statistics.lua @@ -8,7 +8,7 @@ local function percentile(arr, length, pc) local n = pc/100 * (length + 1); local k, d = m_floor(n), n%1; if k == 0 then - return arr[1]; + return arr[1] or 0; elseif k >= length then return arr[length]; end -- cgit v1.2.3 From a0f8ff2628e0ae3f27f6b872137a172f9f5bd717 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 30 Jan 2015 15:38:54 +0100 Subject: sessionmanager: Add pre-resource-bind event that would let plugins have a say in resource binding --- core/sessionmanager.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index 09920b7d..476de931 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -117,6 +117,16 @@ function bind_resource(session, resource) if session.resource then return nil, "cancel", "already-bound", "Cannot bind multiple resources on a single connection"; end -- We don't support binding multiple resources + local event_payload = { session = session, resource = resource }; + if hosts[session.host].events.fire_event("pre-resource-bind", event_payload) == false then + local err = event_payload.error; + if err then return nil, err.type, err.condition, err.text; end + return nil, "cancel", "not-allowed"; + else + -- In case a plugin wants to poke at it + resource = event_payload.resource; + end + resource = resourceprep(resource); resource = resource ~= "" and resource or uuid_generate(); --FIXME: Randomly-generated resources must be unique per-user, and never conflict with existing -- cgit v1.2.3