]> jfr.im git - irc/quakenet/snircd.git/blame - ircd/s_numeric.c
Should be unsigned long for A
[irc/quakenet/snircd.git] / ircd / s_numeric.c
CommitLineData
189935b1 1/*
2 * IRC - Internet Relay Chat, ircd/s_numeric.c
3 * Copyright (C) 1990 Jarkko Oikarinen
4 *
5 * Numerous fixes by Markku Savela
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 1, or (at your option)
10 * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21/** @file
22 * @brief Send a numeric message to a client.
23 * @version $Id: s_numeric.c,v 1.11.2.1 2005/10/10 12:17:48 entrope Exp $
24 */
25#include "config.h"
26
27#include "s_numeric.h"
28#include "channel.h"
29#include "client.h"
30#include "hash.h"
31#include "ircd.h"
32#include "ircd_features.h"
33#include "ircd_snprintf.h"
34#include "numnicks.h"
35#include "send.h"
36#include "struct.h"
37
38
39/*
40 * do_numeric()
41 * Rewritten by Nemesi, Jan 1999, to support numeric nicks in parv[1]
42 *
43 * Called when we get a numeric message from a remote _server_ and we are
44 * supposed to forward it somewhere. Note that we always ignore numerics sent
45 * to 'me' and simply drop the message if we can't handle with this properly:
46 * the savvy approach is NEVER generate an error in response to an... error :)
47 */
48
49/** Forwards a numeric message from a remote server.
50 * @param numeric Value of numeric message.
51 * @param nnn If non-zero, treat parv[1] as a numnick; else as a client name.
52 * @param cptr Client that originated the numeric.
53 * @param sptr Peer that sent us the numeric.
54 * @param parc Count of valid arguments in \a parv.
55 * @param parv Argument list.
56 * @return Zero (always).
57 */
58int do_numeric(int numeric, int nnn, struct Client *cptr, struct Client *sptr,
59 int parc, char *parv[])
60{
61 struct Client *acptr = 0;
62 struct Channel *achptr = 0;
63 char num[4];
64
65 /* Avoid trash, we need it to come from a server and have a target */
66 if ((parc < 2) || !IsServer(sptr))
67 return 0;
68
69 /* Who should receive this message ? Will we do something with it ?
70 Note that we use findUser functions, so the target can't be neither
71 a server, nor a channel (?) nor a list of targets (?) .. u2.10
72 should never generate numeric replies to non-users anyway
73 Ahem... it can be a channel actually, csc bots use it :\ --Nem */
74
75 if (IsChannelName(parv[1]))
76 achptr = FindChannel(parv[1]);
77 else
78 acptr = (nnn) ? (findNUser(parv[1])) : (FindUser(parv[1]));
79
80 if (((!acptr) || (cli_from(acptr) == cptr)) && !achptr)
81 return 0;
82
83 /* Remap low number numerics, not that I understand WHY.. --Nemesi */
84 /* numerics below 100 talk about the current 'connection', you're not
85 * connected to a remote server so it doesn't make sense to send them
86 * remotely - but the information they contain may be useful, so we
87 * remap them up. Weird, but true. -- Isomer */
88 if (numeric < 100)
89 numeric += 100;
90
91 ircd_snprintf(0, num, sizeof(num), "%03d", numeric);
92
93 /* Since 2.10.10.pl14 we rewrite numerics from remote servers to appear to
94 * come from the local server
95 */
96 if (acptr)
97 sendcmdto_one((feature_bool(FEAT_HIS_REWRITE) && !IsOper(acptr)) ?
98 &me : sptr,
99 num, num, acptr, "%C %s", acptr, parv[2]);
100 else
101 sendcmdto_channel_butone(feature_bool(FEAT_HIS_REWRITE) ? &me : sptr,
102 num, num, achptr, cptr, SKIP_DEAF | SKIP_BURST,
103 "%H %s", achptr, parv[2]);
104 return 0;
105}