ObjIRC  Diff

Differences From Artifact [74ae5fa759]:

To Artifact [41b9bcc218]:


184
185
186
187
188
189
190

191
192
193
194
195
196
197
198
199
		[self sendLineWithFormat: @"PART %@ :%@", channel, reason];

	[_channels removeObjectForKey: channel];
}

- (void)sendLine: (OFString*)line
{

	[_delegate connection: self
		  didSendLine: line];

	[_socket writeLine: line];
}

- (void)sendLineWithFormat: (OFConstantString*)format, ...
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];







>
|
|







184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
		[self sendLineWithFormat: @"PART %@ :%@", channel, reason];

	[_channels removeObjectForKey: channel];
}

- (void)sendLine: (OFString*)line
{
	if ([_delegate respondsToSelector: @selector(connection:didSendLine:)])
		[_delegate connection: self
			  didSendLine: line];

	[_socket writeLine: line];
}

- (void)sendLineWithFormat: (OFConstantString*)format, ...
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
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
}

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



	[_delegate connection: self
	       didReceiveLine: line];

	components = [line componentsSeparatedByString: @" "];

	/* PING */
	if ([components count] == 2 &&
	    [[components firstObject] isEqual: @"PING"]) {
		OFMutableString *s = [[line mutableCopy] autorelease];
		[s replaceOccurrencesOfString: @"PING"
				   withString: @"PONG"];
		[self sendLine: s];

		return;
	}

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

	/* Connected */
	if ([action isEqual: @"001"] && [components count] >= 4) {


		[_delegate connectionWasEstablished: self];

		return;
	}

	/* JOIN */
	if ([action isEqual: @"JOIN"] && [components count] == 3) {
		OFString *who = [components objectAtIndex: 0];
		OFString *where = [components objectAtIndex: 2];







>
>
|
|


















>
>
|
>







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
289
290
}

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

	if ([_delegate respondsToSelector:
	    @selector(connection:didReceiveLine:)])
		[_delegate connection: self
		       didReceiveLine: line];

	components = [line componentsSeparatedByString: @" "];

	/* PING */
	if ([components count] == 2 &&
	    [[components firstObject] isEqual: @"PING"]) {
		OFMutableString *s = [[line mutableCopy] autorelease];
		[s replaceOccurrencesOfString: @"PING"
				   withString: @"PONG"];
		[self sendLine: s];

		return;
	}

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

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

		return;
	}

	/* JOIN */
	if ([action isEqual: @"JOIN"] && [components count] == 3) {
		OFString *who = [components objectAtIndex: 0];
		OFString *where = [components objectAtIndex: 2];
294
295
296
297
298
299
300


301
302
303
304
305
306
307
308
309
310
			[_channels setObject: channel
				      forKey: where];
		} else
			channel = [_channels objectForKey: where];

		[channel addObject: [user nickname]];



		[_delegate connection: self
			   didSeeUser: user
			  joinChannel: where];

		return;
	}

	/* NAMES reply */
	if ([action isEqual: @"353"] && [components count] >= 6) {
		OFString *where;







>
>
|
|
|







300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
			[_channels setObject: channel
				      forKey: where];
		} else
			channel = [_channels objectForKey: where];

		[channel addObject: [user nickname]];

		if ([_delegate respondsToSelector:
		    @selector(connection:didSeeUser:joinChannel:)])
			[_delegate connection: self
				   didSeeUser: user
				  joinChannel: where];

		return;
	}

	/* NAMES reply */
	if ([action isEqual: @"353"] && [components count] >= 6) {
		OFString *where;
337
338
339
340
341
342
343


344
345
346
347
348
349
350
351
352
			    [user hasPrefix: @"%"] || [user hasPrefix: @"*"])
				user = [user substringWithRange:
				    of_range(1, [user length] - 1)];

			[channel addObject: user];
		}



		[_delegate	   connection: self
		    didReceiveNamesForChannel: where];

		return;
	}

	/* PART */
	if ([action isEqual: @"PART"] && [components count] >= 3) {
		OFString *who = [components objectAtIndex: 0];







>
>
|
|







345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
			    [user hasPrefix: @"%"] || [user hasPrefix: @"*"])
				user = [user substringWithRange:
				    of_range(1, [user length] - 1)];

			[channel addObject: user];
		}

		if ([_delegate respondsToSelector:
		    @selector(connection:didReceiveNamesForChannel:)])
			[_delegate	   connection: self
			    didReceiveNamesForChannel: where];

		return;
	}

	/* PART */
	if ([action isEqual: @"PART"] && [components count] >= 3) {
		OFString *who = [components objectAtIndex: 0];
363
364
365
366
367
368
369


370
371
372
373
374
375
376
377
378
379
380

		if ([components count] > 3)
			reason = [line substringWithRange:
			    of_range(pos + 2, [line length] - pos - 2)];

		[channel removeObject: [user nickname]];



		[_delegate connection: self
			   didSeeUser: user
			 leaveChannel: where
			       reason: reason];

		return;
	}

	/* KICK */
	if ([action isEqual: @"KICK"] && [components count] >= 4) {
		OFString *who = [components objectAtIndex: 0];







>
>
|
|
|
|







373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392

		if ([components count] > 3)
			reason = [line substringWithRange:
			    of_range(pos + 2, [line length] - pos - 2)];

		[channel removeObject: [user nickname]];

		if ([_delegate respondsToSelector:
		    @selector(connection:didSeeUser:leaveChannel:reason:)])
			[_delegate connection: self
				   didSeeUser: user
				 leaveChannel: where
				       reason: reason];

		return;
	}

	/* KICK */
	if ([action isEqual: @"KICK"] && [components count] >= 4) {
		OFString *who = [components objectAtIndex: 0];
393
394
395
396
397
398
399


400
401
402
403
404
405
406
407
408
409
410
411

		if ([components count] > 4)
			reason = [line substringWithRange:
			    of_range(pos + 2, [line length] - pos - 2)];

		[channel removeObject: [user nickname]];



		[_delegate connection: self
			   didSeeUser: user
			     kickUser: whom
			      channel: where
			       reason: reason];

		return;
	}

	/* QUIT */
	if ([action isEqual: @"QUIT"] && [components count] >= 2) {
		OFString *who = [components objectAtIndex: 0];







>
>
|
|
|
|
|







405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425

		if ([components count] > 4)
			reason = [line substringWithRange:
			    of_range(pos + 2, [line length] - pos - 2)];

		[channel removeObject: [user nickname]];

		if ([_delegate respondsToSelector:
		    @selector(connection:didSeeUser:kickUser:channel:reason:)])
			[_delegate connection: self
				   didSeeUser: user
				     kickUser: whom
				      channel: where
				       reason: reason];

		return;
	}

	/* QUIT */
	if ([action isEqual: @"QUIT"] && [components count] >= 2) {
		OFString *who = [components objectAtIndex: 0];
423
424
425
426
427
428
429


430
431
432
433
434
435
436
437
438
439
			reason = [line substringWithRange:
			    of_range(pos + 2, [line length] - pos - 2)];

		enumerator = [_channels objectEnumerator];
		while ((channel = [enumerator nextObject]) != nil)
			[channel removeObject: [user nickname]];



		[_delegate connection: self
		       didSeeUserQuit: user
			       reason: reason];

		return;
	}

	/* NICK */
	if ([action isEqual: @"NICK"] && [components count] == 3) {
		OFString *who = [components objectAtIndex: 0];







>
>
|
|
|







437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
			reason = [line substringWithRange:
			    of_range(pos + 2, [line length] - pos - 2)];

		enumerator = [_channels objectEnumerator];
		while ((channel = [enumerator nextObject]) != nil)
			[channel removeObject: [user nickname]];

		if ([_delegate respondsToSelector:
		    @selector(connection:didSeeUserQuit:reason:)])
			[_delegate connection: self
			       didSeeUserQuit: user
				       reason: reason];

		return;
	}

	/* NICK */
	if ([action isEqual: @"NICK"] && [components count] == 3) {
		OFString *who = [components objectAtIndex: 0];
457
458
459
460
461
462
463


464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486


487
488
489
490
491


492
493
494

495
496
497
498
499
500
501
		while ((channel = [enumerator nextObject]) != nil) {
			if ([channel containsObject: [user nickname]]) {
				[channel removeObject: [user nickname]];
				[channel addObject: nickname];
			}
		}



		[_delegate connection: self
			   didSeeUser: user
		     changeNicknameTo: nickname];

		return;
	}

	/* PRIVMSG */
	if ([action isEqual: @"PRIVMSG"] && [components count] >= 4) {
		OFString *from = [components objectAtIndex: 0];
		OFString *to = [components objectAtIndex: 2];
		IRCUser *user;
		OFString *msg;
		size_t pos = [from length] + 1 +
		    [[components objectAtIndex: 1] length] + 1 + [to length];

		from = [from substringWithRange:
		    of_range(1, [from length] - 1)];
		msg = [line substringWithRange:
		    of_range(pos + 2, [line length] - pos - 2)];
		user = [IRCUser IRCUserWithString: from];

		if (![to isEqual: _nickname])


			[_delegate connection: self
			    didReceiveMessage: msg
				      channel: to
					 user: user];
		else


			[_delegate	  connection: self
			    didReceivePrivateMessage: msg
						user: user];


		return;
	}

	/* NOTICE */
	if ([action isEqual: @"NOTICE"] && [components count] >= 4) {
		OFString *from = [components objectAtIndex: 0];







>
>
|
|
|



















|
>
>
|
|
|
|
|
>
>
|
|
|
>







473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
		while ((channel = [enumerator nextObject]) != nil) {
			if ([channel containsObject: [user nickname]]) {
				[channel removeObject: [user nickname]];
				[channel addObject: nickname];
			}
		}

		if ([_delegate respondsToSelector:
		    @selector(connection:didSeeUser:changeNicknameTo:)])
			[_delegate connection: self
				   didSeeUser: user
			     changeNicknameTo: nickname];

		return;
	}

	/* PRIVMSG */
	if ([action isEqual: @"PRIVMSG"] && [components count] >= 4) {
		OFString *from = [components objectAtIndex: 0];
		OFString *to = [components objectAtIndex: 2];
		IRCUser *user;
		OFString *msg;
		size_t pos = [from length] + 1 +
		    [[components objectAtIndex: 1] length] + 1 + [to length];

		from = [from substringWithRange:
		    of_range(1, [from length] - 1)];
		msg = [line substringWithRange:
		    of_range(pos + 2, [line length] - pos - 2)];
		user = [IRCUser IRCUserWithString: from];

		if (![to isEqual: _nickname]) {
			if ([_delegate respondsToSelector: @selector(connection:
			    didReceiveMessage:channel:user:)])
				[_delegate connection: self
				    didReceiveMessage: msg
					      channel: to
						 user: user];
		} else {
			if ([_delegate respondsToSelector: @selector(connection:
			    didReceivePrivateMessage:user:)])
				[_delegate	  connection: self
				    didReceivePrivateMessage: msg
							user: user];
		}

		return;
	}

	/* NOTICE */
	if ([action isEqual: @"NOTICE"] && [components count] >= 4) {
		OFString *from = [components objectAtIndex: 0];
513
514
515
516
517
518
519
520


521
522
523
524
525


526
527
528

529
530
531
532
533
534
535
		if (![from containsString: @"!"] || [to isEqual: @"*"]) {
			/* System message - ignore for now */
			return;
		}

		user = [IRCUser IRCUserWithString: from];

		if (![to isEqual: _nickname])


			[_delegate connection: self
			     didReceiveNotice: notice
				      channel: to
					 user: user];
		else


			[_delegate connection: self
			     didReceiveNotice: notice
					 user: user];


		return;
	}
}

