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
45 #include "s_newconf.h"
49 /* Give all UID nicks the same TS. This ensures nick TS is always the same on
50 * all servers for each nick-user pair, also if a user with a UID nick changes
51 * their nick but is collided again (the server detecting the collision will
52 * not propagate the nick change further). -- jilles
54 #define SAVE_NICKTS 100
56 static void mr_nick(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
57 static void m_nick(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
58 static void mc_nick(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
59 static void ms_nick(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
60 static void ms_uid(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
61 static void ms_euid(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
62 static void ms_save(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
63 static bool can_save(struct Client
*);
64 static void save_user(struct Client
*, struct Client
*, struct Client
*);
65 static void bad_nickname(struct Client
*, const char *);
66 static void change_remote_nick(struct Client
*, struct Client
*, time_t,
68 static bool clean_username(const char *);
69 static bool clean_host(const char *);
70 static bool clean_uid(const char *uid
, const char *sid
);
72 static void set_initial_nick(struct Client
*client_p
, struct Client
*source_p
, char *nick
);
73 static void change_local_nick(struct Client
*client_p
, struct Client
*source_p
, char *nick
, int);
74 static void register_client(struct Client
*client_p
, struct Client
*server
,
75 const char *nick
, time_t newts
, int parc
, const char *parv
[]);
76 static void perform_nick_collides(struct Client
*, struct Client
*,
77 struct Client
*, int, const char **,
78 time_t, const char *, const char *);
79 static void perform_nickchange_collides(struct Client
*, struct Client
*,
80 struct Client
*, int, const char **, time_t, const char *);
82 struct Message nick_msgtab
= {
84 {{mr_nick
, 0}, {m_nick
, 0}, {mc_nick
, 3}, {ms_nick
, 0}, mg_ignore
, {m_nick
, 0}}
86 struct Message uid_msgtab
= {
88 {mg_ignore
, mg_ignore
, mg_ignore
, {ms_uid
, 9}, mg_ignore
, mg_ignore
}
90 struct Message euid_msgtab
= {
92 {mg_ignore
, mg_ignore
, mg_ignore
, {ms_euid
, 12}, mg_ignore
, mg_ignore
}
94 struct Message save_msgtab
= {
96 {mg_ignore
, mg_ignore
, mg_ignore
, {ms_save
, 3}, mg_ignore
, mg_ignore
}
99 mapi_clist_av1 nick_clist
[] = { &nick_msgtab
, &uid_msgtab
, &euid_msgtab
,
100 &save_msgtab
, NULL
};
102 static const char nick_desc
[] =
103 "Provides the NICK client and server commands as well as the UID, EUID, and SAVE TS6 server commands";
105 DECLARE_MODULE_AV2(nick
, NULL
, NULL
, nick_clist
, NULL
, NULL
, NULL
, NULL
, nick_desc
);
111 mr_nick(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
113 struct Client
*target_p
;
116 if (strlen(client_p
->id
) == 3)
118 exit_client(client_p
, client_p
, client_p
, "Mixing client and server protocol");
122 if(parc
< 2 || EmptyString(parv
[1]))
124 sendto_one(source_p
, form_str(ERR_NONICKNAMEGIVEN
),
125 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
);
129 /* copy the nick and terminate it */
130 rb_strlcpy(nick
, parv
[1], ConfigFileEntry
.nicklen
);
132 /* check the nickname is ok */
133 if(!clean_nick(nick
, 1))
135 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
),
136 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, parv
[1]);
140 /* check if the nick is resv'd */
141 if(find_nick_resv(nick
))
143 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
),
144 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, nick
);
148 if(rb_dictionary_find(nd_dict
, nick
))
150 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
151 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, nick
);
155 if((target_p
= find_named_client(nick
)) == NULL
)
156 set_initial_nick(client_p
, source_p
, nick
);
157 else if(source_p
== target_p
)
158 strcpy(source_p
->name
, nick
);
160 sendto_one(source_p
, form_str(ERR_NICKNAMEINUSE
), me
.name
, "*", nick
);
167 m_nick(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
169 struct Client
*target_p
;
172 if(parc
< 2 || EmptyString(parv
[1]))
174 sendto_one(source_p
, form_str(ERR_NONICKNAMEGIVEN
), me
.name
, source_p
->name
);
178 /* mark end of grace period, to prevent nickflooding */
179 if(!IsFloodDone(source_p
))
180 flood_endgrace(source_p
);
182 /* terminate nick to NICKLEN, we dont want clean_nick() to error! */
183 rb_strlcpy(nick
, parv
[1], ConfigFileEntry
.nicklen
);
185 /* check the nickname is ok */
186 if(!clean_nick(nick
, 1))
188 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
), me
.name
, source_p
->name
, nick
);
192 if(!IsExemptResv(source_p
) && find_nick_resv(nick
))
194 sendto_one(source_p
, form_str(ERR_ERRONEUSNICKNAME
), me
.name
, source_p
->name
, nick
);
198 if(rb_dictionary_find(nd_dict
, nick
))
200 sendto_one(source_p
, form_str(ERR_UNAVAILRESOURCE
),
201 me
.name
, EmptyString(source_p
->name
) ? "*" : source_p
->name
, nick
);
205 if((target_p
= find_named_client(nick
)))
207 /* If(target_p == source_p) the client is changing nicks between
208 * equivalent nicknames ie: [nick] -> {nick}
210 if(target_p
== source_p
)
212 /* check the nick isnt exactly the same */
213 if(strcmp(target_p
->name
, nick
))
214 change_local_nick(client_p
, source_p
, nick
, 1);
218 /* drop unregged client */
219 else if(IsUnknown(target_p
))
221 exit_client(NULL
, target_p
, &me
, "Overridden");
222 change_local_nick(client_p
, source_p
, nick
, 1);
225 sendto_one(source_p
, form_str(ERR_NICKNAMEINUSE
), me
.name
, source_p
->name
, nick
);
230 change_local_nick(client_p
, source_p
, nick
, 1);
235 * server -> server nick change
237 * parv[2] = TS when nick change
240 mc_nick(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
242 struct Client
*target_p
;
245 /* if nicks erroneous, or too long, kill */
246 if(!clean_nick(parv
[1], 0))
248 bad_nickname(client_p
, parv
[1]);
252 newts
= atol(parv
[2]);
253 target_p
= find_named_client(parv
[1]);
255 /* if the nick doesnt exist, allow it and process like normal */
258 change_remote_nick(client_p
, source_p
, newts
, parv
[1], 1);
260 else if(IsUnknown(target_p
))
262 exit_client(NULL
, target_p
, &me
, "Overridden");
263 change_remote_nick(client_p
, source_p
, newts
, parv
[1], 1);
265 else if(target_p
== source_p
)
267 /* client changing case of nick */
268 if(strcmp(target_p
->name
, parv
[1]))
269 change_remote_nick(client_p
, source_p
, newts
, parv
[1], 1);
271 /* we've got a collision! */
273 perform_nickchange_collides(source_p
, client_p
, target_p
,
274 parc
, parv
, newts
, parv
[1]);
278 ms_nick(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
280 const char *nick
, *server
;
282 nick
= parc
> 1 ? parv
[1] : "?";
283 server
= parc
> 7 ? parv
[7] : "?";
285 sendto_wallops_flags(UMODE_WALLOP
, &me
,
286 "Link %s cancelled, TS5 nickname %s on %s introduced (old server?)",
287 client_p
->name
, nick
, server
);
288 sendto_server(NULL
, NULL
, CAP_TS6
, NOCAPS
,
289 ":%s WALLOPS :Link %s cancelled, TS5 nickname %s on %s introduced (old server?)",
290 me
.id
, client_p
->name
, nick
, server
);
291 ilog(L_SERVER
, "Link %s cancelled, TS5 nickname %s on %s introduced (old server?)",
292 client_p
->name
, nick
, server
);
294 exit_client(client_p
, client_p
, &me
, "TS5 nickname introduced");
309 ms_uid(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
311 struct Client
*target_p
;
313 char squitreason
[120];
315 newts
= atol(parv
[3]);
319 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
320 "Dropping server %s due to (invalid) command 'UID' "
321 "with %d arguments (expecting 10)", client_p
->name
, parc
);
322 ilog(L_SERVER
, "Excess parameters (%d) for command 'UID' from %s.",
323 parc
, client_p
->name
);
324 snprintf(squitreason
, sizeof squitreason
,
325 "Excess parameters (%d) to %s command, expecting %d",
327 exit_client(client_p
, client_p
, client_p
, squitreason
);
331 /* if nicks erroneous, or too long, kill */
332 if(!clean_nick(parv
[1], 0))
334 bad_nickname(client_p
, parv
[1]);
338 if(!clean_uid(parv
[8], source_p
->id
))
340 snprintf(squitreason
, sizeof squitreason
,
341 "Invalid UID %s for nick %s on %s/%s",
342 parv
[8], parv
[1], source_p
->name
, source_p
->id
);
343 exit_client(client_p
, client_p
, client_p
, squitreason
);
347 if(!clean_username(parv
[5]) || !clean_host(parv
[6]))
349 ServerStats
.is_kill
++;
350 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
351 "Bad user@host: %s@%s From: %s(via %s)",
352 parv
[5], parv
[6], source_p
->name
, client_p
->name
);
353 sendto_one(client_p
, ":%s KILL %s :%s (Bad user@host)", me
.id
, parv
[8], me
.name
);
357 /* check length of clients gecos */
358 if(strlen(parv
[9]) > REALLEN
)
360 char *s
= LOCAL_COPY(parv
[9]);
361 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Long realname from server %s for %s",
362 source_p
->name
, parv
[1]);
367 target_p
= find_named_client(parv
[1]);
371 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
373 else if(IsUnknown(target_p
))
375 exit_client(NULL
, target_p
, &me
, "Overridden");
376 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
378 /* we've got a collision! */
380 perform_nick_collides(source_p
, client_p
, target_p
, parc
, parv
,
381 newts
, parv
[1], parv
[8]);
398 ms_euid(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
400 struct Client
*target_p
;
402 char squitreason
[120];
404 newts
= atol(parv
[3]);
408 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
409 "Dropping server %s due to (invalid) command 'EUID' "
410 "with %d arguments (expecting 12)", client_p
->name
, parc
);
411 ilog(L_SERVER
, "Excess parameters (%d) for command 'EUID' from %s.",
412 parc
, client_p
->name
);
413 snprintf(squitreason
, sizeof squitreason
,
414 "Excess parameters (%d) to %s command, expecting %d",
416 exit_client(client_p
, client_p
, client_p
, squitreason
);
420 /* if nicks erroneous, or too long, kill */
421 if(!clean_nick(parv
[1], 0))
423 bad_nickname(client_p
, parv
[1]);
427 if(!clean_uid(parv
[8], source_p
->id
))
429 snprintf(squitreason
, sizeof squitreason
,
430 "Invalid UID %s for nick %s on %s/%s",
431 parv
[8], parv
[1], source_p
->name
, source_p
->id
);
432 exit_client(client_p
, client_p
, client_p
, squitreason
);
436 if(!clean_username(parv
[5]) || !clean_host(parv
[6]))
438 ServerStats
.is_kill
++;
439 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
440 "Bad user@host: %s@%s From: %s(via %s)",
441 parv
[5], parv
[6], source_p
->name
, client_p
->name
);
442 sendto_one(client_p
, ":%s KILL %s :%s (Bad user@host)", me
.id
, parv
[8], me
.name
);
446 if(strcmp(parv
[9], "*") && !clean_host(parv
[9]))
448 ServerStats
.is_kill
++;
449 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
450 "Bad realhost: %s From: %s(via %s)",
451 parv
[9], source_p
->name
, client_p
->name
);
452 sendto_one(client_p
, ":%s KILL %s :%s (Bad user@host)", me
.id
, parv
[8], me
.name
);
456 /* check length of clients gecos */
457 if(strlen(parv
[11]) > REALLEN
)
459 char *s
= LOCAL_COPY(parv
[11]);
460 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Long realname from server %s for %s",
461 source_p
->name
, parv
[1]);
466 target_p
= find_named_client(parv
[1]);
470 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
472 else if(IsUnknown(target_p
))
474 exit_client(NULL
, target_p
, &me
, "Overridden");
475 register_client(client_p
, source_p
, parv
[1], newts
, parc
, parv
);
477 /* we've got a collision! */
479 perform_nick_collides(source_p
, client_p
, target_p
, parc
, parv
,
480 newts
, parv
[1], parv
[8]);
488 ms_save(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
490 struct Client
*target_p
;
492 target_p
= find_id(parv
[1]);
493 if (target_p
== NULL
)
495 if (!IsPerson(target_p
))
496 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
497 "Ignored SAVE message for non-person %s from %s",
498 target_p
->name
, source_p
->name
);
499 else if (IsDigit(target_p
->name
[0]))
500 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
501 "Ignored noop SAVE message for %s from %s",
502 target_p
->name
, source_p
->name
);
503 else if (target_p
->tsinfo
== atol(parv
[2]))
504 save_user(client_p
, source_p
, target_p
);
506 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
507 "Ignored SAVE message for %s from %s",
508 target_p
->name
, source_p
->name
);
513 * input - username to check
514 * output - false if erroneous, else true
518 clean_username(const char *username
)
522 for(; *username
; username
++)
526 if(!IsUserChar(*username
))
538 * input - host to check
539 * output - false if erroneous, else true
543 clean_host(const char *host
)
551 if(!IsHostChar(*host
))
562 clean_uid(const char *uid
, const char *sid
)
566 if(strncmp(uid
, sid
, strlen(sid
)))
587 set_initial_nick(struct Client
*client_p
, struct Client
*source_p
, char *nick
)
589 char note
[NICKLEN
+ 10];
591 /* This had to be copied here to avoid problems.. */
592 source_p
->tsinfo
= rb_current_time();
593 if(source_p
->name
[0])
594 del_from_client_hash(source_p
->name
, source_p
);
596 strcpy(source_p
->name
, nick
);
597 add_to_client_hash(nick
, source_p
);
599 snprintf(note
, sizeof(note
), "Nick: %s", nick
);
600 rb_note(client_p
->localClient
->F
, note
);
602 if(source_p
->flags
& FLAGS_SENTUSER
)
604 /* got user, heres nick. */
605 register_local_user(client_p
, source_p
);
610 change_local_nick(struct Client
*client_p
, struct Client
*source_p
,
611 char *nick
, int dosend
)
613 struct Client
*target_p
;
614 rb_dlink_node
*ptr
, *next_ptr
;
615 struct Channel
*chptr
;
616 char note
[NICKLEN
+ 10];
621 chptr
= find_bannickchange_channel(source_p
);
624 sendto_one_numeric(source_p
, ERR_BANNICKCHANGE
,
625 form_str(ERR_BANNICKCHANGE
),
626 nick
, chptr
->chname
);
629 if((source_p
->localClient
->last_nick_change
+ ConfigFileEntry
.max_nick_time
) < rb_current_time())
630 source_p
->localClient
->number_of_nick_changes
= 0;
632 source_p
->localClient
->last_nick_change
= rb_current_time();
633 source_p
->localClient
->number_of_nick_changes
++;
635 if(ConfigFileEntry
.anti_nick_flood
&& !IsOper(source_p
) &&
636 source_p
->localClient
->number_of_nick_changes
> ConfigFileEntry
.max_nick_changes
)
638 sendto_one(source_p
, form_str(ERR_NICKTOOFAST
),
639 me
.name
, source_p
->name
, source_p
->name
,
640 nick
, ConfigFileEntry
.max_nick_time
);
645 samenick
= irccmp(source_p
->name
, nick
) ? 0 : 1;
647 /* dont reset TS if theyre just changing case of nick */
650 /* force the TS to increase -- jilles */
651 if (source_p
->tsinfo
>= rb_current_time())
654 source_p
->tsinfo
= rb_current_time();
655 monitor_signoff(source_p
);
656 /* we only do bancache for local users -- jilles */
658 invalidate_bancache_user(source_p
);
661 sendto_realops_snomask(SNO_NCHANGE
, L_ALL
,
662 "Nick change: From %s to %s [%s@%s]",
663 source_p
->name
, nick
, source_p
->username
, source_p
->host
);
665 /* send the nick change to the users channels */
666 sendto_common_channels_local(source_p
, NOCAPS
, NOCAPS
, ":%s!%s@%s NICK :%s",
667 source_p
->name
, source_p
->username
, source_p
->host
, nick
);
669 /* send the nick change to servers.. */
672 whowas_add_history(source_p
, 1);
676 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s NICK %s :%ld",
677 use_id(source_p
), nick
, (long) source_p
->tsinfo
);
681 /* Finally, add to hash */
682 del_from_client_hash(source_p
->name
, source_p
);
683 strcpy(source_p
->name
, nick
);
684 add_to_client_hash(nick
, source_p
);
687 monitor_signon(source_p
);
689 /* Make sure everyone that has this client on its accept list
690 * loses that reference.
692 /* we used to call del_all_accepts() here, but theres no real reason
693 * to clear a clients own list of accepted clients. So just remove
694 * them from everyone elses list --anfl
696 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, source_p
->on_allow_list
.head
)
698 target_p
= ptr
->data
;
700 rb_dlinkFindDestroy(source_p
, &target_p
->localClient
->allow_list
);
701 rb_dlinkDestroy(ptr
, &source_p
->on_allow_list
);
704 snprintf(note
, sizeof(note
), "Nick: %s", nick
);
705 rb_note(client_p
->localClient
->F
, note
);
711 * change_remote_nick()
714 change_remote_nick(struct Client
*client_p
, struct Client
*source_p
,
715 time_t newts
, const char *nick
, int dosend
)
718 int samenick
= irccmp(source_p
->name
, nick
) ? 0 : 1;
720 /* client changing their nick - dont reset ts if its same */
723 source_p
->tsinfo
= newts
? newts
: rb_current_time();
724 monitor_signoff(source_p
);
727 sendto_common_channels_local(source_p
, NOCAPS
, NOCAPS
, ":%s!%s@%s NICK :%s",
728 source_p
->name
, source_p
->username
, source_p
->host
, nick
);
732 whowas_add_history(source_p
, 1);
735 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s NICK %s :%ld",
736 use_id(source_p
), nick
, (long) source_p
->tsinfo
);
740 del_from_client_hash(source_p
->name
, source_p
);
742 /* invalidate nick delay when a remote client uses the nick.. */
743 if((nd
= rb_dictionary_retrieve(nd_dict
, nick
)))
746 strcpy(source_p
->name
, nick
);
747 add_to_client_hash(nick
, source_p
);
750 monitor_signon(source_p
);
752 /* remove all accepts pointing to the client */
753 del_all_accepts(source_p
);
757 perform_nick_collides(struct Client
*source_p
, struct Client
*client_p
,
758 struct Client
*target_p
, int parc
, const char *parv
[],
759 time_t newts
, const char *nick
, const char *uid
)
765 use_save
= ConfigFileEntry
.collision_fnc
&& can_save(target_p
) &&
766 uid
!= NULL
&& can_save(source_p
);
767 action
= use_save
? "saved" : "killed";
769 /* if we dont have a ts, or their TS's are the same, kill both */
770 if(!newts
|| !target_p
->tsinfo
|| (newts
== target_p
->tsinfo
))
772 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
773 "Nick collision on %s(%s <- %s)(both %s)",
774 target_p
->name
, target_p
->from
->name
, client_p
->name
, action
);
778 save_user(&me
, &me
, target_p
);
779 ServerStats
.is_save
++;
780 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
782 register_client(client_p
, source_p
,
783 uid
, SAVE_NICKTS
, parc
, parv
);
787 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
788 form_str(ERR_NICKCOLLISION
), target_p
->name
);
790 /* if the new client being introduced has a UID, we need to
791 * issue a KILL for it..
794 sendto_one(client_p
, ":%s KILL %s :%s (Nick collision (new))",
795 me
.id
, uid
, me
.name
);
797 /* we then need to KILL the old client everywhere */
798 kill_client_serv_butone(NULL
, target_p
, "%s (Nick collision (new))", me
.name
);
799 ServerStats
.is_kill
++;
801 target_p
->flags
|= FLAGS_KILLED
;
802 exit_client(client_p
, target_p
, &me
, "Nick collision (new)");
806 /* the timestamps are different */
809 sameuser
= (target_p
->user
) && !irccmp(target_p
->username
, parv
[5])
810 && !irccmp(target_p
->host
, parv
[6]);
812 if((sameuser
&& newts
< target_p
->tsinfo
) ||
813 (!sameuser
&& newts
> target_p
->tsinfo
))
815 /* if we have a UID, then we need to issue a KILL,
816 * otherwise we do nothing and hope that the other
817 * client will collide it..
821 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
823 register_client(client_p
, source_p
,
824 uid
, SAVE_NICKTS
, parc
, parv
);
828 ":%s KILL %s :%s (Nick collision (new))",
829 me
.id
, uid
, me
.name
);
835 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
836 "Nick collision on %s(%s <- %s)(older %s)",
837 target_p
->name
, target_p
->from
->name
,
838 client_p
->name
, action
);
840 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
841 "Nick collision on %s(%s <- %s)(newer %s)",
842 target_p
->name
, target_p
->from
->name
,
843 client_p
->name
, action
);
847 ServerStats
.is_save
++;
848 save_user(&me
, &me
, target_p
);
852 ServerStats
.is_kill
++;
853 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
854 form_str(ERR_NICKCOLLISION
), target_p
->name
);
856 /* now we just need to kill the existing client */
857 kill_client_serv_butone(client_p
, target_p
,
858 "%s (Nick collision (new))", me
.name
);
860 target_p
->flags
|= FLAGS_KILLED
;
861 (void) exit_client(client_p
, target_p
, &me
, "Nick collision");
864 register_client(client_p
, source_p
,
865 nick
, newts
, parc
, parv
);
872 perform_nickchange_collides(struct Client
*source_p
, struct Client
*client_p
,
873 struct Client
*target_p
, int parc
,
874 const char *parv
[], time_t newts
, const char *nick
)
880 use_save
= ConfigFileEntry
.collision_fnc
&& can_save(target_p
) &&
882 action
= use_save
? "saved" : "killed";
884 /* its a client changing nick and causing a collide */
885 if(!newts
|| !target_p
->tsinfo
|| (newts
== target_p
->tsinfo
) || !source_p
->user
)
887 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
888 "Nick change collision from %s to %s(%s <- %s)(both %s)",
889 source_p
->name
, target_p
->name
, target_p
->from
->name
,
890 client_p
->name
, action
);
894 ServerStats
.is_save
+= 2;
895 save_user(&me
, &me
, target_p
);
896 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
897 source_p
->id
, (long)newts
);
898 /* don't send a redundant nick change */
899 if (!IsDigit(source_p
->name
[0]))
900 change_remote_nick(client_p
, source_p
, SAVE_NICKTS
, source_p
->id
, 1);
904 ServerStats
.is_kill
++;
905 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
906 form_str(ERR_NICKCOLLISION
), target_p
->name
);
908 kill_client_serv_butone(NULL
, source_p
, "%s (Nick change collision)", me
.name
);
910 ServerStats
.is_kill
++;
912 kill_client_serv_butone(NULL
, target_p
, "%s (Nick change collision)", me
.name
);
914 target_p
->flags
|= FLAGS_KILLED
;
915 exit_client(NULL
, target_p
, &me
, "Nick collision(new)");
916 source_p
->flags
|= FLAGS_KILLED
;
917 exit_client(client_p
, source_p
, &me
, "Nick collision(old)");
923 sameuser
= !irccmp(target_p
->username
, source_p
->username
) &&
924 !irccmp(target_p
->host
, source_p
->host
);
926 if((sameuser
&& newts
< target_p
->tsinfo
) ||
927 (!sameuser
&& newts
> target_p
->tsinfo
))
930 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
931 "Nick change collision from %s to %s(%s <- %s)(older %s)",
932 source_p
->name
, target_p
->name
,
933 target_p
->from
->name
, client_p
->name
, action
);
935 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
936 "Nick change collision from %s to %s(%s <- %s)(newer %s)",
937 source_p
->name
, target_p
->name
,
938 target_p
->from
->name
, client_p
->name
, action
);
942 ServerStats
.is_save
++;
943 /* can't broadcast a SAVE because the
944 * nickchange has happened at client_p
945 * but not in other directions -- jilles */
946 sendto_one(client_p
, ":%s SAVE %s %ld", me
.id
,
947 source_p
->id
, (long)newts
);
948 /* send a :<id> NICK <id> <ts> (!) */
949 if (!IsDigit(source_p
->name
[0]))
950 change_remote_nick(client_p
, source_p
, SAVE_NICKTS
, source_p
->id
, 1);
954 ServerStats
.is_kill
++;
956 sendto_one_numeric(source_p
, ERR_NICKCOLLISION
,
957 form_str(ERR_NICKCOLLISION
), source_p
->name
);
959 /* kill the client issuing the nickchange */
960 kill_client_serv_butone(client_p
, source_p
,
961 "%s (Nick change collision)", me
.name
);
963 source_p
->flags
|= FLAGS_KILLED
;
966 exit_client(client_p
, source_p
, &me
, "Nick collision(old)");
968 exit_client(client_p
, source_p
, &me
, "Nick collision(new)");
975 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
976 "Nick collision on %s(%s <- %s)(older %s)",
977 target_p
->name
, target_p
->from
->name
,
978 client_p
->name
, action
);
980 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
981 "Nick collision on %s(%s <- %s)(newer %s)",
982 target_p
->name
, target_p
->from
->name
,
983 client_p
->name
, action
);
987 ServerStats
.is_save
++;
988 save_user(&me
, &me
, target_p
);
992 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
993 form_str(ERR_NICKCOLLISION
), target_p
->name
);
995 /* kill the client who existed before hand */
996 kill_client_serv_butone(client_p
, target_p
, "%s (Nick collision)", me
.name
);
998 ServerStats
.is_kill
++;
1000 target_p
->flags
|= FLAGS_KILLED
;
1001 (void) exit_client(client_p
, target_p
, &me
, "Nick collision");
1006 change_remote_nick(client_p
, source_p
, newts
, nick
, 1);
1010 register_client(struct Client
*client_p
, struct Client
*server
,
1011 const char *nick
, time_t newts
, int parc
, const char *parv
[])
1013 struct Client
*source_p
;
1015 struct nd_entry
*nd
;
1019 source_p
= make_client(client_p
);
1020 user
= make_user(source_p
);
1021 rb_dlinkAddTail(source_p
, &source_p
->node
, &global_client_list
);
1023 source_p
->hopcount
= atoi(parv
[2]);
1024 source_p
->tsinfo
= newts
;
1026 strcpy(source_p
->name
, nick
);
1027 rb_strlcpy(source_p
->username
, parv
[5], sizeof(source_p
->username
));
1028 rb_strlcpy(source_p
->host
, parv
[6], sizeof(source_p
->host
));
1029 rb_strlcpy(source_p
->orighost
, source_p
->host
, sizeof(source_p
->orighost
));
1033 rb_strlcpy(source_p
->info
, parv
[11], sizeof(source_p
->info
));
1034 rb_strlcpy(source_p
->sockhost
, parv
[7], sizeof(source_p
->sockhost
));
1035 rb_strlcpy(source_p
->id
, parv
[8], sizeof(source_p
->id
));
1036 add_to_id_hash(source_p
->id
, source_p
);
1037 if (strcmp(parv
[9], "*"))
1039 rb_strlcpy(source_p
->orighost
, parv
[9], sizeof(source_p
->orighost
));
1040 if (irccmp(source_p
->host
, source_p
->orighost
))
1041 SetDynSpoof(source_p
);
1043 if (strcmp(parv
[10], "*"))
1044 rb_strlcpy(source_p
->user
->suser
, parv
[10], sizeof(source_p
->user
->suser
));
1048 rb_strlcpy(source_p
->info
, parv
[9], sizeof(source_p
->info
));
1049 rb_strlcpy(source_p
->sockhost
, parv
[7], sizeof(source_p
->sockhost
));
1050 rb_strlcpy(source_p
->id
, parv
[8], sizeof(source_p
->id
));
1051 add_to_id_hash(source_p
->id
, source_p
);
1058 /* remove any nd entries for this nick */
1059 if((nd
= rb_dictionary_retrieve(nd_dict
, nick
)))
1062 add_to_client_hash(nick
, source_p
);
1063 add_to_hostname_hash(source_p
->orighost
, source_p
);
1064 monitor_signon(source_p
);
1069 flag
= user_modes
[(unsigned char) *m
];
1071 if(flag
& UMODE_SERVICE
)
1076 RB_DLINK_FOREACH(ptr
, service_list
.head
)
1078 if(!irccmp((const char *) ptr
->data
, server
->name
))
1092 /* increment +i count if theyre invis */
1093 if(!(source_p
->umodes
& UMODE_INVISIBLE
) && (flag
& UMODE_INVISIBLE
))
1096 /* increment opered count if theyre opered */
1097 if(!(source_p
->umodes
& UMODE_OPER
) && (flag
& UMODE_OPER
))
1100 source_p
->umodes
|= flag
;
1104 if(IsOper(source_p
) && !IsService(source_p
))
1105 rb_dlinkAddAlloc(source_p
, &oper_list
);
1107 SetRemoteClient(source_p
);
1109 if(++Count
.total
> Count
.max_tot
)
1110 Count
.max_tot
= Count
.total
;
1112 source_p
->servptr
= server
;
1114 rb_dlinkAdd(source_p
, &source_p
->lnode
, &source_p
->servptr
->serv
->users
);
1116 call_hook(h_new_remote_user
, source_p
);
1118 introduce_client(client_p
, source_p
, user
, nick
, parc
== 12);
1121 /* Check if we can do SAVE. target_p can be a client to save or a
1122 * server introducing a client -- jilles */
1124 can_save(struct Client
*target_p
)
1126 struct Client
*serv_p
;
1128 if (MyClient(target_p
))
1130 if (!has_id(target_p
))
1132 serv_p
= IsServer(target_p
) ? target_p
: target_p
->servptr
;
1133 while (serv_p
!= NULL
&& serv_p
!= &me
)
1135 if (!(serv_p
->serv
->caps
& CAP_SAVE
))
1137 serv_p
= serv_p
->servptr
;
1139 return serv_p
== &me
;
1143 save_user(struct Client
*client_p
, struct Client
*source_p
,
1144 struct Client
*target_p
)
1146 if (!MyConnect(target_p
) && (!has_id(target_p
) || !IsCapable(target_p
->from
, CAP_SAVE
)))
1148 /* This shouldn't happen */
1149 /* Note we only need SAVE support in this direction */
1150 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1151 "Killed %s!%s@%s for nick collision detected by %s (%s does not support SAVE)",
1152 target_p
->name
, target_p
->username
, target_p
->host
, source_p
->name
, target_p
->from
->name
);
1153 kill_client_serv_butone(NULL
, target_p
, "%s (Nick collision (no SAVE support))", me
.name
);
1154 ServerStats
.is_kill
++;
1156 target_p
->flags
|= FLAGS_KILLED
;
1157 (void) exit_client(NULL
, target_p
, &me
, "Nick collision (no SAVE support)");
1160 sendto_server(client_p
, NULL
, CAP_SAVE
|CAP_TS6
, NOCAPS
, ":%s SAVE %s %ld",
1161 source_p
->id
, target_p
->id
, (long)target_p
->tsinfo
);
1162 sendto_server(client_p
, NULL
, CAP_TS6
, CAP_SAVE
, ":%s NICK %s :%ld",
1163 target_p
->id
, target_p
->id
, (long)SAVE_NICKTS
);
1164 if (!IsMe(client_p
))
1165 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
1166 "Received SAVE message for %s from %s",
1167 target_p
->name
, source_p
->name
);
1168 if (MyClient(target_p
))
1170 sendto_one_numeric(target_p
, RPL_SAVENICK
,
1171 form_str(RPL_SAVENICK
), target_p
->id
);
1172 change_local_nick(target_p
, target_p
, target_p
->id
, 0);
1173 target_p
->tsinfo
= SAVE_NICKTS
;
1176 change_remote_nick(target_p
, target_p
, SAVE_NICKTS
, target_p
->id
, 0);
1179 static void bad_nickname(struct Client
*client_p
, const char *nick
)
1181 char squitreason
[100];
1183 sendto_wallops_flags(UMODE_WALLOP
, &me
,
1184 "Squitting %s because of bad nickname %s (NICKLEN mismatch?)",
1185 client_p
->name
, nick
);
1186 sendto_server(NULL
, NULL
, CAP_TS6
, NOCAPS
,
1187 ":%s WALLOPS :Squitting %s because of bad nickname %s (NICKLEN mismatch?)",
1188 me
.id
, client_p
->name
, nick
);
1189 ilog(L_SERVER
, "Link %s cancelled, bad nickname %s sent (NICKLEN mismatch?)",
1190 client_p
->name
, nick
);
1192 snprintf(squitreason
, sizeof squitreason
,
1193 "Bad nickname introduced [%s]", nick
);
1194 exit_client(client_p
, client_p
, &me
, squitreason
);