annotate mod_ircd/mod_ircd.lua @ 288:9233d7ee3c09

mod_admin_web: Initial PoC commit
author Florian Zeitz <florob@babelmonkeys.de>
date Fri, 17 Dec 2010 03:34:53 +0100
parents e5cc0fe5eec3
children 282abba844e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 local irc_listener = { default_port = 6667, default_mode = "*l" };
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 local sessions = {};
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 local commands = {};
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 local nicks = {};
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 local st = require "util.stanza";
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 local conference_server = module:get_option("conference_server") or "conference.jabber.org";
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 local function irc_close_session(session)
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 session.conn:close();
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 end
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 function irc_listener.onincoming(conn, data)
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 local session = sessions[conn];
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 if not session then
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 session = { conn = conn, host = module.host, reset_stream = function () end,
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 close = irc_close_session, log = logger.init("irc"..(conn.id or "1")),
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 roster = {} };
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 sessions[conn] = session;
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 function session.data(data)
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 module:log("debug", "Received: %s", data);
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 local command, args = data:match("^%s*([^ ]+) *(.*)%s*$");
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 if not command then
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 module:log("warn", "Invalid command: %s", data);
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 return;
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 end
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 command = command:upper();
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 module:log("debug", "Received command: %s", command);
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 if commands[command] then
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 local ret = commands[command](session, args);
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 if ret then
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 session.send(ret.."\r\n");
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 end
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 end
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 end
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 function session.send(data)
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 module:log("debug", "sending: %s", data);
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 return conn:write(data.."\r\n");
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 end
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 end
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 if data then
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 session.data(data);
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 end
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 end
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 function irc_listener.ondisconnect(conn, error)
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 module:log("debug", "Client disconnected");
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 sessions[conn] = nil;
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 end
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 function commands.NICK(session, nick)
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55 nick = nick:match("^[%w_]+");
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56 if nicks[nick] then
236
24582ea48471 mod_ircd: Fix "nickname in use" reply
Matthew Wild <mwild1@gmail.com>
parents: 212
diff changeset
57 session.send(":"..session.host.." 433 * "..nick.." :The nickname "..nick.." is already in use");
111
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
58 return;
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
59 end
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
60 nicks[nick] = session;
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
61 session.nick = nick;
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
62 session.full_jid = nick.."@"..module.host.."/ircd";
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
63 session.type = "c2s";
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
64 module:log("debug", "Client bound to %s", session.full_jid);
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
65 session.send(":"..session.host.." 001 "..session.nick.." :Welcome to XMPP via the "..session.host.." gateway "..session.nick);
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
66 end
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
67
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
68 local joined_mucs = {};
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
69 function commands.JOIN(session, channel)
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
70 if not joined_mucs[channel] then
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
71 joined_mucs[channel] = { occupants = {}, sessions = {} };
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
72 end
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
73 joined_mucs[channel].sessions[session] = true;
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
74 local join_stanza = st.presence({ from = session.full_jid, to = channel:gsub("^#", "").."@"..conference_server.."/"..session.nick });
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
75 core_process_stanza(session, join_stanza);
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
76 session.send(":"..session.nick.." JOIN :"..channel);
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
77 session.send(":"..session.host.." 332 "..session.nick.." "..channel.." :Connection in progress...");
211
35314bf3410a added correct NAME_REPLY on JOIN message reply
Bjoern Kalkbrenner <terminar@cyberphoria.org>
parents: 154
diff changeset
78 local nicks = session.nick;
35314bf3410a added correct NAME_REPLY on JOIN message reply
Bjoern Kalkbrenner <terminar@cyberphoria.org>
parents: 154
diff changeset
79 for nick in pairs(joined_mucs[channel].occupants) do
35314bf3410a added correct NAME_REPLY on JOIN message reply
Bjoern Kalkbrenner <terminar@cyberphoria.org>
parents: 154
diff changeset
80 nicks = nicks.." "..nick;
35314bf3410a added correct NAME_REPLY on JOIN message reply
Bjoern Kalkbrenner <terminar@cyberphoria.org>
parents: 154
diff changeset
81 end
35314bf3410a added correct NAME_REPLY on JOIN message reply
Bjoern Kalkbrenner <terminar@cyberphoria.org>
parents: 154
diff changeset
82 session.send(":"..session.host.." 353 "..session.nick.." = "..channel.." :"..nicks);
111
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
83 session.send(":"..session.host.." 366 "..session.nick.." "..channel.." :End of /NAMES list.");
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
84 end
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
85
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
86 function commands.PART(session, channel)
132
d4ff1cd414e5 mod_ircd: Add PING command / Echo PART back
Florian Zeitz <florob@babelmonkeys.de>
parents: 111
diff changeset
87 local channel, part_message = channel:match("^([^:]+):?(.*)$");
d4ff1cd414e5 mod_ircd: Add PING command / Echo PART back
Florian Zeitz <florob@babelmonkeys.de>
parents: 111
diff changeset
88 channel = channel:match("^([%S]*)");
111
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
89 core_process_stanza(session, st.presence{ type = "unavailable", from = session.full_jid,
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
90 to = channel:gsub("^#", "").."@"..conference_server.."/"..session.nick }:tag("status"):text(part_message));
132
d4ff1cd414e5 mod_ircd: Add PING command / Echo PART back
Florian Zeitz <florob@babelmonkeys.de>
parents: 111
diff changeset
91 session.send(":"..session.nick.." PART :"..channel);
111
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
92 end
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
93
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
94 function commands.PRIVMSG(session, message)
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
95 local who, message = message:match("^(%S+) :(.+)$");
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
96 if joined_mucs[who] then
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
97 core_process_stanza(session, st.message{to=who:gsub("^#", "").."@"..conference_server, type="groupchat"}:tag("body"):text(message));
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
98 end
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
99 end
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
100
132
d4ff1cd414e5 mod_ircd: Add PING command / Echo PART back
Florian Zeitz <florob@babelmonkeys.de>
parents: 111
diff changeset
101 function commands.PING(session, server)
d4ff1cd414e5 mod_ircd: Add PING command / Echo PART back
Florian Zeitz <florob@babelmonkeys.de>
parents: 111
diff changeset
102 session.send(":"..session.host..": PONG "..server);
d4ff1cd414e5 mod_ircd: Add PING command / Echo PART back
Florian Zeitz <florob@babelmonkeys.de>
parents: 111
diff changeset
103 end
d4ff1cd414e5 mod_ircd: Add PING command / Echo PART back
Florian Zeitz <florob@babelmonkeys.de>
parents: 111
diff changeset
104
111
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
105 function commands.WHO(session, channel)
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
106 if joined_mucs[channel] then
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
107 for nick in pairs(joined_mucs[channel].occupants) do
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
108 --n=MattJ 91.85.191.50 irc.freenode.net MattJ H :0 Matthew Wild
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
109 session.send(":"..session.host.." 352 "..session.nick.." "..channel.." "..nick.." "..nick.." "..session.host.." "..nick.." H :0 "..nick);
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
110 end
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
111 session.send(":"..session.host.." 315 "..session.nick.." "..channel.. " :End of /WHO list");
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
112 end
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
113 end
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
114
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
115 function commands.MODE(session, channel)
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
116 session.send(":"..session.host.." 324 "..session.nick.." "..channel.." +J");
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
117 end
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
118
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
119 --- Component (handle stanzas from the server for IRC clients)
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
120 function irc_component(origin, stanza)
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
121 local from, from_bare = stanza.attr.from, jid.bare(stanza.attr.from);
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
122 local from_node = "#"..jid.split(stanza.attr.from);
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
123
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
124 if joined_mucs[from_node] and from_bare == from then
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
125 -- From room itself
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
126 local joined_muc = joined_mucs[from_node];
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
127 if stanza.name == "message" then
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
128 local subject = stanza:get_child("subject");
151
5abf15351b9a mod_ircd: Fixed handling of empty <subject/> elements.
Waqas Hussain <waqas20@gmail.com>
parents: 150
diff changeset
129 subject = subject and (subject:get_text() or "");
111
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
130 if subject then
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
131 for session in pairs(joined_muc.sessions) do
151
5abf15351b9a mod_ircd: Fixed handling of empty <subject/> elements.
Waqas Hussain <waqas20@gmail.com>
parents: 150
diff changeset
132 session.send(":"..session.host.." 332 "..session.nick.." "..from_node.." :"..subject);
111
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
133 end
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
134 end
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
135 end
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
136 elseif joined_mucs[from_node] then
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
137 -- From room occupant
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
138 local joined_muc = joined_mucs[from_node];
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
139 local nick = select(3, jid.split(from)):gsub(" ", "_");
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
140 if stanza.name == "presence" then
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
141 local what;
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
142 if not stanza.attr.type then
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
143 if joined_muc.occupants[nick] then
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
144 return;
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
145 end
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
146 joined_muc.occupants[nick] = true;
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
147 what = "JOIN";
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
148 else
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
149 joined_muc.occupants[nick] = nil;
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
150 what = "PART";
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
151 end
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
152 for session in pairs(joined_muc.sessions) do
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
153 if nick ~= session.nick then
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
154 session.send(":"..nick.."!"..nick.." "..what.." :"..from_node);
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
155 end
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
156 end
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
157 elseif stanza.name == "message" then
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
158 local body = stanza:get_child("body");
150
fd7f7ebf257e mod_ircd: Fixed handling of empty <body/> elements.
Waqas Hussain <waqas20@gmail.com>
parents: 132
diff changeset
159 body = body and body:get_text() or "";
111
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
160 local hasdelay = stanza:get_child("delay", "urn:xmpp:delay");
154
1849614af19a mod_ircd: Log error when receiving a message without a valid nick
Matthew Wild <mwild1@gmail.com>
parents: 151
diff changeset
161 if body ~= "" and nick then
212
16b76c7b6316 fixed broadcast PRIVMSG bug
Bjoern Kalkbrenner <terminar@cyberphoria.org>
parents: 211
diff changeset
162 local to_nick = jid.split(stanza.attr.to);
16b76c7b6316 fixed broadcast PRIVMSG bug
Bjoern Kalkbrenner <terminar@cyberphoria.org>
parents: 211
diff changeset
163 local session = nicks[to_nick];
16b76c7b6316 fixed broadcast PRIVMSG bug
Bjoern Kalkbrenner <terminar@cyberphoria.org>
parents: 211
diff changeset
164 if nick ~= session.nick or hasdelay then
16b76c7b6316 fixed broadcast PRIVMSG bug
Bjoern Kalkbrenner <terminar@cyberphoria.org>
parents: 211
diff changeset
165 session.send(":"..nick.." PRIVMSG "..from_node.." :"..body);
111
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
166 end
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
167 end
154
1849614af19a mod_ircd: Log error when receiving a message without a valid nick
Matthew Wild <mwild1@gmail.com>
parents: 151
diff changeset
168 if not nick then
1849614af19a mod_ircd: Log error when receiving a message without a valid nick
Matthew Wild <mwild1@gmail.com>
parents: 151
diff changeset
169 module:log("error", "Invalid nick from JID: %s", from);
1849614af19a mod_ircd: Log error when receiving a message without a valid nick
Matthew Wild <mwild1@gmail.com>
parents: 151
diff changeset
170 end
111
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
171 end
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
172 end
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
173 end
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
174
276
27c652363874 mod_ircd: Updated to use events instead of componentmanager.
Waqas Hussain <waqas20@gmail.com>
parents: 236
diff changeset
175 local function stanza_handler(event)
27c652363874 mod_ircd: Updated to use events instead of componentmanager.
Waqas Hussain <waqas20@gmail.com>
parents: 236
diff changeset
176 irc_component(event.origin, event.stanza);
27c652363874 mod_ircd: Updated to use events instead of componentmanager.
Waqas Hussain <waqas20@gmail.com>
parents: 236
diff changeset
177 return true;
27c652363874 mod_ircd: Updated to use events instead of componentmanager.
Waqas Hussain <waqas20@gmail.com>
parents: 236
diff changeset
178 end
282
e5cc0fe5eec3 mod_ircd: Give stanza handlers a negative priority, to allow mod_iq to process them first.
Waqas Hussain <waqas20@gmail.com>
parents: 276
diff changeset
179 module:hook("iq/bare", stanza_handler, -1);
e5cc0fe5eec3 mod_ircd: Give stanza handlers a negative priority, to allow mod_iq to process them first.
Waqas Hussain <waqas20@gmail.com>
parents: 276
diff changeset
180 module:hook("message/bare", stanza_handler, -1);
e5cc0fe5eec3 mod_ircd: Give stanza handlers a negative priority, to allow mod_iq to process them first.
Waqas Hussain <waqas20@gmail.com>
parents: 276
diff changeset
181 module:hook("presence/bare", stanza_handler, -1);
e5cc0fe5eec3 mod_ircd: Give stanza handlers a negative priority, to allow mod_iq to process them first.
Waqas Hussain <waqas20@gmail.com>
parents: 276
diff changeset
182 module:hook("iq/full", stanza_handler, -1);
e5cc0fe5eec3 mod_ircd: Give stanza handlers a negative priority, to allow mod_iq to process them first.
Waqas Hussain <waqas20@gmail.com>
parents: 276
diff changeset
183 module:hook("message/full", stanza_handler, -1);
e5cc0fe5eec3 mod_ircd: Give stanza handlers a negative priority, to allow mod_iq to process them first.
Waqas Hussain <waqas20@gmail.com>
parents: 276
diff changeset
184 module:hook("presence/full", stanza_handler, -1);
e5cc0fe5eec3 mod_ircd: Give stanza handlers a negative priority, to allow mod_iq to process them first.
Waqas Hussain <waqas20@gmail.com>
parents: 276
diff changeset
185 module:hook("iq/host", stanza_handler, -1);
e5cc0fe5eec3 mod_ircd: Give stanza handlers a negative priority, to allow mod_iq to process them first.
Waqas Hussain <waqas20@gmail.com>
parents: 276
diff changeset
186 module:hook("message/host", stanza_handler, -1);
e5cc0fe5eec3 mod_ircd: Give stanza handlers a negative priority, to allow mod_iq to process them first.
Waqas Hussain <waqas20@gmail.com>
parents: 276
diff changeset
187 module:hook("presence/host", stanza_handler, -1);
276
27c652363874 mod_ircd: Updated to use events instead of componentmanager.
Waqas Hussain <waqas20@gmail.com>
parents: 236
diff changeset
188 require "core.componentmanager".register_component(module.host, function() end); -- COMPAT Prosody 0.7
111
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
189
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
190 prosody.events.add_handler("server-stopping", function (shutdown)
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
191 module:log("debug", "Closing IRC connections prior to shutdown");
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
192 for channel, joined_muc in pairs(joined_mucs) do
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
193 for session in pairs(joined_muc.sessions) do
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
194 core_process_stanza(session,
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
195 st.presence{ type = "unavailable", from = session.full_jid,
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
196 to = channel:gsub("^#", "").."@"..conference_server.."/"..session.nick }
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
197 :tag("status")
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
198 :text("Connection closed: Server is shutting down"..(shutdown.reason and (": "..shutdown.reason) or "")));
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
199 session:close();
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
200 end
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
201 end
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
202 end);
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
203
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
204 require "net.connlisteners".register("irc", irc_listener);
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
205 require "net.connlisteners".start("irc", { port = module:get_option("port") });