2 * ircd-ratbox: A slightly useful ircd.
3 * m_nick.c: Sets a users nick.
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 * $Id: m_nick.c 3518 2007-06-22 21:59:09Z jilles $
48 #include "s_newconf.h"
52 /* Give all UID nicks the same TS. This ensures nick TS is always the same on
53 * all servers for each nick-user pair, also if a user with a UID nick changes
54 * their nick but is collided again (the server detecting the collision will
55 * not propagate the nick change further). -- jilles
57 #define SAVE_NICKTS 100
59 static int mr_nick(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
60 static int m_nick(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
61 static int mc_nick(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
62 static int ms_nick(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
63 static int ms_uid(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
64 static int ms_euid(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
65 static int ms_save(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
66 static int can_save(struct Client
*);
67 static void save_user(struct Client
*, struct Client
*, struct Client
*);
68 static void bad_nickname(struct Client
*, const char *);
70 struct Message nick_msgtab
= {
71 "NICK", 0, 0, 0, MFLG_SLOW
,
72 {{mr_nick
, 0}, {m_nick
, 0}, {mc_nick
, 3}, {ms_nick
, 0}, mg_ignore
, {m_nick
, 0}}
74 struct Message uid_msgtab
= {
75 "UID", 0, 0, 0, MFLG_SLOW
,
76 {mg_ignore
, mg_ignore
, mg_ignore
, {ms_uid
, 9}, mg_ignore
, mg_ignore
}
78 struct Message euid_msgtab
= {
79 "EUID", 0, 0, 0, MFLG_SLOW
,
80 {mg_ignore
, mg_ignore
, mg_ignore
, {ms_euid
, 12}, mg_ignore
, mg_ignore
}
82 struct Message save_msgtab
= {
83 "SAVE", 0, 0, 0, MFLG_SLOW
,
84 {mg_ignore
, mg_ignore
, mg_ignore
, {ms_save
, 3}, mg_ignore
, mg_ignore
}
87 mapi_clist_av1 nick_clist
[] = { &nick_msgtab
, &uid_msgtab
, &euid_msgtab
,
90 DECLARE_MODULE_AV1(nick
, NULL
, NULL
, nick_clist
, NULL
, NULL
, "$Revision: 3518 $");
92 static int change_remote_nick(struct Client
*, struct Client
*, time_t,
95 static int clean_username(const char *);
96 static int clean_host(const char *);
97 static int clean_uid(const char *uid
, const char *sid
);
99 static void set_initial_nick(struct Client
*client_p
, struct Client
*source_p
, char *nick
);
100 static void change_local_nick(struct Client
*client_p
, struct Client
*source_p
, char *nick
, int);
101 static int register_client(struct Client
*client_p
, struct Client
*server
,
102 const char *nick
, time_t newts
, int parc
, const char *parv
[]);
104 static int perform_nick_collides(struct Client
*, struct Client
*,
105 struct Client
*, int, const char **,
106 time_t, const char *, const char *);
107 static int perform_nickchange_collides(struct Client
*, struct Client
*,
108 struct Client
*, int, const char **, time_t, const char *);
114 mr_nick(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
116 struct Client
*target_p
;
119 if (strlen(client_p
->id
) == 3)
121 exit_client(client_p
, client_p
, client_p
, "Mixing client and server protocol");
125 if(parc
< 2 || EmptyString(parv
[1]))
127 sendto_one(source_p
, form_str(ERR_NONICKNAMEGIVEN
),
128 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
);
132 /* copy the nick and terminate it */
133 rb_strlcpy(nick
, parv
[1], ConfigFileEntry
.nicklen
);
135 /* check the nickname is ok */
136 if(!clean_nick(nick
, 1))
138 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
),
139 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, parv
[1]);
143 /* check if the nick is resv'd */
144 if(find_nick_resv(nick
))
146 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
),
147 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, nick
);
151 if(irc_dictionary_find(nd_dict
, nick
))
153 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
154 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, nick
);
158 if((target_p
= find_named_client(nick
)) == NULL
)
159 set_initial_nick(client_p
, source_p
, nick
);
160 else if(source_p
== target_p
)
161 strcpy(source_p
->name
, nick
);
163 sendto_one(source_p
, form_str(ERR_NICKNAMEINUSE
), me
.name
, "*", nick
);
172 m_nick(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
174 struct Client
*target_p
;
177 if(parc
< 2 || EmptyString(parv
[1]))
179 sendto_one(source_p
, form_str(ERR_NONICKNAMEGIVEN
), me
.name
, source_p
->name
);
183 /* mark end of grace period, to prevent nickflooding */
184 if(!IsFloodDone(source_p
))
185 flood_endgrace(source_p
);
187 /* terminate nick to NICKLEN, we dont want clean_nick() to error! */
188 rb_strlcpy(nick
, parv
[1], ConfigFileEntry
.nicklen
);
190 /* check the nickname is ok */
191 if(!clean_nick(nick
, 1))
193 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
), me
.name
, source_p
->name
, nick
);
197 if(!IsExemptResv(source_p
) && find_nick_resv(nick
))
199 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
), me
.name
, source_p
->name
, nick
);
203 if(irc_dictionary_find(nd_dict
, nick
))
205 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
206 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, nick
);
210 if((target_p
= find_named_client(nick
)))
212 /* If(target_p == source_p) the client is changing nicks between
213 * equivalent nicknames ie: [nick] -> {nick}
215 if(target_p
== source_p
)
217 /* check the nick isnt exactly the same */
218 if(strcmp(target_p
->name
, nick
))
219 change_local_nick(client_p
, source_p
, nick
, 1);
223 /* drop unregged client */
224 else if(IsUnknown(target_p
))
226 exit_client(NULL
, target_p
, &me
, "Overridden");
227 change_local_nick(client_p
, source_p
, nick
, 1);
230 sendto_one(source_p
, form_str(ERR_NICKNAMEINUSE
), me
.name
, source_p
->name
, nick
);
235 change_local_nick(client_p
, source_p
, nick
, 1);
242 * server -> server nick change
244 * parv[2] = TS when nick change
247 mc_nick(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
249 struct Client
*target_p
;
252 /* if nicks erroneous, or too long, kill */
253 if(!clean_nick(parv
[1], 0))
255 bad_nickname(client_p
, parv
[1]);
259 newts
= atol(parv
[2]);
260 target_p
= find_named_client(parv
[1]);
262 /* if the nick doesnt exist, allow it and process like normal */
265 change_remote_nick(client_p
, source_p
, newts
, parv
[1], 1);
267 else if(IsUnknown(target_p
))
269 exit_client(NULL
, target_p
, &me
, "Overridden");
270 change_remote_nick(client_p
, source_p
, newts
, parv
[1], 1);
272 else if(target_p
== source_p
)
274 /* client changing case of nick */
275 if(strcmp(target_p
->name
, parv
[1]))
276 change_remote_nick(client_p
, source_p
, newts
, parv
[1], 1);
278 /* we've got a collision! */
280 perform_nickchange_collides(source_p
, client_p
, target_p
,
281 parc
, parv
, newts
, parv
[1]);
287 ms_nick(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
289 const char *nick
, *server
;
291 nick
= parc
> 1 ? parv
[1] : "?";
292 server
= parc
> 7 ? parv
[7] : "?";
294 sendto_wallops_flags(UMODE_WALLOP
, &me
,
295 "Link %s cancelled, TS5 nickname %s on %s introduced (old server?)",
296 client_p
->name
, nick
, server
);
297 sendto_server(NULL
, NULL
, CAP_TS6
, NOCAPS
,
298 ":%s WALLOPS :Link %s cancelled, TS5 nickname %s on %s introduced (old server?)",
299 me
.id
, client_p
->name
, nick
, server
);
300 ilog(L_SERVER
, "Link %s cancelled, TS5 nickname %s on %s introduced (old server?)",
301 client_p
->name
, nick
, server
);
303 exit_client(client_p
, client_p
, &me
, "TS5 nickname introduced");
320 ms_uid(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
322 struct Client
*target_p
;
324 char squitreason
[120];
326 newts
= atol(parv
[3]);
330 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
331 "Dropping server %s due to (invalid) command 'UID' "
332 "with %d arguments (expecting 10)", client_p
->name
, parc
);
333 ilog(L_SERVER
, "Excess parameters (%d) for command 'UID' from %s.",
334 parc
, client_p
->name
);
335 snprintf(squitreason
, sizeof squitreason
,
336 "Excess parameters (%d) to %s command, expecting %d",
338 exit_client(client_p
, client_p
, client_p
, squitreason
);
342 /* if nicks erroneous, or too long, kill */
343 if(!clean_nick(parv
[1], 0))
345 bad_nickname(client_p
, parv
[1]);
349 if(!clean_uid(parv
[8], source_p
->id
))
351 snprintf(squitreason
, sizeof squitreason
,
352 "Invalid UID %s for nick %s on %s/%s",
353 parv
[8], parv
[1], source_p
->name
, source_p
->id
);
354 exit_client(client_p
, client_p
, client_p
, squitreason
);
358 if(!clean_username(parv
[5]) || !clean_host(parv
[6]))
360 ServerStats
.is_kill
++;
361 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
362 "Bad user@host: %s@%s From: %s(via %s)",
363 parv
[5], parv
[6], source_p
->name
, client_p
->name
);
364 sendto_one(client_p
, ":%s KILL %s :%s (Bad user@host)", me
.id
, parv
[8], me
.name
);
368 /* check length of clients gecos */
369 if(strlen(parv
[9]) > REALLEN
)
371 char *s
= LOCAL_COPY(parv
[9]);
372 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Long realname from server %s for %s",
373 source_p
->name
, parv
[1]);
378 target_p
= find_named_client(parv
[1]);
382 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
384 else if(IsUnknown(target_p
))
386 exit_client(NULL
, target_p
, &me
, "Overridden");
387 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
389 /* we've got a collision! */
391 perform_nick_collides(source_p
, client_p
, target_p
, parc
, parv
,
392 newts
, parv
[1], parv
[8]);
411 ms_euid(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
413 struct Client
*target_p
;
415 char squitreason
[120];
417 newts
= atol(parv
[3]);
421 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
422 "Dropping server %s due to (invalid) command 'EUID' "
423 "with %d arguments (expecting 12)", client_p
->name
, parc
);
424 ilog(L_SERVER
, "Excess parameters (%d) for command 'EUID' from %s.",
425 parc
, client_p
->name
);
426 snprintf(squitreason
, sizeof squitreason
,
427 "Excess parameters (%d) to %s command, expecting %d",
429 exit_client(client_p
, client_p
, client_p
, squitreason
);
433 /* if nicks erroneous, or too long, kill */
434 if(!clean_nick(parv
[1], 0))
436 bad_nickname(client_p
, parv
[1]);
440 if(!clean_uid(parv
[8], source_p
->id
))
442 snprintf(squitreason
, sizeof squitreason
,
443 "Invalid UID %s for nick %s on %s/%s",
444 parv
[8], parv
[1], source_p
->name
, source_p
->id
);
445 exit_client(client_p
, client_p
, client_p
, squitreason
);
449 if(!clean_username(parv
[5]) || !clean_host(parv
[6]))
451 ServerStats
.is_kill
++;
452 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
453 "Bad user@host: %s@%s From: %s(via %s)",
454 parv
[5], parv
[6], source_p
->name
, client_p
->name
);
455 sendto_one(client_p
, ":%s KILL %s :%s (Bad user@host)", me
.id
, parv
[8], me
.name
);
459 if(strcmp(parv
[9], "*") && !clean_host(parv
[9]))
461 ServerStats
.is_kill
++;
462 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
463 "Bad realhost: %s From: %s(via %s)",
464 parv
[9], source_p
->name
, client_p
->name
);
465 sendto_one(client_p
, ":%s KILL %s :%s (Bad user@host)", me
.id
, parv
[8], me
.name
);
469 /* check length of clients gecos */
470 if(strlen(parv
[11]) > REALLEN
)
472 char *s
= LOCAL_COPY(parv
[11]);
473 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Long realname from server %s for %s",
474 source_p
->name
, parv
[1]);
479 target_p
= find_named_client(parv
[1]);
483 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
485 else if(IsUnknown(target_p
))
487 exit_client(NULL
, target_p
, &me
, "Overridden");
488 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
490 /* we've got a collision! */
492 perform_nick_collides(source_p
, client_p
, target_p
, parc
, parv
,
493 newts
, parv
[1], parv
[8]);
503 ms_save(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
505 struct Client
*target_p
;
507 target_p
= find_id(parv
[1]);
508 if (target_p
== NULL
)
510 if (!IsPerson(target_p
))
511 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
512 "Ignored SAVE message for non-person %s from %s",
513 target_p
->name
, source_p
->name
);
514 else if (IsDigit(target_p
->name
[0]))
515 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
516 "Ignored noop SAVE message for %s from %s",
517 target_p
->name
, source_p
->name
);
518 else if (target_p
->tsinfo
== atol(parv
[2]))
519 save_user(client_p
, source_p
, target_p
);
521 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
522 "Ignored SAVE message for %s from %s",
523 target_p
->name
, source_p
->name
);
529 * input - username to check
530 * output - 0 if erroneous, else 0
534 clean_username(const char *username
)
538 for(; *username
; username
++)
542 if(!IsUserChar(*username
))
554 * input - host to check
555 * output - 0 if erroneous, else 0
559 clean_host(const char *host
)
567 if(!IsHostChar(*host
))
578 clean_uid(const char *uid
, const char *sid
)
582 if(strncmp(uid
, sid
, strlen(sid
)))
603 set_initial_nick(struct Client
*client_p
, struct Client
*source_p
, char *nick
)
605 char note
[NICKLEN
+ 10];
607 /* This had to be copied here to avoid problems.. */
608 source_p
->tsinfo
= rb_current_time();
609 if(source_p
->name
[0])
610 del_from_client_hash(source_p
->name
, source_p
);
612 strcpy(source_p
->name
, nick
);
613 add_to_client_hash(nick
, source_p
);
615 snprintf(note
, sizeof(note
), "Nick: %s", nick
);
616 rb_note(client_p
->localClient
->F
, note
);
618 if(source_p
->flags
& FLAGS_SENTUSER
)
620 /* got user, heres nick. */
621 register_local_user(client_p
, source_p
);
626 change_local_nick(struct Client
*client_p
, struct Client
*source_p
,
627 char *nick
, int dosend
)
629 struct Client
*target_p
;
630 rb_dlink_node
*ptr
, *next_ptr
;
631 struct Channel
*chptr
;
632 char note
[NICKLEN
+ 10];
637 chptr
= find_bannickchange_channel(source_p
);
640 sendto_one_numeric(source_p
, ERR_BANNICKCHANGE
,
641 form_str(ERR_BANNICKCHANGE
),
642 nick
, chptr
->chname
);
645 if((source_p
->localClient
->last_nick_change
+ ConfigFileEntry
.max_nick_time
) < rb_current_time())
646 source_p
->localClient
->number_of_nick_changes
= 0;
648 source_p
->localClient
->last_nick_change
= rb_current_time();
649 source_p
->localClient
->number_of_nick_changes
++;
651 if(ConfigFileEntry
.anti_nick_flood
&& !IsOper(source_p
) &&
652 source_p
->localClient
->number_of_nick_changes
> ConfigFileEntry
.max_nick_changes
)
654 sendto_one(source_p
, form_str(ERR_NICKTOOFAST
),
655 me
.name
, source_p
->name
, source_p
->name
,
656 nick
, ConfigFileEntry
.max_nick_time
);
661 samenick
= irccmp(source_p
->name
, nick
) ? 0 : 1;
663 /* dont reset TS if theyre just changing case of nick */
666 /* force the TS to increase -- jilles */
667 if (source_p
->tsinfo
>= rb_current_time())
670 source_p
->tsinfo
= rb_current_time();
671 monitor_signoff(source_p
);
672 /* we only do bancache for local users -- jilles */
674 invalidate_bancache_user(source_p
);
677 sendto_realops_snomask(SNO_NCHANGE
, L_ALL
,
678 "Nick change: From %s to %s [%s@%s]",
679 source_p
->name
, nick
, source_p
->username
, source_p
->host
);
681 /* send the nick change to the users channels */
682 sendto_common_channels_local(source_p
, NOCAPS
, NOCAPS
, ":%s!%s@%s NICK :%s",
683 source_p
->name
, source_p
->username
, source_p
->host
, nick
);
685 /* send the nick change to servers.. */
688 whowas_add_history(source_p
, 1);
692 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s NICK %s :%ld",
693 use_id(source_p
), nick
, (long) source_p
->tsinfo
);
697 /* Finally, add to hash */
698 del_from_client_hash(source_p
->name
, source_p
);
699 strcpy(source_p
->name
, nick
);
700 add_to_client_hash(nick
, source_p
);
703 monitor_signon(source_p
);
705 /* Make sure everyone that has this client on its accept list
706 * loses that reference.
708 /* we used to call del_all_accepts() here, but theres no real reason
709 * to clear a clients own list of accepted clients. So just remove
710 * them from everyone elses list --anfl
712 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, source_p
->on_allow_list
.head
)
714 target_p
= ptr
->data
;
716 rb_dlinkFindDestroy(source_p
, &target_p
->localClient
->allow_list
);
717 rb_dlinkDestroy(ptr
, &source_p
->on_allow_list
);
720 snprintf(note
, sizeof(note
), "Nick: %s", nick
);
721 rb_note(client_p
->localClient
->F
, note
);
727 * change_remote_nick()
730 change_remote_nick(struct Client
*client_p
, struct Client
*source_p
,
731 time_t newts
, const char *nick
, int dosend
)
734 int samenick
= irccmp(source_p
->name
, nick
) ? 0 : 1;
736 /* client changing their nick - dont reset ts if its same */
739 source_p
->tsinfo
= newts
? newts
: rb_current_time();
740 monitor_signoff(source_p
);
743 sendto_common_channels_local(source_p
, NOCAPS
, NOCAPS
, ":%s!%s@%s NICK :%s",
744 source_p
->name
, source_p
->username
, source_p
->host
, nick
);
748 whowas_add_history(source_p
, 1);
751 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s NICK %s :%ld",
752 use_id(source_p
), nick
, (long) source_p
->tsinfo
);
756 del_from_client_hash(source_p
->name
, source_p
);
758 /* invalidate nick delay when a remote client uses the nick.. */
759 if((nd
= irc_dictionary_retrieve(nd_dict
, nick
)))
762 strcpy(source_p
->name
, nick
);
763 add_to_client_hash(nick
, source_p
);
766 monitor_signon(source_p
);
768 /* remove all accepts pointing to the client */
769 del_all_accepts(source_p
);
775 perform_nick_collides(struct Client
*source_p
, struct Client
*client_p
,
776 struct Client
*target_p
, int parc
, const char *parv
[],
777 time_t newts
, const char *nick
, const char *uid
)
783 use_save
= ConfigFileEntry
.collision_fnc
&& can_save(target_p
) &&
784 uid
!= NULL
&& can_save(source_p
);
785 action
= use_save
? "saved" : "killed";
787 /* if we dont have a ts, or their TS's are the same, kill both */
788 if(!newts
|| !target_p
->tsinfo
|| (newts
== target_p
->tsinfo
))
790 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
791 "Nick collision on %s(%s <- %s)(both %s)",
792 target_p
->name
, target_p
->from
->name
, client_p
->name
, action
);
796 save_user(&me
, &me
, target_p
);
797 ServerStats
.is_save
++;
798 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
800 register_client(client_p
, source_p
,
801 uid
, SAVE_NICKTS
, parc
, parv
);
805 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
806 form_str(ERR_NICKCOLLISION
), target_p
->name
);
808 /* if the new client being introduced has a UID, we need to
809 * issue a KILL for it..
812 sendto_one(client_p
, ":%s KILL %s :%s (Nick collision (new))",
813 me
.id
, uid
, me
.name
);
815 /* we then need to KILL the old client everywhere */
816 kill_client_serv_butone(NULL
, target_p
, "%s (Nick collision (new))", me
.name
);
817 ServerStats
.is_kill
++;
819 target_p
->flags
|= FLAGS_KILLED
;
820 exit_client(client_p
, target_p
, &me
, "Nick collision (new)");
824 /* the timestamps are different */
827 sameuser
= (target_p
->user
) && !irccmp(target_p
->username
, parv
[5])
828 && !irccmp(target_p
->host
, parv
[6]);
830 if((sameuser
&& newts
< target_p
->tsinfo
) ||
831 (!sameuser
&& newts
> target_p
->tsinfo
))
833 /* if we have a UID, then we need to issue a KILL,
834 * otherwise we do nothing and hope that the other
835 * client will collide it..
839 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
841 register_client(client_p
, source_p
,
842 uid
, SAVE_NICKTS
, parc
, parv
);
846 ":%s KILL %s :%s (Nick collision (new))",
847 me
.id
, uid
, me
.name
);
853 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
854 "Nick collision on %s(%s <- %s)(older %s)",
855 target_p
->name
, target_p
->from
->name
,
856 client_p
->name
, action
);
858 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
859 "Nick collision on %s(%s <- %s)(newer %s)",
860 target_p
->name
, target_p
->from
->name
,
861 client_p
->name
, action
);
865 ServerStats
.is_save
++;
866 save_user(&me
, &me
, target_p
);
870 ServerStats
.is_kill
++;
871 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
872 form_str(ERR_NICKCOLLISION
), target_p
->name
);
874 /* now we just need to kill the existing client */
875 kill_client_serv_butone(client_p
, target_p
,
876 "%s (Nick collision (new))", me
.name
);
878 target_p
->flags
|= FLAGS_KILLED
;
879 (void) exit_client(client_p
, target_p
, &me
, "Nick collision");
882 register_client(client_p
, source_p
,
883 nick
, newts
, parc
, parv
);
892 perform_nickchange_collides(struct Client
*source_p
, struct Client
*client_p
,
893 struct Client
*target_p
, int parc
,
894 const char *parv
[], time_t newts
, const char *nick
)
900 use_save
= ConfigFileEntry
.collision_fnc
&& can_save(target_p
) &&
902 action
= use_save
? "saved" : "killed";
904 /* its a client changing nick and causing a collide */
905 if(!newts
|| !target_p
->tsinfo
|| (newts
== target_p
->tsinfo
) || !source_p
->user
)
907 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
908 "Nick change collision from %s to %s(%s <- %s)(both %s)",
909 source_p
->name
, target_p
->name
, target_p
->from
->name
,
910 client_p
->name
, action
);
914 ServerStats
.is_save
+= 2;
915 save_user(&me
, &me
, target_p
);
916 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
917 source_p
->id
, (long)newts
);
918 /* don't send a redundant nick change */
919 if (!IsDigit(source_p
->name
[0]))
920 change_remote_nick(client_p
, source_p
, SAVE_NICKTS
, source_p
->id
, 1);
924 ServerStats
.is_kill
++;
925 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
926 form_str(ERR_NICKCOLLISION
), target_p
->name
);
928 kill_client_serv_butone(NULL
, source_p
, "%s (Nick change collision)", me
.name
);
930 ServerStats
.is_kill
++;
932 kill_client_serv_butone(NULL
, target_p
, "%s (Nick change collision)", me
.name
);
934 target_p
->flags
|= FLAGS_KILLED
;
935 exit_client(NULL
, target_p
, &me
, "Nick collision(new)");
936 source_p
->flags
|= FLAGS_KILLED
;
937 exit_client(client_p
, source_p
, &me
, "Nick collision(old)");
943 sameuser
= !irccmp(target_p
->username
, source_p
->username
) &&
944 !irccmp(target_p
->host
, source_p
->host
);
946 if((sameuser
&& newts
< target_p
->tsinfo
) ||
947 (!sameuser
&& newts
> target_p
->tsinfo
))
950 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
951 "Nick change collision from %s to %s(%s <- %s)(older %s)",
952 source_p
->name
, target_p
->name
,
953 target_p
->from
->name
, client_p
->name
, action
);
955 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
956 "Nick change collision from %s to %s(%s <- %s)(newer %s)",
957 source_p
->name
, target_p
->name
,
958 target_p
->from
->name
, client_p
->name
, action
);
962 ServerStats
.is_save
++;
963 /* can't broadcast a SAVE because the
964 * nickchange has happened at client_p
965 * but not in other directions -- jilles */
966 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
967 source_p
->id
, (long)newts
);
968 /* send a :<id> NICK <id> <ts> (!) */
969 if (!IsDigit(source_p
->name
[0]))
970 change_remote_nick(client_p
, source_p
, SAVE_NICKTS
, source_p
->id
, 1);
974 ServerStats
.is_kill
++;
976 sendto_one_numeric(source_p
, ERR_NICKCOLLISION
,
977 form_str(ERR_NICKCOLLISION
), source_p
->name
);
979 /* kill the client issuing the nickchange */
980 kill_client_serv_butone(client_p
, source_p
,
981 "%s (Nick change collision)", me
.name
);
983 source_p
->flags
|= FLAGS_KILLED
;
986 exit_client(client_p
, source_p
, &me
, "Nick collision(old)");
988 exit_client(client_p
, source_p
, &me
, "Nick collision(new)");
995 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
996 "Nick collision on %s(%s <- %s)(older %s)",
997 target_p
->name
, target_p
->from
->name
,
998 client_p
->name
, action
);
1000 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
1001 "Nick collision on %s(%s <- %s)(newer %s)",
1002 target_p
->name
, target_p
->from
->name
,
1003 client_p
->name
, action
);
1007 ServerStats
.is_save
++;
1008 save_user(&me
, &me
, target_p
);
1012 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
1013 form_str(ERR_NICKCOLLISION
), target_p
->name
);
1015 /* kill the client who existed before hand */
1016 kill_client_serv_butone(client_p
, target_p
, "%s (Nick collision)", me
.name
);
1018 ServerStats
.is_kill
++;
1020 target_p
->flags
|= FLAGS_KILLED
;
1021 (void) exit_client(client_p
, target_p
, &me
, "Nick collision");
1026 change_remote_nick(client_p
, source_p
, newts
, nick
, 1);
1032 register_client(struct Client
*client_p
, struct Client
*server
,
1033 const char *nick
, time_t newts
, int parc
, const char *parv
[])
1035 struct Client
*source_p
;
1037 struct nd_entry
*nd
;
1041 source_p
= make_client(client_p
);
1042 user
= make_user(source_p
);
1043 rb_dlinkAddTail(source_p
, &source_p
->node
, &global_client_list
);
1045 source_p
->hopcount
= atoi(parv
[2]);
1046 source_p
->tsinfo
= newts
;
1048 strcpy(source_p
->name
, nick
);
1049 rb_strlcpy(source_p
->username
, parv
[5], sizeof(source_p
->username
));
1050 rb_strlcpy(source_p
->host
, parv
[6], sizeof(source_p
->host
));
1051 rb_strlcpy(source_p
->orighost
, source_p
->host
, sizeof(source_p
->orighost
));
1055 rb_strlcpy(source_p
->info
, parv
[11], sizeof(source_p
->info
));
1056 rb_strlcpy(source_p
->sockhost
, parv
[7], sizeof(source_p
->sockhost
));
1057 rb_strlcpy(source_p
->id
, parv
[8], sizeof(source_p
->id
));
1058 add_to_id_hash(source_p
->id
, source_p
);
1059 if (strcmp(parv
[9], "*"))
1061 rb_strlcpy(source_p
->orighost
, parv
[9], sizeof(source_p
->orighost
));
1062 if (irccmp(source_p
->host
, source_p
->orighost
))
1063 SetDynSpoof(source_p
);
1065 if (strcmp(parv
[10], "*"))
1066 rb_strlcpy(source_p
->user
->suser
, parv
[10], sizeof(source_p
->user
->suser
));
1070 rb_strlcpy(source_p
->info
, parv
[9], sizeof(source_p
->info
));
1071 rb_strlcpy(source_p
->sockhost
, parv
[7], sizeof(source_p
->sockhost
));
1072 rb_strlcpy(source_p
->id
, parv
[8], sizeof(source_p
->id
));
1073 add_to_id_hash(source_p
->id
, source_p
);
1080 /* remove any nd entries for this nick */
1081 if((nd
= irc_dictionary_retrieve(nd_dict
, nick
)))
1084 add_to_client_hash(nick
, source_p
);
1085 add_to_hostname_hash(source_p
->orighost
, source_p
);
1086 monitor_signon(source_p
);
1091 flag
= user_modes
[(unsigned char) *m
];
1093 if(flag
& UMODE_SERVICE
)
1098 RB_DLINK_FOREACH(ptr
, service_list
.head
)
1100 if(!irccmp((const char *) ptr
->data
, server
->name
))
1114 /* increment +i count if theyre invis */
1115 if(!(source_p
->umodes
& UMODE_INVISIBLE
) && (flag
& UMODE_INVISIBLE
))
1118 /* increment opered count if theyre opered */
1119 if(!(source_p
->umodes
& UMODE_OPER
) && (flag
& UMODE_OPER
))
1122 source_p
->umodes
|= flag
;
1126 if(IsOper(source_p
) && !IsService(source_p
))
1127 rb_dlinkAddAlloc(source_p
, &oper_list
);
1129 SetRemoteClient(source_p
);
1131 if(++Count
.total
> Count
.max_tot
)
1132 Count
.max_tot
= Count
.total
;
1134 source_p
->servptr
= server
;
1136 rb_dlinkAdd(source_p
, &source_p
->lnode
, &source_p
->servptr
->serv
->users
);
1138 call_hook(h_new_remote_user
, source_p
);
1140 return (introduce_client(client_p
, source_p
, user
, nick
, parc
== 12));
1143 /* Check if we can do SAVE. target_p can be a client to save or a
1144 * server introducing a client -- jilles */
1146 can_save(struct Client
*target_p
)
1148 struct Client
*serv_p
;
1150 if (MyClient(target_p
))
1152 if (!has_id(target_p
))
1154 serv_p
= IsServer(target_p
) ? target_p
: target_p
->servptr
;
1155 while (serv_p
!= NULL
&& serv_p
!= &me
)
1157 if (!(serv_p
->serv
->caps
& CAP_SAVE
))
1159 serv_p
= serv_p
->servptr
;
1161 return serv_p
== &me
;
1165 save_user(struct Client
*client_p
, struct Client
*source_p
,
1166 struct Client
*target_p
)
1168 if (!MyConnect(target_p
) && (!has_id(target_p
) || !IsCapable(target_p
->from
, CAP_SAVE
)))
1170 /* This shouldn't happen */
1171 /* Note we only need SAVE support in this direction */
1172 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1173 "Killed %s!%s@%s for nick collision detected by %s (%s does not support SAVE)",
1174 target_p
->name
, target_p
->username
, target_p
->host
, source_p
->name
, target_p
->from
->name
);
1175 kill_client_serv_butone(NULL
, target_p
, "%s (Nick collision (no SAVE support))", me
.name
);
1176 ServerStats
.is_kill
++;
1178 target_p
->flags
|= FLAGS_KILLED
;
1179 (void) exit_client(NULL
, target_p
, &me
, "Nick collision (no SAVE support)");
1182 sendto_server(client_p
, NULL
, CAP_SAVE
|CAP_TS6
, NOCAPS
, ":%s SAVE %s %ld",
1183 source_p
->id
, target_p
->id
, (long)target_p
->tsinfo
);
1184 sendto_server(client_p
, NULL
, CAP_TS6
, CAP_SAVE
, ":%s NICK %s :%ld",
1185 target_p
->id
, target_p
->id
, (long)SAVE_NICKTS
);
1186 if (!IsMe(client_p
))
1187 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
1188 "Received SAVE message for %s from %s",
1189 target_p
->name
, source_p
->name
);
1190 if (MyClient(target_p
))
1192 sendto_one_numeric(target_p
, RPL_SAVENICK
,
1193 form_str(RPL_SAVENICK
), target_p
->id
);
1194 change_local_nick(target_p
, target_p
, target_p
->id
, 0);
1195 target_p
->tsinfo
= SAVE_NICKTS
;
1198 change_remote_nick(target_p
, target_p
, SAVE_NICKTS
, target_p
->id
, 0);
1201 static void bad_nickname(struct Client
*client_p
, const char *nick
)
1203 char squitreason
[100];
1205 sendto_wallops_flags(UMODE_WALLOP
, &me
,
1206 "Squitting %s because of bad nickname %s (NICKLEN mismatch?)",
1207 client_p
->name
, nick
);
1208 sendto_server(NULL
, NULL
, CAP_TS6
, NOCAPS
,
1209 ":%s WALLOPS :Squitting %s because of bad nickname %s (NICKLEN mismatch?)",
1210 me
.id
, client_p
->name
, nick
);
1211 ilog(L_SERVER
, "Link %s cancelled, bad nickname %s sent (NICKLEN mismatch?)",
1212 client_p
->name
, nick
);
1214 snprintf(squitreason
, sizeof squitreason
,
1215 "Bad nickname introduced [%s]", nick
);
1216 exit_client(client_p
, client_p
, &me
, squitreason
);