]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_user/cmd_away.cpp
Sync helpop chmodes s and p with docs
[user/henk/code/inspircd.git] / src / coremods / core_user / cmd_away.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2018 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2013-2014, 2016 Attila Molnar <attilamolnar@hush.com>
6  *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
7  *   Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
8  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
9  *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
10  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
11  *   Copyright (C) 2006, 2008, 2010 Craig Edwards <brain@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 RFC 1459.
33         RPL_UNAWAY = 305,
34         RPL_NOWAWAY = 306
35 };
36
37 CommandAway::CommandAway(Module* parent)
38         : Command(parent, "AWAY", 0, 1)
39         , awayevprov(parent)
40 {
41         allow_empty_last_param = false;
42         syntax = "[:<message>]";
43 }
44
45 /** Handle /AWAY
46  */
47 CmdResult CommandAway::Handle(User* user, const Params& parameters)
48 {
49         LocalUser* luser = IS_LOCAL(user);
50         ModResult MOD_RESULT;
51
52         if (!parameters.empty())
53         {
54                 std::string message(parameters[0]);
55                 if (luser)
56                 {
57                         FIRST_MOD_RESULT_CUSTOM(awayevprov, Away::EventListener, OnUserPreAway, MOD_RESULT, (luser, message));
58                         if (MOD_RESULT == MOD_RES_DENY)
59                                 return CMD_FAILURE;
60                 }
61
62                 user->awaytime = ServerInstance->Time();
63                 user->awaymsg.assign(message, 0, ServerInstance->Config->Limits.MaxAway);
64                 user->WriteNumeric(RPL_NOWAWAY, "You have been marked as being away");
65                 FOREACH_MOD_CUSTOM(awayevprov, Away::EventListener, OnUserAway, (user));
66         }
67         else
68         {
69                 if (luser)
70                 {
71                         FIRST_MOD_RESULT_CUSTOM(awayevprov, Away::EventListener, OnUserPreBack, MOD_RESULT, (luser));
72                         if (MOD_RESULT == MOD_RES_DENY)
73                                 return CMD_FAILURE;
74                 }
75
76                 user->awaytime = 0;
77                 user->awaymsg.clear();
78                 user->WriteNumeric(RPL_UNAWAY, "You are no longer marked as being away");
79                 FOREACH_MOD_CUSTOM(awayevprov, Away::EventListener, OnUserBack, (user));
80         }
81
82         return CMD_SUCCESS;
83 }
84
85 RouteDescriptor CommandAway::GetRouting(User* user, const Params& parameters)
86 {
87         return (IS_LOCAL(user) ? ROUTE_LOCALONLY : ROUTE_BROADCAST);
88 }