/[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.17 by sysadm, Mon Nov 3 06:21:01 2025 UTC Revision 1.30 by sysadm, Sat Jan 3 10:27:14 2026 UTC
# Line 1  Line 1 
1  /***************************************************************************  /* SPDX-License-Identifier: GPL-3.0-or-later */
2                                           user_list_display.c  -  description  /*
3                                                           -------------------   * user_list_display
4          Copyright            : (C) 2004-2025 by Leaflet   *   - user interactive list of (online) users
5          Email                : leaflet@leafok.com   *
6   ***************************************************************************/   * Copyright (C) 2004-2026  Leaflet <leaflet@leafok.com>
7     */
8  /***************************************************************************  
9   *                                                                         *  #ifdef HAVE_CONFIG_H
10   *   This program is free software; you can redistribute it and/or modify  *  #include "config.h"
11   *   it under the terms of the GNU General Public License as published by  *  #endif
  *   the Free Software Foundation; either version 3 of the License, or     *  
  *   (at your option) any later version.                                   *  
  *                                                                         *  
  ***************************************************************************/  
12    
13  #include "common.h"  #include "common.h"
14  #include "io.h"  #include "io.h"
# Line 79  static int user_list_draw_items(int page Line 75  static int user_list_draw_items(int page
75                  p_tm = gmtime(&tm_duration);                  p_tm = gmtime(&tm_duration);
76                  if (p_tm == NULL)                  if (p_tm == NULL)
77                  {                  {
78                          log_error("Invalid time duration\n");                          log_error("Invalid time duration");
79                          str_time_login[0] = '\0';                          str_time_login[0] = '\0';
80                  }                  }
81                  else if (p_tm->tm_year > 70)                  else if (p_tm->tm_year > 70)
# Line 139  static int user_online_list_draw_items(i Line 135  static int user_online_list_draw_items(i
135                  p_tm = gmtime(&tm_duration);                  p_tm = gmtime(&tm_duration);
136                  if (p_tm == NULL)                  if (p_tm == NULL)
137                  {                  {
138                          log_error("Invalid time duration\n");                          log_error("Invalid time duration");
139                          str_time_login[0] = '\0';                          str_time_login[0] = '\0';
140                  }                  }
141                  else if (p_tm->tm_yday > 0)                  else if (p_tm->tm_yday > 0)
# Line 162  static int user_online_list_draw_items(i Line 158  static int user_online_list_draw_items(i
158                  p_tm = gmtime(&tm_duration);                  p_tm = gmtime(&tm_duration);
159                  if (p_tm == NULL)                  if (p_tm == NULL)
160                  {                  {
161                          log_error("Invalid time duration\n");                          log_error("Invalid time duration");
162                          str_time_idle[0] = '\0';                          str_time_idle[0] = '\0';
163                  }                  }
164                  else if (p_tm->tm_min > 0)                  else if (p_tm->tm_min > 0)
# Line 222  static enum select_cmd_t user_list_selec Line 218  static enum select_cmd_t user_list_selec
218                  if (ch != KEY_NULL && ch != KEY_TIMEOUT)                  if (ch != KEY_NULL && ch != KEY_TIMEOUT)
219                  {                  {
220                          BBS_last_access_tm = time(NULL);                          BBS_last_access_tm = time(NULL);
221    
222                            // Refresh current action
223                            if (user_online_update(NULL) < 0)
224                            {
225                                    log_error("user_online_update(NULL) error");
226                            }
227                  }                  }
228    
229                  switch (ch)                  switch (ch)
230                  {                  {
231                  case KEY_NULL: // broken pipe                  case KEY_NULL: // broken pipe
232                          log_error("KEY_NULL\n");                          log_debug("KEY_NULL");
233                  case KEY_ESC:                  case KEY_ESC:
234                  case KEY_LEFT:                  case KEY_LEFT:
235                          return EXIT_LIST; // exit list                          return EXIT_LIST; // exit list
236                  case KEY_TIMEOUT:                  case KEY_TIMEOUT:
237                          if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)                          if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time)
238                          {                          {
239                                  log_error("User input timeout\n");                                  log_debug("User input timeout");
240                                  return EXIT_LIST; // exit list                                  return EXIT_LIST; // exit list
241                          }                          }
242                          continue;                          continue;
# Line 362  int user_list_display(int online_user) Line 364  int user_list_display(int online_user)
364                  ret = query_user_online_list(page_id, online_users, &user_count, &page_count);                  ret = query_user_online_list(page_id, online_users, &user_count, &page_count);
365                  if (ret < 0)                  if (ret < 0)
366                  {                  {
367                          log_error("query_user_online_list(page_id=%d) error\n", page_id);                          log_error("query_user_online_list(page_id=%d) error", page_id);
368                          return -2;                          return -2;
369                  }                  }
370          }          }
# Line 371  int user_list_display(int online_user) Line 373  int user_list_display(int online_user)
373                  ret = query_user_list(page_id, users, &user_count, &page_count);                  ret = query_user_list(page_id, users, &user_count, &page_count);
374                  if (ret < 0)                  if (ret < 0)
375                  {                  {
376                          log_error("query_user_list(page_id=%d) error\n", page_id);                          log_error("query_user_list(page_id=%d) error", page_id);
377                          return -2;                          return -2;
378                  }                  }
379          }          }
# Line 388  int user_list_display(int online_user) Line 390  int user_list_display(int online_user)
390                          ret = user_online_list_draw_items(page_id, online_users, user_count);                          ret = user_online_list_draw_items(page_id, online_users, user_count);
391                          if (ret < 0)                          if (ret < 0)
392                          {                          {
393                                  log_error("user_online_list_draw_items(page_id=%d) error\n", page_id);                                  log_error("user_online_list_draw_items(page_id=%d) error", page_id);
394                                  return -3;                                  return -3;
395                          }                          }
396                  }                  }
# Line 397  int user_list_display(int online_user) Line 399  int user_list_display(int online_user)
399                          ret = user_list_draw_items(page_id, users, user_count);                          ret = user_list_draw_items(page_id, users, user_count);
400                          if (ret < 0)                          if (ret < 0)
401                          {                          {
402                                  log_error("user_list_draw_items(page_id=%d) error\n", page_id);                                  log_error("user_list_draw_items(page_id=%d) error", page_id);
403                                  return -3;                                  return -3;
404                          }                          }
405                  }                  }
# Line 411  int user_list_display(int online_user) Line 413  int user_list_display(int online_user)
413    
414                  if (user_online_update(online_user ? "USER_ONLINE" : "USER_LIST") < 0)                  if (user_online_update(online_user ? "USER_ONLINE" : "USER_LIST") < 0)
415                  {                  {
416                          log_error("user_online_update(%s) error\n",                          log_error("user_online_update(%s) error",
417                                            (online_user ? "USER_ONLINE" : "USER_LIST"));                                            (online_user ? "USER_ONLINE" : "USER_LIST"));
418                  }                  }
419    
# Line 427  int user_list_display(int online_user) Line 429  int user_list_display(int online_user)
429                                  ret = query_user_online_list(page_id, online_users, &user_count, &page_count);                                  ret = query_user_online_list(page_id, online_users, &user_count, &page_count);
430                                  if (ret < 0)                                  if (ret < 0)
431                                  {                                  {
432                                          log_error("query_user_online_list(page_id=%d) error\n", page_id);                                          log_error("query_user_online_list(page_id=%d) error", page_id);
433                                          return -2;                                          return -2;
434                                  }                                  }
435                          }                          }
# Line 436  int user_list_display(int online_user) Line 438  int user_list_display(int online_user)
438                                  ret = query_user_list(page_id, users, &user_count, &page_count);                                  ret = query_user_list(page_id, users, &user_count, &page_count);
439                                  if (ret < 0)                                  if (ret < 0)
440                                  {                                  {
441                                          log_error("query_user_list(page_id=%d) error\n", page_id);                                          log_error("query_user_list(page_id=%d) error", page_id);
442                                          return -2;                                          return -2;
443                                  }                                  }
444                          }                          }
# Line 464  int user_list_display(int online_user) Line 466  int user_list_display(int online_user)
466                          user_list_draw_screen(online_user);                          user_list_draw_screen(online_user);
467                          break;                          break;
468                  default:                  default:
469                          log_error("Unknown command %d\n", ret);                          log_error("Unknown command %d", ret);
470                  }                  }
471          }          }
472    
# Line 483  int user_list_search(void) Line 485  int user_list_search(void)
485          int ret;          int ret;
486          int i;          int i;
487          USER_INFO user_info;          USER_INFO user_info;
488          char user_intro[BBS_user_intro_max_len];          char user_intro[BBS_user_intro_max_len + 1];
489          int ok;          int ok;
490            int ch;
491    
492          username[0] = '\0';          username[0] = '\0';
493    
# Line 492  int user_list_search(void) Line 495  int user_list_search(void)
495    
496          while (!SYS_server_exit)          while (!SYS_server_exit)
497          {          {
498                    clrline(3, SCREEN_ROWS);
499                  get_data(2, 1, "查找谁: ", username, sizeof(username), BBS_username_max_len);                  get_data(2, 1, "查找谁: ", username, sizeof(username), BBS_username_max_len);
500    
501                  if (username[0] == '\0')                  if (username[0] == '\0')
# Line 502  int user_list_search(void) Line 506  int user_list_search(void)
506                  // Verify format                  // Verify format
507                  for (i = 0, ok = 1; ok && username[i] != '\0'; i++)                  for (i = 0, ok = 1; ok && username[i] != '\0'; i++)
508                  {                  {
509                          if (!(isalpha(username[i]) || (i > 0 && (isdigit(username[i]) || username[i] == '_'))))                          if (!(isalpha((int)username[i]) || (i > 0 && (isdigit((int)username[i]) || username[i] == '_'))))
510                          {                          {
511                                  ok = 0;                                  ok = 0;
512                          }                          }
# Line 525  int user_list_search(void) Line 529  int user_list_search(void)
529    
530                  if (ret < 0)                  if (ret < 0)
531                  {                  {
532                          log_error("query_user_info_by_username(%s) error\n", username);                          log_error("query_user_info_by_username(%s) error", username);
533                          return -1;                          return -1;
534                  }                  }
535                  else if (ret > 1)                  else if (ret > 1)
536                  {                  {
537                            for (i = 0; i < MIN(ret, users_per_line * max_user_lines); i++)
538                            {
539                                    moveto(4 + i / users_per_line, 3 + i % users_per_line * (BBS_username_max_len + 3));
540                                    prints("%s", username_list[i]);
541                            }
542                            moveto(SCREEN_ROWS, 1);
543                            if (ret > users_per_line * max_user_lines)
544                            {
545                                    prints("还有更多...");
546                            }
547    
548                          moveto(3, 1);                          moveto(3, 1);
549                          prints("存在多个匹配的用户,[S]精确查找,[L]列出全部? [L]");                          prints("存在多个匹配的用户,按\033[1;33mEnter\033[m精确查找");
550                          iflush();                          iflush();
                         igetch_reset();  
551    
552                          switch (igetch_t(MAX_DELAY_TIME))                          ch = igetch_t(BBS_max_user_idle_time);
553                            switch (ch)
554                          {                          {
555                          case KEY_NULL:                          case KEY_NULL:
556                          case KEY_TIMEOUT:                          case KEY_TIMEOUT:
557                                  return -1;                                  return -1;
558                          case KEY_ESC:                          case KEY_ESC:
559                                  return 0;                                  return 0;
560                          case 'S':                          case CR:
                         case 's':  
561                                  ret = (strcasecmp(username_list[0], username) == 0 ? 1 : 0);                                  ret = (strcasecmp(username_list[0], username) == 0 ? 1 : 0);
562                                  break;                                  break;
563                          case 'L':                          default:
564                          case 'l':                                  i = (int)strnlen(username, sizeof(username) - 1);
565                          case CR:                                  if (i + 1 <= BBS_username_max_len && (isalnum(ch) || ch == '_'))
                                 for (i = 0; i < MIN(ret, users_per_line * max_user_lines); i++)  
                                 {  
                                         moveto(4 + i / users_per_line, 3 + i % users_per_line * (BBS_username_max_len + 3));  
                                         prints("%s", username_list[i]);  
                                 }  
                                 moveto(SCREEN_ROWS, 1);  
                                 if (ret > users_per_line * max_user_lines)  
566                                  {                                  {
567                                          prints("还有更多...");                                          username[i] = (char)ch;
568                                            username[i + 1] = '\0';
569                                  }                                  }
570                                  continue;                                  continue;
                         default:  
                                 moveto(3, 1);  
                                 clrtoeol();  
                                 continue;  
571                          }                          }
572                  }                  }
573    
574                    clrline(3, SCREEN_ROWS);
575                  if (ret == 0)                  if (ret == 0)
576                  {                  {
577                          moveto(3, 1);                          moveto(3, 1);
                         clrtoeol();  
578                          prints("没有找到符合条件的用户");                          prints("没有找到符合条件的用户");
579                          press_any_key();                          press_any_key();
580                          return 0;                          return 0;
# Line 579  int user_list_search(void) Line 583  int user_list_search(void)
583                  {                  {
584                          if (query_user_info_by_uid(uid_list[0], &user_info, user_intro, sizeof(user_intro)) <= 0)                          if (query_user_info_by_uid(uid_list[0], &user_info, user_intro, sizeof(user_intro)) <= 0)
585                          {                          {
586                                  log_error("query_user_info_by_uid(uid=%d) error\n", uid_list[0]);                                  log_error("query_user_info_by_uid(uid=%d) error", uid_list[0]);
587                                  return -2;                                  return -2;
588                          }                          }
589                          else if (user_info_display(&user_info) < 0)                          else if (user_info_display(&user_info) < 0)
590                          {                          {
591                                  log_error("user_info_display(uid=%d) error\n", uid_list[0]);                                  log_error("user_info_display(uid=%d) error", uid_list[0]);
592                                  return -3;                                  return -3;
593                          }                          }
594                          return 1;                          return 1;


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

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