]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_user.cpp
Remove InspIRCd* parameters and fields
[user/henk/code/inspircd.git] / src / commands / cmd_user.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 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
16 /** Handle /USER. These command handlers can be reloaded by the core,
17  * and handle basic RFC1459 commands. Commands within modules work
18  * the same way, however, they can be fully unloaded, where these
19  * may not.
20  */
21 class CommandUser : public Command
22 {
23  public:
24         /** Constructor for user.
25          */
26         CommandUser ( Module* parent) : Command(parent,"USER",4,4) { works_before_reg = true; Penalty = 0; syntax = "<username> <localhost> <remotehost> <GECOS>"; }
27         /** Handle command.
28          * @param parameters The parameters to the comamnd
29          * @param pcnt The number of parameters passed to teh command
30          * @param user The user issuing the command
31          * @return A value from CmdResult to indicate command success or failure.
32          */
33         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
34 };
35
36 CmdResult CommandUser::Handle (const std::vector<std::string>& parameters, User *user)
37 {
38         /* A user may only send the USER command once */
39         if (!(user->registered & REG_USER))
40         {
41                 if (!ServerInstance->IsIdent(parameters[0].c_str()))
42                 {
43                         /*
44                          * RFC says we must use this numeric, so we do. Let's make it a little more nub friendly though. :)
45                          *  -- Craig, and then w00t.
46                          */
47                         user->WriteNumeric(461, "%s USER :Your username is not valid",user->nick.c_str());
48                         return CMD_FAILURE;
49                 }
50                 else
51                 {
52                         /*
53                          * The ident field is IDENTMAX+2 in size to account for +1 for the optional
54                          * ~ character, and +1 for null termination, therefore we can safely use up to
55                          * IDENTMAX here.
56                          */
57                         user->ChangeIdent(parameters[0].c_str());
58                         user->fullname.assign(parameters[3].empty() ? std::string("No info") : parameters[3], 0, ServerInstance->Config->Limits.MaxGecos);
59                         user->registered = (user->registered | REG_USER);
60                 }
61         }
62         else
63         {
64                 user->WriteNumeric(462, "%s :You may not reregister", user->nick.c_str());
65                 return CMD_FAILURE;
66         }
67
68         /* parameters 2 and 3 are local and remote hosts, and are ignored */
69         if (user->registered == REG_NICKUSER)
70         {
71                 ModResult MOD_RESULT;
72
73                 /* user is registered now, bit 0 = USER command, bit 1 = sent a NICK command */
74                 FIRST_MOD_RESULT(OnUserRegister, MOD_RESULT, (user));
75                 if (MOD_RESULT == MOD_RES_DENY)
76                         return CMD_FAILURE;
77
78         }
79
80         return CMD_SUCCESS;
81 }
82
83 COMMAND_INIT(CommandUser)