- (void)processLine: (OFString*)line
{







|
>
>
|
|
|
|
|
>
>
|
|
|
>







536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
		if (![from containsString: @"!"] || [to isEqual: @"*"]) {
			/* System message - ignore for now */
			return;
		}

		user = [IRCUser IRCUserWithString: from];

		if (![to isEqual: _nickname]) {
			if ([_delegate respondsToSelector: @selector(connection:
			    didReceiveNotice:channel:user:)])
				[_delegate connection: self
				     didReceiveNotice: notice
					      channel: to
						 user: user];
		} else {
			if ([_delegate respondsToSelector:
			    @selector(connection:didReceiveNotice:user:)])
				[_delegate connection: self
				     didReceiveNotice: notice
						 user: user];
		}

		return;
	}
}

- (void)processLine: (OFString*)line
{
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
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
				selector: @selector(socket:didReceiveLine:
					      exception:)];
}

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

@implementation OFObject (IRCConnectionDelegate)
- (void)connection: (IRCConnection*)connection
    didReceiveLine: (OFString*)line
{
}

- (void)connection: (IRCConnection*)connection
       didSendLine: (OFString*)line
{
}

- (void)connectionWasEstablished: (IRCConnection*)connection
{
}

- (void)connection: (IRCConnection*)connection
	didSeeUser: (IRCUser*)user
       joinChannel: (OFString*)channel
{
}

