ObjIRC  Diff

Differences From Artifact [db72e704d4]:

To Artifact [adb245b3eb]:


34
35
36
37
38
39
40





41
42
43
44
45
46
47
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52







+
+
+
+
+








#import <ObjFW/macros.h>

#import "IRCConnection.h"
#import "IRCUser.h"

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

- init
{
	self = [super init];

	@try {
		_channels = [[OFMutableDictionary alloc] init];
		_port = 6667;
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
89
90

91
92
93
94
95

96
97
98
99
100

101
102
103
104
105

106
107
108
109
110

111
112
113
114
115

116
117
118
119
120
121
122
123
124
125

126
127
128
129
130

131
132
133
134
135
136



137
138
139
140
141
142
143
68
69
70
71
72
73
74

75
76
77
78
79

80
81
82
83
84
85
86
87
88
89
90
91
92
93
94

95
96
97
98
99

100
101
102
103
104

105
106
107
108
109

110
111
112
113
114

115
116
117
118
119

120
121
122
123
124
125
126
127
128
129

130
131
132
133
134

135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151







-
+




-
+














-
+




-
+




-
+




-
+




-
+




-
+









-
+




-
+






+
+
+







	[_channels release];

	[super dealloc];
}

- (void)setServer: (OFString*)server
{
	OF_SETTER(_server, server, YES, YES)
	OF_SETTER(_server, server, true, 1)
}

- (OFString*)server
{
	OF_GETTER(_server, YES)
	OF_GETTER(_server, true)
}

- (void)setPort: (uint16_t)port
{
	_port = port;
}

- (uint16_t)port
{
	return _port;
}

- (void)setNickname: (OFString*)nickname
{
	OF_SETTER(_nickname, nickname, YES, YES)
	OF_SETTER(_nickname, nickname, true, 1)
}

- (OFString*)nickname
{
	OF_GETTER(_nickname, YES)
	OF_GETTER(_nickname, true)
}

- (void)setUsername: (OFString*)username
{
	OF_SETTER(_username, username, YES, YES)
	OF_SETTER(_username, username, true, 1)
}

- (OFString*)username
{
	OF_GETTER(_username, YES)
	OF_GETTER(_username, true)
}

- (void)setRealname: (OFString*)realname
{
	OF_SETTER(_realname, realname, YES, YES)
	OF_SETTER(_realname, realname, true, 1)
}

- (OFString*)realname
{
	OF_GETTER(_realname, YES)
	OF_GETTER(_realname, true)
}

- (void)setDelegate: (id <IRCConnectionDelegate>)delegate
{
	_delegate = delegate;
}

- (id <IRCConnectionDelegate>)delegate
{
	OF_GETTER(_delegate, NO)
	OF_GETTER(_delegate, false)
}

- (OFTCPSocket*)socket
{
	OF_GETTER(_socket, YES)
	OF_GETTER(_socket, true)
}

- (void)connect
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];

	if (_socket != nil)
		@throw [OFAlreadyConnectedException exception];

	_socket = [[OFTCPSocket alloc] init];
	[_socket connectToHost: _server
			  port: _port];

	[self sendLineWithFormat: @"NICK %@", _nickname];
	[self sendLineWithFormat: @"USER %@ * 0 :%@", _username, _realname];

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
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







-
+











-
+


-
+





-
+


-
+





+
-
-
+
+
+
+
+
+
+
+
+







	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];

	[self IRC_processLine: line];

	[pool release];
}

-	    (BOOL)socket: (OFTCPSocket*)socket
-	    (bool)socket: (OFTCPSocket*)socket
  didReceiveISO88591Line: (OFString*)line
	       exception: (OFException*)exception
{
	if (line != nil) {
		[self IRC_processLine: line];
		[socket asyncReadLineWithTarget: self
				       selector: @selector(socket:
						     didReceiveLine:
						     exception:)];
	}

	return NO;
	return false;
}

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

	if ([exception isKindOfClass: [OFInvalidEncodingException class]])
	if ([exception isKindOfClass: [OFInvalidEncodingException class]]) {
		[socket asyncReadLineWithEncoding: OF_STRING_ENCODING_ISO_8859_1
					   target: self
					 selector: @selector(socket:
						       didReceiveISO88591Line:
						       exception:)];
		return false;

	return NO;
	}

	if ([_delegate respondsToSelector: @selector(connectionWasClosed:)]) {
		[_delegate connectionWasClosed: self];
		[_socket release];
		_socket = nil;
	}

	return false;
}

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