/[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.16 by sysadm, Fri May 2 03:34:58 2025 UTC Revision 1.36 by sysadm, Sun May 11 12:47:32 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   ***************************************************************************/   ***************************************************************************/
# Line 21  Line 20 
20  #include "io.h"  #include "io.h"
21  #include "screen.h"  #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    
41  #define MAX_PROCESS_BAR_LEN 30  #define MAX_PROCESS_BAR_LEN 30
42  #define MAXSTATION 26 * 2  #define MAXSTATION 26 * 2
43  #define STATION_PER_LINE 4  #define STATION_PER_LINE 4
# Line 42  struct _bbsnet_conf Line 47  struct _bbsnet_conf
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;
# Line 52  int load_bbsnet_conf(const char *file_co Line 57  int load_bbsnet_conf(const char *file_co
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            {
66                  return -1;                  return -1;
67            }
68    
69          p_menu = bbsnet_menu.p_menu[0] = malloc(sizeof(MENU));          p_menu = bbsnet_menu.p_menu[0] = malloc(sizeof(MENU));
70          strcpy(p_menu->name, "BBSNET");          strncpy(p_menu->name, "BBSNET", sizeof(p_menu->name) - 1);
71            p_menu->name[sizeof(p_menu->name) - 1] = '\0';
72          p_menu->title.show = 0;          p_menu->title.show = 0;
73          p_menu->screen.show = 0;          p_menu->screen.show = 0;
74    
75          while (fgets(t, 255, fp) && item_count < MAXSTATION)          while (fgets(t, 255, fp) && item_count < MAXSTATION)
76          {          {
77                  t1 = strtok(t, " \t");                  t1 = strtok_r(t, MENU_CONF_DELIM, &saveptr);
78                  t2 = strtok(NULL, " \t\n");                  t2 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr);
79                  t3 = strtok(NULL, " \t\n");                  t3 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr);
80                  t4 = strtok(NULL, " \t\n");                  t4 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr);
81    
82                  if (t1[0] == '#' || t1[0] == '*' || t1 == NULL || t2 == NULL || t3 == NULL)                  if (t1 == NULL || t2 == NULL || t3 == NULL || t4 == NULL || t[0] == '#' || t[0] == '*')
83                    {
84                          continue;                          continue;
85                  strncpy(bbsnet_conf[item_count].host1, t2, 18);                  }
86                  bbsnet_conf[item_count].host1[18] = 0;  
87                  strncpy(bbsnet_conf[item_count].host2, t1, 36);                  strncpy(bbsnet_conf[item_count].host1, t2, sizeof(bbsnet_conf[item_count].host1) - 1);
88                  bbsnet_conf[item_count].host2[36] = 0;                  bbsnet_conf[item_count].host1[sizeof(bbsnet_conf[item_count].host1) - 1] = '\0';
89                  strncpy(bbsnet_conf[item_count].ip, t3, 36);                  strncpy(bbsnet_conf[item_count].host2, t1, sizeof(bbsnet_conf[item_count].host2) - 1);
90                  bbsnet_conf[item_count].ip[36] = 0;                  bbsnet_conf[item_count].host2[sizeof(bbsnet_conf[item_count].host2) - 1] = '\0';
91                  bbsnet_conf[item_count].port = t4 ? atoi(t4) : 23;                  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));                  p_menuitem = p_menu->items[item_count] = malloc(sizeof(MENU_ITEM));
96                  p_menuitem->row = 2 + item_count / STATION_PER_LINE;                  p_menuitem->row = 2 + item_count / STATION_PER_LINE;
97                  p_menuitem->col = 5 + item_count % STATION_PER_LINE * 20;                  p_menuitem->col = 5 + item_count % STATION_PER_LINE * 20;
98                  sprintf(p_menuitem->action, "%d", item_count);                  snprintf(p_menuitem->action, sizeof(p_menuitem->action), "%d", item_count);
99                  p_menuitem->submenu = 0;                  p_menuitem->submenu = 0;
100                  p_menuitem->priv = 0;                  p_menuitem->priv = 0;
101                  p_menuitem->level = 0;                  p_menuitem->level = 0;
102                  p_menuitem->display = 0;                  p_menuitem->display = 0;
103                  p_menuitem->name[0] =                  p_menuitem->name[0] =
104                          (item_count < MAXSTATION / 2 ? 'A' + item_count : 'a' + item_count);                          (char)(item_count < MAXSTATION / 2 ? 'A' + item_count : 'a' + item_count);
105                  p_menuitem->name[1] = '\0';                  p_menuitem->name[1] = '\0';
106                  sprintf(p_menuitem->text, "%c. %s",                  snprintf(p_menuitem->text, sizeof(p_menuitem->text), "%c. %s",
107                                  p_menuitem->name[0], bbsnet_conf[item_count].host1);                                   p_menuitem->name[0], bbsnet_conf[item_count].host1);
108    
109                  item_count++;                  item_count++;
110          }          }
# Line 109  int load_bbsnet_conf(const char *file_co Line 120  int load_bbsnet_conf(const char *file_co
120          return 0;          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            }
132            if (n < 0)
133            {
134                    n = 0;
135            }
136            else if (n > len)
137            {
138                    n = len;
139            }
140    
141          moveto(4, 0);          moveto(4, 0);
142          prints("┌───────────────┐\r\n");          prints(" ------------------------------ \r\n");
143          sprintf(buf2, "            %3d%%              ", n * 100 / len);          snprintf(buf, sizeof(buf), "            %3d%%              ", n * 100 / len);
144          ptr = buf;          strncpy(buf2, buf, (size_t)n);
145          ptr2 = buf2;          buf2[n] = '\0';
146          ptr3 = buf + n;          prints("|\033[46m%s\033[44m%s\033[m|\r\n", buf2, buf + n);
147          while (ptr != ptr3)          prints(" ------------------------------ \r\n");
                 *ptr++ = *ptr2++;  
         *ptr++ = '\x1b';  
         *ptr++ = '[';  
         *ptr++ = '4';  
         *ptr++ = '4';  
         *ptr++ = 'm';  
         while (*ptr2 != '\0')  
                 *ptr++ = *ptr2++;  
         *ptr++ = '\0';  
         prints("│\033[46m%s\033[m│\r\n", buf);  
         prints("└───────────────┘\r\n");  
