/[LeafOK_CVS]/lbbs/src/user_list_display.c
ViewVC logotype

Diff of /lbbs/src/user_list_display.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.13 by sysadm, Tue Oct 28 05:02:17 2025 UTC Revision 1.14 by sysadm, Sun Nov 2 14:38:53 2025 UTC
# Line 24  Line 24 
24  #include "user_priv.h"  #include "user_priv.h"
25  #include "user_info_display.h"  #include "user_info_display.h"
26  #include "user_list_display.h"  #include "user_list_display.h"
27    #include <ctype.h>
28  #include <string.h>  #include <string.h>
29  #include <time.h>  #include <time.h>
30  #include <sys/param.h>  #include <sys/param.h>
# Line 35  enum select_cmd_t Line 36  enum select_cmd_t
36          CHANGE_PAGE,          CHANGE_PAGE,
37          REFRESH_LIST,          REFRESH_LIST,
38          SHOW_HELP,          SHOW_HELP,
39            SEARCH_USER,
40  };  };
41    
42  static int user_list_draw_screen(int online_user)  static int user_list_draw_screen(int online_user)
# Line 43  static int user_list_draw_screen(int onl Line 45  static int user_list_draw_screen(int onl
45          show_top((online_user ? "[线上使用者]" : "[已注册用户]"), BBS_name, "");          show_top((online_user ? "[线上使用者]" : "[已注册用户]"), BBS_name, "");
46          moveto(2, 0);          moveto(2, 0);
47          prints("返回[\033[1;32m←\033[0;37m,\033[1;32mESC\033[0;37m] 选择[\033[1;32m↑\033[0;37m,\033[1;32m↓\033[0;37m] "          prints("返回[\033[1;32m←\033[0;37m,\033[1;32mESC\033[0;37m] 选择[\033[1;32m↑\033[0;37m,\033[1;32m↓\033[0;37m] "
48                     "查看[\033[1;32m→\033[0;37m,\033[1;32mENTER\033[0;37m] 帮助[\033[1;32mh\033[0;37m]\033[m");                     "查看[\033[1;32m→\033[0;37m,\033[1;32mENTER\033[0;37m] 查找[\033[1;32ms\033[0;37m] "
49                       "帮助[\033[1;32mh\033[0;37m]\033[m");
50          moveto(3, 0);          moveto(3, 0);
51    
52          if (online_user)          if (online_user)
# Line 305  static enum select_cmd_t user_list_selec Line 308  static enum select_cmd_t user_list_selec
308                                  (*p_selected_index)++;                                  (*p_selected_index)++;
309                          }                          }
310                          break;                          break;
311                    case 's':
312                            return SEARCH_USER;
313                  case KEY_F5:                  case KEY_F5:
314                          return REFRESH_LIST;                          return REFRESH_LIST;
315                  case 'h':                  case 'h':
# Line 449  int user_list_display(int online_user) Line 454  int user_list_display(int online_user)
454                          user_info_display(online_user ? &(online_users[selected_index].user_info) : &(users[selected_index]));                          user_info_display(online_user ? &(online_users[selected_index].user_info) : &(users[selected_index]));
455                          user_list_draw_screen(online_user);                          user_list_draw_screen(online_user);
456                          break;                          break;
457                    case SEARCH_USER:
458                            user_list_search();
459                            user_list_draw_screen(online_user);
460                            break;
461                  case SHOW_HELP:                  case SHOW_HELP:
462                          // Display help information                          // Display help information
463                          display_file(DATA_READ_HELP, 1);                          display_file(DATA_READ_HELP, 1);
# Line 459  int user_list_display(int online_user) Line 468  int user_list_display(int online_user)
468                  }                  }
469          }          }
470    
471            return 0;
472    }
473    
474    int user_list_search(void)
475    {
476            const int users_per_line = 5;
477            const int max_user_lines = 20;
478            const int max_user_cnt = users_per_line * max_user_lines + 1;
479    
480            char username[BBS_username_max_len + 1];
481            int32_t uid_list[max_user_cnt];
482            char username_list[max_user_cnt][BBS_username_max_len + 1];
483            int ret;
484            int i;
485            USER_INFO user_info;
486            char user_intro[BBS_user_intro_max_len];
487            int ok;
488    
489            username[0] = '\0';
490    
491            clearscr();
492    
493            while (!SYS_server_exit)
494            {
495                    get_data(2, 1, "查找谁: ", username, sizeof(username), BBS_username_max_len);
496    
497                    if (username[0] == '\0')
498                    {
499                            return 0;
500                    }
501    
502                    // Verify format
503                    for (i = 0, ok = 1; ok && username[i] != '\0'; i++)
504                    {
505                            if (!(isalpha(username[i]) || (i > 0 && isdigit(username[i]))))
506                            {
507                                    ok = 0;
508                            }
509                    }
510                    if (ok && i > 12)
511                    {
512                            ok = 0;
513                    }
514                    if (!ok)
515                    {
516                            moveto(3, 1);
517                            clrtoeol();
518                            prints("用户名格式非法");
519                            continue;
520                    }
521    
522                    clrline(3, SCREEN_ROWS);
523    
524                    ret = query_user_info_by_username(username, max_user_cnt, uid_list, username_list);
525    
526                    if (ret < 0)
527                    {
528                            log_error("query_user_info_by_username(%s) error\n", username);
529                            return -1;
530                    }
531                    else if (ret > 1)
532                    {
533                            moveto(3, 1);
534                            prints("存在多个匹配的用户,[S]精确查找,[L]列出全部? [L]");
535                            iflush();
536    
537                            switch (igetch_t(MAX_DELAY_TIME))
538                            {
539                            case KEY_NULL:
540                            case KEY_TIMEOUT:
541                                    return 0;
542                            case 'S':
543                            case 's':
544                                    ret = (strcasecmp(username_list[0], username) == 0 ? 1 : 0);
545                                    break;
546                            default:
547                                    for (i = 0; i < MIN(ret, users_per_line * max_user_lines); i++)
548                                    {
549                                            moveto(4 + i / users_per_line, 3 + i % users_per_line * (BBS_username_max_len + 3));
550                                            prints("%s", username_list[i]);
551                                    }
552                                    moveto(SCREEN_ROWS, 1);
553                                    if (ret > users_per_line * max_user_lines)
554                                    {
555                                            prints("还有更多...");
556                                    }
557                                    continue;
558                            }
559                    }
560    
561                    if (ret == 0)
562                    {
563                            moveto(3, 1);
564                            clrtoeol();
565                            prints("没有找到符合条件的用户");
566                            continue;
567                    }
568                    else // ret == 1
569                    {
570                            if (query_user_info_by_uid(uid_list[0], &user_info, user_intro, sizeof(user_intro)) <= 0)
571                            {
572                                    log_error("query_user_info_by_uid(uid=%d) error\n", uid_list[0]);
573                                    return -2;
574                            }
575                            else if (user_info_display(&user_info) < 0)
576                            {
577                                    log_error("user_info_display(uid=%d) error\n", uid_list[0]);
578                                    return -3;
579                            }
580                            return 1;
581                    }
582            }
583    
584          return 0;          return 0;
585  }  }


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1