Mercurial > prosody-modules
comparison mod_ircd/mod_ircd.in.lua @ 503:db32236d7682
mod_ircd: some cleanup.
| author | Marco Cirillo <maranda@lightwitch.org> |
|---|---|
| date | Sun, 11 Dec 2011 18:51:57 +0000 |
| parents | 30e33292d738 |
| children | de64963d8e7a |
comparison
equal
deleted
inserted
replaced
| 502:aad0b2df9e6b | 503:db32236d7682 |
|---|---|
| 20 | 20 |
| 21 package.loaded["util.sha1"] = require "util.encodings"; | 21 package.loaded["util.sha1"] = require "util.encodings"; |
| 22 local verse = require "verse" | 22 local verse = require "verse" |
| 23 require "verse.component" | 23 require "verse.component" |
| 24 require "socket" | 24 require "socket" |
| 25 c = verse.new(); | 25 c = verse.new(); -- something interferes with prosody's console logging |
| 26 c:add_plugin("groupchat"); | 26 c:add_plugin("groupchat"); |
| 27 | 27 |
| 28 local function verse2prosody(e) | 28 local function verse2prosody(e) |
| 29 return c:event("stanza", e.stanza) or true; | 29 return c:event("stanza", e.stanza) or true; |
| 30 end | 30 end |
| 250 jids[full_jid]["nicks_changing"] = {}; | 250 jids[full_jid]["nicks_changing"] = {}; |
| 251 | 251 |
| 252 if session.nick then nicks[session.nick] = session; end | 252 if session.nick then nicks[session.nick] = session; end |
| 253 end | 253 end |
| 254 local function send_motd(session) | 254 local function send_motd(session) |
| 255 local nick = session.nick; | 255 local nick = session.nick; |
| 256 | 256 |
| 257 if session.username and session.nick then -- send MOTD only if username and nick are set | 257 if session.username and session.nick then -- send MOTD only if username and nick are set |
| 258 session.send{from = muc_server, "001", nick, "Welcome in the IRC to MUC XMPP Gateway, "..nick}; | 258 session.send{from = muc_server, "001", nick, "Welcome in the IRC to MUC XMPP Gateway, "..nick}; |
| 259 session.send{from = muc_server, "002", nick, "Your host is "..muc_server.." running Prosody "..prosody.version}; | 259 session.send{from = muc_server, "002", nick, "Your host is "..muc_server.." running Prosody "..prosody.version}; |
| 260 session.send{from = muc_server, "003", nick, "This server was created the "..os.date(nil, prosody.start_time)} | 260 session.send{from = muc_server, "003", nick, "This server was created the "..os.date(nil, prosody.start_time)} |
| 261 session.send{from = muc_server, "004", nick, table.concat({muc_server, "mod_ircd(alpha-0.8)", "i", "aoqv"}, " ")}; | 261 session.send{from = muc_server, "004", nick, table.concat({muc_server, "mod_ircd(alpha-0.8)", "i", "aoqv"}, " ")}; |
| 262 session.send((":%s %s %s %s :%s"):format(muc_server, "005", nick, "CHANTYPES=# PREFIX=(qaov)~&@+", "are supported by this server")); | 262 session.send((":%s %s %s %s :%s"):format(muc_server, "005", nick, "CHANTYPES=# PREFIX=(qaov)~&@+", "are supported by this server")); |
| 263 session.send((":%s %s %s %s :%s"):format(muc_server, "005", nick, "STATUSMSG=~&@+", "are supported by this server")); | 263 session.send((":%s %s %s %s :%s"):format(muc_server, "005", nick, "STATUSMSG=~&@+", "are supported by this server")); |
| 264 session.send{from = muc_server, "375", nick, "- "..muc_server.." Message of the day -"}; | 264 session.send{from = muc_server, "375", nick, "- "..muc_server.." Message of the day -"}; |
| 265 session.send{from = muc_server, "372", nick, "-"}; | 265 session.send{from = muc_server, "372", nick, "-"}; |
| 266 session.send{from = muc_server, "372", nick, "- Please be warned that this is only a partial irc implementation,"}; | 266 session.send{from = muc_server, "372", nick, "- Please be warned that this is only a partial irc implementation,"}; |
| 267 session.send{from = muc_server, "372", nick, "- it's made to facilitate users transiting away from irc to XMPP."}; | 267 session.send{from = muc_server, "372", nick, "- it's made to facilitate users transiting away from irc to XMPP."}; |
| 268 session.send{from = muc_server, "372", nick, "-"}; | 268 session.send{from = muc_server, "372", nick, "-"}; |
| 269 session.send{from = muc_server, "372", nick, "- Prosody is _NOT_ an IRC Server and it never will."}; | 269 session.send{from = muc_server, "372", nick, "- Prosody is _NOT_ an IRC Server and it never will."}; |
| 270 session.send{from = muc_server, "372", nick, "- We also would like to remind you that this plugin is provided as is,"}; | 270 session.send{from = muc_server, "372", nick, "- We also would like to remind you that this plugin is provided as is,"}; |
| 271 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"}; | 271 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"}; |
| 272 session.send{from = muc_server, "372", nick, "- risk as there's a not so little chance something will break."}; | 272 session.send{from = muc_server, "372", nick, "- risk as there's a not so little chance something will break."}; |
| 273 session.send{from = nick, "MODE", nick, "+i"}; -- why -> Invisible mode setting, | 273 session.send{from = nick, "MODE", nick, "+i"}; -- why -> Invisible mode setting, |
| 274 end -- enforce by default on most servers (since the source host doesn't show it's sensible to have it "set") | 274 end -- enforce by default on most servers (since the source host doesn't show it's sensible to have it "set") |
| 275 end | 275 end |
| 276 | 276 |
| 277 function commands.NICK(session, args) | 277 function commands.NICK(session, args) |
| 278 local nick = args[1]; | 278 local nick = args[1]; |
| 279 nick = nick:gsub("[^%w_]",""); | 279 nick = nick:gsub("[^%w_]",""); |
| 288 | 288 |
| 289 session.send{from=oldnick.."!"..nicks[nick].username, "NICK", nick}; | 289 session.send{from=oldnick.."!"..nicks[nick].username, "NICK", nick}; |
| 290 | 290 |
| 291 -- broadcast changes if required | 291 -- broadcast changes if required |
| 292 if session.rooms then | 292 if session.rooms then |
| 293 session.nicks_changing[nick] = { oldnick, session.username }; | 293 session.nicks_changing[nick] = { oldnick, session.username }; |
| 294 | 294 |
| 295 for id, room in pairs(session.rooms) do room:change_nick(nick); end | 295 for id, room in pairs(session.rooms) do room:change_nick(nick); end |
| 296 | 296 |
| 297 session.nicks_changing[nick] = nil; | 297 session.nicks_changing[nick] = nil; |
| 298 end | 298 end |
| 299 | 299 |
| 309 -- Some choppy clients send in NICK before USER, that needs to be handled | 309 -- Some choppy clients send in NICK before USER, that needs to be handled |
| 310 if session.username then | 310 if session.username then |
| 311 set_t_data(session, jid.join(session.username, component_jid, "ircd")); | 311 set_t_data(session, jid.join(session.username, component_jid, "ircd")); |
| 312 end | 312 end |
| 313 | 313 |
| 314 send_motd(session); | 314 send_motd(session); |
| 315 end | 315 end |
| 316 | 316 |
| 317 function commands.USER(session, params) | 317 function commands.USER(session, params) |
| 318 local username = params[1]; | 318 local username = params[1]; |
| 319 | 319 |
| 329 end | 329 end |
| 330 else | 330 else |
| 331 return session.send{from=muc_server, "462", "USER", "You may not re-register."} | 331 return session.send{from=muc_server, "462", "USER", "You may not re-register."} |
| 332 end | 332 end |
| 333 | 333 |
| 334 send_motd(session); | 334 send_motd(session); |
| 335 end | 335 end |
| 336 | 336 |
| 337 function commands.USERHOST(session, params) -- can show only users on the gateway. Needed for some clients to determinate self hostmask. | 337 function commands.USERHOST(session, params) -- can show only users on the gateway. Needed for some clients to determinate self hostmask. |
| 338 local nick = params[1]; | 338 local nick = params[1]; |
| 339 | 339 |
| 340 if not nick then session.send{from=muc_server, "461", "USERHOST", "Not enough parameters"}; return; end | 340 if not nick then session.send{from=muc_server, "461", "USERHOST", "Not enough parameters"}; return; end |
| 341 | 341 |
| 342 if nicks[nick] and nicks[nick].nick and nicks[nick].username then | 342 if nicks[nick] and nicks[nick].nick and nicks[nick].username then |
| 343 session.send{from=muc_server, "302", session.nick, nick.."=+"..nicks[nick].username}; return; | 343 session.send{from=muc_server, "302", session.nick, nick.."=+"..nicks[nick].username}; return; |
| 344 else | 344 else |
| 345 return; | 345 return; |
| 346 end | 346 end |
| 347 end | 347 end |
| 348 | 348 |
| 349 local function mode_map(am, rm, nicks) | 349 local function mode_map(am, rm, nicks) |
| 350 local rnick; | 350 local rnick; |
| 351 local c_modes; | 351 local c_modes; |
| 378 end | 378 end |
| 379 commands.NAMES(session, channel); | 379 commands.NAMES(session, channel); |
| 380 end | 380 end |
| 381 | 381 |
| 382 room:hook("subject-changed", function(changed) | 382 room:hook("subject-changed", function(changed) |
| 383 session.send((":%s TOPIC %s :%s"):format(changed.by.nick, channel, changed.to or "")); | 383 session.send{from=changed.by.nick, "TOPIC", channel, changed.to or ""} |
| 384 end); | 384 end); |
| 385 | 385 |
| 386 room:hook("message", function(event) | 386 room:hook("message", function(event) |
| 387 if not event.body then return end | 387 if not event.body then return end |
| 388 local nick, body = event.nick, event.body; | 388 local nick, body = event.nick, event.body; |
| 407 if xar_item.attr.affiliation and xar_item.attr.role then | 407 if xar_item.attr.affiliation and xar_item.attr.role then |
| 408 if not jids[session.full_jid].ar_last[ar.room_jid][ar.nick]["affiliation"] and | 408 if not jids[session.full_jid].ar_last[ar.room_jid][ar.nick]["affiliation"] and |
| 409 not jids[session.full_jid].ar_last[ar.room_jid][ar.nick]["role"] then | 409 not jids[session.full_jid].ar_last[ar.room_jid][ar.nick]["role"] then |
| 410 jids[session.full_jid].ar_last[ar.room_jid][ar.nick]["affiliation"] = xar_item.attr.affiliation | 410 jids[session.full_jid].ar_last[ar.room_jid][ar.nick]["affiliation"] = xar_item.attr.affiliation |
| 411 jids[session.full_jid].ar_last[ar.room_jid][ar.nick]["role"] = xar_item.attr.role | 411 jids[session.full_jid].ar_last[ar.room_jid][ar.nick]["role"] = xar_item.attr.role |
| 412 n_self_changing = nicks[ar.nick] and nicks[ar.nick].nicks_changing and nicks[ar.nick].nicks_changing[ar.nick] | 412 n_self_changing = nicks[ar.nick] and nicks[ar.nick].nicks_changing and nicks[ar.nick].nicks_changing[ar.nick] |
| 413 if n_self_changing then return; end | 413 if n_self_changing then return; end |
| 414 c_modes, rnick = mode_map(xar_item.attr.affiliation, xar_item.attr.role, ar.nick); | 414 c_modes, rnick = mode_map(xar_item.attr.affiliation, xar_item.attr.role, ar.nick); |
| 415 if c_modes and rnick then session.send((":%s MODE %s +%s"):format(muc_server, channel, c_modes.." "..rnick)); end | 415 if c_modes and rnick then session.send((":%s MODE %s +%s"):format(muc_server, channel, c_modes.." "..rnick)); end |
| 416 else | 416 else |
| 417 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); | 417 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); |
| 418 if c_modes and rnick then session.send((":%s MODE %s -%s"):format(muc_server, channel, c_modes.." "..rnick)); end | 418 if c_modes and rnick then session.send((":%s MODE %s -%s"):format(muc_server, channel, c_modes.." "..rnick)); end |
| 419 jids[session.full_jid].ar_last[ar.room_jid][ar.nick]["affiliation"] = xar_item.attr.affiliation | 419 jids[session.full_jid].ar_last[ar.room_jid][ar.nick]["affiliation"] = xar_item.attr.affiliation |
| 420 jids[session.full_jid].ar_last[ar.room_jid][ar.nick]["role"] = xar_item.attr.role | 420 jids[session.full_jid].ar_last[ar.room_jid][ar.nick]["role"] = xar_item.attr.role |
| 421 n_self_changing = nicks[ar.nick] and nicks[ar.nick].nicks_changing and nicks[ar.nick].nicks_changing[ar.nick] | 421 n_self_changing = nicks[ar.nick] and nicks[ar.nick].nicks_changing and nicks[ar.nick].nicks_changing[ar.nick] |
| 422 if n_self_changing then return; end | 422 if n_self_changing then return; end |
| 423 c_modes, rnick = mode_map(xar_item.attr.affiliation, xar_item.attr.role, ar.nick); | 423 c_modes, rnick = mode_map(xar_item.attr.affiliation, xar_item.attr.role, ar.nick); |
| 424 if c_modes and rnick then session.send((":%s MODE %s +%s"):format(muc_server, channel, c_modes.." "..rnick)); end | 424 if c_modes and rnick then session.send((":%s MODE %s +%s"):format(muc_server, channel, c_modes.." "..rnick)); end |
| 425 end | 425 end |
| 426 end | 426 end |
| 427 end | 427 end |
| 505 local room = channel and nodeprep(channel:match("^#(%w+)")) or nil; | 505 local room = channel and nodeprep(channel:match("^#(%w+)")) or nil; |
| 506 if not room then return end | 506 if not room then return end |
| 507 channel = channel:match("^([%S]*)"); | 507 channel = channel:match("^([%S]*)"); |
| 508 session.rooms[channel]:leave(part_message); | 508 session.rooms[channel]:leave(part_message); |
| 509 jids[session.full_jid].ar_last[room.."@"..muc_server] = nil; | 509 jids[session.full_jid].ar_last[room.."@"..muc_server] = nil; |
| 510 session.send(":"..session.nick.." PART :"..channel); | 510 session.send{from=session.nick.."!"..session.username, "PART", channel}; |
| 511 end | 511 end |
| 512 | 512 |
| 513 function commands.PRIVMSG(session, args) | 513 function commands.PRIVMSG(session, args) |
| 514 local channel, message = unpack(args); | 514 local channel, message = unpack(args); |
| 515 if message and #message > 0 then | 515 if message and #message > 0 then |
