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


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

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