support changing nicks (by reconnecting)

--HG--
branch : nmdc-ircfrontend
This commit is contained in:
. 2016-05-09 18:57:04 +12:00
parent 74e4f6cfa3
commit c35062a3df
2 changed files with 25 additions and 12 deletions

View File

@ -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

View File

@ -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 {
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()
}