/[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.37 by sysadm, Tue Jun 24 10:01:24 2025 UTC Revision 1.57 by sysadm, Sat Oct 25 13:09:42 2025 UTC
# Line 15  Line 15 
15   ***************************************************************************/   ***************************************************************************/
16    
17  #include "article_cache.h"  #include "article_cache.h"
18    #include "article_favor.h"
19    #include "article_op.h"
20  #include "article_post.h"  #include "article_post.h"
21  #include "article_view_log.h"  #include "article_view_log.h"
22  #include "article_del.h"  #include "article_del.h"
# Line 23  Line 25 
25  #include "log.h"  #include "log.h"
26  #include "login.h"  #include "login.h"
27  #include "menu.h"  #include "menu.h"
28    #include "menu_proc.h"
29  #include "section_list_display.h"  #include "section_list_display.h"
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 <string.h>  #include <string.h>
36  #include <time.h>  #include <time.h>
37  #include <sys/param.h>  #include <sys/param.h>
38    
39    static int section_aid_locations[BBS_max_section] = {0};
40  static int section_topic_view_mode = 0;  static int section_topic_view_mode = 0;
41  static int section_topic_view_tid = -1;  static int section_topic_view_tid = -1;
42    
43  enum select_cmd_t  enum select_cmd_t
44  {  {
45          EXIT_SECTION = 0,          EXIT_SECTION = 0,
46          VIEW_ARTICLE = 1,          VIEW_ARTICLE,
47          CHANGE_PAGE = 2,          CHANGE_PAGE,
48          SHOW_HELP = 3,          SHOW_HELP,
49          CHANGE_NAME_DISPLAY = 4,          CHANGE_NAME_DISPLAY,
50          POST_ARTICLE = 5,          POST_ARTICLE,
51          EDIT_ARTICLE = 6,          EDIT_ARTICLE,
52          DELETE_ARTICLE = 7,          DELETE_ARTICLE,
53          FIRST_TOPIC_ARTICLE = 8,          QUERY_ARTICLE,
54          LAST_TOPIC_ARTICLE = 9,          QUERY_USER,
55          VIEW_EX_DIR = 10,          SET_FAVOR_ARTICLE,
56            UNSET_FAVOR_ARTICLE,
57            FIRST_TOPIC_ARTICLE,
58            LAST_TOPIC_ARTICLE,
59            SCAN_NEW_ARTICLE,
60            VIEW_EX_DIR,
61            SHOW_TOP10,
62  };  };
63    
64  static int section_list_draw_items(int page_id, ARTICLE *p_articles[], int article_count, int display_nickname, int ontop_start_offset)  static int section_list_draw_items(int page_id, ARTICLE *p_articles[], int article_count, int display_nickname, int ontop_start_offset)
# Line 59  static int section_list_draw_items(int p Line 70  static int section_list_draw_items(int p
70          int eol;          int eol;
71          int len;          int len;
72          int i;          int i;
73            size_t j;
74          char article_flag;          char article_flag;
75          int is_viewed;          int is_viewed;
76            int is_favor;
77          time_t tm_now;          time_t tm_now;
78    
79          time(&tm_now);          time(&tm_now);
# Line 83  static int section_list_draw_items(int p Line 96  static int section_list_draw_items(int p
96                          }                          }
97                  }                  }
98    
99                    if (p_articles[i]->tid == 0)
100                    {
101                            is_favor = article_favor_check(p_articles[i]->aid, &BBS_article_favor);
102                            if (is_favor < 0)
103                            {
104                                    log_error("article_favor_check(aid=%d) error\n", p_articles[i]->aid);
105                                    is_favor = 0;
106                            }
107                    }
108                    else
109                    {
110                            is_favor = 0;
111                    }
112    
113                  if (p_articles[i]->excerption)                  if (p_articles[i]->excerption)
114                  {                  {
115                          article_flag = (is_viewed ? 'm' : 'M');                          article_flag = (is_viewed ? 'm' : 'M');
# Line 106  static int section_list_draw_items(int p Line 133  static int section_list_draw_items(int p
133                          strftime(str_time, sizeof(str_time), "%m/%Y", &tm_sub);                          strftime(str_time, sizeof(str_time), "%m/%Y", &tm_sub);
134                  }                  }
135    
136                  strncpy(title_f, (p_articles[i]->tid == 0 ? " " : ""), sizeof(title_f) - 1);                  strncpy(title_f, (p_articles[i]->tid == 0 ? "● " : ""), sizeof(title_f) - 1);
137                  title_f[sizeof(title_f) - 1] = '\0';                  title_f[sizeof(title_f) - 1] = '\0';
138                  strncat(title_f, (p_articles[i]->transship ? "[ת]" : ""), sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));                  strncat(title_f, (p_articles[i]->transship ? "[转载]" : ""), sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));
139                  strncat(title_f, p_articles[i]->title, sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));  
140                  len = split_line(title_f, 47 - (display_nickname ? 8 : 0), &eol, &title_f_len, 1);                  // Rewrite title with "Re: Re: " prefix into "Re: ... "
141                    j = 0;
142                    if (p_articles[i]->tid != 0)
143                    {
144                            while (strncmp(p_articles[i]->title + j, "Re: ", strlen("Re: ")) == 0)
145                            {
146                                    j += strlen("Re: ");
147                            }
148                            if (j >= strlen("Re: Re: "))
149                            {
150                                    strncat(title_f, "Re: ... ", sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));
151                            }
152                            else
153                            {
154                                    j = 0;
155                            }
156                    }
157                    strncat(title_f, p_articles[i]->title + j, sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));
158    
159                    len = split_line(title_f, 59 - (display_nickname ? BBS_nickname_max_len / 2 : BBS_username_max_len), &eol, &title_f_len, 1);
160                  if (title_f[len] != '\0')                  if (title_f[len] != '\0')
161                  {                  {
162                          title_f[len] = '\0';                          title_f[len] = '\0';
# Line 119  static int section_list_draw_items(int p Line 165  static int section_list_draw_items(int p
165                  moveto(4 + i, 1);                  moveto(4 + i, 1);
166                  if (i >= ontop_start_offset)                  if (i >= ontop_start_offset)
167                  {                  {
168                          prints("   \033[1;33m[ʾ]\033[m %c %s%*s %s %s%s\033[m",                          prints("   \033[1;33m[提示]\033[m%c%c %s%*s %s %s%s\033[m",
169                                       (is_favor ? '@' : ' '),
170                                     article_flag,                                     article_flag,
171                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),
172                                     (display_nickname ? BBS_nickname_max_len - (int)strnlen(p_articles[i]->nickname, sizeof(p_articles[i]->nickname))                                     (display_nickname ? BBS_nickname_max_len / 2 - str_length(p_articles[i]->nickname, 1)
173                                                                           : BBS_username_max_len - (int)strnlen(p_articles[i]->username, sizeof(p_articles[i]->username))),                                                                           : BBS_username_max_len - str_length(p_articles[i]->username, 1)),
174                                     "",                                     "",
175                                     str_time,                                     str_time,
176                                     (p_articles[i]->aid == section_topic_view_tid                                     (p_articles[i]->aid == section_topic_view_tid
# Line 135  static int section_list_draw_items(int p Line 182  static int section_list_draw_items(int p
182                  }                  }
183                  else                  else
184                  {                  {
185                          prints("  %s%7d\033[m %c %s%*s %s %s%s\033[m",                          prints("  %s%7d\033[m%c%c %s%*s %s %s%s\033[m",
186                                     (p_articles[i]->aid == section_topic_view_tid                                     (p_articles[i]->aid == section_topic_view_tid
187                                                  ? "\033[1;33m"                                                  ? "\033[1;33m"
188                                                  : (p_articles[i]->tid == section_topic_view_tid                                                  : (p_articles[i]->tid == section_topic_view_tid
189                                                             ? "\033[1;36m"                                                             ? "\033[1;36m"
190                                                             : "")),                                                             : "")),
191                                     p_articles[i]->aid,                                     p_articles[i]->aid,
192                                       (is_favor ? '@' : ' '),
193                                     article_flag,                                     article_flag,
194                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),                                     (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),
195                                     (display_nickname ? BBS_nickname_max_len - (int)strnlen(p_articles[i]->nickname, sizeof(p_articles[i]->nickname))                                     (display_nickname ? BBS_nickname_max_len / 2 - str_length(p_articles[i]->nickname, 1)
196                                                                           : BBS_username_max_len - (int)strnlen(p_articles[i]->username, sizeof(p_articles[i]->username))),                                                                           : BBS_username_max_len - str_length(p_articles[i]->username, 1)),
197                                     "",                                     "",
198                                     str_time,                                     str_time,
199                                     (p_articles[i]->aid == section_topic_view_tid                                     (p_articles[i]->aid == section_topic_view_tid
# Line 162  static int section_list_draw_items(int p Line 210  static int section_list_draw_items(int p
210    
211  static int section_list_draw_screen(const char *sname, const char *stitle, const char *master_list, int display_nickname)  static int section_list_draw_screen(const char *sname, const char *stitle, const char *master_list, int display_nickname)
212  {  {
213          char str_section_master[LINE_BUFFER_LEN] = "";          char str_section_master[LINE_BUFFER_LEN] = "诚征版主中";
214          char str_section_name[LINE_BUFFER_LEN];          char str_section_name[LINE_BUFFER_LEN];
215    
216          if (master_list[0] != '\0')          if (master_list[0] != '\0')
217          {          {
218                  snprintf(str_section_master, sizeof(str_section_master), "%s", master_list);                  snprintf(str_section_master, sizeof(str_section_master), "版主:%s", master_list);
219          }          }
220          snprintf(str_section_name, sizeof(str_section_name), " [%s]", sname);          snprintf(str_section_name, sizeof(str_section_name), "讨论区 [%s]", sname);
221    
222          clearscr();          clearscr();
223          show_top(str_section_master, stitle, str_section_name);          show_top(str_section_master, stitle, str_section_name);
224          moveto(2, 0);          moveto(2, 0);
225          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] "
226                     "Ķ[\033[1;32m\033[0;37m,\033[1;32mENTER\033[0;37m] [\033[1;32mCtrl-P\033[0;37m] "                     "阅读[\033[1;32m→\033[0;37m,\033[1;32mENTER\033[0;37m] 发表[\033[1;32mCtrl-P\033[0;37m] "
227                     "%s[\033[1;32mn\033[0;37m] [\033[1;32mx\033[0;37m] [\033[1;32mh\033[0;37m]\033[m",                     "%s[\033[1;32mn\033[0;37m] 精华区[\033[1;32mx\033[0;37m] 帮助[\033[1;32mh\033[0;37m]\033[m",
228                     (display_nickname ? "û" : "dz"));                     (display_nickname ? "用户名" : "昵称"));
229          moveto(3, 0);          moveto(3, 0);
230          if (display_nickname)          if (display_nickname)
231          {          {
232                  prints("\033[44;37m  \033[1;37m     dz              ±                               \033[m");                  prints("\033[44;37m  \033[1;37m 编  号   发布者昵称           日  期  文章标题                               \033[m");
233          }          }
234          else          else
235          {          {
236                  prints("\033[44;37m  \033[1;37m            ±                                       \033[m");                  prints("\033[44;37m  \033[1;37m 编  号   发 布 者     日  期  文章标题                                       \033[m");
237          }          }
238    
239          return 0;          return 0;
# Line 209  static enum select_cmd_t section_list_se Line 257  static enum select_cmd_t section_list_se
257          {          {
258                  ch = igetch(100);                  ch = igetch(100);
259    
260                  switch (ch)                  if (ch != KEY_NULL && ch != KEY_TIMEOUT)
261                  {                  {
                 case KEY_ESC:  
                 case KEY_LEFT:  
262                          BBS_last_access_tm = time(NULL);                          BBS_last_access_tm = time(NULL);
263                  case KEY_NULL:                   // broken pipe                  }
264                          return EXIT_SECTION; // exit section  
265                    switch (ch)
266                    {
267                    case KEY_NULL: // broken pipe
268                            log_error("KEY_NULL\n");
269                            return EXIT_SECTION;
270                  case KEY_TIMEOUT:                  case KEY_TIMEOUT:
271                          if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)                          if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)
272                          {                          {
273                                  return EXIT_SECTION; // exit section                                  log_error("User input timeout\n");
274                                    return EXIT_SECTION;
275                          }                          }
276                          continue;                          continue;
277                    case KEY_ESC:
278                    case KEY_LEFT:
279                            return EXIT_SECTION;
280                  case 'n':                  case 'n':
                         BBS_last_access_tm = time(NULL);  
281                          return CHANGE_NAME_DISPLAY;                          return CHANGE_NAME_DISPLAY;
282                  case CR:                  case CR:
                         igetch_reset();  
283                  case 'r':                  case 'r':
284                  case KEY_RIGHT:                  case KEY_RIGHT:
285                          if (item_count > 0)                          if (item_count > 0)
286                          {                          {
                                 BBS_last_access_tm = time(NULL);  
287                                  return VIEW_ARTICLE;                                  return VIEW_ARTICLE;
288                          }                          }
289                          break;                          break;
290                  case Ctrl('P'):                  case Ctrl('P'):
291                          return POST_ARTICLE;                          return POST_ARTICLE;
292                  case 'E':                  case 'E':
293                          return EDIT_ARTICLE;                          if (item_count > 0)
294                            {
295                                    return EDIT_ARTICLE;
296                            }
297                            break;
298                  case 'd':                  case 'd':
299                          return DELETE_ARTICLE;                          if (item_count > 0)
300                            {
301                                    return DELETE_ARTICLE;
302                            }
303                            break;
304                    case Ctrl('Q'):
305                            if (item_count > 0)
306                            {
307                                    return QUERY_ARTICLE;
308                            }
309                            break;
310                    case Ctrl('A'):
311                            if (item_count > 0)
312                            {
313                                    return QUERY_USER;
314                            }
315                            break;
316                    case 'F':
317                            if (item_count > 0)
318                            {
319                                    return SET_FAVOR_ARTICLE;
320                            }
321                            break;
322                    case '-':
323                            if (item_count > 0)
324                            {
325                                    return UNSET_FAVOR_ARTICLE;
326                            }
327                            break;
328                  case KEY_HOME:                  case KEY_HOME:
329                          *p_page_id = 0;                          *p_page_id = 0;
330                  case 'P':                  case 'P':
# Line 255  static enum select_cmd_t section_list_se Line 339  static enum select_cmd_t section_list_se
339                                          (*p_page_id)--;                                          (*p_page_id)--;
340                                          *p_selected_index = BBS_article_limit_per_page - 1;                                          *p_selected_index = BBS_article_limit_per_page - 1;
341                                  }                                  }
342                                    else if (ch == KEY_UP || ch == 'k') // Rotate to the tail of section list
343                                    {
344                                            if (total_page > 0)
345                                            {
346                                                    *p_page_id = total_page - 1;
347                                            }
348                                            if (item_count > 0)
349                                            {
350                                                    *p_selected_index = item_count - 1;
351                                            }
352                                    }
353                          }                          }
354                          else                          else
355                          {                          {
# Line 282  static enum select_cmd_t section_list_se Line 377  static enum select_cmd_t section_list_se
377                                          (*p_page_id)++;                                          (*p_page_id)++;
378                                          *p_selected_index = 0;                                          *p_selected_index = 0;
379                                  }                                  }
380                                  else // end of last page                                  else if (ch == KEY_DOWN || ch == 'j') // Rotate to the head of section list
381                                  {                                  {
382                                          return CHANGE_PAGE; // force refresh pages                                          *p_page_id = 0;
383                                            *p_selected_index = 0;
384                                  }                                  }
385                          }                          }
386                          else                          else
# Line 293  static enum select_cmd_t section_list_se Line 389  static enum select_cmd_t section_list_se
389                          }                          }
390                          break;                          break;
391                  case '=':                  case '=':
392                          return FIRST_TOPIC_ARTICLE;                          if (item_count > 0)
393                            {
394                                    return FIRST_TOPIC_ARTICLE;
395                            }
396                            break;
397                  case '\\':                  case '\\':
398                          return LAST_TOPIC_ARTICLE;                          if (item_count > 0)
399                            {
400                                    return LAST_TOPIC_ARTICLE;
401                            }
402                            break;
403                    case 'S':
404                            if (item_count > 0)
405                            {
406                                    return SCAN_NEW_ARTICLE;
407                            }
408                            break;
409                  case 'h':                  case 'h':
410                          return SHOW_HELP;                          return SHOW_HELP;
411                  case 'x':                  case 'x':
412                          return VIEW_EX_DIR;                          return VIEW_EX_DIR;
413                    case 'H':
414                            return SHOW_TOP10;
415                  default:                  default:
416                            break;
417                  }                  }
418    
419                  if (old_page_id != *p_page_id)                  if (old_page_id != *p_page_id)
# Line 325  static enum select_cmd_t section_list_se Line 438  static enum select_cmd_t section_list_se
438                          old_selected_index = *p_selected_index;                          old_selected_index = *p_selected_index;
439                  }                  }
440    
                 BBS_last_access_tm = time(NULL);  
