2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2012 Alexander Barton (alex@barton.de) and Contributors.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * Please read the file COPYING, README and AUTHORS for more information.
26 #include "conn-func.h"
36 #include "irc-macros.h"
37 #include "irc-write.h"
40 #include "irc-login.h"
42 static void Kill_Nick PARAMS((char *Nick, char *Reason));
43 static void Change_Nick PARAMS((CLIENT * Origin, CLIENT * Target, char *NewNick,
47 * Handler for the IRC "PASS" command.
49 * @param Client The client from which this command has been received.
50 * @param Req Request structure with prefix and all parameters.
51 * @return CONNECTED or DISCONNECTED.
54 IRC_PASS( CLIENT *Client, REQUEST *Req )
56 char *type, *orig_flags;
57 int protohigh, protolow;
59 assert( Client != NULL );
60 assert( Req != NULL );
62 /* Return an error if this is not a local client */
63 if (Client_Conn(Client) <= NONE)
64 return IRC_WriteErrClient(Client, ERR_UNKNOWNCOMMAND_MSG,
65 Client_ID(Client), Req->command);
67 if (Client_Type(Client) == CLIENT_UNKNOWN && Req->argc == 1) {
68 /* Not yet registered "unknown" connection, PASS with one
69 * argument: either a regular client, service, or server
70 * using the old RFC 1459 section 4.1.1 syntax. */
71 LogDebug("Connection %d: got PASS command (RFC 1459) ...",
73 } else if ((Client_Type(Client) == CLIENT_UNKNOWN ||
74 Client_Type(Client) == CLIENT_UNKNOWNSERVER) &&
75 (Req->argc == 3 || Req->argc == 4)) {
76 /* Not yet registered "unknown" connection or outgoing server
77 * link, PASS with three or four argument: server using the
78 * RFC 2813 section 4.1.1 syntax. */
79 LogDebug("Connection %d: got PASS command (RFC 2813, new server link) ...",
81 } else if (Client_Type(Client) == CLIENT_UNKNOWN ||
82 Client_Type(Client) == CLIENT_UNKNOWNSERVER) {
83 /* Unregistered connection, but wrong number of arguments: */
84 return IRC_WriteErrClient(Client, ERR_NEEDMOREPARAMS_MSG,
85 Client_ID(Client), Req->command);
87 /* Registered connection, PASS command is not allowed! */
88 return IRC_WriteErrClient(Client, ERR_ALREADYREGISTRED_MSG,
92 Conn_SetPassword(Client_Conn(Client), Req->argv[0]);
94 /* Protocol version */
95 if (Req->argc >= 2 && strlen(Req->argv[1]) >= 4) {
101 Req->argv[1][4] = '\0';
102 protolow = atoi(&Req->argv[1][2]);
103 Req->argv[1][2] = '\0';
104 protohigh = atoi(Req->argv[1]);
106 Req->argv[1][2] = c2;
107 Req->argv[1][4] = c4;
109 Client_SetType(Client, CLIENT_GOTPASS_2813);
111 protohigh = protolow = 0;
112 Client_SetType(Client, CLIENT_GOTPASS);
115 /* Protocol type, see doc/Protocol.txt */
116 if (Req->argc >= 2 && strlen(Req->argv[1]) > 4)
117 type = &Req->argv[1][4];
121 /* Protocol flags/options */
123 orig_flags = Req->argv[3];
127 /* Implementation, version and IRC+ flags */
128 if (Req->argc >= 3) {
129 char *impl, *ptr, *serverver, *flags;
132 ptr = strchr(impl, '|');
136 if (type && strcmp(type, PROTOIRCPLUS) == 0) {
137 /* The peer seems to be a server which supports the
138 * IRC+ protocol (see doc/Protocol.txt). */
139 serverver = ptr ? ptr + 1 : "?";
140 flags = strchr(ptr ? serverver : impl, ':');
147 "Peer on connection %d announces itself as %s-%s using protocol %d.%d/IRC+ (flags: \"%s\").",
148 Client_Conn(Client), impl, serverver,
149 protohigh, protolow, flags);
151 /* The peer seems to be a server supporting the
152 * "original" IRC protocol (RFC 2813). */
153 if (strchr(orig_flags, 'Z'))
158 "Peer on connection %d announces itself as \"%s\" using protocol %d.%d (flags: \"%s\").",
159 Client_Conn(Client), impl,
160 protohigh, protolow, flags);
162 Client_SetFlags(Client, flags);
169 * Handler for the IRC "NICK" command.
171 * @param Client The client from which this command has been received.
172 * @param Req Request structure with prefix and all parameters.
173 * @return CONNECTED or DISCONNECTED.
176 IRC_NICK( CLIENT *Client, REQUEST *Req )
178 CLIENT *intr_c, *target, *c;
179 char *nick, *user, *hostname, *modes, *info;
182 assert( Client != NULL );
183 assert( Req != NULL );
185 /* Some IRC clients, for example BitchX, send the NICK and USER
186 * commands in the wrong order ... */
187 if(Client_Type(Client) == CLIENT_UNKNOWN
188 || Client_Type(Client) == CLIENT_GOTPASS
189 || Client_Type(Client) == CLIENT_GOTNICK
191 || Client_Type(Client) == CLIENT_GOTUSER
193 || Client_Type(Client) == CLIENT_USER
194 || Client_Type(Client) == CLIENT_SERVICE
195 || (Client_Type(Client) == CLIENT_SERVER && Req->argc == 1))
197 /* User registration or change of nickname */
198 _IRC_ARGC_EQ_OR_RETURN_(Client, Req, 1)
200 /* Search "target" client */
201 if (Client_Type(Client) == CLIENT_SERVER) {
202 target = Client_Search(Req->prefix);
204 return IRC_WriteErrClient(Client,
209 /* Is this a restricted client? */
210 if (Client_HasMode(Client, 'r'))
211 return IRC_WriteErrClient(Client,
218 /* If the clients tries to change to its own nickname we won't
219 * do anything. This is how the original ircd behaves and some
220 * clients (for example Snak) expect it to be like this.
221 * But I doubt that this is "really the right thing" ... */
222 if (strcmp(Client_ID(target), Req->argv[0]) == 0)
226 /* Check that the new nickname is available. Special case:
227 * the client only changes from/to upper to lower case. */
228 if (strcasecmp(Client_ID(target), Req->argv[0]) != 0) {
229 if (!Client_CheckNick(target, Req->argv[0]))
233 if (Client_Type(target) != CLIENT_USER &&
234 Client_Type(target) != CLIENT_SERVICE &&
235 Client_Type(target) != CLIENT_SERVER) {
237 LogDebug("Connection %d: got valid NICK command ...",
238 Client_Conn( Client ));
240 /* Register new nickname of this client */
241 Client_SetID( target, Req->argv[0] );
245 Conn_SetAuthPing(Client_Conn(Client), rand());
246 IRC_WriteStrClient(Client, "PING :%ld",
247 Conn_GetAuthPing(Client_Conn(Client)));
248 LogDebug("Connection %d: sent AUTH PING %ld ...",
250 Conn_GetAuthPing(Client_Conn(Client)));
254 /* If we received a valid USER command already then
255 * register the new client! */
256 if( Client_Type( Client ) == CLIENT_GOTUSER )
257 return Login_User( Client );
259 Client_SetType( Client, CLIENT_GOTNICK );
261 /* Nickname change */
262 Change_Nick(Client, target, Req->argv[0],
263 Client_Type(Client) == CLIENT_USER ? true : false);
264 IRC_SetPenalty(target, 2);
268 } else if(Client_Type(Client) == CLIENT_SERVER ||
269 Client_Type(Client) == CLIENT_SERVICE) {
270 /* Server or service introduces new client */
272 /* Bad number of parameters? */
273 if (Req->argc != 2 && Req->argc != 7)
274 return IRC_WriteErrClient(Client, ERR_NEEDMOREPARAMS_MSG,
275 Client_ID(Client), Req->command);
277 if (Req->argc >= 7) {
278 /* RFC 2813 compatible syntax */
280 hops = atoi(Req->argv[1]);
282 hostname = Req->argv[3];
283 token = atoi(Req->argv[4]);
284 modes = Req->argv[5] + 1;
287 /* RFC 1459 compatible syntax */
291 hostname = Client_ID(Client);
292 token = atoi(Req->argv[1]);
297 c = Client_Search(nick);
300 * the new nick is already present on this server:
301 * the new and the old one have to be disconnected now.
303 Log( LOG_ERR, "Server %s introduces already registered nick \"%s\"!", Client_ID( Client ), Req->argv[0] );
304 Kill_Nick( Req->argv[0], "Nick collision" );
308 /* Find the Server this client is connected to */
309 intr_c = Client_GetFromToken(Client, token);
311 Log( LOG_ERR, "Server %s introduces nick \"%s\" on unknown server!?", Client_ID( Client ), Req->argv[0] );
312 Kill_Nick( Req->argv[0], "Unknown server" );
316 c = Client_NewRemoteUser(intr_c, nick, hops, user, hostname,
317 token, modes, info, true);
319 /* Out of memory, we need to disconnect client to keep
320 * network state consistent! */
322 "Can't create client structure! (on connection %d)",
323 Client_Conn(Client));
324 Kill_Nick(Req->argv[0], "Server error");
328 /* RFC 2813: client is now fully registered, inform all the
329 * other servers about the new user.
330 * RFC 1459: announce the new client only after receiving the
331 * USER command, first we need more information! */
333 LogDebug("Client \"%s\" is being registered (RFC 1459) ...",
335 Client_SetType(c, CLIENT_GOTNICK);
337 Client_Introduce(Client, c, CLIENT_USER);
342 return IRC_WriteErrClient(Client, ERR_ALREADYREGISTRED_MSG,
347 * Handler for the IRC "SVSNICK" command.
349 * @param Client The client from which this command has been received.
350 * @param Req Request structure with prefix and all parameters.
351 * @return CONNECTED or DISCONNECTED.
354 IRC_SVSNICK(CLIENT *Client, REQUEST *Req)
356 CLIENT *from, *target;
358 assert(Client != NULL);
361 /* Search the originator */
362 from = Client_Search(Req->prefix);
366 /* Search the target */
367 target = Client_Search(Req->argv[0]);
368 if (!target || Client_Type(target) != CLIENT_USER) {
369 return IRC_WriteErrClient(Client, ERR_NOSUCHNICK_MSG,
370 Client_ID(Client), Req->argv[0]);
373 if (Client_Conn(target) <= NONE) {
374 /* We have to forward the message to the server handling
375 * this user; this is required to make sure all servers
376 * in the network do follow the nick name change! */
377 return IRC_WriteStrClientPrefix(Client_NextHop(target), from,
379 Req->argv[0], Req->argv[1]);
382 /* Make sure that the new nickname is valid */
383 if (!Client_CheckNick(from, Req->argv[1]))
386 Change_Nick(from, target, Req->argv[1], true);
391 * Handler for the IRC "USER" command.
393 * @param Client The client from which this command has been received.
394 * @param Req Request structure with prefix and all parameters.
395 * @return CONNECTED or DISCONNECTED.
398 IRC_USER(CLIENT * Client, REQUEST * Req)
403 assert(Client != NULL);
406 if (Client_Type(Client) == CLIENT_GOTNICK ||
408 Client_Type(Client) == CLIENT_UNKNOWN ||
410 Client_Type(Client) == CLIENT_GOTPASS)
413 _IRC_ARGC_EQ_OR_RETURN_(Client, Req, 4)
415 /* User name: only alphanumeric characters and limited
416 punctuation is allowed.*/
419 if (!isalnum((int)*ptr) &&
420 *ptr != '+' && *ptr != '-' && *ptr != '@' &&
421 *ptr != '.' && *ptr != '_') {
422 Conn_Close(Client_Conn(Client), NULL,
423 "Invalid user name", true);
429 /* Save the received username for authentication, and use
430 * it up to the first '@' as default user name (like ircd2.11,
431 * bahamut, ircd-seven, ...), prefixed with '~', if needed: */
432 Client_SetOrigUser(Client, Req->argv[0]);
433 ptr = strchr(Req->argv[0], '@');
437 ptr = Client_User(Client);
438 if (!ptr || !*ptr || *ptr == '~')
439 Client_SetUser(Client, Req->argv[0], false);
441 Client_SetUser(Client, Req->argv[0], false);
444 /* "Real name" or user info text: Don't set it to the empty
445 * string, the original ircd can't deal with such "real names"
446 * (e. g. "USER user * * :") ... */
448 Client_SetInfo(Client, Req->argv[3]);
450 Client_SetInfo(Client, "-");
452 LogDebug("Connection %d: got valid USER command ...",
453 Client_Conn(Client));
454 if (Client_Type(Client) == CLIENT_GOTNICK)
455 return Login_User(Client);
457 Client_SetType(Client, CLIENT_GOTUSER);
460 } else if (Client_Type(Client) == CLIENT_SERVER ||
461 Client_Type(Client) == CLIENT_SERVICE) {
462 /* Server/service updating an user */
463 _IRC_ARGC_EQ_OR_RETURN_(Client, Req, 4)
465 c = Client_Search(Req->prefix);
467 return IRC_WriteErrClient(Client, ERR_NOSUCHNICK_MSG,
471 Client_SetUser(c, Req->argv[0], true);
472 Client_SetOrigUser(c, Req->argv[0]);
473 Client_SetHostname(c, Req->argv[1]);
474 Client_SetInfo(c, Req->argv[3]);
476 LogDebug("Connection %d: got valid USER command for \"%s\".",
477 Client_Conn(Client), Client_Mask(c));
479 /* RFC 1459 style user registration?
480 * Introduce client to network: */
481 if (Client_Type(c) == CLIENT_GOTNICK)
482 Client_Introduce(Client, c, CLIENT_USER);
485 } else if (Client_Type(Client) == CLIENT_USER) {
486 /* Already registered connection */
487 return IRC_WriteErrClient(Client, ERR_ALREADYREGISTRED_MSG,
490 /* Unexpected/invalid connection state? */
491 return IRC_WriteErrClient(Client, ERR_NOTREGISTERED_MSG,
497 * Handler for the IRC "SERVICE" command.
499 * At the moment ngIRCd doesn't support directly linked services, so this
500 * function returns ERR_ERRONEUSNICKNAME when the SERVICE command has not been
501 * received from a peer server.
503 * @param Client The client from which this command has been received.
504 * @param Req Request structure with prefix and all parameters.
505 * @return CONNECTED or DISCONNECTED.
508 IRC_SERVICE(CLIENT *Client, REQUEST *Req)
511 char *nick, *user, *host, *info, *modes, *ptr;
514 assert(Client != NULL);
517 if (Client_Type(Client) != CLIENT_GOTPASS &&
518 Client_Type(Client) != CLIENT_SERVER)
519 return IRC_WriteErrClient(Client, ERR_ALREADYREGISTRED_MSG,
522 if (Client_Type(Client) != CLIENT_SERVER)
523 return IRC_WriteErrClient(Client, ERR_ERRONEUSNICKNAME_MSG,
524 Client_ID(Client), Req->argv[0]);
527 user = NULL; host = NULL;
528 token = atoi(Req->argv[1]);
529 hops = atoi(Req->argv[4]);
532 /* Validate service name ("nickname") */
533 c = Client_Search(nick);
535 /* Nickname collision: disconnect (KILL) both clients! */
536 Log(LOG_ERR, "Server %s introduces already registered service \"%s\"!",
537 Client_ID(Client), nick);
538 Kill_Nick(nick, "Nick collision");
542 /* Get the server to which the service is connected */
543 intr_c = Client_GetFromToken(Client, token);
545 Log(LOG_ERR, "Server %s introduces service \"%s\" on unknown server!?",
546 Client_ID(Client), nick);
547 Kill_Nick(nick, "Unknown server");
551 /* Get user and host name */
552 ptr = strchr(nick, '@');
558 host = Client_Hostname(intr_c);
559 ptr = strchr(nick, '!');
567 /* According to RFC 2812/2813 parameter 4 <type> "is currently reserved
568 * for future usage"; but we use it to transfer the modes and check
569 * that the first character is a '+' sign and ignore it otherwise. */
570 modes = (Req->argv[3][0] == '+') ? ++Req->argv[3] : "";
572 c = Client_NewRemoteUser(intr_c, nick, hops, user, host,
573 token, modes, info, true);
575 /* Couldn't create client structure, so KILL the service to
576 * keep network status consistent ... */
577 Log(LOG_ALERT, "Can't create client structure! (on connection %d)",
578 Client_Conn(Client));
579 Kill_Nick(nick, "Server error");
583 Client_Introduce(Client, c, CLIENT_SERVICE);
588 * Handler for the IRC "WEBIRC" command.
590 * @param Client The client from which this command has been received.
591 * @param Req Request structure with prefix and all parameters.
592 * @return CONNECTED or DISCONNECTED.
595 IRC_WEBIRC(CLIENT *Client, REQUEST *Req)
597 if (!Conf_WebircPwd[0] || strcmp(Req->argv[0], Conf_WebircPwd) != 0)
598 return IRC_WriteErrClient(Client, ERR_PASSWDMISMATCH_MSG,
601 LogDebug("Connection %d: got valid WEBIRC command: user=%s, host=%s, ip=%s",
602 Client_Conn(Client), Req->argv[1], Req->argv[2], Req->argv[3]);
604 Client_SetUser(Client, Req->argv[1], true);
605 Client_SetOrigUser(Client, Req->argv[1]);
606 Client_SetHostname(Client, Req->argv[2]);
607 Client_SetIPAText(Client, Req->argv[3]);
613 * Handler for the IRC "QUIT" command.
615 * @param Client The client from which this command has been received.
616 * @param Req Request structure with prefix and all parameters.
617 * @return CONNECTED or DISCONNECTED.
620 IRC_QUIT( CLIENT *Client, REQUEST *Req )
623 char quitmsg[LINE_LEN];
625 assert(Client != NULL);
629 strlcpy(quitmsg, Req->argv[0], sizeof quitmsg);
631 if (Client_Type(Client) == CLIENT_SERVER) {
633 target = Client_Search(Req->prefix);
636 "Got QUIT from %s for unknown client!?",
641 if (target != Client) {
642 Client_Destroy(target, "Got QUIT command",
643 Req->argc == 1 ? quitmsg : NULL, true);
646 Conn_Close(Client_Conn(Client), "Got QUIT command",
647 Req->argc == 1 ? quitmsg : NULL, true);
651 if (Req->argc == 1 && quitmsg[0] != '\"') {
652 /* " " to avoid confusion */
653 strlcpy(quitmsg, "\"", sizeof quitmsg);
654 strlcat(quitmsg, Req->argv[0], sizeof quitmsg-1);
655 strlcat(quitmsg, "\"", sizeof quitmsg );
658 /* User, Service, or not yet registered */
659 Conn_Close(Client_Conn(Client), "Got QUIT command",
660 Req->argc == 1 ? quitmsg : NULL, true);
669 * Handler for HTTP command, e.g. GET and POST
671 * We handle these commands here to avoid the quite long timeout when
672 * some user tries to access this IRC daemon using an web browser ...
674 * @param Client The client from which this command has been received.
675 * @param Req Request structure with prefix and all parameters.
676 * @return CONNECTED or DISCONNECTED.
679 IRC_QUIT_HTTP( CLIENT *Client, REQUEST *Req )
682 Req->argv[0] = "Oops, HTTP request received? This is IRC!";
683 return IRC_QUIT(Client, Req);
684 } /* IRC_QUIT_HTTP */
689 * Handler for the IRC "PING" command.
691 * @param Client The client from which this command has been received.
692 * @param Req Request structure with prefix and all parameters.
693 * @return CONNECTED or DISCONNECTED.
696 IRC_PING(CLIENT *Client, REQUEST *Req)
698 CLIENT *target, *from;
700 assert(Client != NULL);
704 return IRC_WriteErrClient(Client, ERR_NOORIGIN_MSG,
707 /* Don't ignore additional arguments when in "strict" mode */
708 _IRC_ARGC_LE_OR_RETURN_(Client, Req, 2)
712 /* A target has been specified ... */
713 target = Client_Search(Req->argv[1]);
715 if (!target || Client_Type(target) != CLIENT_SERVER)
716 return IRC_WriteErrClient(Client, ERR_NOSUCHSERVER_MSG,
717 Client_ID(Client), Req->argv[1]);
719 if (target != Client_ThisServer()) {
720 /* Ok, we have to forward the PING */
721 if (Client_Type(Client) == CLIENT_SERVER)
722 from = Client_Search(Req->prefix);
726 return IRC_WriteErrClient(Client,
727 ERR_NOSUCHSERVER_MSG,
728 Client_ID(Client), Req->prefix);
730 return IRC_WriteStrClientPrefix(target, from,
731 "PING %s :%s", Req->argv[0],
736 if (Client_Type(Client) == CLIENT_SERVER) {
738 from = Client_Search(Req->prefix);
742 from = Client_ThisServer();
744 return IRC_WriteErrClient(Client, ERR_NOSUCHSERVER_MSG,
745 Client_ID(Client), Req->prefix);
747 Log(LOG_DEBUG, "Connection %d: got PING, sending PONG ...",
748 Client_Conn(Client));
751 return IRC_WriteStrClient(Client, "PONG %s :%s",
752 Client_ID(from), Client_ID(Client));
754 /* Some clients depend on the argument being returned in the PONG
755 * reply (not mentioned in any RFC, though) */
756 return IRC_WriteStrClient(Client, "PONG %s :%s",
757 Client_ID(from), Req->argv[0]);
762 * Handler for the IRC "PONG" command.
764 * @param Client The client from which this command has been received.
765 * @param Req Request structure with prefix and all parameters.
766 * @return CONNECTED or DISCONNECTED.
769 IRC_PONG(CLIENT *Client, REQUEST *Req)
771 CLIENT *target, *from;
778 assert(Client != NULL);
781 /* Wrong number of arguments? */
783 if (Client_Type(Client) == CLIENT_USER)
784 return IRC_WriteErrClient(Client, ERR_NOORIGIN_MSG,
789 if (Client_Type(Client) == CLIENT_USER) {
790 _IRC_ARGC_LE_OR_RETURN_(Client, Req, 2)
794 if (Req->argc == 2 && Client_Type(Client) == CLIENT_SERVER) {
795 target = Client_Search(Req->argv[0]);
797 return IRC_WriteErrClient(Client, ERR_NOSUCHSERVER_MSG,
798 Client_ID(Client), Req->argv[0]);
800 from = Client_Search(Req->prefix);
802 if (target != Client_ThisServer() && target != from) {
803 /* Ok, we have to forward the message. */
805 return IRC_WriteErrClient(Client,
806 ERR_NOSUCHSERVER_MSG,
807 Client_ID(Client), Req->prefix);
809 if (Client_Type(Client_NextHop(target)) != CLIENT_SERVER)
813 return IRC_WriteStrClientPrefix(target, from,
814 "PONG %s :%s", s, Req->argv[1]);
818 /* The connection timestamp has already been updated when the data has
819 * been read from so socket, so we don't need to update it here. */
821 conn = Client_Conn(Client);
824 /* Check authentication PING-PONG ... */
825 auth_ping = Conn_GetAuthPing(conn);
827 LogDebug("AUTH PONG: waiting for token \"%ld\", got \"%s\" ...",
828 auth_ping, Req->argv[0]);
829 if (auth_ping == atoi(Req->argv[0])) {
830 Conn_SetAuthPing(conn, 0);
831 if (Client_Type(Client) == CLIENT_WAITAUTHPING)
834 if (!IRC_WriteStrClient(Client,
835 "To connect, type /QUOTE PONG %ld",
841 if (Client_Type(Client) == CLIENT_SERVER && Conn_LastPing(conn) == 0) {
843 "Synchronization with \"%s\" done (connection %d): %ld second%s [%ld users, %ld channels].",
844 Client_ID(Client), conn, time(NULL) - Conn_GetSignon(conn),
845 time(NULL) - Conn_GetSignon(conn) == 1 ? "" : "s",
846 Client_UserCount(), Channel_CountVisible(NULL));
847 Conn_UpdatePing(conn);
849 LogDebug("Connection %d: received PONG. Lag: %ld seconds.",
850 conn, time(NULL) - Conn_LastPing(conn));
856 * Kill all users with a specific nickname in the network.
858 * @param Nick Nickname.
859 * @param Reason Reason for the KILL.
862 Kill_Nick(char *Nick, char *Reason)
866 assert (Nick != NULL);
867 assert (Reason != NULL);
874 Log(LOG_ERR, "User(s) with nick \"%s\" will be disconnected: %s!",
877 IRC_KILL(Client_ThisServer(), &r);
881 * Change the nickname of a client.
883 * @param Origin The client which caused the nickname change.
884 * @param Target The client of which the nickname should be changed.
885 * @param NewNick The new nickname.
888 Change_Nick(CLIENT *Origin, CLIENT *Target, char *NewNick, bool InformClient)
890 if (Client_Conn(Target) > NONE) {
893 "%s \"%s\" changed nick (connection %d): \"%s\" -> \"%s\".",
894 Client_TypeText(Target), Client_Mask(Target),
895 Client_Conn(Target), Client_ID(Target), NewNick);
896 Conn_UpdateIdle(Client_Conn(Target));
899 LogDebug("%s \"%s\" changed nick: \"%s\" -> \"%s\".",
900 Client_TypeText(Target),
901 Client_Mask(Target), Client_ID(Target), NewNick);
904 /* Inform all servers and users (which have to know) of the new name */
906 IRC_WriteStrClientPrefix(Target, Target, "NICK :%s", NewNick);
907 IRC_WriteStrServersPrefix(NULL, Target, "NICK :%s", NewNick);
909 IRC_WriteStrServersPrefix(Origin, Target, "NICK :%s", NewNick);
910 IRC_WriteStrRelatedPrefix(Target, Target, false, "NICK :%s", NewNick);
912 /* Register old nickname for WHOWAS queries */
913 Client_RegisterWhowas(Target);
915 /* Save new nickname */
916 Client_SetID(Target, NewNick);