]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_conn_umodes.cpp
Fixes from vtable cross-check
[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                 ServerInstance->Modules->Attach(I_OnUserConnect, this);
23         }
24
25         void Prioritize()
26         {
27                 // for things like +x on connect, important, otherwise we have to resort to config order (bleh) -- w00t
28                 ServerInstance->Modules->SetPriority(this, I_OnUserConnect, PRIORITY_FIRST);
29         }
30
31         virtual ~ModuleModesOnConnect()
32         {
33         }
34
35         virtual Version GetVersion()
36         {
37                 return Version("Sets (and unsets) modes on users when they connect", VF_VENDOR);
38         }
39
40         virtual void OnUserConnect(LocalUser* user)
41         {
42                 // Backup and zero out the disabled usermodes, so that we can override them here.
43                 char save[64];
44                 memcpy(save, ServerInstance->Config->DisabledUModes,
45                                 sizeof(ServerInstance->Config->DisabledUModes));
46                 memset(ServerInstance->Config->DisabledUModes, 0, 64);
47
48                 ConfigTag* tag = user->MyClass->config;
49                 std::string ThisModes = tag->getString("modes");
50                 if (!ThisModes.empty())
51                 {
52                         std::string buf;
53                         std::stringstream ss(ThisModes);
54
55                         std::vector<std::string> tokens;
56
57                         // split ThisUserModes into modes and mode params
58                         while (ss >> buf)
59                                 tokens.push_back(buf);
60
61                         std::vector<std::string> modes;
62                         modes.push_back(user->nick);
63                         modes.push_back(tokens[0]);
64
65                         if (tokens.size() > 1)
66                         {
67                                 // process mode params
68                                 for (unsigned int k = 1; k < tokens.size(); k++)
69                                 {
70                                         modes.push_back(tokens[k]);
71                                 }
72                         }
73
74                         ServerInstance->Parser->CallHandler("MODE", modes, user);
75                 }
76
77                 memcpy(ServerInstance->Config->DisabledUModes, save, 64);
78         }
79 };
80
81 MODULE_INIT(ModuleModesOnConnect)