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 * ---------------------------------------------------
21 /* $ModDesc: Sets (and unsets) modes on opers when they oper up */
23 class ModuleModesOnOper : public Module
31 ModuleModesOnOper(InspIRCd* Me)
35 Conf = new ConfigReader(ServerInstance);
38 void Implements(char* List)
40 List[I_OnPostOper] = List[I_OnRehash] = 1;
43 virtual void OnRehash(userrec* user, const std::string ¶meter)
46 Conf = new ConfigReader(ServerInstance);
49 virtual ~ModuleModesOnOper()
54 virtual Version GetVersion()
56 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
59 virtual void OnPostOper(userrec* user, const std::string &opertype)
61 // whenever a user opers, go through the oper types, find their <type:modes>,
62 // and if they have one apply their modes. The mode string can contain +modes
63 // to add modes to the user or -modes to take modes from the user.
64 for (int j =0; j < Conf->Enumerate("type"); j++)
66 std::string typen = Conf->ReadValue("type","name",j);
67 if (!strcmp(typen.c_str(),user->oper))
69 std::string ThisOpersModes = Conf->ReadValue("type","modes",j);
70 char first = *(ThisOpersModes.c_str());
71 if ((first != '+') && (first != '-'))
72 ThisOpersModes = "+" + ThisOpersModes;
73 if (ThisOpersModes != "")
76 stringstream ss(ThisOpersModes);
78 vector<string> tokens;
80 // split ThisOperModes into modes and mode params
82 tokens.push_back(buf);
84 int size = tokens.size() + 1;
85 char** modes = new char*[size];
86 modes[0] = user->nick;
87 modes[1] = (char*)tokens[0].c_str();
89 if (tokens.size() > 1)
91 // process mode params
93 for (unsigned int k = 1; k < tokens.size(); k++)
95 modes[i] = (char*)tokens[k].c_str();
99 std::deque<std::string> n;
100 Event rmode((char *)&n, NULL, "send_mode");
101 for (unsigned int j = 0; j < tokens.size(); j++)
103 n.push_back(modes[j]);
105 rmode.Send(ServerInstance);
106 ServerInstance->SendMode((const char**)modes, size, user);
115 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
117 class ModuleModesOnOperFactory : public ModuleFactory
120 ModuleModesOnOperFactory()
124 ~ModuleModesOnOperFactory()
128 virtual Module * CreateModule(InspIRCd* Me)
130 return new ModuleModesOnOper(Me);
136 extern "C" DllExport void * init_module( void )
138 return new ModuleModesOnOperFactory;