Class: IRCd::IRCServer
- Inherits:
-
WEBrick::GenericServer
- Object
- WEBrick::GenericServer
- IRCd::IRCServer
- Defined in:
- lib/rupircd/server.rb
Constant Summary
Constants included from Command
Constants included from Reply
Class Method Summary collapse
Instance Method Summary collapse
- #channel(chname) ⇒ Object
- #class_for_chname(chname) ⇒ Object
- #handle_reply(user, rpl) ⇒ Object
- #init ⇒ Object
-
#initialize(fconf, *args) ⇒ IRCServer
constructor
A new instance of IRCServer.
- #on_away(user, params) ⇒ Object
- #on_info(user, params) ⇒ Object
- #on_invite(user, params) ⇒ Object
- #on_ison(user, params) ⇒ Object
- #on_join(user, params) ⇒ Object
- #on_kick(user, params) ⇒ Object
- #on_links(user, params) ⇒ Object
- #on_list(user, params) ⇒ Object
- #on_lusers(user, params) ⇒ Object
- #on_mode(user, params) ⇒ Object
- #on_motd(user, params) ⇒ Object
- #on_names(user, params) ⇒ Object
- #on_nick(user, params) ⇒ Object
- #on_notice(user, params) ⇒ Object
- #on_oper(user, params) ⇒ Object
- #on_part(user, params) ⇒ Object
- #on_pass(user, params) ⇒ Object
- #on_ping(user, params) ⇒ Object
- #on_pong(user, params) ⇒ Object
- #on_privmsg(user, params) ⇒ Object
- #on_quit(user, params) ⇒ Object
- #on_stats(user, params) ⇒ Object
- #on_time(user, params) ⇒ Object
- #on_topic(user, params) ⇒ Object
- #on_user(user, params) ⇒ Object
- #on_userhost(user, params) ⇒ Object
- #on_version(user, params) ⇒ Object
- #on_who(user, params) ⇒ Object
- #on_whois(user, params) ⇒ Object
- #on_whowas(user, params) ⇒ Object
- #print_motd(user) ⇒ Object
- #puts_socket(user, *args) ⇒ Object
- #recv_message(user, line) ⇒ Object
- #run(socket) ⇒ Object
- #send_client_message(to, from, cmd, *args) ⇒ Object
- #send_message(to, from, msg, *args) ⇒ Object
- #send_server_message(to, msg, *args) ⇒ Object
- #set_channel(cn, val) ⇒ Object
- #start(*args) ⇒ Object
- #start_ping(user) ⇒ Object
- #unregister(user, msg = "EOF From client") ⇒ Object
- #user_from_nick(nick) ⇒ Object
Methods included from Utils
#channame?, #correct_nick?, #mask_to_regex
Constructor Details
#initialize(fconf, *args) ⇒ IRCServer
Returns a new instance of IRCServer.
47 48 49 50 51 52 53 |
# File 'lib/rupircd/server.rb', line 47 def initialize(fconf, *args) @_init_args = [fconf, *args] @fconf = fconf super(fconf.load, *args) @used = Hash.new{|h, k| h[k.upcase] = [0,0,0]} init end |
Class Method Details
.define_oper_command(mtd, &pr) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/rupircd/server.rb', line 35 def define_oper_command(mtd, &pr) define_method(mtd){|usr, param| if usr.operator || usr.local_operator instance_exec(usr, param, &pr) else (usr, "481", "Permission Denied - You're not an IRC operator") end } end |
Instance Method Details
#channel(chname) ⇒ Object
740 741 742 |
# File 'lib/rupircd/server.rb', line 740 def channel(chname) @channels[chname.downcase] end |
#class_for_chname(chname) ⇒ Object
283 284 285 |
# File 'lib/rupircd/server.rb', line 283 def class_for_chname(chname) # overridden in sub-classes end |
#handle_reply(user, rpl) ⇒ Object
692 693 694 695 696 697 698 699 700 701 702 703 704 |
# File 'lib/rupircd/server.rb', line 692 def handle_reply(user, rpl) return unless rpl case rpl[0] when Array rpl.each{|rp| handle_reply(user, rp) } when Command (user, user, *rpl) else (user, *rpl) end end |
#init ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/rupircd/server.rb', line 55 def init @operators = [] @channels = {} @users = [] @users.extend(MonitorMixin) @ping_threads = {} @ping_threads.extend(MonitorMixin) @old_nicks = Hash.new{|h, k| h[k] = []} config.replace(@fconf.load) cf = {} config.fetch(:Opers,{}).each{|nick, pass| cf[mask_to_regex(nick)] = pass } config[:Opers] = cf config[:ServerName] = "127.0.0.1" end |
#on_away(user, params) ⇒ Object
482 483 484 485 486 487 488 489 490 |
# File 'lib/rupircd/server.rb', line 482 def on_away(user, params) if params.empty? || params[0].empty? user.away = "" (user, "305", "You are no longer marked as being away") else user.away = params.shift (user, "306", "You have been marked as being away") end end |
#on_info(user, params) ⇒ Object
342 343 344 345 346 347 348 |
# File 'lib/rupircd/server.rb', line 342 def on_info(user, params) config[:Info].each_line{|line| line.chomp! (user, "371", line) } (user, "374", "End of INFO list") end |
#on_invite(user, params) ⇒ Object
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 |
# File 'lib/rupircd/server.rb', line 363 def on_invite(user, params) if params.size < 2 raise NotEnoughParameter else who, to = params if target = @users.find{|v| v.nick == who} if target.away? msg = target.away (user, "301", who, msg) return end if ch = channel(to) handle_reply(user, ch.invite(user, target)) else (user, "401", who, "No such nick/channel") end else (user, "401", who, "No such nick/channel") end end end |
#on_ison(user, params) ⇒ Object
664 665 666 667 668 |
# File 'lib/rupircd/server.rb', line 664 def on_ison(user, params) raise NotEnoughParameter if params.empty? a = params.find_all{|nick| @users.any?{|us| us.nick == nick}} (user, "303", a.join(" ")) end |
#on_join(user, params) ⇒ Object
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/rupircd/server.rb', line 287 def on_join(user, params) if params[0] == "0" user.joined_channels.each{|ch| channel(ch).part(user, "") } user.joined_channels = [] else chs = params[0].split(",") keys = params[1].split(",") if params.size >= 2 keys ||= [] chs.each_with_index{|ch, i| chclass = case ch when /^\+/ NoModeChannel when /^#/ Channel when /^!#/ SafeChannel else if klass = class_for_chname(ch) klass else (user, "403", ch, "No such channel") next end end unless @channels.has_key?(ch.downcase) set_channel(ch, chclass.new(self, user, ch) ) handle_reply(user, channel(ch).join(user, keys[i])) else rpl = channel(ch).join(user, keys[i]) handle_reply(user, rpl) end } end end |
#on_kick(user, params) ⇒ Object
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 |
# File 'lib/rupircd/server.rb', line 632 def on_kick(user, params) raise NotEnoughParameter if params.size < 2 chs = params[0].split(",") whos = params[1].split(",") msg = params[2].to_s if chs.size == 1 if ch = channel(chs[0]) whos.each{|who| if usr = @users.find{|us|us.nick==who} handle_reply user, ch.kick(usr, user, msg) else (user, "401", who, "No such nick/channel") end } else (user, "403", chs[0], "No such channel") end elsif chs.size == whos.size chs.each_with_index{|chn, i| if chn = channel(chn) if usr = user_from_nick[whos[i]] handle_reply user, ch.kick(usr, user, msg) else (user, "401", whos[i], "No such nick/channel") end else (user, "403", chn, "No such channel") end } end end |
#on_links(user, params) ⇒ Object
350 351 352 |
# File 'lib/rupircd/server.rb', line 350 def on_links(user, params) (user, "365") end |
#on_list(user, params) ⇒ Object
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 |
# File 'lib/rupircd/server.rb', line 385 def on_list(user, params) if params.empty? chs = @channels.find_all{|k, v| v.visible?(nil)} chs.each{|k, v| case (tpc = v.get_topic(user, true))[0] when "331" tpc = "" else tpc = tpc[-1] end (user, "322", k, v.members.size.to_s, tpc) } else chs = params[0].split(",").find_all{|name| channel(name) && channel(n).visible?(user)} chs.each{|k| v = channel(k) uss = v.members.find_all{|m| !m.invisible} case (tpc = v.get_topic(user, true))[0] when "331" tpc = "" else tpc = tpc[-1] end (user, "322", k, v.members.size.to_s, tpc) } end (user, "323", "End of LIST") end |
#on_lusers(user, params) ⇒ Object
197 198 199 200 201 202 203 204 205 206 |
# File 'lib/rupircd/server.rb', line 197 def on_lusers(user, params) (user, "251", "There are #{@users.size} users and 0 services on 1 servers") unless @operators.empty? (user, "252", @operators.size, "operator(s) online") end unless @channels.empty? (user, "254", @channels.size, "channels formed") end (user, "255", "I have #{@users.size} clients and 0 servers") end |
#on_mode(user, params) ⇒ Object
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 |
# File 'lib/rupircd/server.rb', line 492 def on_mode(user, params) if params.size < 1 raise NotEnoughParameter return end to = params.shift if ch = channel(to) handle_reply(user, ch.handle_mode(user, params)) elsif who = @users.find{|v| v.nick == to} if who == user if params.empty? (user, "221", who.get_mode_flags) else rls = who.set_flags(params[0]) (user, user, MODE, user.nick, rls.join(" ")) end else (user, "502", "Cannot change mode for other users") end else (user, "401", to, "No such nick/channel") end end |
#on_motd(user, params) ⇒ Object
184 185 186 |
# File 'lib/rupircd/server.rb', line 184 def on_motd(user, params) print_motd(user) end |
#on_names(user, params) ⇒ Object
452 453 454 455 456 457 458 459 460 461 |
# File 'lib/rupircd/server.rb', line 452 def on_names(user, params) if params.size < 1 raise NotEnoughParameter else chs = params[0].split(",") chs.each{|ch| handle_reply(user, channel(ch).names(user)) } end end |
#on_nick(user, params) ⇒ Object
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 |
# File 'lib/rupircd/server.rb', line 516 def on_nick(user, params) if params.empty? (user, "431", "No nickname given") else nick = params[0] if nick == "0" nick = user.identifier.to_s elsif !correct_nick?(nick) (user, "432", nick, "Erroneous nickname") return end if us = user_from_nick(nick) return if us == user (user, "433", nick, "Nickname is already in use") elsif user.restriction (user, "484", "Your connection is restricted!") else (user, user, NICK, nick) sent = [] user.joined_channels.each{|ch| ch.members.each{|mem| if !sent.include?(mem) && mem != user sent << mem (mem, user, NICK, nick) end } } @old_nicks[nick].unshift user.to_a user.nick = nick end end end |
#on_notice(user, params) ⇒ Object
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 |
# File 'lib/rupircd/server.rb', line 463 def on_notice(user, params) if params.size < 2 raise NotEnoughParameter return end to, msg = params if ch = channel(to) if msg.empty? (user, "412", "No text to send") else handle_reply(user, ch.notice(user, msg)) end elsif who = @users.find{|v| v.nick == to} (who, user, NOTICE, user.nick, msg) else (user, "401", to, "No such nick/channel") end end |
#on_oper(user, params) ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/rupircd/server.rb', line 208 def on_oper(user, params) raise NotEnoughParameter if params.size < 2 nick, pass = params unless opdic = config.fetch(:Opers,{}).find{|k, v| k =~ nick} (user, "491", "No O-lines for your host") return end if Digest::MD5.hexdigest(pass) == opdic[1] user.operator = true user.local_operator = true @operators.push user (user, "381", "You are now an IRC operator") else (user, "464", "Password incorrect") end end |
#on_part(user, params) ⇒ Object
324 325 326 327 328 329 330 331 332 333 334 335 336 |
# File 'lib/rupircd/server.rb', line 324 def on_part(user, params) ch, msg = params msg ||= "" chs = ch.split(",") chs.each{|chname| ch = channel(chname) ch.part(user, msg) if ch.members.empty? @channels.delete(chname.downcase) end user.joined_channels.delete(ch) } end |
#on_pass(user, params) ⇒ Object
553 554 555 |
# File 'lib/rupircd/server.rb', line 553 def on_pass(user, params) puts_socket(user, ERR_ALREADYREGISTRED.new(config[:ServerName], "462", [user.nick, "Unauthorized command (already registered)"])) end |
#on_ping(user, params) ⇒ Object
338 339 340 |
# File 'lib/rupircd/server.rb', line 338 def on_ping(user, params) (user, config[:ServerName], PONG, config[:ServerName], *params) end |
#on_pong(user, params) ⇒ Object
358 359 360 361 |
# File 'lib/rupircd/server.rb', line 358 def on_pong(user, params) @ping_threads[user].kill start_ping(user) end |
#on_privmsg(user, params) ⇒ Object
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 |
# File 'lib/rupircd/server.rb', line 429 def on_privmsg(user, params) if params.size < 2 raise NotEnoughParameter end to, msg = params if ch = channel(to) if msg.empty? (user, "412", "No text to send") else handle_reply(user, ch.privmsg(user, msg)) end elsif who = @users.find{|v| v.nick == to} if who.away? away = who.away (user, "301", to, away) else (who, user, PRIVMSG, who.nick, msg) end else (user, "401", to, "No such nick/channel") end end |
#on_quit(user, params) ⇒ Object
687 688 689 690 |
# File 'lib/rupircd/server.rb', line 687 def on_quit(user, params) (user, nil, ERROR, "Closing", "Link:", "#{user.nick}[#{user.user}@#{user.host}]", %Q!("#{params[0]}")!) unregister(user, params[0]) end |
#on_stats(user, params) ⇒ Object
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/rupircd/server.rb', line 255 def on_stats(user, params) if params.empty? raise NotEnoughParameter return end c = params[0][0] case c when ?l when ?m @used.each_pair{|cmd, val| (user, "212", cmd, val[0]) } when ?o when ?u vs = Time.now.to_i - @started.to_i days = vs / (3600*24) vs -= days * 3600 * 24 hours = vs / 3600 vs -= hours * 3600 minutes = vs/60 vs -= minutes * 60 (user, "242", format("Server Up %d days %d:%02d:%02d",days,hours,minutes,vs)) end (user, "219", c.chr, "End of STATS report") end |
#on_time(user, params) ⇒ Object
354 355 356 |
# File 'lib/rupircd/server.rb', line 354 def on_time(user, params) (user, "391", config[:ServerName], Time.now.to_s) end |
#on_topic(user, params) ⇒ Object
414 415 416 417 418 419 420 421 422 423 424 425 426 427 |
# File 'lib/rupircd/server.rb', line 414 def on_topic(user, params) chn, topic = params unless ch = channel(chn) (user, "403", chn, "No such channel") return end if params.size < 1 raise NotEnoughParameter elsif params.size == 1 (user, *ch.get_topic(user)) else handle_reply(user, ch.set_topic(user, topic)) end end |
#on_user(user, params) ⇒ Object
549 550 551 |
# File 'lib/rupircd/server.rb', line 549 def on_user(user, params) puts_socket(user, ERR_ALREADYREGISTRED.new(config[:ServerName], "462", [user.nick, "Unauthorized command (already registered)"])) end |
#on_userhost(user, params) ⇒ Object
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 |
# File 'lib/rupircd/server.rb', line 670 def on_userhost(user, params) raise NotEnoughParameter if params.empty? targs = params[0..4] targs.map!{|nick| if tg = @users.find{|u| u.nick == nick} suf = @operators.include?(tg.socket) ? "*" : "" pre = tg.away? ? "-" : "+" usr = tg.user host = tg.host nick + suf + "=" + pre + usr + "@" + host + " " else "" end } (user, "302", targs.join(" ")) end |
#on_version(user, params) ⇒ Object
251 252 253 |
# File 'lib/rupircd/server.rb', line 251 def on_version(user, params) (user, "351", "rupircd-#{VERSION} #{config[:ServerName]} :Ruby Pseudo IRCD 0.1b") end |
#on_who(user, params) ⇒ Object
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 |
# File 'lib/rupircd/server.rb', line 609 def on_who(user, params) raise NotEnoughParameter if params.empty? mask = mask_to_regex(params[0]) chs = @channels.find_all{|name, ch| name =~ mask && ch.visible?(user)} unless chs.empty? chs.each{|name, ch| ch.members.each{|usr| sym = usr.away? ? "G" : "H" sym += @operators.include?(usr) ? "*" : "" sym += ch.mode.op?(usr) ? "@" : (ch.mode.voiced?(usr) ? "+" : "") (user, "352", usr.name, usr.user, usr.host, config[:ServerName], usr.nick, sym, "0 #{real}") } (user, "315", name, "End of WHO list") } else usrs = @users.find_all{|us| us.nick =~ mask || us.user =~ mask || us.host =~ mask} usrs.each{|usr| (user, "352", "*", usr.user, usr.host, config[:ServerName], usr.nick, "H", "0 #{usr.real}") (user, "315", usr.nick, "End of WHO list") } end end |
#on_whois(user, params) ⇒ Object
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 |
# File 'lib/rupircd/server.rb', line 557 def on_whois(user, params) raise NotEnoughParameter if params.empty? params[0].split(",").each{|mask| reg = mask_to_regex(mask) matched = @users.find_all{|usr| usr.nick =~ reg} if matched.empty? (user, "401", mask, "No such nick/channel") else matched.each{|target| sc = target.socket (user, "311", target.nick, target.user, target.host, "*", target.real) (user, "312", target.nick, config[:ServerName], "this server.") (user, "313", target.nick, "is an IRC operator") if @operators.include?(target) chs = [] target.joined_channels.each{|ch| if ch.visible?(user) pr = "" if ch.mode.op?(target) pr = "@" else ch.mode.voiced?(target) pr = "+" end chs << pr+ch.name end } (user, "319", target.nick, chs.join(" ")) if target.away? away = target.away (user, "301", target.nick, away) end (user, "318", target.nick, "End of WHOIS list") } end } end |
#on_whowas(user, params) ⇒ Object
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 |
# File 'lib/rupircd/server.rb', line 593 def on_whowas(user, params) raise NotEnoughParameter if params.empty? params[0].split(",").each{|nick| if @users.any?{|us| us.nick == nick} (user, "312", nick, config[:ServerName], "this server.") elsif @old_nicks[nick].empty? (user, "406", nick, "There was no such nickname") else @old_nicks[nick].each{|nms| (user, "314", *nms) } end (user, "369", nick, "End of WHOWAS") } end |
#print_motd(user) ⇒ Object
188 189 190 191 192 193 194 195 |
# File 'lib/rupircd/server.rb', line 188 def print_motd(user) (user, "375", "- #{config[:ServerName]} Message of the day - ") config[:Motd].each_line{|line| line.chomp! (user, "372", "- " + line) } (user, "376", "End of MOTD command") end |
#puts_socket(user, *args) ⇒ Object
715 716 717 718 719 720 721 722 723 724 725 726 727 728 |
# File 'lib/rupircd/server.rb', line 715 def puts_socket(user, *args) user.socket.synchronize do if user.socket.closed? unregister(user, "Connection reset by peer") else begin args.map!{|a| a.to_s.encode config().fetch(:Encoding, "ISO-2022-JP")} user.socket.puts(*args) rescue Errno::EPIPE => e unregister(user, "Connection reset by peer") end end end end |
#recv_message(user, line) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/rupircd/server.rb', line 162 def (user, line) line.chomp! return if line.empty? begin msg = Message.parse(line) params = msg.params @used[msg.command.upcase][0] += 1 mtd = "on_" + msg.command.downcase if respond_to?(mtd) __send__(mtd, user, params) else raise UnknownCommand.new(msg.command) end rescue NotEnoughParameter => e (user, "461", msg.command, "Not enough parameters") rescue UnknownCommand => e (user, "421", e.cmd, "Unknown command") rescue puts $!, $@ end end |
#run(socket) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/rupircd/server.rb', line 85 def run(socket) socket.extend(MonitorMixin) user = nil nick = nil pass = nil begin first = true while line = socket.gets line.chomp! next if line.empty? case msg = Message.parse(line) when PASS if first pass = msg.params[-1] first = false else end when USER user = msg.params if msg.params.size < 4 socket.puts err_needmoreparams(msg.command, "Not enough parameters") user = nil end when NICK nick = msg.params[0] if us = @users.find{|us| us.nick == nick} socket.puts ERR_NICKNAMEINUSE.new(config[:ServerName], "433", [nick, "Nickname is already in use"]) nick = nil else end end break if nick && user end end return unless nick && user start_ping(user) begin host = Resolv.getname(socket.addr[-1]) rescue host = socket.addr[-1] end user = User.new(nick, "~"+user[0].split("@")[0], host, user[-1], socket, user[1]) @old_nicks[nick].unshift user.to_a @users << user (user, "001", "Welcome to the Internet Relay Network #{user}") (user, "002", "Your host is #{config[:ServerName]}, running version 0.1b") (user, "003", "This server was created #{Time.now}") (user, "004", "#{config[:ServerName]} 0.1b aiwroOs oavimnqsrtklObeI") print_motd(user) while !socket.closed? && line = socket.gets (user, line) end unregister(user) end |
#send_client_message(to, from, cmd, *args) ⇒ Object
730 731 732 733 |
# File 'lib/rupircd/server.rb', line 730 def (to, from, cmd, *args) msg = cmd.new(from.to_s, cmd.name.split('::').last, args) puts_socket(to, msg) end |
#send_message(to, from, msg, *args) ⇒ Object
706 707 708 709 710 711 712 713 |
# File 'lib/rupircd/server.rb', line 706 def (to, from, msg, *args) case msg when Command (to, from, msg, *args) when Reply (to, msg, *args) end end |
#send_server_message(to, msg, *args) ⇒ Object
735 736 737 738 |
# File 'lib/rupircd/server.rb', line 735 def (to, msg, *args) args.unshift to.nick puts_socket(to, Message.build(config[:ServerName], msg, args) ) end |
#set_channel(cn, val) ⇒ Object
744 745 746 |
# File 'lib/rupircd/server.rb', line 744 def set_channel(cn, val) @channels[cn.downcase] = val end |
#start(*args) ⇒ Object
748 749 750 751 |
# File 'lib/rupircd/server.rb', line 748 def start(*args) @started = Time.now super end |
#start_ping(user) ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/rupircd/server.rb', line 76 def start_ping(user) @ping_threads[user] = Thread.new{ sleep(config[:PINGInterval]) (user, nil, PING, config[:ServerName]) sleep(config[:PINGLimit]) unregister(user, "PING Timeout") } end |
#unregister(user, msg = "EOF From client") ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/rupircd/server.rb', line 140 def unregister(user, msg="EOF From client") synchronize do socket = user.socket @ping_threads[user].kill if @ping_threads.has_key?(socket) sent = [] if @users.include?(user) user.joined_channels.each{|ch| ch.unregister(user) ch.members.each{|mem| unless sent.include?(mem) sent << mem (mem, user, QUIT, msg) end } @channels.reject!{|k,v|v==ch} if ch.members.empty? } @users.delete(user) end end user.socket.close unless user.socket.closed? end |
#user_from_nick(nick) ⇒ Object
72 73 74 |
# File 'lib/rupircd/server.rb', line 72 def user_from_nick(nick) u = @users.find{|u| u.nick == nick} end |