summaryrefslogtreecommitdiff
path: root/src/modules/m_halfvoice.cpp
blob: c961d7c88f5dd4477e5fc0057eabc7bcadbc7ba3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*       +------------------------------------+
 *       | Inspire Internet Relay Chat Daemon |
 *       +------------------------------------+
 *
 *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
 * See: http://wiki.inspircd.org/Credits
 *
 * This program is free but copyrighted software; see
 *            the file COPYING for details.
 *
 * ---------------------------------------------------
 */

#include "inspircd.h"

/* $ModDesc: Provides channel mode +V, adding the - prefix
 *  which does nothing but serves as a status symbol. */

#define HALFVOICE_VALUE 1

class HalfVoiceMode : public ModeHandler
{
 public:
	HalfVoiceMode(Module* parent) : ModeHandler(parent, "halfvoice", 'V', PARAM_ALWAYS, MODETYPE_CHANNEL)
	{
		list = true;
		prefix = 0;
		levelrequired = HALFOP_VALUE;
		m_paramtype = TR_NICK;
	}

	void SetPrefix(char pfx) { prefix = pfx; }

	unsigned int GetPrefixRank()
	{
		return HALFVOICE_VALUE;
	}

	void RemoveMode(Channel* channel, irc::modestacker* stack)
	{
		const UserMembList* cl = channel->GetUsers();
		std::vector<std::string> mode_junk;
		mode_junk.push_back(channel->name);
		irc::modestacker modestack(false);
		std::deque<std::string> stackresult;

		for (UserMembCIter i = cl->begin(); i != cl->end(); i++)
		{
			if (i->second->hasMode('V'))
			{
				if (stack)
					stack->Push(this->GetModeChar(), i->first->nick);
				else
					modestack.Push(this->GetModeChar(), i->first->nick);
			}
		}

		if (stack)
			return;

		while (modestack.GetStackedLine(stackresult))
		{
			mode_junk.insert(mode_junk.end(), stackresult.begin(), stackresult.end());
			ServerInstance->SendMode(mode_junk, ServerInstance->FakeClient);
			mode_junk.erase(mode_junk.begin() + 1, mode_junk.end());
		}
	}

	void RemoveMode(User* user, irc::modestacker* stack)
	{
	}

	ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
	{
		return MODEACTION_ALLOW;
	}
};

class ModuleHalfVoice : public Module
{
	HalfVoiceMode mh;

 public:
	ModuleHalfVoice() : mh(this)
	{
	}

	void init()
	{
		ConfigTag* tag = ServerInstance->Config->ConfValue("halfvoice");
		std::string pfxchar = tag->getString("prefix", "-");
		mh.SetPrefix(pfxchar[0]);
		ServerInstance->Modules->AddService(mh);
	}

	Version GetVersion()
	{
		return Version("Provides a channel mode that does nothing but serve as a status symbol", VF_VENDOR);
	}
};

MODULE_INIT(ModuleHalfVoice)