From c35062a3df4b363656573aca6b8d52a379581608 Mon Sep 17 00:00:00 2001 From: "." <.@.> Date: Mon, 9 May 2016 18:57:04 +1200 Subject: [PATCH] support changing nicks (by reconnecting) --HG-- branch : nmdc-ircfrontend --- TODO.txt | 10 ---------- server.go | 27 +++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/TODO.txt b/TODO.txt index 4e314d6..d35aea2 100644 --- a/TODO.txt +++ b/TODO.txt @@ -2,16 +2,8 @@ BUGS ==== -- option (maybe default?) to always use Hub-Security's name for system messages in main chat, for mirc/atomic - -- flash of unstyled NMDC client tag - - - Combined solution: mandate hubsec nick parameter, request CTCP VERSION prior to connection, and then apply mirc/atomic-specific fixes - - /wrong/ password message shows up, but not if no password was given for a passworded nick -- we're making a malformed NMDC client tag (no V: part) - WISHLIST @@ -21,8 +13,6 @@ WISHLIST - automatic markdown bold/italic formatting -- support changing nick (via reconnecting) - - support WHOIS - respond to CTCP VERSION with the clienttag on behalf of other users diff --git a/server.go b/server.go index 85ba771..597ba69 100644 --- a/server.go +++ b/server.go @@ -57,6 +57,7 @@ type Server struct { recievedFirstServerMessage bool recievedCtcpVersion bool + nickChangeAttempt int } func NewServer(name string, upstream libnmdc.HubAddress, conn net.Conn) *Server { @@ -245,8 +246,18 @@ func (s *Server) upstreamWorker() { s.sendNames() // delay doing this until now } if hubEvent.StateChange == libnmdc.CONNECTIONSTATE_DISCONNECTED { - // Abandon thread. Don't try to autoreconnect at our level, the remote client can be responsible for that - s.DisconnectClient() + if s.nickChangeAttempt > 0 { + // If this was a nick change, reconnect /immediately/ + s.upstream = nil + s.clientState = CSRegistered + s.maybeStartUpstream() // launches new goroutine + + } else { + // Abandon thread. Don't try to autoreconnect at our level, the remote client can be responsible for that + s.DisconnectClient() + + } + return } case libnmdc.EVENT_HUBNAME_CHANGED: @@ -333,6 +344,18 @@ func (s *Server) handleCommand(command string, args []string) { // Required for compatibility with Lite IRC, which sends USER/NICK in the wrong order } else { + + s.ClientStateLock.Lock() + defer s.ClientStateLock.Unlock() + if s.upstream == nil { + // Not yet connected, should be safe to change nick + s.upstreamLauncher.Self.Nick = args[0] + } else { + // Need to disconnect/reconnect the upstream + s.nickChangeAttempt++ + s.upstream.Disconnect() + } + s.reply(rplKill, "Can't change nicks on this server.") s.DisconnectClient() }