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

Diff of /lbbs/src/section_list_display.c

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

Revision 1.53 by sysadm, Wed Oct 15 01:05:18 2025 UTC Revision 1.60 by sysadm, Sun Nov 2 08:35:23 2025 UTC
# Line 30  Line 30 
30  #include "section_list_loader.h"  #include "section_list_loader.h"
31  #include "screen.h"  #include "screen.h"
32  #include "str_process.h"  #include "str_process.h"
33    #include "user_info_display.h"
34  #include "user_priv.h"  #include "user_priv.h"
35    #include <errno.h>
36  #include <string.h>  #include <string.h>
37  #include <time.h>  #include <time.h>
38  #include <sys/param.h>  #include <sys/param.h>
39    
40  static int section_aid_locations[BBS_max_section] = {0};  static int32_t section_aid_locations[BBS_max_section] = {0};
41  static int section_topic_view_mode = 0;  static int section_topic_view_mode = 0;
42  static int section_topic_view_tid = -1;  static int section_topic_view_tid = -1;
43    
# Line 50  enum select_cmd_t Line 52  enum select_cmd_t
52          EDIT_ARTICLE,          EDIT_ARTICLE,
53          DELETE_ARTICLE,          DELETE_ARTICLE,
54          QUERY_ARTICLE,          QUERY_ARTICLE,
55            QUERY_USER,
56          SET_FAVOR_ARTICLE,          SET_FAVOR_ARTICLE,
57          UNSET_FAVOR_ARTICLE,          UNSET_FAVOR_ARTICLE,
58          FIRST_TOPIC_ARTICLE,          FIRST_TOPIC_ARTICLE,
# Line 255  static enum select_cmd_t section_list_se Line 258  static enum select_cmd_t section_list_se
258          {          {
259                  ch = igetch(100);                  ch = igetch(100);
260    
261                  switch (ch)                  if (ch != KEY_NULL && ch != KEY_TIMEOUT)
262                  {                  {
                 case KEY_ESC:  
                 case KEY_LEFT:  
263                          BBS_last_access_tm = time(NULL);                          BBS_last_access_tm = time(NULL);
264                  case KEY_NULL:                   // broken pipe                  }
265                          return EXIT_SECTION; // exit section  
266                    switch (ch)
267                    {
268                    case KEY_NULL: // broken pipe
269                            log_error("KEY_NULL\n");
270                            return EXIT_SECTION;
271                  case KEY_TIMEOUT:                  case KEY_TIMEOUT:
272                          if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)                          if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)
273                          {                          {
274                                  return EXIT_SECTION; // exit section                                  log_error("User input timeout\n");
275                                    return EXIT_SECTION;
276                          }                          }
277                          continue;                          continue;
278                    case KEY_ESC:
279                    case KEY_LEFT:
280                            return EXIT_SECTION;
281                  case 'n':                  case 'n':
                         BBS_last_access_tm = time(NULL);  
282                          return CHANGE_NAME_DISPLAY;                          return CHANGE_NAME_DISPLAY;
283                  case CR:                  case CR:
                         igetch_reset();  
284                  case 'r':                  case 'r':
285                  case KEY_RIGHT:                  case KEY_RIGHT:
286                          if (item_count > 0)                          if (item_count > 0)
287                          {                          {
                                 BBS_last_access_tm = time(NULL);  
288                                  return VIEW_ARTICLE;                                  return VIEW_ARTICLE;
289                          }                          }
290                          break;                          break;
# Line 301  static enum select_cmd_t section_list_se Line 308  static enum select_cmd_t section_list_se
308                                  return QUERY_ARTICLE;                                  return QUERY_ARTICLE;
309                          }                          }
310                          break;                          break;
311                    case Ctrl('A'):
312                            if (item_count > 0)
313                            {
314                                    return QUERY_USER;
315                            }
316                            break;
317                  case 'F':                  case 'F':
318                          if (item_count > 0)                          if (item_count > 0)
319                          {                          {
# Line 401  static enum select_cmd_t section_list_se Line 414  static enum select_cmd_t section_list_se
414                  case 'H':                  case 'H':
415                          return SHOW_TOP10;                          return SHOW_TOP10;
416                  default:                  default:
417                            break;
418                  }                  }
419    
420                  if (old_page_id != *p_page_id)                  if (old_page_id != *p_page_id)
# Line 425  static enum select_cmd_t section_list_se Line 439  static enum select_cmd_t section_list_se
439                          old_selected_index = *p_selected_index;                          old_selected_index = *p_selected_index;
440                  }                  }
441    
                 BBS_last_access_tm = time(NULL);  
