Permalink
Browse files

Bunch of improvements

  • Loading branch information...
meh committed Feb 23, 2012
1 parent 003810f commit 5c238527f896d8944396665e8817dd23886afe52
@@ -23,9 +23,9 @@ Server
------
- Automatic encoding conversions, defaults to UTF-8. Choose the used encoding with the ENCODING command.
- Highly modular and event driven. The RFC protocol is implemented in a module.
-- Optimized dispatching with Fibers, Threads and nonblocking I/O.
+- Optimized dispatching with EventMachine.
- Supports SSL and creates automatically certificate and key if not given.
-- Easy to understand and edit XML configuration.
+- Easy to understand and edit YAML configuration.
Client
------
View
@@ -33,10 +33,6 @@ modules:
quit: "Quit: #{message}"
kill: "Killed by #{sender.nick}: #{message.empty? ? 'No reason' : message}"
- autotune:
- minimum: 10
- rate: 10
-
firewall:
cloaking:
View
@@ -63,6 +63,8 @@ def initialize (options={})
if @options[:modules]
@options[:modules].each {|name, data|
+ data = false if data == true
+
begin
mod = @modules.load(name, data || {})
@@ -75,7 +75,13 @@ def unbind
@server.delete(self)
unless @disconnected
- server.fire :disconnect, self, 'Client exited'
+ server.fire :disconnect, self, \
+ case EM.report_connection_error_status(@signature)
+ when Errno::ECONNRESET::Errno then 'Connection reset by peer'
+ when Errno::ETIMEDOUT::Errno then 'Ping timeout'
+ when Errno::EHOSTUNREACH::Errno then 'No route to host'
+ else 'Client exited'
+ end
end
end
@@ -117,8 +123,17 @@ def flush!
alias to_s ip
- def ssl!; @ssl = true; end
- def ssl?; @ssl; end
+ def ssl!
+ @ssl = true
+
+ if options[:ssl].is_a? Hash
+ start_tls(private_key_file: options[:ssl][:key], cert_chain_file: options[:ssl][:cert])
+ else
+ start_tls
+ end
+ end
+
+ def ssl?; @ssl; end
end
end; end
@@ -53,16 +53,11 @@ def start
@signature = EM.start_server options[:bind] || '0.0.0.0', options[:port], Client do |client|
client.instance_eval {
- ssl! if options[:ssl]
-
- if options[:ssl].is_a? Hash
- start_tls(private_key_file: options[:ssl][:key], cert_chain_file: options[:ssl][:cert])
- else
- start_tls
- end
-
@server = zelf
@server.add client
+
+ ssl! if options[:ssl]
+
@server.fire :connect, client
}
end
@@ -35,6 +35,12 @@
version '0.1.0'
identifier 'RFC 1460, 2810, 2811, 2812, 2813;'
+module Base::Commands
+ Ignore = [:PING, :PONG, :WHO, :MODE]
+ Unregistered = [:PASS, :NICK, :USER]
+ Unrepeatable = [:PASS, :USER]
+end
+
on :start do |server|
@mutex = RecursiveMutex.new
@joining = {}
@@ -85,7 +91,7 @@ def check_encoding (string)
result = false
encoding = string.encoding
- ['UTF-8', 'ISO-8859-1'].each {|encoding|
+ %w[UTF-8 ISO-8859-1].each {|encoding|
string.force_encoding(encoding)
if string.valid_encoding?
@@ -95,7 +101,7 @@ def check_encoding (string)
string.force_encoding(encoding)
- return result
+ result
end
# check encoding
@@ -195,23 +201,23 @@ def check_encoding (string)
end
# check for ping timeout and registration
- before priority: -100 do |event, thing, string|
+ before priority: -99 do |event, thing, string|
@mutex.synchronize {
@to_ping.delete(~thing)
@pinged_out.delete(~thing)
}
- if thing.client? && !event.alias?(:PING) && !event.alias?(:PONG) && !event.alias?(:WHO) && !event.alias?(:MODE)
+ if thing.client? && Commands::Ignore.none? { |a| event.alias?(a) }
thing.last_action = Action.new(thing, event, string)
end
# if the client tries to do something without having registered, kill it with fire
- if thing.incoming? && !event.alias?(:PASS) && !event.alias?(:NICK) && !event.alias?(:USER)
+ if thing.incoming? && Commands::Unregistered.none? { |a| event.alias?(a) }
thing.send_message ERR_NOTREGISTERED
skip
# if the client tries to reregister, kill it with fire
- elsif (event.alias?(:PASS) || event.alias?(:USER)) && !thing.incoming?
+ elsif !thing.incoming? && Commands::Unrepeatable.any? { |a| event.alias?(a) }
thing.send_message ERR_ALREADYREGISTRED
skip
@@ -231,6 +237,15 @@ def check_encoding (string)
end
end
+ on :cap do |thing, string|
+ whole, command = string.match(/CAP\s+(.*?)$/i).to_a
+
+ if !command
+ thing.send_message ERR_NEEDMOREPARAMS, :USER
+ else
+ end
+ end
+
on :away do |thing, string|
whole, message = string.match(/AWAY\s+(?::)(.*)$/i).to_a
@@ -300,7 +315,7 @@ def register (thing)
client: Support::Modes::Client,
channel: Support::Modes::Channel
- Support.to_hash.map {|(key, value)|
+ client.send_message RPL_ISUPPORT, Support.to_hash.map {|key, value|
value != true ? "#{key}=#{value}" : key
}.join(' ')
@@ -46,7 +46,7 @@ class User
halfop :h,
must: :give_channel_halfop,
inherits: :voice,
- powers: [:kick]
+ powers: [:kick, :give_channel_voice]
voice :v,
must: :give_channel_voice,
@@ -0,0 +1,39 @@
+# failirc, a fail IRC library.
+#
+# Copyleft meh. [http://meh.doesntexist.org | meh@paranoici.org]
+#
+# 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/>.
+
+version '0.0.1'
+identifier 'cap'
+
+Base::Commands::Unregistered << :CAP
+
+input {
+ aliases {
+ cap /^CAP( |$)/i
+ }
+
+ on :cap do |thing, string|
+ whole, command = string.match(/CAP\s+(.+)$/i)
+
+ if !command
+ thing.send_message ERR_NEEDMOREPARAMS, :CAP
+ else
+
+ end
+ end
+}
@@ -43,5 +43,5 @@
server.fire :log, "#{(event.chain == :input) ? '*IN* ' : '*OUT*'} #{thing} #{string.inspect}"
}
-input { before priority: -1000, &logger }
-output { after priority: 1000, &logger }
+input { before priority: -100, &logger }
+output { after priority: 100, &logger }
@@ -0,0 +1,41 @@
+# failirc, a fail IRC library.
+#
+# Copyleft meh. [http://meh.doesntexist.org | meh@paranoici.org]
+#
+# 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/>.
+
+version '0.0.1'
+identifier 'tls'
+
+Base::Commands::Unregistered << :STARTTLS
+
+RPL_STARTTLS = {
+ code: 670,
+ text: ':STARTTLS successful, go ahead with TLS handshake'
+}
+
+input {
+ aliases {
+ starttls /^STARTTLS( |$)/i
+ }
+
+ on :starttls do |thing, string|
+ next if thing.ssl?
+
+ thing.send_message RPL_STARTTLS
+ thing.ssl!
+ end
+}

0 comments on commit 5c23852

Please sign in to comment.