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