From 06c7c487eb50b2f316698a438f68092d0287fec2 Mon Sep 17 00:00:00 2001 From: achmizs Date: Wed, 23 Dec 2015 11:04:22 -0500 Subject: [PATCH] Change the way nick/username/realname are set Rather than have properties, setting which does nothing, we now have readonly properties for nickname/username/realname, and a single setter method, which may be called prior to the session connecting. That way we won't have people setting the properties, and having the properties then not reflecting the state of the connection! --- IRCClient/IRCClientSession.h | 22 +++++++++++++--------- IRCClient/IRCClientSession.m | 18 +++++++++++++++++- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/IRCClient/IRCClientSession.h b/IRCClient/IRCClientSession.h index 5d76f1c..38f7f5c 100644 --- a/IRCClient/IRCClientSession.h +++ b/IRCClient/IRCClientSession.h @@ -102,22 +102,17 @@ /** Server password to provide on connect (may be left empty or nil) */ @property (copy) NSData *password; -/** Nickname of the connected client. Note that setting this after connection will - not result in the client renaming on IRC. You need to send a nick: message instead. +/** Nickname of the connected client. */ -@property (copy) NSString *nickname; +@property (readonly) NSString *nickname; /** Username of the connected client. Also known as the ident. - - Setting this after connection does nothing. */ -@property (copy) NSString *username; +@property (readonly) NSString *username; /** Realname of the connected client. - - Setting this after connection does nothing. */ -@property (copy) NSString *realname; +@property (readonly) NSString *realname; /** The default text encoding for messages on this server. @@ -138,6 +133,15 @@ #pragma mark - Class methods /***************************/ +/** Set the nickname, username, and realname for the session. + + Returns 1 if successfully set, 0 otherwise. + (0 is returned if you try to call this method after the session has + already connected; use the nick: method to attempt a nick change while + connected.) + */ +-(int)setNickname:(NSString *)nickname username:(NSString *)username realname:(NSString *)realname; + /** Connect to the IRC server. Note that this performs the initial DNS lookup and the TCP connection, so if diff --git a/IRCClient/IRCClientSession.m b/IRCClient/IRCClientSession.m index 7a195a4..c374caf 100644 --- a/IRCClient/IRCClientSession.m +++ b/IRCClient/IRCClientSession.m @@ -19,7 +19,7 @@ #pragma mark Defines and includes -#define IRCCLIENTVERSION "2.0a1" +#define IRCCLIENTVERSION "2.0a2" #import "IRCClientSession.h" #import "IRCClientChannel.h" @@ -190,6 +190,22 @@ static void onNumericEvent(irc_session_t *session, unsigned int event, const cha [_thread start]; } +-(int)setNickname:(NSString *)nickname username:(NSString *)username realname:(NSString *)realname +{ + if(self.isConnected) + { + return 0; + } + else + { + _nickname = nickname; + _username = username; + _realname = realname; + + return 1; + } +} + /**************************/ #pragma mark - IRC commands /**************************/