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

Diff of /lbbs/src/bbs_net.c

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

Revision 1.6 by sysadm, Mon Mar 21 18:14:00 2005 UTC Revision 1.25 by sysadm, Tue May 6 05:31:26 2025 UTC
# Line 1  Line 1 
1  /***************************************************************************  /***************************************************************************
2                            bbs_net.c  -  description                                                    bbs_net.c  -  description
3                               -------------------                                                           -------------------
4      begin                : Mon Oct 18 2004          Copyright            : (C) 2004-2025 by Leaflet
5      copyright            : (C) 2004 by Leaflet          Email                : leaflet@leafok.com
     email                : leaflet@leafok.com  
6   ***************************************************************************/   ***************************************************************************/
7    
8  /***************************************************************************  /***************************************************************************
9   *                                                                         *   *                                                                         *
10   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
11   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
12   *   the Free Software Foundation; either version 2 of the License, or     *   *   the Free Software Foundation; either version 3 of the License, or     *
13   *   (at your option) any later version.                                   *   *   (at your option) any later version.                                   *
14   *                                                                         *   *                                                                         *
15   ***************************************************************************/   ***************************************************************************/
16    
17  #include "bbs.h"  #include "bbs.h"
18  #include "common.h"  #include "common.h"
19    #include "log.h"
20  #include "io.h"  #include "io.h"
21    #include "screen.h"
22  #include "menu.h"  #include "menu.h"
23  #include "tcplib.h"  #include "tcplib.h"
24  #include <stdio.h>  #include <stdio.h>
# Line 30  Line 31 
31  #include <unistd.h>  #include <unistd.h>
32  #include <netdb.h>  #include <netdb.h>
33    
34  #define TIME_OUT                15  #define TIME_OUT 15
35  #define MAX_PROCESS_BAR_LEN     30  #define MAX_PROCESS_BAR_LEN 30
36  #define MAXSTATION              26*2  #define MAXSTATION 26 * 2
37  #define STATION_PER_LINE        4  #define STATION_PER_LINE 4
38    
39  struct _bbsnet_conf  struct _bbsnet_conf
40  {  {
41    char host1[20];          char host1[20];
42    char host2[40];          char host2[40];
43    char ip[40];          char ip[40];
44    int port;          in_port_t port;
45  } bbsnet_conf[MAXSTATION];  } bbsnet_conf[MAXSTATION];
46    
47  MENU_SET bbsnet_menu;  MENU_SET bbsnet_menu;
48    
49  int  int load_bbsnet_conf(const char *file_config)
 load_bbsnet_conf (const char *file_config)  
