diff --git a/server.go b/server.go index 508c496..e3383a0 100644 --- a/server.go +++ b/server.go @@ -335,11 +335,17 @@ func (s *Server) handleCommand(command string, args []string) { return } + // mIRC puts a colon in first place when changing nick, hexchat doesn't + suppliedNick := args[0] + if len(suppliedNick) >= 2 && suppliedNick[0] == ':' { + suppliedNick = suppliedNick[1:] + } + if s.clientNick() == "" { // allow set, as part of the login phase - s.upstreamLauncher.Self.Nick = args[0] + s.upstreamLauncher.Self.Nick = suppliedNick - } else if args[0] == s.clientNick() { + } else if suppliedNick == s.clientNick() { // Ignore // Required for compatibility with Lite IRC, which sends USER/NICK in the wrong order @@ -349,9 +355,12 @@ func (s *Server) handleCommand(command string, args []string) { defer s.ClientStateLock.Unlock() if s.upstream == nil { // Not yet connected, should be safe to change nick - s.upstreamLauncher.Self.Nick = args[0] + s.upstreamLauncher.Self.Nick = suppliedNick } else { // Need to disconnect/reconnect the upstream + s.writeClient(fmt.Sprintf(":%s!%s@%s NICK %s", s.clientNick(), s.clientNick(), s.clientNick(), suppliedNick)) // notify client about what they've done + s.upstreamLauncher.Self.Nick = suppliedNick + s.nickChangeAttempt++ s.upstream.Disconnect() }