/[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.8 by sysadm, Tue Mar 22 08:59:31 2005 UTC Revision 1.11 by sysadm, Sat Apr 16 04:49:11 2005 UTC
# Line 119  process_bar (int n, int len) Line 119  process_bar (int n, int len)
119    char *ptr3;    char *ptr3;
120    
121    moveto (4, 0);    moveto (4, 0);
122    prints ("┌───────────────┐\n");    prints ("┌───────────────┐\r\n");
123    sprintf (buf2, "            %3d%%              ", n * 100 / len);    sprintf (buf2, "            %3d%%              ", n * 100 / len);
124    ptr = buf;    ptr = buf;
125    ptr2 = buf2;    ptr2 = buf2;
# Line 134  process_bar (int n, int len) Line 134  process_bar (int n, int len)
134    while (*ptr2 != '\0')    while (*ptr2 != '\0')
135      *ptr++ = *ptr2++;      *ptr++ = *ptr2++;
136    *ptr++ = '\0';    *ptr++ = '\0';
137    prints ("│\033[46m%s\033[m│\n", buf);    prints ("│\033[46m%s\033[m│\r\n", buf);
138    prints ("└───────────────┘\n");    prints ("└───────────────┘\r\n");
139      iflush ();
140  }  }
141    
142  int  int
# Line 151  bbsnet_connect (int n) Line 152  bbsnet_connect (int n)
152    char remote_addr[256];    char remote_addr[256];
153    int remote_port;    int remote_port;
154    time_t t_used;    time_t t_used;
155    struct tm * tm_used;    struct tm *tm_used;
156    
157    prints ("\033[1;32m正在测试往 %s (%s) 的连接,请稍候... \033[m\n",    clearscr ();
158    
159      moveto (0, 0);
160      prints ("\033[1;32m正在测试往 %s (%s) 的连接,请稍候... \033[m\r\n",
161            bbsnet_conf[n].host1, bbsnet_conf[n].ip);            bbsnet_conf[n].host1, bbsnet_conf[n].ip);
162    prints ("\033[1;32m如果在 %d 秒内无法连上,穿梭程序将放弃连接。\033[m\n",    prints ("\033[1;32m如果在 %d 秒内无法连上,穿梭程序将放弃连接。\033[m\r\n",
163            TIME_OUT);            TIME_OUT);
164      iflush ();
165    
166    pHost = gethostbyname (bbsnet_conf[n].ip);    pHost = gethostbyname (bbsnet_conf[n].ip);
167    
168    if (pHost == NULL)    if (pHost == NULL)
169      {      {
170        prints ("\033[1;31m查找主机名失败!\033[m\n");        prints ("\033[1;31m查找主机名失败!\033[m\r\n");
171        press_any_key ();        press_any_key ();
172        return -1;        return -1;
173      }      }
# Line 171  bbsnet_connect (int n) Line 176  bbsnet_connect (int n)
176    
177    if (sock < 0)    if (sock < 0)
178      {      {
179        prints ("\033[1;31m无法创建socket!\033[m\n");        prints ("\033[1;31m无法创建socket!\033[m\r\n");
180        press_any_key ();        press_any_key ();
181        return -1;        return -1;
182      }      }
# Line 187  bbsnet_connect (int n) Line 192  bbsnet_connect (int n)
192                   inet_ntoa (sin.sin_addr), ntohs (sin.sin_port));                   inet_ntoa (sin.sin_addr), ntohs (sin.sin_port));
193        return -2;        return -2;
194      }      }
195      
196    bzero (&sin, sizeof (sin));    bzero (&sin, sizeof (sin));
197    sin.sin_family = AF_INET;    sin.sin_family = AF_INET;
198    sin.sin_addr = *(struct in_addr *) pHost->h_addr_list[0];    sin.sin_addr = *(struct in_addr *) pHost->h_addr_list[0];
# Line 196  bbsnet_connect (int n) Line 201  bbsnet_connect (int n)
201    strcpy (remote_addr, inet_ntoa (sin.sin_addr));    strcpy (remote_addr, inet_ntoa (sin.sin_addr));
202    remote_port = ntohs (sin.sin_port);    remote_port = ntohs (sin.sin_port);
203    
204    prints ("\033[1;32m穿梭进度条提示您当前已使用的时间。\033[m\n");    prints ("\033[1;32m穿梭进度条提示您当前已使用的时间。\033[m\r\n");
205    process_bar (0, MAX_PROCESS_BAR_LEN);    process_bar (0, MAX_PROCESS_BAR_LEN);
206    for (i = 0; i < MAX_PROCESS_BAR_LEN; i++)    for (i = 0; i < MAX_PROCESS_BAR_LEN; i++)
207      {      {
# Line 217  bbsnet_connect (int n) Line 222  bbsnet_connect (int n)
222          break;          break;
223        else        else
224          {          {
225            prints ("\033[1;31m连接失败!\033[m\n");            prints ("\033[1;31m连接失败!\033[m\r\n");
226            press_any_key ();            press_any_key ();
227            return -1;            return -1;
228          }          }
229      }      }
230    if (i == MAX_PROCESS_BAR_LEN)    if (i == MAX_PROCESS_BAR_LEN)
231      {      {
232        prints ("\033[1;31m连接超时!\033[m\n");        prints ("\033[1;31m连接超时!\033[m\r\n");
233        press_any_key ();        press_any_key ();
234        return -1;        return -1;
235      }      }
236    setsockopt (sock, IPPROTO_IP, IP_TOS, &tos, sizeof (int));    setsockopt (sock, IPPROTO_IP, IP_TOS, &tos, sizeof (int));
237    
238    prints ("\033[1;31m连接成功!\033[m\n");    prints ("\033[1;31m连接成功!\033[m\r\n");
239    log_std ("BBSNET connect to %s:%d\n",    log_std ("BBSNET connect to %s:%d\n", remote_addr, remote_port);
     remote_addr, remote_port);  
240    
241    FD_ZERO (&inputs);    FD_ZERO (&inputs);
242    FD_SET (0, &inputs);    FD_SET (0, &inputs);
# Line 283  bbsnet_connect (int n) Line 287  bbsnet_connect (int n)
287                  }                  }
288                write (1, buf, len);                write (1, buf, len);
289              }              }
           break;  
290            BBS_last_access_tm = time (0);            BBS_last_access_tm = time (0);
291              break;
292          }          }
293      }      }
294    
# Line 297  bbsnet_connect (int n) Line 301  bbsnet_connect (int n)
301    tm_used = gmtime (&t_used);    tm_used = gmtime (&t_used);
302    
303    log_std ("BBSNET disconnect, %d days %d hours %d minutes %d seconds used\n",    log_std ("BBSNET disconnect, %d days %d hours %d minutes %d seconds used\n",
304      tm_used->tm_mday - 1, tm_used->tm_hour, tm_used->tm_min, tm_used->tm_sec);             tm_used->tm_mday - 1, tm_used->tm_hour, tm_used->tm_min,
305               tm_used->tm_sec);
306    
307    return 0;    return 0;
308  }  }


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

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