| 6 |
* Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com> |
* Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com> |
| 7 |
*/ |
*/ |
| 8 |
|
|
| 9 |
|
#ifdef HAVE_CONFIG_H |
| 10 |
|
#include "config.h" |
| 11 |
|
#endif |
| 12 |
|
|
| 13 |
#include "article_favor.h" |
#include "article_favor.h" |
| 14 |
#include "article_view_log.h" |
#include "article_view_log.h" |
| 15 |
#include "bbs.h" |
#include "bbs.h" |
| 16 |
#include "bbs_cmd.h" |
#include "bbs_cmd.h" |
| 17 |
#include "bbs_main.h" |
#include "bbs_main.h" |
| 18 |
|
#include "bwf.h" |
| 19 |
#include "common.h" |
#include "common.h" |
| 20 |
#include "database.h" |
#include "database.h" |
| 21 |
#include "editor.h" |
#include "editor.h" |
| 26 |
#include "screen.h" |
#include "screen.h" |
| 27 |
#include "section_list.h" |
#include "section_list.h" |
| 28 |
#include "section_list_display.h" |
#include "section_list_display.h" |
| 29 |
|
#include "str_process.h" |
| 30 |
#include "trie_dict.h" |
#include "trie_dict.h" |
| 31 |
#include "user_list.h" |
#include "user_list.h" |
| 32 |
#include "user_priv.h" |
#include "user_priv.h" |
| 33 |
|
#include <ctype.h> |
| 34 |
#include <errno.h> |
#include <errno.h> |
| 35 |
#include <signal.h> |
#include <signal.h> |
| 36 |
#include <stdlib.h> |
#include <stdlib.h> |
| 38 |
#include <time.h> |
#include <time.h> |
| 39 |
#include <unistd.h> |
#include <unistd.h> |
| 40 |
|
|
| 41 |
|
static void child_proc_sig_usr1_handler(int i) |
| 42 |
|
{ |
| 43 |
|
// Restart log |
| 44 |
|
if (log_restart() < 0) |
| 45 |
|
{ |
| 46 |
|
log_error("Restart logging failed\n"); |
| 47 |
|
} |
| 48 |
|
} |
| 49 |
|
|
| 50 |
int bbs_info() |
int bbs_info() |
| 51 |
{ |
{ |
| 52 |
prints("欢迎光临 \033[1;33m%s \033[32m[%s] \033[37m( %s )\033[m\r\n", |
prints("\r\n欢迎光临 \033[1;33m%s \033[32m[%s] \033[37m(%s)\033[m\r\n", |
| 53 |
BBS_name, BBS_server, APP_INFO); |
BBS_name, BBS_server, APP_INFO); |
| 54 |
|
|
| 55 |
return iflush(); |
return iflush(); |
| 94 |
"\033[32m目前上站人数 [\033[36m%d/%d\033[32m] " |
"\033[32m目前上站人数 [\033[36m%d/%d\033[32m] " |
| 95 |
"匿名游客[\033[36m%d\033[32m] " |
"匿名游客[\033[36m%d\033[32m] " |
| 96 |
"注册用户数[\033[36m%d/%d\033[32m]\r\n" |
"注册用户数[\033[36m%d/%d\033[32m]\r\n" |
| 97 |
"从 [\033[36m%s\033[32m] 起,累计访问人次:[\033[36m%d\033[32m]\033[m\r\n", |
"从 [\033[36m%s\033[32m] 起,累计访问人次: [\033[36m%d\033[32m]\033[m\r\n", |
| 98 |
BBS_name, u_online, BBS_max_client, u_anonymous, u_total, |
BBS_name, u_online, BBS_max_client, u_anonymous, u_total, |
| 99 |
BBS_max_user_count, BBS_start_dt, u_login_count); |
BBS_max_user_count, BBS_start_dt, u_login_count); |
| 100 |
|
|
| 154 |
if (ch != KEY_NULL && ch != KEY_TIMEOUT) |
if (ch != KEY_NULL && ch != KEY_TIMEOUT) |
| 155 |
{ |
{ |
| 156 |
BBS_last_access_tm = time(NULL); |
BBS_last_access_tm = time(NULL); |
| 157 |
|
#ifdef _DEBUG |
| 158 |
|
log_error("Debug: BBS_last_access_tm is updated\n"); |
| 159 |
|
#endif |
| 160 |
} |
} |
| 161 |
|
|
| 162 |
if (bbs_menu.choose_step == 0 && time(NULL) - t_last_action >= 10) |
if (bbs_menu.choose_step == 0 && time(NULL) - t_last_action >= 10) |
| 219 |
int ch; |
int ch; |
| 220 |
|
|
| 221 |
snprintf(msg, sizeof(msg), |
snprintf(msg, sizeof(msg), |
| 222 |
"\rChoose character set in 5 seconds [UTF-8, GBK]: [U/g]"); |
"\rChoose character set in 5 seconds, (U)UTF-8, (G)GBK [U]: "); |
| 223 |
|
|
| 224 |
while (!SYS_server_exit) |
while (!SYS_server_exit) |
| 225 |
{ |
{ |
| 226 |
ch = press_any_key_ex(msg, 5); |
ch = press_any_key_ex(msg, 5); |
| 227 |
switch (ch) |
switch (toupper(ch)) |
| 228 |
{ |
{ |
| 229 |
case KEY_NULL: |
case KEY_NULL: |
| 230 |
return -1; |
return -1; |
| 231 |
case KEY_TIMEOUT: |
case KEY_TIMEOUT: |
| 232 |
case CR: |
case CR: |
|
case 'u': |
|
| 233 |
case 'U': |
case 'U': |
| 234 |
return 0; |
break; |
|
case 'g': |
|
| 235 |
case 'G': |
case 'G': |
| 236 |
if (io_conv_init("GBK") < 0) |
if (io_conv_init("GBK") < 0) |
| 237 |
{ |
{ |
| 238 |
log_error("io_conv_init(%s) error\n", "GBK"); |
log_error("io_conv_init(%s) error\n", "GBK"); |
| 239 |
return -1; |
return -1; |
| 240 |
} |
} |
| 241 |
return 0; |
break; |
| 242 |
default: |
default: |
| 243 |
continue; |
continue; |
| 244 |
} |
} |
| 245 |
|
|
| 246 |
|
break; |
| 247 |
|
} |
| 248 |
|
|
| 249 |
|
snprintf(msg, sizeof(msg), |
| 250 |
|
"\r请在5秒内选择宽字符显示规则, (V)变宽, (F)定宽? [V]: "); |
| 251 |
|
|
| 252 |
|
while (!SYS_server_exit) |
| 253 |
|
{ |
| 254 |
|
ch = press_any_key_ex(msg, 5); |
| 255 |
|
switch (toupper(ch)) |
| 256 |
|
{ |
| 257 |
|
case KEY_NULL: |
| 258 |
|
return -1; |
| 259 |
|
case KEY_TIMEOUT: |
| 260 |
|
case CR: |
| 261 |
|
case 'V': |
| 262 |
|
UTF8_fixed_width = 0; |
| 263 |
|
break; |
| 264 |
|
case 'F': |
| 265 |
|
UTF8_fixed_width = 1; |
| 266 |
|
break; |
| 267 |
|
default: |
| 268 |
|
continue; |
| 269 |
|
} |
| 270 |
|
|
| 271 |
|
break; |
| 272 |
} |
} |
| 273 |
|
|
| 274 |
return 0; |
return 0; |
| 292 |
log_error("set signal action of SIGCHLD error: %d\n", errno); |
log_error("set signal action of SIGCHLD error: %d\n", errno); |
| 293 |
goto cleanup; |
goto cleanup; |
| 294 |
} |
} |
| 295 |
|
act.sa_handler = child_proc_sig_usr1_handler; |
| 296 |
|
if (sigaction(SIGUSR1, &act, NULL) == -1) |
| 297 |
|
{ |
| 298 |
|
log_error("set signal action of SIGUSR1 error: %d\n", errno); |
| 299 |
|
goto cleanup; |
| 300 |
|
} |
| 301 |
|
|
| 302 |
// Set data pools in shared memory readonly |
// Set data pools in shared memory readonly |
| 303 |
if (set_trie_dict_shm_readonly() < 0) |
if (set_trie_dict_shm_readonly() < 0) |
| 312 |
{ |
{ |
| 313 |
goto cleanup; |
goto cleanup; |
| 314 |
} |
} |
| 315 |
|
#ifdef HAVE_SYSTEM_V |
| 316 |
if (set_user_list_pool_shm_readonly() < 0) |
if (set_user_list_pool_shm_readonly() < 0) |
| 317 |
{ |
{ |
| 318 |
goto cleanup; |
goto cleanup; |
| 319 |
} |
} |
| 320 |
|
#endif |
| 321 |
|
|
| 322 |
// Load menu in shared memory |
// Load menu in shared memory |
| 323 |
if (set_menu_shm_readonly(&bbs_menu) < 0) |
if (set_menu_shm_readonly(&bbs_menu) < 0) |
| 326 |
} |
} |
| 327 |
|
|
| 328 |
// Set default charset |
// Set default charset |
| 329 |
if (io_conv_init(BBS_DEFAULT_CHARSET) < 0) |
if (io_conv_init(BBS_default_charset) < 0) |
| 330 |
{ |
{ |
| 331 |
log_error("io_conv_init(%s) error\n", BBS_DEFAULT_CHARSET); |
log_error("io_conv_init(%s) error\n", BBS_default_charset); |
| 332 |
goto cleanup; |
goto cleanup; |
| 333 |
} |
} |
| 334 |
|
|
| 335 |
set_input_echo(0); |
set_input_echo(0); |
| 336 |
|
|
| 337 |
// Set user charset |
// Set user charset |
| 338 |
bbs_charset_select(); |
if (bbs_charset_select() < 0) |
| 339 |
|
{ |
| 340 |
|
goto cleanup; |
| 341 |
|
} |
| 342 |
|
|
| 343 |
// System info |
// System info |
| 344 |
if (bbs_info() < 0) |
if (bbs_info() < 0) |
| 444 |
detach_article_block_shm(); |
detach_article_block_shm(); |
| 445 |
detach_trie_dict_shm(); |
detach_trie_dict_shm(); |
| 446 |
|
|
| 447 |
|
// Cleanup BWF |
| 448 |
|
bwf_unload(); |
| 449 |
|
|
| 450 |
return 0; |
return 0; |
| 451 |
} |
} |