Class: IRC::Server::Modules::Base

Inherits:
IRC::Server::Module show all
Defined in:
lib/failirc/server/modules/Base.rb

Defined Under Namespace

Modules: Utils

Constant Summary collapse

@@version =
'0.0.1'
@@modes =
{
    :groups => {
        :can_change_channel_modes => [
            :can_change_channel_extended_modes, :can_change_topic_mode,
            :can_change_no_external_messages_mode, :can_change_secret_mode,
            :can_change_ssl_mode, :can_change_moderated_mode,
            :can_change_invite_only_mode, :can_change_auditorium_mode,
            :can_change_anonymous_mode, :can_change_limit_mode,
            :can_change_redirect_mode, :can_change_noknock_mode,
            :can_add_invitation, :can_channel_ban, :can_add_ban_exception,
            :can_change_channel_password, :can_change_nocolors_mode,
            :can_change_noctcp_mode, :can_change_no_nick_change_mode,
            :can_change_nokicks_mode, :can_change_strip_colors_mode,
            :can_change_noinvites_mode,
        ],
         :can_change_user_modes => [
            :can_give_channel_operator, :can_give_channel_half_operator,
            :can_give_voice, :can_change_user_extended_modes,
        ],
         :can_change_client_modes => [
            :can_change_client_extended_modes,
        ],
    },
     :channel => {
        :a => :anonymous,
        :c => :no_colors,
        :C => :no_ctcps,
        :i => :invite_only,
        :l => :limit,
        :L => :redirect,
        :k => :password,
        :K => :no_knock,
        :m => :moderated,
        :n => :no_external_messages,
        :N => :no_nick_change,
        :Q => :no_kicks,
        :s => :secret,
        :S => :strip_colors,
        :t => :topic_change_needs_privileges,
        :u => :auditorium,
        :V => :no_invites,
        :z => :ssl_only,
    },
     :user => {
        :x => [:y, :can_give_channel_admin],
        :y => [:o, :admin],
        :o => [:h, :operator, :can_change_topic, :can_invite, :can_change_channel_modes, :can_change_user_modes],
        :h => [:v, :halfoperator, :can_kick],
        :v => [:voice, :can_talk],
    },
     :client => {
        :netadmin => [:N, :operator],
        :operator => [:o, :can_kill, :can_kick, :can_give_channel_owner, :can_change_topic, :can_change_channel_modes, :can_change_user_modes, :can_change_client_modes],
    },
}
@@supportedModes =
{
    :client  => [],
    :channel => [],
}
@@support =
{}

Instance Attribute Summary collapse

Attributes inherited from IRC::Server::Module

#server

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server) ⇒ Base

Returns a new instance of Base.



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
# File 'lib/failirc/server/modules/Base.rb', line 129