50  {  {
51    FILE *fp;          FILE *fp;
52    MENU *p_menu;          MENU *p_menu;
53    MENU_ITEM *p_menuitem;          MENU_ITEM *p_menuitem;
54    char t[256], *t1, *t2, *t3, *t4;          char t[256], *t1, *t2, *t3, *t4, *saveptr;
55    int item_count = 0;          int item_count = 0;
   
   fp = fopen (file_config, "r");  
   if (fp == NULL)  
     return -1;  
   
   p_menu = bbsnet_menu.p_menu[0] = malloc (sizeof (MENU));  
   strcpy (p_menu->name, "BBSNET");  
   p_menu->title.show = 0;  
   p_menu->screen.show = 0;  
   
   while (fgets (t, 255, fp) && item_count < MAXSTATION)  
     {  
       t1 = strtok (t, " \t");  
       t2 = strtok (NULL, " \t\n");  
       t3 = strtok (NULL, " \t\n");  
       t4 = strtok (NULL, " \t\n");  
   
       if (t1[0] == '#' || t1[0] == '*' || t1 == NULL || t2 == NULL  
           || t3 == NULL)  
         continue;  
       strncpy (bbsnet_conf[item_count].host1, t2, 18);  
       bbsnet_conf[item_count].host1[18] = 0;  
       strncpy (bbsnet_conf[item_count].host2, t1, 36);  
       bbsnet_conf[item_count].host2[36] = 0;  
       strncpy (bbsnet_conf[item_count].ip, t3, 36);  
       bbsnet_conf[item_count].ip[36] = 0;  
       bbsnet_conf[item_count].port = t4 ? atoi (t4) : 23;  
   
       p_menuitem = p_menu->items[item_count] = malloc (sizeof (MENU_ITEM));  
       p_menuitem->row = 2 + item_count / STATION_PER_LINE;  
       p_menuitem->col = 5 + item_count % STATION_PER_LINE * 20;  
       sprintf (p_menuitem->action, "%d", item_count);  
       p_menuitem->submenu = 0;  
       p_menuitem->priv = 0;  
       p_menuitem->level = 0;  
       p_menuitem->display = 0;  
       p_menuitem->name[0] =  
         (item_count < MAXSTATION / 2 ? 'A' + item_count : 'a' + item_count);  
       p_menuitem->name[1] = '\0';  
       sprintf (p_menuitem->text, "%c. %s",  
                p_menuitem->name[0], bbsnet_conf[item_count].host1);  
   
       item_count++;  
     }  
   fclose (fp);  
   
   p_menu->item_count = item_count;  
   p_menu->item_cur_pos = 0;  
   
   bbsnet_menu.menu_count = 1;  
   bbsnet_menu.menu_select_depth = 0;  
   bbsnet_menu.p_menu_select[0] = bbsnet_menu.p_menu[0];  
56    
57    return 0;          fp = fopen(file_config, "r");
58  }          if (fp == NULL)
59            {
60                    return -1;
61            }
62    
63  // from Maple-hightman          p_menu = bbsnet_menu.p_menu[0] = malloc(sizeof(MENU));
64  // added by flyriver, 2001.3.3          strncpy(p_menu->name, "BBSNET", sizeof(p_menu->name) - 1);
65  int          p_menu->name[sizeof(p_menu->name) - 1] = '\0';
66  telnetopt (int fd, char *buf, int max)          p_menu->title.show = 0;
67  {          p_menu->screen.show = 0;
68    unsigned char c, d, e;  
69    int pp = 0;          while (fgets(t, 255, fp) && item_count < MAXSTATION)
70    unsigned char tmp[30];          {
71                    t1 = strtok_r(t, " \t", &saveptr);
72    while (pp < max)                  t2 = strtok_r(NULL, " \t\n", &saveptr);
73      {                  t3 = strtok_r(NULL, " \t\n", &saveptr);
74        c = buf[pp++];                  t4 = strtok_r(NULL, " \t\n", &saveptr);
75        if (c == 255)  
76          {                  if (t1 == NULL || t2 == NULL || t3 == NULL || t[0] == '#' || t[0] == '*')
77            d = buf[pp++];                  {
78            e = buf[pp++];                          continue;
79            iflush ();                  }
80            if ((d == 253) && (e == 3 || e == 24))  
81              {                  strncpy(bbsnet_conf[item_count].host1, t2, sizeof(bbsnet_conf[item_count].host1) - 1);
82                tmp[0] = 255;                  bbsnet_conf[item_count].host1[sizeof(bbsnet_conf[item_count].host1) - 1] = '\0';
83                tmp[1] = 251;                  strncpy(bbsnet_conf[item_count].host2, t1, sizeof(bbsnet_conf[item_count].host2) - 1);
84                tmp[2] = e;                  bbsnet_conf[item_count].host2[sizeof(bbsnet_conf[item_count].host2) - 1] = '\0';
85                write (fd, tmp, 3);                  strncpy(bbsnet_conf[item_count].ip, t3, sizeof(bbsnet_conf[item_count].ip) - 1);
86                continue;                  bbsnet_conf[item_count].ip[sizeof(bbsnet_conf[item_count].ip) - 1] = '\0';
87              }                  bbsnet_conf[item_count].port = (in_port_t)(t4 ? atoi(t4) : 23);
88            if ((d == 251 || d == 252) && (e == 1 || e == 3 || e == 24))  
89              {                  p_menuitem = p_menu->items[item_count] = malloc(sizeof(MENU_ITEM));
90                tmp[0] = 255;                  p_menuitem->row = 2 + item_count / STATION_PER_LINE;
91                tmp[1] = 253;                  p_menuitem->col = 5 + item_count % STATION_PER_LINE * 20;
92                tmp[2] = e;                  snprintf(p_menuitem->action, sizeof(p_menuitem->action), "%d", item_count);
93                write (fd, tmp, 3);                  p_menuitem->submenu = 0;
94                continue;                  p_menuitem->priv = 0;
95              }                  p_menuitem->level = 0;
96            if (d == 251 || d == 252)                  p_menuitem->display = 0;
97              {                  p_menuitem->name[0] =
98                tmp[0] = 255;                          (char)(item_count < MAXSTATION / 2 ? 'A' + item_count : 'a' + item_count);
99                tmp[1] = 254;                  p_menuitem->name[1] = '\0';
100                tmp[2] = e;                  snprintf(p_menuitem->text, sizeof(p_menuitem->text), "%c. %s",
101                write (fd, tmp, 3);                                   p_menuitem->name[0], bbsnet_conf[item_count].host1);
102                continue;  
103              }                  item_count++;
104            if (d == 253 || d == 254)          }
105              {          fclose(fp);
106                tmp[0] = 255;  
107                tmp[1] = 252;          p_menu->item_count = item_count;
108                tmp[2] = e;          p_menu->item_cur_pos = 0;
109                write (fd, tmp, 3);  
110                continue;          bbsnet_menu.menu_count = 1;
111              }          bbsnet_menu.menu_select_depth = 0;
112            if (d == 250)          bbsnet_menu.p_menu_select[0] = bbsnet_menu.p_menu[0];
113              {  
114                while (e != 240 && pp < max)          return 0;
                 e = buf[pp++];  
               tmp[0] = 255;  
               tmp[1] = 250;  
               tmp[2] = 24;  
               tmp[3] = 0;  
               tmp[4] = 65;  
               tmp[5] = 78;  
               tmp[6] = 83;  
               tmp[7] = 73;  
               tmp[8] = 255;  
               tmp[9] = 240;  
               write (fd, tmp, 10);  
             }  
         }  
       else  
         outc (c);  
     }  
   iflush ();  
   return 0;  
115  }  }
116    
117  static void  static void process_bar(int n, int len)
 process_bar (int n, int len)  
