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


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

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