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
|
/* +------------------------------------+
* | Inspire Internet Relay Chat Daemon |
* +------------------------------------+
*
* InspIRCd: (C) 2002-2011 InspIRCd Development Team
* See: http://wiki.inspircd.org/Credits
*
* This program is free but copyrighted software; see
* the file COPYING for details.
*
* ---------------------------------------------------
*/
#include "inspircd.h"
static void DisplayList(User* user, Channel* channel)
{
std::stringstream items;
for(ModeIDIter id; id; id++)
{
ModeHandler* mh = ServerInstance->Modes->FindMode(id);
if (!mh || mh->IsListMode() || mh->GetModeType() != MODETYPE_CHANNEL)
continue;
if (!channel->IsModeSet(mh))
continue;
items << " +" << mh->name;
if (mh->GetNumParams(true))
items << " " << channel->GetModeParameter(mh);
}
char pfx[MAXBUF];
snprintf(pfx, MAXBUF, ":%s 961 %s %s", ServerInstance->Config->ServerName.c_str(), user->nick.c_str(), channel->name.c_str());
user->SendText(std::string(pfx), items);
user->WriteNumeric(960, "%s %s :End of mode list", user->nick.c_str(), channel->name.c_str());
}
class CommandProp : public Command
{
public:
CommandProp(Module* parent) : Command(parent, "PROP", 1)
{
syntax = "<user|channel> {[+-]<mode> [<value>]}*";
}
CmdResult Handle(const std::vector<std::string> ¶meters, User *src)
{
Channel* chan = ServerInstance->FindChan(parameters[0]);
User* user = ServerInstance->FindNick(parameters[0]);
if (!chan && !user)
{
if (parameters[0] == "*")
{
std::string pfx = ":" + ServerInstance->Config->ServerName + " 020 " + src->nick;
std::set<std::string> modeset;
for(ModeIDIter id; id; id++)
{
ModeHandler* mh = ServerInstance->Modes->FindMode(id);
if (mh)
modeset.insert(mh->name);
}
std::stringstream dump;
for(std::set<std::string>::iterator i = modeset.begin(); i != modeset.end(); i++)
dump << " " << *i;
src->SendText(pfx, dump);
return CMD_SUCCESS;
}
src->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",src->nick.c_str(),parameters[0].c_str());
return CMD_FAILURE;
}
if (parameters.size() == 1)
{
if (chan)
DisplayList(src, chan);
return CMD_SUCCESS;
}
unsigned int i = 1;
irc::modestacker modes;
while (i < parameters.size())
{
std::string prop = parameters[i++];
bool plus = prop[0] != '-';
if (prop[0] == '+' || prop[0] == '-')
prop.erase(prop.begin());
ModeHandler* mh = ServerInstance->Modes->FindMode(prop);
if (mh && mh->GetModeType() == MODETYPE_CHANNEL)
{
irc::modechange mc(mh->id);
mc.adding = plus;
if (mh->GetNumParams(plus))
{
if (i == 2 && parameters.size() == 2 && chan && mh->IsListMode())
{
// special case: display list mode
mh->DisplayList(src, chan);
return CMD_SUCCESS;
}
if (i == parameters.size())
{
src->WriteNumeric(ERR_NEEDMOREPARAMS, "%s PROP :Not enough parameters.", src->nick.c_str());
return CMD_FAILURE;
}
mc.value = parameters[i++];
}
modes.push(mc);
}
}
ServerInstance->SendMode(src, chan ? (Extensible*)chan : (Extensible*)user, modes, true);
return CMD_SUCCESS;
}
};
class ModuleNamedModes : public Module
{
CommandProp cmd;
public:
ModuleNamedModes() : cmd(this)
{
}
void init()
{
ServerInstance->Modules->AddService(cmd);
}
Version GetVersion()
{
return Version("Provides the ability to manipulate modes via long names.",VF_VENDOR);
}
};
MODULE_INIT(ModuleNamedModes)
|