| 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" |
| 181 |
return -1; |
return -1; |
| 182 |
} |
} |
| 183 |
|
|
| 184 |
if (user_online_del(db) < 0) |
if (user_online_exp(db) < 0) |
| 185 |
{ |
{ |
| 186 |
return -2; |
return -2; |
| 187 |
} |
} |
| 188 |
|
|
| 189 |
|
if (user_online_del(db) < 0) |
| 190 |
|
{ |
| 191 |
|
return -3; |
| 192 |
|
} |
| 193 |
|
|
| 194 |
mysql_close(db); |
mysql_close(db); |
| 195 |
|
|
| 196 |
display_file(DATA_GOODBYE, 1); |
display_file(DATA_GOODBYE, 1); |
| 197 |
|
|
| 198 |
log_common("User logout\n"); |
log_common("User [%s] logout\n", BBS_username); |
| 199 |
|
|
| 200 |
return 0; |
return 0; |
| 201 |
} |
} |
| 219 |
{ |
{ |
| 220 |
ch = igetch(100); |
ch = igetch(100); |
| 221 |
|
|
| 222 |
|
if (ch != KEY_NULL && ch != KEY_TIMEOUT) |
| 223 |
|
{ |
| 224 |
|
BBS_last_access_tm = time(NULL); |
| 225 |
|
} |
| 226 |
|
|
| 227 |
if (bbs_menu.choose_step == 0 && time(NULL) - t_last_action >= 10) |
if (bbs_menu.choose_step == 0 && time(NULL) - t_last_action >= 10) |
| 228 |
{ |
{ |
| 229 |
t_last_action = time(NULL); |
t_last_action = time(NULL); |
| 242 |
switch (ch) |
switch (ch) |
| 243 |
{ |
{ |
| 244 |
case KEY_NULL: // broken pipe |
case KEY_NULL: // broken pipe |
| 245 |
|
log_error("KEY_NULL\n"); |
| 246 |
return 0; |
return 0; |
| 247 |
case KEY_TIMEOUT: |
case KEY_TIMEOUT: |
| 248 |
if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME) |
if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME) |
| 249 |
{ |
{ |
| 250 |
|
log_error("User input timeout\n"); |
| 251 |
return 0; |
return 0; |
| 252 |
} |
} |
| 253 |
continue; |
continue; |
| 254 |
case CR: |
case CR: |
|
igetch_reset(); |
|
| 255 |
default: |
default: |
| 256 |
switch (menu_control(&bbs_menu, ch)) |
switch (menu_control(&bbs_menu, ch)) |
| 257 |
{ |
{ |
| 273 |
} |
} |
| 274 |
iflush(); |
iflush(); |
| 275 |
} |
} |
| 276 |
|
} |
| 277 |
|
|
| 278 |
|
return 0; |
| 279 |
|
} |
| 280 |
|
|
| 281 |
|
int bbs_charset_select() |
| 282 |
|
{ |
| 283 |
|
char msg[LINE_BUFFER_LEN]; |
| 284 |
|
int ch; |
| 285 |
|
|
| 286 |
|
snprintf(msg, sizeof(msg), |
| 287 |
|
"\rChoose character set in 5 seconds [UTF-8, GBK]: [U/g]"); |
| 288 |
|
|
| 289 |
BBS_last_access_tm = time(NULL); |
while (!SYS_server_exit) |
| 290 |
|
{ |
| 291 |
|
ch = press_any_key_ex(msg, 5); |
| 292 |
|
switch (ch) |
| 293 |
|
{ |
| 294 |
|
case KEY_NULL: |
| 295 |
|
return -1; |
| 296 |
|
case KEY_TIMEOUT: |
| 297 |
|
case CR: |
| 298 |
|
case 'u': |
| 299 |
|
case 'U': |
| 300 |
|
return 0; |
| 301 |
|
case 'g': |
| 302 |
|
case 'G': |
| 303 |
|
if (io_conv_init("GBK////TRANSLIT") < 0) |
| 304 |
|
{ |
| 305 |
|
log_error("io_conv_init(%s) error\n", "GBK////TRANSLIT"); |
| 306 |
|
return -1; |
| 307 |
|
} |
| 308 |
|
return 0; |
| 309 |
|
default: |
| 310 |
|
continue; |
| 311 |
|
} |
| 312 |
} |
} |
| 313 |
|
|
| 314 |
return 0; |
return 0; |
| 317 |
int bbs_main() |
int bbs_main() |
| 318 |
{ |
{ |
| 319 |
struct sigaction act = {0}; |
struct sigaction act = {0}; |
| 320 |
|
char msg[LINE_BUFFER_LEN]; |
| 321 |
|
|
| 322 |
// Set signal handler |
// Set signal handler |
| 323 |
act.sa_handler = SIG_IGN; |
act.sa_handler = SIG_IGN; |
| 353 |
goto cleanup; |
goto cleanup; |
| 354 |
} |
} |
| 355 |
|
|
| 356 |
|
// Set default charset |
| 357 |
|
if (io_conv_init(BBS_DEFAULT_CHARSET) < 0) |
| 358 |
|
{ |
| 359 |
|
log_error("io_conv_init(%s) error\n", BBS_DEFAULT_CHARSET); |
| 360 |
|
goto cleanup; |
| 361 |
|
} |
| 362 |
|
|
| 363 |
set_input_echo(0); |
set_input_echo(0); |
| 364 |
|
|
| 365 |
|
// Set user charset |
| 366 |
|
bbs_charset_select(); |
| 367 |
|
|
| 368 |
// System info |
// System info |
| 369 |
if (bbs_info() < 0) |
if (bbs_info() < 0) |
| 370 |
{ |
{ |
| 380 |
// User login |
// User login |
| 381 |
if (SSH_v2) |
if (SSH_v2) |
| 382 |
{ |
{ |
| 383 |
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); |
| 384 |
iflush(); |
press_any_key_ex(msg, 60); |
|
igetch_t(MAX_DELAY_TIME); |
|
| 385 |
} |
} |
| 386 |
else if (bbs_login() < 0) |
else if (bbs_login() < 0) |
| 387 |
{ |
{ |
| 388 |
goto cleanup; |
goto cleanup; |
| 389 |
} |
} |
| 390 |
|
log_common("User [%s] login\n", BBS_username); |
| 391 |
|
|
| 392 |
// Load article view log |
// Load article view log |
| 393 |
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) |
| 396 |
goto cleanup; |
goto cleanup; |
| 397 |
} |
} |
| 398 |
|
|
| 399 |
|
// Load article favorite |
| 400 |
|
if (article_favor_load(BBS_priv.uid, &BBS_article_favor, 0) < 0) |
| 401 |
|
{ |
| 402 |
|
log_error("article_favor_load() error\n"); |
| 403 |
|
goto cleanup; |
| 404 |
|
} |
| 405 |
|
|
| 406 |
// Init editor memory pool |
// Init editor memory pool |
| 407 |
if (editor_memory_pool_init() < 0) |
if (editor_memory_pool_init() < 0) |
| 408 |
{ |
{ |
| 427 |
log_error("article_view_log_save_inc() error\n"); |
log_error("article_view_log_save_inc() error\n"); |
| 428 |
} |
} |
| 429 |
|
|
| 430 |
|
// Save incremental article favorite |
| 431 |
|
if (article_favor_save_inc(&BBS_article_favor) < 0) |
| 432 |
|
{ |
| 433 |
|
log_error("article_favor_save_inc() error\n"); |
| 434 |
|
} |
| 435 |
|
|
| 436 |
cleanup: |
cleanup: |
| 437 |
|
// Cleanup iconv |
| 438 |
|
io_conv_cleanup(); |
| 439 |
|
|
| 440 |
// Cleanup editor memory pool |
// Cleanup editor memory pool |
| 441 |
editor_memory_pool_cleanup(); |
editor_memory_pool_cleanup(); |
| 442 |
|
|
| 443 |
// Unload article view log |
// Unload article view log |
| 444 |
article_view_log_unload(&BBS_article_view_log); |
article_view_log_unload(&BBS_article_view_log); |
| 445 |
|
|
| 446 |
|
// Unload article favor |
| 447 |
|
article_favor_unload(&BBS_article_favor); |
| 448 |
|
|
| 449 |
// Detach menu in shared memory |
// Detach menu in shared memory |
| 450 |
detach_menu_shm(&bbs_menu); |
detach_menu_shm(&bbs_menu); |
| 451 |
|
detach_menu_shm(&top10_menu); |
| 452 |
|
|
| 453 |
// Detach data pools shm |
// Detach data pools shm |
| 454 |
detach_section_list_shm(); |
detach_section_list_shm(); |