1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/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(1,1,0,1,VF_VENDOR,API_VERSION);
52 virtual void OnPostOper(User* user, const std::string &opertype)
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 (!strcmp(typen.c_str(),user->oper))
62 std::string ThisOpersModes = Conf->ReadValue("type","modes",j);
63 if (!ThisOpersModes.empty())
65 char first = *(ThisOpersModes.c_str());
66 if ((first != '+') && (first != '-'))
67 ThisOpersModes = "+" + ThisOpersModes;
70 stringstream ss(ThisOpersModes);
71 vector<string> tokens;
73 // split ThisOperModes into modes and mode params
75 tokens.push_back(buf);
77 int size = tokens.size() + 1;
78 const char** modes = new const char*[size];
79 modes[0] = user->nick;
81 // process mode params
83 for (unsigned int k = 0; k < tokens.size(); k++)
85 modes[i] = tokens[k].c_str();
89 std::deque<std::string> n;
90 Event rmode((char *)&n, NULL, "send_mode_explicit");
91 for (unsigned int j = 0; j < tokens.size(); j++)
92 n.push_back(modes[j]);
94 rmode.Send(ServerInstance);
95 ServerInstance->SendMode(modes, size, user);
104 MODULE_INIT(ModuleModesOnOper)