Paste number 73792: for xenon

Paste number 73792: for xenon
Pasted by: akempgen
When:3 years, 3 months ago
Share:Tweet this! | http://paste.lisp.org/+1KXS
Channel:#colloquy
Paste contents:
Raw Source | XML | Display As
Index: Chat Core/MVIRCChatConnection.h
===================================================================
--- Chat Core/MVIRCChatConnection.h	(revision 4185)
+++ Chat Core/MVIRCChatConnection.h	(working copy)
@@ -54,6 +54,7 @@
 - (void) _removeDirectClientConnection:(id) connection;
 
 - (void) _setCurrentNickname:(NSString *) nickname;
+- (void) _identifyWithServicesUsingNickname:(NSString *) nickname;
 
 - (void) _periodicCleanUp;
 - (void) _startSendQueue;
Index: Chat Core/MVIRCChatConnection.m
===================================================================
--- Chat Core/MVIRCChatConnection.m	(revision 4185)
+++ Chat Core/MVIRCChatConnection.m	(working copy)
@@ -286,20 +286,9 @@
 #pragma mark -
 
 - (void) setNicknamePassword:(NSString *) newPassword {
-	if( ! [[self localUser] isIdentified] && [newPassword length] && [self isConnected] ) {
-		if( [[self server] hasCaseInsensitiveSubstring:@"quakenet"] ) {
-			[self sendRawMessageImmediatelyWithFormat:@"PRIVMSG Q@CServe.quakenet.org :AUTH %@ %@", [self preferredNickname], newPassword];
-		} else if( [[self server] hasCaseInsensitiveSubstring:@"undernet"] ) {
-			[self sendRawMessageImmediatelyWithFormat:@"PRIVMSG X@channels.undernet.org :LOGIN %@ %@", [self preferredNickname], newPassword];
-		} else if( [[self server] hasCaseInsensitiveSubstring:@"gamesurge"] ) {
-			[self sendRawMessageImmediatelyWithFormat:@"PRIVMSG AuthServ@Services.GameSurge.net :AUTH %@ %@", [self preferredNickname], newPassword];
-		} else if( ![[self nickname] isEqualToString:[self preferredNickname]] ) {
-			[self sendRawMessageImmediatelyWithFormat:@"NICKSERV IDENTIFY %@ %@", [self preferredNickname], newPassword];
-		} else {
-			[self sendRawMessageImmediatelyWithFormat:@"NICKSERV IDENTIFY %@", newPassword];
-		}
-	}
 	[super setNicknamePassword:newPassword];
+	if( [self isConnected] )
+		[self _identifyWithServicesUsingNickname:[self preferredNickname]]; // new the password for the preferred nick -> preferred nickname
 }
 
 #pragma mark -
@@ -1407,6 +1396,28 @@
 
 #pragma mark -
 
+- (void) _identifyWithServicesUsingNickname:(NSString *) nickname {
+	if( ! [[self localUser] isIdentified] && [[self nicknamePassword] length] ) {
+		if( [[self server] hasCaseInsensitiveSubstring:@"quakenet"] ) {
+			[self sendRawMessageImmediatelyWithFormat:@"PRIVMSG Q@CServe.quakenet.org :AUTH %@ %@", [self preferredNickname], [self nicknamePassword]];
+		} else if( [[self server] hasCaseInsensitiveSubstring:@"undernet"] ) {
+			[self sendRawMessageImmediatelyWithFormat:@"PRIVMSG X@channels.undernet.org :LOGIN %@ %@", [self preferredNickname], [self nicknamePassword]];
+		} else if( [[self server] hasCaseInsensitiveSubstring:@"gamesurge"] ) {
+			[self sendRawMessageImmediatelyWithFormat:@"PRIVMSG AuthServ@Services.GameSurge.net :AUTH %@ %@", [self preferredNickname], [self nicknamePassword]];
+		} else if( ![nickname isEqualToString:[self nickname]] ) {
+			[self sendRawMessageImmediatelyWithFormat:@"NICKSERV IDENTIFY %@ %@", nickname, [self nicknamePassword]];
+		} else {
+			// TODO if ( ![nickname isEqualToString:[self preferredNickname]] && keychain has seperate pass for current nickname) {
+			//	[self sendRawMessageImmediatelyWithFormat:@"NICKSERV IDENTIFY %@", <KEYCHAIN PASSWORD>];
+			// } else {
+			[self sendRawMessageImmediatelyWithFormat:@"NICKSERV IDENTIFY %@", [self nicknamePassword]];
+			// }
+		}
+	}
+}
+
+#pragma mark -
+
 - (void) _periodicEvents {
 	MVAssertCorrectThreadRequired( _connectionThread );
 
@@ -1754,20 +1765,8 @@
 		}
 	}
 
