]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_statusprefix.cpp
rename channel modes +it to distinguish them from commands
[user/henk/code/inspircd.git] / src / modules / m_statusprefix.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: Provides channel mode +V, adding the - prefix
17  *  which does nothing but serves as a status symbol. */
18
19 #define STATUS_VALUE 1
20
21 /** Abstraction of StatusPrefixBase for channel mode +a
22  */
23 class StatusPrefix : public ModeHandler
24 {
25  public:
26         StatusPrefix(Module* parent) : ModeHandler(parent, "status", 'V', PARAM_ALWAYS, MODETYPE_CHANNEL)
27         {
28                 list = true;
29                 prefix = 0;
30                 levelrequired = HALFOP_VALUE;
31                 m_paramtype = TR_NICK;
32         }
33
34         void SetPrefix(char pfx) { prefix = pfx; }
35
36         unsigned int GetPrefixRank()
37         {
38                 return STATUS_VALUE;
39         }
40
41         void RemoveMode(Channel* channel, irc::modestacker* stack)
42         {
43                 const UserMembList* cl = channel->GetUsers();
44                 std::vector<std::string> mode_junk;
45                 mode_junk.push_back(channel->name);
46                 irc::modestacker modestack(false);
47                 std::deque<std::string> stackresult;
48
49                 for (UserMembCIter i = cl->begin(); i != cl->end(); i++)
50                 {
51                         if (i->second->hasMode('V'))
52                         {
53                                 if (stack)
54                                         stack->Push(this->GetModeChar(), i->first->nick);
55                                 else
56                                         modestack.Push(this->GetModeChar(), i->first->nick);
57                         }
58                 }
59
60                 if (stack)
61                         return;
62
63                 while (modestack.GetStackedLine(stackresult))
64                 {
65                         mode_junk.insert(mode_junk.end(), stackresult.begin(), stackresult.end());
66                         ServerInstance->SendMode(mode_junk, ServerInstance->FakeClient);
67                         mode_junk.erase(mode_junk.begin() + 1, mode_junk.end());
68                 }
69         }
70
71         void RemoveMode(User* user, irc::modestacker* stack)
72         {
73         }
74
75         ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
76         {
77                 return MODEACTION_ALLOW;
78         }
79 };
80
81 class ModuleStatusPrefix : public Module
82 {
83         StatusPrefix mh;
84
85  public:
86         ModuleStatusPrefix() : mh(this)
87         {
88         }
89
90         void init()
91         {
92                 ConfigTag* tag = ServerInstance->Config->ConfValue("statusprefix");
93                 std::string pfxchar = tag->getString("prefix", "-");
94                 mh.SetPrefix(pfxchar[0]);
95                 ServerInstance->Modules->AddService(mh);
96         }
97
98         ~ModuleStatusPrefix()
99         {
100         }
101
102         Version GetVersion()
103         {
104                 return Version("Provides a channel mode that does nothing but serve as a status symbol", VF_VENDOR);
105         }
106 };
107
108 MODULE_INIT(ModuleStatusPrefix)