| 1 |
michael |
4545 |
/* |
| 2 |
|
|
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
|
|
* |
| 4 |
michael |
8279 |
* Copyright (c) 2014-2018 ircd-hybrid development team |
| 5 |
michael |
4545 |
* |
| 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 |
michael |
4565 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
| 19 |
michael |
4545 |
* USA |
| 20 |
|
|
*/ |
| 21 |
|
|
|
| 22 |
|
|
/*! \file conf_pseudo.c |
| 23 |
|
|
* \brief Handles with pseudo commands/service aliases. |
| 24 |
michael |
6259 |
* \version $Id$ |
| 25 |
michael |
4545 |
*/ |
| 26 |
|
|
|
| 27 |
|
|
#include "stdinc.h" |
| 28 |
|
|
#include "list.h" |
| 29 |
|
|
#include "client.h" |
| 30 |
|
|
#include "parse.h" |
| 31 |
|
|
#include "hash.h" |
| 32 |
|
|
#include "irc_string.h" |
| 33 |
|
|
#include "ircd.h" |
| 34 |
|
|
#include "numeric.h" |
| 35 |
|
|
#include "send.h" |
| 36 |
|
|
#include "memory.h" |
| 37 |
|
|
#include "user.h" |
| 38 |
|
|
#include "server.h" |
| 39 |
|
|
#include "conf_pseudo.h" |
| 40 |
|
|
|
| 41 |
michael |
7294 |
struct PseudoItem |
| 42 |
michael |
4545 |
{ |
| 43 |
|
|
dlink_node node; |
| 44 |
|
|
struct Message msg; |
| 45 |
|
|
char *name; |
| 46 |
|
|
char *nick; |
| 47 |
|
|
char *serv; |
| 48 |
michael |
7294 |
char *prepend; |
| 49 |
michael |
4545 |
char *command; |
| 50 |
|
|
}; |
| 51 |
|
|
|
| 52 |
michael |
7294 |
static dlink_list pseudo_list; |
| 53 |
michael |
4545 |
|
| 54 |
michael |
7685 |
|
| 55 |
|
|
const dlink_list * |
| 56 |
|
|
pseudo_get_list(void) |
| 57 |
|
|
{ |
| 58 |
|
|
return &pseudo_list; |
| 59 |
|
|
} |
| 60 |
|
|
|
| 61 |
michael |
4545 |
static int |
| 62 |
|
|
m_pseudo(struct Client *source_p, int parc, char *parv[]) |
| 63 |
|
|
{ |
| 64 |
|
|
char buffer[IRCD_BUFSIZE] = ""; |
| 65 |
michael |
7294 |
const struct PseudoItem *const pseudo = (const struct PseudoItem *)parv[1]; |
| 66 |
michael |
4545 |
struct Client *target_p = NULL; |
| 67 |
|
|
struct Client *server_p = NULL; |
| 68 |
|
|
const char *msg = parv[parc - 1]; |
| 69 |
|
|
|
| 70 |
|
|
if (parc < 3 || EmptyString(msg)) |
| 71 |
|
|
{ |
| 72 |
|
|
sendto_one_numeric(source_p, &me, ERR_NOTEXTTOSEND); |
| 73 |
|
|
return 0; |
| 74 |
|
|
} |
| 75 |
|
|
|
| 76 |
michael |
8453 |
if (pseudo->prepend) |
| 77 |
michael |
4545 |
{ |
| 78 |
michael |
7294 |
snprintf(buffer, sizeof(buffer), "%s%s", pseudo->prepend, msg); |
| 79 |
michael |
4545 |
msg = buffer; |
| 80 |
|
|
} |
| 81 |
|
|
|
| 82 |
|
|
target_p = find_person(source_p, pseudo->nick); |
| 83 |
|
|
server_p = hash_find_server(pseudo->serv); |
| 84 |
|
|
|
| 85 |
|
|
if (target_p && server_p && (target_p->servptr == server_p) && !IsMe(server_p)) |
| 86 |
|
|
{ |
| 87 |
|
|
sendto_one(target_p, ":%s PRIVMSG %s :%s", |
| 88 |
|
|
source_p->id, target_p->id, msg); |
| 89 |
|
|
return 0; |
| 90 |
|
|
} |
| 91 |
|
|
|
| 92 |
|
|
sendto_one_numeric(source_p, &me, ERR_SERVICESDOWN, pseudo->name); |
| 93 |
|
|
return 0; |
| 94 |
|
|
} |
| 95 |
|
|
|
| 96 |
|
|
void |
| 97 |
michael |
7294 |
pseudo_register(const char *name, const char *nick, const char *serv, |
| 98 |
|
|
const char *prepend, |
| 99 |
michael |
4545 |
const char *command) |
| 100 |
|
|
{ |
| 101 |
|
|
if (find_command(command)) |
| 102 |
|
|
return; |
| 103 |
|
|
|
| 104 |
michael |
7294 |
struct PseudoItem *pseudo = xcalloc(sizeof(*pseudo)); |
| 105 |
|
|
pseudo->name = xstrdup(name); |
| 106 |
|
|
pseudo->nick = xstrdup(nick); |
| 107 |
|
|
pseudo->serv = xstrdup(serv); |
| 108 |
|
|
pseudo->command = xstrdup(command); |
| 109 |
michael |
8453 |
if (!EmptyString(prepend)) |
| 110 |
|
|
pseudo->prepend = xstrdup(prepend); |
| 111 |
michael |
4545 |
|
| 112 |
michael |
7294 |
pseudo->msg.cmd = pseudo->command; |
| 113 |
|
|
pseudo->msg.args_max = 2; |
| 114 |
|
|
pseudo->msg.flags = MFLG_EXTRA; |
| 115 |
|
|
pseudo->msg.extra = pseudo; |
| 116 |
|
|
pseudo->msg.handlers[UNREGISTERED_HANDLER] = m_unregistered; |
| 117 |
|
|
pseudo->msg.handlers[CLIENT_HANDLER] = m_pseudo; |
| 118 |
|
|
pseudo->msg.handlers[SERVER_HANDLER] = m_ignore; |
| 119 |
|
|
pseudo->msg.handlers[ENCAP_HANDLER] = m_ignore; |
| 120 |
|
|
pseudo->msg.handlers[OPER_HANDLER] = m_pseudo; |
| 121 |
|
|
dlinkAdd(pseudo, &pseudo->node, &pseudo_list); |
| 122 |
michael |
4545 |
|
| 123 |
michael |
7294 |
mod_add_cmd(&pseudo->msg); |
| 124 |
michael |
4545 |
} |
| 125 |
|
|
|
| 126 |
|
|
void |
| 127 |
|
|
pseudo_clear(void) |
| 128 |
|
|
{ |
| 129 |
michael |
7294 |
while (pseudo_list.head) |
| 130 |
michael |
4545 |
{ |
| 131 |
michael |
7294 |
struct PseudoItem *pseudo = pseudo_list.head->data; |
| 132 |
|
|
assert(find_command(pseudo->msg.cmd)); |
| 133 |
michael |
4545 |
|
| 134 |
michael |
7294 |
mod_del_cmd(&pseudo->msg); |
| 135 |
|
|
dlinkDelete(&pseudo->node, &pseudo_list); |
| 136 |
michael |
4545 |
|
| 137 |
michael |
7294 |
xfree(pseudo->name); |
| 138 |
|
|
xfree(pseudo->nick); |
| 139 |
|
|
xfree(pseudo->serv); |
| 140 |
|
|
xfree(pseudo->prepend); |
| 141 |
|
|
xfree(pseudo->command); |
| 142 |
|
|
xfree(pseudo); |
| 143 |
michael |
4545 |
} |
| 144 |
|
|
} |
| 145 |
michael |
8453 |
|
| 146 |
|
|
void |
| 147 |
|
|
pseudo_stats(struct Client *source_p) |
| 148 |
|
|
{ |
| 149 |
|
|
dlink_node *node; |
| 150 |
|
|
|
| 151 |
|
|
DLINK_FOREACH(node, pseudo_list.head) |
| 152 |
|
|
{ |
| 153 |
|
|
struct PseudoItem *pseudo = node->data; |
| 154 |
|
|
sendto_one_numeric(source_p, &me, RPL_STATSPSEUDO, pseudo->command, |
| 155 |
|
|
pseudo->name, pseudo->nick, pseudo->serv, |
| 156 |
|
|
pseudo->prepend ? pseudo->prepend : "*"); |
| 157 |
|
|
} |
| 158 |
|
|
} |