1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 static void DisplayList(User* user, Channel* channel)
18 std::stringstream items;
19 for(char letter = 'A'; letter <= 'z'; letter++)
21 ModeHandler* mh = ServerInstance->Modes->FindMode(letter, MODETYPE_CHANNEL);
22 if (!mh || mh->IsListMode())
24 if (!channel->IsModeSet(letter))
26 items << " +" << mh->name;
27 if (mh->GetNumParams(true))
28 items << " " << channel->GetModeParameter(letter);
31 snprintf(pfx, MAXBUF, ":%s 961 %s %s", ServerInstance->Config->ServerName.c_str(), user->nick.c_str(), channel->name.c_str());
32 user->SendText(std::string(pfx), items);
33 user->WriteNumeric(960, "%s %s :End of mode list", user->nick.c_str(), channel->name.c_str());
36 class CommandProp : public Command
39 CommandProp(Module* parent) : Command(parent, "PROP", 1)
41 syntax = "<user|channel> {[+-]<mode> [<value>]}*";
44 CmdResult Handle(const std::vector<std::string> ¶meters, User *src)
46 if (parameters.size() == 1)
48 Channel* chan = ServerInstance->FindChan(parameters[0]);
50 DisplayList(src, chan);
54 std::vector<std::string> modes;
55 modes.push_back(parameters[0]);
57 while (i < parameters.size())
59 std::string prop = parameters[i++];
60 bool plus = prop[0] != '-';
61 if (prop[0] == '+' || prop[0] == '-')
62 prop.erase(prop.begin());
64 for(char letter = 'A'; letter <= 'z'; letter++)
66 ModeHandler* mh = ServerInstance->Modes->FindMode(letter, MODETYPE_CHANNEL);
67 if (mh && mh->name == prop)
69 modes[1].append((plus ? "+" : "-") + std::string(1, letter));
70 if (mh->GetNumParams(plus))
72 if (i != parameters.size())
73 modes.push_back(parameters[i++]);
78 ServerInstance->SendGlobalMode(modes, src);
83 class ModuleNamedModes : public Module
87 ModuleNamedModes() : cmd(this)
93 ServerInstance->Modules->AddService(cmd);
95 Implementation eventlist[] = { I_OnPreMode, I_On005Numeric };
96 ServerInstance->Modules->Attach(eventlist, this, 2);
101 return Version("Provides the ability to manipulate modes via long names.",VF_VENDOR);
106 ServerInstance->Modules->SetPriority(this, I_OnPreMode, PRIORITY_FIRST);
109 void On005Numeric(std::string& line)
111 std::string::size_type pos = line.find(" CHANMODES=");
112 if (pos != std::string::npos)
115 while (line[pos] > 'A' && line[pos] < 'Z')
117 line.insert(pos, 1, 'Z');
121 ModResult OnPreMode(User* source, User* dest, Channel* channel, const std::vector<std::string>& parameters)
124 return MOD_RES_PASSTHRU;
125 if (parameters[1].find('Z') == std::string::npos)
126 return MOD_RES_PASSTHRU;
127 if (parameters.size() <= 2)
129 DisplayList(source, channel);
133 std::vector<std::string> newparms;
134 newparms.push_back(parameters[0]);
135 newparms.push_back(parameters[1]);
137 std::string modelist = newparms[1];
139 unsigned int param_at = 2;
140 for(unsigned int i = 0; i < modelist.length(); i++)
142 unsigned char modechar = modelist[i];
143 if (modechar == '+' || modechar == '-')
145 adding = (modechar == '+');
148 ModeHandler *mh = ServerInstance->Modes->FindMode(modechar, MODETYPE_CHANNEL);
152 std::string name, value;
153 if (param_at < parameters.size())
154 name = parameters[param_at++];
155 std::string::size_type eq = name.find('=');
156 if (eq != std::string::npos)
158 value = name.substr(eq + 1);
159 name = name.substr(0, eq);
161 for(char letter = 'A'; modechar == 0 && letter <= 'z'; letter++)
163 mh = ServerInstance->Modes->FindMode(letter, MODETYPE_CHANNEL);
164 if (mh && mh->name == name)
166 if (mh->GetNumParams(adding))
170 newparms.push_back(value);
183 modelist[i] = modechar;
185 modelist.erase(i--, 1);
187 else if (mh && mh->GetNumParams(adding) && param_at < parameters.size())
189 newparms.push_back(parameters[param_at++]);
192 newparms[1] = modelist;
193 ServerInstance->Modes->Process(newparms, source, false);
198 MODULE_INIT(ModuleNamedModes)