1 |
/* |
2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
* |
4 |
* Copyright (c) 1999 Bahamut development team. |
5 |
* Copyright (c) 2011-2015 ircd-hybrid development team |
6 |
* |
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 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
20 |
* USA |
21 |
*/ |
22 |
|
23 |
/*! \file m_svsnick.c |
24 |
* \brief Includes required functions for processing the SVSNICK command. |
25 |
* \version $Id$ |
26 |
*/ |
27 |
|
28 |
|
29 |
#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 |
#include "user.h" |
38 |
#include "hash.h" |
39 |
#include "watch.h" |
40 |
#include "whowas.h" |
41 |
|
42 |
|
43 |
/*! \brief SVSNICK command handler |
44 |
* |
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 |
* - parv[0] = command |
52 |
* - parv[1] = old nickname |
53 |
* - parv[2] = new nickname |
54 |
* - parv[3] = timestamp |
55 |
*/ |
56 |
static int |
57 |
ms_svsnick(struct Client *source_p, int parc, char *parv[]) |
58 |
{ |
59 |
struct Client *target_p = NULL, *exists_p = NULL; |
60 |
|
61 |
if (!HasFlag(source_p, FLAGS_SERVICE) || !valid_nickname(parv[2], 1)) |
62 |
return 0; |
63 |
|
64 |
if ((target_p = find_person(source_p, parv[1])) == NULL) |
65 |
return 0; |
66 |
|
67 |
if (!MyConnect(target_p)) |
68 |
{ |
69 |
if (target_p->from == source_p->from) |
70 |
{ |
71 |
sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE, |
72 |
"Received wrong-direction SVSNICK " |
73 |
"for %s (behind %s) from %s", |
74 |
target_p->name, source_p->from->name, |
75 |
get_client_name(source_p, HIDE_IP)); |
76 |
return 0; |
77 |
} |
78 |
|
79 |
sendto_one(target_p, ":%s SVSNICK %s %s %s", source_p->id, |
80 |
target_p->id, parv[2], parv[3]); |
81 |
return 0; |
82 |
} |
83 |
|
84 |
if ((exists_p = hash_find_client(parv[2]))) |
85 |
{ |
86 |
if (target_p == exists_p) |
87 |
{ |
88 |
if (!strcmp(target_p->name, parv[2])) |
89 |
return 0; |
90 |
} |
91 |
else if (IsUnknown(exists_p)) |
92 |
exit_client(exists_p, "SVSNICK Override"); |
93 |
else |
94 |
{ |
95 |
exit_client(target_p, "SVSNICK Collide"); |
96 |
return 0; |
97 |
} |
98 |
} |
99 |
|
100 |
target_p->tsinfo = atoi(parv[3]); |
101 |
clear_ban_cache_client(target_p); |
102 |
watch_check_hash(target_p, RPL_LOGOFF); |
103 |
|
104 |
if (HasUMode(target_p, UMODE_REGISTERED)) |
105 |
{ |
106 |
const unsigned int oldmodes = target_p->umodes; |
107 |
char modebuf[IRCD_BUFSIZE] = ""; |
108 |
|
109 |
DelUMode(target_p, UMODE_REGISTERED); |
110 |
send_umode(target_p, target_p, oldmodes, modebuf); |
111 |
} |
112 |
|
113 |
sendto_common_channels_local(target_p, 1, 0, ":%s!%s@%s NICK :%s", |
114 |
target_p->name, target_p->username, |
115 |
target_p->host, parv[2]); |
116 |
|
117 |
whowas_add_history(target_p, 1); |
118 |
|
119 |
sendto_server(NULL, 0, 0, ":%s NICK %s :%lu", |
120 |
target_p->id, parv[2], (unsigned long)target_p->tsinfo); |
121 |
hash_del_client(target_p); |
122 |
strlcpy(target_p->name, parv[2], sizeof(target_p->name)); |
123 |
hash_add_client(target_p); |
124 |
|
125 |
watch_check_hash(target_p, RPL_LOGON); |
126 |
|
127 |
fd_note(&target_p->connection->fd, "Nick: %s", parv[2]); |
128 |
return 0; |
129 |
} |
130 |
|
131 |
static struct Message svsnick_msgtab = |
132 |
{ |
133 |
.cmd = "SVSNICK", |
134 |
.args_min = 4, |
135 |
.args_max = MAXPARA, |
136 |
.handlers[UNREGISTERED_HANDLER] = m_ignore, |
137 |
.handlers[CLIENT_HANDLER] = m_ignore, |
138 |
.handlers[SERVER_HANDLER] = ms_svsnick, |
139 |
.handlers[ENCAP_HANDLER] = m_ignore, |
140 |
.handlers[OPER_HANDLER] = m_ignore |
141 |
}; |
142 |
|
143 |
static void |
144 |
module_init(void) |
145 |
{ |
146 |
mod_add_cmd(&svsnick_msgtab); |
147 |
} |
148 |
|
149 |
static void |
150 |
module_exit(void) |
151 |
{ |
152 |
mod_del_cmd(&svsnick_msgtab); |
153 |
} |
154 |
|
155 |
struct module module_entry = |
156 |
{ |
157 |
.version = "$Revision$", |
158 |
.modinit = module_init, |
159 |
.modexit = module_exit, |
160 |
}; |