1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 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 class ModuleNamedModes : public Module
21 Implementation eventlist[] = { I_OnPreMode, I_On005Numeric };
22 ServerInstance->Modules->Attach(eventlist, this, 2);
27 return Version("Provides the ability to manipulate modes via long names.",VF_VENDOR);
32 ServerInstance->Modules->SetPriority(this, I_OnPreMode, PRIORITY_FIRST);
35 void On005Numeric(std::string& line)
37 std::string::size_type pos = line.find(" CHANMODES=");
38 if (pos != std::string::npos)
41 while (line[pos] > 'A' && line[pos] < 'Z')
43 line.insert(pos, 1, 'Z');
47 void DisplayList(User* user, Channel* channel)
49 for(char letter = 'A'; letter <= 'z'; letter++)
51 ModeHandler* mh = ServerInstance->Modes->FindMode(letter, MODETYPE_CHANNEL);
52 if (!mh || mh->IsListMode())
54 if (!channel->IsModeSet(letter))
56 std::string item = mh->name;
57 if (mh->GetNumParams(true))
58 item += "=" + channel->GetModeParameter(letter);
59 user->WriteNumeric(961, "%s %s %s", user->nick.c_str(), channel->name.c_str(), item.c_str());
61 user->WriteNumeric(960, "%s %s :End of mode list", user->nick.c_str(), channel->name.c_str());
64 ModResult OnPreMode(User* source, User* dest, Channel* channel, const std::vector<std::string>& parameters)
67 return MOD_RES_PASSTHRU;
68 if (parameters[1].find('Z') == std::string::npos)
69 return MOD_RES_PASSTHRU;
70 if (parameters.size() <= 2)
72 DisplayList(source, channel);
76 std::vector<std::string> newparms;
77 newparms.push_back(parameters[0]);
78 newparms.push_back(parameters[1]);
80 std::string modelist = newparms[1];
82 unsigned int param_at = 2;
83 for(unsigned int i = 0; i < modelist.length(); i++)
85 unsigned char modechar = modelist[i];
86 if (modechar == '+' || modechar == '-')
88 adding = (modechar == '+');
91 ModeHandler *mh = ServerInstance->Modes->FindMode(modechar, MODETYPE_CHANNEL);
95 std::string name, value;
96 if (param_at < parameters.size())
97 name = parameters[param_at++];
98 std::string::size_type eq = name.find('=');
99 if (eq != std::string::npos)
101 value = name.substr(eq + 1);
102 name = name.substr(0, eq);
104 for(char letter = 'A'; modechar == 0 && letter <= 'z'; letter++)
106 mh = ServerInstance->Modes->FindMode(letter, MODETYPE_CHANNEL);
107 if (mh && mh->name == name)
109 if (mh->GetNumParams(adding))
113 newparms.push_back(value);
126 modelist[i] = modechar;
128 modelist.erase(i, 1);
130 else if (mh && mh->GetNumParams(adding) && param_at < parameters.size())
132 newparms.push_back(parameters[param_at++]);
135 newparms[1] = modelist;
136 ServerInstance->Modes->Process(newparms, source, false);
141 MODULE_INIT(ModuleNamedModes)