2 * IRC - Internet Relay Chat, ircd/m_names.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
94 #include "ircd_reply.h"
95 #include "ircd_string.h"
106 * m_names - generic message handler
108 * parv[0] = sender prefix
111 int m_names(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
113 struct Channel *chptr;
114 struct Client *c2ptr;
115 struct Membership* member;
116 struct Channel *ch2ptr = 0;
117 int idx, flag, len, mlen;
118 char *s, *para = parc > 1 ? parv[1] : 0;
121 if (parc > 2 && hunt_server(1, cptr, sptr, "%s%s " TOK_NAMES " %s %s", 2, parc, parv))
124 mlen = strlen(me.name) + 10 + strlen(sptr->name);
126 if (!EmptyString(para))
128 s = strchr(para, ',');
132 m_names(cptr, sptr, parc, parv);
134 clean_channelname(para);
135 ch2ptr = FindChannel(para);
139 * First, do all visible channels (public and the one user self is)
142 for (chptr = GlobalChannelList; chptr; chptr = chptr->next)
144 if ((chptr != ch2ptr) && !EmptyString(para))
145 continue; /* -- wanted a specific channel */
146 if (!MyConnect(sptr) && EmptyString(para))
149 if (!ShowChannel(sptr, chptr))
150 continue; /* -- users on this are not listed */
153 /* Find users on same channel (defined by chptr) */
156 len = strlen(chptr->chname);
157 strcpy(buf + 2, chptr->chname);
158 strcpy(buf + 2 + len, " :");
160 if (PubChannel(chptr))
162 else if (SecretChannel(chptr))
166 for (member = chptr->members; member; member = member->next_member)
168 c2ptr = member->user;
170 if (sptr != c2ptr && IsInvisible(c2ptr) && !find_channel_member(sptr, chptr))
173 if (IsZombie(member))
175 if (member->user != sptr)
183 else if (IsChanOp(member))
188 else if (HasVoice(member))
193 strcat(buf, c2ptr->name);
195 idx += strlen(c2ptr->name) + 1;
200 sprintf_irc(yxx, "%s%s", NumNick(c2ptr));
201 assert(c2ptr == findNUser(yxx));
202 sprintf_irc(buf + strlen(buf), "(%s) ", yxx);
205 if (mlen + idx + NICKLEN + 11 > BUFSIZE)
207 if (mlen + idx + NICKLEN + 5 > BUFSIZE)
209 /* space, modifier, nick, \r \n \0 */
211 sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf);
213 ircd_strncpy(buf + 2, chptr->chname, len + 1);
216 if (PubChannel(chptr))
218 else if (SecretChannel(chptr))
225 sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf);
227 if (!EmptyString(para))
229 sendto_one(sptr, rpl_str(RPL_ENDOFNAMES), me.name, parv[0],
230 ch2ptr ? ch2ptr->chname : para);
234 /* Second, do all non-public, non-secret channels in one big sweep */
236 strcpy(buf, "* * :");
239 for (c2ptr = GlobalClientList; c2ptr; c2ptr = c2ptr->next)
241 struct Channel *ch3ptr;
242 int showflag = 0, secret = 0;
245 if (!IsUser(c2ptr) || (sptr != c2ptr && IsInvisible(c2ptr)))
250 member = c2ptr->user->channel;
252 * Don't show a client if they are on a secret channel or when
253 * they are on a channel sptr is on since they have already
254 * been show earlier. -avalon
258 ch3ptr = member->channel;
260 if (PubChannel(ch3ptr) || find_channel_member(sptr, ch3ptr))
263 if (SecretChannel(ch3ptr))
265 member = member->next_channel;
267 if (showflag) /* Have we already shown them ? */
270 if (secret) /* On any secret channels ? */
273 strcat(buf, c2ptr->name);
275 idx += strlen(c2ptr->name) + 1;
280 sprintf_irc(yxx, "%s%s", NumNick(c2ptr));
281 assert(c2ptr == findNUser(yxx));
282 sprintf_irc(buf + strlen(buf), "(%s) ", yxx);
287 if (mlen + idx + NICKLEN + 9 > BUFSIZE)
289 if (mlen + idx + NICKLEN + 3 > BUFSIZE) /* space, \r\n\0 */
292 sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf);
293 strcpy(buf, "* * :");
299 sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf);
300 sendto_one(sptr, rpl_str(RPL_ENDOFNAMES), me.name, parv[0], "*");
306 * ms_names - server message handler
308 * parv[0] = sender prefix
311 int ms_names(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
313 struct Channel *chptr;
314 struct Client *c2ptr;
315 struct Membership* member;
316 struct Channel *ch2ptr = 0;
317 int idx, flag, len, mlen;
318 char *s, *para = parc > 1 ? parv[1] : 0;
321 if (parc > 2 && hunt_server(1, cptr, sptr, "%s%s " TOK_NAMES " %s %s", 2, parc, parv))
324 mlen = strlen(me.name) + 10 + strlen(sptr->name);
326 if (!EmptyString(para))
328 s = strchr(para, ',');
332 m_names(cptr, sptr, parc, parv);
334 clean_channelname(para);
335 ch2ptr = FindChannel(para);
339 * First, do all visible channels (public and the one user self is)
342 for (chptr = GlobalChannelList; chptr; chptr = chptr->next)
344 if ((chptr != ch2ptr) && !EmptyString(para))
345 continue; /* -- wanted a specific channel */
346 if (!MyConnect(sptr) && EmptyString(para))
349 if (!ShowChannel(sptr, chptr))
350 continue; /* -- users on this are not listed */
353 /* Find users on same channel (defined by chptr) */
356 len = strlen(chptr->chname);
357 strcpy(buf + 2, chptr->chname);
358 strcpy(buf + 2 + len, " :");
360 if (PubChannel(chptr))
362 else if (SecretChannel(chptr))
366 for (member = chptr->members; member; member = member->next_member)
368 c2ptr = member->user;
370 if (sptr != c2ptr && IsInvisible(c2ptr) && !find_channel_member(sptr, chptr))
373 if (IsZombie(member))
375 if (member->user != sptr)
383 else if (IsChanOp(member))
388 else if (HasVoice(member))
393 strcat(buf, c2ptr->name);
395 idx += strlen(c2ptr->name) + 1;
400 sprintf_irc(yxx, "%s%s", NumNick(c2ptr));
401 assert(c2ptr == findNUser(yxx));
402 sprintf_irc(buf + strlen(buf), "(%s) ", yxx);
405 if (mlen + idx + NICKLEN + 11 > BUFSIZE)
407 if (mlen + idx + NICKLEN + 5 > BUFSIZE)
409 /* space, modifier, nick, \r \n \0 */
411 sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf);
413 ircd_strncpy(buf + 2, chptr->chname, len + 1);
416 if (PubChannel(chptr))
418 else if (SecretChannel(chptr))
425 sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf);
427 if (!EmptyString(para))
429 sendto_one(sptr, rpl_str(RPL_ENDOFNAMES), me.name, parv[0],
430 ch2ptr ? ch2ptr->chname : para);
434 /* Second, do all non-public, non-secret channels in one big sweep */
436 strcpy(buf, "* * :");
439 for (c2ptr = GlobalClientList; c2ptr; c2ptr = c2ptr->next)
441 struct Channel *ch3ptr;
442 int showflag = 0, secret = 0;
445 if (!IsUser(c2ptr) || (sptr != c2ptr && IsInvisible(c2ptr)))
450 member = c2ptr->user->channel;
452 * Don't show a client if they are on a secret channel or when
453 * they are on a channel sptr is on since they have already
454 * been show earlier. -avalon
458 ch3ptr = member->channel;
460 if (PubChannel(ch3ptr) || find_channel_member(sptr, ch3ptr))
463 if (SecretChannel(ch3ptr))
465 member = member->next_channel;
467 if (showflag) /* Have we already shown them ? */
470 if (secret) /* On any secret channels ? */
473 strcat(buf, c2ptr->name);
475 idx += strlen(c2ptr->name) + 1;
480 sprintf_irc(yxx, "%s%s", NumNick(c2ptr));
481 assert(c2ptr == findNUser(yxx));
482 sprintf_irc(buf + strlen(buf), "(%s) ", yxx);
487 if (mlen + idx + NICKLEN + 9 > BUFSIZE)
489 if (mlen + idx + NICKLEN + 3 > BUFSIZE) /* space, \r\n\0 */
492 sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf);
493 strcpy(buf, "* * :");
499 sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf);
500 sendto_one(sptr, rpl_str(RPL_ENDOFNAMES), me.name, parv[0], "*");
508 * m_names - Added by Jto 27 Apr 1989
510 * parv[0] = sender prefix
513 int m_names(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
515 struct Channel *chptr;
516 struct Client *c2ptr;
517 struct Membership* member;
518 struct Channel *ch2ptr = 0;
519 int idx, flag, len, mlen;
520 char *s, *para = parc > 1 ? parv[1] : 0;
523 if (parc > 2 && hunt_server(1, cptr, sptr, "%s%s " TOK_NAMES " %s %s", 2, parc, parv))
526 mlen = strlen(me.name) + 10 + strlen(sptr->name);
528 if (!EmptyString(para))
530 s = strchr(para, ',');
534 m_names(cptr, sptr, parc, parv);
536 clean_channelname(para);
537 ch2ptr = FindChannel(para);
541 * First, do all visible channels (public and the one user self is)
544 for (chptr = GlobalChannelList; chptr; chptr = chptr->next)
546 if ((chptr != ch2ptr) && !EmptyString(para))
547 continue; /* -- wanted a specific channel */
548 if (!MyConnect(sptr) && EmptyString(para))
551 if (!ShowChannel(sptr, chptr))
552 continue; /* -- users on this are not listed */
555 /* Find users on same channel (defined by chptr) */
558 len = strlen(chptr->chname);
559 strcpy(buf + 2, chptr->chname);
560 strcpy(buf + 2 + len, " :");
562 if (PubChannel(chptr))
564 else if (SecretChannel(chptr))
568 for (member = chptr->members; member; member = member->next_member)
570 c2ptr = member->user;
572 if (sptr != c2ptr && IsInvisible(c2ptr) && !find_channel_member(sptr, chptr))
575 if (IsZombie(member))
577 if (member->user != sptr)
585 else if (IsChanOp(member))
590 else if (HasVoice(member))
595 strcat(buf, c2ptr->name);
597 idx += strlen(c2ptr->name) + 1;
602 sprintf_irc(yxx, "%s%s", NumNick(c2ptr));
603 assert(c2ptr == findNUser(yxx));
604 sprintf_irc(buf + strlen(buf), "(%s) ", yxx);
607 if (mlen + idx + NICKLEN + 11 > BUFSIZE)
609 if (mlen + idx + NICKLEN + 5 > BUFSIZE)
611 /* space, modifier, nick, \r \n \0 */
613 sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf);
615 ircd_strncpy(buf + 2, chptr->chname, len + 1);
618 if (PubChannel(chptr))
620 else if (SecretChannel(chptr))
627 sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf);
629 if (!EmptyString(para))
631 sendto_one(sptr, rpl_str(RPL_ENDOFNAMES), me.name, parv[0],
632 ch2ptr ? ch2ptr->chname : para);
636 /* Second, do all non-public, non-secret channels in one big sweep */
638 strcpy(buf, "* * :");
641 for (c2ptr = GlobalClientList; c2ptr; c2ptr = c2ptr->next)
643 struct Channel *ch3ptr;
644 int showflag = 0, secret = 0;
647 if (!IsUser(c2ptr) || (sptr != c2ptr && IsInvisible(c2ptr)))
652 member = c2ptr->user->channel;
654 * Don't show a client if they are on a secret channel or when
655 * they are on a channel sptr is on since they have already
656 * been show earlier. -avalon
660 ch3ptr = member->channel;
662 if (PubChannel(ch3ptr) || find_channel_member(sptr, ch3ptr))
665 if (SecretChannel(ch3ptr))
667 member = member->next_channel;
669 if (showflag) /* Have we already shown them ? */
672 if (secret) /* On any secret channels ? */
675 strcat(buf, c2ptr->name);
677 idx += strlen(c2ptr->name) + 1;
682 sprintf_irc(yxx, "%s%s", NumNick(c2ptr));
683 assert(c2ptr == findNUser(yxx));
684 sprintf_irc(buf + strlen(buf), "(%s) ", yxx);
689 if (mlen + idx + NICKLEN + 9 > BUFSIZE)
691 if (mlen + idx + NICKLEN + 3 > BUFSIZE) /* space, \r\n\0 */
694 sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf);
695 strcpy(buf, "* * :");
701 sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf);
702 sendto_one(sptr, rpl_str(RPL_ENDOFNAMES), me.name, parv[0], "*");