This repository has been archived by the owner on Apr 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
parseline.c
360 lines (292 loc) · 11.4 KB
/
parseline.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
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
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
187
188
189
190
191
192
193
194
195
196
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
/*******************************************************************************
*
* lightweight - a minimalistic chanserv for ircu's p10-protocol
*
* copyright 2002 by Rasmus Have & David Mansell
*
* $Id: parseline.c,v 1.23 2003/09/08 01:19:25 zarjazz Exp $
*
*******************************************************************************/
/*
This file is part of lightweight.
lightweight is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
lightweight is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with lightweight; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <lightweight.h>
#include <globalexterns.h>
#include <usersdb.h>
#include <channelsdb.h>
#include <channels.h>
int ParseLine(void)
{
char *sender;
char *command;
char *tail;
/* Make sure we dont have any spaces in front. */
sender = StripBlanks(currentline);
/* Given that every single line is passed through here
* I don't see that null lines are a problem. I'm
* 99% sure they are simply caused by a chunk ending
* between the \r and \n from the server.
*
* The easiest way to deal with this is simply to bounce
* them back here silently. - splidge
*/
if (*sender == '\0')
return (0);
/* fprintf(stderr,"<< %s\n",sender); */
/* Get the pointer to the next word (the command) and make the sender token zero terminated. */
command = SeperateWord(sender);
/* Get a pointer to the tail and zero terminate the command. */
tail = SeperateWord(command);
/* Switch over the commands we give a fuck about and fuck the rest. */
if (command[0] == 'B' && command[1] == '\0') {
/* Grab the timestamp from the burst */
/* a9 B #bar 1016451591 a9AAD:ov,a8AAE:o,a9AAK */
char *channel, *timestr, *modestr;
struct reggedchannel *chn_ptr;
time_t newtimestamp;
char buf[512];
channel = tail;
timestr = SeperateWord(channel);
modestr = SeperateWord(timestr);
SeperateWord(modestr);
chn_ptr = GetChannelPointer(channel);
if (chn_ptr != NULL) {
newtimestamp = strtol(timestr, NULL, 10);
SyncTimestamp(chn_ptr, newtimestamp);
if (IsInviteOnly(chn_ptr) && (!modestr || !strchr(modestr, 'i'))) {
/* Channel is bursted without +i but is invite only. Send +i mode. */
sprintf(buf, "%sAAA M %s +i\r\n", my_numeric, chn_ptr->channelname);
SendLine(buf);
}
}
} else if (command[0] == 'N' && command[1] == '\0') {
/* Nick command recieved. */
/* Branch on Nick introduction and Nick change. */
/* Introdution: Create a new user in the userdb. */
/* Change: Update the userdb. */
if (sender[2] == '\0') {
/* Came from server: it's a new user */
/* AD N Q 3 000000100 TheQBot CServe.quakenet.org +oiwdk B]AAAB ADAAA :The Q Bot */
int isoper = 0;
char *nick = tail;
char *numeric;
char *tempstr;
char *account = NULL;
int i;
for (i = 0; i < 5; i++)
tail = SeperateWord(tail);
if (*tail == '+') {
/* There are usermodes for this user.
* We are interested in three things:
* - We now need to advance an extra word down the sentence
* - Check if the usermodes include +o (oper)
* - Check if the usermodes include +r (registered nick)
* (and do appropriate things with this information
* After this block executes, "tail" will point at the IP address field
* (if there were no modes this was true already) */
tempstr = tail; /* tempstr = list of user modes */
tail = SeperateWord(tail);
if (IsCharInString('r', tempstr)) {
/* Found +r usermode -- that means the user is already authed */
/* tail is now pointing at the auth name, so grab that and advance another word */
account = tail;
tail = SeperateWord(tail);
}
if (IsCharInString('h', tempstr)) {
/* Found +h usermode - just skip the parameter */
tail = SeperateWord(tail);
}
isoper = IsCharInString('o', tempstr);
}
tail = SeperateWord(tail);
numeric = tail;
SeperateWord(tail);
UserNickCreation(numeric, nick, isoper);
if (account != NULL) {
char *accountts;
if((accountts=strchr(account,':'))){
char *accountid;
*accountts++='\0';
if((accountid=strchr(accountts,':'))){
*accountid++='\0';
}
}
/* Account was authed: so call the auth routine now... */
AuthUser(numeric, account);
}
} else {
/* Rename */
/* [hAAA N splidge_ 1013972401 */
char *newnick = tail;
tail = SeperateWord(tail);
UserNickChange(sender, newnick);
}
} else if (command[0] == 'A' && command[1] == 'C' && command[2] == '\0') {
/* ACCOUNT command received. */
/* Auth the user */
/* AD AC [hAAA splidge */
char *numeric, *account, *accountts, *accountid;
numeric = tail;
account = SeperateWord(tail);
tail = SeperateWord(tail);
if((accountts=strchr(account,' '))){
*accountts++='\0';
if((accountid=strchr(accountts,' '))){
*accountid++='\0';
}
}
AuthUser(numeric, account);
} else if (command[0] == 'Q' && command[1] == '\0') {
/* Quit command recieved. */
/* Remove user from userdb. */
/* Thank you for flying QuakeNet. */
/* [hAAA Q :m00 */
DeleteUser(sender);
} else if (command[0] == 'D' && command[1] == '\0') {
/* Kill command received. */
/* Much like Quit, this one */
/* a9AAD D bcAAQ :frogsquad.netsplit.net!splidge (m00) */
char *victim = tail;
tail = SeperateWord(tail);
DeleteUser(victim);
} else if (command[0] == 'J' && command[1] == '\0') {
/* Join command recieved. */
/* Check if user is authed or if channel is known, whichever is fastest. */
/* If authed or if channel is known, check if user has flags on channel, and op/voice the person in that case. */
/* The only stuff in the tail is the list of channels to join, or 0 */
/* Luckily, ircu seems to deal with most of the "JOIN 0" nastiness for us */
/* a9AAD J #foo,#bar */
/* a9AAD J 0 */
/* Seperate off the second parameter (if any) */
SeperateWord(tail);
DoJoins(sender, tail, 0); /* Last parameter = 0 => this is NOT a CREATE */
} else if (command[0] == 'C' && command[1] == '\0') {
/* Create command recieved. */
/* Check if user is authed or if channel is known, whichever is fastest. */
/* If authed or if channel is known, check if user has flags on channel, and op/voice the person in that case. Deop in the opposite case. */
char *chanlist = tail;
char *timestr;
timestr = SeperateWord(tail);
SeperateWord(timestr);
DoJoins(sender, chanlist, strtol(timestr, NULL, 10)); /* Last parameter = timestamp */
} else if (command[0] == 'M' && command[1] == '\0') {
/* mode change */
/* [hAAA M splidge[wind] :+k */
/* [hAAA M #twilightzone -o [hAAA */
int dir = 1;
char *target;
char *modes;
char *cp;
struct user *usrptr;
target = tail;
modes = SeperateWord(target);
if (target[0] != '#') { /* Not a channel (you don't get mode changes on + channels... */
/* This must be a user mode change. Make sure it all checks out */
/* Assuming it does, we're only interested in users who are opering or deopering */
if ((usrptr = FindUserByNumeric(sender)) == NULL) {
Error(ERR_PROTOCOL | ERR_WARNING, "Mode change from non-existent user %s", sender);
return 0;
}
if (Strcmp(usrptr->nick, target)) {
Error(ERR_PROTOCOL | ERR_WARNING, "Mode change for other user (%s) from %s", target, usrptr->nick);
return 0;
}
SeperateWord(modes);
if (modes == NULL) {
Error(ERR_PROTOCOL | ERR_WARNING, "Mode change with no parameters from %s", sender);
return 0;
}
for (cp = modes; *cp != '\0'; cp++) { /* Step over each character in the mode string */
switch (*cp) {
case '+':
dir = 1;
break;
case '-':
dir = 0;
break;
case 'o':
usrptr->oper = dir;
break;
}
}
} else {
/* Channel mode change -- which we healthily ignore for now */
/* Eeep! Need to examine -i channelmodes, since we introduced invite only channels. */
DoChanMode(sender, target, modes);
}
} else if (command[0] == 'P' && command[1] == '\0') {
/* Privmsg command recieved. */
/* Usersupport... ugh. */
/* a9AAD P #twilightzone :ooops */
/* a9AAD P #twilightzone :I missed a field out :) */
/* a9AAD P ppAAA :YOU SUCK */
char *content;
content = SeperateWord(tail);
/* Ignore the target (assume it was us..) */
/* Note that since we're not doing AUTH we don't need "secure" messages */
/* Check that the user is authed -- we don't talk to unauthed masses */
ProcessMessage(sender, content + 1);
} else if (command[0] == 'G' && command[1] == '\0') {
/* Ping command recieved. */
/* Send "Im fine. Weather is good. Send more money.". */
char buf[512];
sprintf(buf, "%s Z %s\r\n", my_numeric, tail);
SendLine(buf);
} else if (command[0] == 'S' && command[1] == '\0') {
/* Server command recieved. */
/* Create server in the servertree. */
/* AH S hub.uk.quakenet.org 2 0 1013950331 P10 AKAD] 0 :BarrysWorld QuakeNet IRC Server */
char *servername;
int count;
int iparentnumeric;
int iservernumeric;
int imaxusersnumeric;
servername = tail;
for (count = 0; count < 5; count++)
tail = SeperateWord(tail);
iparentnumeric = NumericToLong(sender, 2);
iservernumeric = NumericToLong(tail, 2);
imaxusersnumeric = NumericToLong(tail + 2, 3) + 1;
AddServer(iservernumeric, servername, imaxusersnumeric, iparentnumeric);
} else if (command[0] == 'S' && command[1] == 'Q' && command[2] == '\0') {
/* Server Quit command recieved. */
/* Delete server in the servertree and remove all corresponding clients. */
/* [h SQ wind.splidge.netsplit.net 0 :Ping timeout */
char *servername;
servername = tail;
tail = SeperateWord(tail);
HandleSquit(servername);
} else if (command[0] == 'E' && command[1] == 'B' && command[2] == '\0') {
/* End of burst command. */
/* If it's OUR server we need to ack */
char buf[10];
/* Quick hack to get some stats whenever a EB is recieved. */
UserHashStats();
if (!strncmp(sender, MyServer, 2)) {
/* It was my server which said EB so throw back a EA. */
/* We end our own burst here too */
burst_done = 1;
#ifndef HORRIBLE_DEOPALL_HACK
sprintf(buf, "%s EB\r\n", my_numeric);
SendLine(buf);
sprintf(buf, "%s EA\r\n", my_numeric);
SendLine(buf);
#endif
}
} else {
/* Crap command recieved. */
/* Well, is there anything else we care about? */
}
return (1);
}