ObjIRC  Diff

Differences From Artifact [c0d4a5d2c9]:

To Artifact [df4362f571]:


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
152

153
154
155
156

157
158
159
160
161
162
163
164
165
166
167


168
169
170
171
172
173
174
175
176
177
178
179




180
181
182
183
184
185
186
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

152
153
154


155
156
157
158
159
160
161
162
163
164


165
166
167
168
169
170
171
172
173
174




175
176
177
178
179
180
181
182
183
184
185







-
+


















-
+


-
-
+









-
-
+
+








-
-
-
-
+
+
+
+







	[pool release];
}

- (void)handleConnection
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFString *line;
	OFArray *splitted;
	OFArray *split;

	for (;;) {
		@try {
			line = [sock readLine];
		} @catch (OFInvalidEncodingException *e) {
			[e dealloc];
			line = [sock readLineWithEncoding:
			    OF_STRING_ENCODING_WINDOWS_1252];
		}

		if (line == nil)
			break;

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

		splitted = [line componentsSeparatedByString: @" "];
		split = [line componentsSeparatedByString: @" "];

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

			continue;
		}

		/* Connected */
		if (splitted.count >= 4 &&
		    [[splitted objectAtIndex: 1] isEqual: @"001"]) {
		if (split.count >= 4 &&
		    [[split objectAtIndex: 1] isEqual: @"001"]) {
			if ([delegate respondsToSelector:
			    @selector(connectionWasEstablished:)])
				[delegate connectionWasEstablished: self];

			continue;
		}

		/* JOIN */
		if (splitted.count == 3 &&
		    [[splitted objectAtIndex: 1] isEqual: @"JOIN"]) {
			OFString *who = [splitted objectAtIndex: 0];
			OFString *where = [splitted objectAtIndex: 2];
		if (split.count == 3 &&
		    [[split objectAtIndex: 1] isEqual: @"JOIN"]) {
			OFString *who = [split objectAtIndex: 0];
			OFString *where = [split objectAtIndex: 2];
			IRCUser *user;
			IRCChannel *channel;

			who = [who substringWithRange:
			    of_range(1, who.length - 1)];
			user = [IRCUser IRCUserWithString: who];

198
199
200
201
202
203
204
205
206
207
208




209
210
211
212
213

214
215
216
217
218
219
220
221

222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239



240
241
242
243

244
245
246
247
248
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
197
198
199
200
201
202
203




204
205
206
207
208
209
210
211

212
213
214
215
216
217
218
219

220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235



236
237
238
239
240
241

242
243
244
245

246
247

248
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







-
-
-
-
+
+
+
+




-
+







-
+















-
-
-
+
+
+



-
+



-


-
+













-
-
-
-
+
+
+
+



-
+







					  didSeeUser: user
					 joinChannel: channel];

			continue;
		}

		/* PART */
		if (splitted.count >= 3 &&
		    [[splitted objectAtIndex: 1] isEqual: @"PART"]) {
			OFString *who = [splitted objectAtIndex: 0];
			OFString *where = [splitted objectAtIndex: 2];
		if (split.count >= 3 &&
		    [[split objectAtIndex: 1] isEqual: @"PART"]) {
			OFString *who = [split objectAtIndex: 0];
			OFString *where = [split objectAtIndex: 2];
			IRCUser *user;
			IRCChannel *channel;
			OFString *reason = nil;
			size_t pos = who.length + 1 +
			    [[splitted objectAtIndex: 1] length] + 1 +
			    [[split objectAtIndex: 1] length] + 1 +
			    where.length;

			who = [who substringWithRange:
			    of_range(1, who.length - 1)];
			user = [IRCUser IRCUserWithString: who];
			channel = [channels objectForKey: where];

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

			if ([delegate respondsToSelector:
			    @selector(connection:didSeeUser:leaveChannel:
			    withReason:)])
				[delegate connection: self
					  didSeeUser: user
					leaveChannel: channel
					  withReason: reason];

			continue;
		}

		/* QUIT */
		if (splitted.count >= 2 &&
		    [[splitted objectAtIndex: 1] isEqual: @"QUIT"]) {
			OFString *who = [splitted objectAtIndex: 0];
		if (split.count >= 2 &&
		    [[split objectAtIndex: 1] isEqual: @"QUIT"]) {
			OFString *who = [split objectAtIndex: 0];
			IRCUser *user;
			OFString *reason = nil;
			size_t pos = who.length + 1 +
			    [[splitted objectAtIndex: 1] length];
			    [[split objectAtIndex: 1] length];

			who = [who substringWithRange:
			    of_range(1, who.length - 1)];

			user = [IRCUser IRCUserWithString: who];

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

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

			continue;
		}

		/* PRIVMSG */
		if (splitted.count >= 4 &&
		    [[splitted objectAtIndex: 1] isEqual: @"PRIVMSG"]) {
			OFString *from = [splitted objectAtIndex: 0];
			OFString *to = [splitted objectAtIndex: 2];
		if (split.count >= 4 &&
		    [[split objectAtIndex: 1] isEqual: @"PRIVMSG"]) {
			OFString *from = [split objectAtIndex: 0];
			OFString *to = [split objectAtIndex: 2];
			IRCUser *user;
			OFString *msg;
			size_t pos = from.length + 1 +
			    [[splitted objectAtIndex: 1] length] + 1 +
			    [[split 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)];