- (void)connection: (IRCConnection*)connection
	didSeeUser: (IRCUser*)user
      leaveChannel: (OFString*)channel
	    reason: (OFString*)reason
{
}

- (void)connection: (IRCConnection*)connection
        didSeeUser: (IRCUser*)user
  changeNicknameTo: (OFString*)nickname
{
}

- (void)connection: (IRCConnection*)connection
	didSeeUser: (IRCUser*)user
	  kickUser: (OFString*)kickedUser
	   channel: (OFString*)channel
	    reason: (OFString*)reason
{
}

- (void)connection: (IRCConnection*)connection
    didSeeUserQuit: (IRCUser*)user
	    reason: (OFString*)reason
{
}

-  (void)connection: (IRCConnection*)connection
  didReceiveMessage: (OFString*)msg
	    channel: (OFString*)channel
	       user: (IRCUser*)user
{
}

-	  (void)connection: (IRCConnection*)connection
  didReceivePrivateMessage: (OFString*)msg
		      user: (IRCUser*)user
{
}

- (void)connection: (IRCConnection*)connection
  didReceiveNotice: (OFString*)notice
	   channel: (OFString*)channel
	      user: (IRCUser*)user
{
}

- (void)connection: (IRCConnection*)connection
  didReceiveNotice: (OFString*)notice
	      user: (IRCUser*)user
{
}

-	   (void)connection: (IRCConnection*)connection
  didReceiveNamesForChannel: (OFString*)channel
{
}

- (void)connectionWasClosed: (IRCConnection*)connection
{
}
@end









<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
608
609
610
611
612
613
614
615
616




















































































				selector: @selector(socket:didReceiveLine:
					      exception:)];
}

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