| 1 |
adx |
30 |
/* |
| 2 |
|
|
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
| 3 |
|
|
* m_nick.c: Sets a users nick. |
| 4 |
|
|
* |
| 5 |
|
|
* Copyright (C) 2002 by the past and present ircd coders, and others. |
| 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 20 |
|
|
* USA |
| 21 |
|
|
* |
| 22 |
knight |
31 |
* $Id$ |
| 23 |
adx |
30 |
*/ |
| 24 |
|
|
|
| 25 |
|
|
#include "stdinc.h" |
| 26 |
michael |
1011 |
#include "list.h" |
| 27 |
adx |
30 |
#include "client.h" |
| 28 |
|
|
#include "hash.h" |
| 29 |
|
|
#include "fdlist.h" |
| 30 |
|
|
#include "irc_string.h" |
| 31 |
|
|
#include "ircd.h" |
| 32 |
|
|
#include "numeric.h" |
| 33 |
michael |
1309 |
#include "conf.h" |
| 34 |
adx |
30 |
#include "s_user.h" |
| 35 |
|
|
#include "whowas.h" |
| 36 |
|
|
#include "s_serv.h" |
| 37 |
|
|
#include "send.h" |
| 38 |
|
|
#include "channel.h" |
| 39 |
michael |
1192 |
#include "channel_mode.h" |
| 40 |
michael |
1309 |
#include "log.h" |
| 41 |
adx |
30 |
#include "resv.h" |
| 42 |
|
|
#include "parse.h" |
| 43 |
|
|
#include "modules.h" |
| 44 |
|
|
#include "packet.h" |
| 45 |
michael |
876 |
#include "watch.h" |
| 46 |
michael |
1751 |
#include "s_misc.h" |
| 47 |
adx |
30 |
|
| 48 |
|
|
|
| 49 |
|
|
static void nick_from_server(struct Client *, struct Client *, int, char **, |
| 50 |
michael |
1559 |
time_t, const char *, char *, char *); |
| 51 |
michael |
981 |
static void uid_from_server(struct Client *, struct Client *, int, char **, |
| 52 |
michael |
1559 |
time_t, const char *, char *, char *); |
| 53 |
adx |
30 |
static int check_clean_nick(struct Client *client_p, struct Client *source_p, |
| 54 |
michael |
981 |
char *nick, struct Client *server_p); |
| 55 |
adx |
30 |
static int check_clean_user(struct Client *client_p, char *nick, char *user, |
| 56 |
|
|
struct Client *server_p); |
| 57 |
|
|
static int check_clean_host(struct Client *client_p, char *nick, char *host, |
| 58 |
|
|
struct Client *server_p); |
| 59 |
|
|
|
| 60 |
michael |
981 |
static int clean_user_name(const char *); |
| 61 |
adx |
30 |
static void perform_nick_collides(struct Client *, struct Client *, struct Client *, |
| 62 |
michael |
1559 |
int, char **, time_t, const char *, char *, char *, char *); |
| 63 |
adx |
30 |
|
| 64 |
|
|
|
| 65 |
michael |
1002 |
/* set_initial_nick() |
| 66 |
|
|
* |
| 67 |
|
|
* inputs |
| 68 |
|
|
* output |
| 69 |
|
|
* side effects - |
| 70 |
|
|
* |
| 71 |
|
|
* This function is only called to set up an initially registering |
| 72 |
|
|
* client. |
| 73 |
|
|
*/ |
| 74 |
|
|
static void |
| 75 |
michael |
1003 |
set_initial_nick(struct Client *source_p, const char *nick) |
| 76 |
michael |
1002 |
{ |
| 77 |
|
|
/* Client setting NICK the first time */ |
| 78 |
|
|
|
| 79 |
|
|
/* This had to be copied here to avoid problems.. */ |
| 80 |
|
|
source_p->tsinfo = CurrentTime; |
| 81 |
|
|
source_p->localClient->registration &= ~REG_NEED_NICK; |
| 82 |
|
|
|
| 83 |
|
|
if (source_p->name[0]) |
| 84 |
|
|
hash_del_client(source_p); |
| 85 |
|
|
|
| 86 |
|
|
strlcpy(source_p->name, nick, sizeof(source_p->name)); |
| 87 |
|
|
hash_add_client(source_p); |
| 88 |
|
|
|
| 89 |
|
|
/* fd_desc is long enough */ |
| 90 |
michael |
1003 |
fd_note(&source_p->localClient->fd, "Nick: %s", nick); |
| 91 |
michael |
1002 |
|
| 92 |
|
|
if (!source_p->localClient->registration) |
| 93 |
michael |
1080 |
register_local_user(source_p); |
| 94 |
michael |
1002 |
} |
| 95 |
|
|
|
| 96 |
michael |
1192 |
/* change_local_nick() |
| 97 |
|
|
* |
| 98 |
|
|
* inputs - pointer to server |
| 99 |
|
|
* - pointer to client |
| 100 |
|
|
* - nick |
| 101 |
|
|
* output - |
| 102 |
|
|
* side effects - changes nick of a LOCAL user |
| 103 |
|
|
*/ |
| 104 |
|
|
static void |
| 105 |
michael |
1193 |
change_local_nick(struct Client *source_p, const char *nick) |
| 106 |
michael |
1192 |
{ |
| 107 |
|
|
assert(source_p->name[0] && !EmptyString(nick)); |
| 108 |
michael |
1193 |
assert(MyConnect(source_p)); |
| 109 |
michael |
1192 |
|
| 110 |
|
|
/* |
| 111 |
|
|
* Client just changing his/her nick. If he/she is |
| 112 |
|
|
* on a channel, send note of change to all clients |
| 113 |
|
|
* on that channel. Propagate notice to other servers. |
| 114 |
|
|
*/ |
| 115 |
|
|
if ((source_p->localClient->last_nick_change + |
| 116 |
|
|
ConfigFileEntry.max_nick_time) < CurrentTime) |
| 117 |
|
|
source_p->localClient->number_of_nick_changes = 0; |
| 118 |
|
|
source_p->localClient->last_nick_change = CurrentTime; |
| 119 |
|
|
source_p->localClient->number_of_nick_changes++; |
| 120 |
|
|
|
| 121 |
|
|
if ((ConfigFileEntry.anti_nick_flood && |
| 122 |
|
|
(source_p->localClient->number_of_nick_changes |
| 123 |
|
|
<= ConfigFileEntry.max_nick_changes)) || |
| 124 |
|
|
!ConfigFileEntry.anti_nick_flood || |
| 125 |
michael |
1219 |
(HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.no_oper_flood)) |
| 126 |
michael |
1192 |
{ |
| 127 |
michael |
1193 |
int samenick = !irccmp(source_p->name, nick); |
| 128 |
michael |
1192 |
|
| 129 |
|
|
if (!samenick) |
| 130 |
|
|
{ |
| 131 |
|
|
source_p->tsinfo = CurrentTime; |
| 132 |
|
|
clear_ban_cache_client(source_p); |
| 133 |
|
|
watch_check_hash(source_p, RPL_LOGOFF); |
| 134 |
|
|
|
| 135 |
|
|
if (HasUMode(source_p, UMODE_REGISTERED)) |
| 136 |
|
|
{ |
| 137 |
|
|
unsigned int oldmodes = source_p->umodes; |
| 138 |
|
|
char modebuf[IRCD_BUFSIZE] = { '\0' }; |
| 139 |
|
|
|
| 140 |
|
|
DelUMode(source_p, UMODE_REGISTERED); |
| 141 |
|
|
send_umode(source_p, source_p, oldmodes, 0xffffffff, modebuf); |
| 142 |
|
|
} |
| 143 |
|
|
} |
| 144 |
|
|
|
| 145 |
|
|
/* XXX - the format of this notice should eventually be changed |
| 146 |
|
|
* to either %s[%s@%s], or even better would be get_client_name() -bill |
| 147 |
|
|
*/ |
| 148 |
michael |
1618 |
sendto_realops_flags(UMODE_NCHANGE, L_ALL, SEND_NOTICE, |
| 149 |
|
|
"Nick change: From %s to %s [%s@%s]", |
| 150 |
michael |
1192 |
source_p->name, nick, source_p->username, source_p->host); |
| 151 |
michael |
1734 |
sendto_common_channels_local(source_p, 1, 0, ":%s!%s@%s NICK :%s", |
| 152 |
michael |
1192 |
source_p->name, source_p->username, |
| 153 |
|
|
source_p->host, nick); |
| 154 |
|
|
add_history(source_p, 1); |
| 155 |
|
|
|
| 156 |
michael |
1474 |
sendto_server(source_p, CAP_TS6, NOCAPS, |
| 157 |
michael |
1192 |
":%s NICK %s :%lu", |
| 158 |
|
|
ID(source_p), nick, (unsigned long)source_p->tsinfo); |
| 159 |
michael |
1474 |
sendto_server(source_p, NOCAPS, CAP_TS6, |
| 160 |
michael |
1192 |
":%s NICK %s :%lu", |
| 161 |
|
|
source_p->name, nick, (unsigned long)source_p->tsinfo); |
| 162 |
|
|
|
| 163 |
|
|
hash_del_client(source_p); |
| 164 |
|
|
strcpy(source_p->name, nick); |
| 165 |
|
|
hash_add_client(source_p); |
| 166 |
|
|
|
| 167 |
|
|
if (!samenick) |
| 168 |
|
|
watch_check_hash(source_p, RPL_LOGON); |
| 169 |
|
|
|
| 170 |
|
|
/* fd_desc is long enough */ |
| 171 |
michael |
1193 |
fd_note(&source_p->localClient->fd, "Nick: %s", nick); |
| 172 |
michael |
1192 |
} |
| 173 |
|
|
else |
| 174 |
michael |
1834 |
sendto_one(source_p, form_str(ERR_NICKTOOFAST), |
| 175 |
michael |
1192 |
me.name, source_p->name, source_p->name, |
| 176 |
|
|
nick, ConfigFileEntry.max_nick_time); |
| 177 |
|
|
} |
| 178 |
|
|
|
| 179 |
michael |
981 |
/*! \brief NICK command handler (called by unregistered, |
| 180 |
|
|
* locally connected clients) |
| 181 |
adx |
30 |
* |
| 182 |
michael |
981 |
* \param client_p Pointer to allocated Client struct with physical connection |
| 183 |
|
|
* to this server, i.e. with an open socket connected. |
| 184 |
|
|
* \param source_p Pointer to allocated Client struct from which the message |
| 185 |
|
|
* originally comes from. This can be a local or remote client. |
| 186 |
|
|
* \param parc Integer holding the number of supplied arguments. |
| 187 |
|
|
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
| 188 |
|
|
* pointers. |
| 189 |
|
|
* \note Valid arguments for this command are: |
| 190 |
|
|
* - parv[0] = sender prefix |
| 191 |
|
|
* - parv[1] = nickname |
| 192 |
adx |
30 |
*/ |
| 193 |
|
|
static void |
| 194 |
|
|
mr_nick(struct Client *client_p, struct Client *source_p, |
| 195 |
|
|
int parc, char *parv[]) |
| 196 |
|
|
{ |
| 197 |
michael |
885 |
struct Client *target_p = NULL; |
| 198 |
michael |
1687 |
struct MaskItem *conf = NULL; |
| 199 |
michael |
1431 |
char nick[NICKLEN + 1]; |
| 200 |
michael |
885 |
char *s = NULL; |
| 201 |
|
|
|
| 202 |
adx |
30 |
if (parc < 2 || EmptyString(parv[1])) |
| 203 |
|
|
{ |
| 204 |
michael |
1834 |
sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN), me.name, |
| 205 |
michael |
1234 |
source_p->name[0] ? source_p->name : "*"); |
| 206 |
adx |
30 |
return; |
| 207 |
|
|
} |
| 208 |
|
|
|
| 209 |
|
|
/* Terminate the nick at the first ~ */ |
| 210 |
|
|
if ((s = strchr(parv[1], '~')) != NULL) |
| 211 |
|
|
*s = '\0'; |
| 212 |
|
|
|
| 213 |
|
|
/* copy the nick and terminate it */ |
| 214 |
michael |
1751 |
strlcpy(nick, parv[1], IRCD_MIN(sizeof(nick), ServerInfo.max_nick_length + 1)); |
| 215 |
adx |
30 |
|
| 216 |
|
|
/* check the nickname is ok */ |
| 217 |
michael |
1165 |
if (!valid_nickname(nick, 1)) |
| 218 |
adx |
30 |
{ |
| 219 |
michael |
1834 |
sendto_one(source_p, form_str(ERR_ERRONEUSNICKNAME), me.name, |
| 220 |
michael |
1838 |
source_p->name[0] ? source_p->name : "*", parv[1], |
| 221 |
|
|
"Erroneous Nickname"); |
| 222 |
adx |
30 |
return; |
| 223 |
|
|
} |
| 224 |
|
|
|
| 225 |
|
|
/* check if the nick is resv'd */ |
| 226 |
michael |
1688 |
if ((conf = find_matching_name_conf(CONF_NRESV, nick, NULL, NULL, 0))) |
| 227 |
adx |
30 |
{ |
| 228 |
michael |
1687 |
++conf->count; |
| 229 |
michael |
1834 |
sendto_one(source_p, form_str(ERR_ERRONEUSNICKNAME), me.name, |
| 230 |
michael |
1838 |
source_p->name[0] ? source_p->name : "*", nick, conf->reason); |
| 231 |
michael |
1698 |
sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE, |
| 232 |
michael |
1442 |
"Forbidding reserved nick [%s] from user %s", |
| 233 |
|
|
nick, get_client_name(client_p, HIDE_IP)); |
| 234 |
adx |
30 |
return; |
| 235 |
|
|
} |
| 236 |
|
|
|
| 237 |
michael |
1169 |
if ((target_p = hash_find_client(nick)) == NULL) |
| 238 |
michael |
1003 |
set_initial_nick(source_p, nick); |
| 239 |
adx |
30 |
else if (source_p == target_p) |
| 240 |
michael |
1080 |
strlcpy(source_p->name, nick, sizeof(source_p->name)); |
| 241 |
adx |
30 |
else |
| 242 |
michael |
1834 |
sendto_one(source_p, form_str(ERR_NICKNAMEINUSE), me.name, "*", nick); |
| 243 |
adx |
30 |
} |
| 244 |
|
|
|
| 245 |
michael |
981 |
|
| 246 |
|
|
/*! \brief NICK command handler (called by already registered, |
| 247 |
|
|
* locally connected clients) |
| 248 |
adx |
30 |
* |
| 249 |
michael |
981 |
* \param client_p Pointer to allocated Client struct with physical connection |
| 250 |
|
|
* to this server, i.e. with an open socket connected. |
| 251 |
|
|
* \param source_p Pointer to allocated Client struct from which the message |
| 252 |
|
|
* originally comes from. This can be a local or remote client. |
| 253 |
|
|
* \param parc Integer holding the number of supplied arguments. |
| 254 |
|
|
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
| 255 |
|
|
* pointers. |
| 256 |
|
|
* \note Valid arguments for this command are: |
| 257 |
|
|
* - parv[0] = sender prefix |
| 258 |
|
|
* - parv[1] = nickname |
| 259 |
adx |
30 |
*/ |
| 260 |
|
|
static void |
| 261 |
|
|
m_nick(struct Client *client_p, struct Client *source_p, |
| 262 |
|
|
int parc, char *parv[]) |
| 263 |
|
|
{ |
| 264 |
michael |
1431 |
char nick[NICKLEN + 1]; |
| 265 |
michael |
885 |
struct Client *target_p = NULL; |
| 266 |
michael |
1687 |
struct MaskItem *conf = NULL; |
| 267 |
adx |
30 |
|
| 268 |
michael |
1193 |
assert(source_p == client_p); |
| 269 |
|
|
|
| 270 |
adx |
30 |
if (parc < 2 || EmptyString(parv[1])) |
| 271 |
|
|
{ |
| 272 |
michael |
1834 |
sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN), |
| 273 |
michael |
981 |
me.name, source_p->name); |
| 274 |
adx |
30 |
return; |
| 275 |
|
|
} |
| 276 |
|
|
|
| 277 |
|
|
/* mark end of grace period, to prevent nickflooding */ |
| 278 |
|
|
if (!IsFloodDone(source_p)) |
| 279 |
|
|
flood_endgrace(source_p); |
| 280 |
|
|
|
| 281 |
|
|
/* terminate nick to NICKLEN */ |
| 282 |
michael |
1751 |
strlcpy(nick, parv[1], IRCD_MIN(sizeof(nick), ServerInfo.max_nick_length + 1)); |
| 283 |
adx |
30 |
|
| 284 |
|
|
/* check the nickname is ok */ |
| 285 |
michael |
1165 |
if (!valid_nickname(nick, 1)) |
| 286 |
adx |
30 |
{ |
| 287 |
michael |
1838 |
sendto_one(source_p, form_str(ERR_ERRONEUSNICKNAME), me.name, |
| 288 |
|
|
source_p->name, nick, "Erroneous Nickname"); |
| 289 |
adx |
30 |
return; |
| 290 |
|
|
} |
| 291 |
|
|
|
| 292 |
michael |
1687 |
|
| 293 |
|
|
if (!IsExemptResv(source_p) && |
| 294 |
|
|
!(HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.oper_pass_resv) && |
| 295 |
|
|
(conf = find_matching_name_conf(CONF_NRESV, nick, NULL, NULL, 0))) |
| 296 |
adx |
30 |
{ |
| 297 |
michael |
1687 |
++conf->count; |
| 298 |
michael |
1834 |
sendto_one(source_p, form_str(ERR_ERRONEUSNICKNAME), |
| 299 |
michael |
1838 |
me.name, source_p->name, nick, conf->reason); |
| 300 |
michael |
1698 |
sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE, |
| 301 |
michael |
1442 |
"Forbidding reserved nick [%s] from user %s", |
| 302 |
|
|
nick, get_client_name(client_p, HIDE_IP)); |
| 303 |
adx |
30 |
return; |
| 304 |
|
|
} |
| 305 |
|
|
|
| 306 |
michael |
1169 |
if ((target_p = hash_find_client(nick)) == NULL) |
| 307 |
michael |
1193 |
change_local_nick(source_p, nick); |
| 308 |
michael |
981 |
else if (target_p == source_p) |
| 309 |
adx |
30 |
{ |
| 310 |
michael |
981 |
/* |
| 311 |
|
|
* If (target_p == source_p) the client is changing nicks between |
| 312 |
adx |
30 |
* equivalent nicknames ie: [nick] -> {nick} |
| 313 |
|
|
*/ |
| 314 |
|
|
|
| 315 |
michael |
981 |
/* check the nick isnt exactly the same */ |
| 316 |
|
|
if (strcmp(target_p->name, nick)) |
| 317 |
michael |
1193 |
change_local_nick(source_p, nick); |
| 318 |
michael |
981 |
} |
| 319 |
|
|
else if (IsUnknown(target_p)) |
| 320 |
|
|
{ |
| 321 |
|
|
/* |
| 322 |
|
|
* if the client that has the nick isn't registered yet (nick but no |
| 323 |
adx |
30 |
* user) then drop the unregged client |
| 324 |
|
|
*/ |
| 325 |
michael |
981 |
exit_client(target_p, &me, "Overridden"); |
| 326 |
michael |
1193 |
change_local_nick(source_p, nick); |
| 327 |
adx |
30 |
} |
| 328 |
|
|
else |
| 329 |
michael |
1834 |
sendto_one(source_p, form_str(ERR_NICKNAMEINUSE), me.name, |
| 330 |
michael |
981 |
source_p->name, nick); |
| 331 |
adx |
30 |
} |
| 332 |
|
|
|
| 333 |
michael |
981 |
|
| 334 |
|
|
/*! \brief NICK command handler (called by servers and remotely |
| 335 |
|
|
* connected clients) |
| 336 |
|
|
* |
| 337 |
|
|
* \param client_p Pointer to allocated Client struct with physical connection |
| 338 |
|
|
* to this server, i.e. with an open socket connected. |
| 339 |
|
|
* \param source_p Pointer to allocated Client struct from which the message |
| 340 |
|
|
* originally comes from. This can be a local or remote client. |
| 341 |
|
|
* \param parc Integer holding the number of supplied arguments. |
| 342 |
|
|
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
| 343 |
|
|
* pointers. |
| 344 |
|
|
* \note Valid arguments for this command are: |
| 345 |
|
|
* |
| 346 |
adx |
30 |
* server -> server nick change |
| 347 |
michael |
981 |
* - parv[0] = sender prefix |
| 348 |
|
|
* - parv[1] = nickname |
| 349 |
|
|
* - parv[2] = TS when nick change |
| 350 |
adx |
30 |
* |
| 351 |
michael |
1196 |
* server introducing new nick (without services support) |
| 352 |
michael |
981 |
* - parv[0] = sender prefix |
| 353 |
|
|
* - parv[1] = nickname |
| 354 |
|
|
* - parv[2] = hop count |
| 355 |
|
|
* - parv[3] = TS |
| 356 |
|
|
* - parv[4] = umode |
| 357 |
|
|
* - parv[5] = username |
| 358 |
|
|
* - parv[6] = hostname |
| 359 |
|
|
* - parv[7] = server |
| 360 |
|
|
* - parv[8] = ircname |
| 361 |
michael |
1196 |
* |
| 362 |
|
|
* server introducing new nick (with services support) |
| 363 |
|
|
* - parv[0] = sender prefix |
| 364 |
|
|
* - parv[1] = nickname |
| 365 |
|
|
* - parv[2] = hop count |
| 366 |
|
|
* - parv[3] = TS |
| 367 |
|
|
* - parv[4] = umode |
| 368 |
|
|
* - parv[5] = username |
| 369 |
|
|
* - parv[6] = hostname |
| 370 |
|
|
* - parv[7] = server |
| 371 |
|
|
* - parv[8] = services id (timestamp) |
| 372 |
|
|
* - parv[9] = ircname |
| 373 |
adx |
30 |
*/ |
| 374 |
|
|
static void |
| 375 |
|
|
ms_nick(struct Client *client_p, struct Client *source_p, |
| 376 |
|
|
int parc, char *parv[]) |
| 377 |
|
|
{ |
| 378 |
michael |
981 |
struct Client *target_p = NULL; |
| 379 |
adx |
30 |
time_t newts = 0; |
| 380 |
michael |
1559 |
const char *svsid = "0"; |
| 381 |
adx |
30 |
|
| 382 |
michael |
1531 |
if (parc < 3 || EmptyString(parv[parc - 1])) |
| 383 |
adx |
30 |
return; |
| 384 |
|
|
|
| 385 |
michael |
1196 |
if (parc >= 9) |
| 386 |
adx |
30 |
{ |
| 387 |
michael |
1169 |
struct Client *server_p = hash_find_server(parv[7]); |
| 388 |
adx |
30 |
|
| 389 |
|
|
if (server_p == NULL) |
| 390 |
|
|
{ |
| 391 |
michael |
1618 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 392 |
adx |
30 |
"Invalid server %s from %s for NICK %s", |
| 393 |
michael |
981 |
parv[7], source_p->name, parv[1]); |
| 394 |
adx |
30 |
sendto_one(client_p, ":%s KILL %s :%s (Server doesn't exist!)", |
| 395 |
michael |
981 |
me.name, parv[1], me.name); |
| 396 |
adx |
30 |
return; |
| 397 |
|
|
} |
| 398 |
|
|
|
| 399 |
michael |
981 |
if (check_clean_nick(client_p, source_p, parv[1], server_p) || |
| 400 |
|
|
check_clean_user(client_p, parv[1], parv[5], server_p) || |
| 401 |
|
|
check_clean_host(client_p, parv[1], parv[6], server_p)) |
| 402 |
adx |
30 |
return; |
| 403 |
|
|
|
| 404 |
|
|
if (IsServer(source_p)) |
| 405 |
michael |
981 |
newts = atol(parv[3]); |
| 406 |
michael |
1196 |
if (IsServer(source_p) && parc == 10) |
| 407 |
michael |
1559 |
svsid = parv[8]; |
| 408 |
adx |
30 |
} |
| 409 |
|
|
else if (parc == 3) |
| 410 |
|
|
{ |
| 411 |
|
|
if (IsServer(source_p)) |
| 412 |
michael |
981 |
/* Servers can't change nicks.. */ |
| 413 |
adx |
30 |
return; |
| 414 |
|
|
|
| 415 |
michael |
981 |
if (check_clean_nick(client_p, source_p, parv[1], |
| 416 |
adx |
30 |
source_p->servptr)) |
| 417 |
|
|
return; |
| 418 |
michael |
981 |
|
| 419 |
|
|
newts = atol(parv[2]); |
| 420 |
adx |
30 |
} |
| 421 |
|
|
|
| 422 |
|
|
/* if the nick doesnt exist, allow it and process like normal */ |
| 423 |
michael |
1169 |
if ((target_p = hash_find_client(parv[1])) == NULL) |
| 424 |
michael |
1196 |
nick_from_server(client_p, source_p, parc, parv, newts, svsid, parv[1], parv[parc-1]); |
| 425 |
michael |
981 |
else if (IsUnknown(target_p)) |
| 426 |
adx |
30 |
{ |
| 427 |
michael |
981 |
/* we're not living in the past anymore, an unknown client is local only. */ |
| 428 |
adx |
30 |
exit_client(target_p, &me, "Overridden"); |
| 429 |
michael |
1196 |
nick_from_server(client_p, source_p, parc, parv, newts, svsid, parv[1], parv[parc-1]); |
| 430 |
adx |
30 |
} |
| 431 |
michael |
981 |
else if (target_p == source_p) |
| 432 |
adx |
30 |
{ |
| 433 |
michael |
981 |
if (strcmp(target_p->name, parv[1])) |
| 434 |
michael |
1196 |
nick_from_server(client_p, source_p, parc, parv, newts, svsid, parv[1], parv[parc-1]); |
| 435 |
adx |
30 |
} |
| 436 |
michael |
981 |
else |
| 437 |
|
|
perform_nick_collides(source_p, client_p, target_p, parc, parv, |
| 438 |
michael |
1196 |
newts, svsid, parv[1], parv[parc-1], NULL); |
| 439 |
adx |
30 |
} |
| 440 |
|
|
|
| 441 |
michael |
981 |
|
| 442 |
|
|
/*! \brief UID command handler (called by servers) |
| 443 |
adx |
30 |
* |
| 444 |
michael |
981 |
* \param client_p Pointer to allocated Client struct with physical connection |
| 445 |
|
|
* to this server, i.e. with an open socket connected. |
| 446 |
|
|
* \param source_p Pointer to allocated Client struct from which the message |
| 447 |
|
|
* originally comes from. This can be a local or remote client. |
| 448 |
|
|
* \param parc Integer holding the number of supplied arguments. |
| 449 |
|
|
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
| 450 |
|
|
* pointers. |
| 451 |
|
|
* \note Valid arguments for this command are: |
| 452 |
|
|
* |
| 453 |
michael |
1196 |
* server introducing new nick (without services support) |
| 454 |
michael |
981 |
* - parv[0] = sender prefix |
| 455 |
|
|
* - parv[1] = nickname |
| 456 |
|
|
* - parv[2] = hop count |
| 457 |
|
|
* - parv[3] = TS |
| 458 |
|
|
* - parv[4] = umode |
| 459 |
|
|
* - parv[5] = username |
| 460 |
|
|
* - parv[6] = hostname |
| 461 |
|
|
* - parv[7] = ip |
| 462 |
|
|
* - parv[8] = uid |
| 463 |
|
|
* - parv[9] = ircname (gecos) |
| 464 |
michael |
1196 |
* |
| 465 |
|
|
* server introducing new nick (with services support) |
| 466 |
|
|
* - parv[ 0] = sender prefix |
| 467 |
|
|
* - parv[ 1] = nickname |
| 468 |
|
|
* - parv[ 2] = hop count |
| 469 |
|
|
* - parv[ 3] = TS |
| 470 |
|
|
* - parv[ 4] = umode |
| 471 |
|
|
* - parv[ 5] = username |
| 472 |
|
|
* - parv[ 6] = hostname |
| 473 |
|
|
* - parv[ 7] = ip |
| 474 |
|
|
* - parv[ 8] = uid |
| 475 |
|
|
* - parv[ 9] = services id (timestamp) |
| 476 |
|
|
* - parv[10] = ircname (gecos) |
| 477 |
adx |
30 |
*/ |
| 478 |
|
|
static void |
| 479 |
|
|
ms_uid(struct Client *client_p, struct Client *source_p, |
| 480 |
|
|
int parc, char *parv[]) |
| 481 |
|
|
{ |
| 482 |
michael |
981 |
struct Client *target_p = NULL; |
| 483 |
adx |
30 |
time_t newts = 0; |
| 484 |
michael |
1559 |
const char *svsid = "0"; |
| 485 |
adx |
30 |
|
| 486 |
michael |
1196 |
if (parc < 10 || EmptyString(parv[parc-1])) |
| 487 |
adx |
30 |
return; |
| 488 |
|
|
|
| 489 |
michael |
981 |
if (check_clean_nick(client_p, source_p, parv[1], source_p) || |
| 490 |
|
|
check_clean_user(client_p, parv[1], parv[5], source_p) || |
| 491 |
|
|
check_clean_host(client_p, parv[1], parv[6], source_p)) |
| 492 |
adx |
30 |
return; |
| 493 |
|
|
|
| 494 |
michael |
981 |
newts = atol(parv[3]); |
| 495 |
michael |
1559 |
svsid = parc == 11 ? parv[9] : "0"; |
| 496 |
adx |
30 |
|
| 497 |
michael |
981 |
/* |
| 498 |
|
|
* if there is an ID collision, kill our client, and kill theirs. |
| 499 |
adx |
30 |
* this may generate 401's, but it ensures that both clients always |
| 500 |
|
|
* go, even if the other server refuses to do the right thing. |
| 501 |
|
|
*/ |
| 502 |
michael |
981 |
if ((target_p = hash_find_id(parv[8])) != NULL) |
| 503 |
adx |
30 |
{ |
| 504 |
michael |
1618 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 505 |
adx |
30 |
"ID collision on %s(%s <- %s)(both killed)", |
| 506 |
|
|
target_p->name, target_p->from->name, |
| 507 |
|
|
client_p->name); |
| 508 |
|
|
kill_client_ll_serv_butone(NULL, target_p, "%s (ID collision)", |
| 509 |
|
|
me.name); |
| 510 |
|
|
|
| 511 |
michael |
896 |
++ServerStats.is_kill; |
| 512 |
michael |
1219 |
AddFlag(target_p, FLAGS_KILLED); |
| 513 |
adx |
30 |
exit_client(target_p, &me, "ID Collision"); |
| 514 |
|
|
return; |
| 515 |
|
|
} |
| 516 |
|
|
|
| 517 |
michael |
1169 |
if ((target_p = hash_find_client(parv[1])) == NULL) |
| 518 |
michael |
1196 |
uid_from_server(client_p, source_p, parc, parv, newts, svsid, parv[1], parv[parc-1]); |
| 519 |
adx |
30 |
else if (IsUnknown(target_p)) |
| 520 |
|
|
{ |
| 521 |
|
|
exit_client(target_p, &me, "Overridden"); |
| 522 |
michael |
1196 |
uid_from_server(client_p, source_p, parc, parv, newts, svsid, parv[1], parv[parc-1]); |
| 523 |
adx |
30 |
} |
| 524 |
|
|
else |
| 525 |
michael |
1196 |
perform_nick_collides(source_p, client_p, target_p, parc, parv, newts, svsid, parv[1], |
| 526 |
|
|
parv[parc-1], parv[8]); |
| 527 |
adx |
30 |
} |
| 528 |
|
|
|
| 529 |
|
|
/* check_clean_nick() |
| 530 |
|
|
* |
| 531 |
|
|
* input - pointer to source |
| 532 |
|
|
* - |
| 533 |
|
|
* - nickname |
| 534 |
|
|
* - truncated nickname |
| 535 |
|
|
* - origin of client |
| 536 |
|
|
* - pointer to server nick is coming from |
| 537 |
|
|
* output - none |
| 538 |
|
|
* side effects - if nickname is erroneous, or a different length to |
| 539 |
|
|
* truncated nickname, return 1 |
| 540 |
|
|
*/ |
| 541 |
|
|
static int |
| 542 |
|
|
check_clean_nick(struct Client *client_p, struct Client *source_p, |
| 543 |
michael |
981 |
char *nick, struct Client *server_p) |
| 544 |
adx |
30 |
{ |
| 545 |
|
|
/* the old code did some wacky stuff here, if the nick is invalid, kill it |
| 546 |
|
|
* and dont bother messing at all |
| 547 |
|
|
*/ |
| 548 |
michael |
1165 |
if (!valid_nickname(nick, 0)) |
| 549 |
adx |
30 |
{ |
| 550 |
michael |
896 |
++ServerStats.is_kill; |
| 551 |
michael |
1618 |
sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE, |
| 552 |
michael |
981 |
"Bad/long Nick: %s From: %s(via %s)", |
| 553 |
adx |
30 |
nick, server_p->name, client_p->name); |
| 554 |
|
|
|
| 555 |
|
|
sendto_one(client_p, ":%s KILL %s :%s (Bad Nickname)", |
| 556 |
michael |
981 |
me.name, nick, me.name); |
| 557 |
adx |
30 |
|
| 558 |
|
|
/* bad nick change */ |
| 559 |
|
|
if (source_p != client_p) |
| 560 |
|
|
{ |
| 561 |
|
|
kill_client_ll_serv_butone(client_p, source_p, |
| 562 |
|
|
"%s (Bad Nickname)", |
| 563 |
|
|
me.name); |
| 564 |
michael |
1219 |
AddFlag(source_p, FLAGS_KILLED); |
| 565 |
adx |
30 |
exit_client(source_p, &me, "Bad Nickname"); |
| 566 |
|
|
} |
| 567 |
|
|
|
| 568 |
michael |
981 |
return 1; |
| 569 |
adx |
30 |
} |
| 570 |
|
|
|
| 571 |
michael |
981 |
return 0; |
| 572 |
adx |
30 |
} |
| 573 |
|
|
|
| 574 |
|
|
/* check_clean_user() |
| 575 |
|
|
* |
| 576 |
|
|
* input - pointer to client sending data |
| 577 |
|
|
* - nickname |
| 578 |
|
|
* - username to check |
| 579 |
|
|
* - origin of NICK |
| 580 |
|
|
* output - none |
| 581 |
|
|
* side effects - if username is erroneous, return 1 |
| 582 |
|
|
*/ |
| 583 |
|
|
static int |
| 584 |
|
|
check_clean_user(struct Client *client_p, char *nick, |
| 585 |
|
|
char *user, struct Client *server_p) |
| 586 |
|
|
{ |
| 587 |
michael |
981 |
if (!clean_user_name(user)) |
| 588 |
adx |
30 |
{ |
| 589 |
michael |
896 |
++ServerStats.is_kill; |
| 590 |
michael |
1618 |
sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE, |
| 591 |
michael |
981 |
"Bad/Long Username: %s Nickname: %s From: %s(via %s)", |
| 592 |
|
|
user, nick, server_p->name, client_p->name); |
| 593 |
adx |
30 |
sendto_one(client_p, ":%s KILL %s :%s (Bad Username)", |
| 594 |
|
|
me.name, nick, me.name); |
| 595 |
michael |
981 |
return 1; |
| 596 |
adx |
30 |
} |
| 597 |
|
|
|
| 598 |
michael |
981 |
return 0; |
| 599 |
adx |
30 |
} |
| 600 |
|
|
|
| 601 |
|
|
/* check_clean_host() |
| 602 |
|
|
* |
| 603 |
|
|
* input - pointer to client sending us data |
| 604 |
|
|
* - nickname |
| 605 |
|
|
* - hostname to check |
| 606 |
|
|
* - source name |
| 607 |
|
|
* output - none |
| 608 |
|
|
* side effects - if hostname is erroneous, return 1 |
| 609 |
|
|
*/ |
| 610 |
|
|
static int |
| 611 |
|
|
check_clean_host(struct Client *client_p, char *nick, |
| 612 |
|
|
char *host, struct Client *server_p) |
| 613 |
|
|
{ |
| 614 |
michael |
1795 |
if (!valid_hostname(host)) |
| 615 |
adx |
30 |
{ |
| 616 |
michael |
896 |
++ServerStats.is_kill; |
| 617 |
michael |
1618 |
sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE, |
| 618 |
michael |
981 |
"Bad/Long Hostname: %s Nickname: %s From: %s(via %s)", |
| 619 |
|
|
host, nick, server_p->name, client_p->name); |
| 620 |
adx |
30 |
sendto_one(client_p, ":%s KILL %s :%s (Bad Hostname)", |
| 621 |
|
|
me.name, nick, me.name); |
| 622 |
michael |
981 |
return 1; |
| 623 |
adx |
30 |
} |
| 624 |
|
|
|
| 625 |
michael |
981 |
return 0; |
| 626 |
adx |
30 |
} |
| 627 |
|
|
|
| 628 |
|
|
/* clean_user_name() |
| 629 |
|
|
* |
| 630 |
|
|
* input - username |
| 631 |
|
|
* output - none |
| 632 |
|
|
* side effects - walks through the username, returning 0 if erroneous |
| 633 |
|
|
*/ |
| 634 |
|
|
static int |
| 635 |
michael |
981 |
clean_user_name(const char *user) |
| 636 |
adx |
30 |
{ |
| 637 |
michael |
981 |
const char *p = user; |
| 638 |
|
|
|
| 639 |
|
|
assert(user && *user); |
| 640 |
|
|
|
| 641 |
|
|
for (; *p; ++p) |
| 642 |
|
|
if (!IsUserChar(*p)) |
| 643 |
adx |
30 |
return 0; |
| 644 |
|
|
|
| 645 |
michael |
981 |
return p - user <= USERLEN; |
| 646 |
adx |
30 |
} |
| 647 |
|
|
|
| 648 |
|
|
/* |
| 649 |
|
|
* nick_from_server() |
| 650 |
|
|
*/ |
| 651 |
|
|
static void |
| 652 |
|
|
nick_from_server(struct Client *client_p, struct Client *source_p, int parc, |
| 653 |
michael |
1559 |
char *parv[], time_t newts, const char *svsid, char *nick, char *ngecos) |
| 654 |
adx |
30 |
{ |
| 655 |
michael |
876 |
int samenick = 0; |
| 656 |
|
|
|
| 657 |
adx |
30 |
if (IsServer(source_p)) |
| 658 |
|
|
{ |
| 659 |
|
|
/* A server introducing a new client, change source */ |
| 660 |
|
|
source_p = make_client(client_p); |
| 661 |
|
|
dlinkAdd(source_p, &source_p->node, &global_client_list); |
| 662 |
|
|
|
| 663 |
|
|
if (parc > 2) |
| 664 |
|
|
source_p->hopcount = atoi(parv[2]); |
| 665 |
|
|
if (newts) |
| 666 |
|
|
source_p->tsinfo = newts; |
| 667 |
|
|
else |
| 668 |
|
|
{ |
| 669 |
|
|
newts = source_p->tsinfo = CurrentTime; |
| 670 |
|
|
ts_warn("Remote nick %s (%s) introduced without a TS", nick, parv[0]); |
| 671 |
|
|
} |
| 672 |
|
|
|
| 673 |
michael |
1559 |
strlcpy(source_p->svid, svsid, sizeof(source_p->svid)); |
| 674 |
michael |
1196 |
strlcpy(source_p->info, ngecos, sizeof(source_p->info)); |
| 675 |
adx |
30 |
/* copy the nick in place */ |
| 676 |
michael |
1158 |
strlcpy(source_p->name, nick, sizeof(source_p->name)); |
| 677 |
adx |
30 |
hash_add_client(source_p); |
| 678 |
|
|
|
| 679 |
|
|
if (parc > 8) |
| 680 |
|
|
{ |
| 681 |
michael |
981 |
const char *m; |
| 682 |
adx |
30 |
|
| 683 |
|
|
/* parse usermodes */ |
| 684 |
michael |
896 |
for (m = &parv[4][1]; *m; ++m) |
| 685 |
adx |
30 |
{ |
| 686 |
michael |
896 |
unsigned int flag = user_modes[(unsigned char)*m]; |
| 687 |
adx |
30 |
|
| 688 |
michael |
1182 |
if ((flag & UMODE_INVISIBLE) && !HasUMode(source_p, UMODE_INVISIBLE)) |
| 689 |
michael |
1169 |
++Count.invisi; |
| 690 |
michael |
1182 |
if ((flag & UMODE_OPER) && !HasUMode(source_p, UMODE_OPER)) |
| 691 |
michael |
1169 |
++Count.oper; |
| 692 |
michael |
896 |
|
| 693 |
adx |
30 |
source_p->umodes |= flag & SEND_UMODES; |
| 694 |
|
|
} |
| 695 |
|
|
|
| 696 |
michael |
1080 |
register_remote_user(source_p, parv[5], parv[6], |
| 697 |
adx |
30 |
parv[7], ngecos); |
| 698 |
michael |
222 |
return; |
| 699 |
adx |
30 |
} |
| 700 |
|
|
} |
| 701 |
|
|
else if (source_p->name[0]) |
| 702 |
|
|
{ |
| 703 |
michael |
981 |
samenick = !irccmp(source_p->name, nick); |
| 704 |
michael |
876 |
|
| 705 |
adx |
30 |
/* client changing their nick */ |
| 706 |
michael |
876 |
if (!samenick) |
| 707 |
michael |
706 |
{ |
| 708 |
michael |
1158 |
DelUMode(source_p, UMODE_REGISTERED); |
| 709 |
michael |
876 |
watch_check_hash(source_p, RPL_LOGOFF); |
| 710 |
adx |
30 |
source_p->tsinfo = newts ? newts : CurrentTime; |
| 711 |
michael |
706 |
} |
| 712 |
adx |
30 |
|
| 713 |
michael |
1734 |
sendto_common_channels_local(source_p, 1, 0, ":%s!%s@%s NICK :%s", |
| 714 |
adx |
30 |
source_p->name,source_p->username, |
| 715 |
|
|
source_p->host, nick); |
| 716 |
|
|
|
| 717 |
michael |
706 |
add_history(source_p, 1); |
| 718 |
michael |
1474 |
sendto_server(client_p, CAP_TS6, NOCAPS, |
| 719 |
adx |
30 |
":%s NICK %s :%lu", |
| 720 |
|
|
ID(source_p), nick, (unsigned long)source_p->tsinfo); |
| 721 |
michael |
1474 |
sendto_server(client_p, NOCAPS, CAP_TS6, |
| 722 |
adx |
30 |
":%s NICK %s :%lu", |
| 723 |
michael |
981 |
source_p->name, nick, (unsigned long)source_p->tsinfo); |
| 724 |
adx |
30 |
} |
| 725 |
|
|
|
| 726 |
|
|
/* set the new nick name */ |
| 727 |
|
|
if (source_p->name[0]) |
| 728 |
|
|
hash_del_client(source_p); |
| 729 |
|
|
|
| 730 |
michael |
1158 |
strlcpy(source_p->name, nick, sizeof(source_p->name)); |
| 731 |
adx |
30 |
hash_add_client(source_p); |
| 732 |
michael |
876 |
|
| 733 |
|
|
if (!samenick) |
| 734 |
|
|
watch_check_hash(source_p, RPL_LOGON); |
| 735 |
adx |
30 |
} |
| 736 |
|
|
|
| 737 |
|
|
/* |
| 738 |
|
|
* client_from_server() |
| 739 |
|
|
*/ |
| 740 |
|
|
static void |
| 741 |
michael |
981 |
uid_from_server(struct Client *client_p, struct Client *source_p, int parc, |
| 742 |
michael |
1559 |
char *parv[], time_t newts, const char *svsid, char *nick, char *ugecos) |
| 743 |
adx |
30 |
{ |
| 744 |
michael |
981 |
const char *m = NULL; |
| 745 |
adx |
30 |
const char *servername = source_p->name; |
| 746 |
|
|
|
| 747 |
|
|
source_p = make_client(client_p); |
| 748 |
|
|
dlinkAdd(source_p, &source_p->node, &global_client_list); |
| 749 |
|
|
|
| 750 |
|
|
source_p->hopcount = atoi(parv[2]); |
| 751 |
|
|
source_p->tsinfo = newts; |
| 752 |
michael |
1559 |
strlcpy(source_p->svid, svsid, sizeof(source_p->svid)); |
| 753 |
adx |
30 |
|
| 754 |
|
|
/* copy the nick in place */ |
| 755 |
|
|
strcpy(source_p->name, nick); |
| 756 |
|
|
strlcpy(source_p->id, parv[8], sizeof(source_p->id)); |
| 757 |
|
|
strlcpy(source_p->sockhost, parv[7], sizeof(source_p->sockhost)); |
| 758 |
michael |
1196 |
strlcpy(source_p->info, ugecos, sizeof(source_p->info)); |
| 759 |
adx |
30 |
|
| 760 |
|
|
hash_add_client(source_p); |
| 761 |
|
|
hash_add_id(source_p); |
| 762 |
|
|
|
| 763 |
|
|
/* parse usermodes */ |
| 764 |
michael |
896 |
for (m = &parv[4][1]; *m; ++m) |
| 765 |
adx |
30 |
{ |
| 766 |
michael |
896 |
unsigned int flag = user_modes[(unsigned char)*m]; |
| 767 |
|
|
|
| 768 |
michael |
1182 |
if ((flag & UMODE_INVISIBLE) && !HasUMode(source_p, UMODE_INVISIBLE)) |
| 769 |
michael |
896 |
++Count.invisi; |
| 770 |
michael |
1182 |
if ((flag & UMODE_OPER) && !HasUMode(source_p, UMODE_OPER)) |
| 771 |
michael |
896 |
++Count.oper; |
| 772 |
adx |
30 |
|
| 773 |
|
|
source_p->umodes |= flag & SEND_UMODES; |
| 774 |
|
|
} |
| 775 |
|
|
|
| 776 |
michael |
1080 |
register_remote_user(source_p, parv[5], parv[6], |
| 777 |
michael |
1196 |
servername, ugecos); |
| 778 |
adx |
30 |
} |
| 779 |
|
|
|
| 780 |
|
|
static void |
| 781 |
|
|
perform_nick_collides(struct Client *source_p, struct Client *client_p, |
| 782 |
|
|
struct Client *target_p, int parc, char *parv[], |
| 783 |
michael |
1559 |
time_t newts, const char *svsid, char *nick, char *gecos, char *uid) |
| 784 |
adx |
30 |
{ |
| 785 |
|
|
int sameuser; |
| 786 |
|
|
|
| 787 |
|
|
/* server introducing new nick */ |
| 788 |
|
|
if (IsServer(source_p)) |
| 789 |
|
|
{ |
| 790 |
|
|
/* if we dont have a ts, or their TS's are the same, kill both */ |
| 791 |
|
|
if (!newts || !target_p->tsinfo || (newts == target_p->tsinfo)) |
| 792 |
|
|
{ |
| 793 |
michael |
1618 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 794 |
adx |
30 |
"Nick collision on %s(%s <- %s)(both killed)", |
| 795 |
|
|
target_p->name, target_p->from->name, |
| 796 |
|
|
client_p->name); |
| 797 |
|
|
|
| 798 |
|
|
/* if we have a UID, issue a kill for it */ |
| 799 |
|
|
if (uid) |
| 800 |
|
|
sendto_one(client_p, ":%s KILL %s :%s (Nick collision (new))", |
| 801 |
|
|
me.id, uid, me.name); |
| 802 |
|
|
|
| 803 |
|
|
kill_client_ll_serv_butone(NULL, target_p, |
| 804 |
|
|
"%s (Nick collision (new))", |
| 805 |
|
|
me.name); |
| 806 |
michael |
896 |
++ServerStats.is_kill; |
| 807 |
michael |
1834 |
sendto_one(target_p, form_str(ERR_NICKCOLLISION), |
| 808 |
adx |
30 |
me.name, target_p->name, target_p->name); |
| 809 |
|
|
|
| 810 |
michael |
1219 |
AddFlag(target_p, FLAGS_KILLED); |
| 811 |
adx |
30 |
exit_client(target_p, &me, "Nick collision (new)"); |
| 812 |
|
|
return; |
| 813 |
|
|
} |
| 814 |
|
|
/* the timestamps are different */ |
| 815 |
|
|
else |
| 816 |
|
|
{ |
| 817 |
|
|
sameuser = !irccmp(target_p->username, parv[5]) && |
| 818 |
|
|
!irccmp(target_p->host, parv[6]); |
| 819 |
|
|
|
| 820 |
|
|
/* if the users are the same (loaded a client on a different server) |
| 821 |
|
|
* and the new users ts is older, or the users are different and the |
| 822 |
|
|
* new users ts is newer, ignore the new client and let it do the kill |
| 823 |
|
|
*/ |
| 824 |
|
|
if ((sameuser && newts < target_p->tsinfo) || |
| 825 |
|
|
(!sameuser && newts > target_p->tsinfo)) |
| 826 |
|
|
{ |
| 827 |
|
|
if (uid) |
| 828 |
|
|
sendto_one(client_p, ":%s KILL %s :%s (Nick collision (new))", |
| 829 |
|
|
me.id, uid, me.name); |
| 830 |
|
|
return; |
| 831 |
|
|
} |
| 832 |
|
|
else |
| 833 |
|
|
{ |
| 834 |
|
|
if (sameuser) |
| 835 |
michael |
1618 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 836 |
adx |
30 |
"Nick collision on %s(%s <- %s)(older killed)", |
| 837 |
|
|
target_p->name, target_p->from->name, |
| 838 |
|
|
client_p->name); |
| 839 |
|
|
else |
| 840 |
michael |
1624 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 841 |
adx |
30 |
"Nick collision on %s(%s <- %s)(newer killed)", |
| 842 |
|
|
target_p->name, target_p->from->name, |
| 843 |
|
|
client_p->name); |
| 844 |
|
|
|
| 845 |
michael |
896 |
++ServerStats.is_kill; |
| 846 |
michael |
1834 |
sendto_one(target_p, form_str(ERR_NICKCOLLISION), |
| 847 |
adx |
30 |
me.name, target_p->name, target_p->name); |
| 848 |
|
|
|
| 849 |
|
|
/* if it came from a LL server, itd have been source_p, |
| 850 |
|
|
* so we dont need to mark target_p as known |
| 851 |
|
|
*/ |
| 852 |
|
|
kill_client_ll_serv_butone(source_p, target_p, |
| 853 |
|
|
"%s (Nick collision (new))", |
| 854 |
|
|
me.name); |
| 855 |
|
|
|
| 856 |
michael |
1219 |
AddFlag(target_p, FLAGS_KILLED); |
| 857 |
adx |
30 |
exit_client(target_p, &me, "Nick collision"); |
| 858 |
|
|
|
| 859 |
michael |
1196 |
if (!uid && (parc == 9 || parc == 10)) |
| 860 |
|
|
nick_from_server(client_p, source_p, parc, parv, newts, svsid, nick, gecos); |
| 861 |
|
|
else if (uid && (parc == 10 || parc == 11)) |
| 862 |
|
|
uid_from_server(client_p, source_p, parc, parv, newts, svsid, nick, gecos); |
| 863 |
adx |
30 |
|
| 864 |
|
|
return; |
| 865 |
|
|
} |
| 866 |
|
|
} |
| 867 |
|
|
} |
| 868 |
|
|
|
| 869 |
|
|
/* its a client changing nick and causing a collide */ |
| 870 |
|
|
if (!newts || !target_p->tsinfo || (newts == target_p->tsinfo)) |
| 871 |
michael |
981 |
{ |
| 872 |
michael |
1618 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 873 |
adx |
30 |
"Nick change collision from %s to %s(%s <- %s)(both killed)", |
| 874 |
|
|
source_p->name, target_p->name, target_p->from->name, |
| 875 |
|
|
client_p->name); |
| 876 |
|
|
|
| 877 |
michael |
1834 |
sendto_one(target_p, form_str(ERR_NICKCOLLISION), me.name, |
| 878 |
michael |
981 |
target_p->name, target_p->name); |
| 879 |
|
|
|
| 880 |
michael |
896 |
++ServerStats.is_kill; |
| 881 |
michael |
981 |
kill_client_ll_serv_butone(NULL, source_p, "%s (Nick change collision)", |
| 882 |
|
|
me.name); |
| 883 |
adx |
30 |
|
| 884 |
michael |
896 |
++ServerStats.is_kill; |
| 885 |
michael |
981 |
kill_client_ll_serv_butone(NULL, target_p, "%s (Nick change collision)", |
| 886 |
|
|
me.name); |
| 887 |
adx |
30 |
|
| 888 |
michael |
1219 |
AddFlag(target_p, FLAGS_KILLED); |
| 889 |
adx |
30 |
exit_client(target_p, &me, "Nick collision (new)"); |
| 890 |
michael |
981 |
|
| 891 |
michael |
1219 |
AddFlag(source_p, FLAGS_KILLED); |
| 892 |
adx |
30 |
exit_client(source_p, &me, "Nick collision (old)"); |
| 893 |
|
|
return; |
| 894 |
|
|
} |
| 895 |
|
|
else |
| 896 |
|
|
{ |
| 897 |
|
|
sameuser = !irccmp(target_p->username, source_p->username) && |
| 898 |
|
|
!irccmp(target_p->host, source_p->host); |
| 899 |
|
|
|
| 900 |
|
|
if ((sameuser && newts < target_p->tsinfo) || |
| 901 |
|
|
(!sameuser && newts > target_p->tsinfo)) |
| 902 |
|
|
{ |
| 903 |
|
|
if (sameuser) |
| 904 |
michael |
1618 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 905 |
adx |
30 |
"Nick change collision from %s to %s(%s <- %s)(older killed)", |
| 906 |
|
|
source_p->name, target_p->name, target_p->from->name, |
| 907 |
|
|
client_p->name); |
| 908 |
|
|
else |
| 909 |
michael |
1618 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 910 |
adx |
30 |
"Nick change collision from %s to %s(%s <- %s)(newer killed)", |
| 911 |
|
|
source_p->name, target_p->name, target_p->from->name, |
| 912 |
|
|
client_p->name); |
| 913 |
|
|
|
| 914 |
michael |
896 |
++ServerStats.is_kill; |
| 915 |
adx |
30 |
kill_client_ll_serv_butone(client_p, source_p, |
| 916 |
|
|
"%s (Nick change collision)", |
| 917 |
|
|
me.name); |
| 918 |
|
|
|
| 919 |
michael |
1219 |
AddFlag(source_p, FLAGS_KILLED); |
| 920 |
adx |
30 |
|
| 921 |
|
|
if (sameuser) |
| 922 |
|
|
exit_client(source_p, &me, "Nick collision (old)"); |
| 923 |
|
|
else |
| 924 |
|
|
exit_client(source_p, &me, "Nick collision (new)"); |
| 925 |
|
|
return; |
| 926 |
|
|
} |
| 927 |
|
|
else |
| 928 |
|
|
{ |
| 929 |
|
|
if (sameuser) |
| 930 |
michael |
1618 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 931 |
adx |
30 |
"Nick collision on %s(%s <- %s)(older killed)", |
| 932 |
|
|
target_p->name, target_p->from->name, |
| 933 |
|
|
client_p->name); |
| 934 |
|
|
else |
| 935 |
michael |
1618 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 936 |
adx |
30 |
"Nick collision on %s(%s <- %s)(newer killed)", |
| 937 |
|
|
target_p->name, target_p->from->name, |
| 938 |
|
|
client_p->name); |
| 939 |
|
|
|
| 940 |
|
|
kill_client_ll_serv_butone(source_p, target_p, |
| 941 |
|
|
"%s (Nick collision)", |
| 942 |
|
|
me.name); |
| 943 |
|
|
|
| 944 |
michael |
896 |
++ServerStats.is_kill; |
| 945 |
michael |
1834 |
sendto_one(target_p, form_str(ERR_NICKCOLLISION), |
| 946 |
adx |
30 |
me.name, target_p->name, target_p->name); |
| 947 |
|
|
|
| 948 |
michael |
1219 |
AddFlag(target_p, FLAGS_KILLED); |
| 949 |
adx |
30 |
exit_client(target_p, &me, "Nick collision"); |
| 950 |
|
|
} |
| 951 |
|
|
} |
| 952 |
|
|
|
| 953 |
|
|
/* we should only ever call nick_from_server() here, as |
| 954 |
|
|
* this is a client changing nick, not a new client |
| 955 |
|
|
*/ |
| 956 |
michael |
1196 |
nick_from_server(client_p, source_p, parc, parv, newts, svsid, nick, gecos); |
| 957 |
adx |
30 |
} |
| 958 |
michael |
1230 |
|
| 959 |
|
|
static struct Message nick_msgtab = { |
| 960 |
|
|
"NICK", 0, 0, 0, MAXPARA, MFLG_SLOW, 0, |
| 961 |
|
|
{mr_nick, m_nick, ms_nick, m_ignore, m_nick, m_ignore} |
| 962 |
|
|
}; |
| 963 |
|
|
|
| 964 |
|
|
static struct Message uid_msgtab = { |
| 965 |
|
|
"UID", 0, 0, 10, MAXPARA, MFLG_SLOW, 0, |
| 966 |
|
|
{m_ignore, m_ignore, ms_uid, m_ignore, m_ignore, m_ignore} |
| 967 |
|
|
}; |
| 968 |
|
|
|
| 969 |
|
|
static void |
| 970 |
|
|
module_init(void) |
| 971 |
|
|
{ |
| 972 |
|
|
mod_add_cmd(&uid_msgtab); |
| 973 |
|
|
mod_add_cmd(&nick_msgtab); |
| 974 |
|
|
} |
| 975 |
|
|
|
| 976 |
|
|
static void |
| 977 |
|
|
module_exit(void) |
| 978 |
|
|
{ |
| 979 |
|
|
mod_del_cmd(&uid_msgtab); |
| 980 |
|
|
mod_del_cmd(&nick_msgtab); |
| 981 |
|
|
} |
| 982 |
|
|
|
| 983 |
|
|
struct module module_entry = { |
| 984 |
|
|
.node = { NULL, NULL, NULL }, |
| 985 |
|
|
.name = NULL, |
| 986 |
|
|
.version = "$Revision$", |
| 987 |
|
|
.handle = NULL, |
| 988 |
|
|
.modinit = module_init, |
| 989 |
|
|
.modexit = module_exit, |
| 990 |
|
|
.flags = MODULE_FLAG_CORE |
| 991 |
|
|
}; |