ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/src/parse.c
Revision: 534
Committed: Tue Mar 21 19:06:29 2006 UTC (20 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 25607 byte(s)
Log Message:
- Renamed MAXPARA definition to IRCD_MAXPARA and moved it to ircd_defs.h
- Untabified parse.c

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * parse.c: The message parser.
4 *
5 * Copyright (C) 2002 by the past and present ircd coders, and others.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 *
22 * $Id$
23 */
24
25 #include "stdinc.h"
26 #include "parse.h"
27 #include "client.h"
28 #include "channel.h"
29 #include "handlers.h"
30 #include "common.h"
31 #include "hash.h"
32 #include "ircd.h"
33 #include "numeric.h"
34 #include "send.h"
35 #include "ircd_handler.h"
36 #include "msg.h"
37 #include "s_conf.h"
38 #include "s_user.h"
39 #include "s_serv.h"
40
41 /*
42 * (based on orabidoo's parser code)
43 *
44 * This has always just been a trie. Look at volume III of Knuth ACP
45 *
46 *
47 * ok, you start out with an array of pointers, each one corresponds
48 * to a letter at the current position in the command being examined.
49 *
50 * so roughly you have this for matching 'trie' or 'tie'
51 *
52 * 't' points -> [MessageTree *] 'r' -> [MessageTree *] -> 'i'
53 * -> [MessageTree *] -> [MessageTree *] -> 'e' and matches
54 *
55 * 'i' -> [MessageTree *] -> 'e' and matches
56 *
57 * BUGS (Limitations!)
58 *
59 * I designed this trie to parse ircd commands. Hence it currently
60 * casefolds. This is trivial to fix by increasing MAXPTRLEN.
61 * This trie also "folds" '{' etc. down. This means, the input to this
62 * trie must be alpha tokens only. This again, is a limitation that
63 * can be overcome by increasing MAXPTRLEN to include upper/lower case
64 * at the expense of more memory. At the extreme end, you could make
65 * MAXPTRLEN 128.
66 *
67 * This is also not a patricia trie. On short ircd tokens, this is
68 * not likely going to matter.
69 *
70 * Diane Bruce (Dianora), June 6 2003
71 */
72
73 #define MAXPTRLEN 32
74 /* Must be a power of 2, and
75 * larger than 26 [a-z]|[A-Z]
76 * its used to allocate the set
77 * of pointers at each node of the tree
78 * There are MAXPTRLEN pointers at each node.
79 * Obviously, there have to be more pointers
80 * Than ASCII letters. 32 is a nice number
81 * since there is then no need to shift
82 * 'A'/'a' to base 0 index, at the expense
83 * of a few never used pointers. For a small
84 * parser like this, this is a good compromise
85 * and does make it somewhat faster.
86 *
87 * - Dianora
88 */
89
90 struct MessageTree
91 {
92 int links; /* Count of all pointers (including msg) at this node
93 * used as reference count for deletion of _this_ node.
94 */
95 struct Message *msg;
96 struct MessageTree *pointers[MAXPTRLEN];
97 };
98
99 static struct MessageTree msg_tree;
100
101 /*
102 * NOTE: parse() should not be called recursively by other functions!
103 */
104 static char *sender;
105 static char *para[IRCD_MAXPARA + 1];
106 static char buffer[1024];
107
108 static int cancel_clients(struct Client *, struct Client *, char *);
109 static void remove_unknown(struct Client *, char *, char *);
110 static void do_numeric(char[], struct Client *, struct Client *, int, char **);
111 static void handle_command(struct Message *, struct Client *, struct Client *, unsigned int, char **);
112 static void recurse_report_messages(struct Client *source_p, struct MessageTree *mtree);
113 static void add_msg_element(struct MessageTree *mtree_p, struct Message *msg_p, const char *cmd);
114 static void del_msg_element(struct MessageTree *mtree_p, const char *cmd);
115
116 /* turn a string into a parc/parv pair */
117 static inline int
118 string_to_array(char *string, char *parv[])
119 {
120 char *p;
121 char *buf = string;
122 int x = 1;
123
124 parv[x] = NULL;
125
126 while (*buf == ' ') /* skip leading spaces */
127 buf++;
128
129 if (*buf == '\0') /* ignore all-space args */
130 return(x);
131
132 do
133 {
134 if (*buf == ':') /* Last parameter */
135 {
136 buf++;
137 parv[x++] = buf;
138 parv[x] = NULL;
139 return(x);
140 }
141 else
142 {
143 parv[x++] = buf;
144 parv[x] = NULL;
145
146 if ((p = strchr(buf, ' ')) != NULL)
147 {
148 *p++ = '\0';
149 buf = p;
150 }
151 else
152 return(x);
153 }
154
155 while (*buf == ' ')
156 buf++;
157
158 if (*buf == '\0')
159 return(x);
160 } while (x < IRCD_MAXPARA - 1);
161
162 if (*p == ':')
163 p++;
164
165 parv[x++] = p;
166 parv[x] = NULL;
167 return(x);
168 }
169
170 /*
171 * parse a buffer.
172 *
173 * NOTE: parse() should not be called recusively by any other functions!
174 */
175 void
176 parse(struct Client *client_p, char *pbuffer, char *bufend)
177 {
178 struct Client *from = client_p;
179 char *ch;
180 char *s;
181 char *numeric = 0;
182 unsigned int i = 0;
183 int paramcount;
184 int mpara = 0;
185 struct Message *mptr = NULL;
186
187 if (IsDefunct(client_p))
188 return;
189
190 assert(client_p->localClient->fd.flags.open);
191 assert((bufend - pbuffer) < 512);
192
193 for (ch = pbuffer; *ch == ' '; ch++) /* skip spaces */
194 /* null statement */ ;
195
196 para[0] = from->name;
197
198 if (*ch == ':')
199 {
200 ch++;
201
202 /* Copy the prefix to 'sender' assuming it terminates
203 * with SPACE (or NULL, which is an error, though).
204 */
205 sender = ch;
206
207 if ((s = strchr(ch, ' ')) != NULL)
208 {
209 *s = '\0';
210 s++;
211 ch = s;
212 }
213
214 if (*sender && IsServer(client_p))
215 {
216 /*
217 * XXX it could be useful to know which of these occurs most frequently.
218 * the ID check should always come first, though, since it is so easy.
219 */
220 if ((from = find_person(client_p, sender)) == NULL)
221 {
222 from = find_server(sender);
223
224 if (from == NULL && IsCapable(client_p, CAP_TS6) &&
225 client_p->name[0] == '*' && IsDigit(*sender) && strlen(sender) == 3)
226 {
227 /* Dirty hack to allow messages from masked SIDs (i.e. the ones
228 * hidden by fakename="..."). It shouldn't break anything, since
229 * unknown SIDs don't happen during normal ircd work --adx
230 */
231 from = client_p;
232 }
233 }
234
235 /*
236 * Hmm! If the client corresponding to the
237 * prefix is not found--what is the correct
238 * action??? Now, I will ignore the message
239 * (old IRC just let it through as if the
240 * prefix just wasn't there...) --msa
241 */
242 if (from == NULL)
243 {
244 ++ServerStats.is_unpf;
245 remove_unknown(client_p, sender, pbuffer);
246 return;
247 }
248
249 para[0] = from->name;
250
251 if (from->from != client_p)
252 {
253 ++ServerStats.is_wrdi;
254 cancel_clients(client_p, from, pbuffer);
255 return;
256 }
257 }
258
259 while (*ch == ' ')
260 ++ch;
261 }
262
263 if (*ch == '\0')
264 {
265 ++ServerStats.is_empt;
266 return;
267 }
268
269 /* Extract the command code from the packet. Point s to the end
270 * of the command code and calculate the length using pointer
271 * arithmetic. Note: only need length for numerics and *all*
272 * numerics must have parameters and thus a space after the command
273 * code. -avalon
274 */
275
276 /* EOB is 3 chars long but is not a numeric */
277 if (*(ch + 3) == ' ' && /* ok, lets see if its a possible numeric.. */
278 IsDigit(*ch) && IsDigit(*(ch + 1)) && IsDigit(*(ch + 2)))
279 {
280 mptr = NULL;
281 numeric = ch;
282 paramcount = IRCD_MAXPARA;
283 ++ServerStats.is_num;
284 s = ch + 3; /* I know this is ' ' from above if */
285 *s++ = '\0'; /* blow away the ' ', and point s to next part */
286 }
287 else
288 {
289 int ii = 0;
290
291 if ((s = strchr(ch, ' ')) != NULL)
292 *s++ = '\0';
293
294 if ((mptr = find_command(ch)) == NULL)
295 {
296 /* Note: Give error message *only* to recognized
297 * persons. It's a nightmare situation to have
298 * two programs sending "Unknown command"'s or
299 * equivalent to each other at full blast....
300 * If it has got to person state, it at least
301 * seems to be well behaving. Perhaps this message
302 * should never be generated, though... --msa
303 * Hm, when is the buffer empty -- if a command
304 * code has been found ?? -Armin
305 */
306 if (pbuffer[0] != '\0')
307 {
308 if (IsClient(from))
309 sendto_one(from, form_str(ERR_UNKNOWNCOMMAND),
310 me.name, from->name, ch);
311 }
312
313 ++ServerStats.is_unco;
314 return;
315 }
316
317 assert(mptr->cmd != NULL);
318
319 paramcount = mptr->parameters;
320 mpara = mptr->maxpara;
321
322 ii = bufend - ((s) ? s : ch);
323 mptr->bytes += ii;
324 }
325
326 if (s != NULL)
327 i = string_to_array(s, para);
328 else
329 {
330 i = 0;
331 para[1] = NULL;
332 }
333
334 if (mptr == NULL)
335 do_numeric(numeric, client_p, from, i, para);
336 else
337 handle_command(mptr, client_p, from, i, para);
338 }
339
340 /* handle_command()
341 *
342 * inputs - pointer to message block
343 * - pointer to client
344 * - pointer to client message is from
345 * - count of number of args
346 * - pointer to argv[] array
347 * output - -1 if error from server
348 * side effects -
349 */
350 static void
351 handle_command(struct Message *mptr, struct Client *client_p,
352 struct Client *from, unsigned int i, char *hpara[])
353 {
354 MessageHandler handler = 0;
355
356 if (IsServer(client_p))
357 mptr->rcount++;
358
359 mptr->count++;
360
361 /* New patch to avoid server flooding from unregistered connects
362 * - Pie-Man 07/27/2000 */
363 if (!IsRegistered(client_p))
364 {
365 /* if its from a possible server connection
366 * ignore it.. more than likely its a header thats sneaked through
367 */
368 if ((IsHandshake(client_p) || IsConnecting(client_p) ||
369 IsServer(client_p)) && !(mptr->flags & MFLG_UNREG))
370 return;
371 }
372
373 handler = mptr->handlers[client_p->handler];
374
375 /* check right amount of params is passed... --is */
376 if (i < mptr->parameters)
377 {
378 if (!IsServer(client_p))
379 {
380 sendto_one(client_p, form_str(ERR_NEEDMOREPARAMS),
381 me.name, EmptyString(hpara[0]) ? "*" : hpara[0], mptr->cmd);
382 }
383 else
384 {
385 sendto_realops_flags(UMODE_ALL, L_ALL,
386 "Dropping server %s due to (invalid) command '%s' "
387 "with only %d arguments (expecting %d).",
388 client_p->name, mptr->cmd, i, mptr->parameters);
389 ilog(L_CRIT, "Insufficient parameters (%d) for command '%s' from %s.",
390 i, mptr->cmd, client_p->name);
391 exit_client(client_p, client_p,
392 "Not enough arguments to server command.");
393 }
394 }
395 else
396 (*handler)(client_p, from, i, hpara);
397 }
398
399 /* clear_tree_parse()
400 *
401 * inputs - NONE
402 * output - NONE
403 * side effects - MUST MUST be called at startup ONCE before
404 * any other keyword routine is used.
405 */
406 void
407 clear_tree_parse(void)
408 {
409 memset(&msg_tree, 0, sizeof(msg_tree));
410 }
411
412 /* add_msg_element()
413 *
414 * inputs - pointer to MessageTree
415 * - pointer to Message to add for given command
416 * - pointer to current portion of command being added
417 * output - NONE
418 * side effects - recursively build the Message Tree ;-)
419 */
420 /*
421 * How this works.
422 *
423 * The code first checks to see if its reached the end of the command
424 * If so, that struct MessageTree has a msg pointer updated and the links
425 * count incremented, since a msg pointer is a reference.
426 * Then the code descends recursively, building the trie.
427 * If a pointer index inside the struct MessageTree is NULL a new
428 * child struct MessageTree has to be allocated.
429 * The links (reference count) is incremented as they are created
430 * in the parent.
431 */
432 static void
433 add_msg_element(struct MessageTree *mtree_p,
434 struct Message *msg_p, const char *cmd)
435 {
436 struct MessageTree *ntree_p;
437
438 if (*cmd == '\0')
439 {
440 mtree_p->msg = msg_p;
441 mtree_p->links++; /* Have msg pointer, so up ref count */
442 }
443 else
444 {
445 /* *cmd & (MAXPTRLEN-1)
446 * convert the char pointed to at *cmd from ASCII to an integer
447 * between 0 and MAXPTRLEN.
448 * Thus 'A' -> 0x1 'B' -> 0x2 'c' -> 0x3 etc.
449 */
450
451 if ((ntree_p = mtree_p->pointers[*cmd & (MAXPTRLEN-1)]) == NULL)
452 {
453 ntree_p = (struct MessageTree *)MyMalloc(sizeof(struct MessageTree));
454 mtree_p->pointers[*cmd & (MAXPTRLEN-1)] = ntree_p;
455
456 mtree_p->links++; /* Have new pointer, so up ref count */
457 }
458
459 add_msg_element(ntree_p, msg_p, cmd+1);
460 }
461 }
462
463 /* del_msg_element()
464 *
465 * inputs - Pointer to MessageTree to delete from
466 * - pointer to command name to delete
467 * output - NONE
468 * side effects - recursively deletes a token from the Message Tree ;-)
469 */
470 /*
471 * How this works.
472 *
473 * Well, first off, the code recursively descends into the trie
474 * until it finds the terminating letter of the command being removed.
475 * Once it has done that, it marks the msg pointer as NULL then
476 * reduces the reference count on that allocated struct MessageTree
477 * since a command counts as a reference.
478 *
479 * Then it pops up the recurse stack. As it comes back up the recurse
480 * The code checks to see if the child now has no pointers or msg
481 * i.e. the links count has gone to zero. If its no longer used, the
482 * child struct MessageTree can be deleted. The parent reference
483 * to this child is then removed and the parents link count goes down.
484 * Thus, we continue to go back up removing all unused MessageTree(s)
485 */
486 static void
487 del_msg_element(struct MessageTree *mtree_p, const char *cmd)
488 {
489 struct MessageTree *ntree_p;
490
491 /*
492 * In case this is called for a nonexistent command
493 * check that there is a msg pointer here, else links-- goes -ve
494 * -db
495 */
496 if ((*cmd == '\0') && (mtree_p->msg != NULL))
497 {
498 mtree_p->msg = NULL;
499 mtree_p->links--;
500 }
501 else
502 {
503 if ((ntree_p = mtree_p->pointers[*cmd & (MAXPTRLEN-1)]) != NULL)
504 {
505 del_msg_element(ntree_p, cmd+1);
506
507 if (ntree_p->links == 0)
508 {
509 mtree_p->pointers[*cmd & (MAXPTRLEN-1)] = NULL;
510 mtree_p->links--;
511 MyFree(ntree_p);
512 }
513 }
514 }
515 }
516
517 /* msg_tree_parse()
518 *
519 * inputs - Pointer to command to find
520 * - Pointer to MessageTree root
521 * output - Find given command returning Message * if found NULL if not
522 * side effects - none
523 */
524 static struct Message *
525 msg_tree_parse(const char *cmd, struct MessageTree *root)
526 {
527 struct MessageTree *mtree = root;
528 assert(cmd && *cmd);
529
530 while (IsAlpha(*cmd) && (mtree = mtree->pointers[*cmd & (MAXPTRLEN - 1)]))
531 if (*++cmd == '\0')
532 return mtree->msg;
533
534 return NULL;
535 }
536
537 /* mod_add_cmd()
538 *
539 * inputs - pointer to struct Message
540 * output - none
541 * side effects - load this one command name
542 * msg->count msg->bytes is modified in place, in
543 * modules address space. Might not want to do that...
544 */
545 void
546 mod_add_cmd(struct Message *msg)
547 {
548 struct Message *found_msg = NULL;
549
550 if (msg == NULL)
551 return;
552
553 /* someone loaded a module with a bad messagetab */
554 assert(msg->cmd != NULL);
555
556 /* command already added? */
557 if ((found_msg = msg_tree_parse(msg->cmd, &msg_tree)) != NULL)
558 return;
559
560 add_msg_element(&msg_tree, msg, msg->cmd);
561 msg->count = msg->rcount = msg->bytes = 0;
562 }
563
564 /* mod_del_cmd()
565 *
566 * inputs - pointer to struct Message
567 * output - none
568 * side effects - unload this one command name
569 */
570 void
571 mod_del_cmd(struct Message *msg)
572 {
573 assert(msg != NULL);
574
575 if (msg == NULL)
576 return;
577
578 del_msg_element(&msg_tree, msg->cmd);
579 }
580
581 /* find_command()
582 *
583 * inputs - command name
584 * output - pointer to struct Message
585 * side effects - none
586 */
587 struct Message *
588 find_command(const char *cmd)
589 {
590 return msg_tree_parse(cmd, &msg_tree);
591 }
592
593 /* report_messages()
594 *
595 * inputs - pointer to client to report to
596 * output - NONE
597 * side effects - client is shown list of commands
598 */
599 void
600 report_messages(struct Client *source_p)
601 {
602 struct MessageTree *mtree = &msg_tree;
603 int i;
604
605 for (i = 0; i < MAXPTRLEN; i++)
606 {
607 if (mtree->pointers[i] != NULL)
608 recurse_report_messages(source_p, mtree->pointers[i]);
609 }
610 }
611
612 static void
613 recurse_report_messages(struct Client *source_p, struct MessageTree *mtree)
614 {
615 int i;
616
617 if (mtree->msg != NULL)
618 {
619 sendto_one(source_p, form_str(RPL_STATSCOMMANDS),
620 me.name, source_p->name, mtree->msg->cmd,
621 mtree->msg->count, mtree->msg->bytes,
622 mtree->msg->rcount);
623 }
624
625 for (i = 0; i < MAXPTRLEN; i++)
626 {
627 if (mtree->pointers[i] != NULL)
628 recurse_report_messages(source_p, mtree->pointers[i]);
629 }
630 }
631
632 /* cancel_clients()
633 *
634 * inputs -
635 * output -
636 * side effects -
637 */
638 static int
639 cancel_clients(struct Client *client_p, struct Client *source_p, char *cmd)
640 {
641 /* kill all possible points that are causing confusion here,
642 * I'm not sure I've got this all right...
643 * - avalon
644 *
645 * knowing avalon, probably not.
646 */
647
648 /* with TS, fake prefixes are a common thing, during the
649 * connect burst when there's a nick collision, and they
650 * must be ignored rather than killed because one of the
651 * two is surviving.. so we don't bother sending them to
652 * all ops everytime, as this could send 'private' stuff
653 * from lagged clients. we do send the ones that cause
654 * servers to be dropped though, as well as the ones from
655 * non-TS servers -orabidoo
656 */
657 /* Incorrect prefix for a server from some connection. If it is a
658 * client trying to be annoying, just QUIT them, if it is a server
659 * then the same deal.
660 */
661 if (IsServer(source_p) || IsMe(source_p))
662 {
663 sendto_realops_flags(UMODE_DEBUG, L_ADMIN, "Message for %s[%s] from %s",
664 source_p->name, source_p->from->name,
665 get_client_name(client_p, SHOW_IP));
666 sendto_realops_flags(UMODE_DEBUG, L_OPER, "Message for %s[%s] from %s",
667 source_p->name, source_p->from->name,
668 get_client_name(client_p, MASK_IP));
669 sendto_realops_flags(UMODE_DEBUG, L_ALL,
670 "Not dropping server %s (%s) for Fake Direction",
671 client_p->name, source_p->name);
672 return(-1);
673 /* return exit_client(client_p, client_p, &me, "Fake Direction");*/
674 }
675
676 /* Ok, someone is trying to impose as a client and things are
677 * confused. If we got the wrong prefix from a server, send out a
678 * kill, else just exit the lame client.
679 */
680 /* If the fake prefix is coming from a TS server, discard it
681 * silently -orabidoo
682 *
683 * all servers must be TS these days --is
684 */
685 sendto_realops_flags(UMODE_DEBUG, L_ADMIN,
686 "Message for %s[%s@%s!%s] from %s (TS, ignored)",
687 source_p->name, source_p->username, source_p->host,
688 source_p->from->name, get_client_name(client_p, SHOW_IP));
689 sendto_realops_flags(UMODE_DEBUG, L_OPER,
690 "Message for %s[%s@%s!%s] from %s (TS, ignored)",
691 source_p->name, source_p->username, source_p->host,
692 source_p->from->name, get_client_name(client_p, MASK_IP));
693
694 return(0);
695 }
696
697 /* remove_unknown()
698 *
699 * inputs -
700 * output -
701 * side effects -
702 */
703 static void
704 remove_unknown(struct Client *client_p, char *lsender, char *lbuffer)
705 {
706 /* Do kill if it came from a server because it means there is a ghost
707 * user on the other server which needs to be removed. -avalon
708 * Tell opers about this. -Taner
709 */
710 /* '[0-9]something' is an ID (KILL/SQUIT depending on its length)
711 * 'nodots' is a nickname (KILL)
712 * 'no.dot.at.start' is a server (SQUIT)
713 */
714 if ((IsDigit(*lsender) && strlen(lsender) <= IRC_MAXSID) ||
715 strchr(lsender, '.') != NULL)
716 {
717 sendto_realops_flags(UMODE_DEBUG, L_ADMIN,
718 "Unknown prefix (%s) from %s, Squitting %s",
719 lbuffer, get_client_name(client_p, SHOW_IP), lsender);
720 sendto_realops_flags(UMODE_DEBUG, L_OPER,
721 "Unknown prefix (%s) from %s, Squitting %s",
722 lbuffer, client_p->name, lsender);
723 sendto_one(client_p, ":%s SQUIT %s :(Unknown prefix (%s) from %s)",
724 me.name, lsender, lbuffer, client_p->name);
725 }
726 else
727 sendto_one(client_p, ":%s KILL %s :%s (Unknown Client)",
728 me.name, lsender, me.name);
729 }
730
731 /*
732 *
733 * parc number of arguments ('sender' counted as one!)
734 * parv[0] pointer to 'sender' (may point to empty string) (not used)
735 * parv[1]..parv[parc-1]
736 * pointers to additional parameters, this is a NULL
737 * terminated list (parv[parc] == NULL).
738 *
739 * *WARNING*
740 * Numerics are mostly error reports. If there is something
741 * wrong with the message, just *DROP* it! Don't even think of
742 * sending back a neat error message -- big danger of creating
743 * a ping pong error message...
744 */
745 static void
746 do_numeric(char numeric[], struct Client *client_p, struct Client *source_p,
747 int parc, char *parv[])
748 {
749 struct Client *target_p;
750 struct Channel *chptr;
751 char *t; /* current position within the buffer */
752 int i, tl; /* current length of presently being built string in t */
753
754 if (parc < 2 || !IsServer(source_p))
755 return;
756
757 /* Remap low number numerics. */
758 if (numeric[0] == '0')
759 numeric[0] = '1';
760
761 /* Prepare the parameter portion of the message into 'buffer'.
762 * (Because the buffer is twice as large as the message buffer
763 * for the socket, no overflow can occur here... ...on current
764 * assumptions--bets are off, if these are changed --msa)
765 */
766 t = buffer;
767 for (i = 2; i < (parc - 1); i++)
768 {
769 tl = ircsprintf(t, " %s", parv[i]);
770 t += tl;
771 }
772
773 ircsprintf(t," :%s", parv[parc-1]);
774
775 if (((target_p = find_person(client_p, parv[1])) != NULL) ||
776 ((target_p = find_server(parv[1])) != NULL))
777 {
778 if (IsMe(target_p))
779 {
780 int num;
781
782 /*
783 * We shouldn't get numerics sent to us,
784 * any numerics we do get indicate a bug somewhere..
785 */
786 /* ugh. this is here because of nick collisions. when two servers
787 * relink, they burst each other their nicks, then perform collides.
788 * if there is a nick collision, BOTH servers will kill their own
789 * nicks, and BOTH will kill the other servers nick, which wont exist,
790 * because it will have been already killed by the local server.
791 *
792 * unfortunately, as we cant guarantee other servers will do the
793 * "right thing" on a nick collision, we have to keep both kills.
794 * ergo we need to ignore ERR_NOSUCHNICK. --fl_
795 */
796 /* quick comment. This _was_ tried. i.e. assume the other servers
797 * will do the "right thing" and kill a nick that is colliding.
798 * unfortunately, it did not work. --Dianora
799 */
800
801 /* Yes, a good compiler would have optimised this, but
802 * this is probably easier to read. -db
803 */
804 num = atoi(numeric);
805
806 if (num != ERR_NOSUCHNICK)
807 sendto_realops_flags(UMODE_ALL, L_ADMIN,
808 "*** %s(via %s) sent a %s numeric to me: %s",
809 source_p->name, client_p->name, numeric, buffer);
810 return;
811 }
812 else if (target_p->from == client_p)
813 {
814 /* This message changed direction (nick collision?)
815 * ignore it.
816 */
817 return;
818 }
819
820 /* csircd will send out unknown umode flag for +a (admin), drop it here. */
821 if ((atoi(numeric) == ERR_UMODEUNKNOWNFLAG) && MyClient(target_p))
822 return;
823
824 /* Fake it for server hiding, if its our client */
825 if (ConfigServerHide.hide_servers &&
826 MyClient(target_p) && !IsOper(target_p))
827 sendto_one(target_p, ":%s %s %s%s", me.name, numeric, target_p->name, buffer);
828 else if (!MyClient(target_p) && IsCapable(target_p->from, CAP_TS6) && HasID(source_p))
829 sendto_one(target_p, ":%s %s %s%s", source_p->id, numeric, target_p->id, buffer);
830 else /* either it is our client, or a client linked throuh a non-ts6 server. must use names! */
831 sendto_one(target_p, ":%s %s %s%s", source_p->name, numeric, target_p->name, buffer);
832 return;
833 }
834 else if ((chptr = hash_find_channel(parv[1])) != NULL)
835 sendto_channel_local(ALL_MEMBERS, NO, chptr,
836 ":%s %s %s %s",
837 source_p->name,
838 numeric, chptr->chname, buffer);
839 }
840
841 /* m_not_oper()
842 * inputs -
843 * output -
844 * side effects - just returns a nastyogram to given user
845 */
846 void
847 m_not_oper(struct Client *client_p, struct Client *source_p,
848 int parc, char *parv[])
849 {
850 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
851 me.name, parv[0]);
852 }
853
854 void
855 m_unregistered(struct Client *client_p, struct Client *source_p,
856 int parc, char *parv[])
857 {
858 /* bit of a hack.
859 * I don't =really= want to waste a bit in a flag
860 * number_of_nick_changes is only really valid after the client
861 * is fully registered..
862 */
863 if (client_p->localClient->number_of_nick_changes == 0)
864 {
865 sendto_one(client_p, ":%s %d * %s :Register first.",
866 me.name, ERR_NOTREGISTERED, parv[0]);
867 client_p->localClient->number_of_nick_changes++;
868 }
869 }
870
871 void
872 m_registered(struct Client *client_p, struct Client *source_p,
873 int parc, char *parv[])
874 {
875 sendto_one(client_p, form_str(ERR_ALREADYREGISTRED),
876 me.name, parv[0]);
877 }
878
879 void
880 m_ignore(struct Client *client_p, struct Client *source_p,
881 int parc, char *parv[])
882 {
883 return;
884 }
885

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision