Changeset 3550

Show
Ignore:
Timestamp:
01/14/07 12:17:48 (2 years ago)
Author:
timothy
Message:

Cleans up some code and fixes an exception, -[NSConcreteMutableData doubleValue]: selector not recognized. #958 Also makes sure we set and remove the away status of the local user when we get a 305 or 306, some bouncers send this on connect.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Chat Core/MVIRCChatConnection.m

    r3549 r3550  
    2626#define JVWatchedUserWHOISDelay 300. 
    2727#define JVWatchedUserISONDelay 60. 
    28 #define JVMaximumISONCommandLength 510 
     28#define JVMaximumCommandLength 510 
     29#define JVMaximumISONCommandLength JVMaximumCommandLength 
     30#define JVMaximumWatchCommandLength JVMaximumCommandLength 
    2931#define JVMaximumMembersForWhoRequest 100 
     32#define JVFirstViableTimestamp 631138520 
    3033#define JVFallbackEncoding NSISOLatin1StringEncoding 
    3134 
     
    496499- (void) setAwayStatusMessage:(NSAttributedString *) message { 
    497500        if( [[message string] length] ) { 
    498                 [[self localUser] _setStatus:MVChatUserAwayStatus]; 
    499  
    500501                MVSafeCopyAssign( &_awayMessage, message ); 
    501502 
    502503                NSData *msg = [[self class] _flattenedIRCDataForMessage:message withEncoding:[self encoding] andChatFormat:[self outgoingChatFormat]]; 
    503504                [self sendRawMessageImmediatelyWithComponents:@"AWAY :", msg, nil]; 
     505 
     506                [[self localUser] _setAwayStatusMessage:msg]; 
     507                [[self localUser] _setStatus:MVChatUserAwayStatus]; 
    504508        } else { 
    505509                MVSafeAssign( &_awayMessage, nil ); 
     510 
     511                [self sendRawMessage:@"AWAY" immediately:YES]; 
     512 
     513                [[self localUser] _setAwayStatusMessage:nil]; 
    506514                [[self localUser] _setStatus:MVChatUserAvailableStatus]; 
    507                 [self sendRawMessage:@"AWAY" immediately:YES]; 
    508515        } 
    509516} 
     
    882889        // for the command and its parameters. 
    883890 
    884         if( [data length] > 510 ) [data setLength:510]; 
     891        if( [data length] > JVMaximumCommandLength ) [data setLength:JVMaximumCommandLength]; 
    885892        [data appendBytes:"\x0D\x0A" length:2]; 
    886893 
     
    13041311                        _watchCommandSupported = YES; 
    13051312 
    1306                         NSMutableString *request = [[NSMutableString allocWithZone:nil] initWithCapacity:510]; 
     1313                        NSMutableString *request = [[NSMutableString allocWithZone:nil] initWithCapacity:JVMaximumWatchCommandLength]; 
    13071314                        [request setString:@"WATCH "]; 
    13081315 
     
    13141321                                        NSString *nick = [rule nickname]; 
    13151322                                        if( nick && ! [rule nicknameIsRegularExpression] ) { 
    1316                                                 if( ( [nick length] + [request length] + 1 ) > 510 ) { 
     1323                                                if( ( [nick length] + [request length] + 1 ) > JVMaximumWatchCommandLength ) { 
    13171324                                                        [self sendRawMessage:request]; 
    13181325                                                        [request release]; 
    13191326 
    1320                                                         request = [[NSMutableString allocWithZone:nil] initWithCapacity:510]; 
     1327                                                        request = [[NSMutableString allocWithZone:nil] initWithCapacity:JVMaximumWatchCommandLength]; 
    13211328                                                        [request setString:@"WATCH "]; 
    13221329                                                } 
     
    15841591#elif __i386__ 
    15851592                        NSString *processor = @"Intel"; 
     1593#elif __arm__ 
     1594                        NSString *processor = @"ARM"; 
    15861595#else 
    15871596                        NSString *processor = @"Unknown Architecture"; 
     
    20002009        if( [parameters count] == 2 && [sender isKindOfClass:[MVChatUser class]] ) { 
    20012010                MVChatRoom *room = [self joinedChatRoomWithName:[parameters objectAtIndex:0]]; 
    2002                 [room _setTopic:[parameters objectAtIndex:1]]; 
     2011                NSData *topic = [parameters objectAtIndex:1]; 
     2012                if( ! [topic isKindOfClass:[NSData class]] ) topic = nil; 
     2013                [room _setTopic:topic]; 
    20032014                [room _setTopicAuthor:sender]; 
    20042015                [room _setTopicDate:[NSDate date]]; 
     
    20182029        unsigned int i = 0, count = [parameters count]; 
    20192030        while( i < count ) { 
    2020                 NSString *param = [parameters objectAtIndex:i++]; 
     2031                NSString *param = [self _stringFromPossibleData:[parameters objectAtIndex:i++]]; 
    20212032                if( [param length] ) { 
    20222033                        char chr = [param characterAtIndex:0]; 
     
    21502161                        [self _parseRoomModes:[parameters subarrayWithRange:NSMakeRange( 1, [parameters count] - 1)] forRoom:room fromSender:sender]; 
    21512162                } else { 
    2152                         // user modes 
     2163                        // user modes not handled yet 
    21532164                } 
    21542165        } 
     
    22932304        if( [parameters count] == 3 ) { 
    22942305                MVChatUser *user = [self chatUserWithUniqueIdentifier:[parameters objectAtIndex:1]]; 
    2295                 if( ! [[user awayStatusMessage] isEqual:[parameters objectAtIndex:2]] ) { 
     2306                NSData *awayMsg = [parameters objectAtIndex:2]; 
     2307                if( ! [awayMsg isKindOfClass:[NSData class]] ) awayMsg = nil; 
     2308 
     2309                if( ! [[user awayStatusMessage] isEqual:awayMsg] ) { 
     2310                        [user _setAwayStatusMessage:awayMsg]; 
    22962311                        [user _setStatus:MVChatUserAwayStatus]; 
    2297                         [user _setAwayStatusMessage:[parameters objectAtIndex:2]]; 
     2312 
    22982313                        [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:MVChatUserAwayStatusMessageChangedNotification object:user userInfo:nil]; 
    22992314                } 
     
    23032318- (void) _handle305WithParameters:(NSArray *) parameters fromSender:(id) sender { // RPL_UNAWAY 
    23042319        MVAssertCorrectThreadRequired( _connectionThread ); 
     2320 
     2321        [[self localUser] _setAwayStatusMessage:nil]; 
     2322        [[self localUser] _setStatus:MVChatUserAvailableStatus]; 
     2323 
    23052324        [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:MVChatConnectionSelfAwayStatusChangedNotification object:self userInfo:nil]; 
    23062325} 
     
    23082327- (void) _handle306WithParameters:(NSArray *) parameters fromSender:(id) sender { // RPL_NOWAWAY 
    23092328        MVAssertCorrectThreadRequired( _connectionThread ); 
     2329 
     2330        [[self localUser] _setStatus:MVChatUserAwayStatus]; 
     2331 
    23102332        [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:MVChatConnectionSelfAwayStatusChangedNotification object:self userInfo:nil]; 
    23112333} 
     
    24192441 
    24202442        if( [parameters count] >= 2 ) { 
    2421                 MVChatRoom *room = [self joinedChatRoomWithName:[parameters objectAtIndex:1]]; 
     2443                MVChatRoom *room = [self joinedChatRoomWithName:[self _stringFromPossibleData:[parameters objectAtIndex:1]]]; 
    24222444                if( room ) [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:MVChatRoomMemberUsersSyncedNotification object:room]; 
    24232445        } 
     
    24562478                        NSString *dateString = [self _stringFromPossibleData:[parameters objectAtIndex:4]]; 
    24572479                        NSTimeInterval time = [dateString doubleValue]; 
    2458                         if( time > 631138520 ) // this makes sure it is a viable date 
     2480                        if( time > JVFirstViableTimestamp ) 
    24592481                                [user setAttribute:[NSDate dateWithTimeIntervalSince1970:time] forKey:MVChatUserBanDateAttribute]; 
    24602482                } 
     
    24712493 
    24722494        if( [parameters count] >= 2 ) { 
    2473                 MVChatRoom *room = [self joinedChatRoomWithName:[parameters objectAtIndex:1]]; 
     2495                MVChatRoom *room = [self joinedChatRoomWithName:[self _stringFromPossibleData:[parameters objectAtIndex:1]]]; 
    24742496                [room _setBansSynced:YES]; 
    24752497                if( room ) [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:MVChatRoomBannedUsersSyncedNotification object:room]; 
     
    24852507        if( [parameters count] == 3 ) { 
    24862508                MVChatRoom *room = [self joinedChatRoomWithName:[parameters objectAtIndex:1]]; 
    2487                 [room _setTopic:[parameters objectAtIndex:2]]; 
     2509                NSData *topic = [parameters objectAtIndex:2]; 
     2510                if( ! [topic isKindOfClass:[NSData class]] ) topic = nil; 
     2511                [room _setTopic:topic]; 
    24882512        } 
    24892513} 
     
    24962520                MVChatUser *author = [MVChatUser wildcardUserFromString:[parameters objectAtIndex:2]]; 
    24972521                [room _setTopicAuthor:author]; 
    2498                 if( [[parameters objectAtIndex:3] doubleValue] > 631138520 ) 
    2499                         [room _setTopicDate:[NSDate dateWithTimeIntervalSince1970:[[parameters objectAtIndex:3] doubleValue]]]; 
     2522 
     2523                NSString *setTime = [self _stringFromPossibleData:[parameters objectAtIndex:3]]; 
     2524                NSTimeInterval time = [setTime doubleValue]; 
     2525                if( time > JVFirstViableTimestamp ) 
     2526                        [room _setTopicDate:[NSDate dateWithTimeIntervalSince1970:time]]; 
     2527 
    25002528                [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:MVChatRoomTopicChangedNotification object:room userInfo:nil]; 
    25012529        } 
     
    25292557        if( [parameters count] >= 3 ) { 
    25302558                MVChatUser *user = [self chatUserWithUniqueIdentifier:[parameters objectAtIndex:1]]; 
    2531                 [user _setServerAddress:[parameters objectAtIndex:2]]; 
     2559                [user _setServerAddress:[self _stringFromPossibleData:[parameters objectAtIndex:2]]]; 
    25322560        } 
    25332561} 
     
    25472575        if( [parameters count] >= 3 ) { 
    25482576                MVChatUser *user = [self chatUserWithUniqueIdentifier:[parameters objectAtIndex:1]]; 
    2549                 [user _setIdleTime:[[parameters objectAtIndex:2] doubleValue]]; 
     2577                NSString *idleTime = [self _stringFromPossibleData:[parameters objectAtIndex:2]]; 
     2578                [user _setIdleTime:[idleTime doubleValue]]; 
    25502579                [user _setDateConnected:nil]; 
    25512580 
     
    25542583                        NSString *connectedTime = [self _stringFromPossibleData:[parameters objectAtIndex:3]]; 
    25552584                        NSTimeInterval time = [connectedTime doubleValue]; 
    2556                         // prevent showing 34+ years connected time, this makes sure it is a viable date 
    2557                         if( time > 631138520 ) [user _setDateConnected:[NSDate dateWithTimeIntervalSince1970:time]]; 
     2585                        if( time > JVFirstViableTimestamp ) 
     2586                               [user _setDateConnected:[NSDate dateWithTimeIntervalSince1970:time]]; 
    25582587                } 
    25592588        }