mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-23 11:12:44 +01:00
Merge pull request #133 from slingamn/default_modes.2
implement #132 (configurable default channel modes)
This commit is contained in:
commit
97010461f7
2
.gitignore
vendored
2
.gitignore
vendored
@ -62,6 +62,8 @@ Temporary Items
|
|||||||
# Linux trash folder which might appear on any partition or disk
|
# Linux trash folder which might appear on any partition or disk
|
||||||
.Trash-*
|
.Trash-*
|
||||||
|
|
||||||
|
# vim swapfiles
|
||||||
|
*.swp
|
||||||
|
|
||||||
### Go ###
|
### Go ###
|
||||||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||||
|
@ -57,7 +57,7 @@ func NewChannel(s *Server, name string, addDefaultModes bool) *Channel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if addDefaultModes {
|
if addDefaultModes {
|
||||||
for _, mode := range DefaultChannelModes {
|
for _, mode := range s.defaultChannelModes {
|
||||||
channel.flags[mode] = true
|
channel.flags[mode] = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -217,6 +217,7 @@ type Config struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Channels struct {
|
Channels struct {
|
||||||
|
DefaultModes *string `yaml:"default-modes"`
|
||||||
Registration ChannelRegistrationConfig
|
Registration ChannelRegistrationConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
21
irc/modes.go
21
irc/modes.go
@ -149,6 +149,7 @@ var (
|
|||||||
supportedChannelModesString = SupportedChannelModes.String()
|
supportedChannelModesString = SupportedChannelModes.String()
|
||||||
|
|
||||||
// DefaultChannelModes are enabled on brand new channels when they're created.
|
// DefaultChannelModes are enabled on brand new channels when they're created.
|
||||||
|
// this can be overridden in the `channels` config, with the `default-modes` key
|
||||||
DefaultChannelModes = Modes{
|
DefaultChannelModes = Modes{
|
||||||
NoOutside, OpOnlyTopic,
|
NoOutside, OpOnlyTopic,
|
||||||
}
|
}
|
||||||
@ -385,6 +386,23 @@ func umodeHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ParseDefaultChannelModes parses the `default-modes` line of the config
|
||||||
|
func ParseDefaultChannelModes(config *Config) Modes {
|
||||||
|
if config.Channels.DefaultModes == nil {
|
||||||
|
// not present in config, fall back to compile-time default
|
||||||
|
return DefaultChannelModes
|
||||||
|
}
|
||||||
|
modeChangeStrings := strings.Split(strings.TrimSpace(*config.Channels.DefaultModes), " ")
|
||||||
|
modeChanges, _ := ParseChannelModeChanges(modeChangeStrings...)
|
||||||
|
defaultChannelModes := make(Modes, 0)
|
||||||
|
for _, modeChange := range modeChanges {
|
||||||
|
if modeChange.op == Add {
|
||||||
|
defaultChannelModes = append(defaultChannelModes, modeChange.mode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return defaultChannelModes
|
||||||
|
}
|
||||||
|
|
||||||
// ParseChannelModeChanges returns the valid changes, and the list of unknown chars.
|
// ParseChannelModeChanges returns the valid changes, and the list of unknown chars.
|
||||||
func ParseChannelModeChanges(params ...string) (ModeChanges, map[rune]bool) {
|
func ParseChannelModeChanges(params ...string) (ModeChanges, map[rune]bool) {
|
||||||
changes := make(ModeChanges, 0)
|
changes := make(ModeChanges, 0)
|
||||||
@ -392,6 +410,9 @@ func ParseChannelModeChanges(params ...string) (ModeChanges, map[rune]bool) {
|
|||||||
|
|
||||||
if 0 < len(params) {
|
if 0 < len(params) {
|
||||||
modeArg := params[0]
|
modeArg := params[0]
|
||||||
|
if len(modeArg) == 0 {
|
||||||
|
return changes, unknown
|
||||||
|
}
|
||||||
op := ModeOp(modeArg[0])
|
op := ModeOp(modeArg[0])
|
||||||
if (op == Add) || (op == Remove) {
|
if (op == Add) || (op == Remove) {
|
||||||
modeArg = modeArg[1:]
|
modeArg = modeArg[1:]
|
||||||
|
36
irc/modes_test.go
Normal file
36
irc/modes_test.go
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
// Copyright (c) 2017 Daniel Oaks
|
||||||
|
// released under the MIT license
|
||||||
|
|
||||||
|
package irc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestParseDefaultChannelModes(t *testing.T) {
|
||||||
|
nt := "+nt"
|
||||||
|
n := "+n"
|
||||||
|
empty := ""
|
||||||
|
tminusi := "+t -i"
|
||||||
|
|
||||||
|
var parseTests = []struct {
|
||||||
|
raw *string
|
||||||
|
expected Modes
|
||||||
|
}{
|
||||||
|
{&nt, Modes{NoOutside, OpOnlyTopic}},
|
||||||
|
{&n, Modes{NoOutside}},
|
||||||
|
{&empty, Modes{}},
|
||||||
|
{&tminusi, Modes{OpOnlyTopic}},
|
||||||
|
{nil, Modes{NoOutside, OpOnlyTopic}},
|
||||||
|
}
|
||||||
|
|
||||||
|
var config Config
|
||||||
|
for _, testcase := range parseTests {
|
||||||
|
config.Channels.DefaultModes = testcase.raw
|
||||||
|
result := ParseDefaultChannelModes(&config)
|
||||||
|
if !reflect.DeepEqual(result, testcase.expected) {
|
||||||
|
t.Errorf("expected modes %s, got %s", testcase.expected, result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -97,6 +97,7 @@ type Server struct {
|
|||||||
connectionThrottleMutex sync.Mutex // used when affecting the connection limiter, to make sure rehashing doesn't make things go out-of-whack
|
connectionThrottleMutex sync.Mutex // used when affecting the connection limiter, to make sure rehashing doesn't make things go out-of-whack
|
||||||
ctime time.Time
|
ctime time.Time
|
||||||
currentOpers map[*Client]bool
|
currentOpers map[*Client]bool
|
||||||
|
defaultChannelModes Modes
|
||||||
dlines *DLineManager
|
dlines *DLineManager
|
||||||
isupport *ISupportList
|
isupport *ISupportList
|
||||||
klines *KLineManager
|
klines *KLineManager
|
||||||
@ -205,6 +206,7 @@ func NewServer(configFilename string, config *Config, logger *logger.Manager) (*
|
|||||||
connectionThrottle: connectionThrottle,
|
connectionThrottle: connectionThrottle,
|
||||||
ctime: time.Now(),
|
ctime: time.Now(),
|
||||||
currentOpers: make(map[*Client]bool),
|
currentOpers: make(map[*Client]bool),
|
||||||
|
defaultChannelModes: ParseDefaultChannelModes(config),
|
||||||
limits: Limits{
|
limits: Limits{
|
||||||
AwayLen: int(config.Limits.AwayLen),
|
AwayLen: int(config.Limits.AwayLen),
|
||||||
ChannelLen: int(config.Limits.ChannelLen),
|
ChannelLen: int(config.Limits.ChannelLen),
|
||||||
@ -1620,6 +1622,8 @@ func (server *Server) rehash() error {
|
|||||||
server.accountRegistration = &accountReg
|
server.accountRegistration = &accountReg
|
||||||
server.channelRegistrationEnabled = config.Channels.Registration.Enabled
|
server.channelRegistrationEnabled = config.Channels.Registration.Enabled
|
||||||
|
|
||||||
|
server.defaultChannelModes = ParseDefaultChannelModes(config)
|
||||||
|
|
||||||
// set new sendqueue size
|
// set new sendqueue size
|
||||||
if config.Server.MaxSendQBytes != server.MaxSendQBytes {
|
if config.Server.MaxSendQBytes != server.MaxSendQBytes {
|
||||||
server.MaxSendQBytes = config.Server.MaxSendQBytes
|
server.MaxSendQBytes = config.Server.MaxSendQBytes
|
||||||
|
@ -137,6 +137,11 @@ accounts:
|
|||||||
|
|
||||||
# channel options
|
# channel options
|
||||||
channels:
|
channels:
|
||||||
|
# modes that are set when new channels are created
|
||||||
|
# +n is no-external-messages and +t is op-only-topic
|
||||||
|
# see /QUOTE HELP cmodes for more channel modes
|
||||||
|
default-modes: +nt
|
||||||
|
|
||||||
# channel registration - requires an account
|
# channel registration - requires an account
|
||||||
registration:
|
registration:
|
||||||
# can users register new channels?
|
# can users register new channels?
|
||||||
|
Loading…
Reference in New Issue
Block a user