]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_user/cmd_user.cpp
Fix some confusing logic in sanick.
[user/henk/code/inspircd.git] / src / coremods / core_user / cmd_user.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2017-2018 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2013-2016 Attila Molnar <attilamolnar@hush.com>
6  *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
7  *   Copyright (C) 2010 Craig Edwards <brain@inspircd.org>
8  *   Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
9  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
10  *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
11  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
12  *
13  * This file is part of InspIRCd.  InspIRCd is free software: you can
14  * redistribute it and/or modify it under the terms of the GNU General Public
15  * License as published by the Free Software Foundation, version 2.
16  *
17  * This program is distributed in the hope that it will be useful, but WITHOUT
18  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
20  * details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24  */
25
26
27 #include "inspircd.h"
28 #include "core_user.h"
29
30 enum
31 {
32         // From ircu.
33         ERR_INVALIDUSERNAME = 468
34 };
35
36 CommandUser::CommandUser(Module* parent)
37         : SplitCommand(parent, "USER", 4, 4)
38 {
39         allow_empty_last_param = false;
40         works_before_reg = true;
41         Penalty = 0;
42         syntax = "<username> <unused> <unused> :<realname>";
43 }
44
45 CmdResult CommandUser::HandleLocal(LocalUser* user, const Params& parameters)
46 {
47         /* A user may only send the USER command once */
48         if (!(user->registered & REG_USER))
49         {
50                 if (!ServerInstance->IsIdent(parameters[0]))
51                 {
52                         user->WriteNumeric(ERR_INVALIDUSERNAME, name, "Your username is not valid");
53                         return CMD_FAILURE;
54                 }
55                 else
56                 {
57                         user->ChangeIdent(parameters[0]);
58                         user->ChangeRealName(parameters[3]);
59                         user->registered = (user->registered | REG_USER);
60                 }
61         }
62         else
63         {
64                 user->WriteNumeric(ERR_ALREADYREGISTERED, "You may not reregister");
65                 user->CommandFloodPenalty += 1000;
66                 return CMD_FAILURE;
67         }
68
69         /* parameters 2 and 3 are local and remote hosts, and are ignored */
70         return CheckRegister(user);
71 }
72
73 CmdResult CommandUser::CheckRegister(LocalUser* user)
74 {
75         // If the user is registered, return CMD_SUCCESS/CMD_FAILURE depending on what modules say, otherwise just
76         // return CMD_SUCCESS without doing anything, knowing the other handler will call us again
77         if (user->registered == REG_NICKUSER)
78         {
79                 ModResult MOD_RESULT;
80                 FIRST_MOD_RESULT(OnUserRegister, MOD_RESULT, (user));
81                 if (MOD_RESULT == MOD_RES_DENY)
82                         return CMD_FAILURE;
83         }
84
85         return CMD_SUCCESS;
86 }