]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_conn_umodes.cpp
Hold reference to the associated ConfigTag inside ConnectClass
[user/henk/code/inspircd.git] / src / modules / m_conn_umodes.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15
16 /* $ModDesc: Sets (and unsets) modes on users when they connect */
17
18 class ModuleModesOnConnect : public Module
19 {
20  public:
21         ModuleModesOnConnect()  {
22                 Implementation eventlist[] = { I_OnUserConnect, I_OnRehash };
23                 ServerInstance->Modules->Attach(eventlist, this, 2);
24                 // for things like +x on connect, important, otherwise we have to resort to config order (bleh) -- w00t
25                 ServerInstance->Modules->SetPriority(this, PRIORITY_FIRST);
26         }
27
28
29         virtual ~ModuleModesOnConnect()
30         {
31         }
32
33         virtual Version GetVersion()
34         {
35                 return Version("Sets (and unsets) modes on users when they connect", VF_VENDOR,API_VERSION);
36         }
37
38         virtual void OnUserConnect(User* user)
39         {
40                 if (!IS_LOCAL(user))
41                         return;
42
43                 // Backup and zero out the disabled usermodes, so that we can override them here.
44                 char save[64];
45                 memcpy(save, ServerInstance->Config->DisabledUModes,
46                                 sizeof(ServerInstance->Config->DisabledUModes));
47                 memset(ServerInstance->Config->DisabledUModes, 0, 64);
48
49                 ConfigTag* tag = user->MyClass->config;
50                 std::string ThisModes = tag->getString("modes");
51                 if (!ThisModes.empty())
52                 {
53                         std::string buf;
54                         std::stringstream ss(ThisModes);
55
56                         std::vector<std::string> tokens;
57
58                         // split ThisUserModes into modes and mode params
59                         while (ss >> buf)
60                                 tokens.push_back(buf);
61
62                         std::vector<std::string> modes;
63                         modes.push_back(user->nick);
64                         modes.push_back(tokens[0]);
65
66                         if (tokens.size() > 1)
67                         {
68                                 // process mode params
69                                 for (unsigned int k = 1; k < tokens.size(); k++)
70                                 {
71                                         modes.push_back(tokens[k]);
72                                 }
73                         }
74
75                         ServerInstance->Parser->CallHandler("MODE", modes, user);
76                 }
77
78                 memcpy(ServerInstance->Config->DisabledUModes, save, 64);
79         }
80 };
81
82 MODULE_INIT(ModuleModesOnConnect)