148          iflush();          iflush();
149  }  }
150    
151  int bbsnet_connect(int n)  int bbsnet_connect(int n)
152  {  {
153          int sock, ch, result, len, loop;          int sock, ret, loop, error;
154            int flags_sock;
155            int flags_stdin;
156            int flags_stdout;
157            int len;
158          struct sockaddr_in sin;          struct sockaddr_in sin;
159          char buf[256];          char input_buf[LINE_BUFFER_LEN];
160          fd_set inputs, testfds;          char output_buf[LINE_BUFFER_LEN];
161            int input_buf_len = 0;
162            int output_buf_len = 0;
163            int input_buf_offset = 0;
164            int output_buf_offset = 0;
165            fd_set read_fds;
166            fd_set write_fds;
167          struct timeval timeout;          struct timeval timeout;
168          struct hostent *pHost = NULL;          struct hostent *p_host = NULL;
169          int rc, rv, tos = 020, i;          int tos;
170          char remote_addr[256];          int i;
171            char remote_addr[IP_ADDR_LEN];
172          int remote_port;          int remote_port;
173          time_t t_used;          time_t t_used;
174          struct tm *tm_used;          struct tm *tm_used;
175            int ch;
176    
177          clearscr();          clearscr();
178    
179          moveto(0, 0);          moveto(0, 0);
180          prints("\033[1;32m正在测试往 %s (%s) 的连接,请稍候... \033[m\r\n",          prints("\033[1;32m正在测试往 %s (%s) 的连接,请稍候... \033[m\r\n",
181                     bbsnet_conf[n].host1, bbsnet_conf[n].ip);                     bbsnet_conf[n].host1, bbsnet_conf[n].ip);
         prints("\033[1;32m如果在 %d 秒内无法连上,穿梭程序将放弃连接。\033[m\r\n",  
                    TIME_OUT);  
182          iflush();          iflush();
183    
184          pHost = gethostbyname(bbsnet_conf[n].ip);          p_host = gethostbyname(bbsnet_conf[n].ip);
185    
186          if (pHost == NULL)          if (p_host == NULL)
187          {          {
188                  prints("\033[1;31m查找主机名失败!\033[m\r\n");                  prints("\033[1;31m查找主机名失败!\033[m\r\n");
189                  press_any_key();                  press_any_key();
# Line 181  int bbsnet_connect(int n) Line 200  int bbsnet_connect(int n)
200          }          }
201    
202          sin.sin_family = AF_INET;          sin.sin_family = AF_INET;
203          sin.sin_addr.s_addr =          sin.sin_addr.s_addr = (hostaddr_server[0] != '\0' ? inet_addr(hostaddr_server) : INADDR_ANY);
                 (strlen(hostaddr_server) > 0 ? inet_addr(hostaddr_server) : INADDR_ANY);  
204          sin.sin_port = 0;          sin.sin_port = 0;
205    
206          if (bind(sock, (struct sockaddr *)&sin, sizeof(sin)) < 0)          if (bind(sock, (struct sockaddr *)&sin, sizeof(sin)) < 0)
207          {          {
208                  log_error("Bind address %s:%u failed\n",                  log_error("Bind address %s:%u failed (%d)\n",
209                                    inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));                                    inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), errno);
210                  return -2;                  return -2;
211          }          }
212    
213          bzero(&sin, sizeof(sin));          bzero(&sin, sizeof(sin));
214          sin.sin_family = AF_INET;          sin.sin_family = AF_INET;
215          sin.sin_addr = *(struct in_addr *)pHost->h_addr_list[0];          sin.sin_addr = *(struct in_addr *)p_host->h_addr_list[0];
216          sin.sin_port = htons(bbsnet_conf[n].port);          sin.sin_port = htons(bbsnet_conf[n].port);
217    
218          strcpy(remote_addr, inet_ntoa(sin.sin_addr));          strncpy(remote_addr, inet_ntoa(sin.sin_addr), sizeof(remote_addr) - 1);
219            remote_addr[sizeof(remote_addr) - 1] = '\0';
220          remote_port = ntohs(sin.sin_port);          remote_port = ntohs(sin.sin_port);
221    
222          prints("\033[1;32m穿梭进度条提示您当前已使用的时间。\033[m\r\n");          prints("\033[1;32m穿梭进度条提示您当前已使用的时间,按\033[1;33mCtrl+C\033[1;32m中断。\033[m\r\n");
223          process_bar(0, MAX_PROCESS_BAR_LEN);          process_bar(0, MAX_PROCESS_BAR_LEN);
224    
225            // Set socket as non-blocking
226            flags_sock = fcntl(sock, F_GETFL, 0);
227            fcntl(sock, F_SETFL, flags_sock | O_NONBLOCK);
228    
229            if ((ret = connect(sock, (struct sockaddr *)&sin, sizeof(sin))) < 0)
230            {
231                    if (errno != EINPROGRESS)
232                    {
233                            prints("\033[1;31m连接失败!\033[m\r\n");
234                            press_any_key();
235                            return -1;
236                    }
237            }
238    
239          for (i = 0; i < MAX_PROCESS_BAR_LEN; i++)          for (i = 0; i < MAX_PROCESS_BAR_LEN; i++)
240          {          {
241                  if (i == 0)                  ch = igetch(0); // 0.1 second
242                          rv =                  if (ch == Ctrl('C') || SYS_server_exit)
243                                  NonBlockConnectEx(sock, (struct sockaddr *)&sin, sizeof(sin),                  {
244                                                                    500, 1);                          return 0;
245                  else                  }
246                          rv =  
247                                  NonBlockConnectEx(sock, (struct sockaddr *)&sin, sizeof(sin),                  FD_ZERO(&read_fds);
248                                                                    500, 0);                  FD_SET(sock, &read_fds);
249                  if (rv == ERR_TCPLIB_TIMEOUT)  
250                    FD_ZERO(&write_fds);
251                    FD_SET(sock, &write_fds);
252    
253                    timeout.tv_sec = 0;
254                    timeout.tv_usec = 400 * 1000; // 0.4 second
255    
256                    ret = select(sock + 1, &read_fds, &write_fds, NULL, &timeout);
257    
258                    if (ret == 0) // Timeout
259                  {                  {
260                          process_bar(i + 1, MAX_PROCESS_BAR_LEN);                          process_bar(i + 1, MAX_PROCESS_BAR_LEN);
                         continue;  
261                  }                  }
262                  else if (rv == 0)                  else if (ret < 0)
                         break;  
                 else  
263                  {                  {
264                          prints("\033[1;31m连接失败!\033[m\r\n");                          if (errno != EINTR)
265                          press_any_key();                          {
266                          return -1;                                  log_error("select() error (%d) !\n", errno);
267                                    return -1;
268                            }
269                    }
270                    // ret > 0
271                    else if (FD_ISSET(sock, &read_fds) || FD_ISSET(sock, &write_fds))
272                    {
273                            len = sizeof(error);
274                            if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &error, (socklen_t *)&len) < 0)
275                            {
276                                    log_error("getsockopt() error (%d) !\n", error);
277                                    return -1;
278                            }
279    
280                            break; // connected
281                  }                  }
282          }          }
283          if (i == MAX_PROCESS_BAR_LEN)          if (i == MAX_PROCESS_BAR_LEN)
# Line 232  int bbsnet_connect(int n) Line 286  int bbsnet_connect(int n)
286                  press_any_key();                  press_any_key();
287                  return -1;                  return -1;
288          }          }
289          setsockopt(sock, IPPROTO_IP, IP_TOS, &tos, sizeof(int));  
290            tos = IPTOS_LOWDELAY;
291            if (setsockopt(sock, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) < 0)
292            {
293                    log_error("setsockopt IP_TOS=%d error (%d)\n", tos, errno);
294            }
295    
296          prints("\033[1;31m连接成功!\033[m\r\n");          prints("\033[1;31m连接成功!\033[m\r\n");
297            iflush();
298          log_std("BBSNET connect to %s:%d\n", remote_addr, remote_port);          log_std("BBSNET connect to %s:%d\n", remote_addr, remote_port);
299    
300          FD_ZERO(&inputs);          // Set STDIN/STDOUT as non-blocking
301          FD_SET(0, &inputs);          flags_stdin = fcntl(STDIN_FILENO, F_GETFL, 0);
302          FD_SET(sock, &inputs);          flags_stdout = fcntl(STDOUT_FILENO, F_GETFL, 0);
303            fcntl(STDIN_FILENO, F_SETFL, flags_stdin | O_NONBLOCK);
304            fcntl(STDOUT_FILENO, F_SETFL, flags_stdout | O_NONBLOCK);
305    
306          BBS_last_access_tm = t_used = time(0);          BBS_last_access_tm = t_used = time(0);
   
