From c273f4c8905b6d605b788e92ae145b5ba0efc2c7 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 12 Jan 2009 02:59:45 +0000 Subject: Set session.ip to the IP address of connecting clients --- core/sessionmanager.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'core') diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index 963de7ce..f04ca29c 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -58,6 +58,7 @@ function new_session(conn) log("info", "open sessions now: ".. open_sessions); local w = conn.write; session.send = function (t) w(tostring(t)); end + session.ip = conn.ip(); return session; end -- cgit v1.2.3 From ea643d3c907ab9787b2e16961cc03c6ddf58e19e Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 12 Jan 2009 03:27:18 +0000 Subject: modulemanager: Change pairs() to ipairs() to allow ordered module loading --- core/modulemanager.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'core') diff --git a/core/modulemanager.lua b/core/modulemanager.lua index 7c1bc0d8..3481aac6 100644 --- a/core/modulemanager.lua +++ b/core/modulemanager.lua @@ -68,11 +68,11 @@ function load_modules_for_host(host) local disabled_set = {}; if modules_enabled then if modules_disabled then - for _, module in pairs(modules_disabled) do + for _, module in ipairs(modules_disabled) do disabled_set[module] = true; end end - for _, module in pairs(modules_enabled) do + for _, module in ipairs(modules_enabled) do if not disabled_set[module] then load(host, module); end -- cgit v1.2.3 From 9ffcaaa1f99a185bec4160399d0b8f52a70a7527 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 12 Jan 2009 04:05:10 +0000 Subject: Add core.actions for managing server 'actions'; and make modulemanager register actions 'load' and 'unload' --- core/actions.lua | 19 +++++++++++++++++++ core/modulemanager.lua | 15 ++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 core/actions.lua (limited to 'core') diff --git a/core/actions.lua b/core/actions.lua new file mode 100644 index 00000000..d0be5aeb --- /dev/null +++ b/core/actions.lua @@ -0,0 +1,19 @@ + +local actions = {}; + +function register(path, t) + local curr = actions; + for comp in path:gmatch("([^/]+)/") do + if curr[comp] == nil then + curr[comp] = {}; + end + curr = curr[comp]; + if type(curr) ~= "table" then + return nil, "path-taken"; + end + end + curr[path:match("/([^/]+)$")] = t; + return true; +end + +return { actions = actions, register= register }; \ No newline at end of file diff --git a/core/modulemanager.lua b/core/modulemanager.lua index 3481aac6..6ef39e82 100644 --- a/core/modulemanager.lua +++ b/core/modulemanager.lua @@ -27,7 +27,7 @@ local addDiscoInfoHandler = require "core.discomanager".addDiscoInfoHandler; local eventmanager = require "core.eventmanager"; local config = require "core.configmanager"; local multitable_new = require "util.multitable".new; - +local register_actions = require "core.actions".register; local loadfile, pcall = loadfile, pcall; local setmetatable, setfenv, getfenv = setmetatable, setfenv, getfenv; @@ -254,4 +254,17 @@ end -------------------------------------------------------------------- +local actions = {}; + +function actions.load(params) + --return true, "Module loaded ("..params.module.." on "..params.host..")"; + return load(params.host, params.module); +end + +function actions.unload(params) + return unload(params.host, params.module); +end + +register_actions("/modules", actions); + return _M; -- cgit v1.2.3