/[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.16 by sysadm, Thu Mar 17 10:48:46 2005 UTC Revision 1.32 by sysadm, Wed Apr 30 09:18:19 2025 UTC
# Line 1  Line 1 
1  /***************************************************************************  /***************************************************************************
2                            bbs_main.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
6      email                : leaflet@leafok.com          email                : leaflet@leafok.com
7   ***************************************************************************/   ***************************************************************************/
8    
9  /***************************************************************************  /***************************************************************************
# Line 15  Line 15 
15   *                                                                         *   *                                                                         *
16   ***************************************************************************/   ***************************************************************************/
17    
18    #include "bbs_main.h"
19  #include "bbs.h"  #include "bbs.h"
20    #include "welcome.h"
21    #include "login.h"
22    #include "user_priv.h"
23  #include "common.h"  #include "common.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>
32    
33  #define ACTIVE_BOARD_HEIGHT     8  int bbs_info()
   
 int  
 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);
   
   set_input_echo (0);  
   
   bbs_info ();  
   
   //Welcome  
   bbs_welcome ();  
   
   //Login  
   ret = bbs_login ();  
   if (ret < 0)  
     return -1;  
   clearscr ();  
   
   //BBS Top 10  
   strcpy (temp, app_home_dir);  
   strcat (temp, "data/bbs_top.txt");  
   display_file_ex (temp, 1, 1);  
   
   //Main  
   bbs_center ();  
37    
38    //Logout          iflush();
   bbs_exit ();  
39    
40    return 0;          return 0;
41  }  }
42    
43  int  int bbs_exit()
 bbs_info ()  
44  {  {
45    prints ("»¶Ó­¹âÁÙ \033[1;33m%s \033[32m[%s]  \033[37m( %s )\r\n",          char temp[256];
           BBS_name, BBS_server, app_version);  
46    
47    iflush ();          strcpy(temp, app_home_dir);
48            strcat(temp, "data/goodbye.txt");
49            display_file_ex(temp, 1, 0);
50    
51    return 0;          sleep(1);
52    
53            return 0;
54  }  }
55    
56  int  int bbs_center()
 bbs_exit ()  
57  {  {
58    char temp[256];          int ch, result, redraw;
59            char temp[256];
60    strcpy (temp, app_home_dir);          time_t t_last_action;
   strcat (temp, "data/goodbye.txt");  
   display_file_ex (temp, 1, 0);  
61    
62    sleep (1);          BBS_last_access_tm = t_last_action = time(0);
63    
64    return 0;          clearscr();
 }  
   
 int  
 bbs_center ()  
 {  
   int ch, result;  
   char key;  
   time_t t_last_action;  
   fd_set inputs, testfds;  
   struct timeval timeout;  
   
   FD_ZERO (&inputs);  
   FD_SET (0, &inputs);  
   
   t_last_action = time (0);  
   
   clearscr ();  
   
   show_top ("²âÊÔ");  
   show_active_board ();  
   display_menu (&bbs_main_menu);  
   show_bottom ("²âÊÔ");  
   
   while (1)  
     {  
       testfds = inputs;  
       timeout.tv_sec = 0;  
       timeout.tv_usec = 100000;  
65    
66        result = select (FD_SETSIZE, &testfds, (fd_set *) NULL,          show_top("");
67                         (fd_set *) NULL, &timeout);          show_active_board();
68            show_bottom("");
69            display_menu(get_menu(&bbs_menu, "TOPMENU"));
70    
71        switch (result)          while (!SYS_exit)
72          {          {
73          case 0:                  ch = igetch();
           break;  
         case -1:  
           log_error ("select() error!\n");  
           break;  
         default:  
           if (FD_ISSET (0, &testfds))  
             {  
               ch = igetch ();  
74    
75                switch (ch)                  if (time(0) - t_last_action >= 10)
76                  {                  {
77                  case KEY_LEFT:                          t_last_action = time(0);
78                    ch = 'G';                          show_active_board();
79                            show_bottom("");
80                    }
81    
82                    switch (ch)
83                    {
84                    case KEY_NULL:
85                            return 0;
86                    case KEY_TIMEOUT:
87                            if (time(0) - BBS_last_access_tm >= MAX_DELAY_TIME)
88                            {
89                                    return -1;
90                            }
91                            continue;
92                  default:                  default:
93                    key = menu_control (&bbs_main_menu, ch);                          redraw = 1;
94                    switch (key)                          switch (menu_control(&bbs_menu, ch))
95                      {                          {
96                      case 'G':                          case EXITBBS:
97                        return 0;                                  return 0;
98                      }                          case REDRAW:
99                                    break;
100                            case NOREDRAW:
101                            case UNKNOWN_CMD:
102                            default:
103                                    redraw = 0;
104                                    break;
105                            }
106                            if (redraw)
107                            {
108                                    clearscr();
109                                    show_top("");
110                                    show_active_board();
111                                    show_bottom("");
112                                    display_current_menu(&bbs_menu);
113                            }
114                  }                  }
115              }                  BBS_last_access_tm = time(0);
           break;  
116          }          }
       if (time (0) - t_last_action >= 10)  
         {  
           t_last_action = time (0);  
           show_active_board ();  
         }  
     }  
117    
118    return 0;          return 0;
119  }  }
120    
121  int  int bbs_main()
 show_top (char *status)  