118  {  {
119    char buf[256];          char buf[256];
120    char buf2[256];          char buf2[256];
121    char *ptr;          char *ptr;
122    char *ptr2;          char *ptr2;
123    char *ptr3;          char *ptr3;
124    
125    moveto (4, 0);          moveto(4, 0);
126    prints ("┌───────────────┐\n");          prints(" ------------------------------ \r\n");
127    sprintf (buf2, "            %3d%%              ", n * 100 / len);          snprintf(buf2, sizeof(buf2), "            %3d%%              ", n * 100 / len);
128    ptr = buf;          ptr = buf;
129    ptr2 = buf2;          ptr2 = buf2;
130    ptr3 = buf + n;          ptr3 = buf + n;
131    while (ptr != ptr3)          while (ptr != ptr3)
132      *ptr++ = *ptr2++;                  *ptr++ = *ptr2++;
133    *ptr++ = '\x1b';          *ptr++ = '\x1b';
134    *ptr++ = '[';          *ptr++ = '[';
135    *ptr++ = '4';          *ptr++ = '4';
136    *ptr++ = '4';          *ptr++ = '4';
137    *ptr++ = 'm';          *ptr++ = 'm';
138    while (*ptr2 != '\0')          while (*ptr2 != '\0')
139      *ptr++ = *ptr2++;                  *ptr++ = *ptr2++;
140    *ptr++ = '\0';          *ptr++ = '\0';
141    prints ("│\033[46m%s\033[m│\n", buf);          prints("|\033[46m%s\033[m|\r\n", buf);
142    prints ("└───────────────┘\n");          prints(" ------------------------------ \r\n");
143            iflush();
144  }  }
145    
146  int  int bbsnet_connect(int n)
 bbsnet_connect (int n)  
