| 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 "bbs_cmd.h" |
| 23 |
|
#include <time.h> |
| 24 |
|
#include <fcntl.h> |
| 25 |
|
#include <unistd.h> |
| 26 |
|
#include <string.h> |
| 27 |
|
|
| 28 |
int |
int |
| 29 |
bbs_main() |
bbs_main () |
| 30 |
{ |
{ |
| 31 |
|
char temp[256]; |
| 32 |
int ret; |
int ret; |
|
|
|
|
bbs_info(); |
|
|
bbs_welcome(); |
|
| 33 |
|
|
| 34 |
ret = bbs_login(); |
set_input_echo (0); |
| 35 |
|
|
| 36 |
|
bbs_info (); |
| 37 |
|
|
| 38 |
|
//Welcome |
| 39 |
|
bbs_welcome (); |
| 40 |
|
|
| 41 |
|
//Login |
| 42 |
|
ret = bbs_login (); |
| 43 |
if (ret < 0) |
if (ret < 0) |
| 44 |
return -1; |
return -1; |
| 45 |
|
clearscr (); |
| 46 |
bbs_center(); |
|
| 47 |
|
//BBS Top 10 |
| 48 |
|
strcpy (temp, app_home_dir); |
| 49 |
|
strcat (temp, "data/bbs_top.txt"); |
| 50 |
|
display_file_ex (temp, 1, 1); |
| 51 |
|
|
| 52 |
|
//Main |
| 53 |
|
bbs_center (); |
| 54 |
|
|
| 55 |
bbs_exit(); |
//Logout |
| 56 |
|
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 action[MAX_MENUACTION_LENGTH]; |
| 91 |
show_bottom(); |
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 |
|
show_bottom (""); |
| 105 |
|
display_menu (get_menu (&bbs_menu, "TOPMENU")); |
| 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_NULL: |
| 131 |
|
return 0; |
| 132 |
|
default: |
| 133 |
|
strcpy (action, menu_control (&bbs_menu, ch)); |
| 134 |
|
switch (get_cmd_value (action)) |
| 135 |
|
{ |
| 136 |
|
case EXITBBS: |
| 137 |
|
return 0; |
| 138 |
|
case BBSNET: |
| 139 |
|
bbs_net (); |
| 140 |
|
clearscr (); |
| 141 |
|
show_top (""); |
| 142 |
|
show_active_board (); |
| 143 |
|
show_bottom (""); |
| 144 |
|
display_current_menu (&bbs_menu); |
| 145 |
|
break; |
| 146 |
|
case UNKNOWN_CMD: |
| 147 |
|
break; |
| 148 |
|
} |
| 149 |
|
} |
| 150 |
|
} |
| 151 |
|
break; |
| 152 |
|
} |
| 153 |
|
if (time (0) - t_last_action >= 10) |
| 154 |
|
{ |
| 155 |
|
t_last_action = time (0); |
| 156 |
|
show_active_board (); |
| 157 |
|
show_bottom (""); |
| 158 |
|
} |
| 159 |
|
} |
| 160 |
|
|
| 161 |
return 0; |
return 0; |
| 162 |
} |
} |