]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_user.cpp
ModResult conversion: Change return type of all module functions
[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 #include "commands/cmd_user.h"
16
17 extern "C" DllExport Command* init_command(InspIRCd* Instance)
18 {
19         return new CommandUser(Instance);
20 }
21
22 CmdResult CommandUser::Handle (const std::vector<std::string>& parameters, User *user)
23 {
24         /* A user may only send the USER command once */
25         if (!(user->registered & REG_USER))
26         {
27                 if (!ServerInstance->IsIdent(parameters[0].c_str()))
28                 {
29                         /*
30                          * RFC says we must use this numeric, so we do. Let's make it a little more nub friendly though. :)
31                          *  -- Craig, and then w00t.
32                          */
33                         user->WriteNumeric(461, "%s USER :Your username is not valid",user->nick.c_str());
34                         return CMD_FAILURE;
35                 }
36                 else
37                 {
38                         /*
39                          * The ident field is IDENTMAX+2 in size to account for +1 for the optional
40                          * ~ character, and +1 for null termination, therefore we can safely use up to
41                          * IDENTMAX here.
42                          */
43                         user->ChangeIdent(parameters[0].c_str());
44                         user->fullname.assign(parameters[3].empty() ? std::string("No info") : parameters[3], 0, ServerInstance->Config->Limits.MaxGecos);
45                         user->registered = (user->registered | REG_USER);
46                 }
47         }
48         else
49         {
50                 user->WriteNumeric(462, "%s :You may not reregister", user->nick.c_str());
51                 return CMD_FAILURE;
52         }
53
54         /* parameters 2 and 3 are local and remote hosts, and are ignored */
55         if (user->registered == REG_NICKUSER)
56         {
57                 ModResult MOD_RESULT;
58
59                 /* user is registered now, bit 0 = USER command, bit 1 = sent a NICK command */
60                 FIRST_MOD_RESULT(ServerInstance, OnUserRegister, MOD_RESULT, (user));
61                 if (MOD_RESULT == MOD_RES_DENY)
62                         return CMD_FAILURE;
63
64         }
65
66         return CMD_SUCCESS;
67 }