]> jfr.im git - irc/rqf/shadowircd.git/blame - extensions/m_olist.c
Automated merge with ssh://hg.atheme.org//hg/charybdis
[irc/rqf/shadowircd.git] / extensions / m_olist.c
CommitLineData
212380e3 1/*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_olist.c: List channels. olist is an oper only command
4 * that shows channels regardless of modes. This
5 * is kinda evil, and might be morally wrong, but
6 * somebody will likely need it.
7 *
8 * Copyright (C) 2002 by the past and present ircd coders, and others.
9 * Copyright (C) 2004 ircd-ratbox Development Team
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 * USA
25 *
26 * $Id: m_olist.c 6 2005-09-10 01:02:21Z nenolod $
27 */
28
29#include "stdinc.h"
30#include "tools.h"
31#include "patricia.h"
32#include "channel.h"
33#include "client.h"
34#include "ircd.h"
35#include "numeric.h"
36#include "s_log.h"
37#include "s_serv.h"
38#include "send.h"
39#include "whowas.h"
40#include "irc_string.h"
41#include "hash.h"
42#include "msg.h"
43#include "parse.h"
44#include "modules.h"
45#include "s_newconf.h"
46#include "sprintf_irc.h"
47
48static int mo_olist(struct Client *, struct Client *, int parc, const char *parv[]);
49
50#ifndef STATIC_MODULES
51
52struct Message olist_msgtab = {
53 "OLIST", 0, 0, 0, MFLG_SLOW,
54 {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_olist, 1}}
55};
56
57mapi_clist_av1 olist_clist[] = { &olist_msgtab, NULL };
58
59DECLARE_MODULE_AV1(okick, NULL, NULL, olist_clist, NULL, NULL, "$Revision: 6 $");
60
61#endif
62
63static void list_all_channels(struct Client *source_p);
64static void list_named_channel(struct Client *source_p, const char *name);
65
66/*
67** mo_olist
68** parv[0] = sender prefix
69** parv[1] = channel
70*/
71static int
72mo_olist(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
73{
74 if(IsOperSpy(source_p))
75 {
76 /* If no arg, do all channels *whee*, else just one channel */
77 if(parc < 2 || EmptyString(parv[1]))
78 {
79 report_operspy(source_p, "LIST", NULL);
80 list_all_channels(source_p);
81 }
82 else
83 {
84 report_operspy(source_p, "LIST", parv[1]);
85 list_named_channel(source_p, parv[1]);
86 }
87 }
88
89 sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name);
90 return 0;
91}
92
93
94/*
95 * list_all_channels
96 * inputs - pointer to client requesting list
97 * output - 0/1
98 * side effects - list all channels to source_p
99 */
100static void
101list_all_channels(struct Client *source_p)
102{
103 struct Channel *chptr;
104 dlink_node *ptr;
105 sendto_one(source_p, form_str(RPL_LISTSTART), me.name, source_p->name);
106
107 DLINK_FOREACH(ptr, global_channel_list.head)
108 {
109 chptr = ptr->data;
110
111 sendto_one(source_p, form_str(RPL_LIST),
112 me.name, source_p->name, chptr->chname,
113 dlink_list_length(&chptr->members),
114 chptr->topic == NULL ? "" : chptr->topic);
115 }
116
117 return;
118}
119
120/*
121 * list_named_channel
122 * inputs - pointer to client requesting list
123 * output - 0/1
124 * side effects - list all channels to source_p
125 */
126static void
127list_named_channel(struct Client *source_p, const char *name)
128{
129 struct Channel *chptr;
130 char *p;
131 char *n = LOCAL_COPY(name);
132
133 sendto_one(source_p, form_str(RPL_LISTSTART), me.name, source_p->name);
134
135 if((p = strchr(n, ',')))
136 *p = '\0';
137
138 if(EmptyString(n))
139 {
140 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
141 form_str(ERR_NOSUCHCHANNEL), n);
142 return;
143 }
144
145 if((chptr = find_channel(n)) == NULL)
146 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
147 form_str(ERR_NOSUCHCHANNEL), n);
148 else
149 sendto_one(source_p, form_str(RPL_LIST), me.name, source_p->name,
150 chptr->chname, dlink_list_length(&chptr->members),
151 chptr->topic ? chptr->topic : "");
152}