147  {  {
148    int sock, ch, result, len, loop;          int sock, result, loop;
149    struct sockaddr_in sin;          ssize_t len;
150    char buf[256];          struct sockaddr_in sin;
151    time_t now, t_last_action;          char buf[256];
152    fd_set inputs, testfds;          fd_set inputs, testfds;
153    struct timeval timeout;          struct timeval timeout;
154    struct hostent *pHost = NULL;          struct hostent *pHost = NULL;
155    int rc, rv, tos = 020, i;          int rv, tos = 020, i;
156            char remote_addr[256];
157    prints ("\033[1;32m正在测试往 %s (%s) 的连接,请稍候... \033[m\n",          int remote_port;
158            bbsnet_conf[n].host1, bbsnet_conf[n].ip);          time_t t_used;
159    prints ("\033[1;32m如果在 %d 秒内无法连上,穿梭程序将放弃连接。\033[m\n",          struct tm *tm_used;
160            TIME_OUT);  
161            clearscr();
162    pHost = gethostbyname (bbsnet_conf[n].ip);  
163            moveto(0, 0);
164    if (pHost == NULL)          prints("\033[1;32m正在测试往 %s (%s) 的连接,请稍候... \033[m\r\n",
165      {                     bbsnet_conf[n].host1, bbsnet_conf[n].ip);
166        prints ("\033[1;31m查找主机名失败!\033[m\n");          prints("\033[1;32m如果在 %d 秒内无法连上,穿梭程序将放弃连接。\033[m\r\n",
167        press_any_key ();                     TIME_OUT);
168        return -1;          iflush();
169      }  
170            pHost = gethostbyname(bbsnet_conf[n].ip);
171    sock = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);  
172            if (pHost == NULL)
173    if (sock < 0)          {
174      {                  prints("\033[1;31m查找主机名失败!\033[m\r\n");
175        prints ("\033[1;31m无法创建socket!\033[m\n");                  press_any_key();
176        press_any_key ();                  return -1;
177        return -1;          }
178      }  
179            sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
180    sin.sin_family = AF_INET;  
181    sin.sin_addr.s_addr =          if (sock < 0)
182      (strlen (hostaddr_server) > 0 ? inet_addr (hostaddr_server) : INADDR_ANY);          {
183    sin.sin_port = 0;                  prints("\033[1;31m无法创建socket!\033[m\r\n");
184                    press_any_key();
185    if (bind (sock, (struct sockaddr *) &sin, sizeof (sin)) < 0)                  return -1;
186      {          }
187        log_error ("Bind address %s:%u failed\n",  
188                   inet_ntoa (sin.sin_addr), ntohs (sin.sin_port));          sin.sin_family = AF_INET;
189        return -2;          sin.sin_addr.s_addr =
190      }                  (strnlen(hostaddr_server, sizeof(hostaddr_server)) > 0 ? inet_addr(hostaddr_server) : INADDR_ANY);
191            sin.sin_port = 0;
192    bzero (&sin, sizeof (sin));  
193    sin.sin_family = AF_INET;          if (bind(sock, (struct sockaddr *)&sin, sizeof(sin)) < 0)
194    sin.sin_port = htons (bbsnet_conf[n].port);          {
195    sin.sin_addr = *(struct in_addr *) pHost->h_addr_list[0];                  log_error("Bind address %s:%u failed\n",
196                                      inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));
197                    return -2;
198    prints ("\033[1;32m穿梭进度条提示您当前已使用的时间。\033[m\n");          }
199    process_bar (0, MAX_PROCESS_BAR_LEN);  
200    for (i = 0; i < MAX_PROCESS_BAR_LEN; i++)          bzero(&sin, sizeof(sin));
201      {          sin.sin_family = AF_INET;
202        if (i == 0)          sin.sin_addr = *(struct in_addr *)pHost->h_addr_list[0];
203          rv =          sin.sin_port = htons(bbsnet_conf[n].port);
204            NonBlockConnectEx (sock, (struct sockaddr *) &sin, sizeof (sin),  
205                               500, 1);          strncpy(remote_addr, inet_ntoa(sin.sin_addr), sizeof(remote_addr) - 1);
206        else          remote_addr[sizeof(remote_addr) - 1] = '\0';
207          rv =          remote_port = ntohs(sin.sin_port);
208            NonBlockConnectEx (sock, (struct sockaddr *) &sin, sizeof (sin),  
209                               500, 0);          prints("\033[1;32m穿梭进度条提示您当前已使用的时间。\033[m\r\n");
210        if (rv == ERR_TCPLIB_TIMEOUT)          process_bar(0, MAX_PROCESS_BAR_LEN);
211          {          for (i = 0; i < MAX_PROCESS_BAR_LEN; i++)
212            process_bar (i + 1, MAX_PROCESS_BAR_LEN);          {
213            continue;                  if (i == 0)
214          }                          rv =
215        else if (rv == 0)                                  NonBlockConnectEx(sock, (struct sockaddr *)&sin, sizeof(sin),
216          break;                                                                    500, 1);
217        else                  else
218          {                          rv =
219            prints ("\033[1;31m连接失败!\033[m\n");                                  NonBlockConnectEx(sock, (struct sockaddr *)&sin, sizeof(sin),
220            press_any_key ();                                                                    500, 0);
221            return -1;                  if (rv == ERR_TCPLIB_TIMEOUT)
222          }                  {
223      }                          process_bar(i + 1, MAX_PROCESS_BAR_LEN);
224    if (i == MAX_PROCESS_BAR_LEN)                          continue;
225      {                  }
226        prints ("\033[1;31m连接超时!\033[m\n");                  else if (rv == 0)
       press_any_key ();  
       return -1;  
     }  
   setsockopt (sock, IPPROTO_IP, IP_TOS, &tos, sizeof (int));  
   prints ("\033[1;31m连接成功!\033[m\n");  
   
   FD_ZERO (&inputs);  
   FD_SET (0, &inputs);  
   FD_SET (sock, &inputs);  
   
   t_last_action = time (0);  
   
   loop = 1;  
   
   while (loop)  
     {  
       testfds = inputs;  
       timeout.tv_sec = 0;  
       timeout.tv_usec = 100000;  
   
       result = select (FD_SETSIZE, &testfds, (fd_set *) NULL,  
                        (fd_set *) NULL, &timeout);  
   
       switch (result)  
         {  
         case 0:  
           break;  
         case -1:  
           log_error ("select() error!\n");  
           break;  
         default:  
           if (FD_ISSET (0, &testfds))  
             {  
               len = read (0, buf, 255);  
               if (len == 0)  
227                  {                  {
228                    loop = 0;                          break;
                   break;  
229                  }                  }
230                write (sock, buf, len);                  else
             }  
           if (FD_ISSET (sock, &testfds))  
             {  
               len = read (sock, buf, 255);  
               if (len == 0)  
231                  {                  {
232                    loop = 0;                          prints("\033[1;31m连接失败!\033[m\r\n");
233                    break;                          press_any_key();
234                            return -1;
235                  }                  }
               write (1, buf, len);  
             }  
           break;  
236          }          }
237        if (time (0) - t_last_action >= 10)          if (i == MAX_PROCESS_BAR_LEN)
238          {          {
239            t_last_action = time (0);                  prints("\033[1;31m连接超时!\033[m\r\n");
240                    press_any_key();
241                    return -1;
242          }          }
243      }          setsockopt(sock, IPPROTO_IP, IP_TOS, &tos, sizeof(int));
244    
245    if (close (sock) == -1)          prints("\033[1;31m连接成功!\033[m\r\n");
246      {          log_std("BBSNET connect to %s:%d\n", remote_addr, remote_port);
       log_error ("Close socket failed\n");  
     }  
