| 1 |
/*************************************************************************** |
/*************************************************************************** |
| 2 |
bbs_main.c - description |
bbs_main.c - description |
| 3 |
------------------- |
------------------- |
| 4 |
begin : Mon Oct 18 2004 |
Copyright : (C) 2004-2025 by Leaflet |
| 5 |
copyright : (C) 2004 by Leaflet |
Email : leaflet@leafok.com |
|
email : leaflet@leafok.com |
|
| 6 |
***************************************************************************/ |
***************************************************************************/ |
| 7 |
|
|
| 8 |
/*************************************************************************** |
/*************************************************************************** |
| 9 |
* * |
* * |
| 10 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
| 11 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
| 12 |
* the Free Software Foundation; either version 2 of the License, or * |
* the Free Software Foundation; either version 3 of the License, or * |
| 13 |
* (at your option) any later version. * |
* (at your option) any later version. * |
| 14 |
* * |
* * |
| 15 |
***************************************************************************/ |
***************************************************************************/ |
| 16 |
|
|
| 17 |
|
#include "bbs_main.h" |
| 18 |
#include "bbs.h" |
#include "bbs.h" |
| 19 |
|
#include "welcome.h" |
| 20 |
|
#include "login.h" |
| 21 |
|
#include "user_priv.h" |
| 22 |
#include "common.h" |
#include "common.h" |
| 23 |
|
#include "database.h" |
| 24 |
|
#include "log.h" |
| 25 |
#include "io.h" |
#include "io.h" |
| 26 |
|
#include "screen.h" |
| 27 |
#include "menu.h" |
#include "menu.h" |
| 28 |
#include <time.h> |
#include "bbs_cmd.h" |
|
#include <fcntl.h> |
|
| 29 |
#include <unistd.h> |
#include <unistd.h> |
| 30 |
|
#include <time.h> |
| 31 |
|
#include <string.h> |
| 32 |
|
|
| 33 |
#define ACTIVE_BOARD_HEIGHT 8 |
int bbs_info() |
|
|
|
|
int |
|
|
bbs_main () |
|
| 34 |
{ |
{ |
| 35 |
char temp[256]; |
prints("»¶Ó¹âÁÙ \033[1;33m%s \033[32m[%s] \033[37m( %s )\r\n", |
| 36 |
int ret; |
BBS_name, BBS_server, app_version); |
|
|
|
|
set_input_echo (0); |
|
|
|
|
|
bbs_info (); |
|
|
|
|
|
//Welcome |
|
|
bbs_welcome (); |
|
|
|
|
|
//Login |
|
|
ret = bbs_login (); |
|
|
if (ret < 0) |
|
|
return -1; |
|
|
clearscr (); |
|
|
|
|
|
//BBS Top 10 |
|
|
strcpy (temp, app_home_dir); |
|
|
strcat (temp, "data/bbs_top.txt"); |
|
|
display_file_ex (temp, 1, 1); |
|
| 37 |
|
|
| 38 |
//Main |
iflush(); |
|
bbs_center (); |
|
| 39 |
|
|
| 40 |
//Logout |
return 0; |
|
bbs_exit (); |
|
|
|
|
|
return 0; |
|
| 41 |
} |
} |
| 42 |
|
|
| 43 |
int |
int bbs_exit() |
|
bbs_info () |
|
| 44 |
{ |
{ |
| 45 |
prints ("»¶Ó¹âÁÙ \033[1;33m%s \033[32m[%s] \033[37m( %s )\r\n", |
display_file_ex(DATA_GOODBYE, 1, 0); |
|
BBS_name, BBS_server, app_version); |
|
|
|
|
|
iflush (); |
|
| 46 |
|
|
| 47 |
return 0; |
return 0; |
| 48 |
} |
} |
| 49 |
|
|
| 50 |
int |
int bbs_center() |
|
bbs_exit () |
|
| 51 |
{ |
{ |
| 52 |
char temp[256]; |
int ch; |
| 53 |
|
time_t t_last_action; |
|
strcpy (temp, app_home_dir); |
|
|
strcat (temp, "data/goodbye.txt"); |
|
|
display_file_ex (temp, 1, 0); |
|
|
|
|
|
sleep (1); |
|
| 54 |
|
|
| 55 |
return 0; |
BBS_last_access_tm = t_last_action = time(0); |
|
} |
|
| 56 |
|
|
| 57 |
int |
clearscr(); |
|
bbs_center () |
|
|
{ |
|
|
int ch, result; |
|
|
char key; |
|
|
time_t t_last_action; |
|
|
fd_set inputs, testfds; |
|
|
struct timeval timeout; |
|
|
|
|
|
FD_ZERO (&inputs); |
|
|
FD_SET (0, &inputs); |
|
|
|
|
|
t_last_action = time (0); |
|
|
|
|
|
clearscr (); |
|
|
|
|
|
show_top ("²âÊÔ"); |
|
|
show_active_board (); |
|
|
display_menu (&bbs_main_menu); |
|
|
show_bottom ("²âÊÔ"); |
|
|
|
|
|
while (1) |
|
|
{ |
|
|
testfds = inputs; |
|
|
timeout.tv_sec = 0; |
|
|
timeout.tv_usec = 100000; |
|
| 58 |
|
|
| 59 |
result = select (FD_SETSIZE, &testfds, (fd_set *) NULL, |
show_top(""); |
| 60 |
(fd_set *) NULL, &timeout); |
show_active_board(); |
| 61 |
|
show_bottom(""); |
| 62 |
|
display_menu(get_menu(&bbs_menu, "TOPMENU")); |
| 63 |
|
|
| 64 |
switch (result) |
while (!SYS_server_exit) |
| 65 |
{ |
{ |
| 66 |
case 0: |
ch = igetch(0); |
| 67 |
break; |
|
| 68 |
case -1: |
if (time(0) - t_last_action >= 10) |
| 69 |
log_error ("select() error!\n"); |
{ |
| 70 |
break; |
t_last_action = time(0); |
| 71 |
default: |
show_active_board(); |
| 72 |
if (FD_ISSET (0, &testfds)) |
show_bottom(""); |
| 73 |
{ |
} |
|
ch = igetch (); |
|
| 74 |
|
|
| 75 |
switch (ch) |
switch (ch) |
| 76 |
{ |
{ |
| 77 |
case KEY_LEFT: |
case KEY_NULL: |
| 78 |
ch = 'G'; |
case KEY_TIMEOUT: |
| 79 |
|
if (time(0) - BBS_last_access_tm >= MAX_DELAY_TIME) |
| 80 |
|
{ |
| 81 |
|
return 0; |
| 82 |
|
} |
| 83 |
|
continue; |
| 84 |
default: |
default: |
| 85 |
key = menu_control (&bbs_main_menu, ch); |
switch (menu_control(&bbs_menu, ch)) |
| 86 |
switch (key) |
{ |
| 87 |
{ |
case EXITBBS: |
| 88 |
case 'G': |
return 0; |
| 89 |
return 0; |
case REDRAW: |
| 90 |
} |
clearscr(); |
| 91 |
|
show_top(""); |
| 92 |
|
show_active_board(); |
| 93 |
|
show_bottom(""); |
| 94 |
|
display_current_menu(&bbs_menu); |
| 95 |
|
break; |
| 96 |
|
case NOREDRAW: |
| 97 |
|
case UNKNOWN_CMD: |
| 98 |
|
default: |
| 99 |
|
break; |
| 100 |
|
} |
| 101 |
} |
} |
| 102 |
} |
BBS_last_access_tm = time(0); |
|
break; |
|
|
} |
|
|
if (time (0) - t_last_action >= 10) |
|
|
{ |
|
|
t_last_action = time (0); |
|
|
show_active_board (); |
|
| 103 |
} |
} |
|
} |
|
| 104 |
|
|
| 105 |
return 0; |
return 0; |
| 106 |
} |
} |
| 107 |
|
|
| 108 |
int |
int bbs_main() |
|
show_top (char *status) |
|
| 109 |
{ |
{ |
| 110 |
char buffer[256]; |
int ret; |
|
|
|
|
str_space (buffer, 20 - strlen (BBS_current_section_name)); |
|
| 111 |
|
|
| 112 |
moveto (1, 0); |
set_input_echo(0); |
|
prints ("\033[1;44;33m%-20s \033[37m%20s" |
|
|
" %s\033[33mÌÖÂÛÇø [%s]\033[m", |
|
|
status, BBS_name, buffer, BBS_current_section_name); |
|
|
iflush (); |
|
| 113 |
|
|
| 114 |
return 0; |
bbs_info(); |
|
} |
|
|
|
|
|
int |
|
|
show_bottom (char *msg) |
|
|
{ |
|
|
char str_time[256], str_time_onine[20], buffer[256]; |
|
|
time_t time_online; |
|
|
struct tm *tm_online; |
|
|
|
|
|
get_time_str (str_time, 256); |
|
|
str_space (buffer, 33 - strlen (BBS_username)); |
|
|
|
|
|
time_online = time (0) - BBS_login_tm; |
|
|
tm_online = gmtime (&time_online); |
|
|
|
|
|
moveto (screen_lines, 0); |
|
|
prints ("\033[1;44;33m[\033[36m%s\033[33m]" |
|
|
"%sÕʺÅ[\033[36m%s\033[33m]" |
|
|
"[\033[36m%1d\033[33m:\033[36m%2d\033[33m:\033[36m%2d\033[33m]\033[m", |
|
|
str_time, buffer, BBS_username, tm_online->tm_mday - 1, |
|
|
tm_online->tm_hour, tm_online->tm_min); |
|
|
iflush (); |
|
| 115 |
|
|
| 116 |
return 0; |
// Welcome |
| 117 |
} |
bbs_welcome(); |
| 118 |
|
|
| 119 |
int |
// Login |
| 120 |
show_active_board () |
ret = bbs_login(); |
| 121 |
{ |
if (ret < 0) |
| 122 |
char filename[256], buffer[260]; |
return -1; |
| 123 |
FILE *fin; |
log_std("User \"%s\"(%ld) login from %s:%d\n", |
| 124 |
int i, j; |
BBS_username, BBS_priv.uid, hostaddr_client, port_client); |
| 125 |
static long int line; |
clearscr(); |
| 126 |
|
|
| 127 |
sprintf (filename, "%sdata/active_board.txt", app_home_dir); |
// BBS Top 10 |
| 128 |
|
display_file_ex("./var/bbs_top.txt", 1, 1); |
| 129 |
|
|
| 130 |
clrline (3, 2 + ACTIVE_BOARD_HEIGHT); |
// Main |
| 131 |
|
bbs_center(); |
| 132 |
|
|
| 133 |
moveto (3, 0); |
// Logout |
| 134 |
|
bbs_exit(); |
| 135 |
|
log_std("User logout\n"); |
| 136 |
|
|
| 137 |
if ((fin = fopen (filename, "r")) != NULL) |
MYSQL *db = db_open(); |
| 138 |
{ |
if (db == NULL) |
|
for (j = 0; j < line; j++) |
|
| 139 |
{ |
{ |
| 140 |
if (fgets (buffer, 255, fin) == NULL) |
return -1; |
|
{ |
|
|
line = 0; |
|
|
rewind (fin); |
|
|
break; |
|
|
} |
|
| 141 |
} |
} |
| 142 |
|
|
| 143 |
for (j = 0; j < ACTIVE_BOARD_HEIGHT; j++) |
user_online_del(db); |
| 144 |
{ |
|
| 145 |
if (fgets (buffer, 255, fin) == NULL) |
mysql_close(db); |
|
{ |
|
|
line = 0; |
|
|
if (j == 0) |
|
|
{ |
|
|
rewind (fin); |
|
|
if (fgets (buffer, 255, fin) == NULL) |
|
|
{ |
|
|
break; |
|
|
} |
|
|
} |
|
|
else |
|
|
{ |
|
|
break; |
|
|
} |
|
|
} |
|
|
line++; |
|
|
i = strlen (buffer); |
|
|
if (buffer[i - 1] == '\n' && buffer[i - 2] != '\r') |
|
|
{ |
|
|
buffer[i - 1] = '\r'; |
|
|
buffer[i] = '\n'; |
|
|
buffer[i + 1] = '\0'; |
|
|
} |
|
|
prints (buffer); |
|
|
iflush (); |
|
|
} |
|
|
fclose (fin); |
|
|
} |
|
| 146 |
|
|
| 147 |
return 0; |
return 0; |
| 148 |
} |
} |