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;
123 char* para = parc > 1 ? parv[1] : 0;
126 if (parc > 2 && hunt_server_cmd(sptr, CMD_NAMES, cptr, 1, "%s %C", 2, parc,
130 mlen = strlen(me.name) + 10 + strlen(sptr->name);
132 if (EmptyString(para))
134 else if (*para == '0')
137 s = strchr(para, ',');
140 m_names(cptr, sptr, parc, parv);
142 clean_channelname(para);
143 ch2ptr = FindChannel(para);
146 * First, do all visible channels (public and the one user self is)
149 for (chptr = GlobalChannelList; chptr; chptr = chptr->next)
151 if ((chptr != ch2ptr) && !EmptyString(para))
152 continue; /* -- wanted a specific channel */
153 if (!MyConnect(sptr) && EmptyString(para))
156 if (!ShowChannel(sptr, chptr))
157 continue; /* -- users on this are not listed */
160 /* Find users on same channel (defined by chptr) */
163 len = strlen(chptr->chname);
164 strcpy(buf + 2, chptr->chname);
165 strcpy(buf + 2 + len, " :");
167 if (PubChannel(chptr))
169 else if (SecretChannel(chptr))
174 for (member = chptr->members; member; member = member->next_member)
176 c2ptr = member->user;
182 if (IsZombie(member))
184 if (member->user != sptr)
192 else if (IsChanOp(member))
197 else if (HasVoice(member))
202 strcat(buf, c2ptr->name);
203 idx += strlen(c2ptr->name) + 1;
205 if (mlen + idx + NICKLEN + 5 > BUFSIZE)
206 /* space, modifier, nick, \r \n \0 */
208 send_reply(sptr, RPL_NAMREPLY, buf);
210 ircd_strncpy(buf + 2, chptr->chname, len + 1);
213 if (PubChannel(chptr))
215 else if (SecretChannel(chptr))
223 send_reply(sptr, RPL_NAMREPLY, buf);
225 if (!EmptyString(para))
227 send_reply(sptr, RPL_ENDOFNAMES, ch2ptr ? ch2ptr->chname : para);
231 /* Second, do all non-public, non-secret channels in one big sweep */
233 strcpy(buf, "* * :");
236 for (c2ptr = GlobalClientList; c2ptr; c2ptr = c2ptr->next)
238 struct Channel *ch3ptr;
239 int showflag = 0, secret = 0;
242 if (!IsUser(c2ptr) || (sptr != c2ptr && IsInvisible(c2ptr)))
247 member = c2ptr->user->channel;
249 * Don't show a client if they are on a secret channel or when
250 * they are on a channel sptr is on since they have already
251 * been show earlier. -avalon
255 ch3ptr = member->channel;
257 if (PubChannel(ch3ptr) || find_channel_member(sptr, ch3ptr))
260 if (SecretChannel(ch3ptr))
262 member = member->next_channel;
264 if (showflag) /* Have we already shown them ? */
267 if (secret) /* On any secret channels ? */
270 strcat(buf, c2ptr->name);
272 idx += strlen(c2ptr->name) + 1;
277 sprintf_irc(yxx, "%s%s", NumNick(c2ptr));
278 assert(c2ptr == findNUser(yxx));
279 sprintf_irc(buf + strlen(buf), "(%s) ", yxx);
284 if (mlen + idx + NICKLEN + 9 > BUFSIZE)
286 if (mlen + idx + NICKLEN + 3 > BUFSIZE) /* space, \r\n\0 */
289 send_reply(sptr, RPL_NAMREPLY, buf);
290 strcpy(buf, "* * :");
296 send_reply(sptr, RPL_NAMREPLY, buf);
297 send_reply(sptr, RPL_ENDOFNAMES, "*");
303 * ms_names - server message handler
305 * parv[0] = sender prefix
308 int ms_names(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
310 struct Channel *chptr;
311 struct Client *c2ptr;
312 struct Membership* member;
313 struct Channel *ch2ptr = 0;
314 int idx, flag, len, mlen;
315 char *s, *para = parc > 1 ? parv[1] : 0;
318 if (parc > 2 && hunt_server_cmd(sptr, CMD_NAMES, cptr, 1, "%s %C", 2, parc,
322 mlen = strlen(me.name) + 10 + strlen(sptr->name);
324 if (!EmptyString(para))
326 s = strchr(para, ',');
330 m_names(cptr, sptr, parc, parv);
332 clean_channelname(para);
333 ch2ptr = FindChannel(para);
337 * First, do all visible channels (public and the one user self is)
340 for (chptr = GlobalChannelList; chptr; chptr = chptr->next)
342 if ((chptr != ch2ptr) && !EmptyString(para))
343 continue; /* -- wanted a specific channel */
344 if (!MyConnect(sptr) && EmptyString(para))
347 if (!ShowChannel(sptr, chptr))
348 continue; /* -- users on this are not listed */
351 /* Find users on same channel (defined by chptr) */
354 len = strlen(chptr->chname);
355 strcpy(buf + 2, chptr->chname);
356 strcpy(buf + 2 + len, " :");
358 if (PubChannel(chptr))
360 else if (SecretChannel(chptr))
364 for (member = chptr->members; member; member = member->next_member)
366 c2ptr = member->user;
368 if (sptr != c2ptr && IsInvisible(c2ptr) && !find_channel_member(sptr, chptr))
371 if (IsZombie(member))
373 if (member->user != sptr)
381 else if (IsChanOp(member))
386 else if (HasVoice(member))
391 strcat(buf, c2ptr->name);
393 idx += strlen(c2ptr->name) + 1;
398 sprintf_irc(yxx, "%s%s", NumNick(c2ptr));
399 assert(c2ptr == findNUser(yxx));
400 sprintf_irc(buf + strlen(buf), "(%s) ", yxx);
403 if (mlen + idx + NICKLEN + 11 > BUFSIZE)
405 if (mlen + idx + NICKLEN + 5 > BUFSIZE)
407 /* space, modifier, nick, \r \n \0 */
409 send_reply(sptr, RPL_NAMREPLY, buf);
411 ircd_strncpy(buf + 2, chptr->chname, len + 1);
414 if (PubChannel(chptr))
416 else if (SecretChannel(chptr))
423 send_reply(sptr, RPL_NAMREPLY, buf);
425 if (!EmptyString(para))
427 send_reply(sptr, RPL_ENDOFNAMES, ch2ptr ? ch2ptr->chname : para);
431 /* Second, do all non-public, non-secret channels in one big sweep */
433 strcpy(buf, "* * :");
436 for (c2ptr = GlobalClientList; c2ptr; c2ptr = c2ptr->next)
438 struct Channel *ch3ptr;
439 int showflag = 0, secret = 0;
442 if (!IsUser(c2ptr) || (sptr != c2ptr && IsInvisible(c2ptr)))
447 member = c2ptr->user->channel;
449 * Don't show a client if they are on a secret channel or when
450 * they are on a channel sptr is on since they have already
451 * been show earlier. -avalon
455 ch3ptr = member->channel;
457 if (PubChannel(ch3ptr) || find_channel_member(sptr, ch3ptr))
460 if (SecretChannel(ch3ptr))
462 member = member->next_channel;
464 if (showflag) /* Have we already shown them ? */
467 if (secret) /* On any secret channels ? */
470 strcat(buf, c2ptr->name);
472 idx += strlen(c2ptr->name) + 1;
477 sprintf_irc(yxx, "%s%s", NumNick(c2ptr));
478 assert(c2ptr == findNUser(yxx));
479 sprintf_irc(buf + strlen(buf), "(%s) ", yxx);
484 if (mlen + idx + NICKLEN + 9 > BUFSIZE)
486 if (mlen + idx + NICKLEN + 3 > BUFSIZE) /* space, \r\n\0 */
489 send_reply(sptr, RPL_NAMREPLY, buf);
490 strcpy(buf, "* * :");
496 send_reply(sptr, RPL_NAMREPLY, buf);
497 send_reply(sptr, RPL_ENDOFNAMES, "*");
505 * m_names - Added by Jto 27 Apr 1989
507 * parv[0] = sender prefix
510 int m_names(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
512 struct Channel *chptr;
513 struct Client *c2ptr;
514 struct Membership* member;
515 struct Channel *ch2ptr = 0;
516 int idx, flag, len, mlen;
517 char *s, *para = parc > 1 ? parv[1] : 0;
520 if (parc > 2 && hunt_server(1, cptr, sptr, "%s%s " TOK_NAMES " %s %s", 2, parc, parv)) /* XXX DEAD */
523 mlen = strlen(me.name) + 10 + strlen(sptr->name);
525 if (!EmptyString(para))
527 s = strchr(para, ',');
531 m_names(cptr, sptr, parc, parv);
533 clean_channelname(para);
534 ch2ptr = FindChannel(para);
538 * First, do all visible channels (public and the one user self is)
541 for (chptr = GlobalChannelList; chptr; chptr = chptr->next)
543 if ((chptr != ch2ptr) && !EmptyString(para))
544 continue; /* -- wanted a specific channel */
545 if (!MyConnect(sptr) && EmptyString(para))
548 if (!ShowChannel(sptr, chptr))
549 continue; /* -- users on this are not listed */
552 /* Find users on same channel (defined by chptr) */
555 len = strlen(chptr->chname);
556 strcpy(buf + 2, chptr->chname);
557 strcpy(buf + 2 + len, " :");
559 if (PubChannel(chptr))
561 else if (SecretChannel(chptr))
565 for (member = chptr->members; member; member = member->next_member)
567 c2ptr = member->user;
569 if (sptr != c2ptr && IsInvisible(c2ptr) && !find_channel_member(sptr, chptr))
572 if (IsZombie(member))
574 if (member->user != sptr)
582 else if (IsChanOp(member))
587 else if (HasVoice(member))
592 strcat(buf, c2ptr->name);
594 idx += strlen(c2ptr->name) + 1;
599 sprintf_irc(yxx, "%s%s", NumNick(c2ptr));
600 assert(c2ptr == findNUser(yxx));
601 sprintf_irc(buf + strlen(buf), "(%s) ", yxx);
604 if (mlen + idx + NICKLEN + 11 > BUFSIZE)
606 if (mlen + idx + NICKLEN + 5 > BUFSIZE)
608 /* space, modifier, nick, \r \n \0 */
610 sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf); /* XXX DEAD */
612 ircd_strncpy(buf + 2, chptr->chname, len + 1);
615 if (PubChannel(chptr))
617 else if (SecretChannel(chptr))
624 sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf); /* XXX DEAD */
626 if (!EmptyString(para))
628 sendto_one(sptr, rpl_str(RPL_ENDOFNAMES), me.name, parv[0], /* XXX DEAD */
629 ch2ptr ? ch2ptr->chname : para);
633 /* Second, do all non-public, non-secret channels in one big sweep */
635 strcpy(buf, "* * :");
638 for (c2ptr = GlobalClientList; c2ptr; c2ptr = c2ptr->next)
640 struct Channel *ch3ptr;
641 int showflag = 0, secret = 0;
644 if (!IsUser(c2ptr) || (sptr != c2ptr && IsInvisible(c2ptr)))
649 member = c2ptr->user->channel;
651 * Don't show a client if they are on a secret channel or when
652 * they are on a channel sptr is on since they have already
653 * been show earlier. -avalon
657 ch3ptr = member->channel;
659 if (PubChannel(ch3ptr) || find_channel_member(sptr, ch3ptr))
662 if (SecretChannel(ch3ptr))
664 member = member->next_channel;
666 if (showflag) /* Have we already shown them ? */
669 if (secret) /* On any secret channels ? */
672 strcat(buf, c2ptr->name);
674 idx += strlen(c2ptr->name) + 1;
679 sprintf_irc(yxx, "%s%s", NumNick(c2ptr));
680 assert(c2ptr == findNUser(yxx));
681 sprintf_irc(buf + strlen(buf), "(%s) ", yxx);
686 if (mlen + idx + NICKLEN + 9 > BUFSIZE)
688 if (mlen + idx + NICKLEN + 3 > BUFSIZE) /* space, \r\n\0 */
691 sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf); /* XXX DEAD */
692 strcpy(buf, "* * :");
698 sendto_one(sptr, rpl_str(RPL_NAMREPLY), me.name, parv[0], buf); /* XXX DEAD */
699 sendto_one(sptr, rpl_str(RPL_ENDOFNAMES), me.name, parv[0], "*"); /* XXX DEAD */