/[svn]/ircd-hybrid/branches/8.2.x/modules/m_svsnick.c
ViewVC logotype

Contents of /ircd-hybrid/branches/8.2.x/modules/m_svsnick.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 7854 - (show annotations)
Sun Nov 6 20:57:44 2016 UTC (4 years ago) by michael
File MIME type: text/x-chdr
File size: 4993 byte(s)
- m_svsnick.c: add source ts support

1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1999 Bahamut development team.
5 * Copyright (c) 2011-2016 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] = old timestampt
54 * - parv[3] = new nickname
55 * - parv[4] = new timestamp
56 */
57 static int
58 ms_svsnick(struct Client *source_p, int parc, char *parv[])
59 {
60 struct Client *target_p = NULL, *exists_p = NULL;
61 const char *new_nick = parc == 5 ? parv[3] : parv[2]; /* TBR: compatibility mode */
62 uintmax_t ts = 0, new_ts = 0;
63
64 if (!HasFlag(source_p, FLAGS_SERVICE))
65 return 0;
66
67 if (!valid_nickname(new_nick, 1))
68 return 0;
69
70 if ((target_p = find_person(source_p, parv[1])) == NULL)
71 return 0;
72
73 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 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 get_client_name(source_p, HIDE_IP));
96 return 0;
97 }
98
99 sendto_one(target_p, ":%s SVSNICK %s %s %s", source_p->id,
100 target_p->id, new_nick, parv[3]);
101 return 0;
102 }
103
104 if ((exists_p = hash_find_client(new_nick)))
105 {
106 if (target_p == exists_p)
107 {
108 if (!strcmp(target_p->name, new_nick))
109 return 0;
110 }
111 else if (IsUnknown(exists_p))
112 exit_client(exists_p, "SVSNICK Override");
113 else
114 {
115 exit_client(target_p, "SVSNICK Collide");
116 return 0;
117 }
118 }
119
120 target_p->tsinfo = new_ts;
121 clear_ban_cache_list(&target_p->channel);
122 watch_check_hash(target_p, RPL_LOGOFF);
123
124 if (HasUMode(target_p, UMODE_REGISTERED))
125 {
126 const unsigned int oldmodes = target_p->umodes;
127 char modebuf[IRCD_BUFSIZE] = "";
128
129 DelUMode(target_p, UMODE_REGISTERED);
130 send_umode(target_p, 1, oldmodes, modebuf);
131 }
132
133 sendto_common_channels_local(target_p, 1, 0, 0, ":%s!%s@%s NICK :%s",
134 target_p->name, target_p->username,
135 target_p->host, new_nick);
136
137 whowas_add_history(target_p, 1);
138
139 sendto_server(NULL, 0, 0, ":%s NICK %s :%ju",
140 target_p->id, new_nick, target_p->tsinfo);
141 hash_del_client(target_p);
142 strlcpy(target_p->name, new_nick, sizeof(target_p->name));
143 hash_add_client(target_p);
144
145 watch_check_hash(target_p, RPL_LOGON);
146
147 fd_note(&target_p->connection->fd, "Nick: %s", target_p->name);
148 return 0;
149 }
150
151 static struct Message svsnick_msgtab =
152 {
153 .cmd = "SVSNICK",
154 .args_min = 4,
155 .args_max = MAXPARA,
156 .handlers[UNREGISTERED_HANDLER] = m_ignore,
157 .handlers[CLIENT_HANDLER] = m_ignore,
158 .handlers[SERVER_HANDLER] = ms_svsnick,
159 .handlers[ENCAP_HANDLER] = m_ignore,
160 .handlers[OPER_HANDLER] = m_ignore
161 };
162
163 static void
164 module_init(void)
165 {
166 mod_add_cmd(&svsnick_msgtab);
167 }
168
169 static void
170 module_exit(void)
171 {
172 mod_del_cmd(&svsnick_msgtab);
173 }
174
175 struct module module_entry =
176 {
177 .version = "$Revision$",
178 .modinit = module_init,
179 .modexit = module_exit,
180 };

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28