Skip to content

Commit

Permalink
fix nick handling
Browse files Browse the repository at this point in the history
fixes codekitchen#50

 * only auto-retry-nick change when connecting
 * serialize new nick to db when it is changed successfully
 * don't count a client's NICK command as successfully changing the
   nick
  • Loading branch information
ccutrer committed Nov 21, 2013
1 parent f412ead commit 2ad0902
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions lib/tkellem/bouncer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ def client_msg(client, msg)
@away[client] = msg.args.last
check_away_status
false
when 'NICK'
@nick = msg.args.last
true
when 'NAMES', 'WHO'
client
else
Expand Down Expand Up @@ -167,11 +164,19 @@ def server_msg(msg)
false
when '433'
# nick already in use, try another
change_nick("#{@nick}_")
false
attempted_nick = msg.args[1]
if attempted_nick == nick
@nick = "#{attempted_nick}_"
send_msg("NICK #{@nick}")
false
else
true
end
when 'NICK'
if msg.prefix == nick
if msg.prefix.split('!', 2).first == nick
@nick = msg.args.last
@network_user.nick = @nick
@network_user.save! if @network_user.changed?
end
true
when '352'
Expand Down Expand Up @@ -234,7 +239,7 @@ def connection_established(conn)
send_msg("CAP REQ :multi-prefix")
# TODO: support sending a real username, realname, etc
send_msg("USER #{@user.username} somehost tkellem :#{@user.name}@tkellem")
change_nick(@nick, true)
send_msg("NICK #{nick}")
send_msg("CAP END")
@connected_at = Time.now
end
Expand All @@ -254,12 +259,6 @@ def kill!

protected

def change_nick(new_nick, force = false)
return if !force && new_nick == @nick
@nick = new_nick
send_msg("NICK #{new_nick}")
end

def send_welcome(bouncer_conn)
@welcomes.each { |msg| msg.args[0] = nick; bouncer_conn.send_msg(msg) }
end
Expand Down

0 comments on commit 2ad0902

Please sign in to comment.