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
46 #include "s_newconf.h"
50 /* Give all UID nicks the same TS. This ensures nick TS is always the same on
51 * all servers for each nick-user pair, also if a user with a UID nick changes
52 * their nick but is collided again (the server detecting the collision will
53 * not propagate the nick change further). -- jilles
55 #define SAVE_NICKTS 100
57 static int mr_nick(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
58 static int m_nick(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
59 static int mc_nick(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
60 static int ms_nick(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
61 static int ms_uid(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
62 static int ms_euid(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
63 static int ms_save(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
64 static int can_save(struct Client
*);
65 static void save_user(struct Client
*, struct Client
*, struct Client
*);
66 static void bad_nickname(struct Client
*, const char *);
68 struct Message nick_msgtab
= {
70 {{mr_nick
, 0}, {m_nick
, 0}, {mc_nick
, 3}, {ms_nick
, 0}, mg_ignore
, {m_nick
, 0}}
72 struct Message uid_msgtab
= {
74 {mg_ignore
, mg_ignore
, mg_ignore
, {ms_uid
, 9}, mg_ignore
, mg_ignore
}
76 struct Message euid_msgtab
= {
78 {mg_ignore
, mg_ignore
, mg_ignore
, {ms_euid
, 12}, mg_ignore
, mg_ignore
}
80 struct Message save_msgtab
= {
82 {mg_ignore
, mg_ignore
, mg_ignore
, {ms_save
, 3}, mg_ignore
, mg_ignore
}
85 mapi_clist_av1 nick_clist
[] = { &nick_msgtab
, &uid_msgtab
, &euid_msgtab
,
88 static const char nick_desc
[] =
89 "Provides the NICK client and server commands as well as the UID, EUID, and SAVE TS6 server commands";
91 DECLARE_MODULE_AV2(nick
, NULL
, NULL
, nick_clist
, NULL
, NULL
, NULL
, NULL
, nick_desc
);
93 static int change_remote_nick(struct Client
*, struct Client
*, time_t,
96 static int clean_username(const char *);
97 static int clean_host(const char *);
98 static int clean_uid(const char *uid
, const char *sid
);
100 static void set_initial_nick(struct Client
*client_p
, struct Client
*source_p
, char *nick
);
101 static void change_local_nick(struct Client
*client_p
, struct Client
*source_p
, char *nick
, int);
102 static int register_client(struct Client
*client_p
, struct Client
*server
,
103 const char *nick
, time_t newts
, int parc
, const char *parv
[]);
105 static int perform_nick_collides(struct Client
*, struct Client
*,
106 struct Client
*, int, const char **,
107 time_t, const char *, const char *);
108 static int perform_nickchange_collides(struct Client
*, struct Client
*,
109 struct Client
*, int, const char **, time_t, const char *);
115 mr_nick(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
117 struct Client
*target_p
;
120 if (strlen(client_p
->id
) == 3)
122 exit_client(client_p
, client_p
, client_p
, "Mixing client and server protocol");
126 if(parc
< 2 || EmptyString(parv
[1]))
128 sendto_one(source_p
, form_str(ERR_NONICKNAMEGIVEN
),
129 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
);
133 /* copy the nick and terminate it */
134 rb_strlcpy(nick
, parv
[1], ConfigFileEntry
.nicklen
);
136 /* check the nickname is ok */
137 if(!clean_nick(nick
, 1))
139 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
),
140 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, parv
[1]);
144 /* check if the nick is resv'd */
145 if(find_nick_resv(nick
))
147 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
),
148 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, nick
);
152 if(rb_dictionary_find(nd_dict
, nick
))
154 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
155 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, nick
);
159 if((target_p
= find_named_client(nick
)) == NULL
)
160 set_initial_nick(client_p
, source_p
, nick
);
161 else if(source_p
== target_p
)
162 strcpy(source_p
->name
, nick
);
164 sendto_one(source_p
, form_str(ERR_NICKNAMEINUSE
), me
.name
, "*", nick
);
173 m_nick(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
175 struct Client
*target_p
;
178 if(parc
< 2 || EmptyString(parv
[1]))
180 sendto_one(source_p
, form_str(ERR_NONICKNAMEGIVEN
), me
.name
, source_p
->name
);
184 /* mark end of grace period, to prevent nickflooding */
185 if(!IsFloodDone(source_p
))
186 flood_endgrace(source_p
);
188 /* terminate nick to NICKLEN, we dont want clean_nick() to error! */
189 rb_strlcpy(nick
, parv
[1], ConfigFileEntry
.nicklen
);
191 /* check the nickname is ok */
192 if(!clean_nick(nick
, 1))
194 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
), me
.name
, source_p
->name
, nick
);
198 if(!IsExemptResv(source_p
) && find_nick_resv(nick
))
200 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
), me
.name
, source_p
->name
, nick
);
204 if(rb_dictionary_find(nd_dict
, nick
))
206 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
207 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, nick
);
211 if((target_p
= find_named_client(nick
)))
213 /* If(target_p == source_p) the client is changing nicks between
214 * equivalent nicknames ie: [nick] -> {nick}
216 if(target_p
== source_p
)
218 /* check the nick isnt exactly the same */
219 if(strcmp(target_p
->name
, nick
))
220 change_local_nick(client_p
, source_p
, nick
, 1);
224 /* drop unregged client */
225 else if(IsUnknown(target_p
))
227 exit_client(NULL
, target_p
, &me
, "Overridden");
228 change_local_nick(client_p
, source_p
, nick
, 1);
231 sendto_one(source_p
, form_str(ERR_NICKNAMEINUSE
), me
.name
, source_p
->name
, nick
);
236 change_local_nick(client_p
, source_p
, nick
, 1);
243 * server -> server nick change
245 * parv[2] = TS when nick change
248 mc_nick(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
250 struct Client
*target_p
;
253 /* if nicks erroneous, or too long, kill */
254 if(!clean_nick(parv
[1], 0))
256 bad_nickname(client_p
, parv
[1]);
260 newts
= atol(parv
[2]);
261 target_p
= find_named_client(parv
[1]);
263 /* if the nick doesnt exist, allow it and process like normal */
266 change_remote_nick(client_p
, source_p
, newts
, parv
[1], 1);
268 else if(IsUnknown(target_p
))
270 exit_client(NULL
, target_p
, &me
, "Overridden");
271 change_remote_nick(client_p
, source_p
, newts
, parv
[1], 1);
273 else if(target_p
== source_p
)
275 /* client changing case of nick */
276 if(strcmp(target_p
->name
, parv
[1]))
277 change_remote_nick(client_p
, source_p
, newts
, parv
[1], 1);
279 /* we've got a collision! */
281 perform_nickchange_collides(source_p
, client_p
, target_p
,
282 parc
, parv
, newts
, parv
[1]);
288 ms_nick(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
290 const char *nick
, *server
;
292 nick
= parc
> 1 ? parv
[1] : "?";
293 server
= parc
> 7 ? parv
[7] : "?";
295 sendto_wallops_flags(UMODE_WALLOP
, &me
,
296 "Link %s cancelled, TS5 nickname %s on %s introduced (old server?)",
297 client_p
->name
, nick
, server
);
298 sendto_server(NULL
, NULL
, CAP_TS6
, NOCAPS
,
299 ":%s WALLOPS :Link %s cancelled, TS5 nickname %s on %s introduced (old server?)",
300 me
.id
, client_p
->name
, nick
, server
);
301 ilog(L_SERVER
, "Link %s cancelled, TS5 nickname %s on %s introduced (old server?)",
302 client_p
->name
, nick
, server
);
304 exit_client(client_p
, client_p
, &me
, "TS5 nickname introduced");
321 ms_uid(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
323 struct Client
*target_p
;
325 char squitreason
[120];
327 newts
= atol(parv
[3]);
331 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
332 "Dropping server %s due to (invalid) command 'UID' "
333 "with %d arguments (expecting 10)", client_p
->name
, parc
);
334 ilog(L_SERVER
, "Excess parameters (%d) for command 'UID' from %s.",
335 parc
, client_p
->name
);
336 snprintf(squitreason
, sizeof squitreason
,
337 "Excess parameters (%d) to %s command, expecting %d",
339 exit_client(client_p
, client_p
, client_p
, squitreason
);
343 /* if nicks erroneous, or too long, kill */
344 if(!clean_nick(parv
[1], 0))
346 bad_nickname(client_p
, parv
[1]);
350 if(!clean_uid(parv
[8], source_p
->id
))
352 snprintf(squitreason
, sizeof squitreason
,
353 "Invalid UID %s for nick %s on %s/%s",
354 parv
[8], parv
[1], source_p
->name
, source_p
->id
);
355 exit_client(client_p
, client_p
, client_p
, squitreason
);
359 if(!clean_username(parv
[5]) || !clean_host(parv
[6]))
361 ServerStats
.is_kill
++;
362 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
363 "Bad user@host: %s@%s From: %s(via %s)",
364 parv
[5], parv
[6], source_p
->name
, client_p
->name
);
365 sendto_one(client_p
, ":%s KILL %s :%s (Bad user@host)", me
.id
, parv
[8], me
.name
);
369 /* check length of clients gecos */
370 if(strlen(parv
[9]) > REALLEN
)
372 char *s
= LOCAL_COPY(parv
[9]);
373 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Long realname from server %s for %s",
374 source_p
->name
, parv
[1]);
379 target_p
= find_named_client(parv
[1]);
383 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
385 else if(IsUnknown(target_p
))
387 exit_client(NULL
, target_p
, &me
, "Overridden");
388 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
390 /* we've got a collision! */
392 perform_nick_collides(source_p
, client_p
, target_p
, parc
, parv
,
393 newts
, parv
[1], parv
[8]);
412 ms_euid(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
414 struct Client
*target_p
;
416 char squitreason
[120];
418 newts
= atol(parv
[3]);
422 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
423 "Dropping server %s due to (invalid) command 'EUID' "
424 "with %d arguments (expecting 12)", client_p
->name
, parc
);
425 ilog(L_SERVER
, "Excess parameters (%d) for command 'EUID' from %s.",
426 parc
, client_p
->name
);
427 snprintf(squitreason
, sizeof squitreason
,
428 "Excess parameters (%d) to %s command, expecting %d",
430 exit_client(client_p
, client_p
, client_p
, squitreason
);
434 /* if nicks erroneous, or too long, kill */
435 if(!clean_nick(parv
[1], 0))
437 bad_nickname(client_p
, parv
[1]);
441 if(!clean_uid(parv
[8], source_p
->id
))
443 snprintf(squitreason
, sizeof squitreason
,
444 "Invalid UID %s for nick %s on %s/%s",
445 parv
[8], parv
[1], source_p
->name
, source_p
->id
);
446 exit_client(client_p
, client_p
, client_p
, squitreason
);
450 if(!clean_username(parv
[5]) || !clean_host(parv
[6]))
452 ServerStats
.is_kill
++;
453 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
454 "Bad user@host: %s@%s From: %s(via %s)",
455 parv
[5], parv
[6], source_p
->name
, client_p
->name
);
456 sendto_one(client_p
, ":%s KILL %s :%s (Bad user@host)", me
.id
, parv
[8], me
.name
);
460 if(strcmp(parv
[9], "*") && !clean_host(parv
[9]))
462 ServerStats
.is_kill
++;
463 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
464 "Bad realhost: %s From: %s(via %s)",
465 parv
[9], source_p
->name
, client_p
->name
);
466 sendto_one(client_p
, ":%s KILL %s :%s (Bad user@host)", me
.id
, parv
[8], me
.name
);
470 /* check length of clients gecos */
471 if(strlen(parv
[11]) > REALLEN
)
473 char *s
= LOCAL_COPY(parv
[11]);
474 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Long realname from server %s for %s",
475 source_p
->name
, parv
[1]);
480 target_p
= find_named_client(parv
[1]);
484 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
486 else if(IsUnknown(target_p
))
488 exit_client(NULL
, target_p
, &me
, "Overridden");
489 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
491 /* we've got a collision! */
493 perform_nick_collides(source_p
, client_p
, target_p
, parc
, parv
,
494 newts
, parv
[1], parv
[8]);
504 ms_save(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
506 struct Client
*target_p
;
508 target_p
= find_id(parv
[1]);
509 if (target_p
== NULL
)
511 if (!IsPerson(target_p
))
512 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
513 "Ignored SAVE message for non-person %s from %s",
514 target_p
->name
, source_p
->name
);
515 else if (IsDigit(target_p
->name
[0]))
516 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
517 "Ignored noop SAVE message for %s from %s",
518 target_p
->name
, source_p
->name
);
519 else if (target_p
->tsinfo
== atol(parv
[2]))
520 save_user(client_p
, source_p
, target_p
);
522 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
523 "Ignored SAVE message for %s from %s",
524 target_p
->name
, source_p
->name
);
530 * input - username to check
531 * output - 0 if erroneous, else 0
535 clean_username(const char *username
)
539 for(; *username
; username
++)
543 if(!IsUserChar(*username
))
555 * input - host to check
556 * output - 0 if erroneous, else 0
560 clean_host(const char *host
)
568 if(!IsHostChar(*host
))
579 clean_uid(const char *uid
, const char *sid
)
583 if(strncmp(uid
, sid
, strlen(sid
)))
604 set_initial_nick(struct Client
*client_p
, struct Client
*source_p
, char *nick
)
606 char note
[NICKLEN
+ 10];
608 /* This had to be copied here to avoid problems.. */
609 source_p
->tsinfo
= rb_current_time();
610 if(source_p
->name
[0])
611 del_from_client_hash(source_p
->name
, source_p
);
613 strcpy(source_p
->name
, nick
);
614 add_to_client_hash(nick
, source_p
);
616 snprintf(note
, sizeof(note
), "Nick: %s", nick
);
617 rb_note(client_p
->localClient
->F
, note
);
619 if(source_p
->flags
& FLAGS_SENTUSER
)
621 /* got user, heres nick. */
622 register_local_user(client_p
, source_p
);
627 change_local_nick(struct Client
*client_p
, struct Client
*source_p
,
628 char *nick
, int dosend
)
630 struct Client
*target_p
;
631 rb_dlink_node
*ptr
, *next_ptr
;
632 struct Channel
*chptr
;
633 char note
[NICKLEN
+ 10];
638 chptr
= find_bannickchange_channel(source_p
);
641 sendto_one_numeric(source_p
, ERR_BANNICKCHANGE
,
642 form_str(ERR_BANNICKCHANGE
),
643 nick
, chptr
->chname
);
646 if((source_p
->localClient
->last_nick_change
+ ConfigFileEntry
.max_nick_time
) < rb_current_time())
647 source_p
->localClient
->number_of_nick_changes
= 0;
649 source_p
->localClient
->last_nick_change
= rb_current_time();
650 source_p
->localClient
->number_of_nick_changes
++;
652 if(ConfigFileEntry
.anti_nick_flood
&& !IsOper(source_p
) &&
653 source_p
->localClient
->number_of_nick_changes
> ConfigFileEntry
.max_nick_changes
)
655 sendto_one(source_p
, form_str(ERR_NICKTOOFAST
),
656 me
.name
, source_p
->name
, source_p
->name
,
657 nick
, ConfigFileEntry
.max_nick_time
);
662 samenick
= irccmp(source_p
->name
, nick
) ? 0 : 1;
664 /* dont reset TS if theyre just changing case of nick */
667 /* force the TS to increase -- jilles */
668 if (source_p
->tsinfo
>= rb_current_time())
671 source_p
->tsinfo
= rb_current_time();
672 monitor_signoff(source_p
);
673 /* we only do bancache for local users -- jilles */
675 invalidate_bancache_user(source_p
);
678 sendto_realops_snomask(SNO_NCHANGE
, L_ALL
,
679 "Nick change: From %s to %s [%s@%s]",
680 source_p
->name
, nick
, source_p
->username
, source_p
->host
);
682 /* send the nick change to the users channels */
683 sendto_common_channels_local(source_p
, NOCAPS
, NOCAPS
, ":%s!%s@%s NICK :%s",
684 source_p
->name
, source_p
->username
, source_p
->host
, nick
);
686 /* send the nick change to servers.. */
689 whowas_add_history(source_p
, 1);
693 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s NICK %s :%ld",
694 use_id(source_p
), nick
, (long) source_p
->tsinfo
);
698 /* Finally, add to hash */
699 del_from_client_hash(source_p
->name
, source_p
);
700 strcpy(source_p
->name
, nick
);
701 add_to_client_hash(nick
, source_p
);
704 monitor_signon(source_p
);
706 /* Make sure everyone that has this client on its accept list
707 * loses that reference.
709 /* we used to call del_all_accepts() here, but theres no real reason
710 * to clear a clients own list of accepted clients. So just remove
711 * them from everyone elses list --anfl
713 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, source_p
->on_allow_list
.head
)
715 target_p
= ptr
->data
;
717 rb_dlinkFindDestroy(source_p
, &target_p
->localClient
->allow_list
);
718 rb_dlinkDestroy(ptr
, &source_p
->on_allow_list
);
721 snprintf(note
, sizeof(note
), "Nick: %s", nick
);
722 rb_note(client_p
->localClient
->F
, note
);
728 * change_remote_nick()
731 change_remote_nick(struct Client
*client_p
, struct Client
*source_p
,
732 time_t newts
, const char *nick
, int dosend
)
735 int samenick
= irccmp(source_p
->name
, nick
) ? 0 : 1;
737 /* client changing their nick - dont reset ts if its same */
740 source_p
->tsinfo
= newts
? newts
: rb_current_time();
741 monitor_signoff(source_p
);
744 sendto_common_channels_local(source_p
, NOCAPS
, NOCAPS
, ":%s!%s@%s NICK :%s",
745 source_p
->name
, source_p
->username
, source_p
->host
, nick
);
749 whowas_add_history(source_p
, 1);
752 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s NICK %s :%ld",
753 use_id(source_p
), nick
, (long) source_p
->tsinfo
);
757 del_from_client_hash(source_p
->name
, source_p
);
759 /* invalidate nick delay when a remote client uses the nick.. */
760 if((nd
= rb_dictionary_retrieve(nd_dict
, nick
)))
763 strcpy(source_p
->name
, nick
);
764 add_to_client_hash(nick
, source_p
);
767 monitor_signon(source_p
);
769 /* remove all accepts pointing to the client */
770 del_all_accepts(source_p
);
776 perform_nick_collides(struct Client
*source_p
, struct Client
*client_p
,
777 struct Client
*target_p
, int parc
, const char *parv
[],
778 time_t newts
, const char *nick
, const char *uid
)
784 use_save
= ConfigFileEntry
.collision_fnc
&& can_save(target_p
) &&
785 uid
!= NULL
&& can_save(source_p
);
786 action
= use_save
? "saved" : "killed";
788 /* if we dont have a ts, or their TS's are the same, kill both */
789 if(!newts
|| !target_p
->tsinfo
|| (newts
== target_p
->tsinfo
))
791 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
792 "Nick collision on %s(%s <- %s)(both %s)",
793 target_p
->name
, target_p
->from
->name
, client_p
->name
, action
);
797 save_user(&me
, &me
, target_p
);
798 ServerStats
.is_save
++;
799 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
801 register_client(client_p
, source_p
,
802 uid
, SAVE_NICKTS
, parc
, parv
);
806 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
807 form_str(ERR_NICKCOLLISION
), target_p
->name
);
809 /* if the new client being introduced has a UID, we need to
810 * issue a KILL for it..
813 sendto_one(client_p
, ":%s KILL %s :%s (Nick collision (new))",
814 me
.id
, uid
, me
.name
);
816 /* we then need to KILL the old client everywhere */
817 kill_client_serv_butone(NULL
, target_p
, "%s (Nick collision (new))", me
.name
);
818 ServerStats
.is_kill
++;
820 target_p
->flags
|= FLAGS_KILLED
;
821 exit_client(client_p
, target_p
, &me
, "Nick collision (new)");
825 /* the timestamps are different */
828 sameuser
= (target_p
->user
) && !irccmp(target_p
->username
, parv
[5])
829 && !irccmp(target_p
->host
, parv
[6]);
831 if((sameuser
&& newts
< target_p
->tsinfo
) ||
832 (!sameuser
&& newts
> target_p
->tsinfo
))
834 /* if we have a UID, then we need to issue a KILL,
835 * otherwise we do nothing and hope that the other
836 * client will collide it..
840 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
842 register_client(client_p
, source_p
,
843 uid
, SAVE_NICKTS
, parc
, parv
);
847 ":%s KILL %s :%s (Nick collision (new))",
848 me
.id
, uid
, me
.name
);
854 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
855 "Nick collision on %s(%s <- %s)(older %s)",
856 target_p
->name
, target_p
->from
->name
,
857 client_p
->name
, action
);
859 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
860 "Nick collision on %s(%s <- %s)(newer %s)",
861 target_p
->name
, target_p
->from
->name
,
862 client_p
->name
, action
);
866 ServerStats
.is_save
++;
867 save_user(&me
, &me
, target_p
);
871 ServerStats
.is_kill
++;
872 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
873 form_str(ERR_NICKCOLLISION
), target_p
->name
);
875 /* now we just need to kill the existing client */
876 kill_client_serv_butone(client_p
, target_p
,
877 "%s (Nick collision (new))", me
.name
);
879 target_p
->flags
|= FLAGS_KILLED
;
880 (void) exit_client(client_p
, target_p
, &me
, "Nick collision");
883 register_client(client_p
, source_p
,
884 nick
, newts
, parc
, parv
);
893 perform_nickchange_collides(struct Client
*source_p
, struct Client
*client_p
,
894 struct Client
*target_p
, int parc
,
895 const char *parv
[], time_t newts
, const char *nick
)
901 use_save
= ConfigFileEntry
.collision_fnc
&& can_save(target_p
) &&
903 action
= use_save
? "saved" : "killed";
905 /* its a client changing nick and causing a collide */
906 if(!newts
|| !target_p
->tsinfo
|| (newts
== target_p
->tsinfo
) || !source_p
->user
)
908 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
909 "Nick change collision from %s to %s(%s <- %s)(both %s)",
910 source_p
->name
, target_p
->name
, target_p
->from
->name
,
911 client_p
->name
, action
);
915 ServerStats
.is_save
+= 2;
916 save_user(&me
, &me
, target_p
);
917 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
918 source_p
->id
, (long)newts
);
919 /* don't send a redundant nick change */
920 if (!IsDigit(source_p
->name
[0]))
921 change_remote_nick(client_p
, source_p
, SAVE_NICKTS
, source_p
->id
, 1);
925 ServerStats
.is_kill
++;
926 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
927 form_str(ERR_NICKCOLLISION
), target_p
->name
);
929 kill_client_serv_butone(NULL
, source_p
, "%s (Nick change collision)", me
.name
);
931 ServerStats
.is_kill
++;
933 kill_client_serv_butone(NULL
, target_p
, "%s (Nick change collision)", me
.name
);
935 target_p
->flags
|= FLAGS_KILLED
;
936 exit_client(NULL
, target_p
, &me
, "Nick collision(new)");
937 source_p
->flags
|= FLAGS_KILLED
;
938 exit_client(client_p
, source_p
, &me
, "Nick collision(old)");
944 sameuser
= !irccmp(target_p
->username
, source_p
->username
) &&
945 !irccmp(target_p
->host
, source_p
->host
);
947 if((sameuser
&& newts
< target_p
->tsinfo
) ||
948 (!sameuser
&& newts
> target_p
->tsinfo
))
951 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
952 "Nick change collision from %s to %s(%s <- %s)(older %s)",
953 source_p
->name
, target_p
->name
,
954 target_p
->from
->name
, client_p
->name
, action
);
956 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
957 "Nick change collision from %s to %s(%s <- %s)(newer %s)",
958 source_p
->name
, target_p
->name
,
959 target_p
->from
->name
, client_p
->name
, action
);
963 ServerStats
.is_save
++;
964 /* can't broadcast a SAVE because the
965 * nickchange has happened at client_p
966 * but not in other directions -- jilles */
967 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
968 source_p
->id
, (long)newts
);
969 /* send a :<id> NICK <id> <ts> (!) */
970 if (!IsDigit(source_p
->name
[0]))
971 change_remote_nick(client_p
, source_p
, SAVE_NICKTS
, source_p
->id
, 1);
975 ServerStats
.is_kill
++;
977 sendto_one_numeric(source_p
, ERR_NICKCOLLISION
,
978 form_str(ERR_NICKCOLLISION
), source_p
->name
);
980 /* kill the client issuing the nickchange */
981 kill_client_serv_butone(client_p
, source_p
,
982 "%s (Nick change collision)", me
.name
);
984 source_p
->flags
|= FLAGS_KILLED
;
987 exit_client(client_p
, source_p
, &me
, "Nick collision(old)");
989 exit_client(client_p
, source_p
, &me
, "Nick collision(new)");
996 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
997 "Nick collision on %s(%s <- %s)(older %s)",
998 target_p
->name
, target_p
->from
->name
,
999 client_p
->name
, action
);
1001 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
1002 "Nick collision on %s(%s <- %s)(newer %s)",
1003 target_p
->name
, target_p
->from
->name
,
1004 client_p
->name
, action
);
1008 ServerStats
.is_save
++;
1009 save_user(&me
, &me
, target_p
);
1013 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
1014 form_str(ERR_NICKCOLLISION
), target_p
->name
);
1016 /* kill the client who existed before hand */
1017 kill_client_serv_butone(client_p
, target_p
, "%s (Nick collision)", me
.name
);
1019 ServerStats
.is_kill
++;
1021 target_p
->flags
|= FLAGS_KILLED
;
1022 (void) exit_client(client_p
, target_p
, &me
, "Nick collision");
1027 change_remote_nick(client_p
, source_p
, newts
, nick
, 1);
1033 register_client(struct Client
*client_p
, struct Client
*server
,
1034 const char *nick
, time_t newts
, int parc
, const char *parv
[])
1036 struct Client
*source_p
;
1038 struct nd_entry
*nd
;
1042 source_p
= make_client(client_p
);
1043 user
= make_user(source_p
);
1044 rb_dlinkAddTail(source_p
, &source_p
->node
, &global_client_list
);
1046 source_p
->hopcount
= atoi(parv
[2]);
1047 source_p
->tsinfo
= newts
;
1049 strcpy(source_p
->name
, nick
);
1050 rb_strlcpy(source_p
->username
, parv
[5], sizeof(source_p
->username
));
1051 rb_strlcpy(source_p
->host
, parv
[6], sizeof(source_p
->host
));
1052 rb_strlcpy(source_p
->orighost
, source_p
->host
, sizeof(source_p
->orighost
));
1056 rb_strlcpy(source_p
->info
, parv
[11], sizeof(source_p
->info
));
1057 rb_strlcpy(source_p
->sockhost
, parv
[7], sizeof(source_p
->sockhost
));
1058 rb_strlcpy(source_p
->id
, parv
[8], sizeof(source_p
->id
));
1059 add_to_id_hash(source_p
->id
, source_p
);
1060 if (strcmp(parv
[9], "*"))
1062 rb_strlcpy(source_p
->orighost
, parv
[9], sizeof(source_p
->orighost
));
1063 if (irccmp(source_p
->host
, source_p
->orighost
))
1064 SetDynSpoof(source_p
);
1066 if (strcmp(parv
[10], "*"))
1067 rb_strlcpy(source_p
->user
->suser
, parv
[10], sizeof(source_p
->user
->suser
));
1071 rb_strlcpy(source_p
->info
, parv
[9], sizeof(source_p
->info
));
1072 rb_strlcpy(source_p
->sockhost
, parv
[7], sizeof(source_p
->sockhost
));
1073 rb_strlcpy(source_p
->id
, parv
[8], sizeof(source_p
->id
));
1074 add_to_id_hash(source_p
->id
, source_p
);
1081 /* remove any nd entries for this nick */
1082 if((nd
= rb_dictionary_retrieve(nd_dict
, nick
)))
1085 add_to_client_hash(nick
, source_p
);
1086 add_to_hostname_hash(source_p
->orighost
, source_p
);
1087 monitor_signon(source_p
);
1092 flag
= user_modes
[(unsigned char) *m
];
1094 if(flag
& UMODE_SERVICE
)
1099 RB_DLINK_FOREACH(ptr
, service_list
.head
)
1101 if(!irccmp((const char *) ptr
->data
, server
->name
))
1115 /* increment +i count if theyre invis */
1116 if(!(source_p
->umodes
& UMODE_INVISIBLE
) && (flag
& UMODE_INVISIBLE
))
1119 /* increment opered count if theyre opered */
1120 if(!(source_p
->umodes
& UMODE_OPER
) && (flag
& UMODE_OPER
))
1123 source_p
->umodes
|= flag
;
1127 if(IsOper(source_p
) && !IsService(source_p
))
1128 rb_dlinkAddAlloc(source_p
, &oper_list
);
1130 SetRemoteClient(source_p
);
1132 if(++Count
.total
> Count
.max_tot
)
1133 Count
.max_tot
= Count
.total
;
1135 source_p
->servptr
= server
;
1137 rb_dlinkAdd(source_p
, &source_p
->lnode
, &source_p
->servptr
->serv
->users
);
1139 call_hook(h_new_remote_user
, source_p
);
1141 return (introduce_client(client_p
, source_p
, user
, nick
, parc
== 12));
1144 /* Check if we can do SAVE. target_p can be a client to save or a
1145 * server introducing a client -- jilles */
1147 can_save(struct Client
*target_p
)
1149 struct Client
*serv_p
;
1151 if (MyClient(target_p
))
1153 if (!has_id(target_p
))
1155 serv_p
= IsServer(target_p
) ? target_p
: target_p
->servptr
;
1156 while (serv_p
!= NULL
&& serv_p
!= &me
)
1158 if (!(serv_p
->serv
->caps
& CAP_SAVE
))
1160 serv_p
= serv_p
->servptr
;
1162 return serv_p
== &me
;
1166 save_user(struct Client
*client_p
, struct Client
*source_p
,
1167 struct Client
*target_p
)
1169 if (!MyConnect(target_p
) && (!has_id(target_p
) || !IsCapable(target_p
->from
, CAP_SAVE
)))
1171 /* This shouldn't happen */
1172 /* Note we only need SAVE support in this direction */
1173 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1174 "Killed %s!%s@%s for nick collision detected by %s (%s does not support SAVE)",
1175 target_p
->name
, target_p
->username
, target_p
->host
, source_p
->name
, target_p
->from
->name
);
1176 kill_client_serv_butone(NULL
, target_p
, "%s (Nick collision (no SAVE support))", me
.name
);
1177 ServerStats
.is_kill
++;
1179 target_p
->flags
|= FLAGS_KILLED
;
1180 (void) exit_client(NULL
, target_p
, &me
, "Nick collision (no SAVE support)");
1183 sendto_server(client_p
, NULL
, CAP_SAVE
|CAP_TS6
, NOCAPS
, ":%s SAVE %s %ld",
1184 source_p
->id
, target_p
->id
, (long)target_p
->tsinfo
);
1185 sendto_server(client_p
, NULL
, CAP_TS6
, CAP_SAVE
, ":%s NICK %s :%ld",
1186 target_p
->id
, target_p
->id
, (long)SAVE_NICKTS
);
1187 if (!IsMe(client_p
))
1188 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
1189 "Received SAVE message for %s from %s",
1190 target_p
->name
, source_p
->name
);
1191 if (MyClient(target_p
))
1193 sendto_one_numeric(target_p
, RPL_SAVENICK
,
1194 form_str(RPL_SAVENICK
), target_p
->id
);
1195 change_local_nick(target_p
, target_p
, target_p
->id
, 0);
1196 target_p
->tsinfo
= SAVE_NICKTS
;
1199 change_remote_nick(target_p
, target_p
, SAVE_NICKTS
, target_p
->id
, 0);
1202 static void bad_nickname(struct Client
*client_p
, const char *nick
)
1204 char squitreason
[100];
1206 sendto_wallops_flags(UMODE_WALLOP
, &me
,
1207 "Squitting %s because of bad nickname %s (NICKLEN mismatch?)",
1208 client_p
->name
, nick
);
1209 sendto_server(NULL
, NULL
, CAP_TS6
, NOCAPS
,
1210 ":%s WALLOPS :Squitting %s because of bad nickname %s (NICKLEN mismatch?)",
1211 me
.id
, client_p
->name
, nick
);
1212 ilog(L_SERVER
, "Link %s cancelled, bad nickname %s sent (NICKLEN mismatch?)",
1213 client_p
->name
, nick
);
1215 snprintf(squitreason
, sizeof squitreason
,
1216 "Bad nickname introduced [%s]", nick
);
1217 exit_client(client_p
, client_p
, &me
, squitreason
);