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
26 ModuleModesOnOper(InspIRCd* Me)
30 Conf = new ConfigReader(ServerInstance);
31 Implementation eventlist[] = { I_OnPostOper, I_OnRehash };
32 ServerInstance->Modules->Attach(eventlist, this, 2);
36 virtual void OnRehash(User* user, const std::string ¶meter)
39 Conf = new ConfigReader(ServerInstance);
42 virtual ~ModuleModesOnOper()
47 virtual Version GetVersion()
49 return Version("$Id$", VF_VENDOR, API_VERSION);
52 virtual void OnPostOper(User* user, const std::string &opertype, const std::string &opername)
54 // whenever a user opers, go through the oper types, find their <type:modes>,
55 // and if they have one apply their modes. The mode string can contain +modes
56 // to add modes to the user or -modes to take modes from the user.
57 for (int j =0; j < Conf->Enumerate("type"); j++)
59 std::string typen = Conf->ReadValue("type","name",j);
60 if (typen == user->oper)
62 std::string ThisOpersModes = Conf->ReadValue("type","modes",j);
63 if (!ThisOpersModes.empty())
65 ApplyModes(user, ThisOpersModes);
71 if (!opername.empty()) // if user is local ..
73 for (int j = 0; j < Conf->Enumerate("oper"); j++)
75 if (opername == Conf->ReadValue("oper", "name", j))
77 std::string ThisOpersModes = Conf->ReadValue("oper", "modes", j);
78 if (!ThisOpersModes.empty())
80 ApplyModes(user, ThisOpersModes);
88 void ApplyModes(User *u, std::string &smodes)
90 char first = *(smodes.c_str());
91 if ((first != '+') && (first != '-'))
92 smodes = "+" + smodes;
95 std::stringstream ss(smodes);
96 std::vector<std::string> tokens;
98 // split into modes and mode params
100 tokens.push_back(buf);
102 std::vector<std::string> modes;
103 modes.push_back(u->nick);
105 // process mode params
106 for (unsigned int k = 0; k < tokens.size(); k++)
108 modes.push_back(tokens[k]);
111 ServerInstance->SendMode(modes, u);
112 ServerInstance->PI->SendMode(u->uuid, ServerInstance->Modes->GetLastParseParams(), ServerInstance->Modes->GetLastParseTranslate());
116 MODULE_INIT(ModuleModesOnOper)