Software /
code /
prosody
Comparison
main.lua @ 4:09c3845ed442
Presence unavailable on disconnect
author | matthew |
---|---|
date | Sun, 24 Aug 2008 14:52:02 +0000 |
parent | 2:9bb397205f26 |
child | 6:7ad47ce20394 |
comparison
equal
deleted
inserted
replaced
3:f674eb704134 | 4:09c3845ed442 |
---|---|
130 session.stanza_dispatch = init_stanza_dispatcher(session); | 130 session.stanza_dispatch = init_stanza_dispatcher(session); |
131 session.xml_handlers = init_xmlhandlers(session); | 131 session.xml_handlers = init_xmlhandlers(session); |
132 session.parser = lxp.new(session.xml_handlers, ":"); | 132 session.parser = lxp.new(session.xml_handlers, ":"); |
133 | 133 |
134 function session.disconnect(err) | 134 function session.disconnect(err) |
135 if session.last_presence.attr.type ~= "unavailable" then | |
136 local pres = st.presence{ type = "unavailable" }; | |
137 if err == "closed" then err = "connection closed"; end | |
138 pres:tag("status"):text("Disconnected: "..err); | |
139 session.stanza_dispatch(pres); | |
140 end | |
135 hosts[session.host].sessions[session.username] = nil; | 141 hosts[session.host].sessions[session.username] = nil; |
136 session = nil; | 142 session = nil; |
137 print("Disconnected: "..err); | 143 print("Disconnected: "..err); |
138 end | 144 end |
139 end | 145 end |
152 | 158 |
153 setmetatable(_G, { __index = function (t, k) print("WARNING: ATTEMPT TO READ A NIL GLOBAL!!!", k); error("Attempt to read a non-existent global. Naughty boy.", 2); end, __newindex = function (t, k, v) print("ATTEMPT TO SET A GLOBAL!!!!", tostring(k).." = "..tostring(v)); error("Attempt to set a global. Naughty boy.", 2); end }) --]][][[]][]; | 159 setmetatable(_G, { __index = function (t, k) print("WARNING: ATTEMPT TO READ A NIL GLOBAL!!!", k); error("Attempt to read a non-existent global. Naughty boy.", 2); end, __newindex = function (t, k, v) print("ATTEMPT TO SET A GLOBAL!!!!", tostring(k).." = "..tostring(v)); error("Attempt to set a global. Naughty boy.", 2); end }) --]][][[]][]; |
154 | 160 |
155 | 161 |
156 local protected_handler = function (...) local success, ret = pcall(handler, ...); if not success then print("ERROR on "..tostring((select(1, ...)))..": "..ret); end end; | 162 local protected_handler = function (...) local success, ret = pcall(handler, ...); if not success then print("ERROR on "..tostring((select(1, ...)))..": "..ret); end end; |
163 local protected_disconnect = function (...) local success, ret = pcall(disconnect, ...); if not success then print("ERROR on "..tostring((select(1, ...))).." disconnect: "..ret); end end; | |
157 | 164 |
158 print( server.add( { listener = protected_handler, disconnect = disconnect }, 5222, "*", 1, nil ) ) -- server.add will send a status message | 165 print( server.add( { listener = protected_handler, disconnect = protected_disconnect }, 5222, "*", 1, nil ) ) -- server.add will send a status message |
159 print( server.add( { listener = protected_handler, disconnect = disconnect }, 5223, "*", 1, ssl_ctx ) ) -- server.add will send a status message | 166 print( server.add( { listener = protected_handler, disconnect = protected_disconnect }, 5223, "*", 1, ssl_ctx ) ) -- server.add will send a status message |
160 | 167 |
161 server.loop(); | 168 server.loop(); |