Class: IRC::Server::Modules::Cloaking

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

Instance Attribute Summary

Attributes inherited from IRC::Server::Module

#server

Instance Method Summary collapse

Methods inherited from IRC::Server::Module

#finalize

Constructor Details

#initialize(server) ⇒ Cloaking

Returns a new instance of Cloaking.



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

def initialize (server)
    @aliases = {
        :output => {
            :NAMES => /:.*? 353 /,
        },

        :input => {
            :DISGUISEAS => /^DISGUISEAS( |$)/i,
        },
    }

    @events = {
        :custom => {
            :message => Event::Callback.new(self.method(:received_message), -100),
            :notice  => Event::Callback.new(self.method(:received_notice), -100),
            :ctcp    => Event::Callback.new(self.method(:received_ctcp), -100),

            :topic_change => Event::Callback.new(self.method(:topic_change), -100),
        },

        :output => {
            :NAMES => Event::Callback.new(self.method(:hide), -100),
        },

        :input => {
            :DISGUISEAS => self.method(:disguiseas),
        },
    }

    @disguises = {}

    super(server)
end

Instance Method Details

#_353(thing, string) ⇒ Object



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

def _353 (thing, string)
    if thing.modes[:operator]
        return
    end

    match = string.match(/353 .*?:(.*)$/)

    names = match[1].split(/\s+/)
    list  = ''

    names.each {|original|
        if Base::User::levels.has_value(original[0, 1])
            name = original[1, original.length]
        else
            name = original
        end

        if !server.clients[name]
            next
        end

        client = server.clients[name]

        if !(client.modes[:operator] && client.modes[:extended][:hide])
            list << " #{original}"
        end
    }

    string.sub!(/ :(.*)$/, " :#{list[1, list.length]}")
end

#disguise(fromRef) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/failirc/server/modules/Cloaking.rb', line 84

def disguise (fromRef)
    from = fromRef.value

    if from.modes[:operator]
        if @disguises[from].is_a?(Mask)
            fromRef.value = Client.new(server, @disguises[from])
        elsif tmp = server.clients[@disguises[from]]
            fromRef.value = tmp
        end
    end
end

#disguiseas(thing, string) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/failirc/server/modules/Cloaking.rb', line 63

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

    if !thing.modes[:operator]
        thing.send :numeric, ERR_NOPRIVILEGES
        return
    end

    if !match
        @disguises.delete(thing)
    else
        mask = match[1].strip

        if mask.match(/^.+!.+@.+$/)
            @disguises[thing] = Mask::parse(mask)
        else
            @disguises[thing] = mask
        end
    end
end

#hide(thing, string) ⇒ Object



124
125
126
127
128
129
130
131
132
# File 'lib/failirc/server/modules/Cloaking.rb', line 124

def hide (thing, string)
    match = string.match(/:.*? (\d+)/)

    if !match
        return
    end

    self.method("_#{match[1]}".to_sym).call(thing, string) rescue nil
end

#received_ctcp(chain, kind, fromRef, toRef, type, message, level) ⇒ Object



112
113
114
115
116
117
118
# File 'lib/failirc/server/modules/Cloaking.rb', line 112

def received_ctcp (chain, kind, fromRef, toRef, type, message, level)
    if chain != :input || fromRef.value.is_a?(Server)
        return
    end

    disguise(fromRef)
end

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



96
97
98
99
100
101
102
# File 'lib/failirc/server/modules/Cloaking.rb', line 96

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

    disguise(fromRef)
end

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



104
105
106
107
108
109
110
# File 'lib/failirc/server/modules/Cloaking.rb', line 104

def received_notice (chain, fromRef, toRef, message, level=nil)
    if chain != :input || fromRef.value.is_a?(Server)
        return
    end

    disguise(fromRef)
end

#topic_change(channel, topic, fromRef) ⇒ Object



120
121
122
# File 'lib/failirc/server/modules/Cloaking.rb', line 120

def topic_change (channel, topic, fromRef)
    disguise(fromRef)
end