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;
122 char* para = parc > 1 ? parv[1] : 0;
125 if (parc > 2 && hunt_server_cmd(sptr, CMD_NAMES, cptr, 1, "%s %C", 2, parc,
129 mlen = strlen(me.name) + 10 + strlen(sptr->name);
131 if (EmptyString(para))
133 else if (*para == '0')
136 s = strchr(para, ',');
139 m_names(cptr, sptr, parc, parv);
141 clean_channelname(para);
142 ch2ptr = FindChannel(para);
145 * First, do all visible channels (public and the one user self is)
148 for (chptr = GlobalChannelList; chptr; chptr = chptr->next)
150 if ((chptr != ch2ptr) && !EmptyString(para))
151 continue; /* -- wanted a specific channel */
152 if (!MyConnect(sptr) && EmptyString(para))
155 if (!ShowChannel(sptr, chptr))
156 continue; /* -- users on this are not listed */
159 /* Find users on same channel (defined by chptr) */
162 len = strlen(chptr->chname);
163 strcpy(buf + 2, chptr->chname);
164 strcpy(buf + 2 + len, " :");
166 if (PubChannel(chptr))
168 else if (SecretChannel(chptr))
172 for (member = chptr->members; member; member = member->next_member)
174 c2ptr = member->user;
176 if (sptr != c2ptr && IsInvisible(c2ptr) && !find_channel_member(sptr, chptr))
179 if (IsZombie(member))
181 if (member->user != sptr)
189 else if (IsChanOp(member))
194 else if (HasVoice(member))
199 strcat(buf, c2ptr->name);
201 idx += strlen(c2ptr->name) + 1;
206 sprintf_irc(yxx, "%s%s", NumNick(c2ptr));
207 assert(c2ptr == findNUser(yxx));
208 sprintf_irc(buf + strlen(buf), "(%s) ", yxx);
211 if (mlen + idx + NICKLEN + 11 > BUFSIZE)
213 if (mlen + idx + NICKLEN + 5 > BUFSIZE)
215 /* space, modifier, nick, \r \n \0 */
217 send_reply(sptr, RPL_NAMREPLY, buf);
219 ircd_strncpy(buf + 2, chptr->chname, len + 1);
222 if (PubChannel(chptr))
224 else if (SecretChannel(chptr))
231 send_reply(sptr, RPL_NAMREPLY, buf);
233 if (!EmptyString(para))
235 send_reply(sptr, RPL_ENDOFNAMES, ch2ptr ? ch2ptr->chname : para);
239 /* Second, do all non-public, non-secret channels in one big sweep */
241 strcpy(buf, "* * :");
244 for (c2ptr = GlobalClientList; c2ptr; c2ptr = c2ptr->next)
246 struct Channel *ch3ptr;
247 int showflag = 0, secret = 0;
250 if (!IsUser(c2ptr) || (sptr != c2ptr && IsInvisible(c2ptr)))
255 member = c2ptr->user->channel;
257 * Don't show a client if they are on a secret channel or when
258 * they are on a channel sptr is on since they have already
259 * been show earlier. -avalon
263 ch3ptr = member->channel;
265 if (PubChannel(ch3ptr) || find_channel_member(sptr, ch3ptr))
268 if (SecretChannel(ch3ptr))
270 member = member->next_channel;
272 if (showflag) /* Have we already shown them ? */
275 if (secret) /* On any secret channels ? */
278 strcat(buf, c2ptr->name);
280 idx += strlen(c2ptr->name) + 1;
285 sprintf_irc(yxx, "%s%s", NumNick(c2ptr));
286 assert(c2ptr == findNUser(yxx));
287 sprintf_irc(buf + strlen(buf), "(%s) ", yxx);
292 if (mlen + idx + NICKLEN + 9 > BUFSIZE)
294 if (mlen + idx + NICKLEN + 3 > BUFSIZE) /* space, \r\n\0 */
297 send_reply(sptr, RPL_NAMREPLY, buf);
298 strcpy(buf, "* * :");
304 send_reply(sptr, RPL_NAMREPLY, buf);
305 send_reply(sptr, RPL_ENDOFNAMES, "*");
311 * ms_names - server message handler
313 * parv[0] = sender prefix
316 int ms_names(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
318 struct Channel *chptr;
319 struct Client *c2ptr;
320 struct Membership* member;
321 struct Channel *ch2ptr = 0;
322 int idx, flag, len, mlen;
323 char *s, *para = parc > 1 ? parv[1] : 0;
326 if (parc > 2 && hunt_server_cmd(sptr, CMD_NAMES, cptr, 1, "%s %C", 2, parc,
330 mlen = strlen(me.name) + 10 + strlen(sptr->name);
332 if (!EmptyString(para))
334 s = strchr(para, ',');
338 m_names(cptr, sptr, parc, parv);
340 clean_channelname(para);
341 ch2ptr = FindChannel(para);
345 * First, do all visible channels (public and the one user self is)
348 for (chptr = GlobalChannelList; chptr; chptr = chptr->next)
350 if ((chptr != ch2ptr) && !EmptyString(para))
351 continue; /* -- wanted a specific channel */
352 if (!MyConnect(sptr) && EmptyString(para))
355 if (!ShowChannel(sptr, chptr))
356 continue; /* -- users on this are not listed */
359 /* Find users on same channel (defined by chptr) */
362 len = strlen(chptr->chname);
363 strcpy(buf + 2, chptr->chname);
364 strcpy(buf + 2 + len, " :");
366 if (PubChannel(chptr))
368 else if (SecretChannel(chptr))
372 for (member = chptr->members; member; member = member->next_member)
374 c2ptr = member->user;
376 if (sptr != c2ptr && IsInvisible(c2ptr) && !find_channel_member(sptr, chptr))
379 if (IsZombie(member))
381 if (member->user != sptr)
389 else if (IsChanOp(member))
394 else if (HasVoice(member))
399 strcat(buf, c2ptr->name);
401 idx += strlen(c2ptr->name) + 1;
406 sprintf_irc(yxx, "%s%s", NumNick(c2ptr));
407 assert(c2ptr == findNUser(yxx));
408 sprintf_irc(buf + strlen(buf), "(%s) ", yxx);
411 if (mlen + idx + NICKLEN + 11 > BUFSIZE)
413 if (mlen + idx + NICKLEN + 5 > BUFSIZE)
415 /* space, modifier, nick, \r \n \0 */
417 send_reply(sptr, RPL_NAMREPLY, buf);
419 ircd_strncpy(buf + 2, chptr->chname, len + 1);
422 if (PubChannel(chptr))
424 else if (SecretChannel(chptr))
431 send_reply(sptr, RPL_NAMREPLY, buf);
433 if (!EmptyString(para))
435 send_reply(sptr, RPL_ENDOFNAMES, ch2ptr ? ch2ptr->chname : para);
439 /* Second, do all non-public, non-secret channels in one big sweep */
441 strcpy(buf, "* * :");
444 for (c2ptr = GlobalClientList; c2ptr; c2ptr = c2ptr->next)
446 struct Channel *ch3ptr;
447 int showflag = 0, secret = 0;
450 if (!IsUser(c2ptr) || (sptr != c2ptr && IsInvisible(c2ptr)))
455 member = c2ptr->user->channel;
457 * Don't show a client if they are on a secret channel or when
458 * they are on a channel sptr is on since they have already
459 * been show earlier. -avalon
463 ch3ptr = member->channel;
465 if (PubChannel(ch3ptr) || find_channel_member(sptr, ch3ptr))
468 if (SecretChannel(ch3ptr))
470 member = member->next_channel;
472 if (showflag) /* Have we already shown them ? */
475 if (secret) /* On any secret channels ? */
478 strcat(buf, c2ptr->name);
480 idx += strlen(c2ptr->name) + 1;
485 sprintf_irc(yxx, "%s%s", NumNick(c2ptr));
486 assert(c2ptr == findNUser(yxx));
487 sprintf_irc(buf + strlen(buf), "(%s) ", yxx);
492 if (mlen + idx + NICKLEN + 9 > BUFSIZE)
494 if (mlen + idx + NICKLEN + 3 > BUFSIZE) /* space, \r\n\0 */
497 send_reply(sptr, RPL_NAMREPLY, buf);
498 strcpy(buf, "* * :");
504 send_reply(sptr, RPL_NAMREPLY, buf);
505 send_reply(sptr, RPL_ENDOFNAMES, "*");
513 * m_names - Added by Jto 27 Apr 1989
515 * parv[0] = sender prefix
518 int m_names(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
520 struct Channel *chptr;
521 struct Client *c2ptr;
522 struct Membership* member;
523 struct Channel *ch2ptr = 0;
524 int idx, flag, len, mlen;
525 char *s, *para = parc > 1 ? parv[1] : 0;
528 if (parc > 2 && hunt_server(1, cptr, sptr, "%s%s " TOK_NAMES " %s %s", 2, parc, parv)) /* XXX DEAD */
531 mlen = strlen(me.name) + 10 + strlen(sptr->name);
533 if (!EmptyString(para))
535 s = strchr(para, ',');
539 m_names(cptr, sptr, parc, parv);
541 clean_channelname(para);
542 ch2ptr = FindChannel(para);
546 * First, do all visible channels (public and the one user self is)
549 for (chptr = GlobalChannelList; chptr; chptr = chptr->next)
551 if ((chptr != ch2ptr) && !EmptyString(para))
552 continue; /* -- wanted a specific channel */
553 if (!MyConnect(sptr) && EmptyString(para))
556 if (!ShowChannel(sptr, chptr))
557 continue; /* -- users on this are not listed */
560 /* Find users on same channel (defined by chptr) */
563 len = strlen(chptr->chname);
564 strcpy(buf + 2, chptr->chname);
565 strcpy(buf + 2 + len, " :");
567 if (PubChannel(chptr))
569 else if (SecretChannel(chptr))
573 for (member = chptr->members; member; member = member->next_member)
575 c2ptr = member->user;
577 if (sptr != c2ptr && IsInvisible(c2ptr) && !find_channel_member(sptr, chptr))
580 if (IsZombie(member))
582 if (member->user != sptr)
590 else if (IsChanOp(member))
595 else if (HasVoice(member))
600 strcat(buf, c2ptr->name);
602 idx += strlen(c2ptr->name) + 1;
607 sprintf_irc(yxx, "%s%s", NumNick(c2ptr));
608 assert(c2ptr == findNUser(yxx));
609 sprintf_irc(buf + strlen(buf), "(%s) ", yxx);
612 if (mlen + idx + NICKLEN + 11 > BUFSIZE)
614 if (mlen + idx + NICKLEN + 5 > BUFSIZE)
616 /* space, modifier, nick, \r \n \0 */
618 sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf); /* XXX DEAD */
620 ircd_strncpy(buf + 2, chptr->chname, len + 1);
623 if (PubChannel(chptr))
625 else if (SecretChannel(chptr))
632 sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf); /* XXX DEAD */
634 if (!EmptyString(para))
636 sendto_one(sptr, rpl_str(RPL_ENDOFNAMES), me.name, parv[0], /* XXX DEAD */
637 ch2ptr ? ch2ptr->chname : para);
641 /* Second, do all non-public, non-secret channels in one big sweep */
643 strcpy(buf, "* * :");
646 for (c2ptr = GlobalClientList; c2ptr; c2ptr = c2ptr->next)
648 struct Channel *ch3ptr;
649 int showflag = 0, secret = 0;
652 if (!IsUser(c2ptr) || (sptr != c2ptr && IsInvisible(c2ptr)))
657 member = c2ptr->user->channel;
659 * Don't show a client if they are on a secret channel or when
660 * they are on a channel sptr is on since they have already
661 * been show earlier. -avalon
665 ch3ptr = member->channel;
667 if (PubChannel(ch3ptr) || find_channel_member(sptr, ch3ptr))
670 if (SecretChannel(ch3ptr))
672 member = member->next_channel;
674 if (showflag) /* Have we already shown them ? */
677 if (secret) /* On any secret channels ? */
680 strcat(buf, c2ptr->name);
682 idx += strlen(c2ptr->name) + 1;
687 sprintf_irc(yxx, "%s%s", NumNick(c2ptr));
688 assert(c2ptr == findNUser(yxx));
689 sprintf_irc(buf + strlen(buf), "(%s) ", yxx);
694 if (mlen + idx + NICKLEN + 9 > BUFSIZE)
696 if (mlen + idx + NICKLEN + 3 > BUFSIZE) /* space, \r\n\0 */
699 sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf); /* XXX DEAD */
700 strcpy(buf, "* * :");
706 sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf); /* XXX DEAD */
707 sendto_one(sptr, rpl_str(RPL_ENDOFNAMES), me.name, parv[0], "*"); /* XXX DEAD */