]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_user/cmd_nick.cpp
Convert WriteNumeric() calls to pass the parameters of the numeric as method parameters
[user/henk/code/inspircd.git] / src / coremods / core_user / cmd_nick.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2008 Craig Edwards <craigedwards@brainbox.cc>
6  *   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
7  *   Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
8  *
9  * This file is part of InspIRCd.  InspIRCd is free software: you can
10  * redistribute it and/or modify it under the terms of the GNU General Public
11  * License as published by the Free Software Foundation, version 2.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22
23 #include "inspircd.h"
24 #include "core_user.h"
25
26 CommandNick::CommandNick(Module* parent)
27         : SplitCommand(parent, "NICK", 1, 1)
28 {
29         works_before_reg = true;
30         syntax = "<newnick>";
31         Penalty = 0;
32 }
33
34 /** Handle nick changes from users.
35  * NOTE: If you are used to ircds based on ircd2.8, and are looking
36  * for the client introduction code in here, youre in the wrong place.
37  * You need to look in the spanningtree module for this!
38  */
39 CmdResult CommandNick::HandleLocal(const std::vector<std::string>& parameters, LocalUser* user)
40 {
41         std::string oldnick = user->nick;
42         std::string newnick = parameters[0];
43
44         // anything except the initial NICK gets a flood penalty
45         if (user->registered == REG_ALL)
46                 user->CommandFloodPenalty += 4000;
47
48         if (newnick.empty())
49         {
50                 user->WriteNumeric(ERR_ERRONEUSNICKNAME, '*', "Erroneous Nickname");
51                 return CMD_FAILURE;
52         }
53
54         if (newnick == "0")
55         {
56                 newnick = user->uuid;
57         }
58         else if (!ServerInstance->IsNick(newnick))
59         {
60                 user->WriteNumeric(ERR_ERRONEUSNICKNAME, newnick, "Erroneous Nickname");
61                 return CMD_FAILURE;
62         }
63
64         ModResult MOD_RESULT;
65         FIRST_MOD_RESULT(OnUserPreNick, MOD_RESULT, (user, newnick));
66
67         // If a module denied the change, abort now
68         if (MOD_RESULT == MOD_RES_DENY)
69                 return CMD_FAILURE;
70
71         // Disallow the nick change if <security:restrictbannedusers> is on and there is a ban matching this user in
72         // one of the channels they are on
73         if (ServerInstance->Config->RestrictBannedUsers)
74         {
75                 for (User::ChanList::iterator i = user->chans.begin(); i != user->chans.end(); ++i)
76                 {
77                         Channel* chan = (*i)->chan;
78                         if (chan->GetPrefixValue(user) < VOICE_VALUE && chan->IsBanned(user))
79                         {
80                                 user->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (you're banned)");
81                                 return CMD_FAILURE;
82                         }
83                 }
84         }
85
86         if (!user->ChangeNick(newnick))
87                 return CMD_FAILURE;
88
89         if (user->registered < REG_NICKUSER)
90         {
91                 user->registered = (user->registered | REG_NICK);
92                 return CommandUser::CheckRegister(user);
93         }
94
95         return CMD_SUCCESS;
96 }