-	// Identify if we have a user password
-	if( [[self nicknamePassword] length] ) {
-		if( [[self server] hasCaseInsensitiveSubstring:@"quakenet"] ) {
-			[self sendRawMessageImmediatelyWithFormat:@"PRIVMSG Q@CServe.quakenet.org :AUTH %@ %@", [self preferredNickname], [self nicknamePassword]];
-		} else if( [[self server] hasCaseInsensitiveSubstring:@"undernet"] ) {
-			[self sendRawMessageImmediatelyWithFormat:@"PRIVMSG X@channels.undernet.org :LOGIN %@ %@", [self preferredNickname], [self nicknamePassword]];
-		} else if( [[self server] hasCaseInsensitiveSubstring:@"gamesurge"] ) {
-			[self sendRawMessageImmediatelyWithFormat:@"PRIVMSG AuthServ@Services.GameSurge.net :AUTH %@ %@", [self preferredNickname], [self nicknamePassword]];
-		} else if( ![[self nickname] isEqualToString:[self preferredNickname]] ) {
-			[self sendRawMessageImmediatelyWithFormat:@"NICKSERV IDENTIFY %@ %@", [self preferredNickname], [self nicknamePassword]];
-		} else {
-			[self sendRawMessageImmediatelyWithFormat:@"NICKSERV IDENTIFY %@", [self nicknamePassword]];
-		}
-	}
+	// Identify
+	[self _identifyWithServicesUsingNickname:[self preferredNickname]]; // identifying proactively -> preferred nickname
 
 	[self performSelector:@selector( _checkWatchedUsers ) withObject:nil afterDelay:2.];
 }
