summaryrefslogtreecommitdiff
path: root/modules/core/os_main.cpp
blob: ec5e95ac8e362aec84524d24d2f1ac46634f720c (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/* OperServ core functions
 *
 * (C) 2003-2011 Anope Team
 * Contact us at team@anope.org
 *
 * Please read COPYING and README for further details.
 *
 * Based on the original code of Epona by Lara.
 * Based on the original code of Services by Andy Church.
 */

/*************************************************************************/

#include "module.h"
#include "operserv.h"

static BotInfo *OperServ = NULL;

class OperServBotInfo : public BotInfo
{
 public:
	OperServBotInfo(const Anope::string &bnick, const Anope::string &user = "", const Anope::string &bhost = "", const Anope::string &real = "") : BotInfo(bnick, user, bhost, real) { }
	
	void OnMessage(User *u, const Anope::string &message)
	{
		if (!u->HasMode(UMODE_OPER) && Config->OSOpersOnly)
		{
			u->SendMessage(OperServ, ACCESS_DENIED);
			if (Config->WallBadOS)
				ircdproto->SendGlobops(this, "Denied access to %s from %s!%s@%s (non-oper)", Config->s_OperServ.c_str(), u->nick.c_str(), u->GetIdent().c_str(), u->host.c_str());
		}
		else
		{
			BotInfo::OnMessage(u, message);
		}
	}
};

class MyOperServService : public OperServService
{
 public:
	MyOperServService(Module *m) : OperServService(m) { }

	BotInfo *Bot()
	{
		return OperServ;
	}
};

class OperServCore : public Module
{
	MyOperServService myoperserv;

 public:
	OperServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE), myoperserv(this)
	{
		this->SetAuthor("Anope");
		this->SetPermanent(true); // Currently, /os modunload os_main explodes for obvious reasons

		Implementation i[] = { I_OnServerQuit, I_OnUserModeSet, I_OnUserModeUnset, I_OnUserConnect };
		ModuleManager::Attach(i, this, 4);

		ModuleManager::RegisterService(&this->myoperserv);
		
		OperServ = new OperServBotInfo(Config->s_OperServ, Config->ServiceUser, Config->ServiceHost, Config->desc_OperServ);
		OperServ->SetFlag(BI_CORE);

		/* Yes, these are in this order for a reason. Most violent->least violent. */
		XLineManager::RegisterXLineManager(SGLine = new SGLineManager());
		XLineManager::RegisterXLineManager(SZLine = new SZLineManager());
		XLineManager::RegisterXLineManager(SQLine = new SQLineManager());
		XLineManager::RegisterXLineManager(SNLine = new SNLineManager());

		spacesepstream coreModules(Config->OperCoreModules);
		Anope::string module;
		while (coreModules.GetToken(module))
			ModuleManager::LoadModule(module, NULL);
	}

	~OperServCore()
	{
		spacesepstream coreModules(Config->OperCoreModules);
		Anope::string module;
		while (coreModules.GetToken(module))
		{
			Module *m = ModuleManager::FindModule(module);
			if (m != NULL)
				ModuleManager::UnloadModule(m, NULL);
		}

		delete SGLine;
		SGLine = NULL;
		delete SZLine;
		SZLine = NULL;
		delete SQLine;
		SQLine = NULL;
		delete SNLine;
		SNLine = NULL;

		delete OperServ;
	}

	void OnServerQuit(Server *server)
	{
		if (server->HasFlag(SERVER_JUPED))
			ircdproto->SendGlobops(operserv->Bot(), "Received SQUIT for juped server %s", server->GetName().c_str());
	}

	void OnUserModeSet(User *u, UserModeName Name)
	{
		if (Name == UMODE_OPER)
		{
			if (Config->WallOper)
				ircdproto->SendGlobops(OperServ, "\2%s\2 is now an IRC operator.", u->nick.c_str());
			Log(OperServ) << u->nick << " is now an IRC operator";
		}
	}

	void OnUserModeUnset(User *u, UserModeName Name)
	{
		if (Name == UMODE_OPER)
			Log(OperServ) << u->nick << " is no longer an IRC operator";
	}

	void OnUserConnect(dynamic_reference<User> &u, bool &exempt)
	{
		if (u && !exempt)
			XLineManager::CheckAll(u);
	}
};

MODULE_INIT(OperServCore)