| 145 | | static void MVChatUserAway( IRC_SERVER_REC *server, const char *data ) { |
|---|
| 146 | | MVIRCChatConnection *self = [MVIRCChatConnection _connectionForServer:(SERVER_REC *)server]; |
|---|
| 147 | | if( ! self ) return; |
|---|
| 148 | | |
|---|
| 149 | | char *nick = NULL, *message = NULL; |
|---|
| 150 | | char *params = event_get_params( data, 3 | PARAM_FLAG_GETREST, NULL, &nick, &message ); |
|---|
| 151 | | |
|---|
| 152 | | MVChatUser *user = [self chatUserWithUniqueIdentifier:[self stringWithEncodedBytes:nick]]; |
|---|
| 153 | | [user _setStatus:MVChatUserAwayStatus]; |
|---|
| 154 | | |
|---|
| 155 | | // NSData *msgData = [[NSData allocWithZone:nil] initWithBytes:message length:strlen( message )]; |
|---|
| 156 | | |
|---|
| 157 | | // NSNotification *note = [NSNotification notificationWithName:MVChatConnectionUserAwayStatusNotification object:self userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[self stringWithEncodedBytes:nick], @"who", msgData, @"message", nil]]; |
|---|
| 158 | | // [[NSNotificationCenter defaultCenter] postNotificationOnMainThread:note]; |
|---|
| 159 | | // [msgData release]; |
|---|
| 160 | | |
|---|
| 161 | | g_free( params ); |
|---|
| 162 | | } |
|---|
| 163 | | |
|---|
| 164 | | #pragma mark - |
|---|
| 165 | | |
|---|
| 166 | | static void MVChatSelfAwayChanged( IRC_SERVER_REC *server ) { |
|---|
| 167 | | MVIRCChatConnection *self = [MVIRCChatConnection _connectionForServer:(SERVER_REC *)server]; |
|---|
| 168 | | if( ! self ) return; |
|---|
| 169 | | |
|---|
| 170 | | NSNotification *note = [NSNotification notificationWithName:MVChatConnectionSelfAwayStatusChangedNotification object:self userInfo:nil]; |
|---|
| 171 | | [[NSNotificationCenter defaultCenter] postNotificationOnMainThread:note]; |
|---|
| 172 | | } |
|---|
| 173 | | |
|---|
| 174 | | #pragma mark - |
|---|
| 175 | | |
|---|
| 176 | | static void MVChatUserNicknameChanged( IRC_SERVER_REC *server, const char *data, const char *nick, const char *address ) { |
|---|
| 177 | | MVIRCChatConnection *self = [MVIRCChatConnection _connectionForServer:(SERVER_REC *)server]; |
|---|
| 178 | | if( ! self ) return; |
|---|
| 179 | | |
|---|
| 180 | | char *newNick = NULL; |
|---|
| 181 | | char *params = event_get_params( data, 1, &newNick ); |
|---|
| 182 | | |
|---|
| 183 | | NSNotification *note = nil; |
|---|
| 184 | | MVChatUser *user = nil; |
|---|
| 185 | | |
|---|
| 186 | | if( ! strcasecmp( ((SERVER_REC *)server) -> nick, newNick ) ) user = [self localUser]; |
|---|
| 187 | | else user = [self chatUserWithUniqueIdentifier:[self stringWithEncodedBytes:nick]]; |
|---|
| 188 | | |
|---|
| 189 | | if( ! user ) return; |
|---|
| 190 | | |
|---|
| 191 | | NSString *nickname = [self stringWithEncodedBytes:newNick]; |
|---|
| 192 | | NSString *oldNickname = [self stringWithEncodedBytes:nick]; |
|---|
| 193 | | |
|---|
| 194 | | if( [user status] != MVChatUserAwayStatus ) [user _setStatus:MVChatUserAvailableStatus]; |
|---|
| 195 | | [user _setIdleTime:0.]; |
|---|
| 196 | | |
|---|
| 197 | | if( [user isLocalUser] ) { |
|---|
| 198 | | [user _setIdentified:NO]; |
|---|
| 199 | | [user _setUniqueIdentifier:[nickname lowercaseString]]; |
|---|
| 200 | | note = [NSNotification notificationWithName:MVChatConnectionNicknameAcceptedNotification object:self userInfo:nil]; |
|---|
| 201 | | } else { |
|---|
| 202 | | [self _updateKnownUser:user withNewNickname:nickname]; |
|---|
| 203 | | note = [NSNotification notificationWithName:MVChatUserNicknameChangedNotification object:user userInfo:[NSDictionary dictionaryWithObjectsAndKeys:oldNickname, @"oldNickname", nil]]; |
|---|
| 204 | | } |
|---|
| 205 | | |
|---|
| 206 | | NSEnumerator *enumerator = [[self joinedChatRooms] objectEnumerator]; |
|---|
| 207 | | MVChatRoom *room = nil; |
|---|
| 208 | | |
|---|
| 209 | | NSString *oldIdentifier = [oldNickname lowercaseString]; |
|---|
| 210 | | while( ( room = [enumerator nextObject] ) ) { |
|---|
| 211 | | if( ! [room isJoined] || ! [room hasUser:user] ) continue; |
|---|
| 212 | | [room _updateMemberUser:user fromOldUniqueIdentifier:oldIdentifier]; |
|---|
| 213 | | } |
|---|
| 214 | | |
|---|
| 215 | | [[NSNotificationCenter defaultCenter] postNotificationOnMainThread:note]; |
|---|
| 216 | | |
|---|
| 217 | | g_free( params ); |
|---|
| 218 | | } |
|---|
| | 145 | #pragma mark - |
|---|
| | 1256 | #pragma mark Connecting Replies |
|---|
| | 1257 | |
|---|
| | 1258 | - (void) _handle001WithParameters:(NSArray *) parameters fromSender:(MVChatUser *) sender { |
|---|
| | 1259 | [self performSelectorOnMainThread:@selector( _didConnect ) withObject:nil waitUntilDone:NO]; |
|---|
| | 1260 | if( [parameters count] >= 1 ) { |
|---|
| | 1261 | NSString *nickname = [parameters objectAtIndex:0]; |
|---|
| | 1262 | if( ! [nickname isEqualToString:[self nickname]] ) { |
|---|
| | 1263 | [self _setCurrentNickname:nickname]; |
|---|
| | 1264 | [[self localUser] _setUniqueIdentifier:[nickname lowercaseString]]; |
|---|
| | 1265 | [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:MVChatConnectionNicknameAcceptedNotification object:self userInfo:nil]; |
|---|
| | 1266 | } |
|---|
| | 1267 | } |
|---|
| | 1268 | } |
|---|
| | 1269 | |
|---|
| | 1270 | - (void) _handle433WithParameters:(NSArray *) parameters fromSender:(MVChatUser *) sender { // ERR_NICKNAMEINUSE |
|---|
| | 1271 | if( ! [self isConnected] ) { |
|---|
| | 1272 | NSString *nick = [self nextAlternateNickname]; |
|---|
| | 1273 | if( ! [nick length] ) nick = [[self nickname] stringByAppendingString:@"_"]; |
|---|
| | 1274 | if( [nick length] ) [self sendRawMessage:[NSString stringWithFormat:@"NICK %@", nick] immediately:YES]; |
|---|
| | 1275 | } |
|---|
| | 1276 | } |
|---|
| | 1277 | |
|---|
| | 1278 | #pragma mark - |
|---|
| | 1614 | #pragma mark Misc. Replies |
|---|
| | 1615 | |
|---|
| | 1616 | - (void) _handlePingWithParameters:(NSArray *) parameters fromSender:(MVChatUser *) sender { |
|---|
| | 1617 | if( [parameters count] >= 1 ) { |
|---|
| | 1618 | if( [parameters count] == 1 ) [self sendRawMessageWithComponents:@"PONG :", [parameters objectAtIndex:0], nil]; |
|---|
| | 1619 | else [self sendRawMessageWithComponents:@"PONG ", [parameters objectAtIndex:1], @" :", [parameters objectAtIndex:0], nil]; |
|---|
| | 1620 | } |
|---|
| | 1621 | } |
|---|
| | 1622 | |
|---|
| | 1623 | - (void) _handleNickWithParameters:(NSArray *) parameters fromSender:(MVChatUser *) sender { |
|---|
| | 1624 | if( [parameters count] == 1 ) { |
|---|
| | 1625 | id nickname = [parameters objectAtIndex:0]; |
|---|
| | 1626 | if( [nickname isKindOfClass:[NSData class]] ) |
|---|
| | 1627 | nickname = [[[NSString allocWithZone:nil] initWithData:nickname encoding:[self encoding]] autorelease]; |
|---|
| | 1628 | |
|---|
| | 1629 | NSString *oldNickname = [[sender nickname] retain]; |
|---|
| | 1630 | NSString *oldIdentifier = [[sender uniqueIdentifier] retain]; |
|---|
| | 1631 | |
|---|
| | 1632 | if( [sender status] != MVChatUserAwayStatus ) |
|---|
| | 1633 | [sender _setStatus:MVChatUserAvailableStatus]; |
|---|
| | 1634 | [sender _setIdleTime:0.]; |
|---|
| | 1635 | |
|---|
| | 1636 | NSEnumerator *enumerator = [[self joinedChatRooms] objectEnumerator]; |
|---|
| | 1637 | MVChatRoom *room = nil; |
|---|
| | 1638 | |
|---|
| | 1639 | while( ( room = [enumerator nextObject] ) ) { |
|---|
| | 1640 | if( ! [room isJoined] || ! [room hasUser:sender] ) continue; |
|---|
| | 1641 | [room _updateMemberUser:sender fromOldUniqueIdentifier:oldIdentifier]; |
|---|
| | 1642 | } |
|---|
| | 1643 | |
|---|
| | 1644 | if( [sender isLocalUser] ) { |
|---|
| | 1645 | [self _setCurrentNickname:nickname]; |
|---|
| | 1646 | [sender _setIdentified:NO]; |
|---|
| | 1647 | [sender _setUniqueIdentifier:[nickname lowercaseString]]; |
|---|
| | 1648 | [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:MVChatConnectionNicknameAcceptedNotification object:self userInfo:nil]; |
|---|
| | 1649 | } else { |
|---|
| | 1650 | [self _updateKnownUser:sender withNewNickname:nickname]; |
|---|
| | 1651 | [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:MVChatUserNicknameChangedNotification object:sender userInfo:[NSDictionary dictionaryWithObjectsAndKeys:oldNickname, @"oldNickname", nil]]; |
|---|
| | 1652 | } |
|---|
| | 1653 | |
|---|
| | 1654 | [oldNickname release]; |
|---|
| | 1655 | [oldIdentifier release]; |
|---|
| | 1656 | } |
|---|
| | 1657 | } |
|---|
| | 1658 | |
|---|
| | 1659 | #pragma mark - |
|---|
| | 1660 | #pragma mark Away Replies |
|---|
| | 1661 | |
|---|
| | 1662 | - (void) _handle301WithParameters:(NSArray *) parameters fromSender:(id) sender { // RPL_AWAY |
|---|
| | 1663 | if( [parameters count] == 3 ) { |
|---|
| | 1664 | MVChatUser *user = [self chatUserWithUniqueIdentifier:[parameters objectAtIndex:1]]; |
|---|
| | 1665 | if( [[user awayStatusMessage] isEqual:[parameters objectAtIndex:2]] ) { |
|---|
| | 1666 | [sender _setStatus:MVChatUserAwayStatus]; |
|---|
| | 1667 | [user _setAwayStatusMessage:[parameters objectAtIndex:2]]; |
|---|
| | 1668 | [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:MVChatUserAwayStatusMessageChangedNotification object:user userInfo:nil]; |
|---|
| | 1669 | } |
|---|
| | 1670 | } |
|---|
| | 1671 | } |
|---|
| | 1672 | |
|---|
| | 1673 | - (void) _handle305WithParameters:(NSArray *) parameters fromSender:(id) sender { // RPL_UNAWAY |
|---|
| | 1674 | [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:MVChatConnectionSelfAwayStatusChangedNotification object:self userInfo:nil]; |
|---|
| | 1675 | } |
|---|
| | 1676 | |
|---|
| | 1677 | - (void) _handle306WithParameters:(NSArray *) parameters fromSender:(id) sender { // RPL_NOWAWAY |
|---|
| | 1678 | [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:MVChatConnectionSelfAwayStatusChangedNotification object:self userInfo:nil]; |
|---|
| | 1679 | } |
|---|
| | 1680 | |
|---|
| | 1681 | #pragma mark - |
|---|