442                  if (BBS_last_access_tm - last_refresh_tm >= BBS_section_list_load_interval)                  if (BBS_last_access_tm - last_refresh_tm >= BBS_section_list_load_interval)
443                  {                  {
444                          return CHANGE_PAGE; // force section list refresh                          return CHANGE_PAGE; // force section list refresh
# Line 545  int section_list_display(const char *sna Line 558  int section_list_display(const char *sna
558          ARTICLE article_new;          ARTICLE article_new;
559          int page_id_cur;          int page_id_cur;
560          const ARTICLE *p_article_locate;          const ARTICLE *p_article_locate;
561            USER_INFO user_info;
562    
563          p_section = section_list_find_by_name(sname);          p_section = section_list_find_by_name(sname);
564          if (p_section == NULL)          if (p_section == NULL)
# Line 562  int section_list_display(const char *sna Line 576  int section_list_display(const char *sna
576    
577          section_index = get_section_index(p_section);          section_index = get_section_index(p_section);
578    
579          if ((ret = section_list_rd_lock(p_section)) < 0)          if (get_section_info(p_section, NULL, stitle, master_list) < 0)
         {  
                 log_error("section_list_rd_lock(sid = 0) error\n");  
                 return -2;  
         }  
   
         strncpy(stitle, p_section->stitle, sizeof(stitle) - 1);  
         stitle[sizeof(stitle) - 1] = '\0';  
         strncpy(master_list, p_section->master_list, sizeof(master_list) - 1);  
         master_list[sizeof(master_list) - 1] = '\0';  
   
         if ((ret = section_list_rd_unlock(p_section)) < 0)  
580          {          {
581                  log_error("section_list_rd_unlock(sid = 0) error\n");                  log_error("get_section_info(sid=%d) error\n", p_section->sid);
582                  return -2;                  return -4;
583          }          }
584    
585          if (aid == 0)          if (aid == 0)
# Line 658  int section_list_display(const char *sna Line 661  int section_list_display(const char *sna
661                  }                  }
662    
663                  ret = section_list_select(page_count, article_count, &page_id, &selected_index);                  ret = section_list_select(page_count, article_count, &page_id, &selected_index);
664    
665                    // Update current aid location
666                    section_aid_locations[section_index] = p_articles[selected_index]->aid;
667    
668                  switch (ret)                  switch (ret)
669                  {                  {
670                  case EXIT_SECTION:                  case EXIT_SECTION:
# Line 839  int section_list_display(const char *sna Line 846  int section_list_display(const char *sna
846                          // Update current topic                          // Update current topic
847                          section_topic_view_tid = (p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);                          section_topic_view_tid = (p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
848    
                         // Update current aid location  
                         section_aid_locations[section_index] = p_articles[selected_index]->aid;  
   
849                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
850                          {                          {
851                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error\n");
# Line 939  int section_list_display(const char *sna Line 943  int section_list_display(const char *sna
943                                  return -2;                                  return -2;
944                          }                          }
945                          break;                          break;
946                    case QUERY_USER:
947                            if ((ret = query_user_info_by_uid(p_articles[selected_index]->uid, &user_info)) < 0)
948                            {
949                                    log_error("query_user_info_by_uid(uid=%d) error\n", p_articles[selected_index]->uid);
950                                    return -2;
951                            }
952                            else if (ret == 0)
953                            {
954                                    clearscr();
955                                    prints("该用户已升天");
956                                    press_any_key();
957                            }
958                            else if (user_info_display(&user_info) < 0) // && ret > 0
959                            {
960                                    log_error("user_info_display(uid=%d) error\n", p_articles[selected_index]->uid);
961                            }
962    
963                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
964                            {
965                                    log_error("section_list_draw_screen() error\n");
966                                    return -2;
967                            }
968                            break;
969                  case SET_FAVOR_ARTICLE:                  case SET_FAVOR_ARTICLE:
970                          ret = article_favor_set(p_articles[selected_index]->tid == 0                          ret = article_favor_set(p_articles[selected_index]->tid == 0
971                                                                                  ? p_articles[selected_index]->aid                                                                                  ? p_articles[selected_index]->aid
# Line 1090  int section_list_ex_dir_display(SECTION_ Line 1117  int section_list_ex_dir_display(SECTION_
1117                  {                  {
1118                          iflush();                          iflush();
1119                          ch = igetch(100);                          ch = igetch(100);
1120    
1121                            if (ch != KEY_NULL && ch != KEY_TIMEOUT)
1122                            {
1123                                    BBS_last_access_tm = time(NULL);
1124                            }
1125    
1126                          switch (ch)                          switch (ch)
1127                          {                          {
1128                          case KEY_NULL: // broken pipe                          case KEY_NULL: // broken pipe
1129                                    log_error("KEY_NULL\n");
1130                                  return 0;                                  return 0;
1131                          case KEY_TIMEOUT:                          case KEY_TIMEOUT:
1132                                  if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)                                  if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)
1133                                  {                                  {
1134                                            log_error("User input timeout\n");
1135                                          return 0;                                          return 0;
1136                                  }                                  }
1137                                  continue;                                  continue;
1138                          case CR:                          case CR:
                                 igetch_reset();  
1139                          default:                          default:
1140                                  switch (menu_control(&ex_menu_set, ch))                                  switch (menu_control(&ex_menu_set, ch))
1141                                  {                                  {
# Line 1120  int section_list_ex_dir_display(SECTION_ Line 1154  int section_list_ex_dir_display(SECTION_
1154                                  }                                  }
1155                          }                          }
1156    
                         BBS_last_access_tm = time(NULL);  
   
1157                          if (ch == EXITMENU)                          if (ch == EXITMENU)
1158                          {                          {
1159                                  break;                                  break;
# Line 1133  int section_list_ex_dir_display(SECTION_ Line 1165  int section_list_ex_dir_display(SECTION_
1165    
1166          return 0;          return 0;
1167  }  }
1168    
1169    int section_aid_locations_save(int uid)
1170    {
1171            char filename[FILE_PATH_LEN];
1172            FILE *fp;
1173            int i;
1174            int ret = 0;
1175    
1176            snprintf(filename, sizeof(filename), "%s/%d", VAR_SECTION_AID_LOC_DIR, uid);
1177    
1178            if ((fp = fopen(filename, "wb")) == NULL)
1179            {
1180                    log_error("fopen(%s, wb) error: %d\n", filename, errno);
1181                    return -1;
1182            }
1183    
1184            for (i = 0; i < p_section_list_pool->section_count; i++)
1185            {
1186                    if (fwrite(&(p_section_list_pool->sections[i].sid), sizeof(p_section_list_pool->sections[i].sid), 1, fp) != 1)
1187                    {
1188                            log_error("fwrite(%s, sid) error\n", filename);
1189                            ret = -2;
1190                            break;
1191                    }
1192    
1193                    if (fwrite(&(section_aid_locations[i]), sizeof(section_aid_locations[i]), 1, fp) != 1)
1194                    {
1195                            log_error("fwrite(%s, aid) error\n", filename);
1196                            ret = -2;
1197                            break;
1198                    }
1199            }
1200    
1201            if (fclose(fp) < 0)
1202            {
1203                    log_error("fclose(%s) error: %d\n", filename, errno);
1204                    ret = -1;
1205            }
1206    
1207            return ret;
1208    }
1209    
1210    int section_aid_locations_load(int uid)
1211    {
1212            char filename[FILE_PATH_LEN];
1213            FILE *fp;
1214            int i;
1215            int32_t sid;
1216            int32_t aid;
1217            SECTION_LIST *p_section;
1218            int ret = 0;
1219    
1220            snprintf(filename, sizeof(filename), "%s/%d", VAR_SECTION_AID_LOC_DIR, uid);
1221    
1222            if ((fp = fopen(filename, "rb")) == NULL)
1223            {
1224                    if (errno == ENOENT) // file not exist
1225                    {
1226                            return 0;
1227                    }
1228                    log_error("fopen(%s, rb) error: %d\n", filename, errno);
1229                    return -1;
1230            }
1231    
1232            while (!feof(fp))
1233            {
1234                    if (fread(&sid, sizeof(sid), 1, fp) != 1)
1235                    {
1236                            if (ferror(fp) == 0)
1237                            {
1238                                    break;
1239                            }
1240                            log_error("fread(%s, sid) error: %d\n", filename, ferror(fp));
1241                            ret = -2;
1242                            break;
1243                    }
1244    
1245                    if (fread(&aid, sizeof(aid), 1, fp) != 1)
1246                    {
1247                            if (ferror(fp) == 0)
1248                            {
1249                                    break;
1250                            }
1251                            log_error("fread(%s, aid) error: %d\n", filename, ferror(fp));
1252                            ret = -2;
1253                            break;
1254                    }
1255    
1256                    p_section = section_list_find_by_sid(sid);
1257                    if (p_section == NULL)
1258                    {
1259                            continue; // skip section no longer exist
1260                    }
1261    
1262                    i = get_section_index(p_section);
1263                    if (i < 0)
1264                    {
1265                            log_error("get_section_index(sid=%d) error\n", sid);
1266                            ret = -3;
1267                            break;
1268                    }
1269                    section_aid_locations[i] = aid;
1270            }
1271    
1272            if (fclose(fp) < 0)
1273            {
1274                    log_error("fclose(%s) error: %d\n", filename, errno);
1275                    ret = -1;
1276            }
1277    
1278            return ret;
1279    }


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

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