441                  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)
442                  {                  {
443                          return CHANGE_PAGE; // force section list refresh                          return CHANGE_PAGE; // force section list refresh
# Line 346  static int display_article_key_handler(i Line 458  static int display_article_key_handler(i
458                  if (section_topic_view_mode)                  if (section_topic_view_mode)
459                  {                  {
460                          snprintf(p_ctx->msg, sizeof(p_ctx->msg),                          snprintf(p_ctx->msg, sizeof(p_ctx->msg),
461                                           "| [\033[32m\033[33m,\033[32mESC\033[33m] "                                           "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] "
462                                           "ͬĶ[\033[32m\033[33m/\033[32m\033[33m] "                                           "同主题阅读[\033[32m↑\033[33m/\033[32m↓\033[33m] "
463                                           "л[\033[32mp\033[33m] ظ[\033[32mr\033[33m] [\033[32mh\033[33m] |");                                           "切换[\033[32mp\033[33m] 回复[\033[32mr\033[33m] 帮助[\033[32mh\033[33m] |");
464                  }                  }
465                  else                  else
466                  {                  {
467                          snprintf(p_ctx->msg, sizeof(p_ctx->msg),                          snprintf(p_ctx->msg, sizeof(p_ctx->msg),
468                                           "| [\033[32m\033[33m,\033[32mESC\033[33m] "                                           "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] "
469                                           "ƶ[\033[32m\033[33m/\033[32m\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] "                                           "移动[\033[32m↑\033[33m/\033[32m↓\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] "
470                                           "л[\033[32mp\033[33m] ظ[\033[32mr\033[33m] [\033[32mh\033[33m] |");                                           "切换[\033[32mp\033[33m] 回复[\033[32mr\033[33m] 帮助[\033[32mh\033[33m] |");
471                  }                  }
472                  *p_key = 0;                  *p_key = 0;
473                  break;                  break;
# Line 422  static int display_article_key_handler(i Line 534  static int display_article_key_handler(i
534          return 0;          return 0;
535  }  }
536    
537  int section_list_display(const char *sname)  int section_list_display(const char *sname, int32_t aid)
538  {  {
539          static int display_nickname = 0;          static int display_nickname = 0;
540    
541          SECTION_LIST *p_section;          SECTION_LIST *p_section;
542            int64_t section_index;
543            int32_t aid_location;
544          char stitle[BBS_section_title_max_len + 1];          char stitle[BBS_section_title_max_len + 1];
545          char master_list[(BBS_username_max_len + 1) * 3 + 1];          char master_list[(BBS_username_max_len + 1) * 3 + 1];
546          char page_info_str[LINE_BUFFER_LEN];          char page_info_str[LINE_BUFFER_LEN];
# Line 442  int section_list_display(const char *sna Line 556  int section_list_display(const char *sna
556          int direction;          int direction;
557          ARTICLE article_new;          ARTICLE article_new;
558          int page_id_cur;          int page_id_cur;
559            const ARTICLE *p_article_locate;
560            USER_INFO user_info;
561    
562          p_section = section_list_find_by_name(sname);          p_section = section_list_find_by_name(sname);
563          if (p_section == NULL)          if (p_section == NULL)
# Line 450  int section_list_display(const char *sna Line 566  int section_list_display(const char *sna
566                  return -1;                  return -1;
567          }          }
568    
569            if (!checkpriv(&BBS_priv, p_section->sid, S_LIST))
570            {
571                    log_error("Forbid access to unauthorized section, sid=%d, uid=%d\n",
572                                      p_section->sid, BBS_priv.uid);
573                    return -1;
574            }
575    
576            section_index = get_section_index(p_section);
577    
578          if ((ret = section_list_rd_lock(p_section)) < 0)          if ((ret = section_list_rd_lock(p_section)) < 0)
579          {          {
580                  log_error("section_list_rd_lock(sid = 0) error\n");                  log_error("section_list_rd_lock(sid = 0) error\n");
# Line 467  int section_list_display(const char *sna Line 592  int section_list_display(const char *sna
592                  return -2;                  return -2;
593          }          }
594    
595            if (aid == 0)
596            {
597                    aid_location = section_aid_locations[section_index];
598            }
599            else
600            {
601                    aid_location = aid;
602            }
603    
604            // Locate at article with aid_locate
605            if (aid_location > 0)
606            {
607                    p_article_locate = article_block_find_by_aid(aid_location);
608                    if (p_article_locate == NULL)
609                    {
610                            log_error("article_block_find_by_aid(%d) error\n", aid_location);
611                            return -3;
612                    }
613    
614                    ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
615                                                                                    &page_id, &selected_index, &article_count);
616                    if (ret < 0)
617                    {
618                            log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
619                                              p_section->sid, p_article_locate->aid);
620                            return -3;
621                    }
622            }
623    
624          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
625          {          {
626                  log_error("section_list_draw_screen() error\n");                  log_error("section_list_draw_screen() error\n");
# Line 480  int section_list_display(const char *sna Line 634  int section_list_display(const char *sna
634                  return -3;                  return -3;
635          }          }
636    
637            section_topic_view_tid = -1;
638    
639          if (article_count == 0) // empty section          if (article_count == 0) // empty section
640          {          {
641                  selected_index = 0;                  selected_index = 0;
642          }          }
643            else if (aid > 0)
644            {
645                    // Update current topic
646                    section_topic_view_tid = (p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
647    
648                    // Update current aid location
649                    section_aid_locations[section_index] = p_articles[selected_index]->aid;
650            }
651    
652          while (!SYS_server_exit)          while (!SYS_server_exit)
653          {          {
# Line 495  int section_list_display(const char *sna Line 659  int section_list_display(const char *sna
659                  }                  }
660    
661                  snprintf(page_info_str, sizeof(page_info_str),                  snprintf(page_info_str, sizeof(page_info_str),
662                                   "\033[33m[\033[36m%d\033[33m/\033[36m%d\033[33mҳ]",                                   "\033[33m[第\033[36m%d\033[33m/\033[36m%d\033[33m页]",
663                                   page_id + 1, MAX(page_count, 1));                                   page_id + 1, MAX(page_count, 1));
664    
665                  show_bottom(page_info_str);                  show_bottom(page_info_str);
# Line 688  int section_list_display(const char *sna Line 852  int section_list_display(const char *sna
852                          // Update current topic                          // Update current topic
853                          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);
854    
855                            // Update current aid location
856                            section_aid_locations[section_index] = p_articles[selected_index]->aid;
857    
858                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)                          if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
859                          {                          {
860                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error\n");
# Line 774  int section_list_display(const char *sna Line 941  int section_list_display(const char *sna
941                                  return -2;                                  return -2;
942                          }                          }
943                          break;                          break;
944                    case QUERY_ARTICLE:
945                            if ((ret = display_article_meta(p_articles[selected_index]->aid)) < 0)
946                            {
947                                    log_error("display_article_meta(aid=%d) error\n", p_articles[selected_index]->aid);
948                            }
949                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
950                            {
951                                    log_error("section_list_draw_screen() error\n");
952                                    return -2;
953                            }
954                            break;
955                    case QUERY_USER:
956                            if ((ret = query_user_info_by_uid(p_articles[selected_index]->uid, &user_info)) < 0)
957                            {
958                                    log_error("query_user_info_by_uid(uid=%d) error\n", p_articles[selected_index]->uid);
959                                    return -2;
960                            }
961                            else if (ret == 0)
962                            {
963                                    clearscr();
964                                    prints("该用户已升天");
965                                    press_any_key();
966                            }
967                            else if (user_info_display(&user_info) < 0) // && ret > 0
968                            {
969                                    log_error("user_info_display(uid=%d) error\n", p_articles[selected_index]->uid);
970                            }
971    
972                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
973                            {
974                                    log_error("section_list_draw_screen() error\n");
975                                    return -2;
976                            }
977                            break;
978                    case SET_FAVOR_ARTICLE:
979                            ret = article_favor_set(p_articles[selected_index]->tid == 0
980                                                                                    ? p_articles[selected_index]->aid
981                                                                                    : p_articles[selected_index]->tid,
982                                                                            &BBS_article_favor, 1);
983                            if (ret < 0)
984                            {
985                                    log_error("article_favor_set(aid=%d, 1) error\n",
986                                                      p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
987                            }
988                            break;
989                    case UNSET_FAVOR_ARTICLE:
990                            ret = article_favor_set(p_articles[selected_index]->tid == 0
991                                                                                    ? p_articles[selected_index]->aid
992                                                                                    : p_articles[selected_index]->tid,
993                                                                            &BBS_article_favor, 0);
994                            if (ret < 0)
995                            {
996                                    log_error("article_favor_set(aid=%d, 0) error\n",
997                                                      p_articles[selected_index]->tid == 0 ? p_articles[selected_index]->aid : p_articles[selected_index]->tid);
998                            }
999                            break;
1000                  case FIRST_TOPIC_ARTICLE:                  case FIRST_TOPIC_ARTICLE:
1001                  case LAST_TOPIC_ARTICLE:                  case LAST_TOPIC_ARTICLE:
1002                          page_id_cur = page_id;                          page_id_cur = page_id;
# Line 796  int section_list_display(const char *sna Line 1019  int section_list_display(const char *sna
1019                                  }                                  }
1020                          }                          }
1021                          break;                          break;
1022                    case SCAN_NEW_ARTICLE:
1023                            ret = scan_unread_article_in_section(p_section, p_articles[selected_index], &p_article_locate);
1024                            if (ret < 0)
1025                            {
1026                                    log_error("scan_unread_article_in_section(sid=%d, aid=%d) error\n",
1027                                                      p_section->sid, p_articles[selected_index]->aid);
1028                                    return -3;
1029                            }
1030                            else if (ret == 0) // not found
1031                            {
1032                                    break;
1033                            }
1034                            page_id_cur = page_id;
1035                            ret = locate_article_in_section(p_section, p_article_locate, 0, 0,
1036                                                                                            &page_id, &selected_index, &article_count);
1037                            if (ret < 0)
1038                            {
1039                                    log_error("locate_article_in_section(sid=%d, aid=%d, direction=0, step=0) error\n",
1040                                                      p_section->sid, p_article_locate->aid);
1041                                    return -3;
1042                            }
1043                            else if (ret > 0 && page_id != page_id_cur) // found and page changed
1044                            {
1045                                    ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count, &ontop_start_offset);
1046                                    if (ret < 0)
1047                                    {
1048                                            log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id);
1049                                            return -3;
1050                                    }
1051                            }
1052                            break;
1053                  case SHOW_HELP:                  case SHOW_HELP:
1054                          // Display help information                          // Display help information
1055                          display_file(DATA_READ_HELP, 1);                          display_file(DATA_READ_HELP, 1);
# Line 816  int section_list_display(const char *sna Line 1070  int section_list_display(const char *sna
1070                                  return -2;                                  return -2;
1071                          }                          }
1072                          break;                          break;
1073                    case SHOW_TOP10:
1074                            show_top10_menu(NULL);
1075                            if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0)
1076                            {
1077                                    log_error("section_list_draw_screen() error\n");
1078                                    return -2;
1079                            }
1080                            break;
1081                  default:                  default:
1082                          log_error("Unknown command %d\n", ret);                          log_error("Unknown command %d\n", ret);
1083                  }                  }
# Line 826  int section_list_display(const char *sna Line 1088  int section_list_display(const char *sna
1088    
1089  int section_list_ex_dir_display(SECTION_LIST *p_section)  int section_list_ex_dir_display(SECTION_LIST *p_section)
1090  {  {
         char str_section_name[LINE_BUFFER_LEN];  
1091          MENU_SET ex_menu_set;          MENU_SET ex_menu_set;
1092          int ch = 0;          int ch = 0;
1093    
# Line 836  int section_list_ex_dir_display(SECTION_ Line 1097  int section_list_ex_dir_display(SECTION_
1097                  return -1;                  return -1;
1098          }          }
1099    
1100            if (p_section->ex_menu_tm == 0) // N/A
1101            {
1102                    moveto(2, 1);
1103                    clrtoeol();
1104                    prints("该版块精华区未开放");
1105                    press_any_key();
1106                    return 0;
1107            }
1108    
1109          if (get_section_ex_menu_set(p_section, &ex_menu_set) < 0)          if (get_section_ex_menu_set(p_section, &ex_menu_set) < 0)
1110          {          {
1111                  log_error("get_section_ex_menu_set(sid=%d) error\n", p_section->sid);                  log_error("get_section_ex_menu_set(sid=%d) error\n", p_section->sid);
# Line 843  int section_list_ex_dir_display(SECTION_ Line 1113  int section_list_ex_dir_display(SECTION_
1113          }          }
1114          if (get_menu_shm_readonly(&ex_menu_set) < 0)          if (get_menu_shm_readonly(&ex_menu_set) < 0)
1115          {          {
1116                  log_error("set_menu_shm_readonly(sid=%d) error\n", p_section->sid);                  log_error("get_menu_shm_readonly(sid=%d) error\n", p_section->sid);
1117                  return -3;                  return -3;
1118          }          }
1119    
         snprintf(str_section_name, sizeof(str_section_name), "[%s | ]", p_section->sname);  
   
