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 /* $ModDesc: Allows custom prefix modes to be created. */
18 class CustomPrefixMode : public ModeHandler
21 reference<ConfigTag> tag;
24 CustomPrefixMode(Module* parent, ConfigTag* Tag)
25 : ModeHandler(parent, Tag->getString("name"), 0, PARAM_ALWAYS, MODETYPE_CHANNEL), tag(Tag)
28 m_paramtype = TR_NICK;
29 std::string v = tag->getString("prefix");
30 prefix = v.c_str()[0];
31 v = tag->getString("letter");
33 rank = tag->getInt("rank");
34 levelrequired = tag->getInt("ranktoset", rank);
35 depriv = tag->getBool("depriv", true);
38 unsigned int GetPrefixRank()
43 ModResult AccessCheck(User* src, Channel*, std::string& value, bool adding)
45 if (!adding && src->nick == value && depriv)
47 return MOD_RES_PASSTHRU;
50 void RemoveMode(Channel* channel, irc::modestacker* stack)
52 const UserMembList* cl = channel->GetUsers();
53 std::vector<std::string> mode_junk;
54 mode_junk.push_back(channel->name);
55 irc::modestacker modestack(false);
56 std::deque<std::string> stackresult;
58 for (UserMembCIter i = cl->begin(); i != cl->end(); i++)
60 if (i->second->hasMode(mode))
63 stack->Push(this->GetModeChar(), i->first->nick);
65 modestack.Push(this->GetModeChar(), i->first->nick);
72 while (modestack.GetStackedLine(stackresult))
74 mode_junk.insert(mode_junk.end(), stackresult.begin(), stackresult.end());
75 ServerInstance->SendMode(mode_junk, ServerInstance->FakeClient);
76 mode_junk.erase(mode_junk.begin() + 1, mode_junk.end());
80 void RemoveMode(User* user, irc::modestacker* stack)
84 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
86 return MODEACTION_ALLOW;
90 class ModuleCustomPrefix : public Module
92 std::vector<CustomPrefixMode*> modes;
100 ConfigTagList tags = ServerInstance->Config->ConfTags("customprefix");
101 while (tags.first != tags.second)
103 ConfigTag* tag = tags.first->second;
105 CustomPrefixMode* mh = new CustomPrefixMode(this, tag);
108 throw ModuleException("Rank must be specified for prefix at " + tag->getTagLocation());
109 if (!isalpha(mh->GetModeChar()))
110 throw ModuleException("Mode must be a letter for prefix at " + tag->getTagLocation());
113 ServerInstance->Modules->AddService(*mh);
115 catch (ModuleException& e)
117 throw ModuleException(e.err + " (while creating mode from " + tag->getTagLocation() + ")");
122 ~ModuleCustomPrefix()
124 for (std::vector<CustomPrefixMode*>::iterator i = modes.begin(); i != modes.end(); i++)
130 return Version("Provides custom prefix channel modes", VF_VENDOR);
134 MODULE_INIT(ModuleCustomPrefix)