247    
248    return 0;          FD_ZERO(&inputs);
249            FD_SET(0, &inputs);
250            FD_SET(sock, &inputs);
251    
252            BBS_last_access_tm = t_used = time(0);
253    
254            loop = 1;
255    
256            while (loop)
257            {
258                    testfds = inputs;
259                    timeout.tv_sec = TIME_OUT;
260                    timeout.tv_usec = 0;
261    
262                    result = SignalSafeSelect(FD_SETSIZE, &testfds, (fd_set *)NULL,
263                                                                      (fd_set *)NULL, &timeout);
264    
265                    if (result == 0)
266                    {
267                            if (time(0) - BBS_last_access_tm >= MAX_DELAY_TIME)
268                            {
269                                    loop = 0;
270                            }
271                    }
272                    if (result < 0)
273                    {
274                            log_error("select() error (%d) !\n", result);
275                            loop = 0;
276                    }
277                    if (result > 0)
278                    {
279                            if (FD_ISSET(0, &testfds))
280                            {
281                                    len = read(0, buf, 255);
282                                    if (len == 0)
283                                    {
284                                            loop = 0;
285                                    }
286                                    write(sock, buf, (size_t)len);
287                            }
288                            if (FD_ISSET(sock, &testfds))
289                            {
290                                    len = read(sock, buf, 255);
291                                    if (len == 0)
292                                    {
293                                            loop = 0;
294                                    }
295                                    write(1, buf, (size_t)len);
296                            }
297                            BBS_last_access_tm = time(0);
298                    }
299            }
300    
301            if (close(sock) == -1)
302            {
303                    log_error("Close socket failed\n");
304            }
305    
306            t_used = time(0) - t_used;
307            tm_used = gmtime(&t_used);
308    
309            log_std("BBSNET disconnect, %d days %d hours %d minutes %d seconds used\n",
310                            tm_used->tm_mday - 1, tm_used->tm_hour, tm_used->tm_min,
311                            tm_used->tm_sec);
312    
313            return 0;
314  }  }
315    
316  static int  static int
317  bbsnet_refresh ()  bbsnet_refresh()
318  {  {
319    int i;          clearscr();
320            moveto(1, 0);
321            prints(" ----------------------------------------------------------------------------- ");
322            for (int i = 2; i < 19; i++)
323            {
324                    moveto(i, 0);
325                    prints("|");
326                    moveto(i, 79);
327                    prints("|");
328            }
329            moveto(19, 0);
330            prints("|-----------------------------------------------------------------------------|");
331            moveto(22, 0);
332            prints(" ----------------------------------------------------------------------------- ");
333            moveto(23, 0);
334            prints(" [\x1b[1;32mCtrl+C\x1b[m]退出");
335    
336    clearscr ();          iflush();
   moveto (1, 0);  
   prints  
     ("╭══════════════════════════════════════╮");  
   for (i = 2; i < 19; i++)  
     {  
       moveto (i, 0);  
       prints ("║");  
       moveto (i, 79);  
       prints ("║");  
     }  
   moveto (19, 0);  
   prints  
     ("║——————————————————————————————————————║");  
   moveto (22, 0);  
   prints  
     ("╰══════════════════════════════════════╯");  
   moveto (23, 0);  
   prints  
     (" [\x1b[1;32mCtrl+C\x1b[m]退出");  
   iflush ();  
337    
338    return 0;          return 0;
339  }  }
340    
341  int  int bbsnet_selchange(int new_pos)
 bbsnet_selchange (int new_pos)  
