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: Sets (and unsets) modes on opers when they oper up */
18 class ModuleModesOnOper : public Module
23 Implementation eventlist[] = { I_OnPostOper, I_OnRehash };
24 ServerInstance->Modules->Attach(eventlist, this, 2);
28 virtual void OnRehash(User* user)
32 virtual ~ModuleModesOnOper()
36 virtual Version GetVersion()
38 return Version("Sets (and unsets) modes on opers when they oper up", VF_VENDOR);
41 virtual void OnPostOper(User* user, const std::string &opertype, const std::string &opername)
43 TagIndex::iterator typetag = ServerInstance->Config->opertypes.find(opertype);
44 if (typetag == ServerInstance->Config->opertypes.end())
46 // whenever a user opers, go through the oper types, find their <type:modes>,
47 // and if they have one apply their modes. The mode string can contain +modes
48 // to add modes to the user or -modes to take modes from the user.
49 std::string ThisOpersModes = typetag->second->getString("modes");
50 if (!ThisOpersModes.empty())
52 ApplyModes(user, ThisOpersModes);
55 if (!opername.empty()) // if user is local ..
59 ConfigTag* tag = ServerInstance->Config->ConfValue("oper", i);
62 if (tag->getString("name") != opername)
64 ThisOpersModes = tag->getString("modes");
65 if (!ThisOpersModes.empty())
67 ApplyModes(user, ThisOpersModes);
74 void ApplyModes(User *u, std::string &smodes)
76 char first = *(smodes.c_str());
77 if ((first != '+') && (first != '-'))
78 smodes = "+" + smodes;
81 std::stringstream ss(smodes);
82 std::vector<std::string> tokens;
84 // split into modes and mode params
86 tokens.push_back(buf);
88 std::vector<std::string> modes;
89 modes.push_back(u->nick);
91 // process mode params
92 for (unsigned int k = 0; k < tokens.size(); k++)
94 modes.push_back(tokens[k]);
97 ServerInstance->SendMode(modes, u);
98 ServerInstance->PI->SendMode(u->uuid, ServerInstance->Modes->GetLastParseParams(), ServerInstance->Modes->GetLastParseTranslate());
102 MODULE_INIT(ModuleModesOnOper)