| 1 |
/* |
| 2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
* |
| 4 |
* Copyright (c) 1997-2021 ircd-hybrid development team |
| 5 |
* |
| 6 |
* This program is free software; you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU General Public License as published by |
| 8 |
* the Free Software Foundation; either version 2 of the License, or |
| 9 |
* (at your option) any later version. |
| 10 |
* |
| 11 |
* This program is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program; if not, write to the Free Software |
| 18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
| 19 |
* USA |
| 20 |
*/ |
| 21 |
|
| 22 |
/*! \file m_quit.c |
| 23 |
* \brief Includes required functions for processing the QUIT command. |
| 24 |
* \version $Id$ |
| 25 |
*/ |
| 26 |
|
| 27 |
#include "stdinc.h" |
| 28 |
#include "client.h" |
| 29 |
#include "ircd.h" |
| 30 |
#include "irc_string.h" |
| 31 |
#include "send.h" |
| 32 |
#include "parse.h" |
| 33 |
#include "modules.h" |
| 34 |
#include "conf.h" |
| 35 |
|
| 36 |
|
| 37 |
/*! \brief QUIT command handler |
| 38 |
* |
| 39 |
* \param source_p Pointer to allocated Client struct from which the message |
| 40 |
* originally comes from. This can be a local or remote client. |
| 41 |
* \param parc Integer holding the number of supplied arguments. |
| 42 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
| 43 |
* pointers. |
| 44 |
* \note Valid arguments for this command are: |
| 45 |
* - parv[0] = command |
| 46 |
* - parv[1] = quit message |
| 47 |
*/ |
| 48 |
static void |
| 49 |
m_quit(struct Client *source_p, int parc, char *parv[]) |
| 50 |
{ |
| 51 |
char reason[KICKLEN + 1] = "Quit: "; |
| 52 |
|
| 53 |
if (!EmptyString(parv[1]) && (HasUMode(source_p, UMODE_OPER) || |
| 54 |
(source_p->connection->created_monotonic + ConfigGeneral.anti_spam_exit_message_time) |
| 55 |
< event_base->time.sec_monotonic)) |
| 56 |
strlcpy(reason + 6, parv[1], sizeof(reason) - 6); |
| 57 |
|
| 58 |
exit_client(source_p, reason); |
| 59 |
} |
| 60 |
|
| 61 |
/*! \brief QUIT command handler |
| 62 |
* |
| 63 |
* \param source_p Pointer to allocated Client struct from which the message |
| 64 |
* originally comes from. This can be a local or remote client. |
| 65 |
* \param parc Integer holding the number of supplied arguments. |
| 66 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
| 67 |
* pointers. |
| 68 |
* \note Valid arguments for this command are: |
| 69 |
* - parv[0] = command |
| 70 |
* - parv[1] = quit message |
| 71 |
*/ |
| 72 |
static void |
| 73 |
ms_quit(struct Client *source_p, int parc, char *parv[]) |
| 74 |
{ |
| 75 |
char reason[KICKLEN + 1] = ""; /* Essential that buf[0] = '\0' */ |
| 76 |
|
| 77 |
if (!EmptyString(parv[1])) |
| 78 |
strlcpy(reason, parv[1], sizeof(reason)); |
| 79 |
|
| 80 |
exit_client(source_p, reason); |
| 81 |
} |
| 82 |
|
| 83 |
static struct Message quit_msgtab = |
| 84 |
{ |
| 85 |
.cmd = "QUIT", |
| 86 |
.handlers[UNREGISTERED_HANDLER] = { .handler = m_quit }, |
| 87 |
.handlers[CLIENT_HANDLER] = { .handler = m_quit }, |
| 88 |
.handlers[SERVER_HANDLER] = { .handler = ms_quit }, |
| 89 |
.handlers[ENCAP_HANDLER] = { .handler = m_ignore }, |
| 90 |
.handlers[OPER_HANDLER] = { .handler = m_quit } |
| 91 |
}; |
| 92 |
|
| 93 |
static void |
| 94 |
module_init(void) |
| 95 |
{ |
| 96 |
mod_add_cmd(&quit_msgtab); |
| 97 |
} |
| 98 |
|
| 99 |
static void |
| 100 |
module_exit(void) |
| 101 |
{ |
| 102 |
mod_del_cmd(&quit_msgtab); |
| 103 |
} |
| 104 |
|
| 105 |
struct module module_entry = |
| 106 |
{ |
| 107 |
.version = "$Revision$", |
| 108 |
.modinit = module_init, |
| 109 |
.modexit = module_exit, |
| 110 |
.is_core = true |
| 111 |
}; |