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


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

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