Software /
code /
prosody
Comparison
plugins/mod_console.lua @ 2145:daeb6ebf304c
mod_console: Update for new net.server API
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 22 Nov 2009 21:09:25 +0000 |
parent | 2087:5efd79871205 |
child | 2253:a3537266a916 |
comparison
equal
deleted
inserted
replaced
2144:8e59d37a0e68 | 2145:daeb6ebf304c |
---|---|
31 end | 31 end |
32 | 32 |
33 console = {}; | 33 console = {}; |
34 | 34 |
35 function console:new_session(conn) | 35 function console:new_session(conn) |
36 local w = function(s) conn.write(s:gsub("\n", "\r\n")); end; | 36 local w = function(s) conn:write(s:gsub("\n", "\r\n")); end; |
37 local session = { conn = conn; | 37 local session = { conn = conn; |
38 send = function (t) w(tostring(t)); end; | 38 send = function (t) w(tostring(t)); end; |
39 print = function (t) w("| "..tostring(t).."\n"); end; | 39 print = function (t) w("| "..tostring(t).."\n"); end; |
40 disconnect = function () conn.close(); end; | 40 disconnect = function () conn.close(); end; |
41 }; | 41 }; |
51 return session; | 51 return session; |
52 end | 52 end |
53 | 53 |
54 local sessions = {}; | 54 local sessions = {}; |
55 | 55 |
56 function console_listener.listener(conn, data) | 56 function console_listener.onincoming(conn, data) |
57 local session = sessions[conn]; | 57 local session = sessions[conn]; |
58 | 58 |
59 if not session then | 59 if not session then |
60 -- Handle new connection | 60 -- Handle new connection |
61 session = console:new_session(conn); | 61 session = console:new_session(conn); |
124 end)(session, data); | 124 end)(session, data); |
125 end | 125 end |
126 session.send(string.char(0)); | 126 session.send(string.char(0)); |
127 end | 127 end |
128 | 128 |
129 function console_listener.disconnect(conn, err) | 129 function console_listener.ondisconnect(conn, err) |
130 local session = sessions[conn]; | 130 local session = sessions[conn]; |
131 if session then | 131 if session then |
132 session.disconnect(); | 132 session.disconnect(); |
133 sessions[conn] = nil; | 133 sessions[conn] = nil; |
134 end | 134 end |