2 * IRC - Internet Relay Chat, ircd/s_numeric.c
3 * Copyright (C) 1990 Jarkko Oikarinen
5 * Numerous fixes by Markku Savela
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 1, or (at your option)
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.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "s_numeric.h"
33 static char buffer[1024];
37 * Rewritten by Nemesi, Jan 1999, to support numeric nicks in parv[1]
39 * Called when we get a numeric message from a remote _server_ and we are
40 * supposed to forward it somewhere. Note that we always ignore numerics sent
41 * to 'me' and simply drop the message if we can't handle with this properly:
42 * the savy approach is NEVER generate an error in response to an... error :)
45 int do_numeric(int numeric, int nnn, struct Client *cptr, struct Client *sptr,
46 int parc, char *parv[])
48 struct Client *acptr = 0;
49 struct Channel *achptr = 0;
53 /* Avoid trash, we need it to come from a server and have a target */
54 if ((parc < 2) || !IsServer(sptr))
57 /* Who should receive this message ? Will we do something with it ?
58 Note that we use findUser functions, so the target can't be neither
59 a server, nor a channel (?) nor a list of targets (?) .. u2.10
60 should never generate numeric replies to non-users anyway
61 Ahem... it can be a channel actually, csc bots use it :\ --Nem */
63 if (IsChannelName(parv[1]))
64 achptr = FindChannel(parv[1]);
66 acptr = (nnn) ? (findNUser(parv[1])) : (FindUser(parv[1]));
68 if (((!acptr) || (acptr->from == cptr)) && !achptr)
71 /* Remap low number numerics, not that I understand WHY.. --Nemesi */
75 /* Rebuild the buffer with all the parv[] without wasting cycles :) */
79 for (i = 2; i < (parc - 1); i++)
80 for (*b++ = ' ', p = parv[i]; *p; p++)
82 for (*b++ = ' ', *b++ = ':', p = parv[parc - 1]; *p; p++)
87 /* Since .06 this will implicitly use numeric nicks when needed */
90 sendto_prefix_one(acptr, sptr, ":%s %d %s%s",
91 sptr->name, numeric, acptr->name, buffer);
93 sendto_channel_butone(cptr, sptr, achptr, ":%s %d %s%s",
94 sptr->name, numeric, achptr->chname, buffer);