static bool is_topic_valid(t_message *msg, t_client *client, t_chan *chans) { t_chan *tmp; if (msg == NULL || client == NULL) return (false); if (get_nb_params(msg->params) != 1 && get_nb_params(msg->params) != 2) { dprintf(client->client, ERR_NEEDMOREPARAMS, S_NAME, S_ADDR, client->nick, msg->command); return (false); } if ((tmp = find_chan(chans, msg->params[0])) == NULL) { dprintf(client->client, ERR_NOTONCHANNEL, S_NAME, S_ADDR, client->nick, msg->params[0]); return (false); } if (is_in_chan(tmp->name, client) == false) { dprintf(client->client, ERR_NOTONCHANNEL, S_NAME, S_ADDR, client->nick, msg->params[0]); return (false); } return (true); }
static void send_chan(t_message *msg, t_client *client, t_chan *dest) { t_cclient *tmp; if (dest != NULL) { if (is_in_chan(dest->name, client) == false) dprintf(client->client, ERR_CANNOTSENDTOCHAN, S_NAME, S_ADDR, client->nick, dest->name); else { tmp = first_node(&dest->clients->node); while (tmp != NULL) { if (tmp->client != client) dprintf(tmp->client->client, ":%s!%s PRIVMSG %s :%s\r\n", client->nick, client->user, dest->name, msg->params[1]); tmp = tmp->node.next; } } } else dprintf(client->client, ERR_NOSUCHNICK, S_NAME, S_ADDR, client->nick, msg->params[0]); }
int irc_server_cmd_part(t_srv *s, t_usr* u, char** cmd) { t_chn *channel; int r; if (!cmd[1]) return (server_send(u->s, ERR_NEEDMOREPARAMS)); if (u->n == NULL) return (server_send(u->s, ERR_NOLOGIN)); if (((channel = get_channel(s->c, cmd[1])) == NULL)) return (server_send(u->s, ERR_NOSUCHCHANNEL)); else if (is_in_chan(channel, u)) { if (!(r = remove_user_from_chan(s->c, u, (cmd[2] ? cmd[2] : P_MSG)))) remove_chan(s, channel); u->c = NULL; return (EXIT_SUCCESS); } return (server_send(u->s, ERR_NOTONCHANNEL)); }