Permalink
Browse files

Fix few stuff

  • Loading branch information...
1 parent 202d940 commit 649d96f059d8b7ca5d7a494190eb5cf5556cbbf8 @meh committed Jul 13, 2011
@@ -57,7 +57,7 @@ def event (chain, what)
if what.is_a?(Symbol)
Event.new(self, chain, (@chains[chain][what] + @hooks.map {|hook| hook.chains[chain][what]}).flatten.compact, [what])
else
- callbacks = Hash.new { [] }
+ callbacks = Hash.new {|hash, key| hash[key] = [] }
(@hooks + [self]).each {|hook|
hook.chains[chain].each {|key, value|
@@ -68,7 +68,7 @@ def event (chain, what)
regexps, callbacks = callbacks.to_a.select {|(name, callbacks)|
!name.is_a?(Symbol)
}.select {|(regexp, callbacks)|
- what.to_s.match(regexp) rescue nil
+ what.to_s.match(regexp) rescue false
}.transpose
aliases = (regexps || []).flatten.compact.map {|regexp|
@@ -40,7 +40,7 @@ def on (thing, string)
end
def alias? (name)
- @aliases.member?(name.to_sym.downcase)
+ @aliases.member?(name.to_s.downcase.to_sym)
end
def call (*args, &block)
@@ -132,7 +132,7 @@ def interpolate (on=nil)
on.instance_eval("%{#{self}}")
end
rescue Exception => e
- debug e
+ IRC.debug e
self
end
end
@@ -388,9 +388,9 @@ class ThreadSafeHash < CaseInsensitiveHash
def self.def_threaded (*methods)
methods.each {|method|
define_method method do |*args, &block|
- @semaphore.synchronize {
- super
- }
+ @semaphore.synchronize {
+ super(*args, &block)
+ }
end
}
end
@@ -42,7 +42,7 @@ def initialize (data=nil)
end
end
- def method_missing (name, *args)
+ def method_missing (name, *args, &block)
name = name.to_s
begin
@@ -52,10 +52,14 @@ def method_missing (name, *args)
self[name]
end
rescue
- super
+ super(name.to_sym, *args, &block)
end
end
+ def each (&block)
+ @modes.values.uniq.each &block
+ end
+
memoize
def [] (name)
if !supports?(name)
@@ -113,10 +117,32 @@ def as (what)
@as = nil
end
+ def empty?
+ each {|mode|
+ return false if mode.enabled?
+ }
+
+ true
+ end
+
def to_hash
@modes
end
+ def to_s
+ modes = []
+ values = []
+
+ each {|mode|
+ next unless mode.enabled?
+
+ modes << mode.code
+ values << mode.value unless mode.value === false or mode.value === true
+ }
+
+ "+#{modes.join}#{" #{values.join(' ')}" if values}"
+ end
+
def inspect
@@definitions.to_s
end
@@ -32,7 +32,7 @@ def initialize (owner, path)
end
def load (name, options={})
- mod = Module.for(@owner).new
+ mod = Module.for(@owner).new(options)
$:.each {|path|
path = "#{path}/#{@path}/#{name}.rb"
View
@@ -17,11 +17,15 @@
# along with failirc. If not, see <http://www.gnu.org/licenses/>.
#++
+require 'resolv'
+
+require 'failirc/version'
require 'failirc/common/utils'
require 'failirc/common/events'
require 'failirc/common/workers'
require 'failirc/common/modules'
require 'failirc/common/modes'
+require 'failirc/common/mask'
require 'failirc/server/dispatcher'
@@ -30,7 +34,7 @@ module IRC
class Server
extend Forwardable
- attr_reader :options, :dispatcher
+ attr_reader :options, :dispatcher, :created_on
def_delegators :@dispatcher, :listen
def_delegators :@events, :register, :dispatch, :observe, :fire, :hook
@@ -40,6 +44,8 @@ class Server
def initialize (options={})
@options = HashWithIndifferentAccess.new(options)
+ @created_on = Time.new
+
@dispatcher = Dispatcher.new(self)
@events = Events.new(self)
@workers = Workers.new(self)
@@ -57,6 +63,10 @@ def initialize (options={})
mod = @modules.load(name, data)
if mod
+ mod.define_singleton_method :server do
+ self
+ end
+
hook mod
IRC.debug "#{name} loaded"
@@ -78,7 +78,7 @@ def do
return unless @running or not @clients
erroring.each {|client|
- client.kill 'Input/output error', force: true
+ client.disconnect 'Input/output error'
}
reading.each {|thing|
@@ -101,9 +101,7 @@ def clients
end
def wakeup (options = {})
- if options[:reset]
- @clients = nil
- end
+ @clients = nil if options[:reset]
@pipes.last.write '?'
end
@@ -46,9 +46,7 @@ def ssl?
end
def receive
- ap disconnected? or killed?
-
- return if disconnected? or killed?
+ return if disconnected?
begin
input = ''
@@ -63,15 +61,15 @@ def receive
@input.push(string)
}
rescue IOError
- kill 'Input/output error', :force => true
+ disconnect 'Input/output error', :force => true
rescue Errno::EBADF, Errno::EPIPE, OpenSSL::SSL::SSLError
- kill 'Client exited', :force => true
+ disconnect 'Client exited', :force => true
rescue Errno::ECONNRESET
- kill 'Connection reset by peer', :force => true
+ disconnect 'Connection reset by peer', :force => true
rescue Errno::ETIMEDOUT
- kill 'Ping timeout', :force => true
+ disconnect 'Ping timeout', :force => true
rescue Errno::EHOSTUNREACH
- kill 'No route to host', :force => true
+ disconnect 'No route to host', :force => true
rescue Exception => e
IRC.debug e
end
@@ -98,15 +96,15 @@ def flush
@last = nil
rescue IOError
- kill 'Input/output error', :force => true
+ disconnect 'Input/output error'
rescue Errno::EBADF, Errno::EPIPE, OpenSSL::SSL::SSLError
- kill 'Client exited', :force => true
+ disconnect 'Client exited'
rescue Errno::ECONNRESET
- kill 'Connection reset by peer', :force => true
+ disconnect 'Connection reset by peer'
rescue Errno::ETIMEDOUT
- kill 'Ping timeout', :force => true
+ disconnect 'Ping timeout'
rescue Errno::EHOSTUNREACH
- kill 'No route to host', :force => true
+ disconnect 'No route to host'
rescue Errno::EAGAIN, IO::WaitWritable
rescue Exception => e
IRC.debug e
@@ -133,20 +131,32 @@ def handle
}
end
- def kill (message, options={})
- return if killed? and !options[:force]
+ def disconnect (message, options={})
+ return if disconnected? and !options[:force]
- @killed = true
+ server.fire :disconnect, self, message
- server.fire :kill,
- end
+ IRC.debug "#{self} disconnecting because: #{message}"
- def killed?
- !!@killed
+ connected_to.clients.delete(self)
+ dispatcher.wakeup reset: true
+
+ unless disconnected?
+ flush
+ @socket.close
+ end
end
def disconnected?
- @socket.closed?
+ begin
+ @socket.closed?
+ rescue Exception
+ true
+ end
+ end
+
+ def to_s
+ "#{host}"
end
end
@@ -88,6 +88,10 @@ def accept
end
}
end
+
+ def to_s
+ "#{host}/#{port}"
+ end
end
end; end; end
Oops, something went wrong.

0 comments on commit 649d96f

Please sign in to comment.