static void _send_to_channel(t_server *server, int fd, char *chan, char *msg) { t_channel *tmp; int i; t_list *lst; if (!(tmp = get_channel(server->channels, chan))) send_code_msg(server, fd, ERR_NOSUCHNICK, create_error_msg(chan, " :No such nick/channel")); else if (get_list(tmp->clients, server->client[fd].nick) == tmp->clients) send_code_msg(server, fd, ERR_CANNOTSENDTOCHAN, create_error_msg(chan, " :Cannot send to channel")); else { lst = tmp->clients->next; while (lst != tmp->clients) { i = -1; while (++i < MAX_FD) if (server->type_fd[i] == FD_CLIENT && strcmp(server->client[i].nick, lst->data) == 0) break; if (i != fd) send_info_msg(server, i, server->client[fd].nick, msg); lst = lst->next; } } }
void list_channel(t_serv *serv, t_client *client, char **cmd, char *str) { t_tag *list; t_tag *tmp; if (serv->tag) { list = serv->tag; tmp = list->next; while (tmp != list) { send_info_msg(client, tmp->channel); tmp = tmp->next; } send_info_msg(client, tmp->channel); } (void)cmd; (void)str; }
static void _send_to_client(t_server *server, int fd, char *user, char *msg) { int i; int found; i = -1; found = 0; while (!found && ++i < MAX_FD) { if (server->type_fd[i] == FD_CLIENT && strcmp(server->client[i].nick, user) == 0) found = 1; } if (!found) send_code_msg(server, fd, ERR_NOSUCHNICK, create_error_msg(user, " :No such nick/channel")); else send_info_msg(server, i, server->client[fd].nick, msg); }
static int _check_error(t_server *server, int fd, char **argv) { if (argv == NULL || argv[0] == NULL) { send_code_msg(server, fd, ERR_NORECIPIENT, strdup(":No recipient given (PRIVMSG)")); return (1); } else if (argv[1] == NULL) { send_code_msg(server, fd, ERR_NOTEXTTOSEND, strdup(":No text to send")); return (1); } else if (array_len(argv) + strlen("PRIVMSG") > MAX_MSG - strlen("\r\n")) { send_info_msg(server, fd, server->client[fd].nick, "QUIT :Excess Flood"); return (-1); } return (0); }