2 * IRC - Internet Relay Chat, ircd/m_notice.c
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Computing Center
6 * See file AUTHORS in IRC package for additional names of
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 1, or (at your option)
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 * m_functions execute protocol messages on this server:
29 * cptr is always NON-NULL, pointing to a *LOCAL* client
30 * structure (with an open socket connected!). This
31 * identifies the physical socket where the message
32 * originated (or which caused the m_function to be
33 * executed--some m_functions may call others...).
35 * sptr is the source of the message, defined by the
36 * prefix part of the message if present. If not
37 * or prefix not found, then sptr==cptr.
39 * (!IsServer(cptr)) => (cptr == sptr), because
40 * prefixes are taken *only* from servers...
43 * (sptr == cptr) => the message didn't
46 * (sptr != cptr && IsServer(sptr) means
47 * the prefix specified servername. (?)
49 * (sptr != cptr && !IsServer(sptr) means
50 * that message originated from a remote
55 * (!IsServer(sptr)) means that, sptr can safely
56 * taken as defining the target structure of the
57 * message in this server.
59 * *Always* true (if 'parse' and others are working correct):
61 * 1) sptr->from == cptr (note: cptr->from == cptr)
63 * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr
64 * *cannot* be a local connection, unless it's
65 * actually cptr!). [MyConnect(x) should probably
66 * be defined as (x == x->from) --msa ]
68 * parc number of variable parameter strings (if zero,
69 * parv is allowed to be NULL)
71 * parv a NULL terminated list of parameter pointers,
73 * parv[0], sender (prefix string), if not present
74 * this points to an empty string.
75 * parv[1]...parv[parc-1]
76 * pointers to additional parameters
77 * parv[parc] == NULL, *always*
79 * note: it is guaranteed that parv[0]..parv[parc-1] are all
86 * No need to include handlers.h here the signatures must match
87 * and we don't need to force a rebuild of all the handlers everytime
88 * we add a new one to the list. --Bleep
93 #include "ircd_chattr.h"
94 #include "ircd_relay.h"
95 #include "ircd_reply.h"
96 #include "ircd_string.h"
105 #if !defined(XXX_BOGUS_TEMP_HACK)
106 #include "handlers.h"
110 * m_notice - generic message handler
112 int m_notice(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
118 char* vector[MAXTARGETS];
121 assert(cptr == sptr);
123 cli_flags(sptr) &= ~FLAGS_TS8;
125 if (parc < 2 || EmptyString(parv[1]))
126 return send_reply(sptr, ERR_NORECIPIENT, MSG_NOTICE);
128 if (parc < 3 || EmptyString(parv[parc - 1]))
129 return send_reply(sptr, ERR_NOTEXTTOSEND);
131 if (parv[1][0] == '@' && IsChannelPrefix(parv[1][1])) {
132 parv[1]++; /* Get rid of '@' */
133 return m_wallchops(cptr, sptr, parc, parv);
136 count = unique_name_vector(parv[1], ',', vector, MAXTARGETS);
138 for (i = 0; i < count; ++i) {
143 if (IsChannelPrefix(*name)) {
144 relay_channel_notice(sptr, name, parv[parc - 1]);
147 * we have to check for the '@' at least once no matter what we do
148 * handle it first so we don't have to do it twice
150 else if ((server = strchr(name, '@')))
151 relay_directed_notice(sptr, name, server, parv[parc - 1]);
153 relay_private_notice(sptr, name, parv[parc - 1]);
159 * ms_notice - server message handler template
161 int ms_notice(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
166 cli_flags(sptr) &= ~FLAGS_TS8;
170 * we can't deliver it, sending an error back is pointless
172 return protocol_violation(sptr,"Not enough params for NOTICE");
178 if (IsChannelPrefix(*name)) {
179 server_relay_channel_notice(sptr, name, parv[parc - 1]);
182 * coming from another server, we have to check this here
184 else if ('$' == *name && IsOper(sptr)) {
185 server_relay_masked_notice(sptr, name, parv[parc - 1]);
187 else if ((server = strchr(name, '@'))) {
189 * XXX - can't get away with not doing everything
190 * relay_directed_notice has to do
192 relay_directed_notice(sptr, name, server, parv[parc - 1]);
195 server_relay_private_notice(sptr, name, parv[parc - 1]);
201 * mo_notice - oper message handler
203 int mo_notice(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
209 char* vector[MAXTARGETS];
211 assert(cptr == sptr);
213 cli_flags(sptr) &= ~FLAGS_TS8;
215 if (parc < 2 || EmptyString(parv[1]))
216 return send_reply(sptr, ERR_NORECIPIENT, MSG_NOTICE);
218 if (parc < 3 || EmptyString(parv[parc - 1]))
219 return send_reply(sptr, ERR_NOTEXTTOSEND);
221 if (parv[1][0] == '@' && IsChannelPrefix(parv[1][1])) {
222 parv[1]++; /* Get rid of '@' */
223 return m_wallchops(cptr, sptr, parc, parv);
226 count = unique_name_vector(parv[1], ',', vector, MAXTARGETS);
228 for (i = 0; i < count; ++i) {
233 if (IsChannelPrefix(*name))
234 relay_channel_notice(sptr, name, parv[parc - 1]);
236 else if (*name == '$')
237 relay_masked_notice(sptr, name, parv[parc - 1]);
239 else if ((server = strchr(name, '@')))
240 relay_directed_notice(sptr, name, server, parv[parc - 1]);
243 relay_private_notice(sptr, name, parv[parc - 1]);
251 * m_message (used in m_private() and m_notice())
253 * The general function to deliver MSG's between users/channels
255 * parv[0] = sender prefix
256 * parv[1] = receiver list
257 * parv[parc-1] = message text
262 static int m_message(struct Client *cptr, struct Client *sptr,
263 int parc, char *parv[], int notice)
265 struct Client* acptr;
267 struct Channel* chptr;
274 char* vector[MAXTARGETS];
276 sptr->flags &= ~FLAGS_TS8;
278 cmd = notice ? MSG_NOTICE : MSG_PRIVATE;
280 if (parc < 2 || EmptyString(parv[1]))
281 return send_error_to_client(sptr, ERR_NORECIPIENT, cmd); /* XXX DEAD */
283 if (parc < 3 || EmptyString(parv[parc - 1]))
284 return send_error_to_client(sptr, ERR_NOTEXTTOSEND); /* XXX DEAD */
289 parv[1] = canonize(parv[1]);
290 for (p = 0, nick = ircd_strtok(&p, parv[1], ","); nick;
291 nick = ircd_strtok(&p, 0, ","))
294 count = unique_name_vector(parv[1], ',', vector, MAXTARGETS);
295 for (i = 0; i < count; ++i) {
300 if (IsChannelName(nick))
302 if ((chptr = FindChannel(nick)))
304 /* This first: Almost never a server/service */
305 if (client_can_send_to_channel(sptr, chptr) || IsChannelService(sptr))
307 if (MyUser(sptr) && (chptr->mode.mode & MODE_NOPRIVMSGS) &&
308 check_target_limit(sptr, chptr, chptr->chname, 0))
310 sendmsgto_channel_butone(cptr, sptr, chptr, /* XXX DEAD */
311 parv[0], (notice ? TOK_NOTICE : TOK_PRIVATE),
312 chptr->chname, parv[parc - 1]);
315 sendto_one(sptr, err_str(ERR_CANNOTSENDTOCHAN), /* XXX DEAD */
316 me.name, parv[0], chptr->chname);
320 else if (*nick != '$' && !strchr(nick, '@'))
323 * nickname addressed?
326 acptr = FindUser(nick);
327 else if ((acptr = findNUser(nick)) && !IsUser(acptr))
331 if (MyUser(sptr) && !IsChannelService(acptr) &&
332 check_target_limit(sptr, acptr, acptr->name, 0))
334 if (!is_silenced(sptr, acptr))
336 if (!notice && MyConnect(sptr) && acptr->user && acptr->user->away)
337 sendto_one(sptr, rpl_str(RPL_AWAY), /* XXX DEAD */
338 me.name, parv[0], acptr->name, acptr->user->away);
341 add_target(acptr, sptr);
342 sendto_prefix_one(acptr, sptr, ":%s %s %s :%s", /* XXX DEAD */
343 parv[0], cmd, acptr->name, parv[parc - 1]);
346 sendto_prefix_one(acptr, sptr, ":%s %s %s%s :%s", /* XXX DEAD */
347 parv[0], (notice ? TOK_NOTICE : TOK_PRIVATE),
348 NumNick(acptr), parv[parc - 1]);
351 else if (MyUser(sptr))
352 sendto_one(sptr, err_str(ERR_NOSUCHNICK), me.name, parv[0], nick); /* XXX DEAD */
354 sendto_one(sptr, /* XXX DEAD */
355 ":%s %d %s * :Target left UnderNet. Failed to deliver: [%.50s]",
356 me.name, ERR_NOSUCHNICK, sptr->name, parv[parc - 1]);
360 * The following two cases allow masks in NOTICEs
363 * Armin, 8Jun90 (gruner@informatik.tu-muenchen.de)
365 if ((*nick == '$' || *nick == '#') && IsAnOper(sptr))
369 if (!(s = strrchr(nick, '.')))
371 sendto_one(sptr, err_str(ERR_NOTOPLEVEL), me.name, parv[0], nick); /* XXX DEAD */
375 if (*s == '.' || *s == '*' || *s == '?')
377 if (*s == '*' || *s == '?')
379 sendto_one(sptr, err_str(ERR_WILDTOPLEVEL), me.name, parv[0], nick); /* XXX DEAD */
383 sendto_match_butone(IsServer(cptr) ? cptr : 0, /* XXX DEAD */
384 sptr, nick + 1, (*nick == '#') ? MATCH_HOST : MATCH_SERVER,
385 ":%s %s %s :%s", parv[0], cmd, nick, parv[parc - 1]);
388 else if ((server = strchr(nick, '@')) && (acptr = FindServer(server + 1)))
391 * NICK[%host]@server addressed? See if <server> is me first
395 sendto_one(acptr, ":%s %s %s :%s", parv[0], cmd, nick, parv[parc - 1]); /* XXX DEAD */
399 /* Look for an user whose NICK is equal to <nick> and then
400 * check if it's hostname matches <host> and if it's a local
403 if ((host = strchr(nick, '%')))
406 if ((!(acptr = FindUser(nick))) ||
407 (!(MyUser(acptr))) ||
408 ((!(EmptyString(host))) && match(host, acptr->user->host)))
417 if (!(is_silenced(sptr, acptr)))
418 sendto_prefix_one(acptr, sptr, ":%s %s %s :%s", /* XXX DEAD */
419 parv[0], cmd, nick, parv[parc - 1]);
423 if (IsChannelName(nick))
424 sendto_one(sptr, err_str(ERR_NOSUCHCHANNEL), me.name, parv[0], nick); /* XXX DEAD */
426 sendto_one(sptr, err_str(ERR_NOSUCHNICK), me.name, parv[0], nick); /* XXX DEAD */
434 * parv[0] = sender prefix
435 * parv[1] = receiver list
436 * parv[parc-1] = message text
438 int m_private(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
440 return m_message(cptr, sptr, parc, parv, 0);
446 * parv[0] = sender prefix
447 * parv[1] = receiver list
448 * parv[parc-1] = notice text
450 int m_notice(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
452 if (MyUser(sptr) && parv[1] && parv[1][0] == '@' &&
453 IsChannelName(&parv[1][1]))
455 parv[1]++; /* Get rid of '@' */
456 return m_wallchops(cptr, sptr, parc, parv);
458 return m_message(cptr, sptr, parc, parv, 1);