failirc 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/bin/failbot +162 -0
  2. data/bin/failircd +61 -0
  3. data/lib/failirc.rb +25 -0
  4. data/lib/failirc/client.rb +227 -0
  5. data/lib/failirc/client/channel.rb +98 -0
  6. data/lib/failirc/client/channels.rb +85 -0
  7. data/lib/failirc/client/client.rb +59 -0
  8. data/lib/failirc/client/clients.rb +43 -0
  9. data/lib/failirc/client/dispatcher.rb +209 -0
  10. data/lib/failirc/client/dispatcher/connectiondispatcher.rb +410 -0
  11. data/lib/failirc/client/dispatcher/event.rb +113 -0
  12. data/lib/failirc/client/dispatcher/eventdispatcher.rb +203 -0
  13. data/lib/failirc/client/module.rb +103 -0
  14. data/lib/failirc/client/modules/Base.rb +361 -0
  15. data/lib/failirc/client/modules/Logger.rb +89 -0
  16. data/lib/failirc/client/server.rb +89 -0
  17. data/lib/failirc/client/user.rb +66 -0
  18. data/lib/failirc/client/users.rb +100 -0
  19. data/lib/failirc/errors.rb +339 -0
  20. data/lib/failirc/extensions.rb +124 -0
  21. data/lib/failirc/mask.rb +117 -0
  22. data/lib/failirc/modes.rb +54 -0
  23. data/lib/failirc/responses.rb +360 -0
  24. data/lib/failirc/server.rb +266 -0
  25. data/lib/failirc/server/channel.rb +122 -0
  26. data/lib/failirc/server/channels.rb +84 -0
  27. data/lib/failirc/server/client.rb +100 -0
  28. data/lib/failirc/server/clients.rb +54 -0
  29. data/lib/failirc/server/dispatcher.rb +219 -0
  30. data/lib/failirc/server/dispatcher/connectiondispatcher.rb +477 -0
  31. data/lib/failirc/server/dispatcher/event.rb +113 -0
  32. data/lib/failirc/server/dispatcher/eventdispatcher.rb +196 -0
  33. data/lib/failirc/server/link.rb +50 -0
  34. data/lib/failirc/server/links.rb +49 -0
  35. data/lib/failirc/server/module.rb +103 -0
  36. data/lib/failirc/server/modules/Base.rb +2545 -0
  37. data/lib/failirc/server/modules/Cloaking.rb +170 -0
  38. data/lib/failirc/server/modules/Firewall.rb +104 -0
  39. data/lib/failirc/server/modules/Netlog.rb +67 -0
  40. data/lib/failirc/server/modules/Roulette.rb +78 -0
  41. data/lib/failirc/server/modules/TinyURL.rb +98 -0
  42. data/lib/failirc/server/modules/Translate.rb +62 -0
  43. data/lib/failirc/server/modules/WordFilter.rb +144 -0
  44. data/lib/failirc/server/user.rb +72 -0
  45. data/lib/failirc/server/users.rb +103 -0
  46. data/lib/failirc/sslutils.rb +74 -0
  47. data/lib/failirc/utils.rb +53 -0
  48. metadata +107 -0