342  {  {
343    moveto (20, 0);          moveto(20, 0);
344    clrtoeol ();          clrtoeol();
345    prints ("║\x1b[1m单位:\x1b[1;33m%-18s\x1b[m  站名:\x1b[1;33m%s\x1b[m",          prints("|\x1b[1m单位:\x1b[1;33m%-18s\x1b[m  站名:\x1b[1;33m%s\x1b[m",
346            bbsnet_conf[new_pos].host2, bbsnet_conf[new_pos].host1);                     bbsnet_conf[new_pos].host2, bbsnet_conf[new_pos].host1);
347    moveto (20, 79);          moveto(20, 79);
348    prints ("║");          prints("|");
349    moveto (21, 0);          moveto(21, 0);
350    clrtoeol ();          clrtoeol();
351    prints ("║\x1b[1m连往:\x1b[1;33m%-20s", bbsnet_conf[new_pos].ip);          prints("|\x1b[1m连往:\x1b[1;33m%-20s", bbsnet_conf[new_pos].ip);
352    if (bbsnet_conf[new_pos].port != 23)          if (bbsnet_conf[new_pos].port != 23)
353      prints ("  %d", bbsnet_conf[new_pos].port);          {
354    prints ("\x1b[m");                  prints("  %d", bbsnet_conf[new_pos].port);
355    moveto (21, 79);          }
356    prints ("║");          prints("\x1b[m");
357    iflush ();          moveto(21, 79);
358            prints("|");
359            iflush();
360    
361    return 0;          return 0;
362  }  }
363    
364  int  int bbs_net()
 bbs_net ()  
