@@ -186,12 +186,13 @@ [_channels removeObjectForKey: channel]; } - (void)sendLine: (OFString*)line { - [_delegate connection: self - didSendLine: line]; + if ([_delegate respondsToSelector: @selector(connection:didSendLine:)]) + [_delegate connection: self + didSendLine: line]; [_socket writeLine: line]; } - (void)sendLineWithFormat: (OFConstantString*)format, ... @@ -252,12 +253,14 @@ - (void)IRC_processLine: (OFString*)line { OFArray *components; OFString *action = nil; - [_delegate connection: self - didReceiveLine: line]; + if ([_delegate respondsToSelector: + @selector(connection:didReceiveLine:)]) + [_delegate connection: self + didReceiveLine: line]; components = [line componentsSeparatedByString: @" "]; /* PING */ if ([components count] == 2 && @@ -272,11 +275,14 @@ action = [[components objectAtIndex: 1] uppercaseString]; /* Connected */ if ([action isEqual: @"001"] && [components count] >= 4) { - [_delegate connectionWasEstablished: self]; + if ([_delegate respondsToSelector: + @selector(connectionWasEstablished:)]) + [_delegate connectionWasEstablished: self]; + return; } /* JOIN */ if ([action isEqual: @"JOIN"] && [components count] == 3) { @@ -296,13 +302,15 @@ } else channel = [_channels objectForKey: where]; [channel addObject: [user nickname]]; - [_delegate connection: self - didSeeUser: user - joinChannel: where]; + if ([_delegate respondsToSelector: + @selector(connection:didSeeUser:joinChannel:)]) + [_delegate connection: self + didSeeUser: user + joinChannel: where]; return; } /* NAMES reply */ @@ -339,12 +347,14 @@ of_range(1, [user length] - 1)]; [channel addObject: user]; } - [_delegate connection: self - didReceiveNamesForChannel: where]; + if ([_delegate respondsToSelector: + @selector(connection:didReceiveNamesForChannel:)]) + [_delegate connection: self + didReceiveNamesForChannel: where]; return; } /* PART */ @@ -365,14 +375,16 @@ reason = [line substringWithRange: of_range(pos + 2, [line length] - pos - 2)]; [channel removeObject: [user nickname]]; - [_delegate connection: self - didSeeUser: user - leaveChannel: where - reason: reason]; + if ([_delegate respondsToSelector: + @selector(connection:didSeeUser:leaveChannel:reason:)]) + [_delegate connection: self + didSeeUser: user + leaveChannel: where + reason: reason]; return; } /* KICK */ @@ -395,15 +407,17 @@ reason = [line substringWithRange: of_range(pos + 2, [line length] - pos - 2)]; [channel removeObject: [user nickname]]; - [_delegate connection: self - didSeeUser: user - kickUser: whom - channel: where - reason: reason]; + if ([_delegate respondsToSelector: + @selector(connection:didSeeUser:kickUser:channel:reason:)]) + [_delegate connection: self + didSeeUser: user + kickUser: whom + channel: where + reason: reason]; return; } /* QUIT */ @@ -425,13 +439,15 @@ enumerator = [_channels objectEnumerator]; while ((channel = [enumerator nextObject]) != nil) [channel removeObject: [user nickname]]; - [_delegate connection: self - didSeeUserQuit: user - reason: reason]; + if ([_delegate respondsToSelector: + @selector(connection:didSeeUserQuit:reason:)]) + [_delegate connection: self + didSeeUserQuit: user + reason: reason]; return; } /* NICK */ @@ -459,13 +475,15 @@ [channel removeObject: [user nickname]]; [channel addObject: nickname]; } } - [_delegate connection: self - didSeeUser: user - changeNicknameTo: nickname]; + if ([_delegate respondsToSelector: + @selector(connection:didSeeUser:changeNicknameTo:)]) + [_delegate connection: self + didSeeUser: user + changeNicknameTo: nickname]; return; } /* PRIVMSG */ @@ -481,19 +499,24 @@ 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]) - [_delegate connection: self - didReceiveMessage: msg - channel: to - user: user]; - else - [_delegate connection: self - didReceivePrivateMessage: msg - user: user]; + if (![to isEqual: _nickname]) { + if ([_delegate respondsToSelector: @selector(connection: + didReceiveMessage:channel:user:)]) + [_delegate connection: self + didReceiveMessage: msg + channel: to + user: user]; + } else { + if ([_delegate respondsToSelector: @selector(connection: + didReceivePrivateMessage:user:)]) + [_delegate connection: self + didReceivePrivateMessage: msg + user: user]; + } return; } /* NOTICE */ @@ -515,19 +538,24 @@ return; } user = [IRCUser IRCUserWithString: from]; - if (![to isEqual: _nickname]) - [_delegate connection: self - didReceiveNotice: notice - channel: to - user: user]; - else - [_delegate connection: self - didReceiveNotice: notice - user: user]; + if (![to isEqual: _nickname]) { + if ([_delegate respondsToSelector: @selector(connection: + didReceiveNotice:channel:user:)]) + [_delegate connection: self + didReceiveNotice: notice + channel: to + user: user]; + } else { + if ([_delegate respondsToSelector: + @selector(connection:didReceiveNotice:user:)]) + [_delegate connection: self + didReceiveNotice: notice + user: user]; + } return; } } @@ -582,91 +610,7 @@ } - (OFSet*)usersInChannel: (OFString*)channel { return [[[_channels objectForKey: channel] copy] autorelease]; -} -@end - -@implementation OFObject (IRCConnectionDelegate) -- (void)connection: (IRCConnection*)connection - didReceiveLine: (OFString*)line -{ -} - -- (void)connection: (IRCConnection*)connection - didSendLine: (OFString*)line -{ -} - -- (void)connectionWasEstablished: (IRCConnection*)connection -{ -} - -- (void)connection: (IRCConnection*)connection - didSeeUser: (IRCUser*)user - joinChannel: (OFString*)channel -{ -} - -- (void)connection: (IRCConnection*)connection - didSeeUser: (IRCUser*)user - leaveChannel: (OFString*)channel - reason: (OFString*)reason -{ -} - -- (void)connection: (IRCConnection*)connection - didSeeUser: (IRCUser*)user - changeNicknameTo: (OFString*)nickname -{ -} - -- (void)connection: (IRCConnection*)connection - didSeeUser: (IRCUser*)user - kickUser: (OFString*)kickedUser - channel: (OFString*)channel - reason: (OFString*)reason -{ -} - -- (void)connection: (IRCConnection*)connection - didSeeUserQuit: (IRCUser*)user - reason: (OFString*)reason -{ -} - -- (void)connection: (IRCConnection*)connection - didReceiveMessage: (OFString*)msg - channel: (OFString*)channel - user: (IRCUser*)user -{ -} - -- (void)connection: (IRCConnection*)connection - didReceivePrivateMessage: (OFString*)msg - user: (IRCUser*)user -{ -} - -- (void)connection: (IRCConnection*)connection - didReceiveNotice: (OFString*)notice - channel: (OFString*)channel - user: (IRCUser*)user -{ -} - -- (void)connection: (IRCConnection*)connection - didReceiveNotice: (OFString*)notice - user: (IRCUser*)user -{ -} - -- (void)connection: (IRCConnection*)connection - didReceiveNamesForChannel: (OFString*)channel -{ -} - -- (void)connectionWasClosed: (IRCConnection*)connection -{ } @end