]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_nick.cpp
a69f1ddac2cc18bdd465c66eac5cb80f9daaf5d5
[user/henk/code/inspircd.git] / src / commands / cmd_nick.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "xline.h"
16
17 /** Handle /NICK. These command handlers can be reloaded by the core,
18  * and handle basic RFC1459 commands. Commands within modules work
19  * the same way, however, they can be fully unloaded, where these
20  * may not.
21  */
22 class CommandNick : public Command
23 {
24  public:
25         /** Constructor for nick.
26          */
27         CommandNick ( Module* parent) : Command(parent,"NICK", 1, 1) { works_before_reg = true; syntax = "<newnick>"; Penalty = 0; }
28         /** Handle command.
29          * @param parameters The parameters to the comamnd
30          * @param pcnt The number of parameters passed to teh command
31          * @param user The user issuing the command
32          * @return A value from CmdResult to indicate command success or failure.
33          */
34         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
35 };
36
37 /** Handle nick changes from users.
38  * NOTE: If you are used to ircds based on ircd2.8, and are looking
39  * for the client introduction code in here, youre in the wrong place.
40  * You need to look in the spanningtree module for this!
41  */
42 CmdResult CommandNick::Handle (const std::vector<std::string>& parameters, User *user)
43 {
44         std::string oldnick = user->nick;
45         std::string newnick = parameters[0];
46
47         // anything except the initial NICK gets a flood penalty
48         if (user->registered == REG_ALL && IS_LOCAL(user))
49                 IS_LOCAL(user)->CommandFloodPenalty += 4000;
50
51         if (newnick.empty())
52         {
53                 user->WriteNumeric(432, "%s * :Erroneous Nickname", oldnick.c_str());
54                 return CMD_FAILURE;
55         }
56
57         if (newnick == "0")
58         {
59                 newnick = user->uuid;
60         }
61         else if (!ServerInstance->IsNick(newnick.c_str(), ServerInstance->Config->Limits.NickMax))
62         {
63                 user->WriteNumeric(432, "%s %s :Erroneous Nickname", user->nick.c_str(),newnick.c_str());
64                 return CMD_FAILURE;
65         }
66
67         if (!user->ChangeNick(newnick, false))
68                 return CMD_FAILURE;
69
70         if (user->registered < REG_NICKUSER)
71         {
72                 user->registered = (user->registered | REG_NICK);
73                 if (user->registered == REG_NICKUSER)
74                 {
75                         /* user is registered now, bit 0 = USER command, bit 1 = sent a NICK command */
76                         ModResult MOD_RESULT;
77                         FIRST_MOD_RESULT(OnUserRegister, MOD_RESULT, (IS_LOCAL(user)));
78                         if (MOD_RESULT == MOD_RES_DENY)
79                                 return CMD_FAILURE;
80
81                         // return early to not penalize new users
82                         return CMD_SUCCESS;
83                 }
84         }
85
86         return CMD_SUCCESS;
87 }
88
89
90 COMMAND_INIT(CommandNick)