| 71 | | static void MVChatGotUserMode( CHANNEL_REC *channel, NICK_REC *nick, char *by, char *mode, char *type ) { |
|---|
| 72 | | MVIRCChatConnection *self = [MVIRCChatConnection _connectionForServer:channel -> server]; |
|---|
| 73 | | if( ! self ) return; |
|---|
| 74 | | |
|---|
| 75 | | MVChatRoom *room = [self joinedChatRoomWithName:[self stringWithEncodedBytes:channel -> name]]; |
|---|
| 76 | | MVChatUser *member = [self chatUserWithUniqueIdentifier:[self stringWithEncodedBytes:nick -> nick]]; |
|---|
| 77 | | MVChatUser *byMember = ( by ? [self chatUserWithUniqueIdentifier:[self stringWithEncodedBytes:by]] : nil ); |
|---|
| 78 | | |
|---|
| 79 | | unsigned int m = MVChatRoomMemberNoModes; |
|---|
| 80 | | if( *mode == '@' ) m = MVChatRoomMemberOperatorMode; |
|---|
| 81 | | else if( *mode == '%' ) m = MVChatRoomMemberHalfOperatorMode; |
|---|
| 82 | | else if( *mode == '+' ) m = MVChatRoomMemberVoicedMode; |
|---|
| 83 | | |
|---|
| 84 | | if( m == MVChatRoomMemberNoModes ) return; |
|---|
| 85 | | |
|---|
| 86 | | if( *type == '+' ) [room _setMode:m forMemberUser:member]; |
|---|
| 87 | | else [room _removeMode:m forMemberUser:member]; |
|---|
| 88 | | |
|---|
| 89 | | NSNotification *note = [NSNotification notificationWithName:MVChatRoomUserModeChangedNotification object:room userInfo:[NSDictionary dictionaryWithObjectsAndKeys:member, @"who", [NSNumber numberWithBool:( *type == '+' ? YES : NO )], @"enabled", [NSNumber numberWithUnsignedInt:m], @"mode", byMember, @"by", nil]]; |
|---|
| 90 | | [[NSNotificationCenter defaultCenter] postNotificationOnMainThread:note]; |
|---|
| 91 | | } |
|---|
| 92 | | |
|---|
| 93 | | static void MVChatGotRoomMode( CHANNEL_REC *channel, const char *setby ) { |
|---|
| 94 | | MVIRCChatConnection *self = [MVIRCChatConnection _connectionForServer:channel -> server]; |
|---|
| 95 | | if( ! self ) return; |
|---|
| 96 | | |
|---|
| 97 | | MVChatRoom *room = [self joinedChatRoomWithName:[self stringWithEncodedBytes:channel -> name]]; |
|---|
| 98 | | MVChatUser *byMember = ( setby ? [self chatUserWithUniqueIdentifier:[self stringWithEncodedBytes:setby]] : nil ); |
|---|
| 99 | | |
|---|
| 100 | | unsigned int oldModes = [room modes]; |
|---|
| 101 | | |
|---|
| 102 | | [room _clearModes]; |
|---|
| 103 | | |
|---|
| 104 | | if( strchr( channel -> mode, 'p' ) ) |
|---|
| 105 | | [room _setMode:MVChatRoomPrivateMode withAttribute:nil]; |
|---|
| 106 | | |
|---|
| 107 | | if( strchr( channel -> mode, 's' ) ) |
|---|
| 108 | | [room _setMode:MVChatRoomSecretMode withAttribute:nil]; |
|---|
| 109 | | |
|---|
| 110 | | if( strchr( channel -> mode, 'i' ) ) |
|---|
| 111 | | [room _setMode:MVChatRoomInviteOnlyMode withAttribute:nil]; |
|---|
| 112 | | |
|---|
| 113 | | if( strchr( channel -> mode, 'm' ) ) |
|---|
| 114 | | [room _setMode:MVChatRoomNormalUsersSilencedMode withAttribute:nil]; |
|---|
| 115 | | |
|---|
| 116 | | if( strchr( channel -> mode, 'n' ) ) |
|---|
| 117 | | [room _setMode:MVChatRoomNoOutsideMessagesMode withAttribute:nil]; |
|---|
| 118 | | |
|---|
| 119 | | if( strchr( channel -> mode, 't' ) ) |
|---|
| 120 | | [room _setMode:MVChatRoomOperatorsOnlySetTopicMode withAttribute:nil]; |
|---|
| 121 | | |
|---|
| 122 | | if( strchr( channel -> mode, 'k' ) ) |
|---|
| 123 | | [room _setMode:MVChatRoomPassphraseToJoinMode withAttribute:[self stringWithEncodedBytes:channel -> key]]; |
|---|
| 124 | | |
|---|
| 125 | | if( strchr( channel -> mode, 'l' ) ) |
|---|
| 126 | | [room _setMode:MVChatRoomLimitNumberOfMembersMode withAttribute:[NSNumber numberWithInt:channel -> limit]]; |
|---|
| 127 | | |
|---|
| 128 | | unsigned int changedModes = ( oldModes ^ [room modes] ); |
|---|
| 129 | | |
|---|
| 130 | | NSNotification *note = [NSNotification notificationWithName:MVChatRoomModesChangedNotification object:room userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInt:changedModes], @"changedModes", byMember, @"by", nil]]; |
|---|
| 131 | | [[NSNotificationCenter defaultCenter] postNotificationOnMainThread:note]; |
|---|
| 132 | | } |
|---|
| 133 | | |
|---|
| 134 | | #pragma mark - |
|---|
| 135 | | |
|---|
| 216 | | |
|---|
| 217 | | #pragma mark - |
|---|
| 218 | | |
|---|
| 219 | | static void MVChatErrorNoSuchUser( IRC_SERVER_REC *server, const char *data ) { |
|---|
| 220 | | MVIRCChatConnection *self = [MVIRCChatConnection _connectionForServer:(SERVER_REC *)server]; |
|---|
| 221 | | if( ! self ) return; |
|---|
| 222 | | |
|---|
| 223 | | g_return_if_fail( data != NULL ); |
|---|
| 224 | | |
|---|
| 225 | | char *nick = NULL; |
|---|
| 226 | | char *params = event_get_params( data, 2, NULL, &nick ); |
|---|
| 227 | | |
|---|
| 228 | | [self _processErrorCode:ERR_NOSUCHNICK withContext:nick]; |
|---|
| 229 | | |
|---|
| 230 | | g_free( params ); |
|---|
| 231 | | } |
|---|
| 232 | | |
|---|
| 233 | | static void MVChatErrorUnknownCommand( IRC_SERVER_REC *server, const char *data ) { |
|---|
| 234 | | MVIRCChatConnection *self = [MVIRCChatConnection _connectionForServer:(SERVER_REC *)server]; |
|---|
| 235 | | if( ! self ) return; |
|---|
| 236 | | |
|---|
| 237 | | g_return_if_fail( data != NULL ); |
|---|
| 238 | | |
|---|
| 239 | | char *command = NULL; |
|---|
| 240 | | char *params = event_get_params( data, 2, NULL, &command ); |
|---|
| 241 | | |
|---|
| 242 | | [self _processErrorCode:ERR_UNKNOWNCOMMAND withContext:command]; |
|---|
| 243 | | |
|---|
| 244 | | g_free( params ); |
|---|
| 245 | | } |
|---|
| 246 | | |
|---|
| 247 | | #pragma mark - */ |
|---|
| | 151 | */ |
|---|