| 1 |
/* |
| 2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
* |
| 4 |
* Copyright (c) 1997-2018 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_away.c |
| 23 |
* \brief Includes required functions for processing the AWAY command. |
| 24 |
* \version $Id$ |
| 25 |
*/ |
| 26 |
|
| 27 |
#include "stdinc.h" |
| 28 |
#include "client.h" |
| 29 |
#include "irc_string.h" |
| 30 |
#include "ircd.h" |
| 31 |
#include "numeric.h" |
| 32 |
#include "send.h" |
| 33 |
#include "parse.h" |
| 34 |
#include "modules.h" |
| 35 |
#include "conf.h" |
| 36 |
#include "server.h" |
| 37 |
#include "user.h" |
| 38 |
#include "isupport.h" |
| 39 |
|
| 40 |
|
| 41 |
/*! |
| 42 |
* |
| 43 |
* \param source_p Pointer to client to set (un)away |
| 44 |
* \param message Away message; can be NULL |
| 45 |
*/ |
| 46 |
static void |
| 47 |
do_away(struct Client *source_p, const char *message) |
| 48 |
{ |
| 49 |
assert(IsClient(source_p)); |
| 50 |
|
| 51 |
if (EmptyString(message)) |
| 52 |
{ |
| 53 |
/* Marking as not away */ |
| 54 |
if (source_p->away[0]) |
| 55 |
{ |
| 56 |
source_p->away[0] = '\0'; |
| 57 |
|
| 58 |
/* We now send this only if they were away before --is */ |
| 59 |
sendto_server(source_p, 0, 0, ":%s AWAY", source_p->id); |
| 60 |
sendto_common_channels_local(source_p, 1, CAP_AWAY_NOTIFY, 0, ":%s!%s@%s AWAY", |
| 61 |
source_p->name, source_p->username, source_p->host); |
| 62 |
} |
| 63 |
|
| 64 |
if (MyConnect(source_p)) |
| 65 |
sendto_one_numeric(source_p, &me, RPL_UNAWAY); |
| 66 |
return; |
| 67 |
} |
| 68 |
|
| 69 |
if (MyConnect(source_p)) |
| 70 |
{ |
| 71 |
if ((source_p->connection->away.last_attempt + ConfigGeneral.away_time) < CurrentTime) |
| 72 |
source_p->connection->away.count = 0; |
| 73 |
|
| 74 |
if (source_p->connection->away.count > ConfigGeneral.away_count) |
| 75 |
{ |
| 76 |
sendto_one_numeric(source_p, &me, ERR_TOOMANYAWAY); |
| 77 |
return; |
| 78 |
} |
| 79 |
|
| 80 |
source_p->connection->away.last_attempt = CurrentTime; |
| 81 |
source_p->connection->away.count++; |
| 82 |
sendto_one_numeric(source_p, &me, RPL_NOWAWAY); |
| 83 |
} |
| 84 |
|
| 85 |
strlcpy(source_p->away, message, sizeof(source_p->away)); |
| 86 |
sendto_common_channels_local(source_p, 1, CAP_AWAY_NOTIFY, 0, ":%s!%s@%s AWAY :%s", |
| 87 |
source_p->name, source_p->username, |
| 88 |
source_p->host, source_p->away); |
| 89 |
sendto_server(source_p, 0, 0, ":%s AWAY :%s", |
| 90 |
source_p->id, source_p->away); |
| 91 |
} |
| 92 |
|
| 93 |
/*! \brief AWAY command handler |
| 94 |
* |
| 95 |
* \param source_p Pointer to allocated Client struct from which the message |
| 96 |
* originally comes from. This can be a local or remote client. |
| 97 |
* \param parc Integer holding the number of supplied arguments. |
| 98 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
| 99 |
* pointers. |
| 100 |
* \note Valid arguments for this command are: |
| 101 |
* - parv[0] = command |
| 102 |
* - parv[1] = away message |
| 103 |
*/ |
| 104 |
static int |
| 105 |
m_away(struct Client *source_p, int parc, char *parv[]) |
| 106 |
{ |
| 107 |
const char *const message = parv[1]; |
| 108 |
|
| 109 |
do_away(source_p, message); |
| 110 |
return 0; |
| 111 |
} |
| 112 |
|
| 113 |
/*! \brief AWAY command handler |
| 114 |
* |
| 115 |
* \param source_p Pointer to allocated Client struct from which the message |
| 116 |
* originally comes from. This can be a local or remote client. |
| 117 |
* \param parc Integer holding the number of supplied arguments. |
| 118 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
| 119 |
* pointers. |
| 120 |
* \note Valid arguments for this command are: |
| 121 |
* - parv[0] = command |
| 122 |
* - parv[1] = away message |
| 123 |
*/ |
| 124 |
static int |
| 125 |
ms_away(struct Client *source_p, int parc, char *parv[]) |
| 126 |
{ |
| 127 |
const char *const message = parv[1]; |
| 128 |
|
| 129 |
do_away(source_p, message); |
| 130 |
return 0; |
| 131 |
} |
| 132 |
|
| 133 |
static struct Message away_msgtab = |
| 134 |
{ |
| 135 |
.cmd = "AWAY", |
| 136 |
.args_max = MAXPARA, |
| 137 |
.handlers[UNREGISTERED_HANDLER] = m_unregistered, |
| 138 |
.handlers[CLIENT_HANDLER] = m_away, |
| 139 |
.handlers[SERVER_HANDLER] = ms_away, |
| 140 |
.handlers[ENCAP_HANDLER] = m_ignore, |
| 141 |
.handlers[OPER_HANDLER] = m_away |
| 142 |
}; |
| 143 |
|
| 144 |
static void |
| 145 |
module_init(void) |
| 146 |
{ |
| 147 |
mod_add_cmd(&away_msgtab); |
| 148 |
isupport_add("AWAYLEN", NULL, AWAYLEN); |
| 149 |
} |
| 150 |
|
| 151 |
static void |
| 152 |
module_exit(void) |
| 153 |
{ |
| 154 |
mod_del_cmd(&away_msgtab); |
| 155 |
isupport_delete("AWAYLEN"); |
| 156 |
} |
| 157 |
|
| 158 |
struct module module_entry = |
| 159 |
{ |
| 160 |
.version = "$Revision$", |
| 161 |
.modinit = module_init, |
| 162 |
.modexit = module_exit, |
| 163 |
}; |