def initialize (server)
    @aliases = {
        :input => {
            :PASS => /^PASS( |$)/i,
            :NICK => /^(:[^ ] )?NICK( |$)/i,
            :USER => /^(:[^ ] )?USER( |$)/i,

            :PING => /^PING( |$)/i,
            :PONG => /^PONG( |$)/i,

            :AWAY     => /^AWAY( |$)/i,
            :MODE     => /^MODE( |$)/i,
            :ENCODING => /^ENCODING( |$)/i,

            :JOIN   => /^(:[^ ] )?JOIN( |$)/i,
            :PART   => /^(:[^ ] )?PART( |$)/i,
            :KICK   => /^(:[^ ] )?KICK( |$)/i,
            :INVITE => /^INVITE( |$)/i,
            :KNOCK  => /^KNOCK( |$)/i,

            :TOPIC => /^(:[^ ] )?TOPIC( |$)/i,
            :NAMES => /^NAMES( |$)/i,
            :LIST  => /^LIST( |$)/i,

            :WHO    => /^WHO( |$)/i,
            :WHOIS  => /^WHOIS( |$)/i,
            :WHOWAS => /^WHOWAS( |$)/i,
            :ISON   => /^ISON( |$)/i,

            :PRIVMSG => /^(:[^ ] )?PRIVMSG( |$)/i,
            :NOTICE  => /^NOTICE( |$)/i,

            :MAP     => /^MAP( |$)/i,
            :VERSION => /^VERSION( |$)/i,

            :OPER => /^OPER( |$)/i,
            :KILL => /^KILL( |$)/i,

            :QUIT => /^QUIT( |$)/i,
        },
    }

    @events = {
        :pre  => [Event::Callback.new(self.method(:input_encoding), -1234567890), self.method(:check)],
        :post => [Event::Callback.new(self.method(:output_encoding), 1234567890)],

        :custom => {
            :client_nick_change => self.method(:client_nick_change),

            :kill => self.method(:client_quit),

            :join   => self.method(:client_join),
            :part   => self.method(:user_part),
            :kick   => self.method(:send_kick),
            :invite => self.method(:client_invite),

            :whois => self.method(:send_whois),

            :message => [self.method(:handling_message), self.method(:send_message)],
            :notice  => [self.method(:handling_notice), self.method(:send_notice)],
            :ctcp    => [self.method(:handling_ctcp), self.method(:send_ctcp)],
            :error   => self.method(:send_error),

            :topic_change => self.method(:topic_change),

            :mode => [self.method(:normal_mode), self.method(:extended_mode)],
        },

        :default => self.method(:unknown_command),

        :input => {
            :PING => self.method(:ping),
            :PONG => self.method(:pong),

            :AWAY     => self.method(:away),
            :MODE     => self.method(:mode),
            :ENCODING => self.method(:encoding),

            :PASS => self.method(:pass),
            :NICK => self.method(:nick),
            :USER => self.method(:user),

            :JOIN   => self.method(:join),
            :PART   => self.method(:part),
            :KICK   => self.method(:kick),
            :INVITE => self.method(:invite),
            :KNOCK  => self.method(:knock),

            :TOPIC => self.method(:topic),
            :NAMES => self.method(:names),
            :LIST  => self.method(:list),

            :WHO    => self.method(:who),
            :WHOIS  => self.method(:whois),
            :WHOWAS => self.method(:whowas),
            :ISON   => self.method(:ison),

            :PRIVMSG => self.method(:privmsg),
            :NOTICE  => self.method(:notice),

            :MAP     => self.method(:map),
            :VERSION => self.method(:version),

            :OPER => self.method(:oper),
            :KILL => self.method(:kill),

            :QUIT => self.method(:quit),
        },
    }

    super(server)

    server.data[:nicks] = {}

    @@supportedModes[:client].insert(-1, *('o'.split(//)))
    @@supportedModes[:channel].insert(-1, *('abcCehiIkKlLmnoQsStuvVxyz'.split(//)))

    @@support.merge!({
        'CASEMAPPING' => 'ascii',
        'SAFELIST'    => true,
        'EXCEPTS'     => true,
        'CHANTYPES'   => '&#+!',
        'PREFIX'      => '(xyohv)~&@%+',
        'STATUSMSG'   => '~&@%+',
        'FNC'         => true,

        'CMDS' => 'KNOCK',
    })

    @joining   = ThreadSafeHash.new
    @semaphore = Mutex.new

    @pingedOut = ThreadSafeHash.new
    @toPing    = ThreadSafeHash.new

    @pingInterval = server.dispatcher.setInterval Fiber.new {
        while true
            # time to ping non active users
            @toPing.each_value {|client|
                @pingedOut[client.socket] = client

                if client.modes[:registered]
                    client.send :raw, "PING :#{server.host}"
                end
            }

            # clear and refil the hash of clients to ping with all the connected clients
            @toPing.clear
            @toPing.merge!(Hash[server.clients.values.collect {|client| [client.socket, client]}])

            Fiber.yield

            # people who didn't answer with a PONG has to YIFF IN HELL.
            @pingedOut.each_value {|client|
                if !client.socket.closed?
                    server.kill client, 'Ping timeout', true
                end
            }

            @pingedOut.clear
        end
    }, (@pingTimeout / 2)
end

Instance Attribute Details

#messagesObject (readonly)

Returns the value of attribute messages.



37
38
39
# File 'lib/failirc/server/modules/Base.rb', line 37

def messages
  @messages
end

Class Method Details

.modesObject



113
114
115
# File 'lib/failirc/server/modules/Base.rb', line 113

def self.modes
    @@modes
end

.supportObject



121
122
123
# File 'lib/failirc/server/modules/Base.rb', line 121

def self.support
    @@support
end

.supportedModesObject



117
118
119
# File 'lib/failirc/server/modules/Base.rb', line 117

def self.supportedModes
    @@supportedModes
end

.versionObject



109
110
111
# File 'lib/failirc/server/modules/Base.rb', line 109

def self.version
    @@version
end

Instance Method Details

#away(thing, string) ⇒ Object



892
893
894
895
896
897
898
899
900
901
902
# File 'lib/failirc/server/modules/Base.rb', line 892

def away (thing, string)
    match = string.match(/AWAY\s+(:)?(.*)$/i)

    if !match || match[2].empty?
        thing.modes[:away] = false
        thing.send :numeric, RPL_UNAWAY
    else
        thing.modes[:away] = match[2]
        thing.send :numeric, RPL_NOWAWAY
    end
end

#check(event, thing, string) ⇒ Object



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
# File 'lib/failirc/server/modules/Base.rb', line 668

def check (event, thing, string)
    if event.chain != :input || !thing || !string
        return
    end

    @toPing.delete(thing.socket)
    @pingedOut.delete(thing.socket)

    if !event.aliases.include?(:PING) && !event.aliases.include?(:PONG) && !event.aliases.include?(:WHO) && !event.aliases.include?(:MODE)
        thing.modes[:last_action] = Utils::Client::Action.new(thing, event, string)
    end

    stop = false

    # if the client tries to do something without having registered, kill it with fire
    if !event.aliases.include?(:PASS) && !event.aliases.include?(:NICK) && !event.aliases.include?(:USER) && !thing.modes[:registered]
        thing.send :numeric, ERR_NOTREGISTERED
        stop = true
    # if the client tries to reregister, kill it with fire
    elsif (event.aliases.include?(:PASS) || event.aliases.include?(:USER)) && thing.modes[:registered]
        thing.send :numeric, ERR_ALREADYREGISTRED
        stop = true
    end

    return !stop
end

#client_invite(from, to, channel) ⇒ Object



1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
# File 'lib/failirc/server/modules/Base.rb', line 1918

def client_invite (from, to, channel)
    from.send :numeric, RPL_INVITING, {
        :nick    => to.nick,
        :channel => channel,
    }

    target = channel

    if channel = server.channels[target]
        channel.modes[:invited][to.nick] = true
        server.dispatcher.execute :notice, :input, ref{:server}, ref{:channel}, "#{from.nick} invited #{to.nick} into the channel.", '@'
    end

    to.send :raw, ":#{from.mask} INVITE #{to.nick} :#{target}"
end

#client_join(client, channel) ⇒ Object



1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
# File 'lib/failirc/server/modules/Base.rb', line 1734

def client_join (client, channel)
    empty = channel.empty?
    user  = channel.add(client)

    if empty
        handle_mode server, channel, "+o #{user.nick}", true
    else
        channel.modes[:invited].delete(client.nick)
    end

    user.client.channels.add(channel)

    if user.channel.modes[:anonymous]
        mask = Mask.new 'anonymous', 'anonymous', 'anonymous.'
    else
        mask = user.mask
    end

    user.channel.send :raw, ":#{mask} JOIN :#{user.channel}"

    if !user.channel.topic.nil?
        topic user.client, "TOPIC #{user.channel}"
    end

    names user.client, "NAMES #{user.channel}"
end

#client_nick_change(thing, nick) ⇒ Object



831
832
833
834
835
836
837
838
839
840
841
842
843
# File 'lib/failirc/server/modules/Base.rb', line 831

def client_nick_change (thing, nick)
    if server.clients[nick] || server.data[:nicks][nick]
        thing.send :numeric, ERR_NICKNAMEINUSE, nick
        return false
    end

    allowed = eval(@nickAllowed) rescue false

    if !allowed || nick.downcase == 'anonymous'
        thing.send :numeric, ERR_ERRONEUSNICKNAME, nick
        return false
    end
end

#client_quit(thing, message) ⇒ Object



2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
# File 'lib/failirc/server/modules/Base.rb', line 2527

def client_quit (thing, message)
    server.data[:nicks].delete(thing.nick)

    @toPing.delete(thing.socket)
    @pingedOut.delete(thing.socket)

    thing.channels.select {|name, channel| channel.modes[:anonymous]}.each_value {|channel|
        server.dispatcher.execute :part, channel.user(thing).clone, message
    }

    thing.channels.unique_users.send :raw, ":#{thing.mask} QUIT :#{message}"
end

#descriptionObject



125
126
127
# File 'lib/failirc/server/modules/Base.rb', line 125

def description
    "Base-#{Base.version}"
end

#encoding(thing, string) ⇒ Object



1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
# File 'lib/failirc/server/modules/Base.rb', line 1588

def encoding (thing, string)
    match = string.match(/ENCODING\s+(.+?)(\s+(.+))?$/i)

    if !match
        thing.send :numeric, ERR_NEEDMOREPARAMS, 'ENCODING'
        return
    end

    if match[2]
        nick = match[1].strip
        name = match[3].strip
    else
        nick = nil
        name = match[1].strip
    end

    begin
        "".encode(name)

        if nick
            if Utils::checkFlag(thing, :operator)
                if client = server.clients[nick]
                    client.modes[:encoding] = name
                else
                    thing.send :numeric, ERR_NOSUCHNICK, nick
                end
            else
                thing.send :numeric, ERR_NOPRIVILEGES
            end
        else
            thing.modes[:encoding] = name
        end
    rescue Encoding::ConverterNotFoundError
        server.dispatcher.execute(:error, thing, "#{name} is not a valid encoding.")
    end
end

#extended_mode(kind, from, thing, type, mode, values, output = nil) ⇒ Object



1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
# File 'lib/failirc/server/modules/Base.rb', line 1546

def extended_mode (kind, from, thing, type, mode, values, output=nil)
    if kind != :extended
        return
    end

    if thing.is_a?(Server::Channel) && !Utils::checkFlag(from, :can_change_channel_extended_modes)
        from.send :numeric, ERR_CHANOPRIVSNEEDED, thing.name
        return
    elsif thing.is_a?(Server::User) && !Utils::checkFlag(from, :can_change_user_extended_modes)
        from.send :numeric, ERR_CHANOPRIVSNEEDED, thing.channel.name
        return
    elsif thing.is_a?(Server::Client) && from.nick != thing.nick && !Utils::checkFlag(from, :can_change_client_extended_modes) && !Utils::checkFlag(from, :frozen)
        from.send :numeric, ERR_NOPRIVILEGES
        return
    end

    if type == '?'
        if thing.is_a?(Server::Channel)
            name = thing.name
        elsif thing.is_a?(Server::User)
            name = "#{thing.nick}@#{thing.channel.name}"
        elsif thing.is_a?(Server::Client)
            name = thing.nick
        end

        thing.modes[:extended].each {|key, value|
            from.server.dispatcher.execute :notice, :output, ref{:server}, ref{:from}, "#{name} #{key} = #{value}"
        }
    else
        if !mode.match(/^\w+$/)
            from.server.dispatcher.execute :error, from, "#{mode} is not a valid extended mode."
            return
        end

        if type == '+'
            thing.modes[:extended][mode.to_sym] = values || true
        else
            thing.modes[:extended].delete(mode.to_sym)
        end
    end
end

#finalizeObject



333
334
335
# File 'lib/failirc/server/modules/Base.rb', line 333

def finalize
    server.dispatcher.clearInterval @pingInterval
end

#handle_mode(from, thing, request, noAnswer = false) ⇒ Object



988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
# File 'lib/failirc/server/modules/Base.rb', line 988

def handle_mode (from, thing, request, noAnswer=false)
    if match = request.match(/^=(.*)$/)
        value = match[1].strip

        if value == '?'
            server.dispatcher.execute :mode, :extended, from, thing, '?', nil, nil, nil
        else
            modes = value.split(/[^\\],/)

            modes.each {|mode|
                if mode[0, 1] == '-'
                    type = '-'
                else
                    type = '+'
                end

                mode.sub!(/^[+\-]/, '')

                mode = mode.split(/=/)

                server.dispatcher.execute :mode, :extended, from, thing, type, *mode, nil
            }
        end
    else
        output = {
            :modes  => [],
            :values => [],
        }

        match = request.match(/^\s*([+\-])?\s*([^ ]+)(\s+(.+))?$/)

        if !match
            return false
        end

        type   = match[1] || '+'
        modes  = match[2].split(//)
        values = (match[4] || '').strip.split(/ /)

        modes.each {|mode|
            server.dispatcher.execute :mode, :normal, from, thing, type, mode, values, output
        }

        if from.is_a?(Server::Client) || from.is_a?(Server::User)
            from = from.mask
        end

        if !noAnswer && (!output[:modes].empty? || !output[:values].empty?)
            string = "#{type}#{output[:modes].join('')}"
            
            if !output[:values].empty?
                string << " #{output[:values].join(' ')}"
            end

            thing.send :raw, ":#{from} MODE #{thing.is_a?(Server::Channel) ? thing.name : thing.nick} #{string}"
        end

    end
end

#handling_ctcp(chain, kind, fromRef, toRef, type, message, level = nil) ⇒ Object



2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
# File 'lib/failirc/server/modules/Base.rb', line 2371

def handling_ctcp (chain, kind, fromRef, toRef, type, message, level=nil)
    if chain != :input
        return
    end

    from = fromRef.value
    to   = toRef.value

    if to.is_a?(Channel)
        if to.modes[:no_ctcps]
            from.send :numeric, ERR_NOCTCPS, to.name
            return false
        end

        to.users.each_value {|user|
            if user.client != from && Utils::User::isLevelEnough(user, level)
                server.dispatcher.execute :ctcp, :output, kind, fromRef, ref{:user}, type, message, level
            end
        }
    elsif to.is_a?(Client) || to.is_a?(User)
        server.dispatcher.execute :ctcp, :output, kind, fromRef, toRef, type, message, level
    end
end

#handling_message(chain, fromRef, toRef, message) ⇒ Object



2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
# File 'lib/failirc/server/modules/Base.rb', line 2244

def handling_message (chain, fromRef, toRef, message)
    if chain != :input
        return
    end

    from = fromRef.value
    to   = toRef.value

    if to.is_a?(Channel)
        if to.modes[:strip_colors]
            message.gsub!(/\x03((\d{1,2})?(,\d{1,2})?)?/, '')
        end

        if to.modes[:no_colors] && message.include?("\x03")
            from.send :numeric, ERR_NOCOLORS, to.name
            return false
        end

        to.users.each_value {|user|
            if user.client != from
                server.dispatcher.execute :message, :output, fromRef, ref{:user}, message
            end
        }
    elsif to.is_a?(Client)
        server.dispatcher.execute :message, :output, fromRef, toRef, message
    end
end

#handling_notice(chain, fromRef, toRef, message, level = nil) ⇒ Object



2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
# File 'lib/failirc/server/modules/Base.rb', line 2329

def handling_notice (chain, fromRef, toRef, message, level=nil)
    if chain != :input
        return
    end

    from = fromRef.value
    to   = toRef.value

    if to.is_a?(Channel)
        to.users.each_value {|user|
            if user.client != from && Utils::User::isLevelEnough(user, level)
                server.dispatcher.execute :notice, :output, fromRef, ref{:user}, message, level
            end
        }
    elsif to.is_a?(Client)
        server.dispatcher.execute :notice, :output, fromRef, toRef, message, level
    end
end

#input_encoding(event, thing, string) ⇒ Object



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
# File 'lib/failirc/server/modules/Base.rb', line 695

def input_encoding (event, thing, string)
    if event.chain != :input
        return
    end

    begin
        if thing.modes[:encoding]
            string.force_encoding(thing.modes[:encoding])
            string.encode!('UTF-8')
        else
            string.force_encoding('UTF-8')

            if !string.valid_encoding?
                raise Encoding::InvalidByteSequenceError
            end
        end
    rescue
        if thing.modes[:encoding]
            server.dispatcher.execute :error, thing, 'The encoding you choose seems to not be the one you are using.'
        else
            server.dispatcher.execute :error, thing, 'Please specify the encoding you are using with ENCODING <encoding>'
        end

        string.force_encoding('ASCII-8BIT')

        string.encode!('UTF-8',
            :invalid => :replace,
            :undef   => :replace
        )
    end
end

#invite(thing, string) ⇒ Object



1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
# File 'lib/failirc/server/modules/Base.rb', line 1865

def invite (thing, string)
    match = string.match(/INVITE\s+(.+?)\s+(.+?)$/i)

    if !match
        thing.send :numeric, ERR_NEEDMOREPARAMS, 'INVITE'
        return
    end

    nick    = match[1].strip
    channel = match[2].strip

    if !server.clients[nick]
        thing.send :numeric, ERR_NOSUCHNICK, nick
        return
    end

    if server.channels[channel]
        requesting = server.channels[channel].user(thing) || thing

        if !Utils::checkFlag(requesting, :can_invite) && !thing.channels[channel]
            thing.send :numeric, ERR_NOTONCHANNEL, channel
            return
        end

        if !Utils::checkFlag(requesting, :can_invite)
            thing.send :numeric, ERR_CHANOPRIVSNEEDED, channel
            return
        end

        if server.channels[channel].users[nick]
            thing.send :numeric, ERR_USERONCHANNEL, {
                :nick    => nick,
                :channel => channel,
            }

            return
        end

        if server.channels[channel].modes[:no_invites]
            thing.send :numeric, ERR_NOINVITE, channel
            return false
        end
    end

    client = server.clients[nick]

    if client.modes[:away]
        thing.send :numeric, RPL_AWAY, client
    end

    server.dispatcher.execute :invite, thing, client, channel
end

#ison(thing, string) ⇒ Object



2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
# File 'lib/failirc/server/modules/Base.rb', line 2167

def ison (thing, string)
    match = string.match(/ISON\s+(.+)$/i)

    if !match
        thing.send :numeric, ERR_NEEDMOREPARAMS, 'ISON'
        return
    end

    result = String.new

    match.split(/\s+/).each {|nick|
        if server.clients[nick]
            result << " #{nick}"
        end
    }

    result = result[1, result.length]

    thing.send :numeric, RPL_ISON, result
end

#join(thing, string) ⇒ Object



1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
# File 'lib/failirc/server/modules/Base.rb', line 1625

def join (thing, string)
    match = string.match(/JOIN\s+(.+?)(\s+(.+))?$/i)

    if !match
        thing.send :numeric, ERR_NEEDMOREPARAMS, 'JOIN'
        return
    end

    if match[1] == '0'
        thing.channels.each_value {|channel|
            server.dispatcher.execute :part, channel[thing.nick], 'Left all channels'
        }

        return
    end

    channels  = match[1].split(/,/)
    passwords = (match[3] || '').split(/,/)

    channels.each {|channel|
        channel.strip!

        if !Utils::Channel::type(channel)
            channel = "##{channel}"
        end

        if !Utils::Channel::isValid(channel)
            thing.send :numeric, ERR_BADCHANMASK, channel
            next
        end

        jump = false

        @semaphore.synchronize {
            if thing.channels[channel] || @joining[thing]
                jump = true
                break
            end

            @joining[thing] = true

            if !server.channels[channel]
                channel = server.channels[channel] = Channel.new(server, channel)
            else
                channel = server.channels[channel]
            end
        }

        if jump
            next
        end

        if !channel.modes[:bans]
            channel.modes[:bans]       = []
            channel.modes[:exceptions] = []
            channel.modes[:invites]    = []
            channel.modes[:invited]    = ThreadSafeHash.new
        end

        if channel.modes[:password]
            password = passwords.shift
        else
            password = ''
        end

        if channel.modes[:l]
            if channel.users.length >= channel.modes[:l]
                @joining.delete(thing)

                if channel.modes[:L]
                    join thing, "JOIN #{channel.modes[:L]}"
                else
                    thing.send :numeric, ERR_CHANNELISFULL, channel.name
                end

                next
            end
        end

        if channel.modes[:ssl_only] && !thing.modes[:ssl]
            thing.send :numeric, ERR_SSLREQUIRED, channel.name
            @joining.delete(thing)
            next
        end

        if channel.modes[:password] && password != channel.modes[:password]
            thing.send :numeric, ERR_BADCHANNELKEY, channel.name
            @joining.delete(thing)
            next
        end

        if channel.modes[:invite_only] && !Utils::Channel::invited?(channel, thing, true)
            thing.send :numeric, ERR_INVITEONLYCHAN, channel.name
            @joining.delete(thing)
            next
        end

        if Utils::Channel::banned?(channel, thing) && !Utils::Channel::exception?(channel, thing) && !Utils::Channel::invited?(channel, thing)
            thing.send :numeric, ERR_BANNEDFROMCHAN, channel.name
            @joining.delete(thing)
            next
        end

        server.dispatcher.execute(:join, thing, channel)

        @joining.delete(thing)
    }
end

#kick(thing, string) ⇒ Object



1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
# File 'lib/failirc/server/modules/Base.rb', line 1808

def kick (thing, string)
    match = string.match(/KICK\s+(.+?)\s+(.+?)(\s+:(.*))?$/i)

    if !match
        thing.send :numeric, ERR_NEEDMOREPARAMS, 'KICK'
        return
    end

    channel = match[1]
    user    = match[2]
    message = match[4]

    if !Utils::Channel::isValid(channel)
        thing.send :numeric, ERR_BADCHANMASK, channel
        return
    end

    if !server.channels[channel]
        thing.send :numeric, ERR_NOSUCHCHANNEL, channel
        return
    end

    if !server.clients[user]
        thing.send :numeric, ERR_NOSUCHNICK, user
        return
    end

    channel = server.channels[channel]
    user    = channel[user]

    if !user
        thing.send :numeric, ERR_NOTONCHANNEL, channel.name
        return
    end

    if thing.channels[channel.name]
        thing = thing.channels[channel.name].user(thing)
    end

    if Utils::checkFlag(thing, :can_kick)
        if channel.modes[:no_kicks]
            thing.send :numeric, ERR_NOKICKS
        else
            server.dispatcher.execute(:kick, thing, user, message)
        end
    else
        thing.send :numeric, ERR_CHANOPRIVSNEEDED, channel.name
    end
end

#kill(thing, string) ⇒ Object



2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
# File 'lib/failirc/server/modules/Base.rb', line 2486

def kill (thing, string)
    match = string.match(/KILL\s+(.*?)(\s+(:)?(.*))?$/i)

    if !match
        thing.send :numeric, ERR_NEEDMOREPARAMS, 'KILL'
        return
    end

    if !Utils::checkFlag(thing, :can_kill)
        thing.send :numeric, ERR_NOPRIVILEGES
        return
    end

    nick    = match[1]
    client  = server.clients[nick]
    message = match[4]

    if !client
        thing.send :numeric, ERR_NOSUCHNICK, nick
        return
    end

    sender = thing

    text = eval(Utils::escapeMessage(@messages[:kill]))

    client.send :raw, ":#{client.mask} QUIT :#{text}"

    server.kill client, text
end

#knock(thing, string) ⇒ Object



1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
# File 'lib/failirc/server/modules/Base.rb', line 1934

def knock (thing, string)
    match = string.match(/KNOCK\s+(.+?)(\s+:(.*))?$/i)

    if !match
        thing.send :numeric, ERR_NEEDMOREPARAMS, 'KNOCK'
        return
    end

    channel = match[1]
    message = match[3]

    if !server.channels[channel]
        thing.send :numeric, ERR_NOKNOCK, { :channel => channel, :reason => 'Channel does not exist!' }
        return
    end

    channel = server.channels[channel]

    if !channel.modes[:i]
        thing.send :numeric, ERR_NOKNOCK, { :channel => channel.name, :reason => 'Channel is not invite only!' }
        return
    end

    if channel.modes[:K]
        thing.send :numeric, ERR_NOKNOCK, { :channel => channel.name, :reason => 'No knocks are allowed! (+K)' }
        return
    end

    server.dispatcher.execute :notice, :input, ref{:server}, ref{:channel}, "[Knock] by #{thing.mask} (#{message ? message : 'no reason specified'})", '@'
    server.dispatcher.execute :notice, :input, ref{:server}, ref{:thing}, "Knocked on #{channel.name}"
end

#list(thing, string) ⇒ Object



2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
# File 'lib/failirc/server/modules/Base.rb', line 2046

def list (thing, string)
    match = string.match(/LIST(\s+(.*))?$/)

    channels = (match[2].strip || '').split(/,/)

    thing.send :numeric, RPL_LISTSTART

    if channels.empty?
        channels = server.channels
    else
        tmp = Channels.new(thing.server)

        channels.each {|channel|
            if channel = server.channels[channel]
                tmp.add(channel)
            end
        }

        channels = tmp
    end

    channels.each_value {|channel|
        if !channel.modes[:secret] || thing.channels[channel.name]
            thing.send :numeric, RPL_LIST, channel
        end
    }

    thing.send :numeric, RPL_LISTEND
end

#map(thing, string) ⇒ Object



2442
2443
2444
# File 'lib/failirc/server/modules/Base.rb', line 2442

def map (thing, string)
    server.dispatcher.execute :notice, :input, ref{:server}, ref{:thing}, 'The X tells the point.'
end

#mode(thing, string) ⇒ Object



904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
# File 'lib/failirc/server/modules/Base.rb', line 904

def mode (thing, string)
    # MODE user/channel = +option,-option
    match = string.match(/MODE\s+([^ ]+)(\s+(:)?(.*))?$/i)

    if !match
        thing.send :numeric, ERR_NEEDMOREPARAMS, 'MODE'
        return
    end

    name  = match[1]
    value = match[4] || ''

    # long options, extended protocol
    if match = value.match(/^=\s+(.*)$/)
        if Utils::Channel::isValid(name)
            channel = server.channels[name]

            if channel
                handle_mode channel.user(thing) || thing, channel, value
            else
                thing.send :numeric, ERR_NOSUCHCHANNEL, name
            end
        elsif match = name.match(/^([^@])@(.*)$/)
            user    = match[1]
            channel = match[2]

            if tmp = server.channels[channel]
                channel = tmp

                if tmp = server.clients[user]
                    if tmp = channel.user(tmp)
                        user = tmp

                        handle_mode thing, user, value
                    else
                        thing.send :numeric, ERR_USERNOTINCHANNEL, {
                            :nick    => user,
                            :channel => channel,
                        }
                    end
                else
                    thing.send :numeric, ERR_NOSUCHNICK, user
                end
            else
                thing.send :numeric, ERR_NOSUCHCHANNEL, channel
            end
        else
            if tmp = server.clients[name]
                client = tmp

                handle_mode thing, client, value
            else
                thing.send :numeric, ERR_NOSUCHNICK, name
            end
        end
    # usual shit
    else
        if Utils::Channel::isValid(name)
            if server.channels[name]
                channel = server.channels[name]

                if value.empty?
                    thing.send :numeric, RPL_CHANNELMODEIS, channel
                    thing.send :numeric, RPL_CHANCREATEDON, channel
                else
                    if thing.channels[name]
                        thing = thing.channels[name].user(thing)
                    end

                    handle_mode thing, channel, value
                end
            else
                thing.send :numeric, ERR_NOSUCHCHANNEL, name
            end
        else
            if server.clients[name]
                handle_mode thing, server.clients[name], value
            else
                thing.send :numeric, ERR_NOSUCHNICK, name
            end
        end
    end
end

#names(thing, string) ⇒ Object



2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
# File 'lib/failirc/server/modules/Base.rb', line 2011

def names (thing, string)
    match = string.match(/NAMES\s+(.*)$/i)

    if !match
        thing.send :numeric, RPL_ENDOFNAMES, thing.nick
        return
    end

    channel = match[1].strip

    if channel = thing.channels[channel]
        users = String.new
        thing = channel.user(thing)

        channel.users.each_value {|user|
            if channel.modes[:auditorium] && !Utils::User::isLevelEnough(user, '%') && !Utils::checkFlag(thing, :operator)
                if user.modes[:level]
                    users << " #{user}"
                end
            else
                users << " #{user}"
            end
        }

        users = users[1, users.length]

        thing.send :numeric, RPL_NAMREPLY, {
            :channel => channel.name,
            :users   => users,
        }
    end

    thing.send :numeric, RPL_ENDOFNAMES, channel
end

#nick(thing, string) ⇒ Object



769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
# File 'lib/failirc/server/modules/Base.rb', line 769

def nick (thing, string)
    if !thing.is_a?(Client)
        return
    end

    match = string.match(/NICK\s+(:)?(.+)$/i)

    # no nickname was passed, so tell the user is a faggot
    if !match
        thing.send :numeric, ERR_NONICKNAMEGIVEN
        return
    end

    nick = match[2].strip

    if server.dispatcher.execute(:client_nick_change, thing, nick) == false
        if !thing.modes[:registered]
            thing.modes[:__warned] = nick
        end

        return
    end

    if !thing.modes[:registered]
        thing.nick = nick

        # try to register it
        Utils::registration(thing)
    else
        ok = true

        thing.channels.each_value {|channel|
            if channel.modes[:no_nick_change] && !Utils::User::isLevelEnough(channel.user(thing), '+')
                thing.send :numeric, ERR_NONICKCHANGE, channel.name
                ok = false
                break
            end
        }

        if !ok
            return false
        end

        server.data[:nicks].delete(nick)

        mask       = thing.mask.clone
        thing.nick = nick

        server.clients[thing.nick] = server.clients.delete(mask.nick)

        thing.channels.each_value {|channel|
            channel.users.add(channel.users.delete(mask.nick))
        }

        if thing.channels.empty?
            thing.send :raw, ":#{mask} NICK :#{nick}"
        else
            thing.channels.unique_users.send :raw, ":#{mask} NICK :#{nick}"
        end
    end
end

#normal_mode(kind, from, thing, type, mode, values, output = {:modes => [], :values => []}) ⇒ Object



1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
# File 'lib/failirc/server/modules/Base.rb', line 1048

def normal_mode (kind, from, thing, type, mode, values, output={:modes => [], :values => []})
    if kind != :normal
        return
    end

    if thing.is_a?(Server::Channel)
        case mode

        when 'a'
            if thing.type != '&' && thing.type != '!'
                server.dispatcher.execute :error, from, 'Only & and ! channels can use this mode.'
            end

            if Utils::checkFlag(from, :can_change_anonymous_mode)
                if Utils::checkFlag(thing, :a) == (type == '+')
                    return
                end

                Utils::setFlags(thing, :a, type == '+')

                output[:modes].push('a')
            end

        when 'b'
            if values.empty?
                thing.modes[:bans].each {|ban|
                    from.send :numeric, RPL_BANLIST, ban
                }
                
                from.send :numeric, RPL_ENDOFBANLIST, thing.name
                return
            end

            if Utils::checkFlag(from, :can_channel_ban)
                mask = Mask.parse(values.shift)

                if type == '+'
                    if !thing.modes[:bans].any? {|ban| ban == mask}
                        thing.modes[:bans].push(mask)
                    end
                else
                    result = thing.modes[:bans].reject! {|ban|
                        if ban == mask
                            true
                        end
                    }

                    if !result
                        mask = nil
                    end
                end

                if mask
                    output[:modes].push('b')
                    output[:values].push(mask.to_s)
                end
            else
                from.send :numeric, ERR_CHANOPRIVSNEEDED, thing.name
            end

        when 'c'
            if Utils::checkFlag(from, :can_change_nocolors_mode)
                if Utils::checkFlag(thing, :c) == (type == '+')
                    return
                end

                Utils::setFlags(thing, :c, type == '+')

                output[:modes].push('c')
            else
                from.send :numeric, ERR_CHANOPRIVSNEEDED, thing.name
            end

        when 'C'
            if Utils::checkFlag(from, :can_change_noctcp_mode)
                if Utils::checkFlag(thing, :C) == (type == '+')
                    return
                end

                Utils::setFlags(thing, :C, type == '+')

                output[:modes].push('C')
            else
                from.send :numeric, ERR_CHANOPRIVSNEEDED, thing.name
            end

        when 'e'
            if Utils::checkFlag(from, :can_add_ban_exception)
                mask = Mask.parse(values.shift)

                if type == '+'
                    if !thing.modes[:exceptions].any? {|exception| exception == mask}
                        thing.modes[:exceptions].push(mask)
                    end
                else
                    result = thing.modes[:exceptions].reject! {|exception|
                        if exception == mask
                            true
                        end
                    }

                    if !result
                        mask = nil
                    end
                end

                if mask
                    output[:modes].push('e')
                    output[:values].push(mask.to_s)
                end
            else
                from.send :numeric, ERR_CHANOPRIVSNEEDED, thing.name
            end

        when 'h'
            if Utils::checkFlag(from, :can_give_channel_half_operator)
                value = values.shift

                if !(user = thing.users[value])
                    from.send :numeric, ERR_NOSUCHNICK, value
                    return
                end

                if Utils::checkFlag(user, :h) == (type == '+')
                    return
                end

                Utils::User::setLevel(user, :h, (type == '+'))

                output[:modes].push('h')
                output[:values].push(value)
            else
                from.send :numeric, ERR_CHANOPRIVSNEEDED, thing.name
            end

        when 'i'
            if Utils::checkFlag(from, :can_change_invite_only_mode)
                if Utils::checkFlag(thing, :i) == (type == '+')
                    return
                end

                Utils::setFlags(thing, :i, type == '+')

                output[:modes].push('i')
            else
                from.send :numeric, ERR_CHANOPRIVSNEEDED, thing.name
            end

        when 'I'
            if Utils::checkFlag(from, :can_add_invitation)
                mask = Mask.parse(values.shift)

                if type == '+'
                    if !thing.modes[:invites].any? {|invitation| invitation == mask}
                        thing.modes[:invites].push(mask)
                    end
                else
                    result = thing.modes[:invites].reject! {|invitation|
                        if invitation == mask
                            true
                        end
                    }

                    if !result
                        mask = nil
                    end
                end

                if mask
                    output[:modes].push('I')
                    output[:values].push(mask.to_s)
                end
            else
                from.send :numeric, ERR_CHANOPRIVSNEEDED, thing.name
            end

        when 'k'
            if Utils::checkFlag(from, :can_change_channel_password)
                if type == '+' && (password = values.shift)
                    Utils::setFlags(thing, :k, true)

                    thing.modes[:password] = password
                else
                    password = thing.modes[:password]

                    Utils::setFlags(thing, :k, false)
                end

                if password
                    output[:modes].push('k')
                    output[:values].push(password)
                end
            else
                from.send :numeric, ERR_CHANOPRIVSNEEDED, thing.name
            end

        when 'K'
            if Utils::checkFlag(from, :can_change_noknock_mode)
                if Utils::checkFlag(thing, :K) == (type == '+')
                    return
                end

                Utils::setFlags(thing, :K, type == '+')

                output[:modes].push('K')
               
            else
                from.send :numeric, ERR_CHANOPRIVSNEEDED, thing.name
            end

        when 'l'
            if Utils::checkFlag(from, :can_change_limit_mode)
                if (!Utils::checkFlag(thing, :l) && type == '-') || (Utils::checkFlag(thing, :l) && type == '+')
                    return
                end

                if type == '+'
                    value = values.shift

                    if !value.match(/^\d+$/)
                        return
                    end

                    Utils::setFlags(thing, :l, value)

                    output[:modes].push('l')
                    output[:values].push(value)
                else
                    Utils::setFlags(thing, :l, false)

                    output[:modes].push('l')
                end
            else
                from.send :numeric, ERR_CHANOPRIVSNEEDED, thing.name
            end

        when 'L'
            if Utils::checkFlag(from, :can_change_redirect_mode)
                if (!Utils::checkFlag(thing, :L) && type == '-') || (Utils::checkFlag(thing, :L) && type == '+')
                    return
                end

                if type == '+'
                    value = values.shift

                    if !Utils::Channel::isValid(value)
                        return
                    end

                    Utils::setFlag(thing, :L, value)

                    output[:modes].push('L')
                    output[:values].push(value)
                else
                    Utils::setFlag(thing, :L, false)

                    output[:modes].push('L')
                end
            else
                from.send :numeric, ERR_CHANOPRIVSNEEDED, thing.name
            end

        when 'm'
            if Utils::checkFlag(from, :can_change_moderated_mode)
                if Utils::checkFlag(thing, :m) == (type == '+')
                    return
                end

                Utils::setFlags(thing, :m, type == '+')

                output[:modes].push('m')
            else
                from.send :numeric, ERR_CHANOPRIVSNEEDED, thing.name
            end

        when 'n'
            if Utils::checkFlag(from, :can_change_no_external_messages_mode)
                if Utils::checkFlag(thing, :n) == (type == '+')
                    return
                end

                Utils::setFlags(thing, :n, type == '+')

                output[:modes].push('n')
            else
                from.send :numeric, ERR_CHANOPRIVSNEEDED, thing.name
            end

        when 'N'
            if Utils::checkFlag(from, :can_change_no_nick_change_mode)
                if Utils::checkFlag(thing, :N) == (type == '+')
                    return
                end

                Utils::setFlags(thing, :N, type == '+')

                output[:modes].push('N')
            else
                from.send :numeric, ERR_CHANOPRIVSNEEDED, thing.name
            end

        when 'o'
            if Utils::checkFlag(from, :can_give_channel_operator)
                value = values.shift

                if !(user = thing.users[value])
                    from.send :numeric, ERR_NOSUCHNICK, value
                    return
                end

                if Utils::checkFlag(user, :o) == (type == '+')
                    return
                end

                Utils::User::setLevel(user, :o, (type == '+'))

                output[:modes].push('o')
                output[:values].push(value)
            else
                from.send :numeric, ERR_CHANOPRIVSNEEDED, thing.name
            end

        when 'Q'
            if Utils::checkFlag(from, :can_change_nokicks_mode)
                if Utils::checkFlag(thing, :Q) == (type == '+')
                    return
                end

                Utils::setFlags(thing, :Q, type == '+')

                output[:modes].push('Q')
            else
                from.send :numeric, ERR_CHANOPRIVSNEEDED, thing.name
            end

        when 's'
            if Utils::checkFlag(from, :can_change_secret_mode)
                if Utils::checkFlag(thing, :s) == (type == '+')
                    return
                end

                Utils::setFlags(thing, :s, type == '+')

                output[:modes].push('s')
            else
                from.send :numeric, ERR_CHANOPRIVSNEEDED, thing.name
            end

        when 'S'
            if Utils::checkFlag(from, :can_change_strip_colors_mode)
                if Utils::checkFlag(thing, :S) == (type == '+')
                    return
                end

                Utils::setFlags(thing, :S, type == '+')

                output[:modes].push('S')
            else
                from.send :numeric, ERR_CHANOPRIVSNEEDED, thing.name
            end

        when 't'
            if Utils::checkFlag(from, :can_change_topic_mode)
                if Utils::checkFlag(thing, :t) == (type == '+')
                    return
                end

                Utils::setFlags(thing, :t, type == '+')

                output[:modes].push('t')
            else
                from.send :numeric, ERR_CHANOPRIVSNEEDED, thing.name
            end

        when 'u'
            if Utils::checkFlag(from, :can_change_auditorium_mode)
                if Utils::checkFlag(thing, :u) == (type == '+')
                    return
                end

                Utils::setFlags(thing, :u, type == '+')

                output[:modes].push('u')
            else
                from.send :numeric, ERR_CHANOPRIVSNEEDED, thing.name
            end

        when 'v'
            if Utils::checkFlag(from, :can_give_voice)
                value = values.shift

                if !(user = thing.users[value])
                    from.send :numeric, ERR_NOSUCHNICK, value
                    return
                end

                if Utils::checkFlag(user, :v) == (type == '+')
                    return
                end

                Utils::User::setLevel(user, :v, (type == '+'))

                output[:modes].push('v')
                output[:values].push(value)
            else
                from.send :numeric, ERR_CHANOPRIVSNEEDED, thing.name
            end

        when 'V'
            if Utils::checkFlag(from, :can_change_noinvites_mode)
                if Utils::checkFlag(thing, :V) == (type == '+')
                    return
                end

                Utils::setFlags(thing, :V, type == '+')

                output[:modes].push('V')
            else
                from.send :numeric, ERR_CHANOPRIVSNEEDED, thing.name
            end

        when 'x'
            if Utils::checkFlag(from, :can_give_channel_owner)
                value = values.shift

                if !(user = thing.users[value])
                    from.send :numeric, ERR_NOSUCHNICK, value
                    return
                end

                if Utils::checkFlag(user, :x) == (type == '+')
                    return
                end

                Utils::User::setLevel(user, :x, (type == '+'))

                output[:modes].push('x')
                output[:values].push(value)
            else
                from.send :numeric, ERR_CHANOPRIVSNEEDED, thing.name
            end

        when 'y'
            if Utils::checkFlag(from, :can_give_channel_admin)
                value = values.shift

                if !(user = thing.users[value])
                    from.send :numeric, ERR_NOSUCHNICK, value
                    return
                end

                if Utils::checkFlag(user, :y) == (type == '+')
                    return
                end

                Utils::User::setLevel(user, :y, (type == '+'))

                output[:modes].push('y')
                output[:values].push(value)
            else
                from.send :numeric, ERR_CHANOPRIVSNEEDED, thing.name
            end

        when 'z'
            if Utils::checkFlag(from, :can_change_ssl_mode)
                if Utils::checkFlag(thing, :z) == (type == '+')
                    return
                end

                if type == '+'
                    ok = true

                    thing.users.each_value {|user|
                        if !Utils::checkFlag(user, :ssl)
                            ok = false
                            break
                        end
                    }

                    if ok
                        Utils::setFlags(thing, :z, true)
                    else
                        from.send :numeric, ERR_ALLMUSTUSESSL
                        return
                    end
                else
                    Utils::setFlags(thing, :z, false)
                end

                output[:modes].push('z')
            else
                from.send :numeric, ERR_CHANOPRIVSNEEDED, thing.name
            end
        end
    elsif thing.is_a?(Server::Client)
    end
end

#notice(thing, string) ⇒ Object



2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
# File 'lib/failirc/server/modules/Base.rb', line 2295

def notice (thing, string)
    match = string.match(/NOTICE\s+(.*?)\s+:(.*)$/i)

    if !match
        return
    end

    name    = match[1]
    message = match[2]

    if client = server.clients[name]
        Utils::dispatchMessage(:notice, thing, client, message)
    else
        if Utils::User::isLevel(name[0, 1])
            level   = name[0, 1]
            channel = name[1, name.length]
        else
            level   = nil
            channel = name
        end

        if !server.channels[channel]
            # unrealircd sends an error if it can't find nick/channel, what should I do?
            return
        end

        channel = server.channels[channel]

        if !channel.modes[:no_external_messages] || channel.user(thing)
            Utils::dispatchMessage(:notice, thing, channel, message, level)
        end
    end
end

#oper(thing, string) ⇒ Object



2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
# File 'lib/failirc/server/modules/Base.rb', line 2452

def oper (thing, string)
    match = string.match(/OPER\s+(.*?)(\s+(.*?))?$/i)

    if !match
        thing.send :numeric, ERR_NEEDMOREPARAMS, 'OPER'
        return
    end

    password = match[3] || match[1]
    name     = (match[3]) ? match[1] : nil

    mask = thing.mask.clone

    if name
        mask.nick = name
    end

    server.config.elements['config/operators'].elements.each('operator') {|element|
        if mask.match(element.attributes['mask']) && password == element.attributes['password']
            element.attributes['flags'].split(/,/).each {|flag|
                Utils::setFlags(thing, flag.to_sym, true, false, true)
            }

            thing.modes[:message] = 'is an IRC operator'

            thing.send :numeric, RPL_YOUREOPER
            thing.send :raw, ":#{server} MODE #{thing.nick} #{thing.modes}"
            return
        end
    }

    thing.send :numeric, ERR_NOOPERHOST
end

#output_encoding(event, thing, string) ⇒ Object



727
728
729
730
731
732
733
734
735
736
737
738
# File 'lib/failirc/server/modules/Base.rb', line 727

def output_encoding (event, thing, string)
    if event.chain != :output
        return
    end

    if thing.modes[:encoding]
        string.encode!(thing.modes[:encoding],
            :invalid => :replace,
            :undef   => :replace
        )
    end
end

#part(thing, string) ⇒ Object



1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
# File 'lib/failirc/server/modules/Base.rb', line 1761

def part (thing, string)
    match = string.match(/PART\s+(.+?)(\s+:(.*))?$/i)

    if !match
        thing.send :numeric, ERR_NEEDMOREPARAMS, 'PART'
        return
    end

    names   = match[1].split(/,/)
    message = match[3]

    names.each {|name|
        if !Utils::Channel::type(name)
            name = "##{name}"
        end

        channel = server.channels[name]

        if !channel
            thing.send :numeric, ERR_NOSUCHCHANNEL, name
        elsif !thing.channels[name]
            thing.send :numeric, ERR_NOTONCHANNEL, name
        else
            server.dispatcher.execute(:part, channel.user(thing), message)
        end
    }
end

#pass(thing, string) ⇒ Object



748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
# File 'lib/failirc/server/modules/Base.rb', line 748

def pass (thing, string)
    match = string.match(/PASS\s+(:)?(.+)$/i)

    if !match
        thing.send :numeric, ERR_NEEDMOREPARAMS, 'PASS'
    else
        thing.password = match[2]

        if thing.listen.attributes['password']
            if thing.password != thing.listen.attributes['password']
                server.dispatcher.execute(:error, thing, :close, 'Password mismatch')
                server.kill thing, 'Password mismatch'
                return
            end
        end

        # try to register it
        Utils::registration(thing)
    end
end

#ping(thing, string) ⇒ Object



863
864
865
866
867
868
869
870
871
872
873
874
875
# File 'lib/failirc/server/modules/Base.rb', line 863

def ping (thing, string)
    match = string.match(/PING\s+(.*)$/i)

    if !match
        thing.send :numeric, ERR_NOORIGIN
        return
    end

    thing.send :raw, ":#{server.host} PONG #{server.host} :#{match[1]}"

    # RFC isn't that clear about when this error should be shoot
    # thing.send :numeric, ERR_NOSUCHSERVER, match[1]
end

#pong(thing, string) ⇒ Object



877
878
879
880
881
882
883
884
885
886
887
888
889
890
# File 'lib/failirc/server/modules/Base.rb', line 877

def pong (thing, string)
    match = string.match(/PONG\s+(:)?(.*)$/i)

    if !match
        thing.send :numeric, ERR_NOORIGIN
        return
    end

    if match[2] == server.host
        @pingedOut.delete(thing.socket)
    else
        thing.send :numeric, ERR_NOSUCHSERVER, match[2]
    end
end

#privmsg(thing, string) ⇒ Object



2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
# File 'lib/failirc/server/modules/Base.rb', line 2188

def privmsg (thing, string)
    match = string.match(/PRIVMSG\s+(.*?)(\s+:(.*))?$/i)

    if !match
        thing.send :numeric, ERR_NORECIPIENT, 'PRIVMSG'
        return
    end

    if !match[3]
        thing.send :numeric, ERR_NOTEXTTOSEND
        return
    end

    receiver = match[1]
    message  = match[3]

    if Utils::Channel::isValid(receiver)
        channel = server.channels[receiver]

        if !channel
            thing.send :numeric, ERR_NOSUCHNICK, receiver
            return
        end

        thing = channel.user(thing) || thing

        if channel.modes[:moderated] && !Utils::checkFlag(thing, :can_talk)
            thing.send :numeric, ERR_YOUNEEDVOICE, channel.name
            return
        end

        if Utils::Channel::banned?(channel, thing)
            thing.send :numeric, ERR_YOUAREBANNED, channel.name
            return
        end

        if thing.is_a?(Server::User)
            Utils::dispatchMessage(:message, thing, channel, message)
        else
            if server.channels[receiver].modes[:no_external_messages]
                thing.send :numeric, ERR_NOEXTERNALMESSAGES, channel.name
            else
                Utils::dispatchMessage(:message, thing, channel, message)
            end
        end
    else
        client = server.clients[receiver]

        if !client
            thing.send :numeric, ERR_NOSUCHNICK, receiver
        else
            Utils::dispatchMessage(:message, thing, client, message)
        end
    end
end

#quit(thing, string) ⇒ Object



2517
2518
2519
2520
2521
2522
2523
2524
2525
# File 'lib/failirc/server/modules/Base.rb', line 2517

def quit (thing, string)
    match = /^QUIT((\s+)(:)?(.*)?)?$/i.match(string)

    user    = thing
    message = match[4] || user.nick
    text    = eval(Utils::escapeMessage(@messages[:quit]))

    server.kill(thing, text)
end

#rehashObject



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
# File 'lib/failirc/server/modules/Base.rb', line 293

def rehash
    if tmp = server.config.elements['config/modules/module[@name="Base"]/misc/pingTimeout']
        @pingTimeout = tmp.text.to_f
    else
        @pingTimeout = 60
    end

    if tmp = server.config.elements['config/modules/module[@name="Base"]/misc/nickAllowed']
        @nickAllowed = tmp.text
    else
        @nickAllowed = 'nick.match(/^[\w^`-]{1,23}$/)'
    end

    @messages = {}

    if tmp = server.config.elements['config/modules/module[@name="Base"]/messages/part']
        @messages[:part] = tmp.text
    else
        @messages[:part] = '#{message}'
    end

    if tmp = server.config.elements['config/modules/module[@name="Base"]/messages/quit']
        @messages[:quit] = tmp.text
    else
        @messages[:quit] = 'Quit: #{message}'
    end

    if tmp = server.config.elements['config/modules/module[@name="Base"]/messages/kill']
        @messages[:kill] = tmp.text
    else
        @messages[:kill] = 'Kill: #{(message && !message.empty?) ? message : \'No reason\'} (#{sender.nick})'
    end

    if tmp = server.config.elements['config/modules/module[@name="Base"]/messages/version']
        @messages[:version] = tmp.text
    else
        @messages[:version] = 'THE GAME'
    end
end

#send_ctcp(chain, kind, fromRef, toRef, type, message, level = nil) ⇒ Object



2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
# File 'lib/failirc/server/modules/Base.rb', line 2395

def send_ctcp (chain, kind, fromRef, toRef, type, message, level=nil)
    if chain != :output
        return
    end

    from = fromRef.value
    to   = toRef.value

    if to.is_a?(Server::User)
        name = to.channel.name

        if to.channel.modes[:anonymous]
            from = Mask.new 'anonymous', 'anonymous', 'anonymous.'
        end
    elsif to.is_a?(Server::Client)
        name = to.nick
    else
        return
    end

    if message
        text = "#{type} #{message}"
    else
        text = type
    end

    if kind == :message
        kind  = 'PRIVMSG'
        level = ''
    elsif kind == :notice
        kind = 'NOTICE'
    end

    if kind.is_a?(String)
        to.send :raw, ":#{from} #{kind} #{level}#{name} :\x01#{text}\x01"
    end
end

#send_error(thing, message, type = nil) ⇒ Object



2433
2434
2435
2436
2437
2438
2439
2440
# File 'lib/failirc/server/modules/Base.rb', line 2433

def send_error (thing, message, type=nil)
    case type
    when :close
        send_error(thing, "Closing Link: #{thing.nick}[#{thing.ip}] (#{message})")
    else
        thing.send :raw, "ERROR :#{message}"
    end
end

#send_kick(kicker, kicked, message) ⇒ Object



1858
1859
1860
1861
1862
1863
# File 'lib/failirc/server/modules/Base.rb', line 1858

def send_kick (kicker, kicked, message)
    kicked.channel.send :raw, ":#{kicker.mask} KICK #{kicked.channel} #{kicked.nick} :#{message}"

    kicked.channel.delete(kicked)
    kicked.client.channels.delete(kicked.channel)
end

#send_message(chain, fromRef, toRef, message) ⇒ Object



2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
# File 'lib/failirc/server/modules/Base.rb', line 2272

def send_message (chain, fromRef, toRef, message)
    if chain != :output
        return
    end

    from = fromRef.value
    to   = toRef.value

    if to.is_a?(Server::User)
        name = to.channel.name

        if to.channel.modes[:anonymous]
            from = Mask.new 'anonymous', 'anonymous', 'anonymous.'
        end
    elsif to.is_a?(Server::Client)
        name = to.nick
    else
        return
    end

    to.send :raw, ":#{from} PRIVMSG #{name} :#{message}"
end

#send_notice(chain, fromRef, toRef, message, level = nil) ⇒ Object



2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
# File 'lib/failirc/server/modules/Base.rb', line 2348

def send_notice (chain, fromRef, toRef, message, level=nil)
    if chain != :output
        return
    end

    from = fromRef.value
    to   = toRef.value

    if to.is_a?(Server::User)
        name = to.channel.name

        if to.channel.modes[:anonymous]
            from = Mask.new 'anonymous', 'anonymous', 'anonymous.'
        end
    elsif to.is_a?(Server::Client)
        name = to.nick
    else
        return
    end

    to.send :raw, ":#{from} NOTICE #{level}#{name} :#{message}"
end

#send_whois(thing, name) ⇒ Object



2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
# File 'lib/failirc/server/modules/Base.rb', line 2118

def send_whois (thing, name)
    if !server.clients[name]
        thing.send :numeric, ERR_NOSUCHNICK, name
        return
    end

    client = server.clients[name]

    thing.send :numeric, RPL_WHOISUSER, client

    if !client.channels.empty?
        channels = ''

        client.channels.each_value {|channel|
            if !channel.modes[:secret] || thing.channels[channel.name]
                channels << " #{channel.user(client).modes[:level]}#{channel.name}"
            end
        }

        channels = channels[1, channels.length]

        thing.send :numeric, RPL_WHOISCHANNELS, {
            :nick     => client.nick,
            :channels => channels,
        }
    end

    thing.send :numeric, RPL_WHOISSERVER, client

    if client.modes[:ssl]
        thing.send :numeric, RPL_USINGSSL, client
    end

    if client.modes[:away]
        thing.send :numeric, RPL_AWAY, client
    end

    if client.modes[:message]
        thing.send :numeric, RPL_WHOISOPERATOR, client
    end

    thing.send :numeric, RPL_WHOISIDLE, client
    thing.send :numeric, RPL_ENDOFWHOIS, client
end

#topic(thing, string) ⇒ Object



1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
# File 'lib/failirc/server/modules/Base.rb', line 1966

def topic (thing, string)
    match = string.match(/TOPIC\s+(.*?)(\s+:(.*))?$/i)

    if !match
        thing.send :numeric, ERR_NEEDMOREPARAMS, 'TOPIC'
        return
    end

    channel = match[1].strip

    if !server.channels[channel]
        thing.send :numeric, ERR_NOSUCHCHANNEL, channel
        return
    end

    channel = server.channels[channel]

    if !Utils::checkFlag(thing, :can_change_topic) && !thing.channels[channel.name] && !Utils::checkFlag(thing, :operator)
        thing.send :numeric, ERR_NOTONCHANNEL, channel
    else
        if match[2]
            topic = match[3].to_s

            if channel.modes[:t] && !Utils::checkFlag(channel.user(thing), :can_change_topic)
                thing.send :numeric, ERR_CHANOPRIVSNEEDED, channel
            else
                server.dispatcher.execute :topic_change, channel, topic, ref{:thing}
            end
        else
            if !channel.topic
                thing.send :numeric, RPL_NOTOPIC, channel
            else
                thing.send :numeric, RPL_TOPIC, channel.topic
                thing.send :numeric, RPL_TOPICSETON, channel.topic
            end
        end
    end
end

#topic_change(channel, topic, fromRef) ⇒ Object



2005
2006
2007
2008
2009
# File 'lib/failirc/server/modules/Base.rb', line 2005

def topic_change (channel, topic, fromRef)
    channel.topic = [fromRef.value, topic]

    channel.send :raw, ":#{channel.topic.setBy} TOPIC #{channel} :#{channel.topic}"
end

#unknown_command(event, thing, string) ⇒ Object



740
741
742
743
744
745
746
# File 'lib/failirc/server/modules/Base.rb', line 740

def unknown_command (event, thing, string)
    match = string.match(/^([^ ]+)/)

    if match && thing.modes[:registered]
        thing.send :numeric, ERR_UNKNOWNCOMMAND, match[1]
    end
end

#user(thing, string) ⇒ Object



845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
# File 'lib/failirc/server/modules/Base.rb', line 845

def user (thing, string)
    if thing.is_a?(Client)
        match = string.match(/USER\s+([^ ]+)\s+[^ ]+\s+[^ ]+\s+:(.+)$/i)

        if !match
            thing.send :numeric, ERR_NEEDMOREPARAMS, 'USER'
        else
            thing.user     = match[1]
            thing.realName = match[2]

            # try to register it
            Utils::registration(thing)
        end
    elsif thing.is_a?(Link)

    end
end

#user_part(user, message) ⇒ Object



1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
# File 'lib/failirc/server/modules/Base.rb', line 1789

def user_part (user, message)
    if user.client.modes[:quitting]
        return false
    end

    text = eval(Utils::escapeMessage(@messages[:part]))

    if user.channel.modes[:anonymous]
        mask = Mask.new 'anonymous', 'anonymous', 'anonymous.'
    else
        mask = user.mask
    end

    user.channel.send :raw, ":#{mask} PART #{user.channel} :#{text}"

    user.channel.delete(user)
    user.client.channels.delete(user.channel.name)
end

#version(thing, string) ⇒ Object



2446
2447
2448
2449
2450
# File 'lib/failirc/server/modules/Base.rb', line 2446

def version (thing, string)
    comments = eval(Utils::escapeMessage(@messages[:version]))

    thing.send :numeric, RPL_VERSION
end

#who(thing, string) ⇒ Object



2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
# File 'lib/failirc/server/modules/Base.rb', line 2076

def who (thing, string)
    match = string.match(/WHO\s+(.*?)(\s+o)?$/i)

    name = match[1].strip || '*'

    if match
        op = match[2]

        if Utils::Channel::isValid(name) && server.channels[name]
            channel = server.channels[name]

            channel.users.each_value {|user|
                thing.send :numeric, RPL_WHOREPLY, {
                    :channel => channel,
                    :user    => user,
                    :hops    => 0,
                }
            }
        else

        end
    end

    thing.send :numeric, RPL_ENDOFWHO, name
end

#whois(thing, string) ⇒ Object



2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
# File 'lib/failirc/server/modules/Base.rb', line 2102

def whois (thing, string)
    match = string.match(/WHOIS\s+(.+?)(\s+(.+?))?$/i)

    if !match
        thing.send :numeric, ERR_NEEDMOREPARAMS, 'WHOIS'
        return
    end

    names  = (match[3] || match[1]).strip.split(/,/)
    server = match[3] ? match[1].strip : nil

    names.each {|name|
        thing.server.dispatcher.execute(:whois, thing, name)
    }
end

#whowas(thing, string) ⇒ Object



2163
2164
2165
# File 'lib/failirc/server/modules/Base.rb', line 2163

def whowas (thing, string)
    thing.send :raw, 'PHONE'
end