Fixed logic bug, but it's a bit ugly :-/

This commit is contained in:
Alex Bramley 2011-08-24 14:39:27 +01:00
parent 4c0f62666d
commit d74fd18d3d
2 changed files with 8 additions and 8 deletions

View File

@ -125,7 +125,12 @@ func (conn *Conn) h_PART(line *Line) {
ch := conn.GetChannel(line.Args[0]) ch := conn.GetChannel(line.Args[0])
n := conn.GetNick(line.Nick) n := conn.GetNick(line.Nick)
if ch != nil && n != nil { if ch != nil && n != nil {
if _, ok := ch.Nicks[n]; ok {
ch.DelNick(n) ch.DelNick(n)
} else {
conn.error("irc.PART(): nick %s is not on channel %s",
line.Nick, line.Args[0])
}
} else { } else {
conn.error("irc.PART(): buh? PART of channel %s by nick %s", conn.error("irc.PART(): buh? PART of channel %s by nick %s",
line.Args[0], line.Nick) line.Args[0], line.Nick)

View File

@ -227,14 +227,9 @@ func TestPART(t *testing.T) {
} }
// Test error states. // Test error states.
// TODO(fluffle): BUG? // Part a known user from a known channel they are not on.
// user1 is still a known Nick (on #test2), but receiving another PART
// for user1 from #test1 (or, in fact, a PART on any known Channel, whether
// they are on it or not) won't cause an error because h_PART doesn't
// check whether the Nick is on the Channel before calling DelNick().
// The Nick and Channel structs should expose more of the state info.
c.h_PART(parseLine(":user1!ident1@host1.com PART #test1 :Bye!")) c.h_PART(parseLine(":user1!ident1@host1.com PART #test1 :Bye!"))
c.ExpectNoErrors() c.ExpectError()
// Part an unknown user from a known channel. // Part an unknown user from a known channel.
c.h_PART(parseLine(":user2!ident2@host2.com PART #test1 :Bye!")) c.h_PART(parseLine(":user2!ident2@host2.com PART #test1 :Bye!"))