3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 18:52:41 +01:00

avoid duplicate mode changes

This commit is contained in:
Jeremy Latt 2014-02-25 22:16:23 -08:00
parent 0d277025c1
commit 66f9b42125
3 changed files with 26 additions and 2 deletions

View File

@ -248,10 +248,16 @@ func (channel *Channel) applyModeFlag(client *Client, mode ChannelMode,
switch op { switch op {
case Add: case Add:
if channel.flags[mode] {
return false
}
channel.flags[mode] = true channel.flags[mode] = true
return true return true
case Remove: case Remove:
if !channel.flags[mode] {
return false
}
delete(channel.flags, mode) delete(channel.flags, mode)
return true return true
} }
@ -283,10 +289,16 @@ func (channel *Channel) applyModeMember(client *Client, mode ChannelMode,
switch op { switch op {
case Add: case Add:
if channel.members[target][mode] {
return false
}
channel.members[target][mode] = true channel.members[target][mode] = true
return true return true
case Remove: case Remove:
if !channel.members[target][mode] {
return false
}
channel.members[target][mode] = false channel.members[target][mode] = false
return true return true
} }
@ -318,6 +330,9 @@ func (channel *Channel) applyMode(client *Client, change *ChannelModeChange) boo
client.ErrNeedMoreParams("MODE") client.ErrNeedMoreParams("MODE")
return false return false
} }
if change.arg == channel.key {
return false
}
channel.key = change.arg channel.key = change.arg
return true return true
@ -333,7 +348,7 @@ func (channel *Channel) applyMode(client *Client, change *ChannelModeChange) boo
client.ErrNeedMoreParams("MODE") client.ErrNeedMoreParams("MODE")
return false return false
} }
if limit == 0 { if (limit == 0) || (limit == channel.userLimit) {
return false return false
} }

View File

@ -23,7 +23,7 @@ var (
) )
const ( const (
SEM_VER = "ergonomadic-1.2.2" SEM_VER = "ergonomadic-1.2.3"
CRLF = "\r\n" CRLF = "\r\n"
MAX_REPLY_LEN = 512 - len(CRLF) MAX_REPLY_LEN = 512 - len(CRLF)

View File

@ -525,16 +525,25 @@ func (m *ModeCommand) HandleServer(s *Server) {
case Invisible, ServerNotice, WallOps: case Invisible, ServerNotice, WallOps:
switch change.op { switch change.op {
case Add: case Add:
if target.flags[change.mode] {
continue
}
target.flags[change.mode] = true target.flags[change.mode] = true
changes = append(changes, change) changes = append(changes, change)
case Remove: case Remove:
if !target.flags[change.mode] {
continue
}
delete(target.flags, change.mode) delete(target.flags, change.mode)
changes = append(changes, change) changes = append(changes, change)
} }
case Operator, LocalOperator: case Operator, LocalOperator:
if change.op == Remove { if change.op == Remove {
if !target.flags[change.mode] {
continue
}
delete(target.flags, change.mode) delete(target.flags, change.mode)
changes = append(changes, change) changes = append(changes, change)
} }