Software /
code /
prosody-modules
Annotate
mod_ircd/mod_ircd.in.lua @ 466:0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 01 Nov 2011 18:08:15 +0100 |
parent | 465:030404dd7609 |
child | 468:640e6c0b563d |
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"; |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
55 local nodeprep = require "util.encodings".stringprep.nodeprep; |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
56 |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
57 local function parse_line(line) |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
58 local ret = {}; |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
59 if line:sub(1,1) == ":" then |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
60 ret.from, line = line:match("^:(%w+)%s+(.*)$"); |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
61 end |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
62 for part in line:gmatch("%S+") do |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
63 if part:sub(1,1) == ":" then |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
64 ret[#ret+1] = line:match(":(.*)$"); |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
65 break |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
66 end |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
67 ret[#ret+1]=part; |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
68 end |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
69 return ret; |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
70 end |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
71 |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
72 local function build_line(parts) |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
73 if #parts > 1 then |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
74 parts[#parts] = ":" .. parts[#parts]; |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
75 end |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
76 return (parts.from and ":"..parts.from.." " or "")..table.concat(parts, " "); |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
77 end |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
78 |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
79 local function irc2muc(channel, nick) |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
80 local room = channel and nodeprep(channel:match("^#(%w+)")) or nil; |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
81 return jid.join(room, muc_server, nick) |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
82 end |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
83 local function muc2irc(room) |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
84 local channel, _, nick = jid.split(room); |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
85 return "#"..channel, nick; |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
86 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
|
87 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
|
88 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
|
89 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
|
90 } |
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
|
91 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
|
92 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
|
93 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
|
94 } |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
95 |
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
|
96 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
|
97 |
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 local sessions = {}; |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
99 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
|
100 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
|
101 |
3de60860adca
mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 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
|
103 |
3de60860adca
mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 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
|
105 |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
106 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
|
107 |
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 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
|
109 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
|
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 |
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 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
|
113 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
|
114 if not session then |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
115 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
|
116 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
|
117 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
|
118 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
|
119 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
|
120 function session.data(data) |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
121 local parts = parse_line(data); |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
122 module:log("debug", require"util.serialization".serialize(parts)); |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
123 local command = table.remove(parts, 1); |
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
|
124 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
|
125 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
|
126 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
|
127 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
|
128 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
|
129 if not (command == "USER" or command == "NICK") then |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
130 module:log("debug", "Client tried to send command %s before registering", command); |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
131 return session.send{from=muc_server, 451, command, "You have not registered"} |
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 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
|
133 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
|
134 if commands[command] then |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
135 local ret = commands[command](session, parts); |
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
|
136 if ret then |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
137 return session.send(ret); |
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
|
138 end |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
139 else |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
140 session.send{from=muc_server, 421, session.nick, command, "Unknown command"}; |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
141 return 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
|
142 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
|
143 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
|
144 function session.send(data) |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
145 if type(data) == "string" then |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
146 return conn:write(data.."\r\n"); |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
147 elseif type(data) == "table" then |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
148 local line = build_line(data); |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
149 module:log("debug", line); |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
150 conn:write(line.."\r\n"); |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
151 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
|
152 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
|
153 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
|
154 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
|
155 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
|
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 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
|
158 |
3de60860adca
mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
159 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
|
160 local session = sessions[conn]; |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
161 if session then |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
162 for _, room in pairs(session.rooms) do |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
163 room:leave("Disconnected"); |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
164 end |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
165 if session.nick then |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
166 nicks[session.nick] = nil; |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
167 end |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
168 if session.full_jid then |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
169 jids[session.full_jid] = nil; |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
170 end |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
171 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
|
172 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
|
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 |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
175 function commands.NICK(session, args) |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
176 if session.nick then |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
177 session.send(":"..muc_server.." 484 * "..nick.." :I'm afraid I can't let you do that, "..session.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
|
178 --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
|
179 return; |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
180 end |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
181 local nick = args[1]; |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
182 nick = nick:gsub("[^%w_]",""); |
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
|
183 if nicks[nick] then |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
184 session.send{from=muc_server, 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
|
185 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
|
186 end |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
187 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
|
188 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
|
189 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
|
190 session.nick = nick; |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
191 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
|
192 session.type = "c2s"; |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
193 session.send{from = muc_server, 001, nick, "Welcome to XMPP via the "..session.host.." gateway "..session.nick}; |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
194 session.send{from=nick, "MODE", nick, "+i"}; -- why |
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
|
195 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
|
196 |
329 | 197 function commands.USER(session, params) |
198 -- FIXME | |
199 -- Empty command for now | |
200 end | |
201 | |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
202 function commands.JOIN(session, args) |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
203 local channel = args[1]; |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
204 local room_jid = irc2muc(channel); |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
205 print(session.full_jid); |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
206 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
|
207 if not room then |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
208 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
|
209 end |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
210 session.rooms[channel] = room; |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
211 room.channel = channel; |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
212 room.session = session; |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
213 session.send{from=session.nick, "JOIN", channel}; |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
214 session.send{from=muc_server, 332, session.nick, channel ,"Connection in progress..."}; |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
215 |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
216 room:hook("message", function(event) |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
217 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
|
218 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
|
219 if nick ~= session.nick then |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
220 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
|
221 body = "\1ACTION ".. body:sub(5) .. "\1" |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
222 end |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
223 local type = event.stanza.attr.type; |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
224 session.send{from=nick, "PRIVMSG", type == "groupchat" and channel or nick, body}; |
329 | 225 --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
|
226 end |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
227 end); |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
228 end |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
229 |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
230 c:hook("groupchat/joined", function(room) |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
231 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
|
232 local channel = room.channel; |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
233 session.send{from=session.nick.."!"..session.nick, "JOIN", channel}; |
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
|
234 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
|
235 if room.topic then |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
236 session.send{from=muc_server, 332, room.topic}; |
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
|
237 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
|
238 commands.NAMES(session, channel) |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
239 if session.nick.role then |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
240 session.send{from=muc_server, "MODE", channel, session.nick, modemap[session.nick.role], session.nick} |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
241 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
|
242 room:hook("occupant-joined", function(nick) |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
243 session.send{from=nick.nick.."!"..nick.nick, "JOIN", channel}; |
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
|
244 if nick.role and modemap[nick.role] then |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
245 session.send{from=nick.nick.."!"..nick.nick, "MODE", 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
|
246 end |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
247 end); |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
248 room:hook("occupant-left", function(nick) |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
249 session.send{from=nick.nick.."!"..nick.nick, "PART", room.channel}; |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
250 end); |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
251 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
|
252 |
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
|
253 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
|
254 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
|
255 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
|
256 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
|
257 -- 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
|
258 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
|
259 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
|
260 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
|
261 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
|
262 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
|
263 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
|
264 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
|
265 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
|
266 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
|
267 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
|
268 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
|
269 |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
270 function commands.PART(session, args) |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
271 local channel, part_message = unpack(args); |
132
d4ff1cd414e5
mod_ircd: Add PING command / Echo PART back
Florian Zeitz <florob@babelmonkeys.de>
parents:
111
diff
changeset
|
272 channel = channel:match("^([%S]*)"); |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
273 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
|
274 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
|
275 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
|
276 |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
277 function commands.PRIVMSG(session, args) |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
278 local channel, message = unpack(args); |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
279 if message and #message > 0 then |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
280 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
|
281 message = "/me ".. message:sub(9,-2) |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
282 end |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
283 -- TODO clean out invalid chars |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
284 if channel:sub(1,1) == "#" then |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
285 if session.rooms[channel] then |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
286 module:log("debug", "%s sending PRIVMSG \"%s\" to %s", session.nick, message, channel); |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
287 session.rooms[channel]:send_message(message); |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
288 end |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
289 else -- private message |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
290 local nick = channel; |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
291 module:log("debug", "PM to %s", nick); |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
292 for channel, room in pairs(session.rooms) do |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
293 module:log("debug", "looking for %s in %s", nick, channel); |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
294 if room.occupants[nick] then |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
295 module:log("debug", "found %s in %s", nick, channel); |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
296 local who = room.occupants[nick]; |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
297 -- FIXME PMs in verse |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
298 --room:send_private_message(nick, message); |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
299 local pm = st.message({type="chat",to=who.jid}, message); |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
300 module:log("debug", "sending PM to %s: %s", nick, tostring(pm)); |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
301 room:send(pm) |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
302 break |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
303 end |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
304 end |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
305 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
|
306 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
|
307 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
|
308 |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
309 function commands.PING(session, args) |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
310 session.send{from=muc_server, "PONG", args[1]}; |
132
d4ff1cd414e5
mod_ircd: Add PING command / Echo PART back
Florian Zeitz <florob@babelmonkeys.de>
parents:
111
diff
changeset
|
311 end |
d4ff1cd414e5
mod_ircd: Add PING command / Echo PART back
Florian Zeitz <florob@babelmonkeys.de>
parents:
111
diff
changeset
|
312 |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
313 function commands.WHO(session, args) |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
314 local channel = args[1]; |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
315 if session.rooms[channel] then |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
316 local room = session.rooms[channel] |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
317 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
|
318 --n=MattJ 91.85.191.50 irc.freenode.net MattJ H :0 Matthew Wild |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
319 session.send{from=muc_server, 352, session.nick, channel, nick, nick, muc_server, nick, "H", "0 "..nick} |
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
|
320 end |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
321 session.send{from=muc_server, 315, session.nick, channel, "End of /WHO list"}; |
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
|
322 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
|
323 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
|
324 |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
325 function commands._MODE(session, args) -- FIXME |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
326 local channel, target = unpack(args); |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
327 if target then |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
328 -- do stuff? |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
329 --room:set_affiliation(...) |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
330 else |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
331 -- What's 324? And +J ? |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
332 session.send{from=muc_server, 324, session.nick, channel, "+J"} |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
333 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
|
334 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
|
335 |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
336 function commands.QUIT(session, args) |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
337 session.send{"ERROR", "Closing Link: "..session.nick}; |
329 | 338 for _, room in pairs(session.rooms) do |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
339 room:leave(args[1]); |
329 | 340 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
|
341 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
|
342 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
|
343 sessions[session.conn] = nil; |
329 | 344 session:close(); |
345 end | |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
346 |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
347 function commands.RAW(session, data) |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
348 --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
|
349 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
|
350 |
465
030404dd7609
mod_ircd: Better nameing, squishy.
Kim Alvefur <zash@zash.se>
parents:
461
diff
changeset
|
351 local function desetup() |
030404dd7609
mod_ircd: Better nameing, squishy.
Kim Alvefur <zash@zash.se>
parents:
461
diff
changeset
|
352 require "net.connlisteners".deregister("irc"); |
030404dd7609
mod_ircd: Better nameing, squishy.
Kim Alvefur <zash@zash.se>
parents:
461
diff
changeset
|
353 end |
030404dd7609
mod_ircd: Better nameing, squishy.
Kim Alvefur <zash@zash.se>
parents:
461
diff
changeset
|
354 |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
355 --c:hook("ready", function () |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
356 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
|
357 require "net.connlisteners".start("irc"); |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
358 --end); |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
359 |
465
030404dd7609
mod_ircd: Better nameing, squishy.
Kim Alvefur <zash@zash.se>
parents:
461
diff
changeset
|
360 module:hook("module-unloaded", desetup) |
030404dd7609
mod_ircd: Better nameing, squishy.
Kim Alvefur <zash@zash.se>
parents:
461
diff
changeset
|
361 |
030404dd7609
mod_ircd: Better nameing, squishy.
Kim Alvefur <zash@zash.se>
parents:
461
diff
changeset
|
362 |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
363 --print("Starting loop...") |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
364 --verse.loop() |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
365 |
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
|
366 |