| 1 |
/*************************************************************************** |
/*************************************************************************** |
| 2 |
bbsd.c - description |
bbs_main.c - description |
| 3 |
------------------- |
------------------- |
| 4 |
begin : Mon Oct 18 2004 |
begin : Mon Oct 18 2004 |
| 5 |
copyright : (C) 2004 by Leaflet |
copyright : (C) 2004 by Leaflet |
| 17 |
|
|
| 18 |
#include "bbs.h" |
#include "bbs.h" |
| 19 |
#include "common.h" |
#include "common.h" |
| 20 |
|
#include "io.h" |
| 21 |
|
#include "menu.h" |
| 22 |
|
#include <time.h> |
| 23 |
|
#include <fcntl.h> |
| 24 |
|
#include <unistd.h> |
| 25 |
|
#include <string.h> |
| 26 |
|
|
| 27 |
int |
int |
| 28 |
bbs_main() |
bbs_main () |
| 29 |
{ |
{ |
| 30 |
bbs_welcome(); |
char temp[256]; |
| 31 |
|
int ret; |
| 32 |
|
|
| 33 |
|
set_input_echo (0); |
| 34 |
|
|
| 35 |
|
bbs_info (); |
| 36 |
|
|
| 37 |
|
//Welcome |
| 38 |
|
bbs_welcome (); |
| 39 |
|
|
| 40 |
|
//Login |
| 41 |
|
ret = bbs_login (); |
| 42 |
|
if (ret < 0) |
| 43 |
|
return -1; |
| 44 |
|
clearscr (); |
| 45 |
|
|
| 46 |
|
//BBS Top 10 |
| 47 |
|
strcpy (temp, app_home_dir); |
| 48 |
|
strcat (temp, "data/bbs_top.txt"); |
| 49 |
|
display_file_ex (temp, 1, 1); |
| 50 |
|
|
| 51 |
|
//Main |
| 52 |
|
bbs_center (); |
| 53 |
|
|
| 54 |
|
//Logout |
| 55 |
|
bbs_exit (); |
| 56 |
|
|
| 57 |
|
return 0; |
| 58 |
|
} |
| 59 |
|
|
| 60 |
|
int |
| 61 |
|
bbs_info () |
| 62 |
|
{ |
| 63 |
|
prints ("»¶Ó¹âÁÙ \033[1;33m%s \033[32m[%s] \033[37m( %s )\r\n", |
| 64 |
|
BBS_name, BBS_server, app_version); |
| 65 |
|
|
| 66 |
|
iflush (); |
| 67 |
|
|
| 68 |
|
return 0; |
| 69 |
|
} |
| 70 |
|
|
| 71 |
|
int |
| 72 |
|
bbs_exit () |
| 73 |
|
{ |
| 74 |
|
char temp[256]; |
| 75 |
|
|
| 76 |
|
strcpy (temp, app_home_dir); |
| 77 |
|
strcat (temp, "data/goodbye.txt"); |
| 78 |
|
display_file_ex (temp, 1, 0); |
| 79 |
|
|
| 80 |
|
sleep (1); |
| 81 |
|
|
| 82 |
|
return 0; |
| 83 |
|
} |
| 84 |
|
|
| 85 |
|
int |
| 86 |
|
bbs_center () |
| 87 |
|
{ |
| 88 |
|
int ch, result; |
| 89 |
|
char action[MAX_MENUACTION_LENGTH]; |
| 90 |
|
time_t t_last_action; |
| 91 |
|
fd_set inputs, testfds; |
| 92 |
|
struct timeval timeout; |
| 93 |
|
|
| 94 |
|
FD_ZERO (&inputs); |
| 95 |
|
FD_SET (0, &inputs); |
| 96 |
|
|
| 97 |
|
t_last_action = time (0); |
| 98 |
|
|
| 99 |
|
clearscr (); |
| 100 |
|
|
| 101 |
|
show_top (""); |
| 102 |
|
show_active_board (); |
| 103 |
|
display_menu (get_menu (&bbs_menu, "TOPMENU")); |
| 104 |
|
show_bottom (""); |
| 105 |
|
|
| 106 |
|
while (1) |
| 107 |
|
{ |
| 108 |
|
testfds = inputs; |
| 109 |
|
timeout.tv_sec = 0; |
| 110 |
|
timeout.tv_usec = 100000; |
| 111 |
|
|
| 112 |
|
result = select (FD_SETSIZE, &testfds, (fd_set *) NULL, |
| 113 |
|
(fd_set *) NULL, &timeout); |
| 114 |
|
|
| 115 |
|
switch (result) |
| 116 |
|
{ |
| 117 |
|
case 0: |
| 118 |
|
break; |
| 119 |
|
case -1: |
| 120 |
|
log_error ("select() error!\n"); |
| 121 |
|
break; |
| 122 |
|
default: |
| 123 |
|
if (FD_ISSET (0, &testfds)) |
| 124 |
|
{ |
| 125 |
|
ch = igetch (); |
| 126 |
|
|
| 127 |
|
switch (ch) |
| 128 |
|
{ |
| 129 |
|
case 0: |
| 130 |
|
return 0; |
| 131 |
|
default: |
| 132 |
|
strcpy (action, menu_control (&bbs_menu, ch)); |
| 133 |
|
if (strcmp (action, "EXITBBS") == 0) |
| 134 |
|
return 0; |
| 135 |
|
} |
| 136 |
|
} |
| 137 |
|
break; |
| 138 |
|
} |
| 139 |
|
if (time (0) - t_last_action >= 10) |
| 140 |
|
{ |
| 141 |
|
t_last_action = time (0); |
| 142 |
|
show_active_board (); |
| 143 |
|
} |
| 144 |
|
} |
| 145 |
|
|
| 146 |
return 0; |
return 0; |
| 147 |
} |
} |