]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_user.cpp
7d3f73a3f9fd98be27fbc095f5fdc20681e71a37
[user/henk/code/inspircd.git] / src / commands / cmd_user.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/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 char** parameters, int, 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]))
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->WriteServ("461 %s USER :Your username is not valid",user->nick);
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                         strlcpy(user->ident, parameters[0], IDENTMAX);
44                         strlcpy(user->fullname, *parameters[3] ? parameters[3] : "No info", MAXGECOS);
45                         user->registered = (user->registered | REG_USER);
46                 }
47         }
48         else
49         {
50                 user->WriteServ("462 %s :You may not reregister",user->nick);
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                 int MOD_RESULT = 0;
58
59                 /* user is registered now, bit 0 = USER command, bit 1 = sent a NICK command */
60                 FOREACH_RESULT(I_OnUserRegister,OnUserRegister(user));
61                 if (MOD_RESULT > 0)
62                         return CMD_FAILURE;
63
64         }
65
66         return CMD_SUCCESS;
67 }