122  {  {
123    char buffer[256];          char temp[256];
124            int ret;
125    
126    str_space (buffer, 20 - strlen (BBS_current_section_name));          set_input_echo(0);
127    
128    moveto (1, 0);          bbs_info();
   prints ("\033[1;44;33m%-20s \033[37m%20s"  
           "         %s\033[33mÌÖÂÛÇø [%s]\033[m",  
           status, BBS_name, buffer, BBS_current_section_name);  
   iflush ();  
129    
130    return 0;          // Welcome
131  }          bbs_welcome();
132    
133  int          // Login
134  show_bottom (char *msg)          ret = bbs_login();
135  {          if (ret < 0)
136    char str_time[256], str_time_onine[20], buffer[256];                  return -1;
137    time_t time_online;          log_std("User \"%s\"(%ld) login from %s:%d\n",
138    struct tm *tm_online;                          BBS_username, BBS_priv.uid, hostaddr_client, port_client);
139            clearscr();
   get_time_str (str_time, 256);  
   str_space (buffer, 33 - strlen (BBS_username));  
   
   time_online = time (0) - BBS_login_tm;  
   tm_online = gmtime (&time_online);  
   
   moveto (screen_lines, 0);  
   prints ("\033[1;44;33m[\033[36m%s\033[33m]"  
           "%sÕʺÅ[\033[36m%s\033[33m]"  
           "[\033[36m%1d\033[33m:\033[36m%2d\033[33m:\033[36m%2d\033[33m]\033[m",  
           str_time, buffer, BBS_username, tm_online->tm_mday - 1,  
           tm_online->tm_hour, tm_online->tm_min);  
   iflush ();  
140    
141    return 0;          // BBS Top 10
142  }          strcpy(temp, app_home_dir);
143            strcat(temp, "data/bbs_top.txt");
144            display_file_ex(temp, 1, 1);
145    
146  int          // Main
147  show_active_board ()          bbs_center();
 {  
   char filename[256], buffer[260];  
   FILE *fin;  
   int i, j;  
   static long int line;  
148    
149    sprintf (filename, "%sdata/active_board.txt", app_home_dir);          // Logout
150            bbs_exit();
151    clrline (3, 2 + ACTIVE_BOARD_HEIGHT);          log_std("User logout\n");
   
   moveto (3, 0);  
   
   if ((fin = fopen (filename, "r")) != NULL)  
     {  
       for (j = 0; j < line; j++)  
         {  
           if (fgets (buffer, 255, fin) == NULL)  
             {  
               line = 0;  
               rewind (fin);  
               break;  
             }  
         }  
   
       for (j = 0; j < ACTIVE_BOARD_HEIGHT; j++)  
         {  
           if (fgets (buffer, 255, fin) == NULL)  
             {  
               line = 0;  
               if (j == 0)  
                 {  
                   rewind (fin);  
                   if (fgets (buffer, 255, fin) == NULL)  
                     {  
                       break;  
                     }  
                 }  
               else  
                 {  
                   break;  
                 }  
             }  
           line++;  
           i = strlen (buffer);  
           if (buffer[i - 1] == '\n' && buffer[i - 2] != '\r')  
             {  
               buffer[i - 1] = '\r';  
               buffer[i] = '\n';  
               buffer[i + 1] = '\0';  
             }  
           prints (buffer);  
           iflush ();  
         }  
       fclose (fin);  
     }  
152    
153    return 0;          return 0;
154  }  }


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

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