/usr/share/nadoka/rice/irc.rb is in nadoka 0.7.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 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 282 283 284 285 286 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 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 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 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 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 548 549 550 551 552 553 554 555 556 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 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 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 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 | =begin
= rice - Ruby Irc interfaCE
Original Credit:
Original Id: irc.rb,v 1.9 2001/06/13 10:22:24 akira Exp
Copyright (c) 2001 akira yamada <akira@ruby-lang.org>
You can redistribute it and/or modify it under the same term as Ruby.
== Modified
Modified by K.Sasada.
$Id: irc.rb 230 2010-08-18 07:01:51Z znz $
=end
require 'socket'
require 'thread'
require 'monitor'
begin
require "openssl"
rescue LoadError
end
module RICE
class Error < StandardError; end
class InvalidMessage < Error; end
class UnknownCommand < Error; end
=begin
== RICE::Connection
=end
class Connection
class Error < StandardError; end
class Closed < Error; end
=begin
--- RICE::Connection::new
=end
def initialize(server, port, eol = "\r\n", ssl_params = nil)
@conn = []
@conn.extend(MonitorMixin)
@main_th = nil
self.server = server
self.port = port
self.eol = eol
self.ssl_params = ssl_params
@read_q = Queue.new
@read_th = Thread.new(@read_q, @eol) do |read_q, eol|
read_thread(read_q, eol)
end
@threads = {}
@threads.extend(MonitorMixin)
@dispatcher = Thread.new(@read_q) do |read_q|
loop do
x = read_q.pop
ths = @threads.synchronize do
@threads.keys
end
ths.each do |th|
if th.status
@threads[th].q.push(x)
else
@threads.delete(th)
end
end
end # loop
end
@delay = 0.3
@prev_send_time = Time.now
end
attr :delay, true
attr_reader :server, :port, :ssl_params
=begin
--- RICE::Connection#server=(server)
=end
def server=(server)
raise RuntimeError,
"Already connected to #{@server}:#{@port}" unless @conn.empty?
@server = server
end
=begin
--- RICE::Connection#port=(port)
=end
def port=(port)
raise RuntimeError,
"Already connected to #{@server}:#{@port}" unless @conn.empty?
@port = port
end
=begin
--- RICE::Connection#eol=(eol)
=end
def eol=(eol)
raise RuntimeError,
"Already connected to #{@server}:#{@port}" unless @conn.empty?
@eol = eol
end
=begin
--- RICE::Connection#ssl_params=(ssl_params)
=end
def ssl_params=(ssl_params)
raise RuntimeError,
"Already connected to #{@server}:#{@port}" unless @conn.empty?
unless ssl_params
@ssl_params = false
return
end
raise 'openssl library not installed' unless defined?(OpenSSL)
ssl_params = ssl_params.to_hash
ssl_params[:verify_mode] ||= OpenSSL::SSL::VERIFY_PEER
store = OpenSSL::X509::Store.new
if ssl_params.key?(:ca_cert)
ca_cert = ssl_params.delete(:ca_cert)
if ca_cert
# auto setting ca_path or ca_file like open-uri.rb
if File.directory? ca_cert
store.add_path ca_cert
else
store.add_file ca_cert
end
else
# use ssl_params={:ca_cert=>nil} if you want to disable auto setting
store = nil
end
else
# use default of openssl
store.set_default_paths
end
if store
ssl_params[:cert_store] = store
end
@ssl_params = ssl_params
end
=begin
--- RICE::Connection#start(max_retry = 3, retry_wait = 30)
=end
def start(max_retry = 3, retry_wait = 30)
@client_th = Thread.current # caller thread
if alive?
#sleep retry_wait
return nil
end
@main_th = Thread.new do
begin
Thread.stop
ensure
yield(self) if block_given?
@read_th.raise(Closed) if @read_th.status
close(true)
@client_th.raise(Closed)
end
end
begin
open_conn
rescue SystemCallError
max_retry -= 1
if max_retry == 0
@main_th.kill
raise
end
sleep retry_wait
retry
ensure
@main_th.join
nil
end
end
def open_conn
@conn.synchronize do
conn = TCPSocket.new(@server, @port)
if ssl_params
context = OpenSSL::SSL::SSLContext.new
context.set_params(ssl_params)
conn = OpenSSL::SSL::SSLSocket.new(conn, context)
conn.sync_close = true
conn.connect
if context.verify_mode != OpenSSL::SSL::VERIFY_NONE
conn.post_connection_check(@server)
end
end
@conn[0] = conn
end
@conn[0].extend(MonitorMixin)
@read_th.run
ths = @threads.synchronize do
@threads.keys
end
ths.each do |th|
th.run if th.status && th.stop?
end
end
private :open_conn
=begin
--- RICE::Connection#regist(raise_on_close, *args) {...}
=end
USER_THREAD = Struct.new('User_Thread', :q, :raise_on_close)
def regist(raise_on_close = false, *args)
read_q = Queue.new
th = Thread.new(read_q, self, *args) do |read_q, conn, *args|
yield(read_q, conn, *args)
end
@threads.synchronize do
@threads[th] = USER_THREAD.new(read_q, raise_on_close)
end
th
end
=begin
--- RICE::Connection#unregist(thread)
=end
def unregist(thread)
th = nil
@threads.synchronize do
th = @threads.delete(th)
end
th.exit
th
end
def read_thread(read_q, eol)
begin
read_q.clear
Thread.stop
begin
conn = @conn[0]
while l = conn.gets(eol)
begin
read_q.push(Message.parse(l))
rescue UnknownCommand
$stderr.print l.inspect if $DEBUG
rescue InvalidMessage
begin
read_q.push(Message.parse(l.sub(/\s*#{eol}\z/o, eol)))
rescue
$stderr.print l.inspect if $DEBUG
end
end
end
rescue IOError#, SystemCallError
$stderr.print "#{self.inspect}: read_th get error #{$!}" if $DEBUG
ensure
raise Closed
end
rescue Closed
begin
@main_th.run if @main_th.alive?
rescue Closed
end
retry
end
end
private :read_thread
=begin
--- RICE::Connection#close(restart = false)
=end
def close(restart = false)
begin
unless restart
@main_th.exit if @main_th.alive?
@read_th.exit if @read_th.alive?
end
conn = nil
@conn.synchronize do
conn = @conn.shift
end
conn.close if conn
@threads.synchronize do
@threads.each_key do |th|
if restart
if @threads[th].raise_on_close
if @threads[th].raise_on_close.kind_of?(Exception)
th.raise(@threads[th].raise_on_close)
else
th.raise(Closed)
end
end
else
th.exit
end
end
end
end
end
=begin
--- RICE::Connection#alive?
=end
def alive?
@main_th && @main_th.alive?
end
=begin
--- RICE::Connection#push(message)
=end
def push(message)
conn = @conn[0]
if conn
conn.synchronize do
cmd = message.command
if cmd == 'PRIVMSG' || cmd == 'NOTICE'
# flood control
t = Time.now
if t.to_i <= @prev_send_time.to_i + 2
sleep 1
end
@prev_send_time = t
end
conn.print message.to_s unless conn.closed?
end
else
nil
end
end
alias << push
end # Connection
=begin
== RICE::Message
=end
class Message
module PATTERN
# letter = %x41-5A / %x61-7A ; A-Z / a-z
# digit = %x30-39 ; 0-9
# hexdigit = digit / "A" / "B" / "C" / "D" / "E" / "F"
# special = %x5B-60 / %x7B-7D
# ; "[", "]", "\", "`", "_", "^", "{", "|", "}"
LETTER = 'A-Za-z'
DIGIT = '\d'
HEXDIGIT = "#{DIGIT}A-Fa-f"
SPECIAL = '\x5B-\x60\x7B-\x7D'
# shortname = ( letter / digit ) *( letter / digit / "-" )
# *( letter / digit )
# ; as specified in RFC 1123 [HNAME]
# hostname = shortname *( "." shortname )
SHORTNAME = "[#{LETTER}#{DIGIT}](?:[-#{LETTER}#{DIGIT}\/]*[#{LETTER}#{DIGIT}])?"
HOSTNAME = "#{SHORTNAME}(?:\\.#{SHORTNAME})*\\.?"
# servername = hostname
SERVERNAME = HOSTNAME
# nickname = ( letter / special ) *8( letter / digit / special / "-" )
NICKNAME = "[#{LETTER}#{SPECIAL}][\-#{LETTER}#{DIGIT}#{SPECIAL}]*"
# user = 1*( %x01-09 / %x0B-0C / %x0E-1F / %x21-3F / %x41-FF )
# ; any octet except NUL, CR, LF, " " and "@"
USER = '[\x01-\x09\x0B-\x0C\x0E-\x1F\x21-\x3F\x41-\xFF]+'
# ip4addr = 1*3digit "." 1*3digit "." 1*3digit "." 1*3digit
IP4ADDR = "[#{DIGIT}]{1,3}(?:\\.[#{DIGIT}]{1,3}){3}"
H16 = "[#{HEXDIGIT}]{1,4}" # :nodoc:
LS32 = "(?:#{H16}:#{H16})|#{IP4ADDR}" # :nodoc:
# ip6addr from RFC3986
IP6ADDR = "(?:#{H16}:){6}#{LS32}|" \
"::(?:#{H16}:){5}#{LS32}|" \
"(?:#{H16})?::(?:#{H16}:){4}#{LS32}|" \
"(?:(?:#{H16}:)?#{H16})?::(?:#{H16}:){3}#{LS32}|" \
"(?:(?:#{H16}:){0,2}#{H16})?::(?:#{H16}:){2}#{LS32}|" \
"(?:(?:#{H16}:){0,3}#{H16})?::#{H16}:#{LS32}|" \
"(?:(?:#{H16}:){0,4}#{H16})?::#{LS32}|" \
"(?:(?:#{H16}:){0,5}#{H16})?::#{H16}|" \
"(?:(?:#{H16}:){0,6}#{H16})?::"
# hostaddr = ip4addr / ip6addr
HOSTADDR = "(?:#{IP4ADDR}|#{IP6ADDR})"
# host = hostname / hostaddr
HOST = "(?:#{HOSTNAME}|#{HOSTADDR})"
# prefix = servername / ( nickname [ [ "!" user ] "@" host ] )
PREFIX = "(?:#{NICKNAME}(?:(?:!#{USER})?@#{HOST})?|#{SERVERNAME})"
# nospcrlfcl = %x01-09 / %x0B-0C / %x0E-1F / %x21-39 / %x3B-FF
# ; any octet except NUL, CR, LF, " " and ":"
NOSPCRLFCL = '\x01-\x09\x0B-\x0C\x0E-\x1F\x21-\x39\x3B-\xFF'
# command = 1*letter / 3digit
COMMAND = "(?:[#{LETTER}]+|[#{DIGIT}]{3})"
# SPACE = %x20 ; space character
# middle = nospcrlfcl *( ":" / nospcrlfcl )
# trailing = *( ":" / " " / nospcrlfcl )
# params = *14( SPACE middle ) [ SPACE ":" trailing ]
# =/ 14( SPACE middle ) [ SPACE [ ":" ] trailing ]
MIDDLE = "[#{NOSPCRLFCL}][:#{NOSPCRLFCL}]*"
TRAILING = "[: #{NOSPCRLFCL}]*"
PARAMS = "(?:((?: +#{MIDDLE}){0,14})(?: +:(#{TRAILING}))?|((?: +#{MIDDLE}){14}):?(#{TRAILING}))"
# crlf = %x0D %x0A ; "carriage return" "linefeed"
# message = [ ":" prefix SPACE ] command [ params ] crlf
CRLF = '\x0D\x0A'
MESSAGE = "(?::(#{PREFIX}) +)?(#{COMMAND})#{PARAMS}\s*(#{CRLF}|\n|\r)"
CLIENT_PATTERN = /\A#{NICKNAME}(?:(?:!#{USER})?@#{HOST})\z/on
MESSAGE_PATTERN = /\A#{MESSAGE}\z/on
end # PATTERN
=begin
--- RICE::Message::parse(str)
=end
def self.parse(str)
unless PATTERN::MESSAGE_PATTERN =~ str
raise InvalidMessage, "Invalid message: #{str.inspect}"
else
prefix = $1
command = $2
if $3 && $3.size > 0
middle = $3
trailer = $4
elsif $5 && $5.size > 0
middle = $5
trailer = $6
elsif $4
params = []
trailer = $4
elsif $6
params = []
trailer = $6
else
params = []
end
end
params ||= middle.split(/ /)[1..-1]
params << trailer if trailer
self.build(prefix, command.upcase, params)
end
=begin
--- RICE::Message::build(prefix, command, params)
=end
def self.build(prefix, command, params)
if Command::Commands.include?(command)
Command::Commands[command].new(prefix, command, params)
elsif Reply::Replies.include?(command)
Reply::Replies[command].new(prefix, command, params)
else
raise UnknownCommand, "unknown command: #{command}"
end
end
=begin
--- RICE::Message#prefix
--- RICE::Message#command
--- RICE::Message#params
=end
def initialize(prefix, command, params)
@prefix = prefix
@command = command
@params = params
end
attr_accessor :prefix
attr_reader :command, :params
=begin
--- RICE::Message::#to_s
=end
def to_s
str = ''
if @prefix
str << ':'
str << @prefix
str << ' '
end
str << @command
if @params
f = false
@params.each do |param|
str << ' '
if (param == @params[-1]) && (param.size == 0 || /(^:)|(\s)/ =~ param)
str << ':'
str << param.to_s
f = true
else
str << param.to_s
end
end
end
str << "\x0D\x0A"
str
end
=begin
--- RICE::Message::#to_a
=end
def to_a
[@prefix, @command, @params]
end
def inspect
sprintf('#<%s:0x%x prefix:%s command:%s params:%s>',
self.class, self.object_id, @prefix, @command, @params.inspect)
end
end # Message
=begin
== RICE::Command
=end
module Command
class Command < Message
end # Command
def self.regist_command cmd
eval <<E
class #{cmd} < Command
end
Commands['#{cmd}'] = #{cmd}
def #{cmd.downcase}(*params)
#{cmd}.new(nil, '#{cmd}', params)
end
module_function :#{cmd.downcase}
E
end
Commands = {}
%w(PASS NICK USER OPER MODE SERVICE QUIT SQUIT
JOIN PART TOPIC NAMES LIST INVITE KICK
PRIVMSG NOTICE MOTD LUSERS VERSION STATS LINKS
TIME CONNECT TRACE ADMIN INFO SERVLIST SQUERY
WHO WHOIS WHOWAS KILL PING PONG ERROR
AWAY REHASH DIE RESTART SUMMON USERS WALLOPS USERHOST ISON
).each do |cmd|
self.regist_command cmd
end
class NICK
def to_s
str = ''
if @prefix
str << ':'
str << @prefix
str << ' '
end
str << @command
str << ' '
str << ":#{@params[0]}"
str << "\x0D\x0A"
str
end
end
# XXX:
class PRIVMSG
def to_s
str = ''
if @prefix
str << ':'
str << @prefix
str << ' '
end
str << @command
str << ' '
str << @params[0]
str << ' :'
str << @params[1..-1].join(' ')
str << "\x0D\x0A"
str
end
end
end # Command
=begin
== RICE::Reply
== RICE::CommandResponse
== RICE::ErrorReply
=end
module Reply
class Reply < Message
end
class CommandResponse < Reply
end
class ErrorReply < Reply
end
Replies = {}
Replies_num_to_name = {}
%w(001,RPL_WELCOME
002,RPL_YOURHOST
003,RPL_CREATED
004,RPL_MYINFO
005,RPL_BOUNCE
302,RPL_USERHOST 303,RPL_ISON 301,RPL_AWAY
305,RPL_UNAWAY 306,RPL_NOWAWAY 311,RPL_WHOISUSER
312,RPL_WHOISSERVER 313,RPL_WHOISOPERATOR
317,RPL_WHOISIDLE 318,RPL_ENDOFWHOIS
319,RPL_WHOISCHANNELS 314,RPL_WHOWASUSER
369,RPL_ENDOFWHOWAS 321,RPL_LISTSTART
322,RPL_LIST 323,RPL_LISTEND 325,RPL_UNIQOPIS
324,RPL_CHANNELMODEIS 331,RPL_NOTOPIC
332,RPL_TOPIC 341,RPL_INVITING 342,RPL_SUMMONING
346,RPL_INVITELIST 347,RPL_ENDOFINVITELIST
348,RPL_EXCEPTLIST 349,RPL_ENDOFEXCEPTLIST
351,RPL_VERSION 352,RPL_WHOREPLY 315,RPL_ENDOFWHO
353,RPL_NAMREPLY 366,RPL_ENDOFNAMES 364,RPL_LINKS
365,RPL_ENDOFLINKS 367,RPL_BANLIST 368,RPL_ENDOFBANLIST
371,RPL_INFO 374,RPL_ENDOFINFO 375,RPL_MOTDSTART
372,RPL_MOTD 376,RPL_ENDOFMOTD 381,RPL_YOUREOPER
382,RPL_REHASHING 383,RPL_YOURESERVICE 391,RPL_TIM
392,RPL_ 393,RPL_USERS 394,RPL_ENDOFUSERS 395,RPL_NOUSERS
200,RPL_TRACELINK 201,RPL_TRACECONNECTING
202,RPL_TRACEHANDSHAKE 203,RPL_TRACEUNKNOWN
204,RPL_TRACEOPERATOR 205,RPL_TRACEUSER 206,RPL_TRACESERVER
207,RPL_TRACESERVICE 208,RPL_TRACENEWTYPE 209,RPL_TRACECLASS
210,RPL_TRACERECONNECT 261,RPL_TRACELOG 262,RPL_TRACEEND
211,RPL_STATSLINKINFO 212,RPL_STATSCOMMANDS 219,RPL_ENDOFSTATS
242,RPL_STATSUPTIME 243,RPL_STATSOLINE 221,RPL_UMODEIS
234,RPL_SERVLIST 235,RPL_SERVLISTEND 251,RPL_LUSERCLIENT
252,RPL_LUSEROP 253,RPL_LUSERUNKNOWN 254,RPL_LUSERCHANNELS
255,RPL_LUSERME 256,RPL_ADMINME 257,RPL_ADMINLOC1
258,RPL_ADMINLOC2 259,RPL_ADMINEMAIL 263,RPL_TRYAGAIN
401,ERR_NOSUCHNICK 402,ERR_NOSUCHSERVER 403,ERR_NOSUCHCHANNEL
404,ERR_CANNOTSENDTOCHAN 405,ERR_TOOMANYCHANNELS
406,ERR_WASNOSUCHNICK 407,ERR_TOOMANYTARGETS
408,ERR_NOSUCHSERVICE 409,ERR_NOORIGIN 411,ERR_NORECIPIENT
412,ERR_NOTEXTTOSEND 413,ERR_NOTOPLEVEL 414,ERR_WILDTOPLEVEL
415,ERR_BADMASK 421,ERR_UNKNOWNCOMMAND 422,ERR_NOMOTD
423,ERR_NOADMININFO 424,ERR_FILEERROR 431,ERR_NONICKNAMEGIVEN
432,ERR_ERRONEUSNICKNAME 433,ERR_NICKNAMEINUSE
436,ERR_NICKCOLLISION 437,ERR_UNAVAILRESOURCE
441,ERR_USERNOTINCHANNEL 442,ERR_NOTONCHANNEL
443,ERR_USERONCHANNEL 444,ERR_NOLOGIN 445,ERR_SUMMONDISABLED
446,ERR_USERSDISABLED 451,ERR_NOTREGISTERED
461,ERR_NEEDMOREPARAMS 462,ERR_ALREADYREGISTRED
463,ERR_NOPERMFORHOST 464,ERR_PASSWDMISMATCH
465,ERR_YOUREBANNEDCREEP 466,ERR_YOUWILLBEBANNED
467,ERR_KEYSE 471,ERR_CHANNELISFULL 472,ERR_UNKNOWNMODE
473,ERR_INVITEONLYCHAN 474,ERR_BANNEDFROMCHAN
475,ERR_BADCHANNELKEY 476,ERR_BADCHANMASK 477,ERR_NOCHANMODES
478,ERR_BANLISTFULL 481,ERR_NOPRIVILEGES 482,ERR_CHANOPRIVSNEEDED
483,ERR_CANTKILLSERVER 484,ERR_RESTRICTED
485,ERR_UNIQOPPRIVSNEEDED 491,ERR_NOOPERHOST
501,ERR_UMODEUNKNOWNFLAG 502,ERR_USERSDONTMATCH
231,RPL_SERVICEINFO 232,RPL_ENDOFSERVICES
233,RPL_SERVICE 300,RPL_NONE 316,RPL_WHOISCHANOP
361,RPL_KILLDONE 362,RPL_CLOSING 363,RPL_CLOSEEND
373,RPL_INFOSTART 384,RPL_MYPORTIS 213,RPL_STATSCLINE
214,RPL_STATSNLINE 215,RPL_STATSILINE 216,RPL_STATSKLINE
217,RPL_STATSQLINE 218,RPL_STATSYLINE 240,RPL_STATSVLINE
241,RPL_STATSLLINE 244,RPL_STATSHLINE 244,RPL_STATSSLINE
246,RPL_STATSPING 247,RPL_STATSBLINE 250,RPL_STATSDLINE
492,ERR_NOSERVICEHOST
).each do |num_cmd|
num, cmd = num_cmd.split(',', 2)
eval <<E
class #{cmd} < #{if num[0] == ?0 || num[0] == ?2 || num[0] == ?3
'CommandResponse'
elsif num[0] == ?4 || num[0] == ?5
'ErrorReply'
end}
end
Replies['#{num}'] = #{cmd}
Replies_num_to_name['#{num}'] = '#{cmd.downcase}'
def #{cmd.downcase}(*params)
#{cmd}.new(nil, '#{num}', params)
end
module_function :#{cmd.downcase}
E
end
end # Reply
end # RICE
|