@@ -2019,24 +2018,68 @@
 	if( room ) {
 		[[NSNotificationCenter defaultCenter] postNotificationName:MVChatRoomGotMessageNotification object:room userInfo:noticeInfo];
 	} else {
-		if( target == room || ([target isKindOfClass:[MVChatUser class]] && [target isLocalUser]))
-			[[NSNotificationCenter defaultCenter] postNotificationName:MVChatConnectionGotPrivateMessageNotification object:sender userInfo:noticeInfo];
-
-		if( [[sender nickname] isEqualToString:@"NickServ"] || ( [[sender nickname] isEqualToString:@"Q"] && [[self server] hasCaseInsensitiveSubstring:@"quakenet"] ) || ( [[sender nickname] isEqualToString:@"X"] && [[self server] hasCaseInsensitiveSubstring:@"undernet"] ) || ( [[sender nickname] isEqualToString:@"AuthServ"] && [[self server] hasCaseInsensitiveSubstring:@"gamesurge"] ) ) {
+		if( [[sender nickname] isEqualToString:@"NickServ"] ||
+		   ( [[sender nickname] isEqualToString:@"Q"] && [[self server] hasCaseInsensitiveSubstring:@"quakenet"] ) ||
+		   ( [[sender nickname] isEqualToString:@"X"] && [[self server] hasCaseInsensitiveSubstring:@"undernet"] ) ||
+		   ( [[sender nickname] isEqualToString:@"AuthServ"] && [[self server] hasCaseInsensitiveSubstring:@"gamesurge"] ) ) {
 			NSString *msg = [self _newStringWithBytes:[message bytes] length:[message length]];
 
-			if( [msg hasCaseInsensitiveSubstring:@"NickServ"] && [msg hasCaseInsensitiveSubstring:@"ID"] ) {
+			if( [msg hasCaseInsensitiveSubstring:@"password accepted"] ||			// Nickserv/*
+			   [msg hasCaseInsensitiveSubstring:@"you are now identified"] ||		// NickServ/freenode
+			   [msg hasCaseInsensitiveSubstring:@"you are now logged in"] ||		// Q/quakenet
+			   [msg hasCaseInsensitiveSubstring:@"you are already logged in"] ||	// NickServ/freenode
+			   [msg hasCaseInsensitiveSubstring:@"authentication successful"] ||	// X/undernet
+			   [msg hasCaseInsensitiveSubstring:@"i recognize you"] ) {				// AuthServ/gamesurge
+
+				if( ![[self localUser] isIdentified] ) {
+					[noticeInfo setObject:@"identificationAcceptedAndGained" forKey:@"type"];
+					// if( commandsWaitForIdentification )	// would fix #1398.
+					//	[self performCommands];
+					// if( roomsWaitForIdentification )	// would fix #1217.
+					//	[self joinRooms];
+					// TODO ^ replace with real code and put ifs where they are normally run
+				} else {
+					[noticeInfo setObject:@"identificationAccepted" forKey:@"type"];
+				}
+				[[self localUser] _setIdentified:YES];
+
+				[noticeInfo setObject:[NSNumber numberWithBool:YES] forKey:@"handled"];
+
+			} else if ( ( [msg hasCaseInsensitiveSubstring:@"NickServ"] && [msg hasCaseInsensitiveSubstring:@"ID"] ) ||
+					   [msg hasCaseInsensitiveSubstring:@"identify yourself"] ||
+					   [msg hasCaseInsensitiveSubstring:@"authentication required"] ||
+					   [msg hasCaseInsensitiveSubstring:@"nickname is registered"] ||
+					   [msg hasCaseInsensitiveSubstring:@"nickname is owned"] ) {
+
+				if( [[self localUser] isIdentified] ) {
+					[noticeInfo setObject:@"identificationNeededAndLost" forKey:@"type"];
+				} else {
+					[noticeInfo setObject:@"identificationNeeded" forKey:@"type"];
+				}
+				[[self localUser] _setIdentified:NO];
+
 				if( ! [[self nicknamePassword] length] ) {
 					[[NSNotificationCenter defaultCenter] postNotificationName:MVChatConnectionNeedNicknamePasswordNotification object:self userInfo:nil];
 				} else {
-					[self sendRawMessageImmediatelyWithFormat:@"NICKSERV IDENTIFY %@", [self nicknamePassword]];
+					[self _identifyWithServicesUsingNickname:[self nickname]]; // responding to nickserv -> current nickname
+				}
+				[noticeInfo setObject:[NSNumber numberWithBool:YES] forKey:@"handled"];
+
+			} else if ( ( [msg hasCaseInsensitiveSubstring:@"invalid"] ||		// NickServ/freenode, X/undernet
+						 [msg hasCaseInsensitiveSubstring:@"incorrect"] ) &&	// NickServ/dalnet+foonetic+sorcery+azzurra+webchat+rizon, Q/quakenet, AuthServ/gamesurge
+					   ( [msg hasCaseInsensitiveSubstring:@"password"] || [msg hasCaseInsensitiveSubstring:@"identify"] || [msg hasCaseInsensitiveSubstring:@"identification"] ) ) {
+
+				if( [[self localUser] isIdentified] ) {
+					[noticeInfo setObject:@"identificationFailedAndLost" forKey:@"type"];
+				} else {
+					[noticeInfo setObject:@"identificationFailed" forKey:@"type"];
 				}
-			} else if( [msg hasCaseInsensitiveSubstring:@"password accepted"] || [msg hasCaseInsensitiveSubstring:@"you are now identified"] || [msg hasCaseInsensitiveSubstring:@"you are now logged in"] || [msg hasCaseInsensitiveSubstring:@"you are already logged in"] || [msg hasCaseInsensitiveSubstring:@"authentication successful"] || [msg hasCaseInsensitiveSubstring:@"i recognize you"] ) {
-				[[self localUser] _setIdentified:YES];
-			} else if( [msg hasCaseInsensitiveSubstring:@"authentication required"] || [msg hasCaseInsensitiveSubstring:@"nickname is owned"] ) {
 				[[self localUser] _setIdentified:NO];
-			}
 
+				[[NSNotificationCenter defaultCenter] postNotificationName:MVChatConnectionNeedNicknamePasswordNotification object:self userInfo:nil];
+				[noticeInfo setObject:[NSNumber numberWithBool:YES] forKey:@"handled"];
+
+			}
 			[msg release];
 		} else if (![self isConnected]) {
 			NSString *msg = [self _newStringWithBytes:[message bytes] length:[message length]];
@@ -2049,6 +2092,8 @@
 			[regex release];
 			[msg release];
 		}
+		if( target == room || ( [target isKindOfClass:[MVChatUser class]] && [target isLocalUser] ) )
+			[[NSNotificationCenter defaultCenter] postNotificationName:MVChatConnectionGotPrivateMessageNotification object:sender userInfo:noticeInfo];
 	}
 }
 
