/** * Handler for the IRC "MODE" command. * * This function detects whether user or channel modes should be modified * and calls the appropriate sub-functions. * * @param Client The client from which this command has been received. * @param Req Request structure with prefix and all parameters. * @return CONNECTED or DISCONNECTED. */ GLOBAL bool IRC_MODE( CLIENT *Client, REQUEST *Req ) { CLIENT *cl, *origin; CHANNEL *chan; assert(Client != NULL); assert(Req != NULL); _IRC_GET_SENDER_OR_RETURN_(origin, Req, Client) /* Test for "fake" MODE commands injected by this local instance, * for example when handling the "DefaultUserModes" settings. * This doesn't harm real commands, because prefixes of regular * clients are checked in Validate_Prefix() and can't be faked. */ if (Req->prefix && Client_Search(Req->prefix) == Client_ThisServer()) Client = Client_Search(Req->prefix); /* Channel or user mode? */ cl = NULL; chan = NULL; if (Client_IsValidNick(Req->argv[0])) cl = Client_Search(Req->argv[0]); if (Channel_IsValidName(Req->argv[0])) chan = Channel_Search(Req->argv[0]); if (cl) return Client_Mode(Client, Req, origin, cl); if (chan) return Channel_Mode(Client, Req, origin, chan); /* No target found! */ return IRC_WriteErrClient(Client, ERR_NOSUCHNICK_MSG, Client_ID(Client), Req->argv[0]); } /* IRC_MODE */
/** * Join Channel * This function lets a client join a channel. First, the function * checks that the specified channel name is valid and that the client * isn't already a member. If the specified channel doesn't exist, * a new channel is created. Client is added to channel by function * Add_Client(). */ GLOBAL bool Channel_Join( CLIENT *Client, const char *Name ) { CHANNEL *chan; assert(Client != NULL); assert(Name != NULL); /* Check that the channel name is valid */ if (! Channel_IsValidName(Name)) { IRC_WriteErrClient(Client, ERR_NOSUCHCHANNEL_MSG, Client_ID(Client), Name); return false; } chan = Channel_Search(Name); if(chan) { /* Check if the client is already in the channel */ if (Get_Cl2Chan(chan, Client)) return false; } else { /* If the specified channel does not exist, the channel * is now created */ chan = Channel_Create(Name); if (!chan) return false; } /* Add user to Channel */ if (! Add_Client(chan, Client)) return false; return true; } /* Channel_Join */
/** * Handler for the IRC "MODE" command. * * See RFC 2812 section 3.1.5 ("user mode message") and section 3.2.3 * ("channel mode message"), and RFC 2811 section 4 ("channel modes"). * * @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_MODE( CLIENT *Client, REQUEST *Req ) { CLIENT *cl, *origin; CHANNEL *chan; assert(Client != NULL); assert(Req != NULL); /* No parameters? */ if (Req->argc < 1) return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, Client_ID(Client), Req->command); /* Origin for answers */ if (Client_Type(Client) == CLIENT_SERVER) { origin = Client_Search(Req->prefix); if (!origin) return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG, Client_ID(Client), Req->prefix); } else origin = Client; /* Channel or user mode? */ cl = NULL; chan = NULL; if (Client_IsValidNick(Req->argv[0])) cl = Client_Search(Req->argv[0]); if (Channel_IsValidName(Req->argv[0])) chan = Channel_Search(Req->argv[0]); if (cl) return Client_Mode(Client, Req, origin, cl); if (chan) return Channel_Mode(Client, Req, origin, chan); /* No target found! */ return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG, Client_ID(Client), Req->argv[0]); } /* IRC_MODE */
/** * Generate predefined persistent channels and &SERVER */ GLOBAL void Channel_InitPredefined( void ) { CHANNEL *new_chan; const struct Conf_Channel *conf_chan; const char *c; size_t i, channel_count = array_length(&Conf_Channels, sizeof(*conf_chan)); conf_chan = array_start(&Conf_Channels); assert(channel_count == 0 || conf_chan != NULL); for (i = 0; i < channel_count; i++, conf_chan++) { if (!conf_chan->name[0]) continue; if (!Channel_IsValidName(conf_chan->name)) { Log(LOG_ERR, "Can't create pre-defined channel: invalid name: \"%s\"", conf_chan->name); continue; } new_chan = Channel_Search(conf_chan->name); if (new_chan) { Log(LOG_INFO, "Can't create pre-defined channel \"%s\": name already in use.", conf_chan->name); Set_KeyFile(new_chan, conf_chan->keyfile); continue; } new_chan = Channel_Create(conf_chan->name); if (!new_chan) { Log(LOG_ERR, "Can't create pre-defined channel \"%s\"!", conf_chan->name); continue; } Log(LOG_INFO, "Created pre-defined channel \"%s\".", conf_chan->name); Channel_ModeAdd(new_chan, 'P'); if (conf_chan->topic[0]) Channel_SetTopic(new_chan, NULL, conf_chan->topic); c = conf_chan->modes; while (*c) Channel_ModeAdd(new_chan, *c++); Channel_SetKey(new_chan, conf_chan->key); Channel_SetMaxUsers(new_chan, conf_chan->maxusers); Set_KeyFile(new_chan, conf_chan->keyfile); } if (channel_count) array_free(&Conf_Channels); /* Make sure the local &SERVER channel exists */ if (!Channel_Search("&SERVER")) { new_chan = Channel_Create("&SERVER"); if (new_chan) { Channel_SetModes(new_chan, "mnPt"); Channel_SetTopic(new_chan, Client_ThisServer(), "Server Messages"); } else Log(LOG_ERR, "Failed to create \"&SERVER\" channel!"); } else LogDebug("Required channel \"&SERVER\" already exists, ok."); } /* Channel_InitPredefined */