| 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> |
#include <string.h> |
| 32 |
|
|
| 33 |
int |
int bbs_info() |
|
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); |
| 37 |
|
|
| 38 |
set_input_echo (0); |
iflush(); |
| 39 |
|
|
| 40 |
bbs_info (); |
return 0; |
| 41 |
|
} |
| 42 |
|
|
| 43 |
//Welcome |
int bbs_exit() |
| 44 |
bbs_welcome (); |
{ |
| 45 |
|
display_file_ex(DATA_GOODBYE, 1, 0); |
| 46 |
|
|
| 47 |
//Login |
sleep(1); |
|
ret = bbs_login (); |
|
|
if (ret < 0) |
|
|
return -1; |
|
|
clearscr (); |
|
| 48 |
|
|
| 49 |
//BBS Top 10 |
return 0; |
| 50 |
strcpy (temp, app_home_dir); |
} |
|
strcat (temp, "data/bbs_top.txt"); |
|
|
display_file_ex (temp, 1, 1); |
|
| 51 |
|
|
| 52 |
//Main |
int bbs_center() |
| 53 |
bbs_center (); |
{ |
| 54 |
|
int ch, redraw; |
| 55 |
|
time_t t_last_action; |
| 56 |
|
|
| 57 |
//Logout |
BBS_last_access_tm = t_last_action = time(0); |
|
bbs_exit (); |
|
| 58 |
|
|
| 59 |
return 0; |
clearscr(); |
|
} |
|
| 60 |
|
|
| 61 |
int |
show_top(""); |
| 62 |
bbs_info () |
show_active_board(); |
| 63 |
{ |
show_bottom(""); |
| 64 |
prints ("»¶Ó¹âÁÙ \033[1;33m%s \033[32m[%s] \033[37m( %s )\r\n", |
display_menu(get_menu(&bbs_menu, "TOPMENU")); |
|
BBS_name, BBS_server, app_version); |
|
| 65 |
|
|
| 66 |
iflush (); |
while (!SYS_exit) |
| 67 |
|
{ |
| 68 |
|
ch = igetch(0); |
| 69 |
|
|
| 70 |
return 0; |
if (time(0) - t_last_action >= 10) |
| 71 |
|
{ |
| 72 |
|
t_last_action = time(0); |
| 73 |
|
show_active_board(); |
| 74 |
|
show_bottom(""); |
| 75 |
|
} |
| 76 |
|
|
| 77 |
|
switch (ch) |
| 78 |
|
{ |
| 79 |
|
case KEY_NULL: |
| 80 |
|
return 0; |
| 81 |
|
case KEY_TIMEOUT: |
| 82 |
|
if (time(0) - BBS_last_access_tm >= MAX_DELAY_TIME) |
| 83 |
|
{ |
| 84 |
|
return -1; |
| 85 |
|
} |
| 86 |
|
continue; |
| 87 |
|
default: |
| 88 |
|
redraw = 1; |
| 89 |
|
switch (menu_control(&bbs_menu, ch)) |
| 90 |
|
{ |
| 91 |
|
case EXITBBS: |
| 92 |
|
return 0; |
| 93 |
|
case REDRAW: |
| 94 |
|
break; |
| 95 |
|
case NOREDRAW: |
| 96 |
|
case UNKNOWN_CMD: |
| 97 |
|
default: |
| 98 |
|
redraw = 0; |
| 99 |
|
break; |
| 100 |
|
} |
| 101 |
|
if (redraw) |
| 102 |
|
{ |
| 103 |
|
clearscr(); |
| 104 |
|
show_top(""); |
| 105 |
|
show_active_board(); |
| 106 |
|
show_bottom(""); |
| 107 |
|
display_current_menu(&bbs_menu); |
| 108 |
|
} |
| 109 |
|
} |
| 110 |
|
BBS_last_access_tm = time(0); |
| 111 |
|
} |
| 112 |
|
|
| 113 |
|
return 0; |
| 114 |
} |
} |
| 115 |
|
|
| 116 |
int |
int bbs_main() |
|
bbs_exit () |
|
| 117 |
{ |
{ |
| 118 |
char temp[256]; |
int ret; |
| 119 |
|
|
| 120 |
strcpy (temp, app_home_dir); |
set_input_echo(0); |
|
strcat (temp, "data/goodbye.txt"); |
|
|
display_file_ex (temp, 1, 0); |
|
| 121 |
|
|
| 122 |
sleep (1); |
bbs_info(); |
| 123 |
|
|
| 124 |
return 0; |
// Welcome |
| 125 |
} |
bbs_welcome(); |
| 126 |
|
|
| 127 |
int |
// Login |
| 128 |
bbs_center () |
ret = bbs_login(); |
| 129 |
{ |
if (ret < 0) |
| 130 |
int ch, result; |
return -1; |
| 131 |
char action[MAX_MENUACTION_LENGTH]; |
log_std("User \"%s\"(%ld) login from %s:%d\n", |
| 132 |
time_t t_last_action; |
BBS_username, BBS_priv.uid, hostaddr_client, port_client); |
| 133 |
fd_set inputs, testfds; |
clearscr(); |
|
struct timeval timeout; |
|
|
|
|
|
FD_ZERO (&inputs); |
|
|
FD_SET (0, &inputs); |
|
|
|
|
|
t_last_action = time (0); |
|
|
|
|
|
clearscr (); |
|
|
|
|
|
show_top (""); |
|
|
show_active_board (); |
|
|
display_menu (get_menu (&bbs_menu, "TOPMENU")); |
|
|
show_bottom (""); |
|
|
|
|
|
while (1) |
|
|
{ |
|
|
testfds = inputs; |
|
|
timeout.tv_sec = 0; |
|
|
timeout.tv_usec = 100000; |
|
| 134 |
|
|
| 135 |
result = select (FD_SETSIZE, &testfds, (fd_set *) NULL, |
// BBS Top 10 |
| 136 |
(fd_set *) NULL, &timeout); |
display_file_ex("./var/bbs_top.txt", 1, 1); |
| 137 |
|
|
| 138 |
switch (result) |
// Main |
| 139 |
{ |
bbs_center(); |
|
case 0: |
|
|
break; |
|
|
case -1: |
|
|
log_error ("select() error!\n"); |
|
|
break; |
|
|
default: |
|
|
if (FD_ISSET (0, &testfds)) |
|
|
{ |
|
|
ch = igetch (); |
|
| 140 |
|
|
| 141 |
switch (ch) |
// Logout |
| 142 |
{ |
bbs_exit(); |
| 143 |
case 0: |
log_std("User logout\n"); |
| 144 |
return 0; |
|
| 145 |
default: |
MYSQL *db = db_open(); |
| 146 |
strcpy (action, menu_control (&bbs_menu, ch)); |
if (db == NULL) |
|
if (strcmp (action, "EXITBBS") == 0) |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
break; |
|
|
} |
|
|
if (time (0) - t_last_action >= 10) |
|
| 147 |
{ |
{ |
| 148 |
t_last_action = time (0); |
return -1; |
|
show_active_board (); |
|
| 149 |
} |
} |
|
} |
|
| 150 |
|
|
| 151 |
return 0; |
user_online_del(db); |
| 152 |
|
|
| 153 |
|
mysql_close(db); |
| 154 |
|
|
| 155 |
|
return 0; |
| 156 |
} |
} |