Adjust to ObjFW changes

FossilOrigin-Name: bd405f3759e055a6385f2296dbabf1bf11fce0f71dc1a4c9d6a1c36a50cf2362
This commit is contained in:
Jonathan Schleifer 2024-05-04 21:18:40 +00:00
parent e6c76beab5
commit 812dd76e1f
2 changed files with 22 additions and 38 deletions

View file

@ -25,14 +25,7 @@
#include <stdarg.h> #include <stdarg.h>
#import <ObjFW/OFString.h> #import <ObjFW/ObjFW.h>
#import <ObjFW/OFArray.h>
#import <ObjFW/OFMutableDictionary.h>
#import <ObjFW/OFTCPSocket.h>
#import <ObjFW/OFInvalidEncodingException.h>
#import <ObjFW/macros.h>
#import "IRCConnection.h" #import "IRCConnection.h"
#import "IRCUser.h" #import "IRCUser.h"
@ -91,7 +84,7 @@
void *pool = objc_autoreleasePoolPush(); void *pool = objc_autoreleasePoolPush();
if (_socket != nil) if (_socket != nil)
@throw [OFAlreadyConnectedException exception]; @throw [OFAlreadyOpenException exceptionWithObject: self];
_socket = [[_socketClass alloc] init]; _socket = [[_socketClass alloc] init];
[_socket setDelegate: self]; [_socket setDelegate: self];
@ -256,10 +249,10 @@
components = [line componentsSeparatedByString: @" "]; components = [line componentsSeparatedByString: @" "];
/* PING */ /* PING */
if ([components count] == 2 && if (components.count == 2 &&
[[components firstObject] isEqual: @"PING"]) { [components.firstObject isEqual: @"PING"]) {
OFMutableString *s = [[line mutableCopy] autorelease]; OFMutableString *s = [[line mutableCopy] autorelease];
[s replaceCharactersInRange: OFRangeMake(0, 4) [s replaceCharactersInRange: OFMakeRange(0, 4)
withString: @"PONG"]; withString: @"PONG"];
[self sendLine: s]; [self sendLine: s];
@ -302,7 +295,7 @@
IRCUser *user; IRCUser *user;
OFMutableSet *channel; OFMutableSet *channel;
who = [who substringWithRange: OFRangeMake(1, who.length - 1)]; who = [who substringFromIndex: 1];
user = [IRCUser IRCUserWithString: who]; user = [IRCUser IRCUserWithString: who];
if ([who hasPrefix: if ([who hasPrefix:
@ -344,14 +337,13 @@
[[components objectAtIndex: 4] length] + 6; [[components objectAtIndex: 4] length] + 6;
users = [[line substringWithRange: users = [[line substringWithRange:
OFRangeMake(pos, line.length - pos)] OFMakeRange(pos, line.length - pos)]
componentsSeparatedByString: @" "]; componentsSeparatedByString: @" "];
for (OFString *user in users) { for (OFString *user in users) {
if ([user hasPrefix: @"@"] || [user hasPrefix: @"+"] || if ([user hasPrefix: @"@"] || [user hasPrefix: @"+"] ||
[user hasPrefix: @"%"] || [user hasPrefix: @"*"]) [user hasPrefix: @"%"] || [user hasPrefix: @"*"])
user = [user substringWithRange: user = [user substringFromIndex: 1];
OFRangeMake(1, user.length - 1)];
[channel addObject: user]; [channel addObject: user];
} }
@ -374,13 +366,12 @@
size_t pos = who.length + 1 + size_t pos = who.length + 1 +
[[components objectAtIndex: 1] length] + 1 + where.length; [[components objectAtIndex: 1] length] + 1 + where.length;
who = [who substringWithRange: OFRangeMake(1, who.length - 1)]; who = [who substringFromIndex: 1];
user = [IRCUser IRCUserWithString: who]; user = [IRCUser IRCUserWithString: who];
channel = [_channels objectForKey: where]; channel = [_channels objectForKey: where];
if (components.count > 3) if (components.count > 3)
reason = [line substringWithRange: reason = [line substringFromIndex: pos + 2];
OFRangeMake(pos + 2, line.length - pos - 2)];
[channel removeObject: user.nickname]; [channel removeObject: user.nickname];
@ -406,13 +397,12 @@
[[components objectAtIndex: 1] length] + 1 + [[components objectAtIndex: 1] length] + 1 +
where.length + 1 + whom.length; where.length + 1 + whom.length;
who = [who substringWithRange: OFRangeMake(1, who.length - 1)]; who = [who substringFromIndex: 1];
user = [IRCUser IRCUserWithString: who]; user = [IRCUser IRCUserWithString: who];
channel = [_channels objectForKey: where]; channel = [_channels objectForKey: where];
if ([components count] > 4) if (components.count > 4)
reason = [line substringWithRange: reason = [line substringFromIndex: pos + 2];
OFRangeMake(pos + 2, line.length - pos - 2)];
[channel removeObject: user.nickname]; [channel removeObject: user.nickname];
@ -435,12 +425,11 @@
size_t pos = who.length + 1 + size_t pos = who.length + 1 +
[[components objectAtIndex: 1] length]; [[components objectAtIndex: 1] length];
who = [who substringWithRange: OFRangeMake(1, who.length - 1)]; who = [who substringFromIndex: 1];
user = [IRCUser IRCUserWithString: who]; user = [IRCUser IRCUserWithString: who];
if ([components count] > 2) if ([components count] > 2)
reason = [line substringWithRange: reason = [line substringFromIndex: pos + 2];
OFRangeMake(pos + 2, line.length - pos - 2)];
for (OFString *channel in _channels) for (OFString *channel in _channels)
[[_channels objectForKey: channel] [[_channels objectForKey: channel]
@ -461,9 +450,8 @@
OFString *nickname = [components objectAtIndex: 2]; OFString *nickname = [components objectAtIndex: 2];
IRCUser *user; IRCUser *user;
who = [who substringWithRange: OFRangeMake(1, who.length - 1)]; who = [who substringFromIndex: 1];
nickname = [nickname substringWithRange: nickname = [nickname substringFromIndex: 1];
OFRangeMake(1, nickname.length - 1)];
user = [IRCUser IRCUserWithString: who]; user = [IRCUser IRCUserWithString: who];
@ -497,10 +485,8 @@
size_t pos = from.length + 1 + size_t pos = from.length + 1 +
[[components objectAtIndex: 1] length] + 1 + to.length; [[components objectAtIndex: 1] length] + 1 + to.length;
from = [from substringWithRange: from = [from substringFromIndex: 1];
OFRangeMake(1, from.length - 1)]; message = [line substringFromIndex: pos + 2];
message = [line substringWithRange:
OFRangeMake(pos + 2, line.length - pos - 2)];
user = [IRCUser IRCUserWithString: from]; user = [IRCUser IRCUserWithString: from];
if (![to isEqual: _nickname]) { if (![to isEqual: _nickname]) {
@ -530,10 +516,8 @@
size_t pos = from.length + 1 + size_t pos = from.length + 1 +
[[components objectAtIndex: 1] length] + 1 + to.length; [[components objectAtIndex: 1] length] + 1 + to.length;
from = [from substringWithRange: from = [from substringFromIndex: 1];
OFRangeMake(1, from.length - 1)]; notice = [line substringFromIndex: pos + 2];
notice = [line substringWithRange:
OFRangeMake(pos + 2, line.length - pos - 2)];
if (![from containsString: @"!"] || [to isEqual: @"*"]) { if (![from containsString: @"!"] || [to isEqual: @"*"]) {
/* System message - ignore for now */ /* System message - ignore for now */

View file

@ -33,7 +33,7 @@
OF_APPLICATION_DELEGATE(TestApp) OF_APPLICATION_DELEGATE(TestApp)
@implementation TestApp @implementation TestApp
- (void)applicationDidFinishLaunching - (void)applicationDidFinishLaunching: (OFNotification *)notification
{ {
IRCConnection *connection = [[IRCConnection alloc] init]; IRCConnection *connection = [[IRCConnection alloc] init];