307          loop = 1;          loop = 1;
308    
309          while (loop)          while (loop && !SYS_server_exit)
310          {          {
311                  testfds = inputs;                  FD_ZERO(&read_fds);
312                  timeout.tv_sec = TIME_OUT;                  FD_SET(STDIN_FILENO, &read_fds);
313                  timeout.tv_usec = 0;                  FD_SET(sock, &read_fds);
314    
315                    FD_ZERO(&write_fds);
316                    FD_SET(STDOUT_FILENO, &write_fds);
317                    FD_SET(sock, &write_fds);
318    
319                    timeout.tv_sec = 0;
320                    timeout.tv_usec = 100 * 1000; // 0.1 second
321    
322                  result = SignalSafeSelect(FD_SETSIZE, &testfds, (fd_set *)NULL,                  ret = select(sock + 1, &read_fds, &write_fds, NULL, &timeout);
                                                                   (fd_set *)NULL, &timeout);  
323    
324                  if (result == 0)                  if (ret == 0) // timeout
325                  {                  {
326                          if (time(0) - BBS_last_access_tm >= MAX_DELAY_TIME)                          if (time(0) - BBS_last_access_tm >= MAX_DELAY_TIME)
327                          {                          {
328                                  loop = 0;                                  loop = 0;
329                          }                          }
330                  }                  }
331                  if (result < 0)                  else if (ret < 0)
332                  {                  {
333                          log_error("select() error (%d) !\n", result);                          if (errno != EINTR)
334                          loop = 0;                          {
335                                    log_error("select() error (%d) !\n", errno);
336                                    loop = 0;
337                            }
338                  }                  }
339                  if (result > 0)                  else if (ret > 0)
340                  {                  {
341                          if (FD_ISSET(0, &testfds))                          if ((input_buf_offset >= input_buf_len) && FD_ISSET(STDIN_FILENO, &read_fds))
342                            {
343                                    ret = (int)read(STDIN_FILENO, input_buf, sizeof(input_buf));
344                                    if (ret < 0)
345                                    {
346                                            if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR)
347                                            {
348                                                    log_error("read(STDIN) error (%d)\n", errno);
349                                                    loop = 0;
350                                            }
351                                    }
352                                    else if (ret == 0) // broken pipe
353                                    {
354                                            loop = 0;
355                                    }
356                                    else
357                                    {
358                                            input_buf_len = ret;
359                                            input_buf_offset = 0;
360    
361                                            BBS_last_access_tm = time(0);
362                                    }
363                            }
364    
365                            if ((input_buf_offset < input_buf_len) && FD_ISSET(sock, &write_fds))
366                            {
367                                    ret = (int)write(sock, input_buf + input_buf_offset, (size_t)(input_buf_len - input_buf_offset));
368                                    if (ret < 0)
369                                    {
370                                            if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR)
371                                            {
372                                                    log_error("write(socket) error (%d)\n", errno);
373                                                    loop = 0;
374                                            }
375                                    }
376                                    else if (ret == 0) // broken pipe
377                                    {
378                                            loop = 0;
379                                    }
380                                    else
381                                    {
382                                            input_buf_offset += ret;
383                                    }
384                            }
385    
386                            if ((output_buf_offset >= output_buf_len) && FD_ISSET(sock, &read_fds))
387                          {                          {
388                                  len = read(0, buf, 255);                                  ret = (int)read(sock, output_buf, sizeof(output_buf));
389                                  if (len == 0)                                  if (ret < 0)
390                                    {
391                                            if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR)
392                                            {
393                                                    log_error("read(socket) error (%d)\n", errno);
394                                                    loop = 0;
395                                            }
396                                    }
397                                    else if (ret == 0) // broken pipe
398                                  {                                  {
399                                          loop = 0;                                          loop = 0;
400                                  }                                  }
401                                  write(sock, buf, len);                                  else
402                                    {
403                                            output_buf_len = ret;
404                                            output_buf_offset = 0;
405                                    }
406                          }                          }
407                          if (FD_ISSET(sock, &testfds))  
408                            if ((output_buf_offset < output_buf_len) && FD_ISSET(STDOUT_FILENO, &write_fds))
409                          {                          {
410                                  len = read(sock, buf, 255);                                  ret = (int)write(STDOUT_FILENO, output_buf + output_buf_offset, (size_t)(output_buf_len - output_buf_offset));
411                                  if (len == 0)                                  if (ret < 0)
412                                    {
413                                            if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR)
414                                            {
415                                                    log_error("write(STDOUT) error (%d)\n", errno);
416                                                    loop = 0;
417                                            }
418                                    }
419                                    else if (ret == 0) // broken pipe
420                                  {                                  {
421                                          loop = 0;                                          loop = 0;
422                                  }                                  }
423                                  write(1, buf, len);                                  else
424                                    {
425                                            output_buf_offset += ret;
426                                    }
427                          }                          }
                         BBS_last_access_tm = time(0);  
