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