/[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.7 by sysadm, Wed Oct 22 14:25:15 2025 UTC Revision 1.19 by sysadm, Mon Nov 3 11:49:12 2025 UTC
# Line 22  Line 22 
22  #include "str_process.h"  #include "str_process.h"
23  #include "user_list.h"  #include "user_list.h"
24  #include "user_priv.h"  #include "user_priv.h"
25    #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 34  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 42  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 81  static int user_list_draw_items(int page Line 85  static int user_list_draw_items(int page
85                  else if (p_tm->tm_year > 70)                  else if (p_tm->tm_year > 70)
86                  {                  {
87                          snprintf(str_time_login, sizeof(str_time_login),                          snprintf(str_time_login, sizeof(str_time_login),
88                                           "%d年", p_tm->tm_year - 70);                                           "%d年%d天", p_tm->tm_year - 70, p_tm->tm_yday);
89                  }                  }
90                  else if (p_tm->tm_yday > 0)                  else if (p_tm->tm_yday > 0)
91                  {                  {
# Line 91  static int user_list_draw_items(int page Line 95  static int user_list_draw_items(int page
95                  else if (p_tm->tm_hour > 0)                  else if (p_tm->tm_hour > 0)
96                  {                  {
97                          snprintf(str_time_login, sizeof(str_time_login),                          snprintf(str_time_login, sizeof(str_time_login),
98                                           "%d时%d分", p_tm->tm_hour, p_tm->tm_min);                                           "%d:%.2d", p_tm->tm_hour, p_tm->tm_min);
99                  }                  }
100                  else                  else
101                  {                  {
102                          snprintf(str_time_login, sizeof(str_time_login),                          snprintf(str_time_login, sizeof(str_time_login),
103                                           "%d分%d秒", p_tm->tm_min, p_tm->tm_sec);                                           "%d\'%.2d\"", p_tm->tm_min, p_tm->tm_sec);
104                  }                  }
105    
106                  moveto(4 + i, 1);                  moveto(4 + i, 1);
# Line 141  static int user_online_list_draw_items(i Line 145  static int user_online_list_draw_items(i
145                  else if (p_tm->tm_yday > 0)                  else if (p_tm->tm_yday > 0)
146                  {                  {
147                          snprintf(str_time_login, sizeof(str_time_login),                          snprintf(str_time_login, sizeof(str_time_login),
148                                           "%d天%d时", p_tm->tm_yday, p_tm->tm_hour);                                           "%dd%dh", p_tm->tm_yday, p_tm->tm_hour);
149                  }                  }
150                  else if (p_tm->tm_hour > 0)                  else if (p_tm->tm_hour > 0)
151                  {                  {
152                          snprintf(str_time_login, sizeof(str_time_login),                          snprintf(str_time_login, sizeof(str_time_login),
153                                           "%d时%d分", p_tm->tm_hour, p_tm->tm_min);                                           "%d:%.2d", p_tm->tm_hour, p_tm->tm_min);
154                  }                  }
155                  else                  else
156                  {                  {
157                          snprintf(str_time_login, sizeof(str_time_login),                          snprintf(str_time_login, sizeof(str_time_login),
158                                           "%d\'%d\"", p_tm->tm_min, p_tm->tm_sec);                                           "%d\'%.2d\"", p_tm->tm_min, p_tm->tm_sec);
159                  }                  }
160    
161                  tm_duration = tm_now - p_users[i].last_tm;                  tm_duration = tm_now - p_users[i].last_tm;
# Line 304  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 445  int user_list_display(int online_user) Line 451  int user_list_display(int online_user)
451                          }                          }
452                          break;                          break;
453                  case VIEW_USER:                  case VIEW_USER:
454                          clearscr();                          user_info_display(online_user ? &(online_users[selected_index].user_info) : &(users[selected_index]));
455                          if (online_user)                          user_list_draw_screen(online_user);
456                          {                          break;
457                                  prints("已选中用户 [%s] 会话 %d", online_users[selected_index].user_info.username, online_users[selected_index].id);                  case SEARCH_USER:
458                            user_list_search();
                                 // USER_ONLINE_INFO users[5];  
                                 // int user_cnt = 5;  
                                 // ret = query_user_online_info_by_uid(online_users[selected_index].user_info.uid, users, &user_cnt, 0);  
                                 // if (ret <= 0)  
                                 // {  
                                 //      log_error("query_user_online_info_by_uid(uid=%d, cnt=%d) error: %d\n",  
                                 //                        online_users[selected_index].user_info.uid, user_cnt, ret);  
                                 // }  
                                 // else  
                                 // {  
                                 //      for (int i = 0; i < user_cnt; i++)  
                                 //      {  
                                 //              moveto(2 + i, 1);  
                                 //              prints("会话%d", users[i].id);  
                                 //      }  
                                 // }  
                         }  
                         else  
                         {  
                                 prints("已选中用户 [%s]", users[selected_index].username);  
                         }  
                         press_any_key();  
459                          user_list_draw_screen(online_user);                          user_list_draw_screen(online_user);
460                          break;                          break;
461                  case SHOW_HELP:                  case SHOW_HELP:
# Line 484  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 + 1];
487            int ok;
488            int ch;
489    
490            username[0] = '\0';
491    
492            clearscr();
493    
494            while (!SYS_server_exit)
495            {
496                    clrline(3, SCREEN_ROWS);
497                    get_data(2, 1, "查找谁: ", username, sizeof(username), BBS_username_max_len);
498    
499                    if (username[0] == '\0')
500                    {
501                            return 0;
502                    }
503    
504                    // Verify format
505                    for (i = 0, ok = 1; ok && username[i] != '\0'; i++)
506                    {
507                            if (!(isalpha(username[i]) || (i > 0 && (isdigit(username[i]) || username[i] == '_'))))
508                            {
509                                    ok = 0;
510                            }
511                    }
512                    if (ok && i > BBS_username_max_len)
513                    {
514                            ok = 0;
515                    }
516                    if (!ok)
517                    {
518                            moveto(3, 1);
519                            clrtoeol();
520                            prints("用户名格式非法");
521                            continue;
522                    }
523    
524                    clrline(3, SCREEN_ROWS);
525    
526                    ret = query_user_info_by_username(username, max_user_cnt, uid_list, username_list);
527    
528                    if (ret < 0)
529                    {
530                            log_error("query_user_info_by_username(%s) error\n", username);
531                            return -1;
532                    }
533                    else if (ret > 1)
534                    {
535                            for (i = 0; i < MIN(ret, users_per_line * max_user_lines); i++)
536                            {
537                                    moveto(4 + i / users_per_line, 3 + i % users_per_line * (BBS_username_max_len + 3));
538                                    prints("%s", username_list[i]);
539                            }
540                            moveto(SCREEN_ROWS, 1);
541                            if (ret > users_per_line * max_user_lines)
542                            {
543                                    prints("还有更多...");
544                            }
545    
546                            moveto(3, 1);
547                            prints("存在多个匹配的用户,按\033[1;33mEnter\033[m精确查找");
548                            iflush();
549    
550                            ch = igetch_t(MAX_DELAY_TIME);
551                            switch (ch)
552                            {
553                            case KEY_NULL:
554                            case KEY_TIMEOUT:
555                                    return -1;
556                            case KEY_ESC:
557                                    return 0;
558                            case CR:
559                                    ret = (strcasecmp(username_list[0], username) == 0 ? 1 : 0);
560                                    break;
561                            default:
562                                    i = (int)strnlen(username, sizeof(username) - 1);
563                                    if (i + 1 <= BBS_username_max_len && (isalnum((char)ch) || ch == '_'))
564                                    {
565                                            username[i] = (char)ch;
566                                            username[i + 1] = '\0';
567                                    }
568                                    continue;
569                            }
570                    }
571    
572                    clrline(3, SCREEN_ROWS);
573                    if (ret == 0)
574                    {
575                            moveto(3, 1);
576                            prints("没有找到符合条件的用户");
577                            press_any_key();
578                            return 0;
579                    }
580                    else // ret == 1
581                    {
582                            if (query_user_info_by_uid(uid_list[0], &user_info, user_intro, sizeof(user_intro)) <= 0)
583                            {
584                                    log_error("query_user_info_by_uid(uid=%d) error\n", uid_list[0]);
585                                    return -2;
586                            }
587                            else if (user_info_display(&user_info) < 0)
588                            {
589                                    log_error("user_info_display(uid=%d) error\n", uid_list[0]);
590                                    return -3;
591                            }
592                            return 1;
593                    }
594            }
595    
596          return 0;          return 0;
597  }  }


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

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