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 const char* modes[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 n.push_back(user->nick);
102 n.push_back(modes[0]);
103 for (unsigned int j = 1; j < tokens.size(); j++)
105 n.push_back(modes[j]);
107 rmode.Send(ServerInstance);
108 ServerInstance->SendMode(modes, size, user);
116 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
118 class ModuleModesOnOperFactory : public ModuleFactory
121 ModuleModesOnOperFactory()
125 ~ModuleModesOnOperFactory()
129 virtual Module * CreateModule(InspIRCd* Me)
131 return new ModuleModesOnOper(Me);
137 extern "C" void * init_module( void )
139 return new ModuleModesOnOperFactory;