Quellcode durchsuchen

Modify delegate methods to send self with message

The methods declared in IRCClientSessionDelegate and
IRCClientChannelDelegate now have an additional parameter, for
the session or the channel to send a reference to itself. This is
in order that a single delegate object may manage multiple sessions
or channels, and disambiguate between them when receiving messages.
master
achmizs vor 10 Jahren
Ursprung
Commit
e48560fdce

+ 8
- 8
IRCClient/IRCClientChannel.m Datei anzeigen



- (void)userJoined:(NSData *)nick - (void)userJoined:(NSData *)nick
{ {
[_delegate userJoined:nick];
[_delegate userJoined:nick channel:self];
} }


- (void)userParted:(NSData *)nick withReason:(NSData *)reason us:(BOOL)wasItUs - (void)userParted:(NSData *)nick withReason:(NSData *)reason us:(BOOL)wasItUs
{ {
[_delegate userParted:nick withReason:reason us:wasItUs];
[_delegate userParted:nick channel:self withReason:reason us:wasItUs];
} }


- (void)modeSet:(NSData *)mode withParams:(NSData *)params by:(NSData *)nick - (void)modeSet:(NSData *)mode withParams:(NSData *)params by:(NSData *)nick
{ {
[_delegate modeSet:mode withParams:params by:nick];
[_delegate modeSet:mode forChannel:self withParams:params by:nick];
} }


- (void)topicSet:(NSData *)topic by:(NSData *)nick - (void)topicSet:(NSData *)topic by:(NSData *)nick
{ {
_topic = topic; _topic = topic;
[_delegate topicSet:topic by:nick];
[_delegate topicSet:topic forChannel:self by:nick];
} }


- (void)userKicked:(NSData *)nick withReason:(NSData *)reason by:(NSData *)byNick us:(BOOL)wasItUs - (void)userKicked:(NSData *)nick withReason:(NSData *)reason by:(NSData *)byNick us:(BOOL)wasItUs
{ {
[_delegate userKicked:nick withReason:reason by:byNick us:wasItUs];
[_delegate userKicked:nick fromChannel:self withReason:reason by:byNick us:wasItUs];
} }


- (void)messageSent:(NSData *)message byUser:(NSData *)nick - (void)messageSent:(NSData *)message byUser:(NSData *)nick
{ {
[_delegate messageSent:message byUser:nick];
[_delegate messageSent:message byUser:nick onChannel:self];
} }


- (void)noticeSent:(NSData *)notice byUser:(NSData *)nick - (void)noticeSent:(NSData *)notice byUser:(NSData *)nick
{ {
[_delegate noticeSent:notice byUser:nick];
[_delegate noticeSent:notice byUser:nick onChannel:self];
} }


- (void)actionPerformed:(NSData *)action byUser:(NSData *)nick - (void)actionPerformed:(NSData *)action byUser:(NSData *)nick
{ {
[_delegate actionPerformed:action byUser:nick];
[_delegate actionPerformed:action byUser:nick onChannel:self];
} }


@end @end

+ 10
- 8
IRCClient/IRCClientChannelDelegate.h Datei anzeigen

* object may be supplied instead of the given parameter. * object may be supplied instead of the given parameter.
*/ */


@class IRCClientChannel;

@protocol IRCClientChannelDelegate <NSObject> @protocol IRCClientChannelDelegate <NSObject>


/** When a client joins this channel, the userJoined event is fired. Note that /** When a client joins this channel, the userJoined event is fired. Note that
* *
* @param nick The nickname of the user that joined the channel. * @param nick The nickname of the user that joined the channel.
*/ */
- (void)userJoined:(NSData *)nick;
- (void)userJoined:(NSData *)nick channel:(IRCClientChannel *)sender;


/** When an IRC client parts a channel you are connect to, you will see /** When an IRC client parts a channel you are connect to, you will see
* an onPart event. You will also see this event when you part a channel. * an onPart event. You will also see this event when you part a channel.
* @param reason (optional) The reason, if any, that the user gave for leaving. * @param reason (optional) The reason, if any, that the user gave for leaving.
* @param wasItUs (required) Was it us who parted, or another user? * @param wasItUs (required) Was it us who parted, or another user?
*/ */
- (void)userParted:(NSData *)nick withReason:(NSData *)reason us:(BOOL)wasItUs;
- (void)userParted:(NSData *)nick channel:(IRCClientChannel *)sender withReason:(NSData *)reason us:(BOOL)wasItUs;


