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
29 Conf = new ConfigReader;
30 Implementation eventlist[] = { I_OnPostOper, I_OnRehash };
31 ServerInstance->Modules->Attach(eventlist, this, 2);
35 virtual void OnRehash(User* user)
38 Conf = new ConfigReader;
41 virtual ~ModuleModesOnOper()
46 virtual Version GetVersion()
48 return Version("Sets (and unsets) modes on opers when they oper up", VF_VENDOR, API_VERSION);
51 virtual void OnPostOper(User* user, const std::string &opertype, const std::string &opername)
53 // whenever a user opers, go through the oper types, find their <type:modes>,
54 // and if they have one apply their modes. The mode string can contain +modes
55 // to add modes to the user or -modes to take modes from the user.
56 for (int j =0; j < Conf->Enumerate("type"); j++)
58 std::string typen = Conf->ReadValue("type","name",j);
59 if (typen == user->oper)
61 std::string ThisOpersModes = Conf->ReadValue("type","modes",j);
62 if (!ThisOpersModes.empty())
64 ApplyModes(user, ThisOpersModes);
70 if (!opername.empty()) // if user is local ..
72 for (int j = 0; j < Conf->Enumerate("oper"); j++)
74 if (opername == Conf->ReadValue("oper", "name", j))
76 std::string ThisOpersModes = Conf->ReadValue("oper", "modes", j);
77 if (!ThisOpersModes.empty())
79 ApplyModes(user, ThisOpersModes);
87 void ApplyModes(User *u, std::string &smodes)
89 char first = *(smodes.c_str());
90 if ((first != '+') && (first != '-'))
91 smodes = "+" + smodes;
94 std::stringstream ss(smodes);
95 std::vector<std::string> tokens;
97 // split into modes and mode params
99 tokens.push_back(buf);
101 std::vector<std::string> modes;
102 modes.push_back(u->nick);
104 // process mode params
105 for (unsigned int k = 0; k < tokens.size(); k++)
107 modes.push_back(tokens[k]);
110 ServerInstance->SendMode(modes, u);
111 ServerInstance->PI->SendMode(u->uuid, ServerInstance->Modes->GetLastParseParams(), ServerInstance->Modes->GetLastParseTranslate());
115 MODULE_INIT(ModuleModesOnOper)