| 14 |
* * |
* * |
| 15 |
***************************************************************************/ |
***************************************************************************/ |
| 16 |
|
|
| 17 |
|
#include "article_favor.h" |
| 18 |
#include "article_view_log.h" |
#include "article_view_log.h" |
| 19 |
#include "bbs.h" |
#include "bbs.h" |
| 20 |
#include "bbs_cmd.h" |
#include "bbs_cmd.h" |
| 29 |
#include "screen.h" |
#include "screen.h" |
| 30 |
#include "section_list.h" |
#include "section_list.h" |
| 31 |
#include "trie_dict.h" |
#include "trie_dict.h" |
| 32 |
|
#include "user_list.h" |
| 33 |
#include "user_priv.h" |
#include "user_priv.h" |
| 34 |
#include <errno.h> |
#include <errno.h> |
| 35 |
#include <signal.h> |
#include <signal.h> |
| 40 |
|
|
| 41 |
int bbs_info() |
int bbs_info() |
| 42 |
{ |
{ |
| 43 |
prints("欢迎光临 \033[1;33m%s \033[32m[%s] \033[37m( %s )\r\n", |
prints("欢迎光临 \033[1;33m%s \033[32m[%s] \033[37m( %s )\033[m\r\n", |
| 44 |
BBS_name, BBS_server, APP_INFO); |
BBS_name, BBS_server, APP_INFO); |
| 45 |
|
|
| 46 |
return iflush(); |
return iflush(); |
| 165 |
"注册用户数[\033[36m%d/%d\033[32m]\r\n" |
"注册用户数[\033[36m%d/%d\033[32m]\r\n" |
| 166 |
"从 [\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", |
| 167 |
BBS_name, u_online, BBS_max_client, u_anonymous, u_total, |
BBS_name, u_online, BBS_max_client, u_anonymous, u_total, |
| 168 |
BBS_max_user, BBS_start_dt, u_login_count); |
BBS_max_user_count, BBS_start_dt, u_login_count); |
| 169 |
|
|
| 170 |
iflush(); |
iflush(); |
| 171 |
|
|
| 182 |
return -1; |
return -1; |
| 183 |
} |
} |
| 184 |
|
|
| 185 |
if (user_online_del(db) < 0) |
if (user_online_exp(db) < 0) |
| 186 |
{ |
{ |
| 187 |
return -2; |
return -2; |
| 188 |
} |
} |
| 189 |
|
|
| 190 |
|
if (user_online_del(db) < 0) |
| 191 |
|
{ |
| 192 |
|
return -3; |
| 193 |
|
} |
| 194 |
|
|
| 195 |
mysql_close(db); |
mysql_close(db); |
| 196 |
|
|
| 197 |
display_file(DATA_GOODBYE, 1); |
display_file(DATA_GOODBYE, 1); |
| 198 |
|
|
| 199 |
log_common("User logout\n"); |
log_common("User [%s] logout, idle for %ld seconds since last input\n", BBS_username, time(NULL) - BBS_last_access_tm); |
| 200 |
|
|
| 201 |
return 0; |
return 0; |
| 202 |
} |
} |
| 220 |
{ |
{ |
| 221 |
ch = igetch(100); |
ch = igetch(100); |
| 222 |
|
|
| 223 |
|
if (ch != KEY_NULL && ch != KEY_TIMEOUT) |
| 224 |
|
{ |
| 225 |
|
BBS_last_access_tm = time(NULL); |
| 226 |
|
} |
| 227 |
|
|
| 228 |
if (bbs_menu.choose_step == 0 && time(NULL) - t_last_action >= 10) |
if (bbs_menu.choose_step == 0 && time(NULL) - t_last_action >= 10) |
| 229 |
{ |
{ |
| 230 |
t_last_action = time(NULL); |
t_last_action = time(NULL); |
| 243 |
switch (ch) |
switch (ch) |
| 244 |
{ |
{ |
| 245 |
case KEY_NULL: // broken pipe |
case KEY_NULL: // broken pipe |
| 246 |
|
log_error("KEY_NULL\n"); |
| 247 |
return 0; |
return 0; |
| 248 |
case KEY_TIMEOUT: |
case KEY_TIMEOUT: |
| 249 |
if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME) |
if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME) |
| 250 |
{ |
{ |
| 251 |
|
log_error("User input timeout\n"); |
| 252 |
return 0; |
return 0; |
| 253 |
} |
} |
| 254 |
continue; |
continue; |
| 255 |
case CR: |
case CR: |
|
igetch_reset(); |
|
| 256 |
default: |
default: |
| 257 |
switch (menu_control(&bbs_menu, ch)) |
switch (menu_control(&bbs_menu, ch)) |
| 258 |
{ |
{ |
| 274 |
} |
} |
| 275 |
iflush(); |
iflush(); |
| 276 |
} |
} |
| 277 |
|
} |
| 278 |
|
|
| 279 |
|
return 0; |
| 280 |
|
} |
| 281 |
|
|
| 282 |
BBS_last_access_tm = time(NULL); |
int bbs_charset_select() |
| 283 |
|
{ |
| 284 |
|
char msg[LINE_BUFFER_LEN]; |
| 285 |
|
int ch; |
| 286 |
|
|
| 287 |
|
snprintf(msg, sizeof(msg), |
| 288 |
|
"\rChoose character set in 5 seconds [UTF-8, GBK]: [U/g]"); |
| 289 |
|
|
| 290 |
|
while (!SYS_server_exit) |
| 291 |
|
{ |
| 292 |
|
ch = press_any_key_ex(msg, 5); |
| 293 |
|
switch (ch) |
| 294 |
|
{ |
| 295 |
|
case KEY_NULL: |
| 296 |
|
return -1; |
| 297 |
|
case KEY_TIMEOUT: |
| 298 |
|
case CR: |
| 299 |
|
case 'u': |
| 300 |
|
case 'U': |
| 301 |
|
return 0; |
| 302 |
|
case 'g': |
| 303 |
|
case 'G': |
| 304 |
|
if (io_conv_init("GBK") < 0) |
| 305 |
|
{ |
| 306 |
|
log_error("io_conv_init(%s) error\n", "GBK"); |
| 307 |
|
return -1; |
| 308 |
|
} |
| 309 |
|
return 0; |
| 310 |
|
default: |
| 311 |
|
continue; |
| 312 |
|
} |
| 313 |
} |
} |
| 314 |
|
|
| 315 |
return 0; |
return 0; |
| 318 |
int bbs_main() |
int bbs_main() |
| 319 |
{ |
{ |
| 320 |
struct sigaction act = {0}; |
struct sigaction act = {0}; |
| 321 |
|
char msg[LINE_BUFFER_LEN]; |
| 322 |
|
|
| 323 |
// Set signal handler |
// Set signal handler |
| 324 |
act.sa_handler = SIG_IGN; |
act.sa_handler = SIG_IGN; |
| 347 |
{ |
{ |
| 348 |
goto cleanup; |
goto cleanup; |
| 349 |
} |
} |
| 350 |
|
if (set_user_list_pool_shm_readonly() < 0) |
| 351 |
|
{ |
| 352 |
|
goto cleanup; |
| 353 |
|
} |
| 354 |
|
|
| 355 |
// Load menu in shared memory |
// Load menu in shared memory |
| 356 |
if (set_menu_shm_readonly(&bbs_menu) < 0) |
if (set_menu_shm_readonly(&bbs_menu) < 0) |
| 358 |
goto cleanup; |
goto cleanup; |
| 359 |
} |
} |
| 360 |
|
|
| 361 |
|
// Set default charset |
| 362 |
|
if (io_conv_init(BBS_DEFAULT_CHARSET) < 0) |
| 363 |
|
{ |
| 364 |
|
log_error("io_conv_init(%s) error\n", BBS_DEFAULT_CHARSET); |
| 365 |
|
goto cleanup; |
| 366 |
|
} |
| 367 |
|
|
| 368 |
set_input_echo(0); |
set_input_echo(0); |
| 369 |
|
|
| 370 |
|
// Set user charset |
| 371 |
|
bbs_charset_select(); |
| 372 |
|
|
| 373 |
// System info |
// System info |
| 374 |
if (bbs_info() < 0) |
if (bbs_info() < 0) |
| 375 |
{ |
{ |
| 385 |
// User login |
// User login |
| 386 |
if (SSH_v2) |
if (SSH_v2) |
| 387 |
{ |
{ |
| 388 |
prints("\033[1m%s 欢迎使用ssh方式访问 \033[1;33m按任意键继续...\033[m", BBS_username); |
snprintf(msg, sizeof(msg), "\033[1m%s 欢迎使用ssh方式访问 \033[1;33m按任意键继续...\033[m", BBS_username); |
| 389 |
iflush(); |
press_any_key_ex(msg, 60); |
|
igetch_t(MAX_DELAY_TIME); |
|
| 390 |
} |
} |
| 391 |
else if (bbs_login() < 0) |
else if (bbs_login() < 0) |
| 392 |
{ |
{ |
| 393 |
goto cleanup; |
goto cleanup; |
| 394 |
} |
} |
| 395 |
|
log_common("User [%s] login\n", BBS_username); |
| 396 |
|
|
| 397 |
// Load article view log |
// Load article view log |
| 398 |
if (article_view_log_load(BBS_priv.uid, &BBS_article_view_log, 0) < 0) |
if (article_view_log_load(BBS_priv.uid, &BBS_article_view_log, 0) < 0) |
| 401 |
goto cleanup; |
goto cleanup; |
| 402 |
} |
} |
| 403 |
|
|
| 404 |
|
// Load article favorite |
| 405 |
|
if (article_favor_load(BBS_priv.uid, &BBS_article_favor, 0) < 0) |
| 406 |
|
{ |
| 407 |
|
log_error("article_favor_load() error\n"); |
| 408 |
|
goto cleanup; |
| 409 |
|
} |
| 410 |
|
|
| 411 |
// Init editor memory pool |
// Init editor memory pool |
| 412 |
if (editor_memory_pool_init() < 0) |
if (editor_memory_pool_init() < 0) |
| 413 |
{ |
{ |
| 432 |
log_error("article_view_log_save_inc() error\n"); |
log_error("article_view_log_save_inc() error\n"); |
| 433 |
} |
} |
| 434 |
|
|
| 435 |
|
// Save incremental article favorite |
| 436 |
|
if (article_favor_save_inc(&BBS_article_favor) < 0) |
| 437 |
|
{ |
| 438 |
|
log_error("article_favor_save_inc() error\n"); |
| 439 |
|
} |
| 440 |
|
|
| 441 |
cleanup: |
cleanup: |
| 442 |
|
// Cleanup iconv |
| 443 |
|
io_conv_cleanup(); |
| 444 |
|
|
| 445 |
// Cleanup editor memory pool |
// Cleanup editor memory pool |
| 446 |
editor_memory_pool_cleanup(); |
editor_memory_pool_cleanup(); |
| 447 |
|
|
| 448 |
// Unload article view log |
// Unload article view log |
| 449 |
article_view_log_unload(&BBS_article_view_log); |
article_view_log_unload(&BBS_article_view_log); |
| 450 |
|
|
| 451 |
|
// Unload article favor |
| 452 |
|
article_favor_unload(&BBS_article_favor); |
| 453 |
|
|
| 454 |
// Detach menu in shared memory |
// Detach menu in shared memory |
| 455 |
detach_menu_shm(&bbs_menu); |
detach_menu_shm(&bbs_menu); |
| 456 |
|
detach_menu_shm(&top10_menu); |
| 457 |
|
|
| 458 |
// Detach data pools shm |
// Detach data pools shm |
| 459 |
|
detach_user_list_pool_shm(); |
| 460 |
detach_section_list_shm(); |
detach_section_list_shm(); |
| 461 |
detach_article_block_shm(); |
detach_article_block_shm(); |
| 462 |
detach_trie_dict_shm(); |
detach_trie_dict_shm(); |