Skip to content

Commit

Permalink
Fix duplicate JOIN/PART msgs causing crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
hloeung committed Jun 7, 2024
1 parent 757864a commit 2d3d430
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions mm-go-irckit/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,14 @@ func (ch *channel) Part(u *User, text string) {

if _, ok := ch.usersIdx[u.ID()]; !ok {
ch.mu.Unlock()
for _, to := range ch.usersIdx {
if !to.Ghost && to.Nick != u.Nick {
to.Encode(msg) //nolint:errcheck
}
}

u.Encode(&irc.Message{
Prefix: ch.Prefix(),
Command: irc.ERR_NOTONCHANNEL,
Params: []string{ch.name},
Trailing: "User not on that channel",
})

return
}

Expand Down Expand Up @@ -338,20 +335,8 @@ func (ch *channel) Join(u *User) error {
return nil
}

msg := &irc.Message{
Prefix: u.Prefix(),
Command: irc.JOIN,
Params: []string{ch.name},
}

if _, exists := ch.usersIdx[u.ID()]; exists {
ch.mu.Unlock()
for _, to := range ch.usersIdx {
// only send join messages to real users
if !to.Ghost && to.Nick != u.Nick {
to.Encode(msg) //nolint:errcheck
}
}
return nil
}

Expand All @@ -369,6 +354,12 @@ func (ch *channel) Join(u *User) error {
return nil
}

msg := &irc.Message{
Prefix: u.Prefix(),
Command: irc.JOIN,
Params: []string{ch.name},
}

// send regular users a notification of the join
ch.mu.RLock()

Expand Down

0 comments on commit 2d3d430

Please sign in to comment.