/[LeafOK_CVS]/lbbs/src/bbs_main.c
ViewVC logotype

Diff of /lbbs/src/bbs_main.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.15 by sysadm, Wed Mar 2 16:33:49 2005 UTC Revision 1.16 by sysadm, Thu Mar 17 10:48:46 2005 UTC
# Line 18  Line 18 
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);    set_input_echo (0);
35      
36    bbs_info();    bbs_info ();
37    
38    //Welcome    //Welcome
39    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();    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    display_file_ex (temp, 1, 1);    display_file_ex (temp, 1, 1);
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;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    char temp[256];    char temp[256];
76      
77    strcpy (temp, app_home_dir);    strcpy (temp, app_home_dir);
78    strcat (temp, "data/goodbye.txt");    strcat (temp, "data/goodbye.txt");
79    display_file_ex (temp, 1, 0);    display_file_ex (temp, 1, 0);
80    
81    sleep(1);    sleep (1);
82      
83    return 0;    return 0;
84  }  }
85    
86  int  int
87  bbs_center()  bbs_center ()
88  {  {
89      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 ();    clearscr ();
101    
102    show_top ("²âÊÔ");    show_top ("²âÊÔ");
103      show_active_board ();
104      display_menu (&bbs_main_menu);
105    show_bottom ("²âÊÔ");    show_bottom ("²âÊÔ");
106      
107    igetch();    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_main_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    return 0;    return 0;
151  }  }
# Line 95  int Line 154  int
154  show_top (char *status)  show_top (char *status)
155  {  {
156    char buffer[256];    char buffer[256];
157    
158    str_space (buffer, 20-strlen(BBS_current_section_name));    str_space (buffer, 20 - strlen (BBS_current_section_name));
159    
160    moveto (1, 0);    moveto (1, 0);
161    prints ("\033[1;44;33m%-20s \033[37m%20s"    prints ("\033[1;44;33m%-20s \033[37m%20s"
162          "         %s\033[33mÌÖÂÛÇø [%s]\033[m",            "         %s\033[33mÌÖÂÛÇø [%s]\033[m",
163          status, BBS_name, buffer, BBS_current_section_name);            status, BBS_name, buffer, BBS_current_section_name);
164    iflush ();    iflush ();
165    
166    return 0;    return 0;
# Line 115  show_bottom (char *msg) Line 174  show_bottom (char *msg)
174    struct tm *tm_online;    struct tm *tm_online;
175    
176    get_time_str (str_time, 256);    get_time_str (str_time, 256);
177    str_space (buffer, 33-strlen(BBS_username));    str_space (buffer, 33 - strlen (BBS_username));
178      
179    time_online = time (0) - BBS_login_tm;    time_online = time (0) - BBS_login_tm;
180    tm_online = gmtime (&time_online);    tm_online = gmtime (&time_online);
181    
182    moveto (screen_lines, 0);    moveto (screen_lines, 0);
183    prints ("\033[1;44;33m[\033[36m%s\033[33m]"    prints ("\033[1;44;33m[\033[36m%s\033[33m]"
184          "%sÕʺÅ[\033[36m%s\033[33m]"            "%sÕʺÅ[\033[36m%s\033[33m]"
185          "[\033[36m%1d\033[33m:\033[36m%2d\033[33m:\033[36m%2d\033[33m]\033[m",            "[\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,            str_time, buffer, BBS_username, tm_online->tm_mday - 1,
187          tm_online->tm_hour, tm_online->tm_min);            tm_online->tm_hour, tm_online->tm_min);
188    iflush ();    iflush ();
189    
190    return 0;    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;
252    }


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1