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