| 18 |
#include "bbs.h" |
#include "bbs.h" |
| 19 |
#include "common.h" |
#include "common.h" |
| 20 |
#include "io.h" |
#include "io.h" |
| 21 |
|
#include "menu.h" |
| 22 |
|
#include <time.h> |
| 23 |
|
#include <fcntl.h> |
| 24 |
|
#include <unistd.h> |
| 25 |
|
|
| 26 |
|
#define ACTIVE_BOARD_HEIGHT 8 |
| 27 |
|
|
| 28 |
int |
int |
| 29 |
bbs_main() |
bbs_main () |
| 30 |
{ |
{ |
| 31 |
char temp[256]; |
char temp[256]; |
| 32 |
int ret; |
int ret; |
| 33 |
|
|
| 34 |
|
set_input_echo (0); |
| 35 |
|
|
| 36 |
|
bbs_info (); |
| 37 |
|
|
| 38 |
//Welcome |
//Welcome |
| 39 |
bbs_info(); |
bbs_welcome (); |
|
bbs_welcome(); |
|
| 40 |
|
|
| 41 |
//Login |
//Login |
| 42 |
ret = bbs_login(); |
ret = bbs_login (); |
| 43 |
if (ret < 0) |
if (ret < 0) |
| 44 |
return -1; |
return -1; |
| 45 |
|
clearscr (); |
| 46 |
|
|
| 47 |
//BBS Top 10 |
//BBS Top 10 |
| 48 |
strcpy (temp, app_home_dir); |
strcpy (temp, app_home_dir); |
| 49 |
strcat (temp, "data/bbs_top.txt"); |
strcat (temp, "data/bbs_top.txt"); |
| 50 |
clearscr(); |
display_file_ex (temp, 1, 1); |
|
display_file(temp); |
|
|
press_any_key(); |
|
| 51 |
|
|
| 52 |
//Main |
//Main |
| 53 |
bbs_center(); |
bbs_center (); |
| 54 |
|
|
| 55 |
//Logout |
//Logout |
| 56 |
bbs_exit(); |
bbs_exit (); |
| 57 |
|
|
| 58 |
return 0; |
return 0; |
| 59 |
} |
} |
| 60 |
|
|
| 61 |
int |
int |
| 62 |
bbs_info() |
bbs_info () |
| 63 |
{ |
{ |
| 64 |
prints( |
prints ("»¶Ó¹âÁÙ \033[1;33m%s \033[32m[%s] \033[37m( %s )\r\n", |
| 65 |
"\033[1;37m»¶Ó¹âÁÙ \033[33m%s \033[32m[%s] \033[37m( %s )\r\n", |
BBS_name, BBS_server, app_version); |
| 66 |
BBS_name, BBS_server, app_version); |
|
| 67 |
|
iflush (); |
|
iflush(); |
|
| 68 |
|
|
| 69 |
return 0; |
return 0; |
| 70 |
} |
} |
| 71 |
|
|
| 72 |
int |
int |
| 73 |
bbs_exit() |
bbs_exit () |
| 74 |
{ |
{ |
| 75 |
prints("\033[0;37m\r\n"); |
char temp[256]; |
| 76 |
iflush(); |
|
| 77 |
|
strcpy (temp, app_home_dir); |
| 78 |
|
strcat (temp, "data/goodbye.txt"); |
| 79 |
|
display_file_ex (temp, 1, 0); |
| 80 |
|
|
| 81 |
|
sleep (1); |
| 82 |
|
|
|
sleep(1); |
|
|
|
|
| 83 |
return 0; |
return 0; |
| 84 |
} |
} |
| 85 |
|
|
| 86 |
int |
int |
| 87 |
bbs_center() |
bbs_center () |
| 88 |
{ |
{ |
| 89 |
show_top(); |
int ch, result; |
| 90 |
|
char key; |
| 91 |
|
time_t t_last_action; |
| 92 |
|
fd_set inputs, testfds; |
| 93 |
|
struct timeval timeout; |
| 94 |
|
|
| 95 |
|
FD_ZERO (&inputs); |
| 96 |
|
FD_SET (0, &inputs); |
| 97 |
|
|
| 98 |
|
t_last_action = time (0); |
| 99 |
|
|
| 100 |
|
clearscr (); |
| 101 |
|
|
| 102 |
|
show_top ("²âÊÔ"); |
| 103 |
|
show_active_board (); |
| 104 |
|
display_menu (&bbs_menu); |
| 105 |
|
show_bottom ("²âÊÔ"); |
| 106 |
|
|
| 107 |
|
while (1) |
| 108 |
|
{ |
| 109 |
|
testfds = inputs; |
| 110 |
|
timeout.tv_sec = 0; |
| 111 |
|
timeout.tv_usec = 100000; |
| 112 |
|
|
| 113 |
|
result = select (FD_SETSIZE, &testfds, (fd_set *) NULL, |
| 114 |
|
(fd_set *) NULL, &timeout); |
| 115 |
|
|
| 116 |
|
switch (result) |
| 117 |
|
{ |
| 118 |
|
case 0: |
| 119 |
|
break; |
| 120 |
|
case -1: |
| 121 |
|
log_error ("select() error!\n"); |
| 122 |
|
break; |
| 123 |
|
default: |
| 124 |
|
if (FD_ISSET (0, &testfds)) |
| 125 |
|
{ |
| 126 |
|
ch = igetch (); |
| 127 |
|
|
| 128 |
|
switch (ch) |
| 129 |
|
{ |
| 130 |
|
case KEY_LEFT: |
| 131 |
|
ch = 'G'; |
| 132 |
|
default: |
| 133 |
|
key = menu_control (&bbs_menu, ch); |
| 134 |
|
switch (key) |
| 135 |
|
{ |
| 136 |
|
case 'G': |
| 137 |
|
return 0; |
| 138 |
|
} |
| 139 |
|
} |
| 140 |
|
} |
| 141 |
|
break; |
| 142 |
|
} |
| 143 |
|
if (time (0) - t_last_action >= 10) |
| 144 |
|
{ |
| 145 |
|
t_last_action = time (0); |
| 146 |
|
show_active_board (); |
| 147 |
|
} |
| 148 |
|
} |
| 149 |
|
|
| 150 |
show_bottom(); |
return 0; |
| 151 |
|
} |
| 152 |
|
|
| 153 |
|
int |
| 154 |
|
show_top (char *status) |
| 155 |
|
{ |
| 156 |
|
char buffer[256]; |
| 157 |
|
|
| 158 |
|
str_space (buffer, 20 - strlen (BBS_current_section_name)); |
| 159 |
|
|
| 160 |
|
moveto (1, 0); |
| 161 |
|
prints ("\033[1;44;33m%-20s \033[37m%20s" |
| 162 |
|
" %s\033[33mÌÖÂÛÇø [%s]\033[m", |
| 163 |
|
status, BBS_name, buffer, BBS_current_section_name); |
| 164 |
|
iflush (); |
| 165 |
|
|
| 166 |
|
return 0; |
| 167 |
|
} |
| 168 |
|
|
| 169 |
|
int |
| 170 |
|
show_bottom (char *msg) |
| 171 |
|
{ |
| 172 |
|
char str_time[256], str_time_onine[20], buffer[256]; |
| 173 |
|
time_t time_online; |
| 174 |
|
struct tm *tm_online; |
| 175 |
|
|
| 176 |
|
get_time_str (str_time, 256); |
| 177 |
|
str_space (buffer, 33 - strlen (BBS_username)); |
| 178 |
|
|
| 179 |
|
time_online = time (0) - BBS_login_tm; |
| 180 |
|
tm_online = gmtime (&time_online); |
| 181 |
|
|
| 182 |
|
moveto (screen_lines, 0); |
| 183 |
|
prints ("\033[1;44;33m[\033[36m%s\033[33m]" |
| 184 |
|
"%sÕʺÅ[\033[36m%s\033[33m]" |
| 185 |
|
"[\033[36m%1d\033[33m:\033[36m%2d\033[33m:\033[36m%2d\033[33m]\033[m", |
| 186 |
|
str_time, buffer, BBS_username, tm_online->tm_mday - 1, |
| 187 |
|
tm_online->tm_hour, tm_online->tm_min); |
| 188 |
|
iflush (); |
| 189 |
|
|
| 190 |
|
return 0; |
| 191 |
|
} |
| 192 |
|
|
| 193 |
|
int |
| 194 |
|
show_active_board () |
| 195 |
|
{ |
| 196 |
|
char filename[256], buffer[260]; |
| 197 |
|
FILE *fin; |
| 198 |
|
int i, j; |
| 199 |
|
static long int line; |
| 200 |
|
|
| 201 |
|
sprintf (filename, "%sdata/active_board.txt", app_home_dir); |
| 202 |
|
|
| 203 |
|
clrline (3, 2 + ACTIVE_BOARD_HEIGHT); |
| 204 |
|
|
| 205 |
|
moveto (3, 0); |
| 206 |
|
|
| 207 |
|
if ((fin = fopen (filename, "r")) != NULL) |
| 208 |
|
{ |
| 209 |
|
for (j = 0; j < line; j++) |
| 210 |
|
{ |
| 211 |
|
if (fgets (buffer, 255, fin) == NULL) |
| 212 |
|
{ |
| 213 |
|
line = 0; |
| 214 |
|
rewind (fin); |
| 215 |
|
break; |
| 216 |
|
} |
| 217 |
|
} |
| 218 |
|
|
| 219 |
|
for (j = 0; j < ACTIVE_BOARD_HEIGHT; j++) |
| 220 |
|
{ |
| 221 |
|
if (fgets (buffer, 255, fin) == NULL) |
| 222 |
|
{ |
| 223 |
|
line = 0; |
| 224 |
|
if (j == 0) |
| 225 |
|
{ |
| 226 |
|
rewind (fin); |
| 227 |
|
if (fgets (buffer, 255, fin) == NULL) |
| 228 |
|
{ |
| 229 |
|
break; |
| 230 |
|
} |
| 231 |
|
} |
| 232 |
|
else |
| 233 |
|
{ |
| 234 |
|
break; |
| 235 |
|
} |
| 236 |
|
} |
| 237 |
|
line++; |
| 238 |
|
i = strlen (buffer); |
| 239 |
|
if (buffer[i - 1] == '\n' && buffer[i - 2] != '\r') |
| 240 |
|
{ |
| 241 |
|
buffer[i - 1] = '\r'; |
| 242 |
|
buffer[i] = '\n'; |
| 243 |
|
buffer[i + 1] = '\0'; |
| 244 |
|
} |
| 245 |
|
prints (buffer); |
| 246 |
|
iflush (); |
| 247 |
|
} |
| 248 |
|
fclose (fin); |
| 249 |
|
} |
| 250 |
|
|
| 251 |
return 0; |
return 0; |
| 252 |
} |
} |