Software /
code /
prosody-modules
Annotate
mod_ircd/dev/mod_ircd.old_comments @ 556:e50bdbaa7802
mod_muc_limits: Remove throttle object from all rooms on unload (to make sure new settings are applied on reload)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 15 Jan 2012 01:40:50 +0000 |
parent | 491:5b3db688213d |
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 -- |
483
f4ada087c743
mod_ircd: added listener port configuration, added utf8 checks to TOPIC, added check so that module wonn't get loaded if conference_server is unset.
Marco Cirillo <maranda@lightwitch.org>
parents:
482
diff
changeset
|
11 local component_jid, component_secret, muc_server, port_number = |
f4ada087c743
mod_ircd: added listener port configuration, added utf8 checks to TOPIC, added check so that module wonn't get loaded if conference_server is unset.
Marco Cirillo <maranda@lightwitch.org>
parents:
482
diff
changeset
|
12 module.host, nil, module:get_option_string("conference_server"), module:get_option_number("listener_port", 7000); |
f4ada087c743
mod_ircd: added listener port configuration, added utf8 checks to TOPIC, added check so that module wonn't get loaded if conference_server is unset.
Marco Cirillo <maranda@lightwitch.org>
parents:
482
diff
changeset
|
13 |
f4ada087c743
mod_ircd: added listener port configuration, added utf8 checks to TOPIC, added check so that module wonn't get loaded if conference_server is unset.
Marco Cirillo <maranda@lightwitch.org>
parents:
482
diff
changeset
|
14 if not muc_server then |
f4ada087c743
mod_ircd: added listener port configuration, added utf8 checks to TOPIC, added check so that module wonn't get loaded if conference_server is unset.
Marco Cirillo <maranda@lightwitch.org>
parents:
482
diff
changeset
|
15 module:log ("error", "You need to set the MUC server! halting.") |
f4ada087c743
mod_ircd: added listener port configuration, added utf8 checks to TOPIC, added check so that module wonn't get loaded if conference_server is unset.
Marco Cirillo <maranda@lightwitch.org>
parents:
482
diff
changeset
|
16 return false; |
f4ada087c743
mod_ircd: added listener port configuration, added utf8 checks to TOPIC, added check so that module wonn't get loaded if conference_server is unset.
Marco Cirillo <maranda@lightwitch.org>
parents:
482
diff
changeset
|
17 end |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
18 |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
19 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
|
20 local verse = require "verse" |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
21 require "verse.component" |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
22 require "socket" |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
23 c = verse.new();--verse.logger()) |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
24 c:add_plugin("groupchat"); |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
25 |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
26 local function verse2prosody(e) |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
27 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
|
28 end |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
29 module:hook("message/bare", verse2prosody); |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
30 module:hook("message/full", verse2prosody); |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
31 module:hook("presence/bare", verse2prosody); |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
32 module:hook("presence/full", verse2prosody); |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
33 c.type = "component"; |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
34 c.send = core_post_stanza; |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
35 |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
36 -- 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
|
37 |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
38 -- Add some hooks for debugging |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
39 --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
|
40 --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
|
41 --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
|
42 |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
43 -- This one prints all received data |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
44 --c:hook("incoming-raw", print, 1000); |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
45 --c:hook("stanza", print, 1000); |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
46 --c:hook("outgoing-raw", print, 1000); |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
47 |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
48 -- Print a message after authentication |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
49 --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
|
50 --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
|
51 |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
52 -- 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
|
53 --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
|
54 |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
55 -- Now, actually start the connection: |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
56 --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
|
57 --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
|
58 |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
59 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
|
60 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
|
61 |
468
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
62 local function utf8_clean (s) |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
63 local push, join = table.insert, table.concat; |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
64 local r, i = {}, 1; |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
65 if not(s and #s > 0) then |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
66 return "" |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
67 end |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
68 while true do |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
69 local c = s:sub(i,i) |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
70 local b = c:byte(); |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
71 local w = ( |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
72 (b >= 9 and b <= 10 and 0) or |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
73 (b >= 32 and b <= 126 and 0) or |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
74 (b >= 192 and b <= 223 and 1) or |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
75 (b >= 224 and b <= 239 and 2) or |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
76 (b >= 240 and b <= 247 and 3) or |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
77 (b >= 248 and b <= 251 and 4) or |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
78 (b >= 251 and b <= 252 and 5) or nil |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
79 ) |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
80 if not w then |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
81 push(r, "?") |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
82 else |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
83 local n = i + w; |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
84 if w == 0 then |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
85 push(r, c); |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
86 elseif n > #s then |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
87 push(r, ("?"):format(b)); |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
88 else |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
89 local e = s:sub(i+1,n); |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
90 if e:match('^[\128-\191]*$') then |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
91 push(r, c); |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
92 push(r, e); |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
93 i = n; |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
94 else |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
95 push(r, ("?"):format(b)); |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
96 end |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
97 end |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
98 end |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
99 i = i + 1; |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
100 if i > #s then |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
101 break |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
102 end |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
103 end |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
104 return join(r); |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
105 end |
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
106 |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
107 local function parse_line(line) |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
108 local ret = {}; |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
109 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
|
110 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
|
111 end |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
112 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
|
113 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
|
114 ret[#ret+1] = line:match(":(.*)$"); |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
115 break |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
116 end |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
117 ret[#ret+1]=part; |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
118 end |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
119 return ret; |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
120 end |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
121 |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
122 local function build_line(parts) |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
123 if #parts > 1 then |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
124 parts[#parts] = ":" .. parts[#parts]; |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
125 end |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
126 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
|
127 end |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
128 |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
129 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
|
130 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
|
131 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
|
132 end |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
133 local function muc2irc(room) |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
134 local channel, _, nick = jid.split(room); |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
135 return "#"..channel, nick; |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
136 end |
470
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
137 local role_map = { |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
138 moderator = "@", |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
139 participant = "", |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
140 visitor = "", |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
141 none = "" |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
142 } |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
143 local aff_map = { |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
144 owner = "~", |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
145 administrator = "&", |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
146 member = "+", |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
147 none = "" |
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
|
148 } |
470
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
149 local role_modemap = { |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
150 moderator = "o", |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
151 participant = "", |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
152 visitor = "", |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
153 none = "" |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
154 } |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
155 local aff_modemap = { |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
156 owner = "q", |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
157 administrator = "a", |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
158 member = "v", |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
159 none = "" |
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
|
160 } |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
161 |
483
f4ada087c743
mod_ircd: added listener port configuration, added utf8 checks to TOPIC, added check so that module wonn't get loaded if conference_server is unset.
Marco Cirillo <maranda@lightwitch.org>
parents:
482
diff
changeset
|
162 local irc_listener = { default_port = port_number, default_mode = "*l" }; |
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
|
163 |
3de60860adca
mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
164 local sessions = {}; |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
165 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
|
166 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
|
167 |
3de60860adca
mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
168 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
|
169 |
3de60860adca
mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
170 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
|
171 |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
172 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
|
173 |
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 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
|
175 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
|
176 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
|
177 |
3de60860adca
mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
178 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
|
179 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
|
180 if not session then |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
181 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
|
182 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
|
183 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
|
184 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
|
185 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
|
186 function session.data(data) |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
187 local parts = parse_line(data); |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
188 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
|
189 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
|
190 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
|
191 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
|
192 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
|
193 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
|
194 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
|
195 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
|
196 module:log("debug", "Client tried to send command %s before registering", command); |
468
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
197 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
|
198 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
|
199 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
|
200 if commands[command] then |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
201 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
|
202 if ret then |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
203 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
|
204 end |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
205 else |
468
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
206 session.send{from=muc_server, "421", session.nick, command, "Unknown command"}; |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
207 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
|
208 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
|
209 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
|
210 function session.send(data) |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
211 if type(data) == "string" then |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
212 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
|
213 elseif type(data) == "table" then |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
214 local line = build_line(data); |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
215 module:log("debug", line); |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
216 conn:write(line.."\r\n"); |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
217 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
|
218 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
|
219 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
|
220 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
|
221 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
|
222 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
|
223 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
|
224 |
3de60860adca
mod_ircd: Initial commit of a wonderfully hacky but working IRC->XMPP interface for Prosody
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
225 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
|
226 local session = sessions[conn]; |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
227 if session then |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
228 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
|
229 room:leave("Disconnected"); |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
230 end |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
231 if session.nick then |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
232 nicks[session.nick] = nil; |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
233 end |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
234 if session.full_jid then |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
235 jids[session.full_jid] = nil; |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
236 end |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
237 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
|
238 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
|
239 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
|
240 |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
241 function commands.NICK(session, args) |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
242 if session.nick then |
468
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
243 session.send{from = muc_server, "484", "*", nick, "I'm afraid I can't let you do that"}; |
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 --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
|
245 return; |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
246 end |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
247 local nick = args[1]; |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
248 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
|
249 if nicks[nick] then |
468
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
250 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
|
251 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
|
252 end |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
253 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
|
254 jids[full_jid] = session; |
470
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
255 jids[full_jid]["ar_last"] = {}; |
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
|
256 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
|
257 session.nick = nick; |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
258 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
|
259 session.type = "c2s"; |
470
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
260 |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
261 session.send{from = muc_server, "001", nick, "Welcome in the IRC to MUC XMPP Gateway, "..nick}; |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
262 session.send{from = muc_server, "002", nick, "Your host is "..muc_server.." running Prosody "..prosody.version}; |
472
f3bd98f3a3f8
mod_ircd: Toxic MattJ's artifact removed.
Marco Cirillo <maranda@lightwitch.org>
parents:
471
diff
changeset
|
263 session.send{from = muc_server, "003", nick, "This server was created the "..os.date(nil, prosody.start_time)} |
471
fffac0eef024
mod_ircd: adjusted quirk in the banner I missed.
Marco Cirillo <maranda@lightwitch.org>
parents:
470
diff
changeset
|
264 session.send{from = muc_server, "004", nick, table.concat({muc_server, "mod_ircd(alpha-0.8)", "i", "aoqv"}, " ")}; |
470
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
265 session.send{from = muc_server, "375", nick, "- "..muc_server.." Message of the day -"}; |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
266 session.send{from = muc_server, "372", nick, "-"}; |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
267 session.send{from = muc_server, "372", nick, "- Please be warned that this is only a partial irc implementation,"}; |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
268 session.send{from = muc_server, "372", nick, "- it's made to facilitate users transiting away from irc to XMPP."}; |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
269 session.send{from = muc_server, "372", nick, "-"}; |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
270 session.send{from = muc_server, "372", nick, "- Prosody is _NOT_ an IRC Server and it never will."}; |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
271 session.send{from = muc_server, "372", nick, "- We also would like to remind you that this plugin is provided as is,"}; |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
272 session.send{from = muc_server, "372", nick, "- it's still an Alpha and it's still a work in progress, use it at your sole"}; |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
273 session.send{from = muc_server, "372", nick, "- risk as there's a not so little chance something will break."}; |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
274 |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
275 session.send{from = nick, "MODE", nick, "+i"}; -- why -> Invisible mode setting, |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
276 -- enforce by default on most servers (since the source host doesn't show it's sensible to have it "set") |
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
|
277 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
|
278 |
329 | 279 function commands.USER(session, params) |
280 -- FIXME | |
281 -- Empty command for now | |
282 end | |
283 | |
470
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
284 local function mode_map(am, rm, nicks) |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
285 local rnick; |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
286 local c_modes; |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
287 c_modes = aff_modemap[am]..role_modemap[rm] |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
288 rnick = string.rep(nicks.." ", c_modes:len()) |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
289 if c_modes == "" then return nil, nil end |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
290 return c_modes, rnick |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
291 end |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
292 |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
293 function commands.JOIN(session, args) |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
294 local channel = args[1]; |
469
ff03a325aa41
mod_ircd: ignore JOIN without channel
Kim Alvefur <zash@zash.se>
parents:
468
diff
changeset
|
295 if not channel then return end |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
296 local room_jid = irc2muc(channel); |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
297 print(session.full_jid); |
470
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
298 if not jids[session.full_jid].ar_last[room_jid] then jids[session.full_jid].ar_last[room_jid] = {}; end |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
299 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
|
300 if not room then |
470
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
301 return ":"..muc_server.." ERR :Could not join room: "..err |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
302 end |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
303 session.rooms[channel] = room; |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
304 room.channel = channel; |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
305 room.session = session; |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
306 session.send{from=session.nick, "JOIN", channel}; |
470
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
307 if room.subject then |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
308 session.send{from=muc_server, 332, session.nick, channel ,room.subject}; |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
309 end |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
310 commands.NAMES(session, channel); |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
311 |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
312 room:hook("subject-changed", function(changed) |
482
9d62586e7aae
mod_ircd: hacked around it to make it "work" again, topics should be operational once again.
Marco Cirillo <maranda@lightwitch.org>
parents:
473
diff
changeset
|
313 session.send((":%s TOPIC %s :%s"):format(changed.by.nick, channel, changed.to or "")); |
470
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
314 end); |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
315 |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
316 room:hook("message", function(event) |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
317 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
|
318 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
|
319 if nick ~= session.nick then |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
320 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
|
321 body = "\1ACTION ".. body:sub(5) .. "\1" |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
322 end |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
323 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
|
324 session.send{from=nick, "PRIVMSG", type == "groupchat" and channel or nick, body}; |
329 | 325 --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
|
326 end |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
327 end); |
470
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
328 |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
329 room:hook("presence", function(ar) |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
330 local c_modes; |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
331 local rnick; |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
332 if ar.nick and not jids[session.full_jid].ar_last[ar.room_jid][ar.nick] then jids[session.full_jid].ar_last[ar.room_jid][ar.nick] = {} end |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
333 local x_ar = ar.stanza:get_child("x", "http://jabber.org/protocol/muc#user") |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
334 if x_ar then |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
335 local xar_item = x_ar:get_child("item") |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
336 if xar_item and xar_item.attr and ar.stanza.attr.type ~= "unavailable" then |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
337 if xar_item.attr.affiliation and xar_item.attr.role then |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
338 if not jids[session.full_jid].ar_last[ar.room_jid][ar.nick]["affiliation"] and |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
339 not jids[session.full_jid].ar_last[ar.room_jid][ar.nick]["role"] then |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
340 jids[session.full_jid].ar_last[ar.room_jid][ar.nick]["affiliation"] = xar_item.attr.affiliation |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
341 jids[session.full_jid].ar_last[ar.room_jid][ar.nick]["role"] = xar_item.attr.role |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
342 c_modes, rnick = mode_map(xar_item.attr.affiliation, xar_item.attr.role, ar.nick); |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
343 if c_modes and rnick then session.send((":%s MODE %s +%s"):format(muc_server, channel, c_modes.." "..rnick)); end |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
344 else |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
345 c_modes, rnick = mode_map(jids[session.full_jid].ar_last[ar.room_jid][ar.nick]["affiliation"], jids[session.full_jid].ar_last[ar.room_jid][ar.nick]["role"], ar.nick); |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
346 if c_modes and rnick then session.send((":%s MODE %s -%s"):format(muc_server, channel, c_modes.." "..rnick)); end |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
347 jids[session.full_jid].ar_last[ar.room_jid][ar.nick]["affiliation"] = xar_item.attr.affiliation |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
348 jids[session.full_jid].ar_last[ar.room_jid][ar.nick]["role"] = xar_item.attr.role |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
349 c_modes, rnick = mode_map(xar_item.attr.affiliation, xar_item.attr.role, ar.nick); |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
350 if c_modes and rnick then session.send((":%s MODE %s +%s"):format(muc_server, channel, c_modes.." "..rnick)); end |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
351 end |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
352 end |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
353 end |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
354 end |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
355 end, -1); |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
356 end |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
357 |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
358 c:hook("groupchat/joined", function(room) |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
359 local session = room.session or jids[room.opts.source]; |
470
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
360 local channel = "#"..room.jid:match("^(.*)@"); |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
361 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
|
362 if room.topic then |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
363 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
|
364 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
|
365 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
|
366 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
|
367 session.send{from=nick.nick.."!"..nick.nick, "JOIN", channel}; |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
368 end); |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
369 room:hook("occupant-left", function(nick) |
473
99b246b37809
mod_ircd: fixed aff/roles last data table cleaning code.
Marco Cirillo <maranda@lightwitch.org>
parents:
472
diff
changeset
|
370 jids[session.full_jid].ar_last[nick.jid:match("^(.*)/")][nick.nick] = nil; -- ugly |
470
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
371 session.send{from=nick.nick.."!"..nick.nick, "PART", channel}; |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
372 end); |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
373 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
|
374 |
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
|
375 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
|
376 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
|
377 local room = session.rooms[channel]; |
470
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
378 local symbols_map = { |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
379 owner = "~", |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
380 administrator = "&", |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
381 moderator = "@", |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
382 member = "+" |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
383 } |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
384 |
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
|
385 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
|
386 -- 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
|
387 for nick, n in pairs(room.occupants) do |
470
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
388 if n.affiliation == "owner" and n.role == "moderator" then |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
389 nick = symbols_map[n.affiliation]..nick; |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
390 elseif n.affiliation == "administrator" and n.role == "moderator" then |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
391 nick = symbols_map[n.affiliation]..nick; |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
392 elseif n.affiliation == "member" and n.role == "moderator" then |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
393 nick = symbols_map[n.role]..nick; |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
394 elseif n.affiliation == "member" and n.role == "partecipant" then |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
395 nick = symbols_map[n.affiliation]..nick; |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
396 elseif n.affiliation == "none" and n.role == "moderator" then |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
397 nick = symbols_map[n.role]..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
|
398 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
|
399 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
|
400 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
|
401 nicks = table.concat(nicks, " "); |
470
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
402 session.send((":%s 353 %s = %s :%s"):format(muc_server, session.nick, channel, nicks)); |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
403 session.send((":%s 366 %s %s :End of /NAMES list."):format(muc_server, session.nick, channel)); |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
404 session.send(":"..muc_server.." 353 "..session.nick.." = "..channel.." :"..nicks); |
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
|
405 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
|
406 |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
407 function commands.PART(session, args) |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
408 local channel, part_message = unpack(args); |
470
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
409 local room = channel and nodeprep(channel:match("^#(%w+)")) or nil; |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
410 if not room then return end |
132
d4ff1cd414e5
mod_ircd: Add PING command / Echo PART back
Florian Zeitz <florob@babelmonkeys.de>
parents:
111
diff
changeset
|
411 channel = channel:match("^([%S]*)"); |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
412 session.rooms[channel]:leave(part_message); |
470
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
413 jids[session.full_jid].ar_last[room.."@"..muc_server] = nil; |
132
d4ff1cd414e5
mod_ircd: Add PING command / Echo PART back
Florian Zeitz <florob@babelmonkeys.de>
parents:
111
diff
changeset
|
414 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
|
415 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
|
416 |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
417 function commands.PRIVMSG(session, args) |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
418 local channel, message = unpack(args); |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
419 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
|
420 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
|
421 message = "/me ".. message:sub(9,-2) |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
422 end |
468
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
423 message = utf8_clean(message); |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
424 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
|
425 if session.rooms[channel] then |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
426 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
|
427 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
|
428 end |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
429 else -- private message |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
430 local nick = channel; |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
431 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
|
432 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
|
433 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
|
434 if room.occupants[nick] then |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
435 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
|
436 local who = room.occupants[nick]; |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
437 -- FIXME PMs in verse |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
438 --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
|
439 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
|
440 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
|
441 room:send(pm) |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
442 break |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
443 end |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
444 end |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
445 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
|
446 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
|
447 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
|
448 |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
449 function commands.PING(session, args) |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
450 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
|
451 end |
d4ff1cd414e5
mod_ircd: Add PING command / Echo PART back
Florian Zeitz <florob@babelmonkeys.de>
parents:
111
diff
changeset
|
452 |
470
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
453 function commands.TOPIC(session, message) |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
454 if not message then return end |
483
f4ada087c743
mod_ircd: added listener port configuration, added utf8 checks to TOPIC, added check so that module wonn't get loaded if conference_server is unset.
Marco Cirillo <maranda@lightwitch.org>
parents:
482
diff
changeset
|
455 local channel, topic = message[1], message[2]; |
f4ada087c743
mod_ircd: added listener port configuration, added utf8 checks to TOPIC, added check so that module wonn't get loaded if conference_server is unset.
Marco Cirillo <maranda@lightwitch.org>
parents:
482
diff
changeset
|
456 channel = utf8_clean(channel); |
f4ada087c743
mod_ircd: added listener port configuration, added utf8 checks to TOPIC, added check so that module wonn't get loaded if conference_server is unset.
Marco Cirillo <maranda@lightwitch.org>
parents:
482
diff
changeset
|
457 topic = utf8_clean(topic); |
470
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
458 if not channel then return end |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
459 local room = session.rooms[channel]; |
482
9d62586e7aae
mod_ircd: hacked around it to make it "work" again, topics should be operational once again.
Marco Cirillo <maranda@lightwitch.org>
parents:
473
diff
changeset
|
460 |
485
f8cc2be7e16a
mod_ircd: removed role check.
Marco Cirillo <maranda@lightwitch.org>
parents:
484
diff
changeset
|
461 if topic then room:set_subject(topic); end |
470
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
462 end |
4f9224369e69
mod_ircd: merged in various changes including -- code to propagate aff/role changes as modes, topic hooks/command, scarecrow motd banner, default port.
Marco Cirillo <maranda@lightwitch.org>
parents:
469
diff
changeset
|
463 |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
464 function commands.WHO(session, args) |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
465 local channel = args[1]; |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
466 if session.rooms[channel] then |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
467 local room = session.rooms[channel] |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
468 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
|
469 --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
|
470 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
|
471 end |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
472 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
|
473 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
|
474 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
|
475 |
468
640e6c0b563d
mod_ircd: Scrub invalid UTF-8 sequences, welcome message
Kim Alvefur <zash@zash.se>
parents:
466
diff
changeset
|
476 function commands.MODE(session, args) -- FIXME |
472
f3bd98f3a3f8
mod_ircd: Toxic MattJ's artifact removed.
Marco Cirillo <maranda@lightwitch.org>
parents:
471
diff
changeset
|
477 -- emptied for the time being, until something sane which works is available. |
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
|
478 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
|
479 |
466
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
480 function commands.QUIT(session, args) |
0fcd34ee7301
mod_ircd: Proper line parsing and generating. Fix PMs
Kim Alvefur <zash@zash.se>
parents:
465
diff
changeset
|
481 session.send{"ERROR", "Closing Link: "..session.nick}; |
329 | 482 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
|
483 room:leave(args[1]); |
329 | 484 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
|
485 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
|
486 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
|
487 sessions[session.conn] = nil; |
329 | 488 session:close(); |
489 end | |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
490 |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
491 function commands.RAW(session, data) |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
492 --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
|
493 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
|
494 |
465
030404dd7609
mod_ircd: Better nameing, squishy.
Kim Alvefur <zash@zash.se>
parents:
461
diff
changeset
|
495 local function desetup() |
030404dd7609
mod_ircd: Better nameing, squishy.
Kim Alvefur <zash@zash.se>
parents:
461
diff
changeset
|
496 require "net.connlisteners".deregister("irc"); |
030404dd7609
mod_ircd: Better nameing, squishy.
Kim Alvefur <zash@zash.se>
parents:
461
diff
changeset
|
497 end |
030404dd7609
mod_ircd: Better nameing, squishy.
Kim Alvefur <zash@zash.se>
parents:
461
diff
changeset
|
498 |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
499 --c:hook("ready", function () |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
500 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
|
501 require "net.connlisteners".start("irc"); |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
502 --end); |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
503 |
465
030404dd7609
mod_ircd: Better nameing, squishy.
Kim Alvefur <zash@zash.se>
parents:
461
diff
changeset
|
504 module:hook("module-unloaded", desetup) |
030404dd7609
mod_ircd: Better nameing, squishy.
Kim Alvefur <zash@zash.se>
parents:
461
diff
changeset
|
505 |
030404dd7609
mod_ircd: Better nameing, squishy.
Kim Alvefur <zash@zash.se>
parents:
461
diff
changeset
|
506 |
326
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
507 --print("Starting loop...") |
282abba844e8
mod_ircd: Partial rewrite, use verse for MUC
Kim Alvefur <zash@zash.se>
parents:
282
diff
changeset
|
508 --verse.loop() |