| 28 |
#include "menu.h" |
#include "menu.h" |
| 29 |
#include "screen.h" |
#include "screen.h" |
| 30 |
#include "section_list.h" |
#include "section_list.h" |
| 31 |
|
#include "section_list_display.h" |
| 32 |
#include "trie_dict.h" |
#include "trie_dict.h" |
| 33 |
#include "user_list.h" |
#include "user_list.h" |
| 34 |
#include "user_priv.h" |
#include "user_priv.h" |
| 49 |
|
|
| 50 |
int bbs_welcome(void) |
int bbs_welcome(void) |
| 51 |
{ |
{ |
| 52 |
char sql[SQL_BUFFER_LEN]; |
int u_online = 0; |
| 53 |
|
int u_anonymous = 0; |
| 54 |
|
int u_total = 0; |
| 55 |
|
int u_login_count = 0; |
| 56 |
|
|
| 57 |
u_int32_t u_online = 0; |
if (get_user_online_list_count(&u_online, &u_anonymous) < 0) |
|
u_int32_t u_anonymous = 0; |
|
|
u_int32_t u_total = 0; |
|
|
u_int32_t u_login_count = 0; |
|
|
|
|
|
MYSQL *db; |
|
|
MYSQL_RES *rs; |
|
|
MYSQL_ROW row; |
|
|
|
|
|
db = db_open(); |
|
|
if (db == NULL) |
|
|
{ |
|
|
return -1; |
|
|
} |
|
|
|
|
|
snprintf(sql, sizeof(sql), |
|
|
"SELECT COUNT(*) AS cc FROM " |
|
|
"(SELECT DISTINCT SID FROM user_online " |
|
|
"WHERE last_tm >= SUBDATE(NOW(), INTERVAL %d SECOND)) AS t1", |
|
|
BBS_user_off_line); |
|
|
if (mysql_query(db, sql) != 0) |
|
|
{ |
|
|
log_error("Query user_online error: %s\n", mysql_error(db)); |
|
|
mysql_close(db); |
|
|
return -2; |
|
|
} |
|
|
if ((rs = mysql_store_result(db)) == NULL) |
|
|
{ |
|
|
log_error("Get user_online data failed\n"); |
|
|
mysql_close(db); |
|
|
return -2; |
|
|
} |
|
|
if ((row = mysql_fetch_row(rs))) |
|
| 58 |
{ |
{ |
| 59 |
u_online = (u_int32_t)atoi(row[0]); |
log_error("get_user_online_list_count() error\n"); |
| 60 |
} |
u_online = 0; |
|
mysql_free_result(rs); |
|
|
|
|
|
snprintf(sql, sizeof(sql), |
|
|
"SELECT COUNT(*) AS cc FROM " |
|
|
"(SELECT DISTINCT SID FROM user_online " |
|
|
"WHERE UID = 0 AND last_tm >= SUBDATE(NOW(), INTERVAL %d SECOND)) AS t1", |
|
|
BBS_user_off_line); |
|
|
if (mysql_query(db, sql) != 0) |
|
|
{ |
|
|
log_error("Query user_online error: %s\n", mysql_error(db)); |
|
|
mysql_close(db); |
|
|
return -2; |
|
|
} |
|
|
if ((rs = mysql_store_result(db)) == NULL) |
|
|
{ |
|
|
log_error("Get user_online data failed\n"); |
|
|
mysql_close(db); |
|
|
return -2; |
|
| 61 |
} |
} |
| 62 |
if ((row = mysql_fetch_row(rs))) |
u_online += u_anonymous; |
| 63 |
|
u_online++; // current user |
| 64 |
|
if (BBS_priv.uid == 0) |
| 65 |
{ |
{ |
| 66 |
u_anonymous = (u_int32_t)atoi(row[0]); |
u_anonymous++; |
| 67 |
} |
} |
|
mysql_free_result(rs); |
|
| 68 |
|
|
| 69 |
snprintf(sql, sizeof(sql), "SELECT COUNT(UID) AS cc FROM user_list WHERE enable"); |
if (get_user_list_count(&u_total) < 0) |
|
if (mysql_query(db, sql) != 0) |
|
| 70 |
{ |
{ |
| 71 |
log_error("Query user_list error: %s\n", mysql_error(db)); |
log_error("get_user_list_count() error\n"); |
| 72 |
mysql_close(db); |
u_total = 0; |
|
return -2; |
|
|
} |
|
|
if ((rs = mysql_store_result(db)) == NULL) |
|
|
{ |
|
|
log_error("Get user_list data failed\n"); |
|
|
mysql_close(db); |
|
|
return -2; |
|
|
} |
|
|
if ((row = mysql_fetch_row(rs))) |
|
|
{ |
|
|
u_total = (u_int32_t)atoi(row[0]); |
|
| 73 |
} |
} |
|
mysql_free_result(rs); |
|
| 74 |
|
|
| 75 |
snprintf(sql, sizeof(sql), "SELECT ID FROM user_login_log ORDER BY ID LIMIT 1"); |
if (get_user_login_count(&u_login_count) < 0) |
|
if (mysql_query(db, sql) != 0) |
|
|
{ |
|
|
log_error("Query user_login_log error: %s\n", mysql_error(db)); |
|
|
mysql_close(db); |
|
|
return -2; |
|
|
} |
|
|
if ((rs = mysql_store_result(db)) == NULL) |
|
|
{ |
|
|
log_error("Get user_login_log data failed\n"); |
|
|
mysql_close(db); |
|
|
return -2; |
|
|
} |
|
|
if ((row = mysql_fetch_row(rs))) |
|
| 76 |
{ |
{ |
| 77 |
u_login_count = (u_int32_t)atoi(row[0]); |
log_error("get_user_login_count() error\n"); |
| 78 |
|
u_login_count = 0; |
| 79 |
} |
} |
|
mysql_free_result(rs); |
|
|
|
|
|
mysql_close(db); |
|
|
|
|
|
// Count current user before login |
|
|
u_online++; |
|
|
u_anonymous++; |
|
| 80 |
|
|
| 81 |
// Display logo |
// Display logo |
| 82 |
display_file(DATA_WELCOME, 2); |
display_file(DATA_WELCOME, 2); |
| 317 |
} |
} |
| 318 |
log_common("User [%s] login\n", BBS_username); |
log_common("User [%s] login\n", BBS_username); |
| 319 |
|
|
| 320 |
|
// Load section aid locations |
| 321 |
|
if (section_aid_locations_load(BBS_priv.uid) < 0) |
| 322 |
|
{ |
| 323 |
|
log_error("article_view_log_load() error\n"); |
| 324 |
|
goto cleanup; |
| 325 |
|
} |
| 326 |
|
|
| 327 |
// Load article view log |
// Load article view log |
| 328 |
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) |
| 329 |
{ |
{ |
| 356 |
// Logout |
// Logout |
| 357 |
bbs_logout(); |
bbs_logout(); |
| 358 |
|
|
| 359 |
|
// Save section aid locations |
| 360 |
|
if (section_aid_locations_save(BBS_priv.uid) < 0) |
| 361 |
|
{ |
| 362 |
|
log_error("article_view_log_save() error\n"); |
| 363 |
|
} |
| 364 |
|
|
| 365 |
// Save incremental article view log |
// Save incremental article view log |
| 366 |
if (article_view_log_save_inc(&BBS_article_view_log) < 0) |
if (article_view_log_save_inc(&BBS_article_view_log) < 0) |
| 367 |
{ |
{ |