ObjIRC  Diff

Differences From Artifact [688cb09cde]:

To Artifact [e49892a8ab]:


46
47
48
49
50
51
52
53

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

53
54
55
56
57
58
59
60







-
+







@synthesize pingInterval = _pingInterval, pingTimeout = _pingTimeout;

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

- init
- (instancetype)init
{
	self = [super init];

	@try {
		_socketClass = [OFTCPSocket class];
		_channels = [[OFMutableDictionary alloc] init];
		_port = 6667;
227
228
229
230
231
232
233
234

235
236
237
238
239
240
241
227
228
229
230
231
232
233

234
235
236
237
238
239
240
241







-
+







	    firstObject];

	[self sendLineWithFormat: @"NICK %@", nickname];

	objc_autoreleasePoolPop(pool);
}

- (void)IRC_processLine: (OFString *)line
- (void)irc_processLine: (OFString *)line
{
	OFArray *components;
	OFString *action = nil;

	if ([_delegate respondsToSelector:
	    @selector(connection:didReceiveLine:)])
		[_delegate connection: self
273
274
275
276
277
278
279
280

281
282
283
284
285
286
287
273
274
275
276
277
278
279

280
281
282
283
284
285
286
287







-
+







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

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

		return;
	}

	/* JOIN */
	if ([action isEqual: @"JOIN"] && [components count] == 3) {
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
584
585
586
587

588

589
590
591
592

593
594
595


596
597
598
599
600
601
602
603
604
605




606
607
608

609
610
611
612
613
614
615
616

617
618

619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640


641
642
643
644
645
646
647
648
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
584
585
586

587
588
589
590
591
592

593
594


595
596
597
598
599
600
601
602
603



604
605
606
607
608
609

610
611
612
613
614
615
616
617

618
619

620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640


641
642
643
644
645
646
647
648
649
650







-
+










-
+



-
+













-
+




-
+

+



-
+

-
-
+
+







-
-
-
+
+
+
+


-
+







-
+

-
+




















-
-
+
+








						 user: user];
		}

		return;
	}
}

- (void)IRC_sendPing
- (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)
				  selector: @selector(irc_pingTimeout)
				   repeats: false] retain];
}

- (void)IRC_pingTimeout
- (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];
	[self irc_processLine: line];

	objc_autoreleasePoolPop(pool);
}

-		  (bool)socket: (OFTCPSocket *)socket
-	      (bool)irc_socket: (OFTCPSocket *)socket
  didReceiveWronglyEncodedLine: (OFString *)line
		       context: (id)context
		     exception: (OFException *)exception
{
	if (line != nil) {
		[self IRC_processLine: line];
		[self irc_processLine: line];
		[socket asyncReadLineWithTarget: self
				       selector: @selector(socket:
						     didReceiveLine:
				       selector: @selector(irc_socket:
						     didReceiveLine:context:
						     exception:)
					context: nil];
	}

	return false;
}

-   (bool)socket: (OFTCPSocket *)socket
  didReceiveLine: (OFString *)line
       exception: (OFException *)exception
- (bool)irc_socket: (OFTCPSocket *)socket
    didReceiveLine: (OFString *)line
	   context: (id)context
	 exception: (OFException *)exception
{
	if (line != nil) {
		[self IRC_processLine: line];
		[self irc_processLine: line];
		return true;
	}

	if ([exception isKindOfClass: [OFInvalidEncodingException class]]) {
		[socket
		    asyncReadLineWithEncoding: _fallbackEncoding
				       target: self
				     selector: @selector(socket:
				     selector: @selector(irc_socket:
						   didReceiveWronglyEncodedLine:
						   exception:)
						   context:exception:)
				      context: nil];
		return false;
	}

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

	[_pingTimer invalidate];

	[_socket performSelector: @selector(cancelAsyncRequests)
		      afterDelay: 0];
	[_socket release];
	_socket = nil;

	return false;
}

- (void)handleConnection
{
	[_socket asyncReadLineWithTarget: self
				selector: @selector(socket:didReceiveLine:
					      exception:)
				selector: @selector(irc_socket:didReceiveLine:
					      context:exception:)
				 context: nil];
}

- (OFSet OF_GENERIC(OFString *) *)usersInChannel: (OFString *)channel
{
	return [[[_channels objectForKey: channel] copy] autorelease];
}
@end