@@ -0,0 +1,98 @@
1
+ # failirc, a fail IRC library.
2
+ #
3
+ # Copyleft meh. [http://meh.doesntexist.org | meh.ffff@gmail.com]
4
+ #
5
+ # This file is part of failirc.
6
+ #
7
+ # failirc is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Affero General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # failirc is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Affero General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License
18
+ # along with failirc. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ require 'failirc/utils'
21
+ require 'failirc/modes'
22
+
23
+ require 'failirc/client/users'
24
+
25
+ module IRC
26
+
27
+ class Client
28
+
29
+ class Channel
30
+ class Topic
31
+ attr_reader :server, :channel, :text, :setBy
32
+ attr_accessor :setOn
33
+
34
+ def initialize (channel)
35
+ @server = channel.server
36
+ @channel = channel
37
+ end
38
+
39
+ def to_s
40
+ text
41
+ end
42
+
43
+ def nil?
44
+ text.nil?
45
+ end
46
+ end
47
+
48
+ attr_reader :client, :server, :name, :type, :users, :modes, :topic
49
+ attr_accessor :createdOn
50
+
51
+ def initialize (server, name)
52
+ @client = server.client
53
+ @server = server
54
+ @name = name
55
+ @type = name[0, 1]
56
+
57
+ @createdOn = Time.now
58
+ @users = Users.new(self)
59
+ @modes = Modes.new
60
+ @topic = Topic.new(self)
61
+ end
62
+
63
+ def type
64
+ @name[0, 1]
65
+ end
66
+
67
+ def [] (user)
68
+ users[user]
69
+ end
70
+
71
+ def add (user)
72
+ users.add(user)
73
+ end
74
+
75
+ def delete (user)
76
+ users.delete(user)
77
+ end
78
+
79
+ def user (client)
80
+ return @users[client.nick]
81
+ end
82
+
83
+ def empty?
84
+ return @users.empty?
85
+ end
86
+
87
+ def send (*args)
88
+ users.send(*args)
89
+ end
90
+
91
+ def to_s
92
+ @name
93
+ end
94
+ end
95
+
96
+ end
97
+
98
+ end
@@ -0,0 +1,85 @@
1
+ # failirc, a fail IRC library.
2
+ #
3
+ # Copyleft meh. [http://meh.doesntexist.org | meh.ffff@gmail.com]
4
+ #
5
+ # This file is part of failirc.
6
+ #
7
+ # failirc is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Affero General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # failirc is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Affero General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License
18
+ # along with failirc. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ require 'failirc/utils'
21
+
22
+ require 'failirc/client/client'
23
+ require 'failirc/client/channel'
24
+
25
+ module IRC
26
+
27
+ class Client
28
+
29
+ class Channels < ThreadSafeHash
30
+ attr_reader :server
31
+
32
+ def initialize (server, *args)
33
+ @server = server
34
+
35
+ super(*args)
36
+ end
37
+
38
+ alias __delete delete
39
+
40
+ def delete (channel)
41
+ if channel.is_a?(Channel)
42
+ __delete(channel.name)
43
+ else
44
+ __delete(channel)
45
+ end
46
+ end
47
+
48
+ def add (channel)
49
+ self[channel.name] = channel
50
+ end
51
+
52
+ # get single users in the channels
53
+ def unique_users
54
+ result = {}
55
+
56
+ each_value {|channel|
57
+ channel.users.each {|nick, user|
58
+ result[nick] = user.client
59
+ }
60
+ }
61
+
62
+ return result
63
+ end
64
+
65
+ def to_s (thing=nil)
66
+ result = ''
67
+
68
+
69
+ if thing.is_a?(Client) || thing.is_a?(User)
70
+ each_value {|channel|
71
+ result << " #{channel.user(thing).modes[:level]}#{channel.name}"
72
+ }
73
+ else
74
+ each_value {|channel|
75
+ result << " #{channel.name}"
76
+ }
77
+ end
78
+
79
+ return result[1, result.length]
80
+ end
81
+ end
82
+
83
+ end
84
+
85
+ end
@@ -0,0 +1,59 @@
1
+ # failirc, a fail IRC library.
2
+ #
3
+ # Copyleft meh. [http://meh.doesntexist.org | meh.ffff@gmail.com]
4
+ #
5
+ # This file is part of failirc.
6
+ #
7
+ # failirc is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Affero General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # failirc is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Affero General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License
18
+ # along with failirc. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ require 'failirc/utils'
21
+ require 'failirc/modes'
22
+ require 'failirc/mask'
23
+
24
+ module IRC
25
+
26
+ class Client
27
+
28
+ class Client
29
+ attr_reader :client, :server, :modes, :mask
30
+ attr_accessor :realName
31
+
32
+ def initialize (server, mask)
33
+ @client = client
34
+ @server = server
35
+ @mask = mask
36
+
37
+ @modes = Modes.new
38
+ end
39
+
40
+ def nick
41
+ mask.nick
42
+ end
43
+
44
+ def user
45
+ mask.user
46
+ end
47
+
48
+ def host
49
+ mask.host
50
+ end
51
+
52
+ def to_s
53
+ mask.to_s
54
+ end
55
+ end
56
+
57
+ end
58
+
59
+ end
@@ -0,0 +1,43 @@
1
+ # failirc, a fail IRC library.
2
+ #
3
+ # Copyleft meh. [http://meh.doesntexist.org | meh.ffff@gmail.com]
4
+ #
5
+ # This file is part of failirc.
6
+ #
7
+ # failirc is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Affero General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # failirc is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Affero General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License
18
+ # along with failirc. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ require 'failirc/server/client'
21
+
22
+ module IRC
23
+
24
+ class Client
25
+
26
+ class Clients < Hash
27
+ attr_reader :client, :server
28
+
29
+ def initialize (server, *args)
30
+ @client = server.client
31
+ @server = server
32
+
33
+ super(*args)
34
+ end
35
+
36
+ def add (client)
37
+ self[client.nick] = client
38
+ end
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -0,0 +1,209 @@
1
+ # failirc, a fail IRC library.
2
+ #
3
+ # Copyleft meh. [http://meh.doesntexist.org | meh.ffff@gmail.com]
4
+ #
5
+ # This file is part of failirc.
6
+ #
7
+ # failirc is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Affero General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # failirc is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Affero General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License
18
+ # along with failirc. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ require 'failirc/client/dispatcher/connectiondispatcher'
21
+ require 'failirc/client/dispatcher/eventdispatcher'
22
+
23
+ module IRC
24
+
25
+ class Client
26
+
27
+ class Dispatcher
28
+ attr_reader :client, :connection, :event
29
+
30
+ def initialize (client)
31
+ @client = client
32
+
33
+ @connection = ConnectionDispatcher.new(self)
34
+ @event = EventDispatcher.new(self)
35
+
36
+ @intervals = {}
37
+ @timeouts = {}
38
+ end
39
+
40
+ def start
41
+ @started = true
42
+
43
+ @reading = Fiber.new {
44
+ while true
45
+ @connection.read
46
+
47
+ Fiber.yield
48
+ end
49
+ }
50
+
51
+ @cleaning = Fiber.new {
52
+ while true
53
+ @connection.clean
54
+
55
+ Fiber.yield
56
+ end
57
+ }
58
+
59
+ @handling = Fiber.new {
60
+ while true
61
+ @connection.handle
62
+
63
+ Fiber.yield
64
+ end
65
+ }
66
+
67
+ @writing = Fiber.new {
68
+ while true
69
+ @connection.write
70
+
71
+ Fiber.yield
72
+ end
73
+ }
74
+
75
+ @defaults = [@cleaning, @reading, @handling, @writing]
76
+
77
+ self.loop
78
+ end
79
+
80
+ def stop
81
+ if !@started
82
+ return
83
+ end
84
+
85
+ @started = false
86
+ @stopping = true
87
+
88
+ @event.finalize
89
+ @connection.finalize
90
+
91
+ @stopping = false
92
+ end
93
+
94
+ def loop
95
+ while true
96
+ @defaults.each {|fiber|
97
+ begin
98
+ fiber.resume
99
+ rescue FiberError
100
+ self.debug 'Something went deeply wrong in the dispatcher, aborting.'
101
+ Process::exit 23
102
+ rescue Exception => e
103
+ self.debug e
104
+ end
105
+ }
106
+
107
+ @intervals.each {|fiber, meta|
108
+ begin
109
+ if !@intervals[fiber]
110
+ raise FiberError
111
+ end
112
+
113
+ if meta[:at] <= Time.now
114
+ fiber.resume
115
+
116
+ meta[:at] += meta[:offset]
117
+ end
118
+ rescue FiberError
119
+ clearInterval meta
120
+ rescue Exception => e
121
+ self.debug e
122
+ end
123
+ }
124
+
125
+ @timeouts.each {|fiber, meta|
126
+ begin
127
+ if !@timeouts[fiber]
128
+ raise FiberError
129
+ end
130
+
131
+ if meta[:at] <= Time.now
132
+ fiber.resume
133
+
134
+ clearTimeout meta
135
+ end
136
+ rescue FiberError
137
+ clearTimeout meta
138
+ rescue Exception => e
139
+ self.debug e
140
+ end
141
+ }
142
+ end
143
+ end
144
+
145
+ def setTimeout (fiber, time)
146
+ @timeouts[fiber] = {
147
+ :fiber => fiber,
148
+ :at => Time.now + time,
149
+ :on => Time.now,
150
+ }
151
+ end
152
+
153
+ def clearTimeout (timeout)
154
+ @timeouts.delete(timeout[:fiber])
155
+ end
156
+
157
+ def setInterval (fiber, time)
158
+ @intervals[fiber] = {
159
+ :fiber => fiber,
160
+ :offset => time,
161
+ :at => Time.now + time,
162
+ :on => Time.now,
163
+ }
164
+ end
165
+
166
+ def clearInterval (interval)
167
+ @intervals.delete(interval[:fiber])
168
+ end
169
+
170
+ def servers
171
+ @connection.servers
172
+ end
173
+
174
+ def server (identifier)
175
+ @connection.server identifier
176
+ end
177
+
178
+ def input
179
+ @connection.input
180
+ end
181
+
182
+ def output
183
+ @connection.output
184
+ end
185
+
186
+ def disconnecting
187
+ @connection.disconnecting
188
+ end
189
+
190
+ def alias (*args)
191
+ @event.alias(*args)
192
+ end
193
+
194
+ def register (*args)
195
+ @event.register(*args)
196
+ end
197
+
198
+ def dispatch (*args)
199
+ @event.dispatch(*args)
200
+ end
201
+
202
+ def execute (*args)
203
+ @event.execute(*args)
204
+ end
205
+ end
206
+
207
+ end
208
+
209
+ end