]> jfr.im git - irc/rqf/shadowircd.git/blame - extensions/m_olist.c
BOPM/TCM do not need the ability to global kill, so remove it from server_bot
[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"
212380e3 30#include "channel.h"
31#include "client.h"
32#include "ircd.h"
33#include "numeric.h"
d3455e2c 34#include "logger.h"
212380e3 35#include "s_serv.h"
36#include "send.h"
37#include "whowas.h"
13ae2f4b 38#include "match.h"
212380e3 39#include "hash.h"
40#include "msg.h"
41#include "parse.h"
42#include "modules.h"
43#include "s_newconf.h"
212380e3 44
45static int mo_olist(struct Client *, struct Client *, int parc, const char *parv[]);
46
47#ifndef STATIC_MODULES
48
49struct Message olist_msgtab = {
50 "OLIST", 0, 0, 0, MFLG_SLOW,
51 {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_olist, 1}}
52};
53
54mapi_clist_av1 olist_clist[] = { &olist_msgtab, NULL };
55
56DECLARE_MODULE_AV1(okick, NULL, NULL, olist_clist, NULL, NULL, "$Revision: 6 $");
57
58#endif
59
60static void list_all_channels(struct Client *source_p);
61static void list_named_channel(struct Client *source_p, const char *name);
62
63/*
64** mo_olist
65** parv[0] = sender prefix
66** parv[1] = channel
67*/
68static int
69mo_olist(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
70{
d4715e8f 71 if(!IsOperSpy(source_p))
212380e3 72 {
d4715e8f
JT
73 sendto_one(source_p, form_str(ERR_NOPRIVS),
74 me.name, source_p->name, "oper_spy");
75 sendto_one(source_p, form_str(RPL_LISTEND),
76 me.name, source_p->name);
77 return 0;
78 }
79
80 /* If no arg, do all channels *whee*, else just one channel */
81 if(parc < 2 || EmptyString(parv[1]))
d4715e8f 82 list_all_channels(source_p);
d4715e8f 83 else
d4715e8f 84 list_named_channel(source_p, parv[1]);
212380e3 85
86 sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name);
87 return 0;
88}
89
90
91/*
92 * list_all_channels
93 * inputs - pointer to client requesting list
94 * output - 0/1
95 * side effects - list all channels to source_p
96 */
97static void
98list_all_channels(struct Client *source_p)
99{
100 struct Channel *chptr;
71f6ebfa 101 rb_dlink_node *ptr;
0d234dca
JT
102
103 report_operspy(source_p, "LIST", NULL);
212380e3 104 sendto_one(source_p, form_str(RPL_LISTSTART), me.name, source_p->name);
105
71f6ebfa 106 RB_DLINK_FOREACH(ptr, global_channel_list.head)
212380e3 107 {
108 chptr = ptr->data;
109
110 sendto_one(source_p, form_str(RPL_LIST),
111 me.name, source_p->name, chptr->chname,
c51d32ba 112 rb_dlink_list_length(&chptr->members),
212380e3 113 chptr->topic == NULL ? "" : chptr->topic);
114 }
115
116 return;
117}
118
119/*
120 * list_named_channel
121 * inputs - pointer to client requesting list
122 * output - 0/1
123 * side effects - list all channels to source_p
124 */
125static void
126list_named_channel(struct Client *source_p, const char *name)
127{
128 struct Channel *chptr;
129 char *p;
130 char *n = LOCAL_COPY(name);
131
212380e3 132 if((p = strchr(n, ',')))
133 *p = '\0';
134
0d234dca
JT
135 /* Put operspy notice before any output, but only if channel exists */
136 chptr = EmptyString(n) ? NULL : find_channel(n);
137 if(chptr != NULL)
138 report_operspy(source_p, "LIST", chptr->chname);
139
140 sendto_one(source_p, form_str(RPL_LISTSTART), me.name, source_p->name);
141
212380e3 142 if(EmptyString(n))
212380e3 143 return;
212380e3 144
0d234dca 145 if(chptr == NULL)
212380e3 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,
c51d32ba 150 chptr->chname, rb_dlink_list_length(&chptr->members),
212380e3 151 chptr->topic ? chptr->topic : "");
152}