2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2010 Alexander Barton (alex@barton.de)
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.
25 #include "conn-func.h"
33 #include "irc-write.h"
36 #include "irc-login.h"
39 static bool Hello_User PARAMS(( CLIENT *Client ));
40 static void Kill_Nick PARAMS(( char *Nick, char *Reason ));
41 static void Introduce_Client PARAMS((CLIENT *To, CLIENT *Client, int Type));
42 static void cb_introduceClient PARAMS((CLIENT *Client, CLIENT *Prefix,
47 * Handler for the IRC command "PASS".
48 * See RFC 2813 section 4.1.1, and RFC 2812 section 3.1.1.
51 IRC_PASS( CLIENT *Client, REQUEST *Req )
53 char *type, *orig_flags;
54 int protohigh, protolow;
56 assert( Client != NULL );
57 assert( Req != NULL );
59 /* Return an error if this is not a local client */
60 if (Client_Conn(Client) <= NONE)
61 return IRC_WriteStrClient(Client, ERR_UNKNOWNCOMMAND_MSG,
62 Client_ID(Client), Req->command);
64 if (Client_Type(Client) == CLIENT_UNKNOWN && Req->argc == 1) {
65 /* Not yet registered "unknown" connection, PASS with one
66 * argument: either a regular client, service, or server
67 * using the old RFC 1459 section 4.1.1 syntax. */
68 LogDebug("Connection %d: got PASS command (RFC 1459) ...",
70 } else if ((Client_Type(Client) == CLIENT_UNKNOWN ||
71 Client_Type(Client) == CLIENT_UNKNOWNSERVER) &&
72 (Req->argc == 3 || Req->argc == 4)) {
73 /* Not yet registered "unknown" connection or outgoing server
74 * link, PASS with three or four argument: server using the
75 * RFC 2813 section 4.1.1 syntax. */
76 LogDebug("Connection %d: got PASS command (RFC 2813, new server link) ...",
78 } else if (Client_Type(Client) == CLIENT_UNKNOWN ||
79 Client_Type(Client) == CLIENT_UNKNOWNSERVER) {
80 /* Unregistered connection, but wrong number of arguments: */
81 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
82 Client_ID(Client), Req->command);
84 /* Registered connection, PASS command is not allowed! */
85 return IRC_WriteStrClient(Client, ERR_ALREADYREGISTRED_MSG,
89 Client_SetPassword(Client, Req->argv[0]);
91 /* Protocol version */
92 if (Req->argc >= 2 && strlen(Req->argv[1]) >= 4) {
98 Req->argv[1][4] = '\0';
99 protolow = atoi(&Req->argv[1][2]);
100 Req->argv[1][2] = '\0';
101 protohigh = atoi(Req->argv[1]);
103 Req->argv[1][2] = c2;
104 Req->argv[1][4] = c4;
106 Client_SetType(Client, CLIENT_GOTPASS_2813);
108 protohigh = protolow = 0;
109 Client_SetType(Client, CLIENT_GOTPASS);
112 /* Protocol type, see doc/Protocol.txt */
113 if (Req->argc >= 2 && strlen(Req->argv[1]) > 4)
114 type = &Req->argv[1][4];
118 /* Protocol flags/options */
120 orig_flags = Req->argv[3];
124 /* Implementation, version and IRC+ flags */
125 if (Req->argc >= 3) {
126 char *impl, *ptr, *serverver, *flags;
129 ptr = strchr(impl, '|');
133 if (type && strcmp(type, PROTOIRCPLUS) == 0) {
134 /* The peer seems to be a server which supports the
135 * IRC+ protocol (see doc/Protocol.txt). */
137 flags = strchr(serverver, ':');
144 "Peer announces itself as %s-%s using protocol %d.%d/IRC+ (flags: \"%s\").",
145 impl, serverver, 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 announces itself as \"%s\" using protocol %d.%d (flags: \"%s\").",
155 impl, protohigh, protolow, flags);
157 Client_SetFlags(Client, flags);
165 * IRC "NICK" command.
166 * This function implements the IRC command "NICK" which is used to register
167 * with the server, to change already registered nicknames and to introduce
168 * new users which are connected to other servers.
171 IRC_NICK( CLIENT *Client, REQUEST *Req )
173 CLIENT *intr_c, *target, *c;
174 char *nick, *user, *hostname, *modes, *info;
177 assert( Client != NULL );
178 assert( Req != NULL );
180 /* Some IRC clients, for example BitchX, send the NICK and USER
181 * commands in the wrong order ... */
182 if(Client_Type(Client) == CLIENT_UNKNOWN
183 || Client_Type(Client) == CLIENT_GOTPASS
184 || Client_Type(Client) == CLIENT_GOTNICK
186 || Client_Type(Client) == CLIENT_GOTUSER
188 || Client_Type(Client) == CLIENT_USER
189 || Client_Type(Client) == CLIENT_SERVICE
190 || (Client_Type(Client) == CLIENT_SERVER && Req->argc == 1))
192 /* User registration or change of nickname */
194 /* Wrong number of arguments? */
196 return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG,
200 /* Search "target" client */
201 if( Client_Type( Client ) == CLIENT_SERVER )
203 target = Client_Search( Req->prefix );
205 return IRC_WriteStrClient( Client,
212 /* Is this a restricted client? */
213 if( Client_HasMode( Client, 'r' ))
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 )
234 if( ! Client_CheckNick( target, Req->argv[0] ))
238 if (Client_Type(target) != CLIENT_USER &&
239 Client_Type(target) != CLIENT_SERVICE &&
240 Client_Type(target) != CLIENT_SERVER) {
242 LogDebug("Connection %d: got valid NICK command ...",
243 Client_Conn( Client ));
245 /* Register new nickname of this client */
246 Client_SetID( target, Req->argv[0] );
248 /* If we received a valid USER command already then
249 * register the new client! */
250 if( Client_Type( Client ) == CLIENT_GOTUSER )
251 return Hello_User( Client );
253 Client_SetType( Client, CLIENT_GOTNICK );
255 /* Nickname change */
256 if (Client_Conn(target) > NONE) {
259 "%s \"%s\" changed nick (connection %d): \"%s\" -> \"%s\".",
260 Client_TypeText(target), Client_Mask(target),
261 Client_Conn(target), Client_ID(target),
263 Conn_UpdateIdle(Client_Conn(target));
266 LogDebug("%s \"%s\" changed nick: \"%s\" -> \"%s\".",
267 Client_TypeText(target),
268 Client_Mask(target), Client_ID(target),
272 /* Inform all users and servers (which have to know)
273 * of this nickname change */
274 if( Client_Type( Client ) == CLIENT_USER )
275 IRC_WriteStrClientPrefix( Client, Client,
278 IRC_WriteStrServersPrefix( Client, target,
279 "NICK :%s", Req->argv[0] );
280 IRC_WriteStrRelatedPrefix( target, target, false,
281 "NICK :%s", Req->argv[0] );
283 /* Register old nickname for WHOWAS queries */
284 Client_RegisterWhowas( target );
286 /* Save new nickname */
287 Client_SetID( target, Req->argv[0] );
289 IRC_SetPenalty( target, 2 );
293 } else if(Client_Type(Client) == CLIENT_SERVER ||
294 Client_Type(Client) == CLIENT_SERVICE) {
295 /* Server or service introduces new client */
297 /* Bad number of parameters? */
298 if (Req->argc != 2 && Req->argc != 7)
299 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
300 Client_ID(Client), Req->command);
302 if (Req->argc >= 7) {
303 /* RFC 2813 compatible syntax */
305 hops = atoi(Req->argv[1]);
307 hostname = Req->argv[3];
308 token = atoi(Req->argv[4]);
309 modes = Req->argv[5] + 1;
312 /* RFC 1459 compatible syntax */
316 hostname = Client_ID(Client);
317 token = atoi(Req->argv[1]);
322 c = Client_Search(nick);
325 * the new nick is already present on this server:
326 * the new and the old one have to be disconnected now.
328 Log( LOG_ERR, "Server %s introduces already registered nick \"%s\"!", Client_ID( Client ), Req->argv[0] );
329 Kill_Nick( Req->argv[0], "Nick collision" );
333 /* Find the Server this client is connected to */
334 intr_c = Client_GetFromToken(Client, token);
337 Log( LOG_ERR, "Server %s introduces nick \"%s\" on unknown server!?", Client_ID( Client ), Req->argv[0] );
338 Kill_Nick( Req->argv[0], "Unknown server" );
342 c = Client_NewRemoteUser(intr_c, nick, hops, user, hostname,
343 token, modes, info, true);
346 /* out of memory, need to disconnect client to keep network state consistent */
347 Log( LOG_ALERT, "Can't create client structure! (on connection %d)", Client_Conn( Client ));
348 Kill_Nick( Req->argv[0], "Server error" );
352 /* RFC 2813: client is now fully registered, inform all the
353 * other servers about the new user.
354 * RFC 1459: announce the new client only after receiving the
355 * USER command, first we need more information! */
357 LogDebug("Client \"%s\" is being registered (RFC 1459) ...",
359 Client_SetType(c, CLIENT_GOTNICK);
361 Introduce_Client(Client, c, CLIENT_USER);
365 else return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
370 * Handler for the IRC command "USER".
373 IRC_USER(CLIENT * Client, REQUEST * Req)
380 assert(Client != NULL);
383 if (Client_Type(Client) == CLIENT_GOTNICK ||
385 Client_Type(Client) == CLIENT_UNKNOWN ||
387 Client_Type(Client) == CLIENT_GOTPASS)
391 return IRC_WriteStrClient(Client,
392 ERR_NEEDMOREPARAMS_MSG,
398 ptr = Client_User(Client);
399 if (!ptr || !*ptr || *ptr == '~')
400 Client_SetUser(Client, Req->argv[0], false);
402 Client_SetUser(Client, Req->argv[0], false);
404 Client_SetOrigUser(Client, Req->argv[0]);
406 /* "Real name" or user info text: Don't set it to the empty
407 * string, the original ircd can't deal with such "real names"
408 * (e. g. "USER user * * :") ... */
410 Client_SetInfo(Client, Req->argv[3]);
412 Client_SetInfo(Client, "-");
414 LogDebug("Connection %d: got valid USER command ...",
415 Client_Conn(Client));
416 if (Client_Type(Client) == CLIENT_GOTNICK)
417 return Hello_User(Client);
419 Client_SetType(Client, CLIENT_GOTUSER);
422 } else if (Client_Type(Client) == CLIENT_SERVER ||
423 Client_Type(Client) == CLIENT_SERVICE) {
424 /* Server/service updating an user */
426 return IRC_WriteStrClient(Client,
427 ERR_NEEDMOREPARAMS_MSG,
430 c = Client_Search(Req->prefix);
432 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
436 Client_SetUser(c, Req->argv[0], true);
437 Client_SetOrigUser(c, Req->argv[0]);
438 Client_SetHostname(c, Req->argv[1]);
439 Client_SetInfo(c, Req->argv[3]);
441 LogDebug("Connection %d: got valid USER command for \"%s\".",
442 Client_Conn(Client), Client_Mask(c));
444 /* RFC 1459 style user registration?
445 * Introduce client to network: */
446 if (Client_Type(c) == CLIENT_GOTNICK)
447 Introduce_Client(Client, c, CLIENT_USER);
450 } else if (Client_Type(Client) == CLIENT_USER) {
451 /* Already registered connection */
452 return IRC_WriteStrClient(Client, ERR_ALREADYREGISTRED_MSG,
455 /* Unexpected/invalid connection state? */
456 return IRC_WriteStrClient(Client, ERR_NOTREGISTERED_MSG,
463 * Handler for the IRC command "SERVICE".
464 * This function implements IRC Services registration using the SERVICE command
465 * defined in RFC 2812 3.1.6 and RFC 2813 4.1.4.
466 * At the moment ngIRCd doesn't support directly linked services, so this
467 * function returns ERR_ERRONEUSNICKNAME when the SERVICE command has not been
468 * received from a peer server.
471 IRC_SERVICE(CLIENT *Client, REQUEST *Req)
474 char *nick, *user, *host, *info, *modes, *ptr;
477 assert(Client != NULL);
480 if (Client_Type(Client) != CLIENT_GOTPASS &&
481 Client_Type(Client) != CLIENT_SERVER)
482 return IRC_WriteStrClient(Client, ERR_ALREADYREGISTRED_MSG,
486 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
487 Client_ID(Client), Req->command);
489 if (Client_Type(Client) != CLIENT_SERVER)
490 return IRC_WriteStrClient(Client, ERR_ERRONEUSNICKNAME_MSG,
491 Client_ID(Client), Req->argv[0]);
493 /* Bad number of parameters? */
495 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
496 Client_ID(Client), Req->command);
499 user = NULL; host = NULL;
500 token = atoi(Req->argv[1]);
501 hops = atoi(Req->argv[4]);
504 /* Validate service name ("nick name") */
505 c = Client_Search(nick);
507 /* Nick name collission: disconnect (KILL) both clients! */
508 Log(LOG_ERR, "Server %s introduces already registered service \"%s\"!",
509 Client_ID(Client), nick);
510 Kill_Nick(nick, "Nick collision");
514 /* Get the server to which the service is connected */
515 intr_c = Client_GetFromToken(Client, token);
517 Log(LOG_ERR, "Server %s introduces service \"%s\" on unknown server!?",
518 Client_ID(Client), nick);
519 Kill_Nick(nick, "Unknown server");
523 /* Get user and host name */
524 ptr = strchr(nick, '@');
530 host = Client_Hostname(intr_c);
531 ptr = strchr(nick, '!');
539 /* According to RFC 2812/2813 parameter 4 <type> "is currently reserved
540 * for future usage"; but we use it to transfer the modes and check
541 * that the first character is a '+' sign and ignore it otherwise. */
542 modes = (Req->argv[3][0] == '+') ? ++Req->argv[3] : "";
544 c = Client_NewRemoteUser(intr_c, nick, hops, user, host,
545 token, modes, info, true);
547 /* Couldn't create client structure, so KILL the service to
548 * keep network status consistent ... */
549 Log(LOG_ALERT, "Can't create client structure! (on connection %d)",
550 Client_Conn(Client));
551 Kill_Nick(nick, "Server error");
555 Introduce_Client(Client, c, CLIENT_SERVICE);
561 * Handler for the IRC command "WEBIRC".
562 * Syntax: WEBIRC <password> <username> <real-hostname> <real-IP-address>
565 IRC_WEBIRC(CLIENT *Client, REQUEST *Req)
567 /* Exactly 4 parameters are requited */
569 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
570 Client_ID(Client), Req->command);
572 if (!Conf_WebircPwd[0] || strcmp(Req->argv[0], Conf_WebircPwd) != 0)
573 return IRC_WriteStrClient(Client, ERR_PASSWDMISMATCH_MSG,
576 LogDebug("Connection %d: got valid WEBIRC command: user=%s, host=%s, ip=%s",
577 Client_Conn(Client), Req->argv[1], Req->argv[2], Req->argv[3]);
579 Client_SetUser(Client, Req->argv[1], true);
580 Client_SetOrigUser(Client, Req->argv[1]);
581 Client_SetHostname(Client, Req->argv[2]);
587 IRC_QUIT( CLIENT *Client, REQUEST *Req )
590 char quitmsg[LINE_LEN];
592 assert( Client != NULL );
593 assert( Req != NULL );
595 /* Wrong number of arguments? */
597 return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
600 strlcpy(quitmsg, Req->argv[0], sizeof quitmsg);
602 if ( Client_Type( Client ) == CLIENT_SERVER )
605 target = Client_Search( Req->prefix );
608 Log( LOG_WARNING, "Got QUIT from %s for unknown client!?", Client_ID( Client ));
612 Client_Destroy( target, "Got QUIT command.", Req->argc == 1 ? quitmsg : NULL, true);
618 if (Req->argc == 1 && quitmsg[0] != '\"') {
619 /* " " to avoid confusion */
620 strlcpy(quitmsg, "\"", sizeof quitmsg);
621 strlcat(quitmsg, Req->argv[0], sizeof quitmsg-1);
622 strlcat(quitmsg, "\"", sizeof quitmsg );
625 /* User, Service, or not yet registered */
626 Conn_Close( Client_Conn( Client ), "Got QUIT command.", Req->argc == 1 ? quitmsg : NULL, true);
634 IRC_PING(CLIENT *Client, REQUEST *Req)
636 CLIENT *target, *from;
638 assert(Client != NULL);
642 return IRC_WriteStrClient(Client, ERR_NOORIGIN_MSG,
645 /* Don't ignore additional arguments when in "strict" mode */
647 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
648 Client_ID(Client), Req->command);
652 /* A target has been specified ... */
653 target = Client_Search(Req->argv[1]);
655 if (!target || Client_Type(target) != CLIENT_SERVER)
656 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
657 Client_ID(Client), Req->argv[1]);
659 if (target != Client_ThisServer()) {
660 /* Ok, we have to forward the PING */
661 if (Client_Type(Client) == CLIENT_SERVER)
662 from = Client_Search(Req->prefix);
666 return IRC_WriteStrClient(Client,
667 ERR_NOSUCHSERVER_MSG,
668 Client_ID(Client), Req->prefix);
670 return IRC_WriteStrClientPrefix(target, from,
671 "PING %s :%s", Req->argv[0],
676 if (Client_Type(Client) == CLIENT_SERVER) {
678 from = Client_Search(Req->prefix);
682 from = Client_ThisServer();
684 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
685 Client_ID(Client), Req->prefix);
687 Log(LOG_DEBUG, "Connection %d: got PING, sending PONG ...",
688 Client_Conn(Client));
691 return IRC_WriteStrClient(Client, "PONG %s :%s",
692 Client_ID(from), Client_ID(Client));
694 /* Some clients depend on the argument being returned in the PONG
695 * reply (not mentioned in any RFC, though) */
696 return IRC_WriteStrClient(Client, "PONG %s :%s",
697 Client_ID(from), Req->argv[0]);
703 IRC_PONG(CLIENT *Client, REQUEST *Req)
705 CLIENT *target, *from;
708 assert(Client != NULL);
711 /* Wrong number of arguments? */
713 return IRC_WriteStrClient(Client, ERR_NOORIGIN_MSG,
716 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
717 Client_ID(Client), Req->command);
720 if (Req->argc == 2 && Client_Type(Client) == CLIENT_SERVER) {
721 target = Client_Search(Req->argv[0]);
723 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
724 Client_ID(Client), Req->argv[0]);
726 from = Client_Search(Req->prefix);
728 if (target != Client_ThisServer() && target != from) {
729 /* Ok, we have to forward the message. */
731 return IRC_WriteStrClient(Client,
732 ERR_NOSUCHSERVER_MSG,
733 Client_ID(Client), Req->prefix);
735 if (Client_Type(Client_NextHop(target)) != CLIENT_SERVER)
739 return IRC_WriteStrClientPrefix(target, from,
740 "PONG %s :%s", s, Req->argv[1]);
744 /* The connection timestamp has already been updated when the data has
745 * been read from so socket, so we don't need to update it here. */
747 if (Client_Conn(Client) > NONE)
749 "Connection %d: received PONG. Lag: %ld seconds.",
751 time(NULL) - Conn_LastPing(Client_Conn(Client)));
754 "Connection %d: received PONG.", Client_Conn(Client));
761 Hello_User(CLIENT * Client)
763 assert(Client != NULL);
765 /* Check password ... */
766 if (strcmp(Client_Password(Client), Conf_ServerPwd) != 0) {
769 "Client \"%s\" rejected (connection %d): Bad password!",
770 Client_Mask(Client), Client_Conn(Client));
771 Conn_Close(Client_Conn(Client), NULL, "Bad password", true);
775 Introduce_Client(NULL, Client, CLIENT_USER);
777 if (!IRC_WriteStrClient
778 (Client, RPL_WELCOME_MSG, Client_ID(Client), Client_Mask(Client)))
780 if (!IRC_WriteStrClient
781 (Client, RPL_YOURHOST_MSG, Client_ID(Client),
782 Client_ID(Client_ThisServer()), PACKAGE_VERSION, TARGET_CPU,
783 TARGET_VENDOR, TARGET_OS))
785 if (!IRC_WriteStrClient
786 (Client, RPL_CREATED_MSG, Client_ID(Client), NGIRCd_StartStr))
788 if (!IRC_WriteStrClient
789 (Client, RPL_MYINFO_MSG, Client_ID(Client),
790 Client_ID(Client_ThisServer()), PACKAGE_VERSION, USERMODES,
794 /* Features supported by this server (005 numeric, ISUPPORT),
795 * see <http://www.irc.org/tech_docs/005.html> for details. */
796 if (!IRC_Send_ISUPPORT(Client))
799 if (!IRC_Send_LUSERS(Client))
801 if (!IRC_Show_MOTD(Client))
804 /* Suspend the client for a second ... */
805 IRC_SetPenalty(Client, 1);
812 Kill_Nick( char *Nick, char *Reason )
816 assert( Nick != NULL );
817 assert( Reason != NULL );
819 r.prefix = (char *)Client_ThisServer( );
824 Log( LOG_ERR, "User(s) with nick \"%s\" will be disconnected: %s", Nick, Reason );
825 IRC_KILL( Client_ThisServer( ), &r );
830 Introduce_Client(CLIENT *From, CLIENT *Client, int Type)
832 /* Set client type (user or service) */
833 Client_SetType(Client, Type);
836 if (Conf_IsService(Conf_GetServer(Client_Conn(From)),
838 Client_SetType(Client, CLIENT_SERVICE);
839 LogDebug("%s \"%s\" (+%s) registered (via %s, on %s, %d hop%s).",
840 Client_TypeText(Client), Client_Mask(Client),
841 Client_Modes(Client), Client_ID(From),
842 Client_ID(Client_Introducer(Client)),
843 Client_Hops(Client), Client_Hops(Client) > 1 ? "s": "");
845 Log(LOG_NOTICE, "%s \"%s\" registered (connection %d).",
846 Client_TypeText(Client), Client_Mask(Client),
847 Client_Conn(Client));
848 Log_ServerNotice('c', "Client connecting: %s (%s@%s) [%s] - %s",
849 Client_ID(Client), Client_User(Client),
850 Client_Hostname(Client),
851 Conn_IPA(Client_Conn(Client)),
852 Client_TypeText(Client));
855 /* Inform other servers */
856 IRC_WriteStrServersPrefixFlag_CB(From,
857 From != NULL ? From : Client_ThisServer(),
858 '\0', cb_introduceClient, (void *)Client);
859 } /* Introduce_Client */
863 cb_introduceClient(CLIENT *To, CLIENT *Prefix, void *data)
865 CLIENT *c = (CLIENT *)data;
867 char *modes, *user, *host;
869 modes = Client_Modes(c);
870 user = Client_User(c) ? Client_User(c) : "-";
871 host = Client_Hostname(c) ? Client_Hostname(c) : "-";
873 conn = Client_Conn(To);
874 if (Conn_Options(conn) & CONN_RFC1459) {
875 /* RFC 1459 mode: separate NICK and USER commands */
876 Conn_WriteStr(conn, "NICK %s :%d", Client_ID(c),
878 Conn_WriteStr(conn, ":%s USER %s %s %s :%s",
879 Client_ID(c), user, host,
880 Client_ID(Client_Introducer(c)), Client_Info(c));
882 Conn_WriteStr(conn, ":%s MODE %s +%s",
883 Client_ID(c), Client_ID(c), modes);
885 /* RFC 2813 mode: one combined NICK or SERVICE command */
886 if (Client_Type(c) == CLIENT_SERVICE
887 && strchr(Client_Flags(To), 'S'))
888 IRC_WriteStrClientPrefix(To, Prefix,
889 "SERVICE %s %d * +%s %d :%s",
891 Client_MyToken(Client_Introducer(c)),
892 Client_Modes(c), Client_Hops(c) + 1,
895 IRC_WriteStrClientPrefix(To, Prefix,
896 "NICK %s %d %s %s %d +%s :%s",
897 Client_ID(c), Client_Hops(c) + 1,
899 Client_MyToken(Client_Introducer(c)),
900 modes, Client_Info(c));
902 } /* cb_introduceClient */