blur 1.5.1 → 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/library/blur.rb +3 -1
- data/library/blur/client.rb +11 -10
- data/library/blur/handling.rb +2 -1
- data/library/blur/network.rb +8 -5
- data/library/blur/network/channel.rb +4 -0
- data/library/blur/network/connection.rb +27 -6
- data/library/blur/network/user.rb +4 -0
- data/library/blur/script.rb +4 -3
- data/library/blur/script/cache.rb +2 -2
- metadata +5 -15
data/library/blur.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'yaml'
|
4
|
+
require 'majic'
|
4
5
|
require 'socket'
|
5
6
|
require 'ostruct'
|
7
|
+
require 'openssl'
|
6
8
|
|
7
9
|
Dir.glob("#{File.dirname __FILE__}/blur/**/*.rb").each &method(:require)
|
8
10
|
|
9
11
|
module Blur
|
10
|
-
class << Version = [1,5,
|
12
|
+
class << Version = [1,5,2]
|
11
13
|
def to_s; join '.' end
|
12
14
|
end
|
13
15
|
|
data/library/blur/client.rb
CHANGED
@@ -15,9 +15,7 @@ module Blur
|
|
15
15
|
@callbacks = {}
|
16
16
|
@connected = true
|
17
17
|
|
18
|
-
@options[:networks].
|
19
|
-
@networks.<< Network.new options
|
20
|
-
end
|
18
|
+
@networks = @options[:networks].map { |options| Network.new options }
|
21
19
|
|
22
20
|
load_scripts
|
23
21
|
trap 2, &method(:quit)
|
@@ -35,7 +33,7 @@ module Blur
|
|
35
33
|
end
|
36
34
|
|
37
35
|
def got_command network, command
|
38
|
-
puts "<-
|
36
|
+
puts "<- #{network.inspect ^ :bold} | #{command}"
|
39
37
|
name = :"got_#{command.name.downcase}"
|
40
38
|
|
41
39
|
if respond_to? name
|
@@ -68,6 +66,7 @@ module Blur
|
|
68
66
|
end
|
69
67
|
|
70
68
|
@connected = false
|
69
|
+
unload_scripts
|
71
70
|
|
72
71
|
exit 0
|
73
72
|
end
|
@@ -78,15 +77,17 @@ module Blur
|
|
78
77
|
puts "Starting run loop ..."
|
79
78
|
|
80
79
|
while @connected
|
81
|
-
@networks.each do |network|
|
80
|
+
@networks.select(&:connected?).each do |network|
|
82
81
|
begin
|
83
82
|
network.transcieve
|
84
83
|
sleep 0.05
|
85
84
|
rescue StandardError => exception
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
85
|
+
if network.connected?
|
86
|
+
network.disconnect
|
87
|
+
emit :connection_terminated, network
|
88
|
+
end
|
89
|
+
|
90
|
+
puts "#{"Network error" ^ :red} (#{exception.class.name}): #{exception.message}"
|
90
91
|
end
|
91
92
|
end
|
92
93
|
end
|
@@ -103,7 +104,7 @@ module Blur
|
|
103
104
|
begin
|
104
105
|
script.__send__ name, *args if script.respond_to? name
|
105
106
|
rescue Exception => exception
|
106
|
-
puts "
|
107
|
+
puts ("#{File.basename script.path}:#{exception.line}" ^ :bold) + ": #{"error:" ^ :red} #{exception.message}"
|
107
108
|
end
|
108
109
|
end
|
109
110
|
end
|
data/library/blur/handling.rb
CHANGED
@@ -22,7 +22,7 @@ module Blur
|
|
22
22
|
|
23
23
|
if channel = network.channel_by_name(name)
|
24
24
|
users.each do |user|
|
25
|
-
user.channel = channel
|
25
|
+
user.channel = channel
|
26
26
|
channel.users << user
|
27
27
|
end
|
28
28
|
else
|
@@ -88,6 +88,7 @@ module Blur
|
|
88
88
|
if channel = network.channel_by_name(name)
|
89
89
|
user.name = command.sender.username
|
90
90
|
user.host = command.sender.hostname
|
91
|
+
user.channel = channel
|
91
92
|
|
92
93
|
channel.users << user
|
93
94
|
|
data/library/blur/network.rb
CHANGED
@@ -3,15 +3,18 @@
|
|
3
3
|
module Blur
|
4
4
|
class Network
|
5
5
|
class ConnectionError < StandardError; end
|
6
|
+
|
6
7
|
attr_accessor :options, :channels, :delegate, :connection
|
7
8
|
|
8
9
|
def connected?; @connection.established? end
|
9
10
|
|
11
|
+
def ssl?; @options[:secure] == true end
|
10
12
|
def host; @options[:hostname] end
|
11
|
-
def port; @options[:port] ||=
|
13
|
+
def port; @options[:port] ||= ssl? ? 6697 : 6667 end
|
12
14
|
|
13
15
|
def initialize options = {}
|
14
|
-
@options
|
16
|
+
@options = options
|
17
|
+
@channels = []
|
15
18
|
|
16
19
|
unless options[:nickname]
|
17
20
|
raise ArgumentError, "nickname is missing from the network's option block"
|
@@ -21,7 +24,6 @@ module Blur
|
|
21
24
|
@options[:realname] ||= @options[:username]
|
22
25
|
@options[:channels] ||= []
|
23
26
|
|
24
|
-
@channels = []
|
25
27
|
@connection = Connection.new self, host, port
|
26
28
|
end
|
27
29
|
|
@@ -43,6 +45,7 @@ module Blur
|
|
43
45
|
|
44
46
|
def connect
|
45
47
|
@connection.establish
|
48
|
+
@connection.enable_ssl OpenSSL::SSL::VERIFY_NONE if ssl?
|
46
49
|
|
47
50
|
transmit :PASS, @options[:password] if @options[:password]
|
48
51
|
transmit :NICK, @options[:nickname]
|
@@ -55,7 +58,7 @@ module Blur
|
|
55
58
|
|
56
59
|
def transmit name, *arguments
|
57
60
|
command = Command.new name, arguments
|
58
|
-
puts "->
|
61
|
+
puts "-> #{inspect ^ :bold} | #{command}"
|
59
62
|
|
60
63
|
@connection.transmit command
|
61
64
|
end
|
@@ -65,7 +68,7 @@ module Blur
|
|
65
68
|
end
|
66
69
|
|
67
70
|
def to_s
|
68
|
-
%{#<#{self.class.name} "#{host}:#{port}
|
71
|
+
%{#<#{self.class.name} "#{host}":#{port}>}
|
69
72
|
end
|
70
73
|
end
|
71
74
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Blur
|
4
4
|
class Network
|
5
5
|
class Connection
|
6
|
-
def established?; @socket and not
|
6
|
+
def established?; @socket and not @socket.closed? end
|
7
7
|
|
8
8
|
def initialize delegate, host = nil, port = nil
|
9
9
|
@host = host
|
@@ -17,11 +17,21 @@ module Blur
|
|
17
17
|
def establish
|
18
18
|
@socket = TCPSocket.new @host, @port
|
19
19
|
end
|
20
|
+
|
21
|
+
def enable_ssl validator
|
22
|
+
@secure = true
|
23
|
+
|
24
|
+
context = OpenSSL::SSL::SSLContext.new
|
25
|
+
context.set_params verify_mode: validator
|
26
|
+
|
27
|
+
sslsocket = OpenSSL::SSL::SSLSocket.new @socket, context
|
28
|
+
sslsocket.sync = true
|
29
|
+
sslsocket.connect_nonblock
|
30
|
+
end
|
20
31
|
|
21
32
|
def terminate
|
22
|
-
@socket.close
|
23
|
-
@
|
24
|
-
@buffer = ""
|
33
|
+
@socket = nil if @socket.close
|
34
|
+
@buffer.clear
|
25
35
|
@queue.clear
|
26
36
|
end
|
27
37
|
|
@@ -31,7 +41,7 @@ module Blur
|
|
31
41
|
|
32
42
|
def transcieve
|
33
43
|
readable, writable = IO.select [@socket], [@socket]
|
34
|
-
|
44
|
+
|
35
45
|
# If the socket is ready to recieve, do so.
|
36
46
|
if socket = readable.first
|
37
47
|
@buffer.<< socket.read_nonblock 512
|
@@ -44,7 +54,18 @@ module Blur
|
|
44
54
|
|
45
55
|
# If it's ready to write, do that too until the outoing queue is empty.
|
46
56
|
if socket = writable.first
|
47
|
-
|
57
|
+
while command = @queue.shift
|
58
|
+
socket.write_nonblock "#{command}\n"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
rescue Errno::EAGAIN, Errno::EWOULDBLOCK
|
63
|
+
puts "Insecure connection would block"
|
64
|
+
rescue OpenSSL::SSL::SSLError
|
65
|
+
if $!.message == "read would block"
|
66
|
+
puts "Secure connection would block"
|
67
|
+
else
|
68
|
+
raise $!
|
48
69
|
end
|
49
70
|
end
|
50
71
|
end
|
data/library/blur/script.rb
CHANGED
@@ -28,9 +28,10 @@ module Blur
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def unload!
|
31
|
-
|
32
|
-
|
31
|
+
cache.save if @cache
|
33
32
|
__send__ :unloaded if respond_to? :unloaded
|
33
|
+
|
34
|
+
@cache = nil
|
34
35
|
end
|
35
36
|
|
36
37
|
def script name
|
@@ -51,7 +52,7 @@ module Blur
|
|
51
52
|
module_eval File.read(@path), File.basename(@path), 0
|
52
53
|
@evaluated = true
|
53
54
|
rescue Exception => exception
|
54
|
-
puts "
|
55
|
+
puts "#{File.basename(@path) ^ :bold}:#{exception.line.to_s ^ :bold}: #{"error:" ^ :red} #{exception.message ^ :bold}"
|
55
56
|
end
|
56
57
|
end
|
57
58
|
end
|
@@ -12,7 +12,7 @@ module Blur
|
|
12
12
|
File.exists? "#{path}/#{name}.yml"
|
13
13
|
end
|
14
14
|
|
15
|
-
def [] key; @hash[key]
|
15
|
+
def [] key; @hash[key] end
|
16
16
|
def []= key, value; @hash[key] = value end
|
17
17
|
|
18
18
|
def initialize script
|
@@ -49,4 +49,4 @@ module Blur
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
52
|
-
end
|
52
|
+
end
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blur
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 1
|
7
|
-
- 5
|
8
|
-
- 1
|
9
|
-
version: 1.5.1
|
4
|
+
prerelease:
|
5
|
+
version: 1.5.2
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Mikkel Kroman
|
@@ -14,7 +10,7 @@ autorequire:
|
|
14
10
|
bindir: executables
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date: 2011-
|
13
|
+
date: 2011-02-05 00:00:00 +01:00
|
18
14
|
default_executable:
|
19
15
|
dependencies: []
|
20
16
|
|
@@ -30,7 +26,6 @@ files:
|
|
30
26
|
- library/blur.rb
|
31
27
|
- library/blur/client.rb
|
32
28
|
- library/blur/enhancements.rb
|
33
|
-
- library/blur/handling.rb
|
34
29
|
- library/blur/network.rb
|
35
30
|
- library/blur/network/channel.rb
|
36
31
|
- library/blur/network/command.rb
|
@@ -39,6 +34,7 @@ files:
|
|
39
34
|
- library/blur/script.rb
|
40
35
|
- library/blur/script/cache.rb
|
41
36
|
- library/blur/script/messageparsing.rb
|
37
|
+
- library/blur/handling.rb
|
42
38
|
has_rdoc: true
|
43
39
|
homepage:
|
44
40
|
licenses: []
|
@@ -53,23 +49,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
53
49
|
requirements:
|
54
50
|
- - ">="
|
55
51
|
- !ruby/object:Gem::Version
|
56
|
-
segments:
|
57
|
-
- 1
|
58
|
-
- 9
|
59
|
-
- 1
|
60
52
|
version: 1.9.1
|
61
53
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
54
|
none: false
|
63
55
|
requirements:
|
64
56
|
- - ">="
|
65
57
|
- !ruby/object:Gem::Version
|
66
|
-
segments:
|
67
|
-
- 0
|
68
58
|
version: "0"
|
69
59
|
requirements: []
|
70
60
|
|
71
61
|
rubyforge_project:
|
72
|
-
rubygems_version: 1.
|
62
|
+
rubygems_version: 1.5.0
|
73
63
|
signing_key:
|
74
64
|
specification_version: 3
|
75
65
|
summary: Extensible IRC library
|