/** Received when an IRC client changes the channel mode. What modes are available /** Received when an IRC client changes the channel mode. What modes are available
* for a given channel is an implementation detail for each server. * for a given channel is an implementation detail for each server.
* @param params any parameters with the mode (such as channel key). * @param params any parameters with the mode (such as channel key).
* @param nick the nickname of the IRC client that changed the mode. * @param nick the nickname of the IRC client that changed the mode.
*/ */
- (void)modeSet:(NSData *)mode withParams:(NSData *)params by:(NSData *)nick;
- (void)modeSet:(NSData *)mode forChannel:(IRCClientChannel *)sender withParams:(NSData *)params by:(NSData *)nick;


/** Received when the topic is changed for the channel. /** Received when the topic is changed for the channel.
* *
* @param aTopic The new topic of the channel. * @param aTopic The new topic of the channel.
* @param nick Nickname of the IRC client that changed the topic. * @param nick Nickname of the IRC client that changed the topic.
*/ */
- (void)topicSet:(NSData *)topic by:(NSData *)nick;
- (void)topicSet:(NSData *)topic forChannel:(IRCClientChannel *)sender by:(NSData *)nick;


/** Received when an IRC client is kicked from a channel. /** Received when an IRC client is kicked from a channel.
* *
* @param byNick nickname of the client that performed the kick command * @param byNick nickname of the client that performed the kick command
* @param wasItUs Was it us who got kicked, or another user? * @param wasItUs Was it us who got kicked, or another user?
*/ */
- (void)userKicked:(NSData *)nick withReason:(NSData *)reason by:(NSData *)byNick us:(BOOL)wasItUs;
- (void)userKicked:(NSData *)nick fromChannel:(IRCClientChannel *)sender withReason:(NSData *)reason by:(NSData *)byNick us:(BOOL)wasItUs;


/** Received when an IRC client sends a public PRIVMSG to the channel. Note that the /** Received when an IRC client sends a public PRIVMSG to the channel. Note that the
* user may not necessarily be required to be on the channel to send a message * user may not necessarily be required to be on the channel to send a message
* @param message the message sent to the channel. * @param message the message sent to the channel.
* @param nick the nickname of the IRC client that sent the message. * @param nick the nickname of the IRC client that sent the message.
*/ */
- (void)messageSent:(NSData *)message byUser:(NSData *)nick;
- (void)messageSent:(NSData *)message byUser:(NSData *)nick onChannel:(IRCClientChannel *)sender;


/** Received when an IRC client sends a public NOTICE to the channel. Note that /** Received when an IRC client sends a public NOTICE to the channel. Note that
* the user may not necessarily be required to be on the channel to send a notice to * the user may not necessarily be required to be on the channel to send a notice to
* @param notice the notice sent to the channel. * @param notice the notice sent to the channel.
* @param nick the nickname of the IRC client that sent the notice. * @param nick the nickname of the IRC client that sent the notice.
*/ */
- (void)noticeSent:(NSData *)notice byUser:(NSData *)nick;
- (void)noticeSent:(NSData *)notice byUser:(NSData *)nick onChannel:(IRCClientChannel *)sender;


/** Received when an IRC client sends a CTCP ACTION message to the channel. /** Received when an IRC client sends a CTCP ACTION message to the channel.
* *
* @param action the action message sent to the channel. * @param action the action message sent to the channel.
* @param nick the nickname of the IRC client that sent the message. * @param nick the nickname of the IRC client that sent the message.
*/ */
- (void)actionPerformed:(NSData *)action byUser:(NSData *)nick;
- (void)actionPerformed:(NSData *)action byUser:(NSData *)nick onChannel:(IRCClientChannel *)sender;


@end @end

+ 17
- 17
IRCClient/IRCClientSession.m Datei anzeigen



- (void)connectionSucceeded - (void)connectionSucceeded
{ {
[_delegate connectionSucceeded];
[_delegate connectionSucceeded:self];
} }


- (void)nickChangedFrom:(NSData *)oldNick to:(NSData *)newNick - (void)nickChangedFrom:(NSData *)oldNick to:(NSData *)newNick
if ([_nickname isEqualToData:oldNickOnly]) if ([_nickname isEqualToData:oldNickOnly])
{ {
_nickname = newNick; _nickname = newNick;
[_delegate nickChangedFrom:oldNickOnly to:newNick own:YES];
[_delegate nickChangedFrom:oldNickOnly to:newNick own:YES session:self];
} }
else else
{ {
[_delegate nickChangedFrom:oldNickOnly to:newNick own:NO];
[_delegate nickChangedFrom:oldNickOnly to:newNick own:NO session:self];
} }
} }


