1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
26 /* $ModDesc: Sets (and unsets) modes on opers when they oper up */
28 class ModuleModesOnOper : public Module
36 ModuleModesOnOper(InspIRCd* Me)
40 Conf = new ConfigReader(ServerInstance);
43 void Implements(char* List)
45 List[I_OnPostOper] = List[I_OnRehash] = 1;
48 virtual void OnRehash(const std::string ¶meter)
51 Conf = new ConfigReader(ServerInstance);
54 virtual ~ModuleModesOnOper()
59 virtual Version GetVersion()
61 return Version(1,0,0,1,VF_VENDOR,API_VERSION);
64 virtual void OnPostOper(userrec* user, const std::string &opertype)
66 // whenever a user opers, go through the oper types, find their <type:modes>,
67 // and if they have one apply their modes. The mode string can contain +modes
68 // to add modes to the user or -modes to take modes from the user.
69 for (int j =0; j < Conf->Enumerate("type"); j++)
71 std::string typen = Conf->ReadValue("type","name",j);
72 if (!strcmp(typen.c_str(),user->oper))
74 std::string ThisOpersModes = Conf->ReadValue("type","modes",j);
75 char first = *(ThisOpersModes.c_str());
76 if ((first != '+') && (first != '-'))
77 ThisOpersModes = "+" + ThisOpersModes;
78 if (ThisOpersModes != "")
81 stringstream ss(ThisOpersModes);
83 vector<string> tokens;
85 // split ThisOperModes into modes and mode params
87 tokens.push_back(buf);
89 int size = tokens.size() + 1;
90 const char* modes[size];
91 modes[0] = user->nick;
92 modes[1] = (char*)tokens[0].c_str();
94 if (tokens.size() > 1)
96 // process mode params
98 for (unsigned int k = 1; k < tokens.size(); k++)
100 modes[i] = (char*)tokens[k].c_str();
101 ServerInstance->Log(DEBUG, "m_opermodes.so: got mode param: %s", modes[i]);
106 ServerInstance->Log(DEBUG, "m_opermodes.so: new modes for %s: %s", modes[0], modes[1]);
107 ServerInstance->SendMode(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" void * init_module( void )
138 return new ModuleModesOnOperFactory;