From 3b71be3bf0942c5825370ed579d66f01579c94d9 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Thu, 30 May 2019 05:33:59 -0400 Subject: [PATCH] fix #537 --- irc/channelmanager.go | 33 ++++++++++++++++++++++----------- irc/config.go | 3 ++- oragono.yaml | 4 ++++ 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/irc/channelmanager.go b/irc/channelmanager.go index ad07d1c6..8ceb390b 100644 --- a/irc/channelmanager.go +++ b/irc/channelmanager.go @@ -65,19 +65,30 @@ func (cm *ChannelManager) Join(client *Client, name string, key string, isSajoin return errNoSuchChannel } - cm.Lock() - entry := cm.chans[casefoldedName] - if entry == nil { - registered := cm.registeredChannels[casefoldedName] - entry = &channelManagerEntry{ - channel: NewChannel(server, name, registered), - pendingJoins: 0, + channel := func() *Channel { + cm.Lock() + defer cm.Unlock() + + entry := cm.chans[casefoldedName] + if entry == nil { + registered := cm.registeredChannels[casefoldedName] + // enforce OpOnlyCreation + if !registered && server.Config().Channels.OpOnlyCreation && !client.HasRoleCapabs("chanreg") { + return nil + } + entry = &channelManagerEntry{ + channel: NewChannel(server, name, registered), + pendingJoins: 0, + } + cm.chans[casefoldedName] = entry } - cm.chans[casefoldedName] = entry + entry.pendingJoins += 1 + return entry.channel + }() + + if channel == nil { + return errNoSuchChannel } - entry.pendingJoins += 1 - channel := entry.channel - cm.Unlock() channel.EnsureLoaded() channel.Join(client, key, isSajoin, rb) diff --git a/irc/config.go b/irc/config.go index a3ed6267..8897636d 100644 --- a/irc/config.go +++ b/irc/config.go @@ -320,7 +320,8 @@ type Config struct { Channels struct { DefaultModes *string `yaml:"default-modes"` defaultModes modes.Modes - MaxChannelsPerClient int `yaml:"max-channels-per-client"` + MaxChannelsPerClient int `yaml:"max-channels-per-client"` + OpOnlyCreation bool `yaml:"operator-only-creation"` Registration ChannelRegistrationConfig } diff --git a/oragono.yaml b/oragono.yaml index 35754dea..51415e84 100644 --- a/oragono.yaml +++ b/oragono.yaml @@ -368,6 +368,10 @@ channels: # how many channels can a client be in at once? max-channels-per-client: 100 + # if this is true, new channels can only be created by operators with the + # `chanreg` operator capability + operator-only-creation: false + # channel registration - requires an account registration: # can users register new channels?