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-write.h"
39 #include "irc-login.h"
41 static void Kill_Nick PARAMS((char *Nick, char *Reason));
42 static void Change_Nick PARAMS((CLIENT * Origin, CLIENT * Target, char *NewNick,
47 * Handler for the IRC "PASS" command.
49 * See RFC 2813 section 4.1.1, and RFC 2812 section 3.1.1.
51 * @param Client The client from which this command has been received.
52 * @param Req Request structure with prefix and all parameters.
53 * @returns CONNECTED or DISCONNECTED.
56 IRC_PASS( CLIENT *Client, REQUEST *Req )
58 char *type, *orig_flags;
59 int protohigh, protolow;
61 assert( Client != NULL );
62 assert( Req != NULL );
64 /* Return an error if this is not a local client */
65 if (Client_Conn(Client) <= NONE)
66 return IRC_WriteStrClient(Client, ERR_UNKNOWNCOMMAND_MSG,
67 Client_ID(Client), Req->command);
69 if (Client_Type(Client) == CLIENT_UNKNOWN && Req->argc == 1) {
70 /* Not yet registered "unknown" connection, PASS with one
71 * argument: either a regular client, service, or server
72 * using the old RFC 1459 section 4.1.1 syntax. */
73 LogDebug("Connection %d: got PASS command (RFC 1459) ...",
75 } else if ((Client_Type(Client) == CLIENT_UNKNOWN ||
76 Client_Type(Client) == CLIENT_UNKNOWNSERVER) &&
77 (Req->argc == 3 || Req->argc == 4)) {
78 /* Not yet registered "unknown" connection or outgoing server
79 * link, PASS with three or four argument: server using the
80 * RFC 2813 section 4.1.1 syntax. */
81 LogDebug("Connection %d: got PASS command (RFC 2813, new server link) ...",
83 } else if (Client_Type(Client) == CLIENT_UNKNOWN ||
84 Client_Type(Client) == CLIENT_UNKNOWNSERVER) {
85 /* Unregistered connection, but wrong number of arguments: */
86 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
87 Client_ID(Client), Req->command);
89 /* Registered connection, PASS command is not allowed! */
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 conenction %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);
172 * Handler for the IRC "NICK" command.
174 * See RFC 2812, 3.1.2 "Nick message", and RFC 2813, 4.1.3 "Nick".
176 * This function implements the IRC command "NICK" which is used to register
177 * with the server, to change already registered nicknames and to introduce
178 * new users which are connected to other servers.
180 * @param Client The client from which this command has been received.
181 * @param Req Request structure with prefix and all parameters.
182 * @returns CONNECTED or DISCONNECTED.
185 IRC_NICK( CLIENT *Client, REQUEST *Req )
187 CLIENT *intr_c, *target, *c;
188 char *nick, *user, *hostname, *modes, *info;
191 assert( Client != NULL );
192 assert( Req != NULL );
194 /* Some IRC clients, for example BitchX, send the NICK and USER
195 * commands in the wrong order ... */
196 if(Client_Type(Client) == CLIENT_UNKNOWN
197 || Client_Type(Client) == CLIENT_GOTPASS
198 || Client_Type(Client) == CLIENT_GOTNICK
200 || Client_Type(Client) == CLIENT_GOTUSER
202 || Client_Type(Client) == CLIENT_USER
203 || Client_Type(Client) == CLIENT_SERVICE
204 || (Client_Type(Client) == CLIENT_SERVER && Req->argc == 1))
206 /* User registration or change of nickname */
208 /* Wrong number of arguments? */
210 return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG,
214 /* Search "target" client */
215 if( Client_Type( Client ) == CLIENT_SERVER )
217 target = Client_Search( Req->prefix );
219 return IRC_WriteStrClient( Client,
226 /* Is this a restricted client? */
227 if( Client_HasMode( Client, 'r' ))
228 return IRC_WriteStrClient( Client,
230 Client_ID( Client ));
236 /* If the clients tries to change to its own nickname we won't
237 * do anything. This is how the original ircd behaves and some
238 * clients (for example Snak) expect it to be like this.
239 * But I doubt that this is "really the right thing" ... */
240 if( strcmp( Client_ID( target ), Req->argv[0] ) == 0 )
244 /* Check that the new nickname is available. Special case:
245 * the client only changes from/to upper to lower case. */
246 if( strcasecmp( Client_ID( target ), Req->argv[0] ) != 0 )
248 if( ! Client_CheckNick( target, Req->argv[0] ))
252 if (Client_Type(target) != CLIENT_USER &&
253 Client_Type(target) != CLIENT_SERVICE &&
254 Client_Type(target) != CLIENT_SERVER) {
256 LogDebug("Connection %d: got valid NICK command ...",
257 Client_Conn( Client ));
259 /* Register new nickname of this client */
260 Client_SetID( target, Req->argv[0] );
264 Conn_SetAuthPing(Client_Conn(Client), rand());
265 IRC_WriteStrClient(Client, "PING :%ld",
266 Conn_GetAuthPing(Client_Conn(Client)));
267 LogDebug("Connection %d: sent AUTH PING %ld ...",
269 Conn_GetAuthPing(Client_Conn(Client)));
273 /* If we received a valid USER command already then
274 * register the new client! */
275 if( Client_Type( Client ) == CLIENT_GOTUSER )
276 return Login_User( Client );
278 Client_SetType( Client, CLIENT_GOTNICK );
280 /* Nickname change */
281 Change_Nick(Client, target, Req->argv[0],
282 Client_Type(Client) == CLIENT_USER ? true : false);
283 IRC_SetPenalty(target, 2);
287 } else if(Client_Type(Client) == CLIENT_SERVER ||
288 Client_Type(Client) == CLIENT_SERVICE) {
289 /* Server or service introduces new client */
291 /* Bad number of parameters? */
292 if (Req->argc != 2 && Req->argc != 7)
293 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
294 Client_ID(Client), Req->command);
296 if (Req->argc >= 7) {
297 /* RFC 2813 compatible syntax */
299 hops = atoi(Req->argv[1]);
301 hostname = Req->argv[3];
302 token = atoi(Req->argv[4]);
303 modes = Req->argv[5] + 1;
306 /* RFC 1459 compatible syntax */
310 hostname = Client_ID(Client);
311 token = atoi(Req->argv[1]);
316 c = Client_Search(nick);
319 * the new nick is already present on this server:
320 * the new and the old one have to be disconnected now.
322 Log( LOG_ERR, "Server %s introduces already registered nick \"%s\"!", Client_ID( Client ), Req->argv[0] );
323 Kill_Nick( Req->argv[0], "Nick collision" );
327 /* Find the Server this client is connected to */
328 intr_c = Client_GetFromToken(Client, token);
331 Log( LOG_ERR, "Server %s introduces nick \"%s\" on unknown server!?", Client_ID( Client ), Req->argv[0] );
332 Kill_Nick( Req->argv[0], "Unknown server" );
336 c = Client_NewRemoteUser(intr_c, nick, hops, user, hostname,
337 token, modes, info, true);
340 /* out of memory, need to disconnect client to keep network state consistent */
341 Log( LOG_ALERT, "Can't create client structure! (on connection %d)", Client_Conn( Client ));
342 Kill_Nick( Req->argv[0], "Server error" );
346 /* RFC 2813: client is now fully registered, inform all the
347 * other servers about the new user.
348 * RFC 1459: announce the new client only after receiving the
349 * USER command, first we need more information! */
351 LogDebug("Client \"%s\" is being registered (RFC 1459) ...",
353 Client_SetType(c, CLIENT_GOTNICK);
355 Client_Introduce(Client, c, CLIENT_USER);
359 else return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
364 * Handler for the IRC "SVSNICK" command.
366 * @param Client The client from which this command has been received.
367 * @param Req Request structure with prefix and all parameters.
368 * @return CONNECTED or DISCONNECTED.
371 IRC_SVSNICK(CLIENT *Client, REQUEST *Req)
373 CLIENT *from, *target;
375 assert(Client != NULL);
379 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
380 Client_ID(Client), Req->command);
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_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
391 Client_ID(Client), Req->argv[0]);
394 if (Client_Conn(target) <= NONE) {
395 /* We have to forward the message to the server handling
396 * this user; this is required to make sure all servers
397 * in the network do follow the nick name change! */
398 return IRC_WriteStrClientPrefix(Client_NextHop(target), from,
400 Req->argv[0], Req->argv[1]);
403 /* Make sure that the new nickname is valid */
404 if (!Client_CheckNick(from, Req->argv[1]))
407 Change_Nick(from, target, Req->argv[1], true);
412 * Handler for the IRC "USER" command.
414 * See RFC 2812, 3.1.3 "User message".
416 * @param Client The client from which this command has been received.
417 * @param Req Request structure with prefix and all parameters.
418 * @returns CONNECTED or DISCONNECTED.
421 IRC_USER(CLIENT * Client, REQUEST * Req)
426 assert(Client != NULL);
429 if (Client_Type(Client) == CLIENT_GOTNICK ||
431 Client_Type(Client) == CLIENT_UNKNOWN ||
433 Client_Type(Client) == CLIENT_GOTPASS)
437 return IRC_WriteStrClient(Client,
438 ERR_NEEDMOREPARAMS_MSG,
442 /* User name: only alphanumeric characters and limited
443 punctuation is allowed.*/
446 if (!isalnum(*ptr) &&
447 *ptr != '+' && *ptr != '-' &&
448 *ptr != '.' && *ptr != '_') {
449 Conn_Close(Client_Conn(Client), NULL,
450 "Invalid user name", true);
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);
463 Client_SetOrigUser(Client, Req->argv[0]);
465 /* "Real name" or user info text: Don't set it to the empty
466 * string, the original ircd can't deal with such "real names"
467 * (e. g. "USER user * * :") ... */
469 Client_SetInfo(Client, Req->argv[3]);
471 Client_SetInfo(Client, "-");
473 LogDebug("Connection %d: got valid USER command ...",
474 Client_Conn(Client));
475 if (Client_Type(Client) == CLIENT_GOTNICK)
476 return Login_User(Client);
478 Client_SetType(Client, CLIENT_GOTUSER);
481 } else if (Client_Type(Client) == CLIENT_SERVER ||
482 Client_Type(Client) == CLIENT_SERVICE) {
483 /* Server/service updating an user */
485 return IRC_WriteStrClient(Client,
486 ERR_NEEDMOREPARAMS_MSG,
489 c = Client_Search(Req->prefix);
491 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
495 Client_SetUser(c, Req->argv[0], true);
496 Client_SetOrigUser(c, Req->argv[0]);
497 Client_SetHostname(c, Req->argv[1]);
498 Client_SetInfo(c, Req->argv[3]);
500 LogDebug("Connection %d: got valid USER command for \"%s\".",
501 Client_Conn(Client), Client_Mask(c));
503 /* RFC 1459 style user registration?
504 * Introduce client to network: */
505 if (Client_Type(c) == CLIENT_GOTNICK)
506 Client_Introduce(Client, c, CLIENT_USER);
509 } else if (Client_Type(Client) == CLIENT_USER) {
510 /* Already registered connection */
511 return IRC_WriteStrClient(Client, ERR_ALREADYREGISTRED_MSG,
514 /* Unexpected/invalid connection state? */
515 return IRC_WriteStrClient(Client, ERR_NOTREGISTERED_MSG,
522 * Handler for the IRC "SERVICE" command.
524 * This function implements IRC Services registration using the SERVICE command
525 * defined in RFC 2812 3.1.6 and RFC 2813 4.1.4.
527 * At the moment ngIRCd doesn't support directly linked services, so this
528 * function returns ERR_ERRONEUSNICKNAME when the SERVICE command has not been
529 * received from a peer server.
531 * @param Client The client from which this command has been received.
532 * @param Req Request structure with prefix and all parameters.
533 * @returns CONNECTED or DISCONNECTED..
536 IRC_SERVICE(CLIENT *Client, REQUEST *Req)
539 char *nick, *user, *host, *info, *modes, *ptr;
542 assert(Client != NULL);
545 if (Client_Type(Client) != CLIENT_GOTPASS &&
546 Client_Type(Client) != CLIENT_SERVER)
547 return IRC_WriteStrClient(Client, ERR_ALREADYREGISTRED_MSG,
551 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
552 Client_ID(Client), Req->command);
554 if (Client_Type(Client) != CLIENT_SERVER)
555 return IRC_WriteStrClient(Client, ERR_ERRONEUSNICKNAME_MSG,
556 Client_ID(Client), Req->argv[0]);
558 /* Bad number of parameters? */
560 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
561 Client_ID(Client), Req->command);
564 user = NULL; host = NULL;
565 token = atoi(Req->argv[1]);
566 hops = atoi(Req->argv[4]);
569 /* Validate service name ("nickname") */
570 c = Client_Search(nick);
572 /* Nickname collission: disconnect (KILL) both clients! */
573 Log(LOG_ERR, "Server %s introduces already registered service \"%s\"!",
574 Client_ID(Client), nick);
575 Kill_Nick(nick, "Nick collision");
579 /* Get the server to which the service is connected */
580 intr_c = Client_GetFromToken(Client, token);
582 Log(LOG_ERR, "Server %s introduces service \"%s\" on unknown server!?",
583 Client_ID(Client), nick);
584 Kill_Nick(nick, "Unknown server");
588 /* Get user and host name */
589 ptr = strchr(nick, '@');
595 host = Client_Hostname(intr_c);
596 ptr = strchr(nick, '!');
604 /* According to RFC 2812/2813 parameter 4 <type> "is currently reserved
605 * for future usage"; but we use it to transfer the modes and check
606 * that the first character is a '+' sign and ignore it otherwise. */
607 modes = (Req->argv[3][0] == '+') ? ++Req->argv[3] : "";
609 c = Client_NewRemoteUser(intr_c, nick, hops, user, host,
610 token, modes, info, true);
612 /* Couldn't create client structure, so KILL the service to
613 * keep network status consistent ... */
614 Log(LOG_ALERT, "Can't create client structure! (on connection %d)",
615 Client_Conn(Client));
616 Kill_Nick(nick, "Server error");
620 Client_Introduce(Client, c, CLIENT_SERVICE);
626 * Handler for the IRC "WEBIRC" command.
628 * See doc/Protocol.txt, section II.4:
629 * "Update webchat/proxy client information".
631 * @param Client The client from which this command has been received.
632 * @param Req Request structure with prefix and all parameters.
633 * @returns CONNECTED or DISCONNECTED.
636 IRC_WEBIRC(CLIENT *Client, REQUEST *Req)
638 /* Exactly 4 parameters are requited */
640 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
641 Client_ID(Client), Req->command);
643 if (!Conf_WebircPwd[0] || strcmp(Req->argv[0], Conf_WebircPwd) != 0)
644 return IRC_WriteStrClient(Client, ERR_PASSWDMISMATCH_MSG,
647 LogDebug("Connection %d: got valid WEBIRC command: user=%s, host=%s, ip=%s",
648 Client_Conn(Client), Req->argv[1], Req->argv[2], Req->argv[3]);
650 Client_SetUser(Client, Req->argv[1], true);
651 Client_SetOrigUser(Client, Req->argv[1]);
652 Client_SetHostname(Client, Req->argv[2]);
658 * Handler for the IRC "QUIT" command.
660 * See RFC 2812, 3.1.7 "Quit", and RFC 2813, 4.1.5 "Quit".
662 * @param Client The client from which this command has been received.
663 * @param Req Request structure with prefix and all parameters.
664 * @returns CONNECTED or DISCONNECTED.
667 IRC_QUIT( CLIENT *Client, REQUEST *Req )
670 char quitmsg[LINE_LEN];
672 assert(Client != NULL);
675 /* Wrong number of arguments? */
677 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
678 Client_ID(Client), Req->command);
681 strlcpy(quitmsg, Req->argv[0], sizeof quitmsg);
683 if (Client_Type(Client) == CLIENT_SERVER) {
685 target = Client_Search(Req->prefix);
688 "Got QUIT from %s for unknown client!?",
693 if (target != Client) {
694 Client_Destroy(target, "Got QUIT command.",
695 Req->argc == 1 ? quitmsg : NULL, true);
698 Conn_Close(Client_Conn(Client), "Got QUIT command.",
699 Req->argc == 1 ? quitmsg : NULL, true);
703 if (Req->argc == 1 && quitmsg[0] != '\"') {
704 /* " " to avoid confusion */
705 strlcpy(quitmsg, "\"", sizeof quitmsg);
706 strlcat(quitmsg, Req->argv[0], sizeof quitmsg-1);
707 strlcat(quitmsg, "\"", sizeof quitmsg );
710 /* User, Service, or not yet registered */
711 Conn_Close(Client_Conn(Client), "Got QUIT command.",
712 Req->argc == 1 ? quitmsg : NULL, true);
722 * Handler for HTTP command, e.g. GET and POST
724 * We handle these commands here to avoid the quite long timeout when
725 * some user tries to access this IRC daemon using an web browser ...
727 * @param Client The client from which this command has been received.
728 * @param Req Request structure with prefix and all parameters.
729 * @returns CONNECTED or DISCONNECTED.
732 IRC_QUIT_HTTP( CLIENT *Client, REQUEST *Req )
735 Req->argv[0] = "Oops, HTTP request received? This is IRC!";
736 return IRC_QUIT(Client, Req);
737 } /* IRC_QUIT_HTTP */
743 * Handler for the IRC "PING" command.
745 * See RFC 2812, 3.7.2 "Ping message".
747 * @param Client The client from which this command has been received.
748 * @param Req Request structure with prefix and all parameters.
749 * @returns CONNECTED or DISCONNECTED.
752 IRC_PING(CLIENT *Client, REQUEST *Req)
754 CLIENT *target, *from;
756 assert(Client != NULL);
760 return IRC_WriteStrClient(Client, ERR_NOORIGIN_MSG,
763 /* Don't ignore additional arguments when in "strict" mode */
765 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
766 Client_ID(Client), Req->command);
770 /* A target has been specified ... */
771 target = Client_Search(Req->argv[1]);
773 if (!target || Client_Type(target) != CLIENT_SERVER)
774 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
775 Client_ID(Client), Req->argv[1]);
777 if (target != Client_ThisServer()) {
778 /* Ok, we have to forward the PING */
779 if (Client_Type(Client) == CLIENT_SERVER)
780 from = Client_Search(Req->prefix);
784 return IRC_WriteStrClient(Client,
785 ERR_NOSUCHSERVER_MSG,
786 Client_ID(Client), Req->prefix);
788 return IRC_WriteStrClientPrefix(target, from,
789 "PING %s :%s", Req->argv[0],
794 if (Client_Type(Client) == CLIENT_SERVER) {
796 from = Client_Search(Req->prefix);
800 from = Client_ThisServer();
802 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
803 Client_ID(Client), Req->prefix);
805 Log(LOG_DEBUG, "Connection %d: got PING, sending PONG ...",
806 Client_Conn(Client));
809 return IRC_WriteStrClient(Client, "PONG %s :%s",
810 Client_ID(from), Client_ID(Client));
812 /* Some clients depend on the argument being returned in the PONG
813 * reply (not mentioned in any RFC, though) */
814 return IRC_WriteStrClient(Client, "PONG %s :%s",
815 Client_ID(from), Req->argv[0]);
821 * Handler for the IRC "PONG" command.
823 * See RFC 2812, 3.7.3 "Pong message".
825 * @param Client The client from which this command has been received.
826 * @param Req Request structure with prefix and all parameters.
827 * @returns CONNECTED or DISCONNECTED.
830 IRC_PONG(CLIENT *Client, REQUEST *Req)
832 CLIENT *target, *from;
839 assert(Client != NULL);
842 /* Wrong number of arguments? */
844 if (Client_Type(Client) == CLIENT_USER)
845 return IRC_WriteStrClient(Client, ERR_NOORIGIN_MSG,
851 if (Client_Type(Client) == CLIENT_USER)
852 return IRC_WriteStrClient(Client,
853 ERR_NEEDMOREPARAMS_MSG,
861 if (Req->argc == 2 && Client_Type(Client) == CLIENT_SERVER) {
862 target = Client_Search(Req->argv[0]);
864 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
865 Client_ID(Client), Req->argv[0]);
867 from = Client_Search(Req->prefix);
869 if (target != Client_ThisServer() && target != from) {
870 /* Ok, we have to forward the message. */
872 return IRC_WriteStrClient(Client,
873 ERR_NOSUCHSERVER_MSG,
874 Client_ID(Client), Req->prefix);
876 if (Client_Type(Client_NextHop(target)) != CLIENT_SERVER)
880 return IRC_WriteStrClientPrefix(target, from,
881 "PONG %s :%s", s, Req->argv[1]);
885 /* The connection timestamp has already been updated when the data has
886 * been read from so socket, so we don't need to update it here. */
888 conn = Client_Conn(Client);
891 /* Check authentication PING-PONG ... */
892 auth_ping = Conn_GetAuthPing(conn);
894 LogDebug("AUTH PONG: waiting for token \"%ld\", got \"%s\" ...",
895 auth_ping, Req->argv[0]);
896 if (auth_ping == atoi(Req->argv[0])) {
897 Conn_SetAuthPing(conn, 0);
898 if (Client_Type(Client) == CLIENT_WAITAUTHPING)
901 if (!IRC_WriteStrClient(Client,
902 "To connect, type /QUOTE PONG %ld",
908 if (Client_Type(Client) == CLIENT_SERVER && Conn_LastPing(conn) == 0) {
910 "Synchronization with \"%s\" done (connection %d): %ld seconds [%ld users, %ld channels]",
911 Client_ID(Client), conn, time(NULL) - Conn_GetSignon(conn),
912 Client_UserCount(), Channel_CountVisible(NULL));
913 Conn_UpdatePing(conn);
915 LogDebug("Connection %d: received PONG. Lag: %ld seconds.",
916 conn, time(NULL) - Conn_LastPing(conn));
923 * Kill all users with a specific nickname in the network.
925 * @param Nick Nickname.
926 * @param Reason Reason for the KILL.
929 Kill_Nick(char *Nick, char *Reason)
933 assert (Nick != NULL);
934 assert (Reason != NULL);
941 Log(LOG_ERR, "User(s) with nick \"%s\" will be disconnected: %s",
944 IRC_KILL(Client_ThisServer(), &r);
949 * Change the nickname of a client.
951 * @param Origin The client which caused the nickname change.
952 * @param Target The client of which the nickname should be changed.
953 * @param NewNick The new nickname.
956 Change_Nick(CLIENT *Origin, CLIENT *Target, char *NewNick, bool InformClient)
958 if (Client_Conn(Target) > NONE) {
961 "%s \"%s\" changed nick (connection %d): \"%s\" -> \"%s\".",
962 Client_TypeText(Target), Client_Mask(Target),
963 Client_Conn(Target), Client_ID(Target), NewNick);
964 Conn_UpdateIdle(Client_Conn(Target));
967 LogDebug("%s \"%s\" changed nick: \"%s\" -> \"%s\".",
968 Client_TypeText(Target),
969 Client_Mask(Target), Client_ID(Target), NewNick);
972 /* Inform all servers and users (which have to know) of the new name */
974 IRC_WriteStrClientPrefix(Target, Target, "NICK :%s", NewNick);
975 IRC_WriteStrServersPrefix(NULL, Target, "NICK :%s", NewNick);
977 IRC_WriteStrServersPrefix(Origin, Target, "NICK :%s", NewNick);
978 IRC_WriteStrRelatedPrefix(Target, Target, false, "NICK :%s", NewNick);
980 /* Register old nickname for WHOWAS queries */
981 Client_RegisterWhowas(Target);
983 /* Save new nickname */
984 Client_SetID(Target, NewNick);