modes: Correct mode argument handling, only first param is the modestring

This commit is contained in:
Daniel Oaks 2016-04-14 21:22:17 +10:00
parent 3cef5f2c9d
commit 4177522e74
1 changed files with 53 additions and 47 deletions

View File

@ -450,16 +450,21 @@ func ParseUserModeCommand(nickname Name, args []string) (Command, error) {
changes: make(ModeChanges, 0),
}
for _, modeChange := range args {
if len(modeChange) == 0 {
continue
// account for MODE command with no args to list things
if len(args) < 1 {
// don't do any further processing
return cmd, nil
}
op := ModeOp(modeChange[0])
if (op != Add) && (op != Remove) {
modeArg := args[0]
op := ModeOp(modeArg[0])
if (op == Add) || (op == Remove) {
modeArg = modeArg[1:]
} else {
return nil, ErrParseCommand
}
for _, mode := range modeChange[1:] {
for _, mode := range modeArg {
if mode == '-' || mode == '+' {
op = ModeOp(mode)
continue
@ -469,7 +474,6 @@ func ParseUserModeCommand(nickname Name, args []string) (Command, error) {
op: op,
})
}
}
return cmd, nil
}
@ -531,10 +535,10 @@ func ParseChannelModeCommand(channel Name, args []string) (Command, error) {
changes: make(ChannelModeChanges, 0),
}
for len(args) > 0 {
if len(args[0]) == 0 {
args = args[1:]
continue
// account for MODE command with no args to list things
if len(args) < 1 {
// don't do any further processing
return cmd, nil
}
modeArg := args[0]
@ -542,10 +546,11 @@ func ParseChannelModeCommand(channel Name, args []string) (Command, error) {
if (op == Add) || (op == Remove) {
modeArg = modeArg[1:]
} else {
op = List
return nil, ErrParseCommand
}
skipArgs := 1
currentArgIndex := 1
for _, mode := range modeArg {
if mode == '-' || mode == '+' {
op = ModeOp(mode)
@ -559,15 +564,16 @@ func ParseChannelModeCommand(channel Name, args []string) (Command, error) {
// TODO(dan): separate this into the type A/B/C/D args and use those lists here
case Key, BanMask, ExceptMask, InviteMask, UserLimit,
ChannelOperator, ChannelFounder, ChannelAdmin, Halfop, Voice:
if len(args) > skipArgs {
change.arg = args[skipArgs]
skipArgs += 1
if len(args) > currentArgIndex {
change.arg = args[currentArgIndex]
currentArgIndex++
} else {
// silently skip this mode
continue
}
}
cmd.changes = append(cmd.changes, change)
}
args = args[skipArgs:]
}
return cmd, nil
}