diff mod_c2s_limit_sessions/mod_c2s_limit_sessions.lua @ 1365:ecc948f8d47d

mod_c2s_limit_sessions: Limit number of resources a user may connect
author Kim Alvefur <zash@zash.se>
date Wed, 19 Mar 2014 23:11:33 +0100
parents
children f581210093a7
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mod_c2s_limit_sessions/mod_c2s_limit_sessions.lua	Wed Mar 19 23:11:33 2014 +0100
@@ -0,0 +1,13 @@
+-- mod_c2s_limit_sessions
+
+local next, count = next, require "util.iterators".count;
+
+local max_resources = module:get_option_number("max_resources", 10);
+
+local sessions = hosts[module.host].sessions;
+module:hook("resource-bind", function(event)
+	if count(next, sessions[event.session.username].sessions) > max_resources then
+		session:close{ condition = "policy-violation", text = "Too many resources" };
+		return false
+	end
+end, -1);