tkellem 0.8.5 → 0.8.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/tkellem/bouncer.rb +13 -1
- data/lib/tkellem/irc_message.rb +1 -1
- data/lib/tkellem/tkellem_server.rb +4 -0
- data/lib/tkellem/version.rb +1 -1
- data/spec/irc_message_spec.rb +7 -0
- data/spec/irc_server_spec.rb +48 -2
- metadata +1 -1
data/lib/tkellem/bouncer.rb
CHANGED
@@ -87,6 +87,9 @@ class Bouncer
|
|
87
87
|
@away[client] = msg.args.last
|
88
88
|
check_away_status
|
89
89
|
false
|
90
|
+
when 'NICK'
|
91
|
+
@nick = msg.args.last
|
92
|
+
true
|
90
93
|
else
|
91
94
|
true
|
92
95
|
end
|
@@ -122,6 +125,15 @@ class Bouncer
|
|
122
125
|
# swallow it, we handle ping-pong from clients separately, in
|
123
126
|
# BouncerConnection
|
124
127
|
false
|
128
|
+
when '433'
|
129
|
+
# nick already in use, try another
|
130
|
+
change_nick("#{@nick}_")
|
131
|
+
false
|
132
|
+
when 'NICK'
|
133
|
+
if msg.prefix == nick
|
134
|
+
@nick = msg.args.last
|
135
|
+
end
|
136
|
+
true
|
125
137
|
else
|
126
138
|
true
|
127
139
|
end
|
@@ -183,7 +195,7 @@ class Bouncer
|
|
183
195
|
end
|
184
196
|
|
185
197
|
def send_welcome(bouncer_conn)
|
186
|
-
@welcomes.each { |msg| bouncer_conn.send_msg(msg) }
|
198
|
+
@welcomes.each { |msg| msg.args[0] = nick; bouncer_conn.send_msg(msg) }
|
187
199
|
end
|
188
200
|
|
189
201
|
def connect!
|
data/lib/tkellem/irc_message.rb
CHANGED
@@ -20,7 +20,7 @@ class IrcMessage < Struct.new(:prefix, :command, :args, :ctcp)
|
|
20
20
|
|
21
21
|
msg = self.new(prefix, command, args)
|
22
22
|
|
23
|
-
if args.last.match
|
23
|
+
if args.last.try(:match, %r{#{"\x01"}([^ ]+)([^\1]*)#{"\x01"}})
|
24
24
|
msg.ctcp = $1.upcase
|
25
25
|
msg.args[-1] = $2.strip
|
26
26
|
end
|
data/lib/tkellem/version.rb
CHANGED
data/spec/irc_message_spec.rb
CHANGED
@@ -21,6 +21,13 @@ describe IrcMessage, ".parse" do
|
|
21
21
|
line.args.should == ["#myroom", "http://google.com/"]
|
22
22
|
line.replay.should == orig
|
23
23
|
end
|
24
|
+
|
25
|
+
it "should parse with no arguments" do
|
26
|
+
line = IrcMessage.parse("AWAY")
|
27
|
+
line.command.should == "AWAY"
|
28
|
+
line.args.should == []
|
29
|
+
line.replay.should == "AWAY"
|
30
|
+
end
|
24
31
|
end
|
25
32
|
|
26
33
|
describe IrcMessage, "#with_timestamp" do
|
data/spec/irc_server_spec.rb
CHANGED
@@ -48,7 +48,12 @@ describe Bouncer, "connection" do
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def tk_server
|
51
|
-
|
51
|
+
$tk_server ||= TkellemServer.new
|
52
|
+
end
|
53
|
+
|
54
|
+
after(:each) do
|
55
|
+
$tk_server.stop if $tk_server
|
56
|
+
$tk_server = nil
|
52
57
|
end
|
53
58
|
|
54
59
|
def network_user(opts = {})
|
@@ -60,7 +65,7 @@ describe Bouncer, "connection" do
|
|
60
65
|
def bouncer(opts = {})
|
61
66
|
tk_server
|
62
67
|
network_user
|
63
|
-
@bouncer =
|
68
|
+
@bouncer = $tk_server.bouncers.values.last
|
64
69
|
if opts[:connect]
|
65
70
|
@server_conn = em(IrcServerConnection).new(@bouncer, false)
|
66
71
|
@server_conn.stub!(:send_data)
|
@@ -88,4 +93,45 @@ describe Bouncer, "connection" do
|
|
88
93
|
@client.receive_line("NICK some_other_nick")
|
89
94
|
@client.receive_line("USER #{@user.username}@#{@network.name} a b :c")
|
90
95
|
end
|
96
|
+
|
97
|
+
it "should attempt another nick if the default is taken" do
|
98
|
+
network_user(:nick => 'mynick')
|
99
|
+
bouncer
|
100
|
+
@server_conn = em(IrcServerConnection).new(@bouncer, false)
|
101
|
+
@server_conn.stub!(:send_data)
|
102
|
+
@bouncer.connection_established(@server_conn)
|
103
|
+
@server_conn.should_receive(:send_data).with("NICK mynick_\r\n")
|
104
|
+
@bouncer.server_msg(m ":server 433 * mynick :Nickname already in use")
|
105
|
+
@bouncer.nick.should == 'mynick_'
|
106
|
+
@bouncer.send :ready!
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should change nicks if a client sends nick after connecting" do
|
110
|
+
network_user(:nick => 'mynick')
|
111
|
+
bouncer(:connect => true)
|
112
|
+
@bouncer.server_msg(m ":mynick JOIN #t1")
|
113
|
+
client_connection
|
114
|
+
@client.should_receive(:send_msg).with(":mynick JOIN #t1")
|
115
|
+
@client.receive_line("PASS test123")
|
116
|
+
@client.receive_line("NICK mynick")
|
117
|
+
@client.receive_line("USER #{@user.username}@#{@network.name} a b :c")
|
118
|
+
@bouncer.nick.should == 'mynick'
|
119
|
+
@bouncer.client_msg(@client, m("NICK some_other"))
|
120
|
+
@bouncer.nick.should == 'some_other'
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should change nicks if a server forces nick change" do
|
124
|
+
network_user(:nick => 'mynick')
|
125
|
+
bouncer(:connect => true)
|
126
|
+
@bouncer.server_msg(m ":mynick JOIN #t1")
|
127
|
+
client_connection
|
128
|
+
@client.should_receive(:send_msg).with(":mynick JOIN #t1")
|
129
|
+
@client.receive_line("PASS test123")
|
130
|
+
@client.receive_line("NICK mynick")
|
131
|
+
@client.receive_line("USER #{@user.username}@#{@network.name} a b :c")
|
132
|
+
@bouncer.nick.should == 'mynick'
|
133
|
+
@client.should_receive(:send_msg).with(m ":mynick NICK some_other")
|
134
|
+
@bouncer.server_msg(m ":mynick NICK some_other")
|
135
|
+
@bouncer.nick.should == 'some_other'
|
136
|
+
end
|
91
137
|
end
|