Annotate

mod_ircd/mod_ircd.in.lua @ 465:030404dd7609

mod_ircd: Better nameing, squishy.
author Kim Alvefur <zash@zash.se>
date Tue, 01 Nov 2011 13:52:29 +0100
parent 461:mod_ircd/mod_ircd_broke.lua@bbea8081c865
child 466:0fcd34ee7301
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
326
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
1 -- README
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
2 -- Squish verse into this dir, then squish them into one, which you move
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
3 -- and rename to mod_ircd.lua in your prosody modules/plugins dir.
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
4 --
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
5 -- IRC spec:
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
6 -- http://tools.ietf.org/html/rfc2812
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
7 local _module = module
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
8 module = _G.module
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
9 local module = _module
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
10 --
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
11 local component_jid, component_secret, muc_server =
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
12 module.host, nil, module:get_option("conference_server");
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
13
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
14 package.loaded["util.sha1"] = require "util.encodings";
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
15 local verse = require "verse"
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
16 require "verse.component"
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
17 require "socket"
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
18 c = verse.new();--verse.logger())
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
19 c:add_plugin("groupchat");
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
20
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
21 local function verse2prosody(e)
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
22 return c:event("stanza", e.stanza) or true;
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
23 end
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
24 module:hook("message/bare", verse2prosody);
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
25 module:hook("message/full", verse2prosody);
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
26 module:hook("presence/bare", verse2prosody);
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
27 module:hook("presence/full", verse2prosody);
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
28 c.type = "component";
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
29 c.send = core_post_stanza;
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
30
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
31 -- This plugin is actually a verse based component, but that mode is currently commented out
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
32
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
33 -- Add some hooks for debugging
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
34 --c:hook("opened", function () print("Stream opened!") end);
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
35 --c:hook("closed", function () print("Stream closed!") end);
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
36 --c:hook("stanza", function (stanza) print("Stanza:", stanza) end);
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
37
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
38 -- This one prints all received data
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
39 --c:hook("incoming-raw", print, 1000);
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
40 --c:hook("stanza", print, 1000);
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
41 --c:hook("outgoing-raw", print, 1000);
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
42
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
43 -- Print a message after authentication
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
44 --c:hook("authentication-success", function () print("Logged in!"); end);
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
45 --c:hook("authentication-failure", function (err) print("Failed to log in! Error: "..tostring(err.condition)); end);
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
46
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
47 -- Print a message and exit when disconnected
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
48 --c:hook("disconnected", function () print("Disconnected!"); os.exit(); end);
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
49
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
50 -- Now, actually start the connection:
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
51 --c.connect_host = "127.0.0.1"
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
52 --c:connect_component(component_jid, component_secret);
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
53
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
54 local jid = require "util.jid";
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
55
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
56 local function irc2muc(channel, nick)
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
57 return jid.join(channel:gsub("^#", ""), muc_server, nick)
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
58 end
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
59 local function muc2irc(room)
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
60 local channel, _, nick = jid.split(room);
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
61 return "#"..channel, nick;
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
62 end
335
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
63 local rolemap = {
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
64 moderator = "@",
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
65 participant = "+",
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
66 }
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
67 local modemap = {
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
68 moderator = "o",
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
69 participant = "v",
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
70 }
326
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
71
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
72 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
73
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 sessions = {};
326
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
75 local jids = {};
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
76 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
77
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
78 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
79
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
80 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
81
326
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
82 local conference_server = muc_server;
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
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 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
85 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
86 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
87
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
88 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
89 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
90 if not session then
326
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
91 session = { conn = conn, host = component_jid, reset_stream = function () 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
92 close = irc_close_session, log = logger.init("irc"..(conn.id or "1")),
326
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
93 rooms = {},
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
94 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
95 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
96 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
97 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
98 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
99 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
100 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
101 command = command:upper();
335
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
102 if not session.nick then
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
103 if not (command == "USER" or command == "NICK") then
465
030404dd7609 mod_ircd: Better nameing, squishy.
Kim Alvefur <zash@zash.se>
parents: 461
diff changeset
104 session.send(":" .. muc_server .. " 451 " .. command .. " :You have not registered")
030404dd7609 mod_ircd: Better nameing, squishy.
Kim Alvefur <zash@zash.se>
parents: 461
diff changeset
105 return true;
335
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
106 end
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
107 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
108 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
109 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
110 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
111 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
112 end
326
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
113 else
465
030404dd7609 mod_ircd: Better nameing, squishy.
Kim Alvefur <zash@zash.se>
parents: 461
diff changeset
114 session.send(":" .. muc_server .. " 421 " .. session.nick .. " " .. command .. " :Unknown command")
326
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
115 module:log("debug", "Unknown command: %s", command);
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
116 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
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 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
119 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
120 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
121 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
122 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
123 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
124 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
125 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
126
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 function irc_listener.ondisconnect(conn, error)
326
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
128 local session = sessions[conn];
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
129 for _, room in pairs(session.rooms) do
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
130 room:leave("Disconnected");
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
131 end
335
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
132 jids[session.full_jid] = nil;
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
133 nicks[session.nick] = nil;
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
134 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
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
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 function commands.NICK(session, nick)
326
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
138 if session.nick then
465
030404dd7609 mod_ircd: Better nameing, squishy.
Kim Alvefur <zash@zash.se>
parents: 461
diff changeset
139 session.send(":"..muc_server.." 484 * "..nick.." :I'm afraid I can't let you do that, "..nick);
335
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
140 --TODO Loop throug all rooms and change nick, with help from Verse.
326
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
141 return;
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
142 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
143 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
144 if nicks[nick] then
236
24582ea48471 mod_ircd: Fix "nickname in use" reply
Matthew Wild <mwild1@gmail.com>
parents: 212
diff changeset
145 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
146 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
147 end
326
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
148 local full_jid = jid.join(nick, component_jid, "ircd");
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
149 jids[full_jid] = session;
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
150 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
151 session.nick = nick;
326
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
152 session.full_jid = full_jid;
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
153 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
154 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
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
329
febfb59502fc mod_ircd: Add QUIT command.
Kim Alvefur <zash@zash.se>
parents: 326
diff changeset
157 function commands.USER(session, params)
febfb59502fc mod_ircd: Add QUIT command.
Kim Alvefur <zash@zash.se>
parents: 326
diff changeset
158 -- FIXME
febfb59502fc mod_ircd: Add QUIT command.
Kim Alvefur <zash@zash.se>
parents: 326
diff changeset
159 -- Empty command for now
febfb59502fc mod_ircd: Add QUIT command.
Kim Alvefur <zash@zash.se>
parents: 326
diff changeset
160 end
febfb59502fc mod_ircd: Add QUIT command.
Kim Alvefur <zash@zash.se>
parents: 326
diff changeset
161
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
162 function commands.JOIN(session, channel)
326
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
163 local room_jid = irc2muc(channel);
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
164 print(session.full_jid);
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
165 local room, err = c:join_room(room_jid, session.nick, { source = session.full_jid } );
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
166 if not room then
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
167 return ":"..session.host.." ERR :Could not join room: "..err
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
168 end
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
169 session.rooms[channel] = room;
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
170 room.channel = channel;
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
171 room.session = session;
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
172 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
173 session.send(":"..session.host.." 332 "..session.nick.." "..channel.." :Connection in progress...");
326
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
174 room:hook("message", function(event)
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
175 if not event.body then return end
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
176 local nick, body = event.nick, event.body;
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
177 if nick ~= session.nick then
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
178 if body:sub(1,4) == "/me " then
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
179 body = "\1ACTION ".. body:sub(5) .. "\1"
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
180 end
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
181 session.send(":"..nick.." PRIVMSG "..channel.." :"..body);
329
febfb59502fc mod_ircd: Add QUIT command.
Kim Alvefur <zash@zash.se>
parents: 326
diff changeset
182 --FIXME PM's probably won't work
326
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
183 end
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
184 end);
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
185 end
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
186
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
187 c:hook("groupchat/joined", function(room)
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
188 local session = room.session or jids[room.opts.source];
335
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
189 local channel = room.channel;
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
190 session.send((":%s!%s JOIN %s :"):format(session.nick, session.nick, channel));
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
191 if room.topic then
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
192 session.send((":%s 332 %s :%s"):format(session.host, channel, room.topic));
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
193 end
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
194 commands.NAMES(session, channel)
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
195 --FIXME Ones own mode get's lost
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
196 --session.send((":%s MODE %s +%s %s"):format(session.host, room.channel, modemap[nick.role], nick.nick));
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
197 room:hook("occupant-joined", function(nick)
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
198 session.send((":%s!%s JOIN :%s"):format(nick.nick, nick.nick, channel));
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
199 if nick.role and modemap[nick.role] then
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
200 session.send((":%s MODE %s +%s %s"):format(session.host, room.channel, modemap[nick.role], nick.nick));
326
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
201 end
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
202 end);
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
203 room:hook("occupant-left", function(nick)
335
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
204 session.send((":%s!%s PART %s :"):format(nick.nick, nick.nick, channel));
326
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
205 end);
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
206 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
207
335
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
208 function commands.NAMES(session, channel)
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
209 local nicks = { };
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
210 local room = session.rooms[channel];
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
211 if not room then return end
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
212 -- TODO Break this out into commands.NAMES
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
213 for nick, n in pairs(room.occupants) do
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
214 if n.role and rolemap[n.role] then
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
215 nick = rolemap[n.role] .. nick;
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
216 end
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
217 table.insert(nicks, nick);
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
218 end
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
219 nicks = table.concat(nicks, " ");
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
220 --:molyb.irc.bnfh.org 353 derp = #grill-bit :derp hyamobi walt snuggles_ E-Rock kng grillbit gunnarbot Frink shedma zagabar zash Mrw00t Appiah J10 lectus peck EricJ soso mackt offer hyarion @pettter MMN-o
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
221 session.send((":%s 353 %s = %s :%s"):format(session.host, session.nick, channel, nicks));
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
222 session.send((":%s 366 %s %s :End of /NAMES list."):format(session.host, session.nick, channel));
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
223 session.send(":"..session.host.." 353 "..session.nick.." = "..channel.." :"..nicks);
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
224 end
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
225
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
226 function commands.PART(session, channel)
132
d4ff1cd414e5 mod_ircd: Add PING command / Echo PART back
Florian Zeitz <florob@babelmonkeys.de>
parents: 111
diff changeset
227 local channel, part_message = channel:match("^([^:]+):?(.*)$");
d4ff1cd414e5 mod_ircd: Add PING command / Echo PART back
Florian Zeitz <florob@babelmonkeys.de>
parents: 111
diff changeset
228 channel = channel:match("^([%S]*)");
326
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
229 session.rooms[channel]:leave(part_message);
132
d4ff1cd414e5 mod_ircd: Add PING command / Echo PART back
Florian Zeitz <florob@babelmonkeys.de>
parents: 111
diff changeset
230 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
231 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
232
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
233 function commands.PRIVMSG(session, message)
326
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
234 local channel, message = message:match("^(%S+) :(.+)$");
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
235 if message and #message > 0 and session.rooms[channel] then
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
236 if message:sub(1,8) == "\1ACTION " then
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
237 message = "/me ".. message:sub(9,-2)
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
238 end
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
239 module:log("debug", "%s sending PRIVMSG \"%s\" to %s", session.nick, message, channel);
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
240 session.rooms[channel]:send_message(message);
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
241 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
242 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
243
132
d4ff1cd414e5 mod_ircd: Add PING command / Echo PART back
Florian Zeitz <florob@babelmonkeys.de>
parents: 111
diff changeset
244 function commands.PING(session, server)
d4ff1cd414e5 mod_ircd: Add PING command / Echo PART back
Florian Zeitz <florob@babelmonkeys.de>
parents: 111
diff changeset
245 session.send(":"..session.host..": PONG "..server);
d4ff1cd414e5 mod_ircd: Add PING command / Echo PART back
Florian Zeitz <florob@babelmonkeys.de>
parents: 111
diff changeset
246 end
d4ff1cd414e5 mod_ircd: Add PING command / Echo PART back
Florian Zeitz <florob@babelmonkeys.de>
parents: 111
diff changeset
247
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
248 function commands.WHO(session, channel)
326
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
249 if session.rooms[channel] then
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
250 local room = session.rooms[channel]
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
251 for nick in pairs(room.occupants) do
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
252 --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
253 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
254 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
255 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
256 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
257 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
258
3de60860adca mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
259 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
260 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
261 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
262
329
febfb59502fc mod_ircd: Add QUIT command.
Kim Alvefur <zash@zash.se>
parents: 326
diff changeset
263 function commands.QUIT(session, message)
febfb59502fc mod_ircd: Add QUIT command.
Kim Alvefur <zash@zash.se>
parents: 326
diff changeset
264 session.send("ERROR :Closing Link: "..session.nick);
febfb59502fc mod_ircd: Add QUIT command.
Kim Alvefur <zash@zash.se>
parents: 326
diff changeset
265 for _, room in pairs(session.rooms) do
febfb59502fc mod_ircd: Add QUIT command.
Kim Alvefur <zash@zash.se>
parents: 326
diff changeset
266 room:leave(message);
febfb59502fc mod_ircd: Add QUIT command.
Kim Alvefur <zash@zash.se>
parents: 326
diff changeset
267 end
335
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
268 jids[session.full_jid] = nil;
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
269 nicks[session.nick] = nil;
8b81257c9dc5 mod_ircd: Don't allow any command until nick has been set. Split out NAMES into a command.
Kim Alvefur <zash@zash.se>
parents: 329
diff changeset
270 sessions[session.conn] = nil;
329
febfb59502fc mod_ircd: Add QUIT command.
Kim Alvefur <zash@zash.se>
parents: 326
diff changeset
271 session:close();
febfb59502fc mod_ircd: Add QUIT command.
Kim Alvefur <zash@zash.se>
parents: 326
diff changeset
272 end
326
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
273
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
274 function commands.RAW(session, data)
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
275 --c:send(data)
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
276 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
277
465
030404dd7609 mod_ircd: Better nameing, squishy.
Kim Alvefur <zash@zash.se>
parents: 461
diff changeset
278 local function desetup()
030404dd7609 mod_ircd: Better nameing, squishy.
Kim Alvefur <zash@zash.se>
parents: 461
diff changeset
279 require "net.connlisteners".deregister("irc");
030404dd7609 mod_ircd: Better nameing, squishy.
Kim Alvefur <zash@zash.se>
parents: 461
diff changeset
280 end
030404dd7609 mod_ircd: Better nameing, squishy.
Kim Alvefur <zash@zash.se>
parents: 461
diff changeset
281
326
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
282 --c:hook("ready", function ()
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
283 require "net.connlisteners".register("irc", irc_listener);
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
284 require "net.connlisteners".start("irc");
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
285 --end);
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
286
465
030404dd7609 mod_ircd: Better nameing, squishy.
Kim Alvefur <zash@zash.se>
parents: 461
diff changeset
287 module:hook("module-unloaded", desetup)
030404dd7609 mod_ircd: Better nameing, squishy.
Kim Alvefur <zash@zash.se>
parents: 461
diff changeset
288
030404dd7609 mod_ircd: Better nameing, squishy.
Kim Alvefur <zash@zash.se>
parents: 461
diff changeset
289
326
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
290 --print("Starting loop...")
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
291 --verse.loop()
282abba844e8 mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents: 282
diff changeset
292
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
293