summaryrefslogtreecommitdiff
path: root/src/actions.cpp
blob: 62b5bf5820f49a253a1b02a0ed90507354d8cf02 (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
/* Various routines to perform simple actions.
 *
 * (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 "services.h"

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

/**
 * Note a bad password attempt for the given user.  If they've used up
 * their limit, toss them off.
 * @param u the User to check
 * @return true if the user was killed, otherwise false
 */
bool bad_password(User *u)
{
	if (!u || !Config->BadPassLimit)
		return false;

	if (Config->BadPassTimeout > 0 && u->invalid_pw_time > 0 && u->invalid_pw_time < Anope::CurTime - Config->BadPassTimeout)
		u->invalid_pw_count = 0;
	++u->invalid_pw_count;
	u->invalid_pw_time = Anope::CurTime;
	if (u->invalid_pw_count >= Config->BadPassLimit)
	{
		u->Kill(Config->ServerName, "Too many invalid passwords");
		return true;
	}

	return false;
}

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


/**
 * Unban the user from a channel
 * @param ci channel info for the channel
 * @param u The user to unban
 * @param full True to match against the users real host and IP
 * @return void
 */
void common_unban(ChannelInfo *ci, User *u, bool full)
{
	if (!u || !ci || !ci->c || !ci->c->HasMode(CMODE_BAN))
		return;

	std::pair<Channel::ModeList::iterator, Channel::ModeList::iterator> bans = ci->c->GetModeList(CMODE_BAN);
	for (; bans.first != bans.second;)
	{
		Entry ban(CMODE_BAN, bans.first->second);
		++bans.first;
		if (ban.Matches(u, full))
			ci->c->RemoveMode(NULL, CMODE_BAN, ban.GetMask());
	}
}

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