- (void)userQuit:(NSData *)nick withReason:(NSData *)reason - (void)userQuit:(NSData *)nick withReason:(NSData *)reason
{ {
[_delegate userQuit:nick withReason:reason];
[_delegate userQuit:nick withReason:reason session:self];
} }


- (void)userJoined:(NSData *)nick channel:(NSData *)channelName - (void)userJoined:(NSData *)nick channel:(NSData *)channelName
IRCClientChannel* newChannel = [[IRCClientChannel alloc] initWithName:channelName andIRCSession:_irc_session]; IRCClientChannel* newChannel = [[IRCClientChannel alloc] initWithName:channelName andIRCSession:_irc_session];
_channels[channelName] = newChannel; _channels[channelName] = newChannel;
[_delegate joinedNewChannel:newChannel];
[_delegate joinedNewChannel:newChannel session:self];
} }
else else
{ {


- (void)modeSet:(NSData *)mode by:(NSData *)nick - (void)modeSet:(NSData *)mode by:(NSData *)nick
{ {
[_delegate modeSet:mode by:nick];
[_delegate modeSet:mode by:nick session:self];
} }


- (void)topicSet:(NSData *)newTopic forChannel:(NSData *)channelName by:(NSData *)nick - (void)topicSet:(NSData *)newTopic forChannel:(NSData *)channelName by:(NSData *)nick


- (void)privateMessageReceived:(NSData *)message fromUser:(NSData *)nick - (void)privateMessageReceived:(NSData *)message fromUser:(NSData *)nick
{ {
[_delegate privateMessageReceived:message fromUser:nick];
[_delegate privateMessageReceived:message fromUser:nick session:self];
} }


- (void)serverMessageReceivedFrom:(NSData *)origin params:(NSArray *)params - (void)serverMessageReceivedFrom:(NSData *)origin params:(NSArray *)params
{ {
[_delegate serverMessageReceivedFrom:origin params:params];
[_delegate serverMessageReceivedFrom:origin params:params session:self];
} }


- (void)privateNoticeReceived:(NSData *)notice fromUser:(NSData *)nick - (void)privateNoticeReceived:(NSData *)notice fromUser:(NSData *)nick
{ {
[_delegate privateNoticeReceived:notice fromUser:nick];
[_delegate privateNoticeReceived:notice fromUser:nick session:self];
} }


- (void)noticeSent:(NSData *)notice toChannel:(NSData *)channelName byUser:(NSData *)nick - (void)noticeSent:(NSData *)notice toChannel:(NSData *)channelName byUser:(NSData *)nick


- (void)serverNoticeReceivedFrom:(NSData *)origin params:(NSArray *)params - (void)serverNoticeReceivedFrom:(NSData *)origin params:(NSArray *)params
{ {
[_delegate serverNoticeReceivedFrom:origin params:params];
[_delegate serverNoticeReceivedFrom:origin params:params session:self];
} }


- (void)invitedToChannel:(NSData *)channelName by:(NSData *)nick - (void)invitedToChannel:(NSData *)channelName by:(NSData *)nick
{ {
[_delegate invitedToChannel:channelName by:nick];
[_delegate invitedToChannel:channelName by:nick session:self];
} }


- (void)CTCPRequestReceived:(NSData *)request fromUser:(NSData *)nick - (void)CTCPRequestReceived:(NSData *)request fromUser:(NSData *)nick
} }
else else
{ {
if ([_delegate respondsToSelector:@selector(CTCPRequestReceived:ofType:fromUser:)])
if ([_delegate respondsToSelector:@selector(CTCPRequestReceived:ofType:fromUser:session:)])
{ {
char* request_string = malloc(request.length); char* request_string = malloc(request.length);
[request getBytes:request_string length:request.length]; [request getBytes:request_string length:request.length];
NSData* requestTypeData = [NSData dataWithBytes:request_body length:strlen(request_body) + 1]; NSData* requestTypeData = [NSData dataWithBytes:request_body length:strlen(request_body) + 1];
NSData* requestBodyData = [NSData dataWithBytes:request_type length:strlen(request_type) + 1]; NSData* requestBodyData = [NSData dataWithBytes:request_type length:strlen(request_type) + 1];
[_delegate CTCPRequestReceived:requestBodyData ofType:requestTypeData fromUser:nick];
[_delegate CTCPRequestReceived:requestBodyData ofType:requestTypeData fromUser:nick session:self];
free(request_string); free(request_string);
} }


- (void)CTCPReplyReceived:(NSData *)reply fromUser:(NSData *)nick - (void)CTCPReplyReceived:(NSData *)reply fromUser:(NSData *)nick
{ {
[_delegate CTCPReplyReceived:reply fromUser:nick];
[_delegate CTCPReplyReceived:reply fromUser:nick session:self];
} }


- (void)CTCPActionPerformed:(NSData *)action byUser:(NSData *)nick atTarget:(NSData *)target - (void)CTCPActionPerformed:(NSData *)action byUser:(NSData *)nick atTarget:(NSData *)target
else else
{ {
// An action in a private message // An action in a private message
[_delegate privateCTCPActionReceived:action fromUser:nick];
[_delegate privateCTCPActionReceived:action fromUser:nick session:self];
} }
} }


