X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_customprefix.cpp;h=befc9750d1c90e89957ee14e15ea9b07a635cca0;hb=3d0d64933da3d37866fadfa042e34a1125315db6;hp=7e162c72a971a847a9c61eafec7d2f680fa51650;hpb=8281315255d30d7cad6da4936cf9276b7f58a4dc;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_customprefix.cpp b/src/modules/m_customprefix.cpp index 7e162c72a..befc9750d 100644 --- a/src/modules/m_customprefix.cpp +++ b/src/modules/m_customprefix.cpp @@ -24,17 +24,18 @@ class CustomPrefixMode : public PrefixMode public: reference tag; - CustomPrefixMode(Module* parent, ConfigTag* Tag) - : PrefixMode(parent, Tag->getString("name"), 0, Tag->getInt("rank")) + CustomPrefixMode(Module* parent, const std::string& Name, char Letter, char Prefix, ConfigTag* Tag) + : PrefixMode(parent, Name, Letter, 0, Prefix) , tag(Tag) { - std::string v = tag->getString("prefix"); - prefix = v.c_str()[0]; - v = tag->getString("letter"); - mode = v.c_str()[0]; - ranktoset = tag->getInt("ranktoset", prefixrank, prefixrank, UINT_MAX); - ranktounset = tag->getInt("ranktounset", ranktoset, ranktoset, UINT_MAX); - selfremove = tag->getBool("depriv", true); + unsigned long rank = tag->getUInt("rank", 0, 0, UINT_MAX); + unsigned long setrank = tag->getUInt("ranktoset", prefixrank, rank, UINT_MAX); + unsigned long unsetrank = tag->getUInt("ranktounset", setrank, setrank, UINT_MAX); + bool depriv = tag->getBool("depriv", true); + this->Update(rank, setrank, unsetrank, depriv); + + ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Created the %s prefix: letter=%c prefix=%c rank=%u ranktoset=%u ranktounset=%i depriv=%d", + name.c_str(), GetModeChar(), GetPrefix(), GetPrefixRank(), GetLevelRequired(true), GetLevelRequired(false), CanSelfRemove()); } }; @@ -45,18 +46,47 @@ class ModuleCustomPrefix : public Module void init() CXX11_OVERRIDE { ConfigTagList tags = ServerInstance->Config->ConfTags("customprefix"); - while (tags.first != tags.second) + for (ConfigIter iter = tags.first; iter != tags.second; ++iter) { - ConfigTag* tag = tags.first->second; - tags.first++; - CustomPrefixMode* mh = new CustomPrefixMode(this, tag); - modes.push_back(mh); - if (mh->GetPrefixRank() == 0) - throw ModuleException("Rank must be specified for prefix at " + tag->getTagLocation()); - if (!isalpha(mh->GetModeChar())) - throw ModuleException("Mode must be a letter for prefix at " + tag->getTagLocation()); + ConfigTag* tag = iter->second; + + const std::string name = tag->getString("name"); + if (name.empty()) + throw ModuleException(" must be specified at " + tag->getTagLocation()); + + if (tag->getBool("change")) + { + ModeHandler* mh = ServerInstance->Modes->FindMode(name, MODETYPE_CHANNEL); + if (!mh) + throw ModuleException(" specified for a non-existent mode at " + tag->getTagLocation()); + + PrefixMode* pm = mh->IsPrefixMode(); + if (!pm) + throw ModuleException(" specified for a non-prefix mode at " + tag->getTagLocation()); + + unsigned long rank = tag->getUInt("rank", pm->GetPrefixRank(), 0, UINT_MAX); + unsigned long setrank = tag->getUInt("ranktoset", pm->GetLevelRequired(true), rank, UINT_MAX); + unsigned long unsetrank = tag->getUInt("ranktounset", pm->GetLevelRequired(false), setrank, UINT_MAX); + bool depriv = tag->getBool("depriv", pm->CanSelfRemove()); + pm->Update(rank, setrank, unsetrank, depriv); + + ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Changed the %s prefix: depriv=%u rank=%u ranktoset=%u ranktounset=%u", + pm->name.c_str(), pm->CanSelfRemove(), pm->GetPrefixRank(), pm->GetLevelRequired(true), pm->GetLevelRequired(false)); + continue; + } + + const std::string letter = tag->getString("letter"); + if (letter.length() != 1) + throw ModuleException(" must be set to a mode character at " + tag->getTagLocation()); + + const std::string prefix = tag->getString("prefix"); + if (prefix.length() != 1) + throw ModuleException(" must be set to a mode prefix at " + tag->getTagLocation()); + try { + CustomPrefixMode* mh = new CustomPrefixMode(this, name, letter[0], prefix[0], tag); + modes.push_back(mh); ServerInstance->Modules->AddService(*mh); } catch (ModuleException& e)