From c4da72d9249f6796a1a98e2718811f231a918bb8 Mon Sep 17 00:00:00 2001 From: Jonathan Schleifer Date: Sat, 10 Sep 2011 13:10:59 +0000 Subject: [PATCH] Add support for parsing NOTICE. FossilOrigin-Name: e7642f3cbb58d7c120ba2282081d99b062d15acfbb2aeadadaa3e77886aa4b60 --- src/IRCConnection.h | 7 +++++++ src/IRCConnection.m | 48 +++++++++++++++++++++++++++++++++++++++++++-- tests/test.m | 15 ++++++++++++++ 3 files changed, 68 insertions(+), 2 deletions(-) diff --git a/src/IRCConnection.h b/src/IRCConnection.h index 85c9343..b82844d 100644 --- a/src/IRCConnection.h +++ b/src/IRCConnection.h @@ -56,6 +56,13 @@ - (void)connection: (IRCConnection*)connection didReceivePrivateMessage: (OFString*)msg fromUser: (IRCUser*)user; +- (void)connection: (IRCConnection*)connection + didReceiveNotice: (OFString*)notice + fromUser: (IRCUser*)user; +- (void)connection: (IRCConnection*)connection + didReceiveNotice: (OFString*)notice + fromUser: (IRCUser*)user + inChannel: (IRCChannel*)channel; @end @interface IRCConnection: OFObject diff --git a/src/IRCConnection.m b/src/IRCConnection.m index 50405b6..c10273f 100644 --- a/src/IRCConnection.m +++ b/src/IRCConnection.m @@ -217,7 +217,7 @@ } /* PART */ - if ([action isEqual: @"part"] && split.count >= 3) { + if ([action isEqual: @"PART"] && split.count >= 3) { OFString *who = [split objectAtIndex: 0]; OFString *where = [split objectAtIndex: 2]; IRCUser *user; @@ -306,7 +306,6 @@ of_range(1, from.length - 1)]; msg = [line substringWithRange: of_range(pos + 2, line.length - pos - 2)]; - user = [IRCUser IRCUserWithString: from]; if (![to isEqual: nickname]) { @@ -334,6 +333,51 @@ continue; } + /* NOTICE */ + if ([action isEqual: @"NOTICE"] && split.count >= 4) { + OFString *from = [split objectAtIndex: 0]; + OFString *to = [split objectAtIndex: 2]; + IRCUser *user = nil; + OFString *notice; + size_t pos = from.length + 1 + + [[split objectAtIndex: 1] length] + 1 + + to.length; + + from = [from substringWithRange: + of_range(1, from.length - 1)]; + notice = [line substringWithRange: + of_range(pos + 2, line.length - pos - 2)]; + + if (![from containsString: @"!"] || [to isEqual: @"*"]) + /* System message - ignore for now */ + continue; + + user = [IRCUser IRCUserWithString: from]; + + if (![to isEqual: nickname]) { + IRCChannel *channel; + + channel = [channels objectForKey: to]; + + if ([delegate respondsToSelector: + @selector(connection:didReceiveNotice: + fromUser:inChannel:)]) + [delegate connection: self + didReceiveNotice: notice + fromUser: user + inChannel: channel]; + } else { + if ([delegate respondsToSelector: + @selector(connection:didReceiveNotice: + fromUser:)]) + [delegate connection: self + didReceiveNotice: notice + fromUser: user]; + } + + continue; + } + [pool releaseObjects]; } diff --git a/tests/test.m b/tests/test.m index 617a292..34f77f9 100644 --- a/tests/test.m +++ b/tests/test.m @@ -108,4 +108,19 @@ OF_APPLICATION_DELEGATE(TestApp) { of_log(@"(%@): %@", user, msg); } + +- (void)connection: (IRCConnection*)connection + didReceiveNotice: (OFString*)notice + fromUser: (IRCUser*)user +{ + of_log(@"NOTICE: (%@): %@", user, notice); +} + +- (void)connection: (IRCConnection*)connection + didReceiveNotice: (OFString*)notice + fromUser: (IRCUser*)user + inChannel: (IRCChannel*)channel +{ + of_log(@"NOTICE: [%@] %@: %@", channel, user, notice); +} @end