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 // whenever a user opers, go through the oper types, find their <type:modes>,
44 // and if they have one apply their modes. The mode string can contain +modes
45 // to add modes to the user or -modes to take modes from the user.
46 std::string ThisOpersModes = user->oper->getConfig("modes");
47 if (!ThisOpersModes.empty())
49 ApplyModes(user, ThisOpersModes);
52 ThisOpersModes = user->oper->getConfig("modes");
53 if (!ThisOpersModes.empty())
55 ApplyModes(user, ThisOpersModes);
59 void ApplyModes(User *u, std::string &smodes)
61 char first = *(smodes.c_str());
62 if ((first != '+') && (first != '-'))
63 smodes = "+" + smodes;
66 std::stringstream ss(smodes);
67 std::vector<std::string> tokens;
69 // split into modes and mode params
71 tokens.push_back(buf);
73 std::vector<std::string> modes;
74 modes.push_back(u->nick);
76 // process mode params
77 for (unsigned int k = 0; k < tokens.size(); k++)
79 modes.push_back(tokens[k]);
82 ServerInstance->SendMode(modes, u);
83 ServerInstance->PI->SendMode(u->uuid, ServerInstance->Modes->GetLastParseParams(), ServerInstance->Modes->GetLastParseTranslate());
87 MODULE_INIT(ModuleModesOnOper)