365  {  {
366    int ch, result, pos, i;          int ch, pos, i;
367    char file_config[256];  
368    time_t t_last_action;          load_bbsnet_conf(CONF_BBSNET);
369    fd_set inputs, testfds;  
370    struct timeval timeout;          BBS_last_access_tm = time(0);
371    
372    strcpy (file_config, app_home_dir);          clearscr();
373    strcat (file_config, "conf/bbsnet.conf");          bbsnet_refresh();
374            pos = bbsnet_menu.p_menu[0]->item_cur_pos;
375    load_bbsnet_conf (file_config);          display_menu(get_menu(&bbsnet_menu, "BBSNET"));
376            bbsnet_selchange(pos);
377    FD_ZERO (&inputs);  
378    FD_SET (0, &inputs);          while (1)
379            {
380    t_last_action = time (0);                  ch = igetch(0);
381                    switch (ch)
   clearscr ();  
   bbsnet_refresh ();  
   pos = bbsnet_menu.p_menu[0]->item_cur_pos;  
   display_menu (get_menu (&bbsnet_menu, "BBSNET"));  
   bbsnet_selchange (pos);  
   
   while (1)  
     {  
       testfds = inputs;  
       timeout.tv_sec = 0;  
       timeout.tv_usec = 100000;  
   
       result = select (FD_SETSIZE, &testfds, (fd_set *) NULL,  
                        (fd_set *) NULL, &timeout);  
       switch (result)  
         {  
         case 0:  
           break;  
         case -1:  
           log_error ("select() error!\n");  
           break;  
         default:  
           if (FD_ISSET (0, &testfds))  
             {  
               ch = igetch ();  
               switch (ch)  
382                  {                  {
383                  case KEY_NULL:                  case KEY_NULL:
384                  case Ctrl ('C'):                  case Ctrl('C'):
385                    return 0;                          return 0;
386                    case KEY_TIMEOUT:
387                            if (time(0) - BBS_last_access_tm >= MAX_DELAY_TIME)
388                            {
389                                    return -1;
390                            }
391                            continue;
392                  case CR:                  case CR:
393                    pos = bbsnet_menu.p_menu[0]->item_cur_pos;                          pos = bbsnet_menu.p_menu[0]->item_cur_pos;
394                    bbsnet_connect (pos);                          bbsnet_connect(pos);
395                    bbsnet_refresh ();                          bbsnet_refresh();
396                    display_current_menu (&bbsnet_menu);                          display_current_menu(&bbsnet_menu);
397                    bbsnet_selchange (pos);                          bbsnet_selchange(pos);
398                    break;                          break;
399                  case KEY_UP:                  case KEY_UP:
400                    for (i = 0; i < STATION_PER_LINE; i++)                          for (i = 0; i < STATION_PER_LINE; i++)
401                      menu_control (&bbsnet_menu, KEY_UP);                          {
402                    pos = bbsnet_menu.p_menu[0]->item_cur_pos;                                  menu_control(&bbsnet_menu, KEY_UP);
403                    bbsnet_selchange (pos);                          }
404                    break;                          pos = bbsnet_menu.p_menu[0]->item_cur_pos;
405                            bbsnet_selchange(pos);
406                            break;
407                  case KEY_DOWN:                  case KEY_DOWN:
408                    for (i = 0; i < STATION_PER_LINE; i++)                          for (i = 0; i < STATION_PER_LINE; i++)
409                      menu_control (&bbsnet_menu, KEY_DOWN);                          {
410                    pos = bbsnet_menu.p_menu[0]->item_cur_pos;                                  menu_control(&bbsnet_menu, KEY_DOWN);
411                    bbsnet_selchange (pos);                          }
412                    break;                          pos = bbsnet_menu.p_menu[0]->item_cur_pos;
413                            bbsnet_selchange(pos);
414                            break;
415                  case KEY_LEFT:                  case KEY_LEFT:
416                    menu_control (&bbsnet_menu, KEY_UP);                          menu_control(&bbsnet_menu, KEY_UP);
417                    pos = bbsnet_menu.p_menu[0]->item_cur_pos;                          pos = bbsnet_menu.p_menu[0]->item_cur_pos;
418                    bbsnet_selchange (pos);                          bbsnet_selchange(pos);
419                    break;                          break;
420                  case KEY_RIGHT:                  case KEY_RIGHT:
421                    menu_control (&bbsnet_menu, KEY_DOWN);                          menu_control(&bbsnet_menu, KEY_DOWN);
422                    pos = bbsnet_menu.p_menu[0]->item_cur_pos;                          pos = bbsnet_menu.p_menu[0]->item_cur_pos;
423                    bbsnet_selchange (pos);                          bbsnet_selchange(pos);
424                    break;                          break;
425                  default:                  default:
426                    menu_control (&bbsnet_menu, ch);                          menu_control(&bbsnet_menu, ch);
427                    pos = bbsnet_menu.p_menu[0]->item_cur_pos;                          pos = bbsnet_menu.p_menu[0]->item_cur_pos;
428                    bbsnet_selchange (pos);                          bbsnet_selchange(pos);
429                    break;                          break;
430                  }                  }
431              }                  BBS_last_access_tm = time(0);
           break;  
         }  
       if (time (0) - t_last_action >= 10)  
         {  
           t_last_action = time (0);  
432          }          }
     }  
433    
434    return 0;          return 0;
435  }  }


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

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