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 std::string item = mh->name;
27 if (mh->GetNumParams(true))
28 item += "=" + channel->GetModeParameter(letter);
32 snprintf(pfx, MAXBUF, ":%s 961 %s %s", ServerInstance->Config->ServerName.c_str(), user->nick.c_str(), channel->name.c_str());
33 user->SendText(std::string(pfx), items);
34 user->WriteNumeric(960, "%s %s :End of mode list", user->nick.c_str(), channel->name.c_str());
37 class CommandProp : public Command
40 CommandProp(Module* parent) : Command(parent, "PROP", 1)
42 syntax = "<user|channel> [{+|-}<mode>[=value]]";
43 TRANSLATE3(TR_TEXT, TR_TEXT, TR_END);
46 CmdResult Handle(const std::vector<std::string> ¶meters, User *src)
48 if (parameters.size() == 1)
50 Channel* chan = ServerInstance->FindChan(parameters[0]);
52 DisplayList(src, chan);
56 std::string prop = parameters[1], value;
57 std::string::size_type eq = prop.find('=');
58 if (eq != std::string::npos)
60 value = prop.substr(eq + 1);
61 prop = prop.substr(0, eq);
63 bool plus = prop[0] != '-';
64 if (prop[0] == '+' || prop[0] == '-')
65 prop.erase(prop.begin());
67 for(char letter = 'A'; letter <= 'z'; letter++)
69 ModeHandler* mh = ServerInstance->Modes->FindMode(letter, MODETYPE_CHANNEL);
70 if (mh && mh->name == prop)
72 if (mh->GetNumParams(plus) && value.empty())
74 std::vector<std::string> modes;
75 modes.push_back(parameters[0]);
76 modes.push_back((plus ? "+" : "-") + std::string(1, letter));
77 modes.push_back(value);
78 ServerInstance->SendGlobalMode(modes, src);
86 class ModuleNamedModes : public Module
90 ModuleNamedModes() : cmd(this)
96 ServerInstance->Modules->AddService(cmd);
97 Implementation eventlist[] = { I_OnPreMode, I_On005Numeric };
98 ServerInstance->Modules->Attach(eventlist, this, 2);
103 return Version("Provides the ability to manipulate modes via long names.",VF_VENDOR);
108 ServerInstance->Modules->SetPriority(this, I_OnPreMode, PRIORITY_FIRST);
111 void On005Numeric(std::string& line)
113 std::string::size_type pos = line.find(" CHANMODES=");
114 if (pos != std::string::npos)
117 while (line[pos] > 'A' && line[pos] < 'Z')
119 line.insert(pos, 1, 'Z');
123 ModResult OnPreMode(User* source, User* dest, Channel* channel, const std::vector<std::string>& parameters)
126 return MOD_RES_PASSTHRU;
127 if (parameters[1].find('Z') == std::string::npos)
128 return MOD_RES_PASSTHRU;
129 if (parameters.size() <= 2)
131 DisplayList(source, channel);
135 std::vector<std::string> newparms;
136 newparms.push_back(parameters[0]);
137 newparms.push_back(parameters[1]);
139 std::string modelist = newparms[1];
141 unsigned int param_at = 2;
142 for(unsigned int i = 0; i < modelist.length(); i++)
144 unsigned char modechar = modelist[i];
145 if (modechar == '+' || modechar == '-')
147 adding = (modechar == '+');
150 ModeHandler *mh = ServerInstance->Modes->FindMode(modechar, MODETYPE_CHANNEL);
154 std::string name, value;
155 if (param_at < parameters.size())
156 name = parameters[param_at++];
157 std::string::size_type eq = name.find('=');
158 if (eq != std::string::npos)
160 value = name.substr(eq + 1);
161 name = name.substr(0, eq);
163 for(char letter = 'A'; modechar == 0 && letter <= 'z'; letter++)
165 mh = ServerInstance->Modes->FindMode(letter, MODETYPE_CHANNEL);
166 if (mh && mh->name == name)
168 if (mh->GetNumParams(adding))
172 newparms.push_back(value);
185 modelist[i] = modechar;
187 modelist.erase(i--, 1);
189 else if (mh && mh->GetNumParams(adding) && param_at < parameters.size())
191 newparms.push_back(parameters[param_at++]);
194 newparms[1] = modelist;
195 ServerInstance->Modes->Process(newparms, source, false);
200 MODULE_INIT(ModuleNamedModes)