]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_user.cpp
Gorgonzola!
[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                         // This kinda Sucks, According to the RFC thou, its either this,
33                         // or "You have already registered" :p -- Craig
34                         user->WriteServ("461 %s USER :Not enough parameters",user->nick);
35                         return CMD_FAILURE;
36                 }
37                 else
38                 {
39                         /* We're not checking ident, but I'm not sure I like the idea of '~' prefixing.. */
40                         /* XXX - The ident field is IDENTMAX+2 in size to account for +1 for the optional
41                          * ~ character, and +1 for null termination, therefore we can safely use up to
42                          * IDENTMAX here.
43                          */
44                         strlcpy(user->ident, parameters[0], IDENTMAX);
45                         strlcpy(user->fullname, *parameters[3] ? parameters[3] : "No info", MAXGECOS);
46                         user->registered = (user->registered | REG_USER);
47                 }
48         }
49         else
50         {
51                 user->WriteServ("462 %s :You may not reregister",user->nick);
52                 return CMD_FAILURE;
53         }
54         /* parameters 2 and 3 are local and remote hosts, ignored when sent by client connection */
55         if (user->registered == REG_NICKUSER)
56         {
57                 int MOD_RESULT = 0;
58                 /* user is registered now, bit 0 = USER command, bit 1 = sent a NICK command */
59                 if (ServerInstance->next_call > ServerInstance->Time() + ServerInstance->Config->dns_timeout)
60                         ServerInstance->next_call = ServerInstance->Time() + ServerInstance->Config->dns_timeout;
61                 FOREACH_RESULT(I_OnUserRegister,OnUserRegister(user));
62                 if (MOD_RESULT > 0)
63                         return CMD_FAILURE;
64
65         }
66
67         return CMD_SUCCESS;
68 }