| 1 |
michael |
1165 |
/* |
| 2 |
michael |
2820 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
michael |
1165 |
* |
| 4 |
michael |
2820 |
* Copyright (c) 1999 Bahamut development team. |
| 5 |
michael |
8279 |
* Copyright (c) 2011-2018 ircd-hybrid development team |
| 6 |
michael |
1165 |
* |
| 7 |
|
|
* This program is free software; you can redistribute it and/or modify |
| 8 |
|
|
* it under the terms of the GNU General Public License as published by |
| 9 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
| 10 |
|
|
* (at your option) any later version. |
| 11 |
|
|
* |
| 12 |
|
|
* This program is distributed in the hope that it will be useful, |
| 13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
|
|
* GNU General Public License for more details. |
| 16 |
|
|
* |
| 17 |
|
|
* You should have received a copy of the GNU General Public License |
| 18 |
|
|
* along with this program; if not, write to the Free Software |
| 19 |
michael |
4565 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
| 20 |
michael |
1165 |
* USA |
| 21 |
|
|
*/ |
| 22 |
|
|
|
| 23 |
|
|
/*! \file m_svsnick.c |
| 24 |
michael |
1221 |
* \brief Includes required functions for processing the SVSNICK command. |
| 25 |
michael |
1165 |
* \version $Id$ |
| 26 |
|
|
*/ |
| 27 |
|
|
|
| 28 |
michael |
2820 |
|
| 29 |
michael |
1165 |
#include "stdinc.h" |
| 30 |
|
|
#include "client.h" |
| 31 |
|
|
#include "ircd.h" |
| 32 |
|
|
#include "channel_mode.h" |
| 33 |
|
|
#include "send.h" |
| 34 |
|
|
#include "parse.h" |
| 35 |
|
|
#include "modules.h" |
| 36 |
|
|
#include "irc_string.h" |
| 37 |
michael |
3347 |
#include "user.h" |
| 38 |
michael |
1165 |
#include "hash.h" |
| 39 |
|
|
#include "watch.h" |
| 40 |
|
|
#include "whowas.h" |
| 41 |
|
|
|
| 42 |
|
|
|
| 43 |
michael |
3300 |
/*! \brief SVSNICK command handler |
| 44 |
michael |
1165 |
* |
| 45 |
|
|
* \param source_p Pointer to allocated Client struct from which the message |
| 46 |
|
|
* originally comes from. This can be a local or remote client. |
| 47 |
|
|
* \param parc Integer holding the number of supplied arguments. |
| 48 |
|
|
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
| 49 |
|
|
* pointers. |
| 50 |
|
|
* \note Valid arguments for this command are: |
| 51 |
michael |
3096 |
* - parv[0] = command |
| 52 |
michael |
1165 |
* - parv[1] = old nickname |
| 53 |
michael |
7856 |
* - parv[2] = old timestamp |
| 54 |
michael |
7855 |
* - parv[3] = new nickname |
| 55 |
|
|
* - parv[4] = new timestamp |
| 56 |
michael |
1165 |
*/ |
| 57 |
michael |
2820 |
static int |
| 58 |
michael |
3156 |
ms_svsnick(struct Client *source_p, int parc, char *parv[]) |
| 59 |
michael |
1165 |
{ |
| 60 |
|
|
struct Client *target_p = NULL, *exists_p = NULL; |
| 61 |
michael |
7855 |
const char *new_nick = parc == 5 ? parv[3] : parv[2]; /* TBR: compatibility mode */ |
| 62 |
|
|
uintmax_t ts = 0, new_ts = 0; |
| 63 |
michael |
1165 |
|
| 64 |
michael |
7469 |
if (!HasFlag(source_p, FLAGS_SERVICE)) |
| 65 |
michael |
2820 |
return 0; |
| 66 |
michael |
1165 |
|
| 67 |
michael |
8660 |
if (valid_nickname(new_nick, true) == false) |
| 68 |
michael |
7469 |
return 0; |
| 69 |
|
|
|
| 70 |
michael |
3967 |
if ((target_p = find_person(source_p, parv[1])) == NULL) |
| 71 |
michael |
2820 |
return 0; |
| 72 |
michael |
1165 |
|
| 73 |
michael |
7855 |
if (parc == 5) /* TBR: compatibility mode */ |
| 74 |
|
|
{ |
| 75 |
|
|
ts = strtoumax(parv[2], NULL, 10); |
| 76 |
|
|
if (ts && (ts != target_p->tsinfo)) |
| 77 |
|
|
return 0; |
| 78 |
|
|
} |
| 79 |
|
|
else /* parc == 4 */ |
| 80 |
|
|
ts = strtoumax(parv[3], NULL, 10); |
| 81 |
|
|
|
| 82 |
|
|
if (parc == 4) /* TBR: compatibility mode */ |
| 83 |
|
|
new_ts = ts; |
| 84 |
|
|
else |
| 85 |
|
|
new_ts = strtoumax(parv[4], NULL, 10); |
| 86 |
|
|
|
| 87 |
michael |
3967 |
if (!MyConnect(target_p)) |
| 88 |
|
|
{ |
| 89 |
|
|
if (target_p->from == source_p->from) |
| 90 |
|
|
{ |
| 91 |
|
|
sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE, |
| 92 |
|
|
"Received wrong-direction SVSNICK " |
| 93 |
|
|
"for %s (behind %s) from %s", |
| 94 |
|
|
target_p->name, source_p->from->name, |
| 95 |
michael |
7997 |
client_get_name(source_p, HIDE_IP)); |
| 96 |
michael |
3967 |
return 0; |
| 97 |
|
|
} |
| 98 |
|
|
|
| 99 |
|
|
sendto_one(target_p, ":%s SVSNICK %s %s %s", source_p->id, |
| 100 |
michael |
7855 |
target_p->id, new_nick, parv[3]); |
| 101 |
michael |
2820 |
return 0; |
| 102 |
michael |
3967 |
} |
| 103 |
michael |
1165 |
|
| 104 |
michael |
7855 |
if ((exists_p = hash_find_client(new_nick))) |
| 105 |
michael |
1165 |
{ |
| 106 |
michael |
3138 |
if (target_p == exists_p) |
| 107 |
|
|
{ |
| 108 |
michael |
8603 |
if (strcmp(target_p->name, new_nick) == 0) |
| 109 |
michael |
3138 |
return 0; |
| 110 |
|
|
} |
| 111 |
|
|
else if (IsUnknown(exists_p)) |
| 112 |
michael |
3171 |
exit_client(exists_p, "SVSNICK Override"); |
| 113 |
michael |
1165 |
else |
| 114 |
|
|
{ |
| 115 |
michael |
3171 |
exit_client(target_p, "SVSNICK Collide"); |
| 116 |
michael |
2820 |
return 0; |
| 117 |
michael |
1165 |
} |
| 118 |
|
|
} |
| 119 |
|
|
|
| 120 |
michael |
7855 |
target_p->tsinfo = new_ts; |
| 121 |
michael |
7764 |
clear_ban_cache_list(&target_p->channel); |
| 122 |
michael |
1165 |
watch_check_hash(target_p, RPL_LOGOFF); |
| 123 |
|
|
|
| 124 |
|
|
if (HasUMode(target_p, UMODE_REGISTERED)) |
| 125 |
|
|
{ |
| 126 |
michael |
5548 |
const unsigned int oldmodes = target_p->umodes; |
| 127 |
michael |
3246 |
char modebuf[IRCD_BUFSIZE] = ""; |
| 128 |
michael |
1165 |
|
| 129 |
|
|
DelUMode(target_p, UMODE_REGISTERED); |
| 130 |
michael |
8658 |
send_umode(target_p, true, oldmodes, modebuf); |
| 131 |
michael |
1165 |
} |
| 132 |
|
|
|
| 133 |
michael |
8688 |
sendto_common_channels_local(target_p, true, 0, 0, ":%s!%s@%s NICK :%s", |
| 134 |
michael |
1165 |
target_p->name, target_p->username, |
| 135 |
michael |
7855 |
target_p->host, new_nick); |
| 136 |
michael |
1165 |
|
| 137 |
michael |
8664 |
whowas_add_history(target_p, true); |
| 138 |
michael |
1165 |
|
| 139 |
michael |
6782 |
sendto_server(NULL, 0, 0, ":%s NICK %s :%ju", |
| 140 |
michael |
7855 |
target_p->id, new_nick, target_p->tsinfo); |
| 141 |
michael |
8059 |
|
| 142 |
michael |
1165 |
hash_del_client(target_p); |
| 143 |
michael |
7855 |
strlcpy(target_p->name, new_nick, sizeof(target_p->name)); |
| 144 |
michael |
1165 |
hash_add_client(target_p); |
| 145 |
|
|
|
| 146 |
|
|
watch_check_hash(target_p, RPL_LOGON); |
| 147 |
|
|
|
| 148 |
michael |
8339 |
fd_note(target_p->connection->fd, "Nick: %s", target_p->name); |
| 149 |
michael |
2820 |
return 0; |
| 150 |
michael |
1165 |
} |
| 151 |
michael |
1230 |
|
| 152 |
michael |
2820 |
static struct Message svsnick_msgtab = |
| 153 |
|
|
{ |
| 154 |
michael |
5881 |
.cmd = "SVSNICK", |
| 155 |
|
|
.args_min = 4, |
| 156 |
|
|
.args_max = MAXPARA, |
| 157 |
|
|
.handlers[UNREGISTERED_HANDLER] = m_ignore, |
| 158 |
|
|
.handlers[CLIENT_HANDLER] = m_ignore, |
| 159 |
|
|
.handlers[SERVER_HANDLER] = ms_svsnick, |
| 160 |
|
|
.handlers[ENCAP_HANDLER] = m_ignore, |
| 161 |
|
|
.handlers[OPER_HANDLER] = m_ignore |
| 162 |
michael |
1230 |
}; |
| 163 |
|
|
|
| 164 |
|
|
static void |
| 165 |
|
|
module_init(void) |
| 166 |
|
|
{ |
| 167 |
|
|
mod_add_cmd(&svsnick_msgtab); |
| 168 |
|
|
} |
| 169 |
|
|
|
| 170 |
|
|
static void |
| 171 |
|
|
module_exit(void) |
| 172 |
|
|
{ |
| 173 |
|
|
mod_del_cmd(&svsnick_msgtab); |
| 174 |
|
|
} |
| 175 |
|
|
|
| 176 |
michael |
2820 |
struct module module_entry = |
| 177 |
|
|
{ |
| 178 |
michael |
1230 |
.version = "$Revision$", |
| 179 |
|
|
.modinit = module_init, |
| 180 |
|
|
.modexit = module_exit, |
| 181 |
|
|
}; |