| 138 | | static void MVChatBanNew( CHANNEL_REC *channel, BAN_REC *ban ) { |
|---|
| 139 | | MVIRCChatConnection *self = [MVIRCChatConnection _connectionForServer:channel -> server]; |
|---|
| 140 | | if( ! self || ! ban || ! ban -> ban ) return; |
|---|
| 141 | | |
|---|
| 142 | | NSString *banString = [self stringWithEncodedBytes:ban -> ban]; |
|---|
| 143 | | NSArray *parts = [banString componentsSeparatedByString:@"!"]; |
|---|
| 144 | | NSString *nickname = ( [parts count] >= 1 ? [parts objectAtIndex:0] : nil ); |
|---|
| 145 | | NSString *host = ( [parts count] >= 2 ? [parts objectAtIndex:1] : nil ); |
|---|
| 146 | | MVChatUser *user = [MVChatUser wildcardUserWithNicknameMask:nickname andHostMask:host]; |
|---|
| 147 | | |
|---|
| 148 | | MVChatRoom *room = [self joinedChatRoomWithName:[self stringWithEncodedBytes:channel -> name]]; |
|---|
| 149 | | MVChatUser *byMember = ( ban -> setby ? [self chatUserWithUniqueIdentifier:[self stringWithEncodedBytes:ban -> setby]] : nil ); |
|---|
| 150 | | |
|---|
| 151 | | [room _addBanForUser:user]; |
|---|
| 152 | | |
|---|
| 153 | | NSNotification *note = [NSNotification notificationWithName:MVChatRoomUserBannedNotification object:room userInfo:[NSDictionary dictionaryWithObjectsAndKeys:user, @"user", byMember, @"byUser", nil]]; |
|---|
| 154 | | [[NSNotificationCenter defaultCenter] postNotificationOnMainThread:note]; |
|---|
| 155 | | } |
|---|
| 156 | | |
|---|
| 157 | | static void MVChatBanRemove( CHANNEL_REC *channel, BAN_REC *ban, const char *who ) { |
|---|
| 158 | | MVIRCChatConnection *self = [MVIRCChatConnection _connectionForServer:channel -> server]; |
|---|
| 159 | | if( ! self || ! ban || ! ban -> ban ) return; |
|---|
| 160 | | |
|---|
| 161 | | NSString *banString = [self stringWithEncodedBytes:ban -> ban]; |
|---|
| 162 | | NSArray *parts = [banString componentsSeparatedByString:@"!"]; |
|---|
| 163 | | NSString *nickname = ( [parts count] >= 1 ? [parts objectAtIndex:0] : nil ); |
|---|
| 164 | | NSString *host = ( [parts count] >= 2 ? [parts objectAtIndex:1] : nil ); |
|---|
| 165 | | MVChatUser *user = [MVChatUser wildcardUserWithNicknameMask:nickname andHostMask:host]; |
|---|
| 166 | | |
|---|
| 167 | | MVChatRoom *room = [self joinedChatRoomWithName:[self stringWithEncodedBytes:channel -> name]]; |
|---|
| 168 | | MVChatUser *byMember = ( who ? [self chatUserWithUniqueIdentifier:[self stringWithEncodedBytes:who]] : nil ); |
|---|
| 169 | | |
|---|
| 170 | | [room _removeBanForUser:user]; |
|---|
| 171 | | |
|---|
| 172 | | NSNotification *note = [NSNotification notificationWithName:MVChatRoomUserBanRemovedNotification object:room userInfo:[NSDictionary dictionaryWithObjectsAndKeys:user, @"user", byMember, @"byUser", nil]]; |
|---|
| 173 | | [[NSNotificationCenter defaultCenter] postNotificationOnMainThread:note]; |
|---|
| 174 | | } |
|---|
| 175 | | |
|---|
| | 1371 | - (void) _handleModeWithParameters:(NSArray *) parameters fromSender:(MVChatUser *) sender { |
|---|
| | 1372 | if( [parameters count] >= 2 ) { |
|---|
| | 1373 | NSString *targetName = [parameters objectAtIndex:0]; |
|---|
| | 1374 | if( [[self chatRoomNamePrefixes] characterIsMember:[targetName characterAtIndex:0]] ) { |
|---|
| | 1375 | MVChatRoom *room = [self joinedChatRoomWithName:targetName]; |
|---|
| | 1376 | |
|---|
| | 1377 | #define enabledHighBit ( 1 << 31 ) |
|---|
| | 1378 | #define banMode ( 1 << 30 ) |
|---|
| | 1379 | #define banExcludeMode ( 1 << 29 ) |
|---|
| | 1380 | #define inviteExcludeMode ( 1 << 28 ) |
|---|
| | 1381 | |
|---|
| | 1382 | unsigned long oldModes = [room modes]; |
|---|
| | 1383 | unsigned long value = 0; |
|---|
| | 1384 | NSMutableArray *argsNeeded = [[NSMutableArray allocWithZone:nil] initWithCapacity:10]; |
|---|
| | 1385 | unsigned int i = 1, count = [parameters count]; |
|---|
| | 1386 | while( i < count ) { |
|---|
| | 1387 | NSString *param = [parameters objectAtIndex:i++]; |
|---|
| | 1388 | if( [param length] ) { |
|---|
| | 1389 | char chr = [param characterAtIndex:0]; |
|---|
| | 1390 | if( chr == '+' || chr == '-' ) { |
|---|
| | 1391 | unsigned enabled = YES; |
|---|
| | 1392 | unsigned int j = 0, length = [param length]; |
|---|
| | 1393 | while( j < length ) { |
|---|
| | 1394 | chr = [param characterAtIndex:j++]; |
|---|
| | 1395 | switch( chr ) { |
|---|
| | 1396 | case '+': enabled = YES; break; |
|---|
| | 1397 | case '-': enabled = NO; break; |
|---|
| | 1398 | case 'i': |
|---|
| | 1399 | if( enabled ) [room _setMode:MVChatRoomInviteOnlyMode withAttribute:nil]; |
|---|
| | 1400 | else [room _removeMode:MVChatRoomInviteOnlyMode]; |
|---|
| | 1401 | break; |
|---|
| | 1402 | case 'p': |
|---|
| | 1403 | if( enabled ) [room _setMode:MVChatRoomPrivateMode withAttribute:nil]; |
|---|
| | 1404 | else [room _removeMode:MVChatRoomPrivateMode]; |
|---|
| | 1405 | break; |
|---|
| | 1406 | case 's': |
|---|
| | 1407 | if( enabled ) [room _setMode:MVChatRoomSecretMode withAttribute:nil]; |
|---|
| | 1408 | else [room _removeMode:MVChatRoomSecretMode]; |
|---|
| | 1409 | break; |
|---|
| | 1410 | case 'm': |
|---|
| | 1411 | if( enabled ) [room _setMode:MVChatRoomNormalUsersSilencedMode withAttribute:nil]; |
|---|
| | 1412 | else [room _removeMode:MVChatRoomNormalUsersSilencedMode]; |
|---|
| | 1413 | break; |
|---|
| | 1414 | case 'n': |
|---|
| | 1415 | if( enabled ) [room _setMode:MVChatRoomNoOutsideMessagesMode withAttribute:nil]; |
|---|
| | 1416 | else [room _removeMode:MVChatRoomNoOutsideMessagesMode]; |
|---|
| | 1417 | break; |
|---|
| | 1418 | case 't': |
|---|
| | 1419 | if( enabled ) [room _setMode:MVChatRoomOperatorsOnlySetTopicMode withAttribute:nil]; |
|---|
| | 1420 | else [room _removeMode:MVChatRoomOperatorsOnlySetTopicMode]; |
|---|
| | 1421 | break; |
|---|
| | 1422 | case 'l': |
|---|
| | 1423 | if( ! enabled ) { |
|---|
| | 1424 | [room _removeMode:MVChatRoomLimitNumberOfMembersMode]; |
|---|
| | 1425 | break; |
|---|
| | 1426 | } |
|---|
| | 1427 | value = MVChatRoomLimitNumberOfMembersMode; |
|---|
| | 1428 | goto queue; |
|---|
| | 1429 | case 'k': |
|---|
| | 1430 | if( ! enabled ) [room _removeMode:MVChatRoomPassphraseToJoinMode]; |
|---|
| | 1431 | value = MVChatRoomPassphraseToJoinMode; |
|---|
| | 1432 | goto queue; |
|---|
| | 1433 | case 'b': |
|---|
| | 1434 | value = banMode; |
|---|
| | 1435 | goto queue; |
|---|
| | 1436 | case 'e': |
|---|
| | 1437 | value = banExcludeMode; |
|---|
| | 1438 | goto queue; |
|---|
| | 1439 | case 'I': |
|---|
| | 1440 | value = inviteExcludeMode; |
|---|
| | 1441 | goto queue; |
|---|
| | 1442 | case 'o': |
|---|
| | 1443 | value = MVChatRoomMemberOperatorMode; |
|---|
| | 1444 | goto queue; |
|---|
| | 1445 | case 'h': |
|---|
| | 1446 | value = MVChatRoomMemberHalfOperatorMode; |
|---|
| | 1447 | goto queue; |
|---|
| | 1448 | case 'v': |
|---|
| | 1449 | value = MVChatRoomMemberVoicedMode; |
|---|
| | 1450 | goto queue; |
|---|
| | 1451 | queue: |
|---|
| | 1452 | if( enabled ) value |= enabledHighBit; |
|---|
| | 1453 | [argsNeeded addObject:[NSNumber numberWithUnsignedLong:value]]; |
|---|
| | 1454 | break; |
|---|
| | 1455 | default: |
|---|
| | 1456 | break; |
|---|
| | 1457 | } |
|---|
| | 1458 | } |
|---|
| | 1459 | } else { |
|---|
| | 1460 | if( [argsNeeded count] ) { |
|---|
| | 1461 | unsigned long value = [[argsNeeded objectAtIndex:0] unsignedLongValue]; |
|---|
| | 1462 | BOOL enabled = ( ( value & enabledHighBit ) ? YES : NO ); |
|---|
| | 1463 | unsigned long mode = ( value & ~enabledHighBit ); |
|---|
| | 1464 | |
|---|
| | 1465 | if( mode == MVChatRoomMemberOperatorMode || mode == MVChatRoomMemberHalfOperatorMode || mode == MVChatRoomMemberVoicedMode ) { |
|---|
| | 1466 | MVChatUser *member = [self chatUserWithUniqueIdentifier:param]; |
|---|
| | 1467 | if( enabled ) [room _setMode:mode forMemberUser:member]; |
|---|
| | 1468 | else [room _removeMode:mode forMemberUser:member]; |
|---|
| | 1469 | [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:MVChatRoomUserModeChangedNotification object:room userInfo:[NSDictionary dictionaryWithObjectsAndKeys:member, @"who", [NSNumber numberWithBool:enabled], @"enabled", [NSNumber numberWithUnsignedLong:mode], @"mode", sender, @"by", nil]]; |
|---|
| | 1470 | } else if( mode == banMode ) { |
|---|
| | 1471 | MVChatUser *user = [MVChatUser wildcardUserFromString:param]; |
|---|
| | 1472 | if( enabled ) { |
|---|
| | 1473 | [room _addBanForUser:user]; |
|---|
| | 1474 | [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:MVChatRoomUserBannedNotification object:room userInfo:[NSDictionary dictionaryWithObjectsAndKeys:user, @"user", sender, @"byUser", nil]]; |
|---|
| | 1475 | } else { |
|---|
| | 1476 | [room _removeBanForUser:user]; |
|---|
| | 1477 | [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:MVChatRoomUserBanRemovedNotification object:room userInfo:[NSDictionary dictionaryWithObjectsAndKeys:user, @"user", sender, @"byUser", nil]]; |
|---|
| | 1478 | } |
|---|
| | 1479 | } else if( mode == MVChatRoomLimitNumberOfMembersMode && enabled ) { |
|---|
| | 1480 | [room _setMode:MVChatRoomLimitNumberOfMembersMode withAttribute:[NSNumber numberWithInt:[param intValue]]]; |
|---|
| | 1481 | } else if( mode == MVChatRoomPassphraseToJoinMode ) { |
|---|
| | 1482 | if( enabled ) [room _setMode:MVChatRoomPassphraseToJoinMode withAttribute:param]; |
|---|
| | 1483 | else [room _removeMode:MVChatRoomPassphraseToJoinMode]; |
|---|
| | 1484 | } |
|---|
| | 1485 | |
|---|
| | 1486 | [argsNeeded removeObjectAtIndex:0]; |
|---|
| | 1487 | } |
|---|
| | 1488 | } |
|---|
| | 1489 | } |
|---|
| | 1490 | } |
|---|
| | 1491 | |
|---|
| | 1492 | unsigned int changedModes = ( oldModes ^ [room modes] ); |
|---|
| | 1493 | [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:MVChatRoomModesChangedNotification object:room userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInt:changedModes], @"changedModes", sender, @"by", nil]]; |
|---|
| | 1494 | } else { |
|---|
| | 1495 | // user modes |
|---|
| | 1496 | } |
|---|
| | 1497 | } |
|---|
| | 1498 | } |
|---|
| | 1499 | |
|---|