GLOBAL void Channel_Quit( CLIENT *Client, const char *Reason ) { CHANNEL *c, *next_c; assert( Client != NULL ); assert( Reason != NULL ); if (Conf_MorePrivacy) Reason = ""; IRC_WriteStrRelatedPrefix( Client, Client, false, "QUIT :%s", Reason ); c = My_Channels; while( c ) { next_c = c->next; Remove_Client( REMOVE_QUIT, c, Client, Client, Reason, false ); c = next_c; } } /* Channel_Quit */
/** * Handler for the IRC "NICK" command. * * See RFC 2812, 3.1.2 "Nick message", and RFC 2813, 4.1.3 "Nick". * * This function implements the IRC command "NICK" which is used to register * with the server, to change already registered nicknames and to introduce * new users which are connected to other servers. * * @param Client The client from which this command has been received. * @param Req Request structure with prefix and all parameters. * @returns CONNECTED or DISCONNECTED. */ GLOBAL bool IRC_NICK( CLIENT *Client, REQUEST *Req ) { CLIENT *intr_c, *target, *c; char *nick, *user, *hostname, *modes, *info; int token, hops; assert( Client != NULL ); assert( Req != NULL ); /* Some IRC clients, for example BitchX, send the NICK and USER * commands in the wrong order ... */ if(Client_Type(Client) == CLIENT_UNKNOWN || Client_Type(Client) == CLIENT_GOTPASS || Client_Type(Client) == CLIENT_GOTNICK #ifndef STRICT_RFC || Client_Type(Client) == CLIENT_GOTUSER #endif || Client_Type(Client) == CLIENT_USER || Client_Type(Client) == CLIENT_SERVICE || (Client_Type(Client) == CLIENT_SERVER && Req->argc == 1)) { /* User registration or change of nickname */ /* Wrong number of arguments? */ if( Req->argc != 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command ); /* Search "target" client */ if( Client_Type( Client ) == CLIENT_SERVER ) { target = Client_Search( Req->prefix ); if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[0] ); } else { /* Is this a restricted client? */ if( Client_HasMode( Client, 'r' )) return IRC_WriteStrClient( Client, ERR_RESTRICTED_MSG, Client_ID( Client )); target = Client; } #ifndef STRICT_RFC /* If the clients tries to change to its own nickname we won't * do anything. This is how the original ircd behaves and some * clients (for example Snak) expect it to be like this. * But I doubt that this is "really the right thing" ... */ if( strcmp( Client_ID( target ), Req->argv[0] ) == 0 ) return CONNECTED; #endif /* Check that the new nickname is available. Special case: * the client only changes from/to upper to lower case. */ if( strcasecmp( Client_ID( target ), Req->argv[0] ) != 0 ) { if( ! Client_CheckNick( target, Req->argv[0] )) return CONNECTED; } if (Client_Type(target) != CLIENT_USER && Client_Type(target) != CLIENT_SERVICE && Client_Type(target) != CLIENT_SERVER) { /* New client */ LogDebug("Connection %d: got valid NICK command ...", Client_Conn( Client )); /* Register new nickname of this client */ Client_SetID( target, Req->argv[0] ); #ifndef STRICT_RFC if (Conf_AuthPing) { Conn_SetAuthPing(Client_Conn(Client), rand()); IRC_WriteStrClient(Client, "PING :%ld", Conn_GetAuthPing(Client_Conn(Client))); LogDebug("Connection %d: sent AUTH PING %ld ...", Client_Conn(Client), Conn_GetAuthPing(Client_Conn(Client))); } #endif /* If we received a valid USER command already then * register the new client! */ if( Client_Type( Client ) == CLIENT_GOTUSER ) return Login_User( Client ); else Client_SetType( Client, CLIENT_GOTNICK ); } else { /* Nickname change */ if (Client_Conn(target) > NONE) { /* Local client */ Log(LOG_INFO, "%s \"%s\" changed nick (connection %d): \"%s\" -> \"%s\".", Client_TypeText(target), Client_Mask(target), Client_Conn(target), Client_ID(target), Req->argv[0]); Conn_UpdateIdle(Client_Conn(target)); } else { /* Remote client */ LogDebug("%s \"%s\" changed nick: \"%s\" -> \"%s\".", Client_TypeText(target), Client_Mask(target), Client_ID(target), Req->argv[0]); } /* Inform all users and servers (which have to know) * of this nickname change */ if( Client_Type( Client ) == CLIENT_USER ) IRC_WriteStrClientPrefix( Client, Client, "NICK :%s", Req->argv[0] ); IRC_WriteStrServersPrefix( Client, target, "NICK :%s", Req->argv[0] ); IRC_WriteStrRelatedPrefix( target, target, false, "NICK :%s", Req->argv[0] ); /* Register old nickname for WHOWAS queries */ Client_RegisterWhowas( target ); /* Save new nickname */ Client_SetID( target, Req->argv[0] ); IRC_SetPenalty( target, 2 ); } return CONNECTED; } else if(Client_Type(Client) == CLIENT_SERVER || Client_Type(Client) == CLIENT_SERVICE) { /* Server or service introduces new client */ /* Bad number of parameters? */ if (Req->argc != 2 && Req->argc != 7) return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, Client_ID(Client), Req->command); if (Req->argc >= 7) { /* RFC 2813 compatible syntax */ nick = Req->argv[0]; hops = atoi(Req->argv[1]); user = Req->argv[2]; hostname = Req->argv[3]; token = atoi(Req->argv[4]); modes = Req->argv[5] + 1; info = Req->argv[6]; } else { /* RFC 1459 compatible syntax */ nick = Req->argv[0]; hops = 1; user = Req->argv[0]; hostname = Client_ID(Client); token = atoi(Req->argv[1]); modes = ""; info = Req->argv[0]; } c = Client_Search(nick); if(c) { /* * the new nick is already present on this server: * the new and the old one have to be disconnected now. */ Log( LOG_ERR, "Server %s introduces already registered nick \"%s\"!", Client_ID( Client ), Req->argv[0] ); Kill_Nick( Req->argv[0], "Nick collision" ); return CONNECTED; } /* Find the Server this client is connected to */ intr_c = Client_GetFromToken(Client, token); if( ! intr_c ) { Log( LOG_ERR, "Server %s introduces nick \"%s\" on unknown server!?", Client_ID( Client ), Req->argv[0] ); Kill_Nick( Req->argv[0], "Unknown server" ); return CONNECTED; } c = Client_NewRemoteUser(intr_c, nick, hops, user, hostname, token, modes, info, true); if( ! c ) { /* out of memory, need to disconnect client to keep network state consistent */ Log( LOG_ALERT, "Can't create client structure! (on connection %d)", Client_Conn( Client )); Kill_Nick( Req->argv[0], "Server error" ); return CONNECTED; } /* RFC 2813: client is now fully registered, inform all the * other servers about the new user. * RFC 1459: announce the new client only after receiving the * USER command, first we need more information! */ if (Req->argc < 7) { LogDebug("Client \"%s\" is being registered (RFC 1459) ...", Client_Mask(c)); Client_SetType(c, CLIENT_GOTNICK); } else Client_Introduce(Client, c, CLIENT_USER); return CONNECTED; } else return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client )); } /* IRC_NICK */