- (void)unknownEventReceived:(NSData *)event from:(NSData *)origin params:(NSArray *)params - (void)unknownEventReceived:(NSData *)event from:(NSData *)origin params:(NSArray *)params
{ {
[_delegate unknownEventReceived:event from:origin params:params];
[_delegate unknownEventReceived:event from:origin params:params session:self];
} }


-(void)numericEventReceived:(NSUInteger)event from:(NSData *)origin params:(NSArray *)params -(void)numericEventReceived:(NSUInteger)event from:(NSData *)origin params:(NSArray *)params
{ {
[_delegate numericEventReceived:event from:origin params:params];
[_delegate numericEventReceived:event from:origin params:params session:self];
} }


@end @end

+ 35
- 19
IRCClient/IRCClientSessionDelegate.h Datei anzeigen



#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>


@class IRCClientSession;
@class IRCClientChannel; @class IRCClientChannel;


/** @brief Receives delegate messages from an IRCClientSession. /** @brief Receives delegate messages from an IRCClientSession.
@protocol IRCClientSessionDelegate <NSObject> @protocol IRCClientSessionDelegate <NSObject>


/** The client has successfully connected to the IRC server. */ /** The client has successfully connected to the IRC server. */
- (void)connectionSucceeded;
@required
- (void)connectionSucceeded:(IRCClientSession *)sender;


/** An IRC client on a channel that this client is connected to has changed nickname, /** An IRC client on a channel that this client is connected to has changed nickname,
* or this IRC client has changed nicknames. * or this IRC client has changed nicknames.
* @param oldNick the old nickname * @param oldNick the old nickname
* @param wasItUs did our nick change, or someone else's? * @param wasItUs did our nick change, or someone else's?
*/ */
- (void)nickChangedFrom:(NSData *)oldNick to:(NSData *)newNick own:(BOOL)wasItUs;
@required
- (void)nickChangedFrom:(NSData *)oldNick to:(NSData *)newNick own:(BOOL)wasItUs session:(IRCClientSession *)sender;


/** An IRC client on a channel that this client is connected to has quit IRC. /** An IRC client on a channel that this client is connected to has quit IRC.
* *
* @param nick the nickname of the client that quit. * @param nick the nickname of the client that quit.
* @param reason (optional) the quit message, if any. * @param reason (optional) the quit message, if any.
*/ */
- (void)userQuit:(NSData *)nick withReason:(NSData *)reason;
@required
- (void)userQuit:(NSData *)nick withReason:(NSData *)reason session:(IRCClientSession *)sender;


/** The IRC client has joined (connected) successfully to a new channel. This /** The IRC client has joined (connected) successfully to a new channel. This
* event creates an IRCClientChannel object, which you are expected to assign a * event creates an IRCClientChannel object, which you are expected to assign a
* *
* @param channel the IRCClientChannel object for the newly joined channel. * @param channel the IRCClientChannel object for the newly joined channel.
*/ */
- (void)joinedNewChannel:(IRCClientChannel *)channel;
@required
- (void)joinedNewChannel:(IRCClientChannel *)channel session:(IRCClientSession *)sender;


/** The client has changed it's user mode. /** The client has changed it's user mode.
* *
* @param mode the new mode. * @param mode the new mode.
*/ */
- (void)modeSet:(NSData *)mode by:(NSData *)nick;
@required
- (void)modeSet:(NSData *)mode by:(NSData *)nick session:(IRCClientSession *)sender;


/** The client has received a private PRIVMSG from another IRC client. /** The client has received a private PRIVMSG from another IRC client.
* *
* @param message the text of the message * @param message the text of the message
* @param nick the other IRC Client that sent the message. * @param nick the other IRC Client that sent the message.
*/ */
- (void)privateMessageReceived:(NSData *)message fromUser:(NSData *)nick;
@required
- (void)privateMessageReceived:(NSData *)message fromUser:(NSData *)nick session:(IRCClientSession *)sender;


