]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_nick.cpp
Remove out of date doc and fix typo in commands/cmd_*.cpp
[user/henk/code/inspircd.git] / src / commands / 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
25 /** Handle /NICK.
26  */
27 class CommandNick : public Command
28 {
29  public:
30         /** Constructor for nick.
31          */
32         CommandNick ( Module* parent) : Command(parent,"NICK", 1, 1) { works_before_reg = true; syntax = "<newnick>"; Penalty = 0; }
33         /** Handle command.
34          * @param parameters The parameters to the command
35          * @param user The user issuing the command
36          * @return A value from CmdResult to indicate command success or failure.
37          */
38         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
39 };
40
41 /** Handle nick changes from users.
42  * NOTE: If you are used to ircds based on ircd2.8, and are looking
43  * for the client introduction code in here, youre in the wrong place.
44  * You need to look in the spanningtree module for this!
45  */
46 CmdResult CommandNick::Handle (const std::vector<std::string>& parameters, User *user)
47 {
48         std::string oldnick = user->nick;
49         std::string newnick = parameters[0];
50
51         // anything except the initial NICK gets a flood penalty
52         if (user->registered == REG_ALL && IS_LOCAL(user))
53                 IS_LOCAL(user)->CommandFloodPenalty += 4000;
54
55         if (newnick.empty())
56         {
57                 user->WriteNumeric(ERR_ERRONEUSNICKNAME, "* :Erroneous Nickname");
58                 return CMD_FAILURE;
59         }
60
61         if (newnick == "0")
62         {
63                 newnick = user->uuid;
64         }
65         else if (!ServerInstance->IsNick(newnick))
66         {
67                 user->WriteNumeric(ERR_ERRONEUSNICKNAME, "%s :Erroneous Nickname", newnick.c_str());
68                 return CMD_FAILURE;
69         }
70
71         if (!user->ChangeNick(newnick, false))
72                 return CMD_FAILURE;
73
74         if (user->registered < REG_NICKUSER)
75         {
76                 user->registered = (user->registered | REG_NICK);
77                 if (user->registered == REG_NICKUSER)
78                 {
79                         /* user is registered now, bit 0 = USER command, bit 1 = sent a NICK command */
80                         ModResult MOD_RESULT;
81                         FIRST_MOD_RESULT(OnUserRegister, MOD_RESULT, (IS_LOCAL(user)));
82                         if (MOD_RESULT == MOD_RES_DENY)
83                                 return CMD_FAILURE;
84
85                         // return early to not penalize new users
86                         return CMD_SUCCESS;
87                 }
88         }
89
90         return CMD_SUCCESS;
91 }
92
93
94 COMMAND_INIT(CommandNick)