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