| 25 |
#include "screen.h" |
#include "screen.h" |
| 26 |
#include "menu.h" |
#include "menu.h" |
| 27 |
#include "bbs_cmd.h" |
#include "bbs_cmd.h" |
| 28 |
|
#include "section_list.h" |
| 29 |
|
#include "trie_dict.h" |
| 30 |
#include <unistd.h> |
#include <unistd.h> |
| 31 |
#include <time.h> |
#include <time.h> |
| 32 |
#include <string.h> |
#include <string.h> |
| 33 |
|
#include <stdlib.h> |
| 34 |
|
|
| 35 |
int bbs_info() |
int bbs_info() |
| 36 |
{ |
{ |
| 60 |
BBS_user_off_line); |
BBS_user_off_line); |
| 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 error: %s\n", mysql_error(db)); |
| 64 |
return -2; |
return -2; |
| 65 |
} |
} |
| 66 |
if ((rs = mysql_store_result(db)) == NULL) |
if ((rs = mysql_store_result(db)) == NULL) |
| 81 |
BBS_user_off_line); |
BBS_user_off_line); |
| 82 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 83 |
{ |
{ |
| 84 |
log_error("Query user_online failed\n"); |
log_error("Query user_online error: %s\n", mysql_error(db)); |
| 85 |
return -2; |
return -2; |
| 86 |
} |
} |
| 87 |
if ((rs = mysql_store_result(db)) == NULL) |
if ((rs = mysql_store_result(db)) == NULL) |
| 98 |
snprintf(sql, sizeof(sql), "SELECT COUNT(UID) AS cc FROM user_list WHERE enable"); |
snprintf(sql, sizeof(sql), "SELECT COUNT(UID) AS cc FROM user_list WHERE enable"); |
| 99 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 100 |
{ |
{ |
| 101 |
log_error("Query user_list failed\n"); |
log_error("Query user_list error: %s\n", mysql_error(db)); |
| 102 |
return -2; |
return -2; |
| 103 |
} |
} |
| 104 |
if ((rs = mysql_store_result(db)) == NULL) |
if ((rs = mysql_store_result(db)) == NULL) |
| 115 |
snprintf(sql, sizeof(sql), "SELECT ID FROM user_login_log ORDER BY ID LIMIT 1"); |
snprintf(sql, sizeof(sql), "SELECT ID FROM user_login_log ORDER BY ID LIMIT 1"); |
| 116 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 117 |
{ |
{ |
| 118 |
log_error("Query user_login_log failed\n"); |
log_error("Query user_login_log error: %s\n", mysql_error(db)); |
| 119 |
return -2; |
return -2; |
| 120 |
} |
} |
| 121 |
if ((rs = mysql_store_result(db)) == NULL) |
if ((rs = mysql_store_result(db)) == NULL) |
| 153 |
u_anonymous++; |
u_anonymous++; |
| 154 |
|
|
| 155 |
// Display logo |
// Display logo |
| 156 |
display_file(DATA_WELCOME); |
display_file(DATA_WELCOME, 1, 0); |
| 157 |
|
|
| 158 |
// Display welcome message |
// Display welcome message |
| 159 |
prints("\033[1;35m欢迎光临\033[33m 【 %s 】 \033[35mBBS\r\n" |
prints("\r\033[1;35m欢迎光临\033[33m 【 %s 】 \033[35mBBS\r\n" |
| 160 |
"\033[32m目前上站人数 [\033[36m%d/%d\033[32m] " |
"\033[32m目前上站人数 [\033[36m%d/%d\033[32m] " |
| 161 |
"匿名游客[\033[36m%d\033[32m] " |
"匿名游客[\033[36m%d\033[32m] " |
| 162 |
"注册用户数[\033[36m%d/%d\033[32m]\r\n" |
"注册用户数[\033[36m%d/%d\033[32m]\r\n" |
| 175 |
return -1; |
return -1; |
| 176 |
} |
} |
| 177 |
|
|
| 178 |
if (display_file_ex(DATA_GOODBYE, 1, 0) < 0) |
display_file(DATA_GOODBYE, 1, 1); |
|
{ |
|
|
return -2; |
|
|
} |
|
| 179 |
|
|
| 180 |
log_std("User logout\n"); |
log_std("User logout\n"); |
| 181 |
|
|
| 191 |
|
|
| 192 |
clearscr(); |
clearscr(); |
| 193 |
|
|
| 194 |
show_top(""); |
show_top("", BBS_name, ""); |
| 195 |
show_active_board(); |
show_active_board(); |
| 196 |
show_bottom(""); |
show_bottom(""); |
| 197 |
display_menu(p_bbs_menu); |
display_menu(p_bbs_menu); |
| 198 |
|
iflush(); |
| 199 |
|
|
| 200 |
while (!SYS_server_exit) |
while (!SYS_server_exit) |
| 201 |
{ |
{ |
| 202 |
ch = igetch(100); |
ch = igetch(100); |
| 203 |
|
|
| 204 |
if (time(0) - t_last_action >= 10) |
if (p_bbs_menu->choose_step == 0 && time(0) - t_last_action >= 10) |
| 205 |
{ |
{ |
| 206 |
t_last_action = time(0); |
t_last_action = time(0); |
| 207 |
|
|
| 208 |
show_active_board(); |
show_active_board(); |
| 209 |
show_bottom(""); |
show_bottom(""); |
| 210 |
|
display_menu_cursor(p_bbs_menu, 1); |
| 211 |
|
iflush(); |
| 212 |
} |
} |
| 213 |
|
|
| 214 |
switch (ch) |
switch (ch) |
| 229 |
case EXITBBS: |
case EXITBBS: |
| 230 |
return 0; |
return 0; |
| 231 |
case REDRAW: |
case REDRAW: |
| 232 |
|
t_last_action = time(0); |
| 233 |
clearscr(); |
clearscr(); |
| 234 |
show_top(""); |
show_top("", BBS_name, ""); |
| 235 |
show_active_board(); |
show_active_board(); |
| 236 |
show_bottom(""); |
show_bottom(""); |
| 237 |
display_menu(p_bbs_menu); |
display_menu(p_bbs_menu); |
| 241 |
default: |
default: |
| 242 |
break; |
break; |
| 243 |
} |
} |
| 244 |
|
iflush(); |
| 245 |
} |
} |
| 246 |
|
|
| 247 |
BBS_last_access_tm = time(0); |
BBS_last_access_tm = time(0); |
| 248 |
} |
} |
| 249 |
|
|
| 252 |
|
|
| 253 |
int bbs_main() |
int bbs_main() |
| 254 |
{ |
{ |
| 255 |
MYSQL *db; |
MYSQL *db = NULL; |
| 256 |
|
|
| 257 |
|
// Set data pools in shared memory readonly |
| 258 |
|
if (set_trie_dict_shm_readonly() < 0) |
| 259 |
|
{ |
| 260 |
|
goto cleanup; |
| 261 |
|
} |
| 262 |
|
if (set_article_block_shm_readonly() < 0) |
| 263 |
|
{ |
| 264 |
|
goto cleanup; |
| 265 |
|
} |
| 266 |
|
if (set_section_list_shm_readonly() < 0) |
| 267 |
|
{ |
| 268 |
|
goto cleanup; |
| 269 |
|
} |
| 270 |
|
|
| 271 |
|
// Load menu in shared memory |
| 272 |
|
if (set_menu_shm_readonly(p_bbs_menu) < 0) |
| 273 |
|
{ |
| 274 |
|
goto cleanup; |
| 275 |
|
} |
| 276 |
|
|
| 277 |
set_input_echo(0); |
set_input_echo(0); |
| 278 |
|
|
| 279 |
// System info |
// System info |
| 280 |
if (bbs_info() < 0) |
if (bbs_info() < 0) |
| 281 |
{ |
{ |
| 282 |
return -1; |
goto cleanup; |
| 283 |
} |
} |
| 284 |
|
|
| 285 |
db = db_open(); |
db = db_open(); |
| 286 |
if (db == NULL) |
if (db == NULL) |
| 287 |
{ |
{ |
| 288 |
prints("无法连接数据库\n"); |
prints("无法连接数据库\n"); |
| 289 |
return -2; |
goto cleanup; |
| 290 |
} |
} |
| 291 |
|
|
| 292 |
// Welcome |
// Welcome |
| 293 |
if (bbs_welcome(db) < 0) |
if (bbs_welcome(db) < 0) |
| 294 |
{ |
{ |
| 295 |
mysql_close(db); |
goto cleanup; |
|
return -3; |
|
| 296 |
} |
} |
| 297 |
|
|
| 298 |
// User login |
// User login |
| 299 |
if (bbs_login(db) < 0) |
if (bbs_login(db) < 0) |
| 300 |
{ |
{ |
| 301 |
mysql_close(db); |
goto cleanup; |
|
return -4; |
|
| 302 |
} |
} |
| 303 |
clearscr(); |
clearscr(); |
| 304 |
|
|
| 305 |
// BBS Top 10 |
// BBS Top 10 |
| 306 |
if (display_file_ex("./var/bbs_top.txt", 1, 1) < 0) |
display_file(VAR_BBS_TOP, 1, 1); |
|
{ |
|
|
prints("无法加载本站十大\n"); |
|
|
} |
|
| 307 |
|
|
| 308 |
// Main |
// Main |
| 309 |
bbs_center(); |
bbs_center(); |
| 311 |
// Logout |
// Logout |
| 312 |
bbs_logout(db); |
bbs_logout(db); |
| 313 |
|
|
| 314 |
mysql_close(db); |
cleanup: |
| 315 |
|
if (db != NULL) |
| 316 |
|
{ |
| 317 |
|
mysql_close(db); |
| 318 |
|
} |
| 319 |
|
|
| 320 |
|
// Detach menu in shared memory |
| 321 |
|
detach_menu_shm(p_bbs_menu); |
| 322 |
|
free(p_bbs_menu); |
| 323 |
|
p_bbs_menu = NULL; |
| 324 |
|
|
| 325 |
|
// Detach data pools shm |
| 326 |
|
detach_section_list_shm(); |
| 327 |
|
detach_article_block_shm(); |
| 328 |
|
detach_trie_dict_shm(); |
| 329 |
|
|
| 330 |
return 0; |
return 0; |
| 331 |
} |
} |