From 6851901e200310958f5597a5df0a0e144f8d4834 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Thu, 15 Jul 2021 05:59:45 -0400 Subject: [PATCH] fix #1756 A default channel mode of +i would block channel creation; fix this by treating initial joins as SAJOINs. Note that it's nontrivial to detect initial join in (*Channel).Join, because having 0 members does not necessarily indicate a new channel. --- irc/channelmanager.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/irc/channelmanager.go b/irc/channelmanager.go index 7952682e..5d4f2cd7 100644 --- a/irc/channelmanager.go +++ b/irc/channelmanager.go @@ -117,12 +117,13 @@ func (cm *ChannelManager) Join(client *Client, name string, key string, isSajoin return errNoSuchChannel, "" } - channel, err := func() (*Channel, error) { + channel, err, newChannel := func() (*Channel, error, bool) { + var newChannel bool cm.Lock() defer cm.Unlock() if cm.purgedChannels.Has(casefoldedName) { - return nil, errChannelPurged + return nil, errChannelPurged, false } entry := cm.chans[casefoldedName] if entry == nil { @@ -130,11 +131,11 @@ func (cm *ChannelManager) Join(client *Client, name string, key string, isSajoin // enforce OpOnlyCreation if !registered && server.Config().Channels.OpOnlyCreation && !(isSajoin || client.HasRoleCapabs("chanreg")) { - return nil, errInsufficientPrivs + return nil, errInsufficientPrivs, false } // enforce confusables if !registered && (cm.chansSkeletons.Has(skeleton) || cm.registeredSkeletons.Has(skeleton)) { - return nil, errConfusableIdentifier + return nil, errConfusableIdentifier, false } entry = &channelManagerEntry{ channel: NewChannel(server, name, casefoldedName, registered), @@ -149,9 +150,10 @@ func (cm *ChannelManager) Join(client *Client, name string, key string, isSajoin entry.skeleton = skeleton } cm.chans[casefoldedName] = entry + newChannel = true } entry.pendingJoins += 1 - return entry.channel, nil + return entry.channel, nil, newChannel }() if err != nil { @@ -159,7 +161,7 @@ func (cm *ChannelManager) Join(client *Client, name string, key string, isSajoin } channel.EnsureLoaded() - err, forward = channel.Join(client, key, isSajoin, rb) + err, forward = channel.Join(client, key, isSajoin || newChannel, rb) cm.maybeCleanup(channel, true)