ObjIRC  Diff

Differences From Artifact [475d90a93d]:

To Artifact [84167a7c12]:


39
40
41
42
43
44
45

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76


77
78
79
80
81
82
83
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88







+















+
+
















+
+








@implementation IRCConnection
@synthesize socketClass = _socketClass;
@synthesize server = _server, port = _port;
@synthesize nickname = _nickname, username = _username, realname = _realname;
@synthesize delegate = _delegate, socket = _socket;
@synthesize fallbackEncoding = _fallbackEncoding;
@synthesize pingInterval = _pingInterval, pingTimeout = _pingTimeout;

+ (instancetype)connection
{
	return [[[self alloc] init] autorelease];
}

- init
{
	self = [super init];

	@try {
		_socketClass = [OFTCPSocket class];
		_channels = [[OFMutableDictionary alloc] init];
		_port = 6667;
		_fallbackEncoding = OF_STRING_ENCODING_ISO_8859_1;
		_pingInterval = 120;
		_pingTimeout = 30;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_socket release];
	[_server release];
	[_nickname release];
	[_username release];
	[_realname release];
	[_channels release];
	[_pingData release];
	[_pingTimer release];

	[super dealloc];
}

- (void)connect
{
	void *pool = objc_autoreleasePoolPush();
244
245
246
247
248
249
250













251
252
253
254
255
256
257
258





259
260
261
262
263
264
265
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288







+
+
+
+
+
+
+
+
+
+
+
+
+








+
+
+
+
+







		OFMutableString *s = [[line mutableCopy] autorelease];
		[s replaceCharactersInRange: of_range(0, 4)
				 withString: @"PONG"];
		[self sendLine: s];

		return;
	}

	/* PONG */
	if ([components count] == 4 &&
	    [[components objectAtIndex: 1] isEqual: @"PONG"] &&
	    [[components objectAtIndex: 3] isEqual: _pingData]) {
		[_pingTimer invalidate];

		[_pingData release];
		[_pingTimer release];

		_pingData = nil;
		_pingTimer = nil;
	}

	action = [[components objectAtIndex: 1] uppercaseString];

	/* Connected */
	if ([action isEqual: @"001"] && [components count] >= 4) {
		if ([_delegate respondsToSelector:
		    @selector(connectionWasEstablished:)])
			[_delegate connectionWasEstablished: self];

		[OFTimer scheduledTimerWithTimeInterval: _pingInterval
						 target: self
					       selector: @selector(IRC_sendPing)
						repeats: true];

		return;
	}

	/* JOIN */
	if ([action isEqual: @"JOIN"] && [components count] == 3) {
		OFString *who = [components objectAtIndex: 0];
522
523
524
525
526
527
528

























529
530
531
532
533
534
535
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







				     didReceiveNotice: notice
						 user: user];
		}

		return;
	}
}

- (void)IRC_sendPing
{
	[_pingData release];
	[_pingTimer release];

	_pingData = [[OFString alloc] initWithFormat: @":%d", rand()];
	[_socket writeFormat: @"PING %@\r\n", _pingData];

	_pingTimer = [[OFTimer
	    scheduledTimerWithTimeInterval: _pingTimeout
				    target: self
				  selector: @selector(IRC_pingTimeout)
				   repeats: false] retain];
}

- (void)IRC_pingTimeout
{
	if ([_delegate respondsToSelector: @selector(connectionWasClosed:)])
		[_delegate connectionWasClosed: self];

	[_socket cancelAsyncRequests];
	[_socket release];
	_socket = nil;
}

- (void)processLine: (OFString*)line
{
	void *pool = objc_autoreleasePoolPush();

	[self IRC_processLine: line];

566
567
568
569
570
571
572
573

574




575
576


577
578
579
580
581
582
583
584
614
615
616
617
618
619
620

621
622
623
624
625
626


627
628

629
630
631
632
633
634
635







-
+

+
+
+
+
-
-
+
+
-







				       target: self
				     selector: @selector(socket:
						   didReceiveWronglyEncodedLine:
						   exception:)];
		return false;
	}

	if ([_delegate respondsToSelector: @selector(connectionWasClosed:)]) {
	if ([_delegate respondsToSelector: @selector(connectionWasClosed:)])
		[_delegate connectionWasClosed: self];

	[_pingTimer invalidate];

	[_socket cancelAsyncRequests];
		[_socket release];
		_socket = nil;
	[_socket release];
	_socket = nil;
	}

	return false;
}

- (void)handleConnection
{
	[_socket asyncReadLineWithTarget: self