1120          clearscr();          clearscr();
1121          show_bottom(str_section_name);          show_bottom("");
1122    
1123          if (display_menu(&ex_menu_set) == 0)          if (display_menu(&ex_menu_set) == 0)
1124          {          {
# Line 858  int section_list_ex_dir_display(SECTION_ Line 1126  int section_list_ex_dir_display(SECTION_
1126                  {                  {
1127                          iflush();                          iflush();
1128                          ch = igetch(100);                          ch = igetch(100);
1129    
1130                            if (ch != KEY_NULL && ch != KEY_TIMEOUT)
1131                            {
1132                                    BBS_last_access_tm = time(NULL);
1133                            }
1134    
1135                          switch (ch)                          switch (ch)
1136                          {                          {
1137                          case KEY_NULL: // broken pipe                          case KEY_NULL: // broken pipe
1138                                    log_error("KEY_NULL\n");
1139                                  return 0;                                  return 0;
1140                          case KEY_TIMEOUT:                          case KEY_TIMEOUT:
1141                                  if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)                                  if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME)
1142                                  {                                  {
1143                                            log_error("User input timeout\n");
1144                                          return 0;                                          return 0;
1145                                  }                                  }
1146                                  continue;                                  continue;
1147                          case CR:                          case CR:
                                 igetch_reset();  
1148                          default:                          default:
1149                                  switch (menu_control(&ex_menu_set, ch))                                  switch (menu_control(&ex_menu_set, ch))
1150                                  {                                  {
# Line 878  int section_list_ex_dir_display(SECTION_ Line 1153  int section_list_ex_dir_display(SECTION_
1153                                          break;                                          break;
1154                                  case REDRAW:                                  case REDRAW:
1155                                          clearscr();                                          clearscr();
1156                                          show_bottom(str_section_name);                                          show_bottom("");
1157                                          display_menu(&ex_menu_set);                                          display_menu(&ex_menu_set);
1158                                          break;                                          break;
1159                                  case NOREDRAW:                                  case NOREDRAW:
# Line 888  int section_list_ex_dir_display(SECTION_ Line 1163  int section_list_ex_dir_display(SECTION_
1163                                  }                                  }
1164                          }                          }
1165    
                         BBS_last_access_tm = time(NULL);  
   
1166                          if (ch == EXITMENU)                          if (ch == EXITMENU)
1167                          {                          {
1168                                  break;                                  break;


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

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