Software / code / prosody
Comparison
plugins/muc/mod_muc.lua @ 5062:88e198d65905
MUC: Send unavailable presence when the component or server is shutting down.
| author | Waqas Hussain <waqas20@gmail.com> |
|---|---|
| date | Wed, 01 Aug 2012 01:36:22 +0500 |
| parent | 5058:433cc9a4c7e9 |
| child | 5064:7a1eb302c562 |
comparison
equal
deleted
inserted
replaced
| 5061:186f34d88073 | 5062:88e198d65905 |
|---|---|
| 176 else error("component.send only supports result and error stanzas at the moment"); end | 176 else error("component.send only supports result and error stanzas at the moment"); end |
| 177 end | 177 end |
| 178 | 178 |
| 179 hosts[module:get_host()].muc = { rooms = rooms }; | 179 hosts[module:get_host()].muc = { rooms = rooms }; |
| 180 | 180 |
| 181 local saved = false; | |
| 181 module.save = function() | 182 module.save = function() |
| 183 saved = true; | |
| 182 return {rooms = rooms}; | 184 return {rooms = rooms}; |
| 183 end | 185 end |
| 184 module.restore = function(data) | 186 module.restore = function(data) |
| 185 for jid, oldroom in pairs(data.rooms or {}) do | 187 for jid, oldroom in pairs(data.rooms or {}) do |
| 186 local room = muc_new_room(jid); | 188 local room = muc_new_room(jid); |
| 192 room.save = room_save; | 194 room.save = room_save; |
| 193 rooms[jid] = room; | 195 rooms[jid] = room; |
| 194 end | 196 end |
| 195 hosts[module:get_host()].muc = { rooms = rooms }; | 197 hosts[module:get_host()].muc = { rooms = rooms }; |
| 196 end | 198 end |
| 199 | |
| 200 function shutdown_room(room, stanza) | |
| 201 for nick, occupant in pairs(room._occupants) do | |
| 202 stanza.attr.from = nick; | |
| 203 for jid in pairs(occupant.sessions) do | |
| 204 stanza.attr.to = jid; | |
| 205 room:_route_stanza(stanza); | |
| 206 room._jid_nick[jid] = nil; | |
| 207 end | |
| 208 room._occupants[nick] = nil; | |
| 209 end | |
| 210 end | |
| 211 function shutdown_component() | |
| 212 if not saved then | |
| 213 local stanza = st.presence({type = "unavailable"}) | |
| 214 :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"}) | |
| 215 :tag("item", { affiliation='none', role='none' }):up(); | |
| 216 for roomjid, room in pairs(rooms) do | |
| 217 shutdown_room(room, stanza); | |
| 218 end | |
| 219 shutdown_room(host_room, stanza); | |
| 220 end | |
| 221 end | |
| 222 module.unload = shutdown_component; | |
| 223 module:hook_global("server-stopping", shutdown_component); |