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 char first = *(ThisOpersModes.c_str());
69 if ((first != '+') && (first != '-'))
70 ThisOpersModes = "+" + ThisOpersModes;
71 if (ThisOpersModes != "")
74 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 char** modes = new char*[size];
84 modes[0] = user->nick;
85 modes[1] = (char*)tokens[0].c_str();
87 if (tokens.size() > 1)
89 // process mode params
91 for (unsigned int k = 1; k < tokens.size(); k++)
93 modes[i] = (char*)tokens[k].c_str();
97 std::deque<std::string> n;
98 Event rmode((char *)&n, NULL, "send_mode");
99 for (unsigned int j = 0; j < tokens.size(); j++)
101 n.push_back(modes[j]);
103 rmode.Send(ServerInstance);
104 ServerInstance->SendMode((const char**)modes, size, user);
113 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
115 class ModuleModesOnOperFactory : public ModuleFactory
118 ModuleModesOnOperFactory()
122 ~ModuleModesOnOperFactory()
126 virtual Module * CreateModule(InspIRCd* Me)
128 return new ModuleModesOnOper(Me);
134 extern "C" DllExport void * init_module( void )
136 return new ModuleModesOnOperFactory;