/** The client has received a private NOTICE from another client. /** The client has received a private NOTICE from another client.
* *
* @param notice the text of the message * @param notice the text of the message
* @param nick the nickname of the other IRC client that sent the message. * @param nick the nickname of the other IRC client that sent the message.
*/ */
- (void)privateNoticeReceived:(NSData *)notice fromUser:(NSData *)nick;
@required
- (void)privateNoticeReceived:(NSData *)notice fromUser:(NSData *)nick session:(IRCClientSession *)sender;


/** The client has received a private PRIVMSG from the server. /** The client has received a private PRIVMSG from the server.
* *
* @param origin the sender of the message * @param origin the sender of the message
* @param params the parameters of the message * @param params the parameters of the message
*/ */
- (void)serverMessageReceivedFrom:(NSData *)origin params:(NSArray *)params;
@required
- (void)serverMessageReceivedFrom:(NSData *)origin params:(NSArray *)params session:(IRCClientSession *)sender;


/** The client has received a private NOTICE from the server. /** The client has received a private NOTICE from the server.
* *
* @param origin the sender of the notice * @param origin the sender of the notice
* @param params the parameters of the notice * @param params the parameters of the notice
*/ */
- (void)serverNoticeReceivedFrom:(NSData *)origin params:(NSArray *)params;
@required
- (void)serverNoticeReceivedFrom:(NSData *)origin params:(NSArray *)params session:(IRCClientSession *)sender;


/** The IRC client has been invited to a channel. /** The IRC client has been invited to a channel.
* *
* @param channel the channel for the invitation. * @param channel the channel for the invitation.
* @param nick the nickname of the user that sent the invitation. * @param nick the nickname of the user that sent the invitation.
*/ */
- (void)invitedToChannel:(NSData *)channelName by:(NSData *)nick;
@required
- (void)invitedToChannel:(NSData *)channelName by:(NSData *)nick session:(IRCClientSession *)sender;


/** A private CTCP request was sent to the IRC client. /** A private CTCP request was sent to the IRC client.
* *
* @param type the CTCP request type * @param type the CTCP request type
* @param nick the nickname of the user that sent the request. * @param nick the nickname of the user that sent the request.
*/ */
- (void)CTCPRequestReceived:(NSData *)request ofType:(NSData *)type fromUser:(NSData *)nick;
@optional
- (void)CTCPRequestReceived:(NSData *)request ofType:(NSData *)type fromUser:(NSData *)nick session:(IRCClientSession *)sender;


/** A private CTCP reply was sent to the IRC client. /** A private CTCP reply was sent to the IRC client.
* *
* @param reply an NSData containing the raw C string of the reply. * @param reply an NSData containing the raw C string of the reply.
* @param nick the nickname of the user that sent the reply. * @param nick the nickname of the user that sent the reply.
*/ */
- (void)CTCPReplyReceived:(NSData *)reply fromUser:(NSData *)nick;
@optional
- (void)CTCPReplyReceived:(NSData *)reply fromUser:(NSData *)nick session:(IRCClientSession *)sender;


/** A private CTCP ACTION was sent to the IRC client. /** A private CTCP ACTION was sent to the IRC client.
* *
* @param action the action message text. * @param action the action message text.
* @param nick the nickname of the client that sent the action. * @param nick the nickname of the client that sent the action.
*/ */
- (void)privateCTCPActionReceived:(NSData *)action fromUser:(NSData *)nick;
@required
- (void)privateCTCPActionReceived:(NSData *)action fromUser:(NSData *)nick session:(IRCClientSession *)sender;


/** An unhandled event was received from the IRC server.
/** An unhandled numeric was received from the IRC server
* *
* @param event the unknown event name
* @param event the unknown event number
* @param origin the sender of the event * @param origin the sender of the event
* @param params an NSArray of NSData objects that are the raw C strings of the event. * @param params an NSArray of NSData objects that are the raw C strings of the event.
*/ */
- (void)unknownEventReceived:(NSData *)event from:(NSData *)origin params:(NSArray *)params;
@optional
- (void)numericEventReceived:(NSUInteger)event from:(NSData *)origin params:(NSArray *)params session:(IRCClientSession *)sender;


/** An unhandled numeric was received from the IRC server
/** An unhandled event was received from the IRC server.
* *
* @param event the unknown event number
* @param event the unknown event name
* @param origin the sender of the event * @param origin the sender of the event
* @param params an NSArray of NSData objects that are the raw C strings of the event. * @param params an NSArray of NSData objects that are the raw C strings of the event.
*/ */
- (void)numericEventReceived:(NSUInteger)event from:(NSData *)origin params:(NSArray *)params;
@optional
- (void)unknownEventReceived:(NSData *)event from:(NSData *)origin params:(NSArray *)params session:(IRCClientSession *)sender;


@end @end

Laden…
Abbrechen
Speichern