]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_user.cpp
Extra Dry! Shame it's not in Hereford right now :p
[user/henk/code/inspircd.git] / src / 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 "configreader.h"
16 #include "users.h"
17 #include "commands/cmd_user.h"
18
19 extern "C" DllExport command_t* init_command(InspIRCd* Instance)
20 {
21         return new cmd_user(Instance);
22 }
23
24 CmdResult cmd_user::Handle (const char** parameters, int pcnt, userrec *user)
25 {
26         /* A user may only send the USER command once */
27         if (!(user->registered & REG_USER))
28         {
29                 if (!ServerInstance->IsIdent(parameters[0]))
30                 {
31                         /*
32                          * RFC says we must use this numeric, so we do. Let's make it a little more nub friendly though. :)
33                          *  -- Craig, and then w00t.
34                          */
35                         user->WriteServ("461 %s USER :Your username is not valid",user->nick);
36                         return CMD_FAILURE;
37                 }
38                 else
39                 {
40                         /* We're not checking ident, but I'm not sure I like the idea of '~' prefixing.. */
41                         /* XXX - The ident field is IDENTMAX+2 in size to account for +1 for the optional
42                          * ~ character, and +1 for null termination, therefore we can safely use up to
43                          * IDENTMAX here.
44                          */
45                         strlcpy(user->ident, parameters[0], IDENTMAX);
46                         strlcpy(user->fullname, *parameters[3] ? parameters[3] : "No info", MAXGECOS);
47                         user->registered = (user->registered | REG_USER);
48                 }
49         }
50         else
51         {
52                 user->WriteServ("462 %s :You may not reregister",user->nick);
53                 return CMD_FAILURE;
54         }
55         /* parameters 2 and 3 are local and remote hosts, ignored when sent by client connection */
56         if (user->registered == REG_NICKUSER)
57         {
58                 int MOD_RESULT = 0;
59                 /* user is registered now, bit 0 = USER command, bit 1 = sent a NICK command */
60                 if (ServerInstance->next_call > ServerInstance->Time() + ServerInstance->Config->dns_timeout)
61                         ServerInstance->next_call = ServerInstance->Time() + ServerInstance->Config->dns_timeout;
62                 FOREACH_RESULT(I_OnUserRegister,OnUserRegister(user));
63                 if (MOD_RESULT > 0)
64                         return CMD_FAILURE;
65
66         }
67
68         return CMD_SUCCESS;
69 }