| 1 |
/*************************************************************************** |
/*************************************************************************** |
| 2 |
main.c - description |
main.c - description |
| 3 |
------------------- |
------------------- |
| 4 |
begin : Mon Oct 11 2004 |
begin : Mon Oct 11 2004 |
| 5 |
copyright : (C) 2004 by Leaflet |
copyright : (C) 2004 by Leaflet |
| 6 |
email : leaflet@leafok.com |
email : leaflet@leafok.com |
| 7 |
***************************************************************************/ |
***************************************************************************/ |
| 8 |
|
|
| 9 |
/*************************************************************************** |
/*************************************************************************** |
| 18 |
#include "bbs.h" |
#include "bbs.h" |
| 19 |
#include "common.h" |
#include "common.h" |
| 20 |
#include "io.h" |
#include "io.h" |
| 21 |
|
#include "database.h" |
| 22 |
#include <mysql.h> |
#include <mysql.h> |
| 23 |
#include <string.h> |
#include <string.h> |
| 24 |
|
|
| 25 |
int |
int bbs_welcome() |
|
bbs_welcome () |
|
| 26 |
{ |
{ |
| 27 |
char buffer[256], sql[1024], temp[256]; |
char buffer[256], sql[1024], temp[256]; |
| 28 |
long u_online = 0, u_anonymous = 0, u_total = 0, |
long u_online = 0, u_anonymous = 0, u_total = 0, |
| 29 |
max_u_online = 0, u_login_count = 0; |
max_u_online = 0, u_login_count = 0; |
| 30 |
MYSQL *db; |
MYSQL *db; |
| 31 |
MYSQL_RES *rs; |
MYSQL_RES *rs; |
| 32 |
MYSQL_ROW row; |
MYSQL_ROW row; |
| 33 |
|
|
| 34 |
db = (MYSQL*) db_open(); |
db = (MYSQL *)db_open(); |
| 35 |
if (db == NULL) |
if (db == NULL) |
| 36 |
{ |
{ |
| 37 |
return -1; |
return -1; |
| 38 |
} |
} |
| 39 |
|
|
| 40 |
strcpy(sql, |
strcpy(sql, |
| 41 |
"select SID as cc from user_online where current_action not in" |
"select SID as cc from user_online where current_action not in" |
| 42 |
" ('max_user_limit','max_ip_limit','max_session_limit','exit')" |
" ('max_user_limit','max_ip_limit','max_session_limit','exit')" |
| 43 |
" group by SID"); |
" group by SID"); |
| 44 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 45 |
{ |
{ |
| 46 |
log_error("Query user_online failed\n"); |
log_error("Query user_online failed\n"); |
| 47 |
return -2; |
return -2; |
| 48 |
} |
} |
| 49 |
if ((rs = mysql_store_result(db)) == NULL) |
if ((rs = mysql_store_result(db)) == NULL) |
| 50 |
{ |
{ |
| 51 |
log_error("Get user_online data failed\n"); |
log_error("Get user_online data failed\n"); |
| 52 |
return -2; |
return -2; |
| 53 |
} |
} |
| 54 |
u_online = mysql_num_rows(rs); |
u_online = mysql_num_rows(rs); |
| 55 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 56 |
|
|
| 57 |
strcpy(sql, |
strcpy(sql, |
| 58 |
"select SID as cc from user_online where UID=0 and current_action not in" |
"select SID as cc from user_online where UID=0 and current_action not in" |
| 59 |
" ('max_user_limit','max_ip_limit','max_session_limit','exit')" |
" ('max_user_limit','max_ip_limit','max_session_limit','exit')" |
| 60 |
" group by SID"); |
" group by SID"); |
| 61 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 62 |
{ |
{ |
| 63 |
log_error("Query user_online failed\n"); |
log_error("Query user_online failed\n"); |
| 64 |
return -2; |
return -2; |
| 65 |
} |
} |
| 66 |
if ((rs = mysql_store_result(db)) == NULL) |
if ((rs = mysql_store_result(db)) == NULL) |
| 67 |
{ |
{ |
| 68 |
log_error("Get user_online data failed\n"); |
log_error("Get user_online data failed\n"); |
| 69 |
return -2; |
return -2; |
| 70 |
} |
} |
| 71 |
u_anonymous = mysql_num_rows(rs); |
u_anonymous = mysql_num_rows(rs); |
| 72 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 73 |
|
|
| 74 |
strcpy(sql, |
strcpy(sql, "select count(*) as cc from user_list where enable"); |
| 75 |
"select count(*) as cc from user_list where enable"); |
if (mysql_query(db, sql) != 0) |
| 76 |
if (mysql_query(db, sql) != 0) |
{ |
| 77 |
{ |
log_error("Query user_list failed\n"); |
| 78 |
log_error("Query user_list failed\n"); |
return -2; |
| 79 |
return -2; |
} |
| 80 |
} |
if ((rs = mysql_store_result(db)) == NULL) |
| 81 |
if ((rs = mysql_store_result(db)) == NULL) |
{ |
| 82 |
{ |
log_error("Get user_list data failed\n"); |
| 83 |
log_error("Get user_list data failed\n"); |
return -2; |
| 84 |
return -2; |
} |
| 85 |
} |
if (row = mysql_fetch_row(rs)) |
| 86 |
if (row = mysql_fetch_row(rs)) |
{ |
| 87 |
{ |
u_total = atol(row[0]); |
| 88 |
u_total = atol(row[0]); |
} |
| 89 |
} |
mysql_free_result(rs); |
| 90 |
mysql_free_result(rs); |
|
| 91 |
|
strcpy(sql, "select max(ID) as login_count from user_login_log"); |
| 92 |
strcpy(sql, |
if (mysql_query(db, sql) != 0) |
| 93 |
"select max(ID) as login_count from user_login_log"); |
{ |
| 94 |
if (mysql_query(db, sql) != 0) |
log_error("Query user_login_log failed\n"); |
| 95 |
{ |
return -2; |
| 96 |
log_error("Query user_login_log failed\n"); |
} |
| 97 |
return -2; |
if ((rs = mysql_store_result(db)) == NULL) |
| 98 |
} |
{ |
| 99 |
if ((rs = mysql_store_result(db)) == NULL) |
log_error("Get user_login_log data failed\n"); |
| 100 |
{ |
return -2; |
| 101 |
log_error("Get user_login_log data failed\n"); |
} |
| 102 |
return -2; |
if (row = mysql_fetch_row(rs)) |
| 103 |
} |
{ |
| 104 |
if (row = mysql_fetch_row(rs)) |
u_login_count = atol(row[0]); |
| 105 |
{ |
} |
| 106 |
u_login_count = atol(row[0]); |
mysql_free_result(rs); |
| 107 |
} |
|
| 108 |
mysql_free_result(rs); |
mysql_close(db); |
| 109 |
|
|
| 110 |
mysql_close(db); |
// Log max user_online |
| 111 |
|
FILE *fin, *fout; |
| 112 |
//Log max user_online |
strcpy(temp, app_home_dir); |
| 113 |
FILE *fin, *fout; |
strcat(temp, "var/max_user_online.dat"); |
| 114 |
strcpy(temp, app_home_dir); |
if ((fin = fopen(temp, "r")) != NULL) |
| 115 |
strcat(temp, "data/max_user_online.dat"); |
{ |
| 116 |
if ((fin = fopen(temp, "r")) != NULL) |
fscanf(fin, "%ld", &max_u_online); |
| 117 |
{ |
fclose(fin); |
| 118 |
fscanf(fin, "%ld", &max_u_online); |
} |
| 119 |
fclose(fin); |
if (u_online > max_u_online) |
| 120 |
} |
{ |
| 121 |
if (u_online > max_u_online) |
max_u_online = u_online; |
| 122 |
{ |
if ((fout = fopen(temp, "w")) == NULL) |
| 123 |
max_u_online = u_online; |
{ |
| 124 |
if ((fout = fopen(temp, "w")) == NULL) |
log_error("Open max_user_online.dat failed\n"); |
| 125 |
{ |
return -3; |
| 126 |
log_error("Open max_user_online.dat failed\n"); |
} |
| 127 |
return -3; |
fprintf(fout, "%ld\n", max_u_online); |
| 128 |
} |
fclose(fout); |
| 129 |
fprintf(fout, "%ld\n", max_u_online); |
} |
| 130 |
fclose(fout); |
|
| 131 |
} |
// Display logo |
| 132 |
|
strcpy(temp, app_home_dir); |
| 133 |
//Display welcome message |
strcat(temp, "data/welcome.txt"); |
| 134 |
prints ( |
display_file(temp); |
| 135 |
"\033[1;35m欢迎光临\033[33m 【 %s 】 \033[35mBBS\r\n" |
|
| 136 |
"\033[32m目前上站人数 [\033[36m%ld/%ld\033[32m] " |
// Display welcome message |
| 137 |
"匿名游客[\033[36m%ld\033[32m] " |
prints("\033[1;35m欢迎光临\033[33m 【 %s 】 \033[35mBBS\r\n" |
| 138 |
"注册用户数[\033[36m%ld/%ld\033[32m]\r\n" |
"\033[32m目前上站人数 [\033[36m%ld/%ld\033[32m] " |
| 139 |
"从 [\033[36m%s\033[32m] 起,最高人数记录:" |
"匿名游客[\033[36m%ld\033[32m] " |
| 140 |
"[\033[36m%ld\033[32m],累计访问人次:[\033[36m%ld\033[32m]\r\n", |
"注册用户数[\033[36m%ld/%ld\033[32m]\r\n" |
| 141 |
BBS_name, u_online, BBS_max_client, u_anonymous, u_total, |
"从 [\033[36m%s\033[32m] 起,最高人数记录:" |
| 142 |
BBS_max_user, BBS_start_dt, max_u_online, u_login_count); |
"[\033[36m%ld\033[32m],累计访问人次:[\033[36m%ld\033[32m]\r\n", |
| 143 |
|
BBS_name, u_online, BBS_max_client, u_anonymous, u_total, |
| 144 |
|
BBS_max_user, BBS_start_dt, max_u_online, u_login_count); |
| 145 |
|
|
| 146 |
return 0; |
return 0; |
| 147 |
} |
} |