Index: Controllers/MVConnectionsController.m
===================================================================
--- Controllers/MVConnectionsController.m	(revision 4185)
+++ Controllers/MVConnectionsController.m	(working copy)
@@ -1825,12 +1825,6 @@
 - (void) _requestPassword:(NSNotification *) notification {
 	MVChatConnection *connection = [notification object];
 
-	NSString *pass = [[MVKeyChain defaultKeyChain] internetPasswordForServer:[connection server] securityDomain:[connection server] account:[connection nickname] path:nil port:0 protocol:MVKeyChainProtocolIRC authenticationType:MVKeyChainAuthenticationTypeDefault];
-	if( [pass length] ) {
-		[connection setNicknamePassword:pass];
-		return;
-	}
-
 	if( [nicknameAuth isVisible] ) {
 		// Do somthing better here, like queue requests until the current one is sent
 		return;
Index: Controllers/JVChatController.m
===================================================================
--- Controllers/JVChatController.m	(revision 4185)
+++ Controllers/JVChatController.m	(working copy)
@@ -579,8 +579,8 @@
 	NSData *message = [[notification userInfo] objectForKey:@"message"];
 	MVChatUser* sender = user;
 
-	if( [user isLocalUser] && [notification.userInfo objectForKey:@"target"] )
-		user = [notification.userInfo objectForKey:@"target"];
+	if( [user isLocalUser] && [[notification userInfo] objectForKey:@"target"] )
+		user = [[notification userInfo] objectForKey:@"target"];
 
 	BOOL hideFromUser = NO;
 	if( [[[notification userInfo] objectForKey:@"notice"] boolValue] ) {
@@ -589,7 +589,7 @@
 		if( ! [self chatViewControllerForUser:user ifExists:YES] )
 			hideFromUser = YES;
 
-		if( [[NSUserDefaults standardUserDefaults] boolForKey:@"JVChatAlwaysShowNotices"] )
+		if( [[NSUserDefaults standardUserDefaults] boolForKey:@"JVChatAlwaysShowNotices"] && ![[notification userInfo] objectForKey:@"handled"] )
 			hideFromUser = NO;
 
 		NSMutableDictionary *options = [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInt:[connection encoding]], @"StringEncoding", [NSNumber numberWithBool:[[NSUserDefaults standardUserDefaults] boolForKey:@"JVChatStripMessageColors"]], @"IgnoreFontColors", [NSNumber numberWithBool:[[NSUserDefaults standardUserDefaults] boolForKey:@"JVChatStripMessageFormatting"]], @"IgnoreFontTraits", [NSFont systemFontOfSize:11.], @"BaseFont", nil];
@@ -599,23 +599,42 @@
 			messageString = [NSAttributedString attributedStringWithChatFormat:message options:options];
 		}
 
-		if( ( [user.nickname isEqualToString:@"NickServ"] && ( [messageString.string hasCaseInsensitiveSubstring:@"password accepted"] || [messageString.string hasCaseInsensitiveSubstring:@"you are now identified"] ) ) || ( [user.nickname isEqualToString:@"Q"] && [messageString.string hasCaseInsensitiveSubstring:@"you are now logged in"] ) ) {
-			NSMutableDictionary *context = [NSMutableDictionary dictionary];
-			[context setObject:NSLocalizedString( @"You Have Been Identified", "identified bubble title" ) forKey:@"title"];
-			[context setObject:[NSString stringWithFormat:NSLocalizedString( @"%@ on %@", "identified bubble message, server message and server name" ), [messageString string], [connection server]] forKey:@"description"];
-			[context setObject:[NSImage imageNamed:@"Keychain"] forKey:@"image"];
-			[[JVNotificationController defaultController] performNotification:@"JVNickNameIdentifiedWithServer" withContextInfo:context];
-		} else if( [[user nickname] isEqualToString:@"MemoServ"] ) {
-			if( [[messageString string] rangeOfString:@"new memo" options:NSCaseInsensitiveSearch].location != NSNotFound && [[messageString string] rangeOfString:@" no " options:NSCaseInsensitiveSearch].location == NSNotFound ) {
+		if( [[[notification userInfo] objectForKey:@"type"] length] ) {
+			if( [[[notification userInfo] objectForKey:@"type"] isEqualToString:@"identificationAcceptedAndGained"] ) {
+				
+				NSMutableDictionary *context = [NSMutableDictionary dictionary];
+				[context setObject:NSLocalizedString( @"You Have Been Identified", "identified bubble title" ) forKey:@"title"];
+				[context setObject:[NSString stringWithFormat:NSLocalizedString( @"%@ on %@", "identified bubble message, server message and server name" ), [messageString string], [connection server]] forKey:@"description"];
+				[context setObject:[NSImage imageNamed:@"Keychain"] forKey:@"image"];
+				[[JVNotificationController defaultController] performNotification:@"JVNickNameIdentifiedWithServer" withContextInfo:context];
+				
+			} else if( [[[notification userInfo] objectForKey:@"type"] isEqualToString:@"identificationFailed"] ) {
+				
 				NSMutableDictionary *context = [NSMutableDictionary dictionary];
-				[context setObject:NSLocalizedString( @"You Have New Memos", "new memos bubble title" ) forKey:@"title"];
-				[context setObject:messageString forKey:@"description"];
-				[context setObject:[NSImage imageNamed:@"Stickies"] forKey:@"image"];
-				[context setObject:self forKey:@"target"];
-				[context setObject:NSStringFromSelector( @selector( _checkMemos: ) ) forKey:@"action"];
-				[context setObject:connection forKey:@"representedObject"];
-				[[JVNotificationController defaultController] performNotification:@"JVNewMemosFromServer" withContextInfo:context];
+				[context setObject:NSLocalizedString( @"Identification Failed", "identification failed title" ) forKey:@"title"];
+				[context setObject:[NSString stringWithFormat:NSLocalizedString( @"%@ on %@", "identification failed bubble message, server message and server name" ), [messageString string], [connection server]] forKey:@"description"];
+				[context setObject:[NSImage imageNamed:@"Keychain"] forKey:@"image"];
+				[[JVNotificationController defaultController] performNotification:@"JVNickNameIdentifiedWithServer" withContextInfo:context];
+				
+			} else if( [[[notification userInfo] objectForKey:@"type"] hasCaseInsensitiveSuffix:@"AndLost"] ) {
+				
+				NSMutableDictionary *context = [NSMutableDictionary dictionary];
+				[context setObject:NSLocalizedString( @"You Are No Longer Identified", "no longer identified bubble title" ) forKey:@"title"];
+				[context setObject:[NSString stringWithFormat:NSLocalizedString( @"%@ on %@", "no longer identified bubble message, server message and server name" ), [messageString string], [connection server]] forKey:@"description"];
+				[context setObject:[NSImage imageNamed:@"Keychain"] forKey:@"image"];
+				[[JVNotificationController defaultController] performNotification:@"JVNickNameIdentifiedWithServer" withContextInfo:context];
 			}
+		} else if( [[user nickname] isEqualToString:@"MemoServ"] && [[messageString string] rangeOfString:@"new memo" options:NSCaseInsensitiveSearch].location != NSNotFound && [[messageString string] rangeOfString:@" no " options:NSCaseInsensitiveSearch].location == NSNotFound ) {
+
+			NSMutableDictionary *context = [NSMutableDictionary dictionary];
+			[context setObject:NSLocalizedString( @"You Have New Memos", "new memos bubble title" ) forKey:@"title"];
+			[context setObject:messageString forKey:@"description"];
+			[context setObject:[NSImage imageNamed:@"Stickies"] forKey:@"image"];
+			[context setObject:self forKey:@"target"];
+			[context setObject:NSStringFromSelector( @selector( _checkMemos: ) ) forKey:@"action"];
+			[context setObject:connection forKey:@"representedObject"];
+			[[JVNotificationController defaultController] performNotification:@"JVNewMemosFromServer" withContextInfo:context];
+
 		} else {
 			NSMutableDictionary *context = [NSMutableDictionary dictionary];
 			[context setObject:[NSString stringWithFormat:NSLocalizedString( @"Notice from %@", "notice message from user title" ), [user displayName]] forKey:@"title"];

This paste has no annotations.

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.