Diff

plugins/muc/mod_muc.lua @ 8818:c96c00dc424b

MUC: Add support for an optional hard limit on number of rooms (fixes #766)
author Kim Alvefur <zash@zash.se>
date Tue, 22 May 2018 21:22:51 +0200
parent 8707:fd39c44c0113
child 8833:9c90cd2fc4c3
line wrap: on
line diff
--- a/plugins/muc/mod_muc.lua	Sun May 20 15:20:34 2018 +0200
+++ b/plugins/muc/mod_muc.lua	Tue May 22 21:22:51 2018 +0200
@@ -124,8 +124,15 @@
 	end
 end
 
+local max_rooms = module:get_option_number("muc_max_rooms");
+local max_live_rooms = module:get_option_number("muc_room_cache_size", 100);
+
 local eviction_hit_rate = module:measure("room_eviction", "rate");
-local rooms = cache.new(module:get_option_number("muc_room_cache_size", 100), function (jid, room)
+local rooms = cache.new(max_rooms or max_live_rooms, function (jid, room)
+	if max_rooms then
+		module:log("info", "Room limit of %d reached, no new rooms allowed");
+		return false;
+	end
 	module:log("debug", "Evicting room %s", jid);
 	eviction_hit_rate();
 	room_items_cache[room.jid] = room:get_public() and room:get_name() or nil;