-
Notifications
You must be signed in to change notification settings - Fork 1
/
ds_list.cpp
231 lines (222 loc) · 9.11 KB
/
ds_list.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/* ----------------------------------------------------------------------------
* Name : ds_list.cpp
* Author : Naram Qashat (CyberBotX)
* ----------------------------------------------------------------------------
* Description:
*
* The LIST command of DiceServ. See diceserv.cpp for more information about
* DiceServ, including version and license.
* ----------------------------------------------------------------------------
*/
#include "diceserv.h"
ServiceReference<DiceServService> DiceServ("DiceServService", "DiceServ");
/** LIST command
*
* This will allow Services Operators to list all the nicknames/users or channels (either registered or not) matching a mask that are either ignored, allowed,
* or both.
*/
class DSListCommand : public Command
{
public:
DSListCommand(Module *creator) : Command(creator, "diceserv/list", 3, 4)
{
this->SetDesc(Anope::printf(_("Gives list of %s access"), Config->GetClient("DiceServ")->nick.c_str()));
this->SetSyntax(_("{IGNORE|ALLOW|ALL} \037what\037 \037pattern\037 [{REG|UNREG}]"));
}
void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override
{
Anope::string showtype = params[0], what = params[1], pattern = params[2];
// Ignore type must be one of the following, otherwise we stop processing
enum
{
SHOW_IGNORED,
SHOW_ALLOWED,
SHOW_ALL
} show;
if (showtype.equals_ci("IGNORE"))
show = SHOW_IGNORED;
else if (showtype.equals_ci("ALLOW"))
show = SHOW_ALLOWED;
else if (showtype.equals_ci("ALL"))
show = SHOW_ALL;
else
{
this->OnSyntaxError(source, "");
return;
}
// The type of entries to find must be one of the following, otherwise we stop processing
if (!what.equals_ci("CHANNELS") && !what.equals_ci("NICKS"))
{
this->OnSyntaxError(source, "");
return;
}
enum
{
REG_SHOW_ALL,
REG_SHOW_REG,
REG_SHOW_UNREG
} reg = REG_SHOW_ALL;
// If the optional regtype argument is given, it must be one of the following, otherwise we stop processing
if (params.size() > 3)
{
if (params[3].equals_ci("REG"))
reg = REG_SHOW_REG;
if (params[3].equals_ci("UNREG"))
reg = REG_SHOW_UNREG;
else
{
this->OnSyntaxError(source, "");
return;
}
}
// Show the header
source.Reply(_("List of \037%s %s\037 entries matching \002%s\002%s:"),
show == SHOW_IGNORED ? _("ignored") : (show == SHOW_ALLOWED ? _("allowed") : _("all")), what.equals_ci("CHANNELS") ? _("channels") : _("nicks"),
pattern.c_str(), reg == REG_SHOW_ALL ? "" : (reg == REG_SHOW_REG ? _(" (registered only)") : _(" (unregistered only)")));
bool display;
int shown = 0;
// If we are to show channels, we do so
if (what.equals_ci("CHANNELS"))
{
// If no regtype argument is given or we want to look only at unregistered channels, we process the channels list
if (reg == REG_SHOW_UNREG || reg == REG_SHOW_ALL)
for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it)
{
Channel *c = it->second;
// Skip the channel if it's registered
if (c->ci)
continue;
display = false;
// We will only show the channel if it was part of the ignore type request
bool diceserv_ignore = DiceServ->IsIgnored(c);
if (diceserv_ignore && (show == SHOW_IGNORED || show == SHOW_ALL))
display = true;
else if (!diceserv_ignore && (show == SHOW_ALLOWED || show == SHOW_ALL))
display = true;
// If we are to display the channel, make sure it matches the pattern first, and we haven't shown too many entries already
if (display && (pattern.equals_ci(c->name) || Anope::Match(c->name, pattern)) && ++shown <= 100)
{
if (reg == REG_SHOW_ALL)
source.Reply(" %-20s %-5s %s", c->name.c_str(), _("Unreg"), diceserv_ignore ? _("Ignored") : _("Allowed"));
else
source.Reply(" %-20s %s", c->name.c_str(), diceserv_ignore ? _("Ignored") : _("Allowed"));
}
}
// If no regtype argument is given or we want to look only at registered channels, we process the ChanServ list
if (reg == REG_SHOW_REG || reg == REG_SHOW_ALL)
for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it)
{
ChannelInfo *ci = it->second;
// Skip the channel if it's suspended
if (ci->HasExt("SUSPENDED"))
continue;
display = false;
// We will only show the channel if it was part of the ignore type request
bool diceserv_ignore = DiceServ->IsIgnored(ci);
if (diceserv_ignore && (show == SHOW_IGNORED || show == SHOW_ALL))
display = true;
else if (!diceserv_ignore && (show == SHOW_ALLOWED || show == SHOW_ALL))
display = true;
// If we are to display the channel, make sure it matches the pattern first, and we haven't shown too many entries already
if (display && (pattern.equals_ci(ci->name) || Anope::Match(ci->name, pattern)) && ++shown <= 100)
{
if (reg == REG_SHOW_ALL)
source.Reply(" %-20s %-5s %s", ci->name.c_str(), _("Reg"), diceserv_ignore ? _("Ignored") : _("Allowed"));
else
source.Reply(" %-20s %s", ci->name.c_str(), diceserv_ignore ? _("Ignored") : _("Allowed"));
}
}
}
// Otherwise, we are to show nicks
else
{
// If no regtype argument is given or we want to look only at unregistered nicks, we process the users list
if (reg == REG_SHOW_UNREG || reg == REG_SHOW_ALL)
for (Anope::hash_map<User *>::const_iterator it = UserListByNick.begin(), it_end = UserListByNick.end(); it != it_end; ++it)
{
// Check if the nick is a bot, and skip it if it is
BotInfo *bot = BotInfo::Find(it->second->nick);
if (bot)
continue;
User *nu = it->second;
// Skip the nick if it's registered
if (nu->Account())
continue;
display = false;
// We will only show the channel if it was part of the ignore type request
bool diceserv_ignore = DiceServ->IsIgnored(nu);
if (diceserv_ignore && (show == SHOW_IGNORED || show == SHOW_ALL))
display = true;
else if (!diceserv_ignore && (show == SHOW_ALLOWED || show == SHOW_ALL))
display = true;
// If we are to display the nick, make sure it matches the pattern first, and we haven't shown too many entries already
if (display && (pattern.equals_ci(nu->nick) || Anope::Match(nu->nick, pattern)) && ++shown <= 100)
{
if (reg == REG_SHOW_ALL)
source.Reply(" %-20s %-5s %s", nu->nick.c_str(), _("Unreg"), diceserv_ignore ? _("Ignored") : _("Allowed"));
else
source.Reply(" %-20s %s", nu->nick.c_str(), diceserv_ignore ? _("Ignored") : _("Allowed"));
}
}
// If no regtype argument is given or we want to look only at registered nicks, we process the NickServ list
if (reg == REG_SHOW_REG || reg == REG_SHOW_ALL)
for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end; ++it)
{
NickAlias *na = it->second;
// Skip the nick if it's suspended
if (na->nc && na->nc->HasExt("SUSPENDED"))
continue;
display = false;
// We will only show the channel if it was part of the ignore type request
bool diceserv_ignore = DiceServ->IsIgnored(na->nc);
if (diceserv_ignore && (show == SHOW_IGNORED || show == SHOW_ALL))
display = true;
else if (!diceserv_ignore && (show == SHOW_ALLOWED || show == SHOW_ALL))
display = true;
// If we are to display the nick, make sure it matches the pattern first, and we haven't shown too many entries already
if (display && (pattern.equals_ci(na->nick) || Anope::Match(na->nick, pattern, false)) && ++shown <= 100)
{
if (reg == REG_SHOW_ALL)
source.Reply(" %-20s %-5s %s", na->nick.c_str(), _("Reg"), diceserv_ignore ? _("Ignored") : _("Allowed"));
else
source.Reply(" %-20s %s", na->nick.c_str(), diceserv_ignore ? _("Ignored") : _("Allowed"));
}
}
}
// Show the footer
source.Reply(_("End of list - %d/%d matches shown."), shown > 100 ? 100 : shown, shown);
}
bool OnHelp(CommandSource &source, const Anope::string &) anope_override
{
this->SendSyntax(source);
source.Reply(" ");
source.Reply(_("This will display a list of channels or nicks depending on\n"
"what options you give. The first parameter is what access\n"
"types to show, either all ignored, all allowed, or just all.\n"
" \n"
"\037what\037 MUST be one of the following:\n"
" \n"
" CHANNELS Shows channels based on the display type\n"
" NICKS Shows nicks based on the display type\n"
" \n"
"\037pattern\037 is the mask you want to view.\n"
" \n"
"The final parameter is optional, if given, it will allow you\n"
"to choose if only registered or unregistered entries are\n"
"shown on the list."));
return true;
}
};
class DSList : public Module
{
DSListCommand cmd;
public:
DSList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, THIRD), cmd(this)
{
this->SetAuthor(DiceServService::Author());
this->SetVersion(DiceServService::Version());
if (!DiceServ)
throw ModuleException("No interface for DiceServ");
}
};
MODULE_INIT(DSList)