2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2014 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"
34 #include "irc-macros.h"
35 #include "irc-write.h"
37 #include "irc-login.h"
39 static void Change_Nick PARAMS((CLIENT * Origin, CLIENT * Target, char *NewNick,
43 * Handler for the IRC "PASS" command.
45 * @param Client The client from which this command has been received.
46 * @param Req Request structure with prefix and all parameters.
47 * @return CONNECTED or DISCONNECTED.
50 IRC_PASS( CLIENT *Client, REQUEST *Req )
52 char *type, *orig_flags;
53 int protohigh, protolow;
55 assert( Client != NULL );
56 assert( Req != NULL );
58 /* Return an error if this is not a local client */
59 if (Client_Conn(Client) <= NONE)
60 return IRC_WriteErrClient(Client, ERR_UNKNOWNCOMMAND_MSG,
61 Client_ID(Client), Req->command);
63 if (Client_Type(Client) == CLIENT_UNKNOWN && Req->argc == 1) {
64 /* Not yet registered "unknown" connection, PASS with one
65 * argument: either a regular client, service, or server
66 * using the old RFC 1459 section 4.1.1 syntax. */
67 LogDebug("Connection %d: got PASS command (RFC 1459) ...",
69 } else if ((Client_Type(Client) == CLIENT_UNKNOWN ||
70 Client_Type(Client) == CLIENT_UNKNOWNSERVER) &&
71 (Req->argc == 3 || Req->argc == 4)) {
72 /* Not yet registered "unknown" connection or outgoing server
73 * link, PASS with three or four argument: server using the
74 * RFC 2813 section 4.1.1 syntax. */
75 LogDebug("Connection %d: got PASS command (RFC 2813, new server link) ...",
77 } else if (Client_Type(Client) == CLIENT_UNKNOWN ||
78 Client_Type(Client) == CLIENT_UNKNOWNSERVER) {
79 /* Unregistered connection, but wrong number of arguments: */
80 return IRC_WriteErrClient(Client, ERR_NEEDMOREPARAMS_MSG,
81 Client_ID(Client), Req->command);
83 /* Registered connection, PASS command is not allowed! */
84 return IRC_WriteErrClient(Client, ERR_ALREADYREGISTRED_MSG,
88 Conn_SetPassword(Client_Conn(Client), Req->argv[0]);
90 /* Protocol version */
91 if (Req->argc >= 2 && strlen(Req->argv[1]) >= 4) {
97 Req->argv[1][4] = '\0';
98 protolow = atoi(&Req->argv[1][2]);
99 Req->argv[1][2] = '\0';
100 protohigh = atoi(Req->argv[1]);
102 Req->argv[1][2] = c2;
103 Req->argv[1][4] = c4;
105 Client_SetType(Client, CLIENT_GOTPASS_2813);
107 protohigh = protolow = 0;
108 Client_SetType(Client, CLIENT_GOTPASS);
111 /* Protocol type, see doc/Protocol.txt */
112 if (Req->argc >= 2 && strlen(Req->argv[1]) > 4)
113 type = &Req->argv[1][4];
117 /* Protocol flags/options */
119 orig_flags = Req->argv[3];
123 /* Implementation, version and IRC+ flags */
124 if (Req->argc >= 3) {
125 char *impl, *ptr, *serverver, *flags;
128 ptr = strchr(impl, '|');
132 if (type && strcmp(type, PROTOIRCPLUS) == 0) {
133 /* The peer seems to be a server which supports the
134 * IRC+ protocol (see doc/Protocol.txt). */
135 serverver = ptr ? ptr + 1 : "?";
136 flags = strchr(ptr ? serverver : impl, ':');
143 "Peer on connection %d announces itself as %s-%s using protocol %d.%d/IRC+ (flags: \"%s\").",
144 Client_Conn(Client), impl, serverver,
145 protohigh, protolow, flags);
147 /* The peer seems to be a server supporting the
148 * "original" IRC protocol (RFC 2813). */
149 if (strchr(orig_flags, 'Z'))
154 "Peer on connection %d announces itself as \"%s\" using protocol %d.%d (flags: \"%s\").",
155 Client_Conn(Client), impl,
156 protohigh, protolow, flags);
158 Client_SetFlags(Client, flags);
165 * Handler for the IRC "NICK" command.
167 * @param Client The client from which this command has been received.
168 * @param Req Request structure with prefix and all parameters.
169 * @return CONNECTED or DISCONNECTED.
172 IRC_NICK( CLIENT *Client, REQUEST *Req )
174 CLIENT *intr_c, *target, *c;
176 char *nick, *user, *hostname, *modes, *info;
179 assert( Client != NULL );
180 assert( Req != NULL );
182 /* Some IRC clients, for example BitchX, send the NICK and USER
183 * commands in the wrong order ... */
184 if(Client_Type(Client) == CLIENT_UNKNOWN
185 || Client_Type(Client) == CLIENT_GOTPASS
186 || Client_Type(Client) == CLIENT_GOTNICK
188 || Client_Type(Client) == CLIENT_GOTUSER
190 || Client_Type(Client) == CLIENT_USER
191 || Client_Type(Client) == CLIENT_SERVICE
192 || (Client_Type(Client) == CLIENT_SERVER && Req->argc == 1))
194 /* User registration or change of nickname */
195 _IRC_ARGC_EQ_OR_RETURN_(Client, Req, 1)
197 /* Search "target" client */
198 if (Client_Type(Client) == CLIENT_SERVER) {
199 target = Client_Search(Req->prefix);
201 return IRC_WriteErrClient(Client,
206 /* Is this a restricted client? */
207 if (Client_HasMode(Client, 'r'))
208 return IRC_WriteErrClient(Client,
215 /* If the clients tries to change to its own nickname we won't
216 * do anything. This is how the original ircd behaves and some
217 * clients (for example Snak) expect it to be like this.
218 * But I doubt that this is "really the right thing" ... */
219 if (strcmp(Client_ID(target), Req->argv[0]) == 0)
223 /* Check that the new nickname is available. Special case:
224 * the client only changes from/to upper to lower case. */
225 if (strcasecmp(Client_ID(target), Req->argv[0]) != 0) {
226 if (!Client_CheckNick(target, Req->argv[0]))
230 if (Client_Type(target) != CLIENT_USER &&
231 Client_Type(target) != CLIENT_SERVICE &&
232 Client_Type(target) != CLIENT_SERVER) {
234 LogDebug("Connection %d: got valid NICK command ...",
235 Client_Conn( Client ));
237 /* Register new nickname of this client */
238 Client_SetID( target, Req->argv[0] );
242 #ifdef HAVE_ARC4RANDOM
243 Conn_SetAuthPing(Client_Conn(Client), arc4random());
245 Conn_SetAuthPing(Client_Conn(Client), rand());
247 Conn_WriteStr(Client_Conn(Client), "PING :%ld",
248 Conn_GetAuthPing(Client_Conn(Client)));
249 LogDebug("Connection %d: sent AUTH PING %ld ...",
251 Conn_GetAuthPing(Client_Conn(Client)));
255 /* If we received a valid USER command already then
256 * register the new client! */
257 if( Client_Type( Client ) == CLIENT_GOTUSER )
258 return Login_User( Client );
260 Client_SetType( Client, CLIENT_GOTNICK );
262 /* Nickname change */
264 /* Check that the user isn't on any channels set +N */
265 if(Client_Type(Client) == CLIENT_USER &&
266 !Client_HasMode(Client, 'o')) {
267 chan = Channel_First();
269 if(Channel_IsMemberOf(chan, Client) &&
270 Channel_HasMode(chan, 'N'))
271 return IRC_WriteErrClient(Client,
272 ERR_NONICKCHANGE_MSG,
275 chan = Channel_Next(chan);
279 Change_Nick(Client, target, Req->argv[0],
280 Client_Type(Client) == CLIENT_USER ? true : false);
281 IRC_SetPenalty(target, 2);
285 } else if(Client_Type(Client) == CLIENT_SERVER ||
286 Client_Type(Client) == CLIENT_SERVICE) {
287 /* Server or service introduces new client */
289 /* Bad number of parameters? */
290 if (Req->argc != 2 && Req->argc != 7)
291 return IRC_WriteErrClient(Client, ERR_NEEDMOREPARAMS_MSG,
292 Client_ID(Client), Req->command);
294 if (Req->argc >= 7) {
295 /* RFC 2813 compatible syntax */
297 hops = atoi(Req->argv[1]);
299 hostname = Req->argv[3];
300 token = atoi(Req->argv[4]);
301 modes = Req->argv[5] + 1;
304 /* RFC 1459 compatible syntax */
308 hostname = Client_ID(Client);
309 token = atoi(Req->argv[1]);
314 c = Client_Search(nick);
317 * the new nick is already present on this server:
318 * the new and the old one have to be disconnected now.
321 "Server %s introduces already registered nick \"%s\"!",
322 Client_ID(Client), Req->argv[0]);
323 return IRC_KillClient(Client, NULL, Req->argv[0],
327 /* Find the Server this client is connected to */
328 intr_c = Client_GetFromToken(Client, token);
331 "Server %s introduces nick \"%s\" on unknown server!?",
332 Client_ID(Client), Req->argv[0]);
333 return IRC_KillClient(Client, NULL, Req->argv[0],
337 c = Client_NewRemoteUser(intr_c, nick, hops, user, hostname,
338 token, modes, info, true);
340 /* Out of memory, we need to disconnect client to keep
341 * network state consistent! */
343 "Can't create client structure! (on connection %d)",
344 Client_Conn(Client));
345 return IRC_KillClient(Client, NULL, Req->argv[0],
349 /* RFC 2813: client is now fully registered, inform all the
350 * other servers about the new user.
351 * RFC 1459: announce the new client only after receiving the
352 * USER command, first we need more information! */
354 LogDebug("Client \"%s\" is being registered (RFC 1459) ...",
356 Client_SetType(c, CLIENT_GOTNICK);
358 Client_Introduce(Client, c, CLIENT_USER);
363 return IRC_WriteErrClient(Client, ERR_ALREADYREGISTRED_MSG,
368 * Handler for the IRC "SVSNICK" command.
370 * @param Client The client from which this command has been received.
371 * @param Req Request structure with prefix and all parameters.
372 * @return CONNECTED or DISCONNECTED.
375 IRC_SVSNICK(CLIENT *Client, REQUEST *Req)
377 CLIENT *from, *target;
379 assert(Client != NULL);
382 /* Search the originator */
383 from = Client_Search(Req->prefix);
387 /* Search the target */
388 target = Client_Search(Req->argv[0]);
389 if (!target || Client_Type(target) != CLIENT_USER)
390 return IRC_WriteErrClient(Client, ERR_NOSUCHNICK_MSG,
391 Client_ID(Client), Req->argv[0]);
393 if (Client_Conn(target) <= NONE) {
394 /* We have to forward the message to the server handling
395 * this user; this is required to make sure all servers
396 * in the network do follow the nick name change! */
397 return IRC_WriteStrClientPrefix(Client_NextHop(target), from,
399 Req->argv[0], Req->argv[1]);
402 /* Make sure that the new nickname is valid */
403 if (!Client_CheckNick(from, Req->argv[1]))
406 Change_Nick(from, target, Req->argv[1], true);
411 * Handler for the IRC "USER" command.
413 * @param Client The client from which this command has been received.
414 * @param Req Request structure with prefix and all parameters.
415 * @return CONNECTED or DISCONNECTED.
418 IRC_USER(CLIENT * Client, REQUEST * Req)
423 assert(Client != NULL);
426 if (Client_Type(Client) == CLIENT_GOTNICK ||
428 Client_Type(Client) == CLIENT_UNKNOWN ||
430 Client_Type(Client) == CLIENT_GOTPASS)
433 _IRC_ARGC_EQ_OR_RETURN_(Client, Req, 4)
435 /* User name: only alphanumeric characters and limited
436 punctuation is allowed.*/
439 if (!isalnum((int)*ptr) &&
440 *ptr != '+' && *ptr != '-' && *ptr != '@' &&
441 *ptr != '.' && *ptr != '_') {
442 Conn_Close(Client_Conn(Client), NULL,
443 "Invalid user name", true);
449 /* Save the received username for authentication, and use
450 * it up to the first '@' as default user name (like ircd2.11,
451 * bahamut, ircd-seven, ...), prefixed with '~', if needed: */
452 Client_SetOrigUser(Client, Req->argv[0]);
453 ptr = strchr(Req->argv[0], '@');
457 ptr = Client_User(Client);
458 if (!ptr || !*ptr || *ptr == '~')
459 Client_SetUser(Client, Req->argv[0], false);
461 Client_SetUser(Client, Req->argv[0], false);
464 /* "Real name" or user info text: Don't set it to the empty
465 * string, the original ircd can't deal with such "real names"
466 * (e. g. "USER user * * :") ... */
468 Client_SetInfo(Client, Req->argv[3]);
470 Client_SetInfo(Client, "-");
472 LogDebug("Connection %d: got valid USER command ...",
473 Client_Conn(Client));
474 if (Client_Type(Client) == CLIENT_GOTNICK)
475 return Login_User(Client);
477 Client_SetType(Client, CLIENT_GOTUSER);
480 } else if (Client_Type(Client) == CLIENT_SERVER ||
481 Client_Type(Client) == CLIENT_SERVICE) {
482 /* Server/service updating an user */
483 _IRC_ARGC_EQ_OR_RETURN_(Client, Req, 4)
485 c = Client_Search(Req->prefix);
487 return IRC_WriteErrClient(Client, ERR_NOSUCHNICK_MSG,
491 Client_SetUser(c, Req->argv[0], true);
492 Client_SetOrigUser(c, Req->argv[0]);
493 Client_SetHostname(c, Req->argv[1]);
494 Client_SetInfo(c, Req->argv[3]);
496 LogDebug("Connection %d: got valid USER command for \"%s\".",
497 Client_Conn(Client), Client_Mask(c));
499 /* RFC 1459 style user registration?
500 * Introduce client to network: */
501 if (Client_Type(c) == CLIENT_GOTNICK)
502 Client_Introduce(Client, c, CLIENT_USER);
505 } else if (Client_Type(Client) == CLIENT_USER) {
506 /* Already registered connection */
507 return IRC_WriteErrClient(Client, ERR_ALREADYREGISTRED_MSG,
510 /* Unexpected/invalid connection state? */
511 return IRC_WriteErrClient(Client, ERR_NOTREGISTERED_MSG,
517 * Handler for the IRC "SERVICE" command.
519 * At the moment ngIRCd doesn't support directly linked services, so this
520 * function returns ERR_ERRONEUSNICKNAME when the SERVICE command has not been
521 * received from a peer server.
523 * @param Client The client from which this command has been received.
524 * @param Req Request structure with prefix and all parameters.
525 * @return CONNECTED or DISCONNECTED.
528 IRC_SERVICE(CLIENT *Client, REQUEST *Req)
531 char *nick, *user, *host, *info, *modes, *ptr;
534 assert(Client != NULL);
537 if (Client_Type(Client) != CLIENT_GOTPASS &&
538 Client_Type(Client) != CLIENT_SERVER)
539 return IRC_WriteErrClient(Client, ERR_ALREADYREGISTRED_MSG,
542 if (Client_Type(Client) != CLIENT_SERVER)
543 return IRC_WriteErrClient(Client, ERR_ERRONEUSNICKNAME_MSG,
544 Client_ID(Client), Req->argv[0]);
547 user = NULL; host = NULL;
548 token = atoi(Req->argv[1]);
549 hops = atoi(Req->argv[4]);
552 /* Validate service name ("nickname") */
553 c = Client_Search(nick);
555 /* Nickname collision: disconnect (KILL) both clients! */
557 "Server %s introduces already registered service \"%s\"!",
558 Client_ID(Client), nick);
559 return IRC_KillClient(Client, NULL, nick, "Nick collision");
562 /* Get the server to which the service is connected */
563 intr_c = Client_GetFromToken(Client, token);
566 "Server %s introduces service \"%s\" on unknown server!?",
567 Client_ID(Client), nick);
568 return IRC_KillClient(Client, NULL, nick, "Unknown server");
571 /* Get user and host name */
572 ptr = strchr(nick, '@');
578 host = Client_Hostname(intr_c);
579 ptr = strchr(nick, '!');
587 /* According to RFC 2812/2813 parameter 4 <type> "is currently reserved
588 * for future usage"; but we use it to transfer the modes and check
589 * that the first character is a '+' sign and ignore it otherwise. */
590 modes = (Req->argv[3][0] == '+') ? ++Req->argv[3] : "";
592 c = Client_NewRemoteUser(intr_c, nick, hops, user, host,
593 token, modes, info, true);
595 /* Couldn't create client structure, so KILL the service to
596 * keep network status consistent ... */
598 "Can't create client structure! (on connection %d)",
599 Client_Conn(Client));
600 return IRC_KillClient(Client, NULL, nick, "Server error");
603 Client_Introduce(Client, c, CLIENT_SERVICE);
608 * Handler for the IRC "WEBIRC" command.
610 * @param Client The client from which this command has been received.
611 * @param Req Request structure with prefix and all parameters.
612 * @return CONNECTED or DISCONNECTED.
615 IRC_WEBIRC(CLIENT *Client, REQUEST *Req)
617 if (!Conf_WebircPwd[0] || strcmp(Req->argv[0], Conf_WebircPwd) != 0)
618 return IRC_WriteErrClient(Client, ERR_PASSWDMISMATCH_MSG,
621 LogDebug("Connection %d: got valid WEBIRC command: user=%s, host=%s, ip=%s",
622 Client_Conn(Client), Req->argv[1], Req->argv[2], Req->argv[3]);
624 Client_SetUser(Client, Req->argv[1], true);
625 Client_SetOrigUser(Client, Req->argv[1]);
627 Client_SetHostname(Client, Req->argv[2]);
629 Client_SetHostname(Client, Req->argv[3]);
630 Client_SetIPAText(Client, Req->argv[3]);
636 * Handler for the IRC "QUIT" command.
638 * @param Client The client from which this command has been received.
639 * @param Req Request structure with prefix and all parameters.
640 * @return CONNECTED or DISCONNECTED.
643 IRC_QUIT( CLIENT *Client, REQUEST *Req )
646 char quitmsg[COMMAND_LEN];
648 assert(Client != NULL);
652 strlcpy(quitmsg, Req->argv[0], sizeof quitmsg);
654 if (Client_Type(Client) == CLIENT_SERVER) {
656 target = Client_Search(Req->prefix);
659 "Got QUIT from %s for unknown client!?",
664 if (target != Client) {
665 Client_Destroy(target, "Got QUIT command",
666 Req->argc == 1 ? quitmsg : NULL, true);
669 Conn_Close(Client_Conn(Client), "Got QUIT command",
670 Req->argc == 1 ? quitmsg : NULL, true);
674 if (Req->argc == 1 && quitmsg[0] != '\"') {
675 /* " " to avoid confusion */
676 strlcpy(quitmsg, "\"", sizeof quitmsg);
677 strlcat(quitmsg, Req->argv[0], sizeof quitmsg-1);
678 strlcat(quitmsg, "\"", sizeof quitmsg );
681 /* User, Service, or not yet registered */
682 Conn_Close(Client_Conn(Client), "Got QUIT command",
683 Req->argc == 1 ? quitmsg : NULL, true);
692 * Handler for HTTP command, e.g. GET and POST
694 * We handle these commands here to avoid the quite long timeout when
695 * some user tries to access this IRC daemon using an web browser ...
697 * @param Client The client from which this command has been received.
698 * @param Req Request structure with prefix and all parameters.
699 * @return CONNECTED or DISCONNECTED.
702 IRC_QUIT_HTTP( CLIENT *Client, REQUEST *Req )
705 Req->argv[0] = "Oops, HTTP request received? This is IRC!";
706 return IRC_QUIT(Client, Req);
707 } /* IRC_QUIT_HTTP */
712 * Handler for the IRC "PING" command.
714 * @param Client The client from which this command has been received.
715 * @param Req Request structure with prefix and all parameters.
716 * @return CONNECTED or DISCONNECTED.
719 IRC_PING(CLIENT *Client, REQUEST *Req)
721 CLIENT *target, *from;
723 assert(Client != NULL);
727 return IRC_WriteErrClient(Client, ERR_NOORIGIN_MSG,
730 /* Don't ignore additional arguments when in "strict" mode */
731 _IRC_ARGC_LE_OR_RETURN_(Client, Req, 2)
735 /* A target has been specified ... */
736 target = Client_Search(Req->argv[1]);
738 if (!target || Client_Type(target) != CLIENT_SERVER)
739 return IRC_WriteErrClient(Client, ERR_NOSUCHSERVER_MSG,
740 Client_ID(Client), Req->argv[1]);
742 if (target != Client_ThisServer()) {
743 /* Ok, we have to forward the PING */
744 if (Client_Type(Client) == CLIENT_SERVER)
745 from = Client_Search(Req->prefix);
749 return IRC_WriteErrClient(Client,
750 ERR_NOSUCHSERVER_MSG,
751 Client_ID(Client), Req->prefix);
753 return IRC_WriteStrClientPrefix(target, from,
754 "PING %s :%s", Req->argv[0],
759 if (Client_Type(Client) == CLIENT_SERVER) {
761 from = Client_Search(Req->prefix);
765 from = Client_ThisServer();
767 return IRC_WriteErrClient(Client, ERR_NOSUCHSERVER_MSG,
768 Client_ID(Client), Req->prefix);
770 Log(LOG_DEBUG, "Connection %d: got PING, sending PONG ...",
771 Client_Conn(Client));
774 return IRC_WriteStrClient(Client, "PONG %s :%s",
775 Client_ID(from), Client_ID(Client));
777 /* Some clients depend on the argument being returned in the PONG
778 * reply (not mentioned in any RFC, though) */
779 return IRC_WriteStrClient(Client, "PONG %s :%s",
780 Client_ID(from), Req->argv[0]);
785 * Handler for the IRC "PONG" command.
787 * @param Client The client from which this command has been received.
788 * @param Req Request structure with prefix and all parameters.
789 * @return CONNECTED or DISCONNECTED.
792 IRC_PONG(CLIENT *Client, REQUEST *Req)
794 CLIENT *target, *from;
801 assert(Client != NULL);
804 /* Wrong number of arguments? */
806 if (Client_Type(Client) == CLIENT_USER)
807 return IRC_WriteErrClient(Client, ERR_NOORIGIN_MSG,
812 if (Client_Type(Client) == CLIENT_USER) {
813 _IRC_ARGC_LE_OR_RETURN_(Client, Req, 2)
817 if (Req->argc == 2 && Client_Type(Client) == CLIENT_SERVER) {
818 target = Client_Search(Req->argv[0]);
820 return IRC_WriteErrClient(Client, ERR_NOSUCHSERVER_MSG,
821 Client_ID(Client), Req->argv[0]);
823 from = Client_Search(Req->prefix);
825 if (target != Client_ThisServer() && target != from) {
826 /* Ok, we have to forward the message. */
828 return IRC_WriteErrClient(Client,
829 ERR_NOSUCHSERVER_MSG,
830 Client_ID(Client), Req->prefix);
832 if (Client_Type(Client_NextHop(target)) != CLIENT_SERVER)
836 return IRC_WriteStrClientPrefix(target, from,
837 "PONG %s :%s", s, Req->argv[1]);
841 /* The connection timestamp has already been updated when the data has
842 * been read from so socket, so we don't need to update it here. */
844 conn = Client_Conn(Client);
847 /* Check authentication PING-PONG ... */
848 auth_ping = Conn_GetAuthPing(conn);
850 LogDebug("AUTH PONG: waiting for token \"%ld\", got \"%s\" ...",
851 auth_ping, Req->argv[0]);
852 if (auth_ping == atol(Req->argv[0])) {
853 Conn_SetAuthPing(conn, 0);
854 if (Client_Type(Client) == CLIENT_WAITAUTHPING)
857 if (!IRC_WriteStrClient(Client,
858 "NOTICE %s :To connect, type /QUOTE PONG %ld",
859 Client_ID(Client), auth_ping))
864 if (Client_Type(Client) == CLIENT_SERVER && Conn_LastPing(conn) == 0) {
866 "Synchronization with \"%s\" done (connection %d): %ld second%s [%ld users, %ld channels].",
867 Client_ID(Client), conn, time(NULL) - Conn_GetSignon(conn),
868 time(NULL) - Conn_GetSignon(conn) == 1 ? "" : "s",
869 Client_UserCount(), Channel_CountVisible(NULL));
870 Conn_UpdatePing(conn);
872 LogDebug("Connection %d: received PONG. Lag: %ld seconds.",
873 conn, time(NULL) - Conn_LastPing(conn));
879 * Change the nickname of a client.
881 * @param Origin The client which caused the nickname change.
882 * @param Target The client of which the nickname should be changed.
883 * @param NewNick The new nickname.
886 Change_Nick(CLIENT *Origin, CLIENT *Target, char *NewNick, bool InformClient)
888 if (Client_Conn(Target) > NONE) {
891 "%s \"%s\" changed nick (connection %d): \"%s\" -> \"%s\".",
892 Client_TypeText(Target), Client_Mask(Target),
893 Client_Conn(Target), Client_ID(Target), NewNick);
894 Conn_UpdateIdle(Client_Conn(Target));
897 LogDebug("%s \"%s\" changed nick: \"%s\" -> \"%s\".",
898 Client_TypeText(Target),
899 Client_Mask(Target), Client_ID(Target), NewNick);
902 /* Inform all servers and users (which have to know) of the new name */
904 IRC_WriteStrClientPrefix(Target, Target, "NICK :%s", NewNick);
905 IRC_WriteStrServersPrefix(NULL, Target, "NICK :%s", NewNick);
907 IRC_WriteStrServersPrefix(Origin, Target, "NICK :%s", NewNick);
908 IRC_WriteStrRelatedPrefix(Target, Target, false, "NICK :%s", NewNick);
910 /* Register old nickname for WHOWAS queries */
911 Client_RegisterWhowas(Target);
913 /* Save new nickname */
914 Client_SetID(Target, NewNick);