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
84 * No need to include handlers.h here the signatures must match
85 * and we don't need to force a rebuild of all the handlers everytime
86 * we add a new one to the list. --Bleep
91 #include "ircd_chattr.h"
92 #include "ircd_relay.h"
93 #include "ircd_reply.h"
94 #include "ircd_string.h"
103 #if !defined(XXX_BOGUS_TEMP_HACK)
104 #include "handlers.h"
108 * m_notice - generic message handler
110 int m_notice(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
116 char* vector[MAXTARGETS];
119 assert(cptr == sptr);
121 sptr->flags &= ~FLAGS_TS8;
123 if (parc < 2 || EmptyString(parv[1]))
124 return send_reply(sptr, ERR_NORECIPIENT, MSG_NOTICE);
126 if (parc < 3 || EmptyString(parv[parc - 1]))
127 return send_reply(sptr, ERR_NOTEXTTOSEND);
129 if (parv[1][0] == '@' && IsChannelPrefix(parv[1][1])) {
130 parv[1]++; /* Get rid of '@' */
131 return m_wallchops(cptr, sptr, parc, parv);
134 count = unique_name_vector(parv[1], ',', vector, MAXTARGETS);
136 for (i = 0; i < count; ++i) {
141 if (IsChannelPrefix(*name)) {
142 relay_channel_notice(sptr, name, parv[parc - 1]);
145 * we have to check for the '@' at least once no matter what we do
146 * handle it first so we don't have to do it twice
148 else if ((server = strchr(name, '@')))
149 relay_directed_notice(sptr, name, server, parv[parc - 1]);
151 relay_private_notice(sptr, name, parv[parc - 1]);
157 * ms_notice - server message handler template
159 int ms_notice(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
164 sptr->flags &= ~FLAGS_TS8;
168 * we can't deliver it, sending an error back is pointless
176 if (IsChannelPrefix(*name)) {
177 server_relay_channel_notice(sptr, name, parv[parc - 1]);
180 * coming from another server, we have to check this here
182 else if ('$' == *name && IsOper(sptr)) {
183 server_relay_masked_notice(sptr, name, parv[parc - 1]);
185 else if ((server = strchr(name, '@'))) {
187 * XXX - can't get away with not doing everything
188 * relay_directed_notice has to do
190 relay_directed_notice(sptr, name, server, parv[parc - 1]);
193 server_relay_private_notice(sptr, name, parv[parc - 1]);
199 * mo_notice - oper message handler
201 int mo_notice(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
207 char* vector[MAXTARGETS];
209 assert(cptr == sptr);
211 sptr->flags &= ~FLAGS_TS8;
213 if (parc < 2 || EmptyString(parv[1]))
214 return send_reply(sptr, ERR_NORECIPIENT, MSG_NOTICE);
216 if (parc < 3 || EmptyString(parv[parc - 1]))
217 return send_reply(sptr, ERR_NOTEXTTOSEND);
219 if (parv[1][0] == '@' && IsChannelPrefix(parv[1][1])) {
220 parv[1]++; /* Get rid of '@' */
221 return m_wallchops(cptr, sptr, parc, parv);
224 count = unique_name_vector(parv[1], ',', vector, MAXTARGETS);
226 for (i = 0; i < count; ++i) {
231 if (IsChannelPrefix(*name))
232 relay_channel_notice(sptr, name, parv[parc - 1]);
234 else if (*name == '$')
235 relay_masked_notice(sptr, name, parv[parc - 1]);
237 else if ((server = strchr(name, '@')))
238 relay_directed_notice(sptr, name, server, parv[parc - 1]);
241 relay_private_notice(sptr, name, parv[parc - 1]);
249 * m_message (used in m_private() and m_notice())
251 * The general function to deliver MSG's between users/channels
253 * parv[0] = sender prefix
254 * parv[1] = receiver list
255 * parv[parc-1] = message text
260 static int m_message(struct Client *cptr, struct Client *sptr,
261 int parc, char *parv[], int notice)
263 struct Client* acptr;
265 struct Channel* chptr;
272 char* vector[MAXTARGETS];
274 sptr->flags &= ~FLAGS_TS8;
276 cmd = notice ? MSG_NOTICE : MSG_PRIVATE;
278 if (parc < 2 || EmptyString(parv[1]))
279 return send_error_to_client(sptr, ERR_NORECIPIENT, cmd); /* XXX DEAD */
281 if (parc < 3 || EmptyString(parv[parc - 1]))
282 return send_error_to_client(sptr, ERR_NOTEXTTOSEND); /* XXX DEAD */
287 parv[1] = canonize(parv[1]);
288 for (p = 0, nick = ircd_strtok(&p, parv[1], ","); nick;
289 nick = ircd_strtok(&p, 0, ","))
292 count = unique_name_vector(parv[1], ',', vector, MAXTARGETS);
293 for (i = 0; i < count; ++i) {
298 if (IsChannelName(nick))
300 if ((chptr = FindChannel(nick)))
302 /* This first: Almost never a server/service */
303 if (client_can_send_to_channel(sptr, chptr) || IsChannelService(sptr))
305 if (MyUser(sptr) && (chptr->mode.mode & MODE_NOPRIVMSGS) &&
306 check_target_limit(sptr, chptr, chptr->chname, 0))
308 sendmsgto_channel_butone(cptr, sptr, chptr, /* XXX DEAD */
309 parv[0], (notice ? TOK_NOTICE : TOK_PRIVATE),
310 chptr->chname, parv[parc - 1]);
313 sendto_one(sptr, err_str(ERR_CANNOTSENDTOCHAN), /* XXX DEAD */
314 me.name, parv[0], chptr->chname);
318 else if (*nick != '$' && !strchr(nick, '@'))
321 * nickname addressed?
324 acptr = FindUser(nick);
325 else if ((acptr = findNUser(nick)) && !IsUser(acptr))
329 if (MyUser(sptr) && check_target_limit(sptr, acptr, acptr->name, 0))
331 if (!is_silenced(sptr, acptr))
333 if (!notice && MyConnect(sptr) && acptr->user && acptr->user->away)
334 sendto_one(sptr, rpl_str(RPL_AWAY), /* XXX DEAD */
335 me.name, parv[0], acptr->name, acptr->user->away);
338 add_target(acptr, sptr);
339 sendto_prefix_one(acptr, sptr, ":%s %s %s :%s", /* XXX DEAD */
340 parv[0], cmd, acptr->name, parv[parc - 1]);
343 sendto_prefix_one(acptr, sptr, ":%s %s %s%s :%s", /* XXX DEAD */
344 parv[0], (notice ? TOK_NOTICE : TOK_PRIVATE),
345 NumNick(acptr), parv[parc - 1]);
348 else if (MyUser(sptr))
349 sendto_one(sptr, err_str(ERR_NOSUCHNICK), me.name, parv[0], nick); /* XXX DEAD */
351 sendto_one(sptr, /* XXX DEAD */
352 ":%s %d %s * :Target left UnderNet. Failed to deliver: [%.50s]",
353 me.name, ERR_NOSUCHNICK, sptr->name, parv[parc - 1]);
357 * The following two cases allow masks in NOTICEs
360 * Armin, 8Jun90 (gruner@informatik.tu-muenchen.de)
362 if ((*nick == '$' || *nick == '#') && IsAnOper(sptr))
366 if (!(s = strrchr(nick, '.')))
368 sendto_one(sptr, err_str(ERR_NOTOPLEVEL), me.name, parv[0], nick); /* XXX DEAD */
372 if (*s == '.' || *s == '*' || *s == '?')
374 if (*s == '*' || *s == '?')
376 sendto_one(sptr, err_str(ERR_WILDTOPLEVEL), me.name, parv[0], nick); /* XXX DEAD */
380 sendto_match_butone(IsServer(cptr) ? cptr : 0, /* XXX DEAD */
381 sptr, nick + 1, (*nick == '#') ? MATCH_HOST : MATCH_SERVER,
382 ":%s %s %s :%s", parv[0], cmd, nick, parv[parc - 1]);
385 else if ((server = strchr(nick, '@')) && (acptr = FindServer(server + 1)))
388 * NICK[%host]@server addressed? See if <server> is me first
392 sendto_one(acptr, ":%s %s %s :%s", parv[0], cmd, nick, parv[parc - 1]); /* XXX DEAD */
396 /* Look for an user whose NICK is equal to <nick> and then
397 * check if it's hostname matches <host> and if it's a local
400 if ((host = strchr(nick, '%')))
403 if ((!(acptr = FindUser(nick))) ||
404 (!(MyUser(acptr))) ||
405 ((!(EmptyString(host))) && match(host, acptr->user->host)))
414 if (!(is_silenced(sptr, acptr)))
415 sendto_prefix_one(acptr, sptr, ":%s %s %s :%s", /* XXX DEAD */
416 parv[0], cmd, nick, parv[parc - 1]);
420 if (IsChannelName(nick))
421 sendto_one(sptr, err_str(ERR_NOSUCHCHANNEL), me.name, parv[0], nick); /* XXX DEAD */
423 sendto_one(sptr, err_str(ERR_NOSUCHNICK), me.name, parv[0], nick); /* XXX DEAD */
431 * parv[0] = sender prefix
432 * parv[1] = receiver list
433 * parv[parc-1] = message text
435 int m_private(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
437 return m_message(cptr, sptr, parc, parv, 0);
443 * parv[0] = sender prefix
444 * parv[1] = receiver list
445 * parv[parc-1] = notice text
447 int m_notice(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
449 if (MyUser(sptr) && parv[1] && parv[1][0] == '@' &&
450 IsChannelName(&parv[1][1]))
452 parv[1]++; /* Get rid of '@' */
453 return m_wallchops(cptr, sptr, parc, parv);
455 return m_message(cptr, sptr, parc, parv, 1);