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 * ---------------------------------------------------
19 /* $ModDesc: Sets (and unsets) modes on opers when they oper up */
21 class ModuleModesOnOper : public Module
29 ModuleModesOnOper(InspIRCd* Me)
33 Conf = new ConfigReader(ServerInstance);
36 void Implements(char* List)
38 List[I_OnPostOper] = List[I_OnRehash] = 1;
41 virtual void OnRehash(userrec* user, const std::string ¶meter)
44 Conf = new ConfigReader(ServerInstance);
47 virtual ~ModuleModesOnOper()
52 virtual Version GetVersion()
54 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
57 virtual void OnPostOper(userrec* user, const std::string &opertype)
59 // whenever a user opers, go through the oper types, find their <type:modes>,
60 // and if they have one apply their modes. The mode string can contain +modes
61 // to add modes to the user or -modes to take modes from the user.
62 for (int j =0; j < Conf->Enumerate("type"); j++)
64 std::string typen = Conf->ReadValue("type","name",j);
65 if (!strcmp(typen.c_str(),user->oper))
67 std::string ThisOpersModes = Conf->ReadValue("type","modes",j);
68 if (!ThisOpersModes.empty())
70 char first = *(ThisOpersModes.c_str());
71 if ((first != '+') && (first != '-'))
72 ThisOpersModes = "+" + ThisOpersModes;
75 stringstream ss(ThisOpersModes);
76 vector<string> tokens;
78 // split ThisOperModes into modes and mode params
80 tokens.push_back(buf);
82 int size = tokens.size() + 1;
83 const char** modes = new const char*[size];
84 modes[0] = user->nick;
86 // process mode params
88 for (unsigned int k = 0; k < tokens.size(); k++)
90 modes[i] = tokens[k].c_str();
94 std::deque<std::string> n;
95 Event rmode((char *)&n, NULL, "send_mode_explicit");
96 for (unsigned int j = 0; j < tokens.size(); j++)
97 n.push_back(modes[j]);
99 rmode.Send(ServerInstance);
100 ServerInstance->SendMode(modes, size, user);
109 MODULE_INIT(ModuleModesOnOper)