Permalink
Browse files

Now stuff starts at least.

  • Loading branch information...
1 parent 850d78d commit 002fc8a3a6766bb41dde380ac25527f7a5f1238e @meh committed Jul 10, 2011
View
No changes.
View
@@ -0,0 +1,59 @@
+#! /usr/bin/env ruby
+# failirc, a fail IRC server.
+#
+# Copyleft meh. [http://meh.doesntexist.org | meh.ffff@gmail.com]
+#
+# This file is part of failirc.
+#
+# failirc is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published
+# by the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# failirc is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with failirc. If not, see <http://www.gnu.org/licenses/>.
+
+require 'failirc/server'
+require 'getoptlong'
+
+args = GetoptLong.new(
+ ['--version', '-v', GetoptLong::NO_ARGUMENT],
+ ['--verbose', '-V', GetoptLong::NO_ARGUMENT],
+ ['--config', '-f', GetoptLong::REQUIRED_ARGUMENT]
+)
+
+options = {
+ :verbose => false,
+ :config => '/etc/failircd.conf',
+}
+
+args.each {|option, value|
+ case option
+ when '--version'
+ puts "Fail IRCd #{IRC.version}"
+ exit 0
+
+ when '--verbose'
+ options[:verbose] = true
+
+ when '--config'
+ options[:config] = value
+ end
+}
+
+ircd = IRC::Server.new(YAML.parse_file(options[:config]).transform)
+
+[:INT, :KILL].each {|sig|
+ trap sig.to_s do
+ puts 'FailIRC stopping, bye'
+
+ ircd.stop
+ end
+}
+
+ircd.start
@@ -21,6 +21,10 @@
require 'failirc/common/events/callback'
require 'failirc/common/events/dsl'
+require 'failirc/common/events/aliases'
+require 'failirc/common/events/chains'
+require 'failirc/common/events/custom'
+
module IRC
class Events
@@ -29,9 +33,7 @@ class Events
def initialize (server)
@server = server
- @aliases = Aliases.new
- @chains = Chains.new
- @custom = Custom.new
+ DSL.initialize(self)
@hooks = []
end
@@ -34,3 +34,4 @@ def call (*args, &block)
end
end
+end; end
@@ -17,9 +17,11 @@
# along with failirc. If not, see <http://www.gnu.org/licenses/>.
#++
+require 'rubygems'
require 'thread'
require 'forwardable'
require 'versionub'
+require 'yaml'
class Object
def numeric?
@@ -118,26 +120,26 @@ def interpolate (on=nil)
end
end
-class InsensitiveStruct
- def initialize (data={})
- @data = {}
+module StructLike
+ def method_missing (id, *args)
+ @data ||= {}
- data.each {|name, value|
- self.send name, value
- }
- end
+ id = id.to_s.sub(/[=?]$/, '').to_sym
- def method_missing (id, *args, &block)
- name = id.to_s.downcase
-
- if name.end_with?('=')
- name[-1] = ''
- end
-
- if args.length > 0
- @data[name.to_sym] = args.shift
+ if args.length == 0
+ return @data[id]
else
- @data[name.to_sym]
+ if respond_to? "#{id}="
+ send "#{id}=", *args
+ else
+ value = (args.length > 1) ? args : args.first
+
+ if value.nil?
+ @data.delete(id)
+ else
+ @data[id] = value
+ end
+ end
end
end
@@ -146,6 +148,19 @@ def to_hash
end
end
+
+class InsensitiveStruct
+ include StructLike
+
+ def initialize (data={})
+ @data = {}
+
+ data.each {|name, value|
+ self.send name, value
+ }
+ end
+end
+
class Hash
# Return a new hash with all keys converted to strings.
def stringify_keys
@@ -27,7 +27,7 @@ class Workers
def initialize (parent, range = 2 .. 4)
@parent = parent
- @pool = ActionPool.new(:min_threads => range.begin, :max_threads => range.end)
+ @pool = ActionPool::Pool.new(:min_threads => range.begin, :max_threads => range.end)
end
def do (*args, &block)
@@ -17,8 +17,11 @@
# along with failirc. If not, see <http://www.gnu.org/licenses/>.
#++
-require 'failirc/server/dsl'
-require 'failirc/server/dispatchers'
+require 'failirc/common/utils'
+require 'failirc/common/events'
+require 'failirc/common/workers'
+
+require 'failirc/server/dispatcher'
module IRC
@@ -27,6 +30,7 @@ class Server
attr_reader :options, :dispatcher
+ def_delegators :@dispatcher, :start, :stop
def_delegators :@events, :register, :dispatch, :observe, :fire
def_delegators :@workers, :do
@@ -45,19 +45,21 @@ def initialize (server)
end
def start
- @started = true
+ @running = true
self.loop
end
def stop
- return unless @started
+ return unless @running
- @started = false
+ @running = false
+
+ wakeup
end
def loop
- while @started
+ while @running
self.do
end
end
@@ -71,15 +73,17 @@ def listen (options)
def do
reading, _, erroring = IO.select([@pipes.first] + clients + servers, nil, clients)
+ return unless @running
+
erroring.each {|client|
client.kill 'Input/output error', :force => true
}
reading.each {|thing|
case thing
- when Connections::Server then thing.accept
- when Connections::Client then thing.receive
- when IO then thing.read_nonblock(2048) rescue nil
+ when Dispatcher::Server then thing.accept
+ when Dispatcher::Client then thing.receive
+ when IO then thing.read_nonblock(2048) rescue nil
end
}
@@ -94,7 +98,7 @@ def clients
}.flatten
end
- def wakeup (options)
+ def wakeup (options = {})
if options[:reset]
@clients = nil
end

0 comments on commit 002fc8a

Please sign in to comment.