3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-26 05:49:25 +01:00
This commit is contained in:
Shivaram Lingamneni 2020-05-17 14:02:59 -04:00
parent 1ab06949bf
commit 2f9234318c
2 changed files with 21 additions and 6 deletions

View File

@ -564,7 +564,12 @@ func (channel *Channel) hasClient(client *Client) bool {
// <mode> <mode params>
func (channel *Channel) modeStrings(client *Client) (result []string) {
isMember := client.HasMode(modes.Operator) || channel.hasClient(client)
hasPrivs := client.HasMode(modes.Operator)
channel.stateMutex.RLock()
defer channel.stateMutex.RUnlock()
isMember := hasPrivs || channel.members[client] != nil
showKey := isMember && (channel.key != "")
showUserLimit := channel.userLimit > 0
@ -580,9 +585,6 @@ func (channel *Channel) modeStrings(client *Client) (result []string) {
mods += channel.flags.String()
channel.stateMutex.RLock()
defer channel.stateMutex.RUnlock()
result = []string{mods}
// args for flags with args: The order must match above to keep

View File

@ -134,6 +134,15 @@ func ParseDefaultUserModes(rawModes *string) modes.ModeChanges {
return modeChanges
}
// #1021: channel key must be valid as a non-final parameter
func validateChannelKey(key string) bool {
// empty string is valid in this context because it unsets the mode
if len(key) == 0 {
return true
}
return key[0] != ':' && strings.IndexByte(key, ' ') == -1
}
// ApplyChannelModeChanges applies a given set of mode changes.
func (channel *Channel) ApplyChannelModeChanges(client *Client, isSamode bool, changes modes.ModeChanges, rb *ResponseBuffer) (applied modes.ModeChanges) {
// so we only output one warning for each list type when full
@ -244,8 +253,12 @@ func (channel *Channel) ApplyChannelModeChanges(client *Client, isSamode bool, c
case modes.Key:
switch change.Op {
case modes.Add:
if validateChannelKey(change.Arg) {
channel.setKey(change.Arg)
applied = append(applied, change)
} else {
rb.Add(nil, client.server.name, ERR_INVALIDMODEPARAM, details.nick, "*", fmt.Sprintf(client.t("Invalid mode %[1]s parameter: %[2]s"), string(change.Mode), change.Arg))
}
case modes.Remove:
channel.setKey("")
applied = append(applied, change)