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_WriteStrClient(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 IRC_SetPenalty(Client, 2);
85 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
86 Client_ID(Client), Req->command);
88 /* Registered connection, PASS command is not allowed! */
89 IRC_SetPenalty(Client, 2);
90 return IRC_WriteStrClient(Client, ERR_ALREADYREGISTRED_MSG,
94 Conn_SetPassword(Client_Conn(Client), Req->argv[0]);
96 /* Protocol version */
97 if (Req->argc >= 2 && strlen(Req->argv[1]) >= 4) {
100 c2 = Req->argv[1][2];
101 c4 = Req->argv[1][4];
103 Req->argv[1][4] = '\0';
104 protolow = atoi(&Req->argv[1][2]);
105 Req->argv[1][2] = '\0';
106 protohigh = atoi(Req->argv[1]);
108 Req->argv[1][2] = c2;
109 Req->argv[1][4] = c4;
111 Client_SetType(Client, CLIENT_GOTPASS_2813);
113 protohigh = protolow = 0;
114 Client_SetType(Client, CLIENT_GOTPASS);
117 /* Protocol type, see doc/Protocol.txt */
118 if (Req->argc >= 2 && strlen(Req->argv[1]) > 4)
119 type = &Req->argv[1][4];
123 /* Protocol flags/options */
125 orig_flags = Req->argv[3];
129 /* Implementation, version and IRC+ flags */
130 if (Req->argc >= 3) {
131 char *impl, *ptr, *serverver, *flags;
134 ptr = strchr(impl, '|');
138 if (type && strcmp(type, PROTOIRCPLUS) == 0) {
139 /* The peer seems to be a server which supports the
140 * IRC+ protocol (see doc/Protocol.txt). */
141 serverver = ptr ? ptr + 1 : "?";
142 flags = strchr(ptr ? serverver : impl, ':');
149 "Peer on connection %d announces itself as %s-%s using protocol %d.%d/IRC+ (flags: \"%s\").",
150 Client_Conn(Client), impl, serverver,
151 protohigh, protolow, flags);
153 /* The peer seems to be a server supporting the
154 * "original" IRC protocol (RFC 2813). */
155 if (strchr(orig_flags, 'Z'))
160 "Peer on connection %d announces itself as \"%s\" using protocol %d.%d (flags: \"%s\").",
161 Client_Conn(Client), impl,
162 protohigh, protolow, flags);
164 Client_SetFlags(Client, flags);
171 * Handler for the IRC "NICK" command.
173 * @param Client The client from which this command has been received.
174 * @param Req Request structure with prefix and all parameters.
175 * @return CONNECTED or DISCONNECTED.
178 IRC_NICK( CLIENT *Client, REQUEST *Req )
180 CLIENT *intr_c, *target, *c;
181 char *nick, *user, *hostname, *modes, *info;
184 assert( Client != NULL );
185 assert( Req != NULL );
187 /* Some IRC clients, for example BitchX, send the NICK and USER
188 * commands in the wrong order ... */
189 if(Client_Type(Client) == CLIENT_UNKNOWN
190 || Client_Type(Client) == CLIENT_GOTPASS
191 || Client_Type(Client) == CLIENT_GOTNICK
193 || Client_Type(Client) == CLIENT_GOTUSER
195 || Client_Type(Client) == CLIENT_USER
196 || Client_Type(Client) == CLIENT_SERVICE
197 || (Client_Type(Client) == CLIENT_SERVER && Req->argc == 1))
199 /* User registration or change of nickname */
200 _IRC_ARGC_EQ_OR_RETURN_(Client, Req, 1)
202 /* Search "target" client */
203 if (Client_Type(Client) == CLIENT_SERVER) {
204 target = Client_Search(Req->prefix);
206 return IRC_WriteStrClient( Client,
211 /* Is this a restricted client? */
212 if (Client_HasMode(Client, 'r')) {
213 IRC_SetPenalty(Client, 2);
214 return IRC_WriteStrClient( Client,
216 Client_ID( Client ));
222 /* If the clients tries to change to its own nickname we won't
223 * do anything. This is how the original ircd behaves and some
224 * clients (for example Snak) expect it to be like this.
225 * But I doubt that this is "really the right thing" ... */
226 if (strcmp(Client_ID(target), Req->argv[0]) == 0)
230 /* Check that the new nickname is available. Special case:
231 * the client only changes from/to upper to lower case. */
232 if (strcasecmp(Client_ID(target), Req->argv[0]) != 0) {
233 if (!Client_CheckNick(target, Req->argv[0]))
237 if (Client_Type(target) != CLIENT_USER &&
238 Client_Type(target) != CLIENT_SERVICE &&
239 Client_Type(target) != CLIENT_SERVER) {
241 LogDebug("Connection %d: got valid NICK command ...",
242 Client_Conn( Client ));
244 /* Register new nickname of this client */
245 Client_SetID( target, Req->argv[0] );
249 Conn_SetAuthPing(Client_Conn(Client), rand());
250 IRC_WriteStrClient(Client, "PING :%ld",
251 Conn_GetAuthPing(Client_Conn(Client)));
252 LogDebug("Connection %d: sent AUTH PING %ld ...",
254 Conn_GetAuthPing(Client_Conn(Client)));
258 /* If we received a valid USER command already then
259 * register the new client! */
260 if( Client_Type( Client ) == CLIENT_GOTUSER )
261 return Login_User( Client );
263 Client_SetType( Client, CLIENT_GOTNICK );
265 /* Nickname change */
266 Change_Nick(Client, target, Req->argv[0],
267 Client_Type(Client) == CLIENT_USER ? true : false);
268 IRC_SetPenalty(target, 2);
272 } else if(Client_Type(Client) == CLIENT_SERVER ||
273 Client_Type(Client) == CLIENT_SERVICE) {
274 /* Server or service introduces new client */
276 /* Bad number of parameters? */
277 if (Req->argc != 2 && Req->argc != 7)
278 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
279 Client_ID(Client), Req->command);
281 if (Req->argc >= 7) {
282 /* RFC 2813 compatible syntax */
284 hops = atoi(Req->argv[1]);
286 hostname = Req->argv[3];
287 token = atoi(Req->argv[4]);
288 modes = Req->argv[5] + 1;
291 /* RFC 1459 compatible syntax */
295 hostname = Client_ID(Client);
296 token = atoi(Req->argv[1]);
301 c = Client_Search(nick);
304 * the new nick is already present on this server:
305 * the new and the old one have to be disconnected now.
307 Log( LOG_ERR, "Server %s introduces already registered nick \"%s\"!", Client_ID( Client ), Req->argv[0] );
308 Kill_Nick( Req->argv[0], "Nick collision" );
312 /* Find the Server this client is connected to */
313 intr_c = Client_GetFromToken(Client, token);
315 Log( LOG_ERR, "Server %s introduces nick \"%s\" on unknown server!?", Client_ID( Client ), Req->argv[0] );
316 Kill_Nick( Req->argv[0], "Unknown server" );
320 c = Client_NewRemoteUser(intr_c, nick, hops, user, hostname,
321 token, modes, info, true);
323 /* Out of memory, we need to disconnect client to keep
324 * network state consistent! */
326 "Can't create client structure! (on connection %d)",
327 Client_Conn(Client));
328 Kill_Nick(Req->argv[0], "Server error");
332 /* RFC 2813: client is now fully registered, inform all the
333 * other servers about the new user.
334 * RFC 1459: announce the new client only after receiving the
335 * USER command, first we need more information! */
337 LogDebug("Client \"%s\" is being registered (RFC 1459) ...",
339 Client_SetType(c, CLIENT_GOTNICK);
341 Client_Introduce(Client, c, CLIENT_USER);
346 return IRC_WriteStrClient(Client, ERR_ALREADYREGISTRED_MSG,
351 * Handler for the IRC "SVSNICK" command.
353 * @param Client The client from which this command has been received.
354 * @param Req Request structure with prefix and all parameters.
355 * @return CONNECTED or DISCONNECTED.
358 IRC_SVSNICK(CLIENT *Client, REQUEST *Req)
360 CLIENT *from, *target;
362 assert(Client != NULL);
365 _IRC_ARGC_EQ_OR_RETURN_(Client, Req, 2)
367 /* Search the originator */
368 from = Client_Search(Req->prefix);
372 /* Search the target */
373 target = Client_Search(Req->argv[0]);
374 if (!target || Client_Type(target) != CLIENT_USER) {
375 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
376 Client_ID(Client), Req->argv[0]);
379 if (Client_Conn(target) <= NONE) {
380 /* We have to forward the message to the server handling
381 * this user; this is required to make sure all servers
382 * in the network do follow the nick name change! */
383 return IRC_WriteStrClientPrefix(Client_NextHop(target), from,
385 Req->argv[0], Req->argv[1]);
388 /* Make sure that the new nickname is valid */
389 if (!Client_CheckNick(from, Req->argv[1]))
392 Change_Nick(from, target, Req->argv[1], true);
397 * Handler for the IRC "USER" command.
399 * @param Client The client from which this command has been received.
400 * @param Req Request structure with prefix and all parameters.
401 * @return CONNECTED or DISCONNECTED.
404 IRC_USER(CLIENT * Client, REQUEST * Req)
409 assert(Client != NULL);
412 if (Client_Type(Client) == CLIENT_GOTNICK ||
414 Client_Type(Client) == CLIENT_UNKNOWN ||
416 Client_Type(Client) == CLIENT_GOTPASS)
419 _IRC_ARGC_EQ_OR_RETURN_(Client, Req, 4)
421 /* User name: only alphanumeric characters and limited
422 punctuation is allowed.*/
425 if (!isalnum((int)*ptr) &&
426 *ptr != '+' && *ptr != '-' && *ptr != '@' &&
427 *ptr != '.' && *ptr != '_') {
428 Conn_Close(Client_Conn(Client), NULL,
429 "Invalid user name", true);
435 /* Save the received username for authentication, and use
436 * it up to the first '@' as default user name (like ircd2.11,
437 * bahamut, ircd-seven, ...), prefixed with '~', if needed: */
438 Client_SetOrigUser(Client, Req->argv[0]);
439 ptr = strchr(Req->argv[0], '@');
443 ptr = Client_User(Client);
444 if (!ptr || !*ptr || *ptr == '~')
445 Client_SetUser(Client, Req->argv[0], false);
447 Client_SetUser(Client, Req->argv[0], false);
450 /* "Real name" or user info text: Don't set it to the empty
451 * string, the original ircd can't deal with such "real names"
452 * (e. g. "USER user * * :") ... */
454 Client_SetInfo(Client, Req->argv[3]);
456 Client_SetInfo(Client, "-");
458 LogDebug("Connection %d: got valid USER command ...",
459 Client_Conn(Client));
460 if (Client_Type(Client) == CLIENT_GOTNICK)
461 return Login_User(Client);
463 Client_SetType(Client, CLIENT_GOTUSER);
466 } else if (Client_Type(Client) == CLIENT_SERVER ||
467 Client_Type(Client) == CLIENT_SERVICE) {
468 /* Server/service updating an user */
469 _IRC_ARGC_EQ_OR_RETURN_(Client, Req, 4)
471 c = Client_Search(Req->prefix);
473 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
477 Client_SetUser(c, Req->argv[0], true);
478 Client_SetOrigUser(c, Req->argv[0]);
479 Client_SetHostname(c, Req->argv[1]);
480 Client_SetInfo(c, Req->argv[3]);
482 LogDebug("Connection %d: got valid USER command for \"%s\".",
483 Client_Conn(Client), Client_Mask(c));
485 /* RFC 1459 style user registration?
486 * Introduce client to network: */
487 if (Client_Type(c) == CLIENT_GOTNICK)
488 Client_Introduce(Client, c, CLIENT_USER);
491 } else if (Client_Type(Client) == CLIENT_USER) {
492 /* Already registered connection */
493 IRC_SetPenalty(Client, 2);
494 return IRC_WriteStrClient(Client, ERR_ALREADYREGISTRED_MSG,
497 /* Unexpected/invalid connection state? */
498 IRC_SetPenalty(Client, 2);
499 return IRC_WriteStrClient(Client, ERR_NOTREGISTERED_MSG,
505 * Handler for the IRC "SERVICE" command.
507 * At the moment ngIRCd doesn't support directly linked services, so this
508 * function returns ERR_ERRONEUSNICKNAME when the SERVICE command has not been
509 * received from a peer server.
511 * @param Client The client from which this command has been received.
512 * @param Req Request structure with prefix and all parameters.
513 * @return CONNECTED or DISCONNECTED.
516 IRC_SERVICE(CLIENT *Client, REQUEST *Req)
519 char *nick, *user, *host, *info, *modes, *ptr;
522 assert(Client != NULL);
525 if (Client_Type(Client) != CLIENT_GOTPASS &&
526 Client_Type(Client) != CLIENT_SERVER) {
527 IRC_SetPenalty(Client, 2);
528 return IRC_WriteStrClient(Client, ERR_ALREADYREGISTRED_MSG,
532 _IRC_ARGC_EQ_OR_RETURN_(Client, Req, 6)
534 if (Client_Type(Client) != CLIENT_SERVER)
535 return IRC_WriteStrClient(Client, ERR_ERRONEUSNICKNAME_MSG,
536 Client_ID(Client), Req->argv[0]);
539 user = NULL; host = NULL;
540 token = atoi(Req->argv[1]);
541 hops = atoi(Req->argv[4]);
544 /* Validate service name ("nickname") */
545 c = Client_Search(nick);
547 /* Nickname collission: disconnect (KILL) both clients! */
548 Log(LOG_ERR, "Server %s introduces already registered service \"%s\"!",
549 Client_ID(Client), nick);
550 Kill_Nick(nick, "Nick collision");
554 /* Get the server to which the service is connected */
555 intr_c = Client_GetFromToken(Client, token);
557 Log(LOG_ERR, "Server %s introduces service \"%s\" on unknown server!?",
558 Client_ID(Client), nick);
559 Kill_Nick(nick, "Unknown server");
563 /* Get user and host name */
564 ptr = strchr(nick, '@');
570 host = Client_Hostname(intr_c);
571 ptr = strchr(nick, '!');
579 /* According to RFC 2812/2813 parameter 4 <type> "is currently reserved
580 * for future usage"; but we use it to transfer the modes and check
581 * that the first character is a '+' sign and ignore it otherwise. */
582 modes = (Req->argv[3][0] == '+') ? ++Req->argv[3] : "";
584 c = Client_NewRemoteUser(intr_c, nick, hops, user, host,
585 token, modes, info, true);
587 /* Couldn't create client structure, so KILL the service to
588 * keep network status consistent ... */
589 Log(LOG_ALERT, "Can't create client structure! (on connection %d)",
590 Client_Conn(Client));
591 Kill_Nick(nick, "Server error");
595 Client_Introduce(Client, c, CLIENT_SERVICE);
600 * Handler for the IRC "WEBIRC" command.
602 * @param Client The client from which this command has been received.
603 * @param Req Request structure with prefix and all parameters.
604 * @return CONNECTED or DISCONNECTED.
607 IRC_WEBIRC(CLIENT *Client, REQUEST *Req)
609 _IRC_ARGC_EQ_OR_RETURN_(Client, Req, 4)
611 if (!Conf_WebircPwd[0] || strcmp(Req->argv[0], Conf_WebircPwd) != 0)
612 return IRC_WriteStrClient(Client, ERR_PASSWDMISMATCH_MSG,
615 LogDebug("Connection %d: got valid WEBIRC command: user=%s, host=%s, ip=%s",
616 Client_Conn(Client), Req->argv[1], Req->argv[2], Req->argv[3]);
618 Client_SetUser(Client, Req->argv[1], true);
619 Client_SetOrigUser(Client, Req->argv[1]);
620 Client_SetHostname(Client, Req->argv[2]);
625 * Handler for the IRC "QUIT" command.
627 * @param Client The client from which this command has been received.
628 * @param Req Request structure with prefix and all parameters.
629 * @return CONNECTED or DISCONNECTED.
632 IRC_QUIT( CLIENT *Client, REQUEST *Req )
635 char quitmsg[LINE_LEN];
637 assert(Client != NULL);
640 _IRC_ARGC_LE_OR_RETURN_(Client, Req, 1)
643 strlcpy(quitmsg, Req->argv[0], sizeof quitmsg);
645 if (Client_Type(Client) == CLIENT_SERVER) {
647 target = Client_Search(Req->prefix);
650 "Got QUIT from %s for unknown client!?",
655 if (target != Client) {
656 Client_Destroy(target, "Got QUIT command",
657 Req->argc == 1 ? quitmsg : NULL, true);
660 Conn_Close(Client_Conn(Client), "Got QUIT command",
661 Req->argc == 1 ? quitmsg : NULL, true);
665 if (Req->argc == 1 && quitmsg[0] != '\"') {
666 /* " " to avoid confusion */
667 strlcpy(quitmsg, "\"", sizeof quitmsg);
668 strlcat(quitmsg, Req->argv[0], sizeof quitmsg-1);
669 strlcat(quitmsg, "\"", sizeof quitmsg );
672 /* User, Service, or not yet registered */
673 Conn_Close(Client_Conn(Client), "Got QUIT command",
674 Req->argc == 1 ? quitmsg : NULL, true);
683 * Handler for HTTP command, e.g. GET and POST
685 * We handle these commands here to avoid the quite long timeout when
686 * some user tries to access this IRC daemon using an web browser ...
688 * @param Client The client from which this command has been received.
689 * @param Req Request structure with prefix and all parameters.
690 * @return CONNECTED or DISCONNECTED.
693 IRC_QUIT_HTTP( CLIENT *Client, REQUEST *Req )
696 Req->argv[0] = "Oops, HTTP request received? This is IRC!";
697 return IRC_QUIT(Client, Req);
698 } /* IRC_QUIT_HTTP */
703 * Handler for the IRC "PING" command.
705 * @param Client The client from which this command has been received.
706 * @param Req Request structure with prefix and all parameters.
707 * @return CONNECTED or DISCONNECTED.
710 IRC_PING(CLIENT *Client, REQUEST *Req)
712 CLIENT *target, *from;
714 assert(Client != NULL);
718 return IRC_WriteStrClient(Client, ERR_NOORIGIN_MSG,
721 /* Don't ignore additional arguments when in "strict" mode */
722 _IRC_ARGC_LE_OR_RETURN_(Client, Req, 2)
726 /* A target has been specified ... */
727 target = Client_Search(Req->argv[1]);
729 if (!target || Client_Type(target) != CLIENT_SERVER)
730 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
731 Client_ID(Client), Req->argv[1]);
733 if (target != Client_ThisServer()) {
734 /* Ok, we have to forward the PING */
735 if (Client_Type(Client) == CLIENT_SERVER)
736 from = Client_Search(Req->prefix);
740 return IRC_WriteStrClient(Client,
741 ERR_NOSUCHSERVER_MSG,
742 Client_ID(Client), Req->prefix);
744 return IRC_WriteStrClientPrefix(target, from,
745 "PING %s :%s", Req->argv[0],
750 if (Client_Type(Client) == CLIENT_SERVER) {
752 from = Client_Search(Req->prefix);
756 from = Client_ThisServer();
758 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
759 Client_ID(Client), Req->prefix);
761 Log(LOG_DEBUG, "Connection %d: got PING, sending PONG ...",
762 Client_Conn(Client));
765 return IRC_WriteStrClient(Client, "PONG %s :%s",
766 Client_ID(from), Client_ID(Client));
768 /* Some clients depend on the argument being returned in the PONG
769 * reply (not mentioned in any RFC, though) */
770 return IRC_WriteStrClient(Client, "PONG %s :%s",
771 Client_ID(from), Req->argv[0]);
776 * Handler for the IRC "PONG" command.
778 * @param Client The client from which this command has been received.
779 * @param Req Request structure with prefix and all parameters.
780 * @return CONNECTED or DISCONNECTED.
783 IRC_PONG(CLIENT *Client, REQUEST *Req)
785 CLIENT *target, *from;
792 assert(Client != NULL);
795 /* Wrong number of arguments? */
797 if (Client_Type(Client) == CLIENT_USER)
798 return IRC_WriteStrClient(Client, ERR_NOORIGIN_MSG,
803 if (Client_Type(Client) == CLIENT_USER) {
804 _IRC_ARGC_LE_OR_RETURN_(Client, Req, 2)
808 if (Req->argc == 2 && Client_Type(Client) == CLIENT_SERVER) {
809 target = Client_Search(Req->argv[0]);
811 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
812 Client_ID(Client), Req->argv[0]);
814 from = Client_Search(Req->prefix);
816 if (target != Client_ThisServer() && target != from) {
817 /* Ok, we have to forward the message. */
819 return IRC_WriteStrClient(Client,
820 ERR_NOSUCHSERVER_MSG,
821 Client_ID(Client), Req->prefix);
823 if (Client_Type(Client_NextHop(target)) != CLIENT_SERVER)
827 return IRC_WriteStrClientPrefix(target, from,
828 "PONG %s :%s", s, Req->argv[1]);
832 /* The connection timestamp has already been updated when the data has
833 * been read from so socket, so we don't need to update it here. */
835 conn = Client_Conn(Client);
838 /* Check authentication PING-PONG ... */
839 auth_ping = Conn_GetAuthPing(conn);
841 LogDebug("AUTH PONG: waiting for token \"%ld\", got \"%s\" ...",
842 auth_ping, Req->argv[0]);
843 if (auth_ping == atoi(Req->argv[0])) {
844 Conn_SetAuthPing(conn, 0);
845 if (Client_Type(Client) == CLIENT_WAITAUTHPING)
848 if (!IRC_WriteStrClient(Client,
849 "To connect, type /QUOTE PONG %ld",
855 if (Client_Type(Client) == CLIENT_SERVER && Conn_LastPing(conn) == 0) {
857 "Synchronization with \"%s\" done (connection %d): %ld second%s [%ld users, %ld channels].",
858 Client_ID(Client), conn, time(NULL) - Conn_GetSignon(conn),
859 time(NULL) - Conn_GetSignon(conn) == 1 ? "" : "s",
860 Client_UserCount(), Channel_CountVisible(NULL));
861 Conn_UpdatePing(conn);
863 LogDebug("Connection %d: received PONG. Lag: %ld seconds.",
864 conn, time(NULL) - Conn_LastPing(conn));
870 * Kill all users with a specific nickname in the network.
872 * @param Nick Nickname.
873 * @param Reason Reason for the KILL.
876 Kill_Nick(char *Nick, char *Reason)
880 assert (Nick != NULL);
881 assert (Reason != NULL);
888 Log(LOG_ERR, "User(s) with nick \"%s\" will be disconnected: %s!",
891 IRC_KILL(Client_ThisServer(), &r);
895 * Change the nickname of a client.
897 * @param Origin The client which caused the nickname change.
898 * @param Target The client of which the nickname should be changed.
899 * @param NewNick The new nickname.
902 Change_Nick(CLIENT *Origin, CLIENT *Target, char *NewNick, bool InformClient)
904 if (Client_Conn(Target) > NONE) {
907 "%s \"%s\" changed nick (connection %d): \"%s\" -> \"%s\".",
908 Client_TypeText(Target), Client_Mask(Target),
909 Client_Conn(Target), Client_ID(Target), NewNick);
910 Conn_UpdateIdle(Client_Conn(Target));
913 LogDebug("%s \"%s\" changed nick: \"%s\" -> \"%s\".",
914 Client_TypeText(Target),
915 Client_Mask(Target), Client_ID(Target), NewNick);
918 /* Inform all servers and users (which have to know) of the new name */
920 IRC_WriteStrClientPrefix(Target, Target, "NICK :%s", NewNick);
921 IRC_WriteStrServersPrefix(NULL, Target, "NICK :%s", NewNick);
923 IRC_WriteStrServersPrefix(Origin, Target, "NICK :%s", NewNick);
924 IRC_WriteStrRelatedPrefix(Target, Target, false, "NICK :%s", NewNick);
926 /* Register old nickname for WHOWAS queries */
927 Client_RegisterWhowas(Target);
929 /* Save new nickname */
930 Client_SetID(Target, NewNick);