| 1 |
/* |
| 2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
* |
| 4 |
* Copyright (c) 1997-2014 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 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 "s_serv.h" |
| 37 |
#include "packet.h" |
| 38 |
#include "s_user.h" |
| 39 |
|
| 40 |
|
| 41 |
/* |
| 42 |
* m_away |
| 43 |
* parv[0] = command |
| 44 |
* parv[1] = away message |
| 45 |
*/ |
| 46 |
static int |
| 47 |
m_away(struct Client *client_p, struct Client *source_p, |
| 48 |
int parc, char *parv[]) |
| 49 |
{ |
| 50 |
if (!IsFloodDone(source_p)) |
| 51 |
flood_endgrace(source_p); |
| 52 |
|
| 53 |
if (parc < 2 || EmptyString(parv[1])) |
| 54 |
{ |
| 55 |
/* Marking as not away */ |
| 56 |
if (source_p->away[0]) |
| 57 |
{ |
| 58 |
source_p->away[0] = '\0'; |
| 59 |
/* we now send this only if they were away before --is */ |
| 60 |
sendto_server(client_p, NOCAPS, NOCAPS, ":%s AWAY", ID(source_p)); |
| 61 |
sendto_common_channels_local(source_p, 1, CAP_AWAY_NOTIFY, |
| 62 |
":%s!%s@%s AWAY", |
| 63 |
source_p->name, source_p->username, |
| 64 |
source_p->host); |
| 65 |
} |
| 66 |
|
| 67 |
sendto_one_numeric(source_p, &me, RPL_UNAWAY); |
| 68 |
return 0; |
| 69 |
} |
| 70 |
|
| 71 |
if ((CurrentTime - source_p->localClient->last_away) < ConfigFileEntry.pace_wait) |
| 72 |
{ |
| 73 |
sendto_one_numeric(source_p, &me, RPL_LOAD2HI); |
| 74 |
return 0; |
| 75 |
} |
| 76 |
|
| 77 |
source_p->localClient->last_away = CurrentTime; |
| 78 |
sendto_one_numeric(source_p, &me, RPL_NOWAWAY); |
| 79 |
|
| 80 |
if (!strncmp(source_p->away, parv[1], sizeof(source_p->away) - 1)) |
| 81 |
return 0; |
| 82 |
|
| 83 |
strlcpy(source_p->away, parv[1], sizeof(source_p->away)); |
| 84 |
|
| 85 |
sendto_common_channels_local(source_p, 1, CAP_AWAY_NOTIFY, |
| 86 |
":%s!%s@%s AWAY :%s", |
| 87 |
source_p->name, source_p->username, |
| 88 |
source_p->host, source_p->away); |
| 89 |
sendto_server(client_p, NOCAPS, NOCAPS, ":%s AWAY :%s", |
| 90 |
ID(source_p), source_p->away); |
| 91 |
return 0; |
| 92 |
} |
| 93 |
|
| 94 |
static int |
| 95 |
ms_away(struct Client *client_p, struct Client *source_p, |
| 96 |
int parc, char *parv[]) |
| 97 |
{ |
| 98 |
if (parc < 2 || EmptyString(parv[1])) |
| 99 |
{ |
| 100 |
/* Marking as not away */ |
| 101 |
if (source_p->away[0]) |
| 102 |
{ |
| 103 |
source_p->away[0] = '\0'; |
| 104 |
/* we now send this only if they were away before --is */ |
| 105 |
sendto_server(client_p, NOCAPS, NOCAPS, ":%s AWAY", ID(source_p)); |
| 106 |
sendto_common_channels_local(source_p, 1, CAP_AWAY_NOTIFY, |
| 107 |
":%s!%s@%s AWAY", |
| 108 |
source_p->name, source_p->username, |
| 109 |
source_p->host); |
| 110 |
} |
| 111 |
|
| 112 |
return 0; |
| 113 |
} |
| 114 |
|
| 115 |
if (!strncmp(source_p->away, parv[1], sizeof(source_p->away) - 1)) |
| 116 |
return 0; |
| 117 |
|
| 118 |
strlcpy(source_p->away, parv[1], sizeof(source_p->away)); |
| 119 |
|
| 120 |
sendto_common_channels_local(source_p, 1, CAP_AWAY_NOTIFY, |
| 121 |
":%s!%s@%s AWAY :%s", |
| 122 |
source_p->name, source_p->username, |
| 123 |
source_p->host, source_p->away); |
| 124 |
sendto_server(client_p, NOCAPS, NOCAPS, ":%s AWAY :%s", |
| 125 |
ID(source_p), source_p->away); |
| 126 |
return 0; |
| 127 |
} |
| 128 |
|
| 129 |
static struct Message away_msgtab = |
| 130 |
{ |
| 131 |
"AWAY", 0, 0, 0, MAXPARA, MFLG_SLOW, 0, |
| 132 |
{ m_unregistered, m_away, ms_away, m_ignore, m_away, m_ignore } |
| 133 |
}; |
| 134 |
|
| 135 |
static void |
| 136 |
module_init(void) |
| 137 |
{ |
| 138 |
mod_add_cmd(&away_msgtab); |
| 139 |
add_isupport("AWAYLEN", NULL, AWAYLEN); |
| 140 |
} |
| 141 |
|
| 142 |
static void |
| 143 |
module_exit(void) |
| 144 |
{ |
| 145 |
mod_del_cmd(&away_msgtab); |
| 146 |
delete_isupport("AWAYLEN"); |
| 147 |
} |
| 148 |
|
| 149 |
struct module module_entry = |
| 150 |
{ |
| 151 |
.node = { NULL, NULL, NULL }, |
| 152 |
.name = NULL, |
| 153 |
.version = "$Revision$", |
| 154 |
.handle = NULL, |
| 155 |
.modinit = module_init, |
| 156 |
.modexit = module_exit, |
| 157 |
.flags = 0 |
| 158 |
}; |