428                  }                  }
429          }          }
430    
431            // Restore STDIN/STDOUT flags
432            fcntl(STDIN_FILENO, F_SETFL, flags_stdin);
433            fcntl(STDOUT_FILENO, F_SETFL, flags_stdout);
434    
435            // Restore socket flags
436            fcntl(sock, F_SETFL, flags_sock);
437    
438          if (close(sock) == -1)          if (close(sock) == -1)
439          {          {
440                  log_error("Close socket failed\n");                  log_error("Close socket failed\n");
# Line 308  int bbsnet_connect(int n) Line 453  int bbsnet_connect(int n)
453  static int  static int
454  bbsnet_refresh()  bbsnet_refresh()
455  {  {
         int i;  
   
456          clearscr();          clearscr();
457          moveto(1, 0);          moveto(1, 0);
458          prints("╭══════════════════════════════════════╮");          prints(" ----------------------------------------------------------------------------- ");
459          for (i = 2; i < 19; i++)          for (int i = 2; i < 19; i++)
460          {          {
461                  moveto(i, 0);                  moveto(i, 0);
462                  prints("║");                  prints("|");
463                  moveto(i, 79);                  moveto(i, 79);
464                  prints("║");                  prints("|");
465          }          }
466          moveto(19, 0);          moveto(19, 0);
467          prints("║——————————————————————————————————————║");          prints("|-----------------------------------------------------------------------------|");
468          moveto(22, 0);          moveto(22, 0);
469          prints("╰══════════════════════════════════════╯");          prints(" ----------------------------------------------------------------------------- ");
470          moveto(23, 0);          moveto(23, 0);
471          prints(" [\x1b[1;32mCtrl+C\x1b[m]退出");          prints(" [\x1b[1;32mCtrl+C\x1b[m]退出");
472    
# Line 336  int bbsnet_selchange(int new_pos) Line 479  int bbsnet_selchange(int new_pos)
479  {  {
480          moveto(20, 0);          moveto(20, 0);
481          clrtoeol();          clrtoeol();
482          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",
483                     bbsnet_conf[new_pos].host2, bbsnet_conf[new_pos].host1);                     bbsnet_conf[new_pos].host2, bbsnet_conf[new_pos].host1);
484          moveto(20, 79);          moveto(20, 79);
485          prints("║");          prints("|");
486          moveto(21, 0);          moveto(21, 0);
487          clrtoeol();          clrtoeol();
488          prints("║\x1b[1m连往:\x1b[1;33m%-20s", bbsnet_conf[new_pos].ip);          prints("|\x1b[1m连往:\x1b[1;33m%-20s", bbsnet_conf[new_pos].ip);
489          if (bbsnet_conf[new_pos].port != 23)          if (bbsnet_conf[new_pos].port != 23)
490            {
491                  prints("  %d", bbsnet_conf[new_pos].port);                  prints("  %d", bbsnet_conf[new_pos].port);
492            }
493          prints("\x1b[m");          prints("\x1b[m");
494          moveto(21, 79);          moveto(21, 79);
495          prints("║");          prints("|");
496          iflush();          iflush();
497    
498          return 0;          return 0;
# Line 356  int bbsnet_selchange(int new_pos) Line 501  int bbsnet_selchange(int new_pos)
501  int bbs_net()  int bbs_net()
502  {  {
503          int ch, pos, i;          int ch, pos, i;
         char file_config[256];  
504    
505          strcpy(file_config, app_home_dir);          load_bbsnet_conf(CONF_BBSNET);
         strcat(file_config, "conf/bbsnet.conf");  
   
         load_bbsnet_conf(file_config);  
506    
507          BBS_last_access_tm = time(0);          BBS_last_access_tm = time(0);
508    
# Line 371  int bbs_net() Line 512  int bbs_net()
512          display_menu(get_menu(&bbsnet_menu, "BBSNET"));          display_menu(get_menu(&bbsnet_menu, "BBSNET"));
513          bbsnet_selchange(pos);          bbsnet_selchange(pos);
514    
515          while (1)          while (!SYS_server_exit)
516          {          {
517                  ch = igetch(0);                  ch = igetch(0);
518                  switch (ch)                  switch (ch)
519                  {                  {
520                  case KEY_NULL:                  case KEY_NULL:  // broken pipe
521                  case Ctrl('C'):                  case Ctrl('C'): // user cancel
522                          return 0;                          return 0;
523                  case KEY_TIMEOUT:                  case KEY_TIMEOUT:
524                          if (time(0) - BBS_last_access_tm >= MAX_DELAY_TIME)                          if (time(0) - BBS_last_access_tm >= MAX_DELAY_TIME)
525                          {                          {
526                                  return -1;                                  return 0;
527                          }                          }
528                          continue;                          continue;
529                  case CR:                  case CR:
# Line 394  int bbs_net() Line 535  int bbs_net()
535                          break;                          break;
536                  case KEY_UP:                  case KEY_UP:
537                          for (i = 0; i < STATION_PER_LINE; i++)                          for (i = 0; i < STATION_PER_LINE; i++)
538                            {
539                                  menu_control(&bbsnet_menu, KEY_UP);                                  menu_control(&bbsnet_menu, KEY_UP);
540                            }
541                          pos = bbsnet_menu.p_menu[0]->item_cur_pos;                          pos = bbsnet_menu.p_menu[0]->item_cur_pos;
542                          bbsnet_selchange(pos);                          bbsnet_selchange(pos);
543                          break;                          break;
544                  case KEY_DOWN:                  case KEY_DOWN:
545                          for (i = 0; i < STATION_PER_LINE; i++)                          for (i = 0; i < STATION_PER_LINE; i++)
546                            {
547                                  menu_control(&bbsnet_menu, KEY_DOWN);                                  menu_control(&bbsnet_menu, KEY_DOWN);
548                            }
549                          pos = bbsnet_menu.p_menu[0]->item_cur_pos;                          pos = bbsnet_menu.p_menu[0]->item_cur_pos;
550                          bbsnet_selchange(pos);                          bbsnet_selchange(pos);
551                          break;                          break;


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

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