From 8e1e22cbf75c40cf8441dbd83183864b5784638b Mon Sep 17 00:00:00 2001 From: Jonathan Schleifer Date: Fri, 9 Sep 2011 16:23:50 +0000 Subject: [PATCH] Add support for handling PART and fix parsing of JOIN. FossilOrigin-Name: 92093d341f66e0a9f0227e44f122b8caca3ced8aff1f50d88b4bb7d4a4a4ba81 --- src/IRCConnection.h | 16 ++++++++++------ src/IRCConnection.m | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/IRCConnection.h b/src/IRCConnection.h index b35f0ab..7eebd4b 100644 --- a/src/IRCConnection.h +++ b/src/IRCConnection.h @@ -31,19 +31,23 @@ @protocol IRCConnectionDelegate @optional -- (void)connection: (IRCConnection*)conn +- (void)connection: (IRCConnection*)connection didReceiveLine: (OFString*)line; -- (void)connection: (IRCConnection*)conn +- (void)connection: (IRCConnection*)connection didSendLine: (OFString*)line; -- (void)connectionWasEstablished: (IRCConnection*)conn; -- (void)connection: (IRCConnection*)conn +- (void)connectionWasEstablished: (IRCConnection*)connection; +- (void)connection: (IRCConnection*)connection didSeeUser: (IRCUser*)user joinChannel: (IRCChannel*)channel; -- (void)connection: (IRCConnection*)conn +- (void)connection: (IRCConnection*)connection + didSeeUser: (IRCUser*)user + leaveChannel: (IRCChannel*)channel + withReason: (OFString*)reason; +- (void)connection: (IRCConnection*)connection didReceiveMessage: (OFString*)msg fromUser: (IRCUser*)user inChannel: (IRCChannel*)channel; -- (void)connection: (IRCConnection*)conn +- (void)connection: (IRCConnection*)connection didReceivePrivateMessage: (OFString*)msg fromUser: (IRCUser*)user; @end diff --git a/src/IRCConnection.m b/src/IRCConnection.m index 2c702a3..801aa6a 100644 --- a/src/IRCConnection.m +++ b/src/IRCConnection.m @@ -182,9 +182,6 @@ who = [who substringWithRange: of_range(1, who.length - 1)]; - where = [where substringWithRange: - of_range(1, where.length - 1)]; - user = [IRCUser IRCUserWithString: who]; if ([who hasPrefix: @@ -204,6 +201,38 @@ continue; } + /* PART */ + if (splitted.count >= 3 && + [[splitted objectAtIndex: 1] isEqual: @"PART"]) { + OFString *who = [splitted objectAtIndex: 0]; + OFString *where = [splitted objectAtIndex: 2]; + IRCUser *user; + IRCChannel *channel; + OFString *reason = nil; + size_t pos = who.length + 1 + + [[splitted objectAtIndex: 1] length] + 1 + + where.length; + + who = [who substringWithRange: + of_range(1, who.length - 1)]; + user = [IRCUser IRCUserWithString: who]; + channel = [channels objectForKey: where]; + + if (splitted.count > 3) + reason = [line substringWithRange: + of_range(pos + 2, line.length - pos - 2)]; + + if ([delegate respondsToSelector: + @selector(connection:didSeeUser:leaveChannel: + withReason:)]) + [delegate connection: self + didSeeUser: user + leaveChannel: channel + withReason: reason]; + + continue; + } + /* PRIVMSG */ if (splitted.count >= 4 && [[splitted objectAtIndex: 1] isEqual: @"PRIVMSG"]) {