void hf_msgch(t_env *env, char *str, int fd) {//verifier que on est bien dans la salle ? char *chanel rooms_list *tmp; t_usercont *utmp; str = str + 7; chanel = get_first_word(str); tmp = env->rooms_list; while (tmp != NULL) { if (ft_strcmp(tmp->name, chanel) == 0) break; tmp = tmp->next; } if (tmp == NULL) { add_to_queue(env, "There is no such room", fd); return ; } str = str + ft_strlen(chanel) + 1; free(chanel); utmp = tmp->users; //rajouter le nom de l'utilisateur au debut du message while (utmp != NULL) { if (fd != utmp->user->fd) add_to_queue(env, str, utmp->user->fd); utmp = utmp->next; } }
void hf_msg(t_env *env, char *str, int fd) { char *usr; int fdr; str = str + 5; usr = get_first_word(str); str = str + ft_strlen(usr) + 1; fdr = get_client_fd(usr, env->users_list); if (fdr == -1) add_to_queue(env, "There is no such user", fd); else { add_to_queue(env, str, fdr); } free(usr); }
void help_text_area::add_text_item(const std::string& text, const std::string& ref_dst, bool broken_link, int _font_size, bool bold, bool italic, SDL_Color text_color ) { const int font_size = _font_size < 0 ? normal_font_size : _font_size; if (text.empty()) return; const int remaining_width = get_remaining_width(); size_t first_word_start = text.find_first_not_of(" "); if (first_word_start == std::string::npos) { first_word_start = 0; } if (text[first_word_start] == '\n') { down_one_line(); std::string rest_text = text; rest_text.erase(0, first_word_start + 1); add_text_item(rest_text, ref_dst, broken_link, _font_size, bold, italic, text_color); return; } const std::string first_word = get_first_word(text); int state = ref_dst == "" ? 0 : TTF_STYLE_UNDERLINE; state |= bold ? TTF_STYLE_BOLD : 0; state |= italic ? TTF_STYLE_ITALIC : 0; if (curr_loc_.first != get_min_x(curr_loc_.second, curr_row_height_) && remaining_width < font::line_width(first_word, font_size, state)) { // The first word does not fit, and we are not at the start of // the line. Move down. down_one_line(); std::string s = remove_first_space(text); add_text_item(s, ref_dst, broken_link, _font_size, bold, italic, text_color); } else { std::vector<std::string> parts = split_in_width(text, font_size, remaining_width); std::string first_part = parts.front(); // Always override the color if we have a cross reference. SDL_Color color; if(ref_dst.empty()) color = text_color; else if(broken_link) color = font::BAD_COLOR; else color = font::YELLOW_COLOR; surface surf(font::get_rendered_text(first_part, font_size, color, state)); if (!surf.null()) add_item(item(surf, curr_loc_.first, curr_loc_.second, first_part, ref_dst)); if (parts.size() > 1) { std::string& s = parts.back(); const std::string first_word_before = get_first_word(s); const std::string first_word_after = get_first_word(remove_first_space(s)); if (get_remaining_width() >= font::line_width(first_word_after, font_size, state) && get_remaining_width() < font::line_width(first_word_before, font_size, state)) { // If the removal of the space made this word fit, we // must move down a line, otherwise it will be drawn // without a space at the end of the line. s = remove_first_space(s); down_one_line(); } else if (!(font::line_width(first_word_before, font_size, state) < get_remaining_width())) { s = remove_first_space(s); } add_text_item(s, ref_dst, broken_link, _font_size, bold, italic, text_color); } } }