| 1 |
/* |
| 2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
* |
| 4 |
* Copyright (c) 1997-2017 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_ison.c |
| 23 |
* \brief Includes required functions for processing the ISON 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 |
|
| 36 |
|
| 37 |
/*! \brief ISON 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] = space-separated list of nicknames |
| 47 |
*/ |
| 48 |
static int |
| 49 |
m_ison(struct Client *source_p, int parc, char *parv[]) |
| 50 |
{ |
| 51 |
char *nick; |
| 52 |
char *p = NULL; |
| 53 |
char *current_insert_point = NULL; |
| 54 |
char buf[IRCD_BUFSIZE]; |
| 55 |
int len, cut = 0; |
| 56 |
|
| 57 |
len = snprintf(buf, sizeof(buf), numeric_form(RPL_ISON), me.name, source_p->name); |
| 58 |
current_insert_point = buf + len; |
| 59 |
|
| 60 |
for (nick = strtok_r(parv[1], " ", &p); nick; |
| 61 |
nick = strtok_r(NULL, " ", &p)) |
| 62 |
{ |
| 63 |
const struct Client *target_p = find_person(source_p, nick); |
| 64 |
if (target_p) |
| 65 |
{ |
| 66 |
len = strlen(target_p->name); |
| 67 |
|
| 68 |
if ((current_insert_point + (len + 5)) < (buf + sizeof(buf))) |
| 69 |
{ |
| 70 |
cut = 1; |
| 71 |
strlcpy(current_insert_point, target_p->name, len + 1); |
| 72 |
current_insert_point += len; |
| 73 |
*current_insert_point++ = ' '; |
| 74 |
} |
| 75 |
else |
| 76 |
break; |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
*(current_insert_point - cut) = '\0'; |
| 81 |
|
| 82 |
sendto_one(source_p, "%s", buf); |
| 83 |
return 0; |
| 84 |
} |
| 85 |
|
| 86 |
static struct Message ison_msgtab = |
| 87 |
{ |
| 88 |
.cmd = "ISON", |
| 89 |
.args_min = 2, |
| 90 |
.args_max = 1, |
| 91 |
.handlers[UNREGISTERED_HANDLER] = m_unregistered, |
| 92 |
.handlers[CLIENT_HANDLER] = m_ison, |
| 93 |
.handlers[SERVER_HANDLER] = m_ignore, |
| 94 |
.handlers[ENCAP_HANDLER] = m_ignore, |
| 95 |
.handlers[OPER_HANDLER] = m_ison |
| 96 |
}; |
| 97 |
|
| 98 |
static void |
| 99 |
module_init(void) |
| 100 |
{ |
| 101 |
mod_add_cmd(&ison_msgtab); |
| 102 |
} |
| 103 |
|
| 104 |
static void |
| 105 |
module_exit(void) |
| 106 |
{ |
| 107 |
mod_del_cmd(&ison_msgtab); |
| 108 |
} |
| 109 |
|
| 110 |
struct module module_entry = |
| 111 |
{ |
| 112 |
.version = "$Revision$", |
| 113 |
.modinit = module_init, |
| 114 |
.modexit = module_exit, |
| 115 |
}; |