/[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.21 by sysadm, Mon May 5 11:11:06 2025 UTC
# Line 52  int load_bbsnet_conf(const char *file_co Line 52  int load_bbsnet_conf(const char *file_co
52          FILE *fp;          FILE *fp;
53          MENU *p_menu;          MENU *p_menu;
54          MENU_ITEM *p_menuitem;          MENU_ITEM *p_menuitem;
55          char t[256], *t1, *t2, *t3, *t4;          char t[256], *t1, *t2, *t3, *t4, *saveptr;
56          int item_count = 0;          int item_count = 0;
57    
58          fp = fopen(file_config, "r");          fp = fopen(file_config, "r");
59          if (fp == NULL)          if (fp == NULL)
60            {
61                  return -1;                  return -1;
62            }
63    
64          p_menu = bbsnet_menu.p_menu[0] = malloc(sizeof(MENU));          p_menu = bbsnet_menu.p_menu[0] = malloc(sizeof(MENU));
65          strcpy(p_menu->name, "BBSNET");          strncpy(p_menu->name, "BBSNET", sizeof(p_menu->name) - 1);
66            p_menu->name[sizeof(p_menu->name) - 1] = '\0';
67          p_menu->title.show = 0;          p_menu->title.show = 0;
68          p_menu->screen.show = 0;          p_menu->screen.show = 0;
69    
70          while (fgets(t, 255, fp) && item_count < MAXSTATION)          while (fgets(t, 255, fp) && item_count < MAXSTATION)
71          {          {
72                  t1 = strtok(t, " \t");                  t1 = strtok_r(t, " \t", &saveptr);
73                  t2 = strtok(NULL, " \t\n");                  t2 = strtok_r(NULL, " \t\n", &saveptr);
74                  t3 = strtok(NULL, " \t\n");                  t3 = strtok_r(NULL, " \t\n", &saveptr);
75                  t4 = strtok(NULL, " \t\n");                  t4 = strtok_r(NULL, " \t\n", &saveptr);
76    
77                  if (t1[0] == '#' || t1[0] == '*' || t1 == NULL || t2 == NULL || t3 == NULL)                  if (t1 == NULL || t2 == NULL || t3 == NULL || t[0] == '#' || t[0] == '*')
78                    {
79                          continue;                          continue;
80                  strncpy(bbsnet_conf[item_count].host1, t2, 18);                  }
81                  bbsnet_conf[item_count].host1[18] = 0;  
82                  strncpy(bbsnet_conf[item_count].host2, t1, 36);                  strncpy(bbsnet_conf[item_count].host1, t2, sizeof(bbsnet_conf[item_count].host1) - 1);
83                  bbsnet_conf[item_count].host2[36] = 0;                  bbsnet_conf[item_count].host1[sizeof(bbsnet_conf[item_count].host1) - 1] = '\0';
84                  strncpy(bbsnet_conf[item_count].ip, t3, 36);                  strncpy(bbsnet_conf[item_count].host2, t1, sizeof(bbsnet_conf[item_count].host2) - 1);
85                  bbsnet_conf[item_count].ip[36] = 0;                  bbsnet_conf[item_count].host2[sizeof(bbsnet_conf[item_count].host2) - 1] = '\0';
86                    strncpy(bbsnet_conf[item_count].ip, t3, sizeof(bbsnet_conf[item_count].ip) - 1);
87                    bbsnet_conf[item_count].ip[sizeof(bbsnet_conf[item_count].ip) - 1] = '\0';
88                  bbsnet_conf[item_count].port = t4 ? atoi(t4) : 23;                  bbsnet_conf[item_count].port = t4 ? atoi(t4) : 23;
89    
90                  p_menuitem = p_menu->items[item_count] = malloc(sizeof(MENU_ITEM));                  p_menuitem = p_menu->items[item_count] = malloc(sizeof(MENU_ITEM));
# Line 92  int load_bbsnet_conf(const char *file_co Line 98  int load_bbsnet_conf(const char *file_co
98                  p_menuitem->name[0] =                  p_menuitem->name[0] =
99                          (item_count < MAXSTATION / 2 ? 'A' + item_count : 'a' + item_count);                          (item_count < MAXSTATION / 2 ? 'A' + item_count : 'a' + item_count);
100                  p_menuitem->name[1] = '\0';                  p_menuitem->name[1] = '\0';
101                  sprintf(p_menuitem->text, "%c. %s",                  snprintf(p_menuitem->text, sizeof(p_menuitem->text), "%c. %s",
102                                  p_menuitem->name[0], bbsnet_conf[item_count].host1);                                   p_menuitem->name[0], bbsnet_conf[item_count].host1);
103    
104                  item_count++;                  item_count++;
105          }          }
# Line 109  int load_bbsnet_conf(const char *file_co Line 115  int load_bbsnet_conf(const char *file_co
115          return 0;          return 0;
116  }  }
117    
118  static void  static void process_bar(int n, int len)
 process_bar(int n, int len)  
119  {  {
120          char buf[256];          char buf[256];
121          char buf2[256];          char buf2[256];
# Line 119  process_bar(int n, int len) Line 124  process_bar(int n, int len)
124          char *ptr3;          char *ptr3;
125    
126          moveto(4, 0);          moveto(4, 0);
127          prints("┌───────────────┐\r\n");          prints("┌──────────────────────────────┐\r\n");
128          sprintf(buf2, "            %3d%%              ", n * 100 / len);          sprintf(buf2, "            %3d%%              ", n * 100 / len);
129          ptr = buf;          ptr = buf;
130          ptr2 = buf2;          ptr2 = buf2;
# Line 135  process_bar(int n, int len) Line 140  process_bar(int n, int len)
140                  *ptr++ = *ptr2++;                  *ptr++ = *ptr2++;
141          *ptr++ = '\0';          *ptr++ = '\0';
142          prints("│\033[46m%s\033[m│\r\n", buf);          prints("│\033[46m%s\033[m│\r\n", buf);
143          prints("└───────────────┘\r\n");          prints("└──────────────────────────────┘\r\n");
144          iflush();          iflush();
145  }  }
146    
147  int bbsnet_connect(int n)  int bbsnet_connect(int n)
148  {  {
149          int sock, ch, result, len, loop;          int sock, result, len, loop;
150          struct sockaddr_in sin;          struct sockaddr_in sin;
151          char buf[256];          char buf[256];
152          fd_set inputs, testfds;          fd_set inputs, testfds;
153          struct timeval timeout;          struct timeval timeout;
154          struct hostent *pHost = NULL;          struct hostent *pHost = NULL;
155          int rc, rv, tos = 020, i;          int rv, tos = 020, i;
156          char remote_addr[256];          char remote_addr[256];
157          int remote_port;          int remote_port;
158          time_t t_used;          time_t t_used;
# Line 182  int bbsnet_connect(int n) Line 187  int bbsnet_connect(int n)
187    
188          sin.sin_family = AF_INET;          sin.sin_family = AF_INET;
189          sin.sin_addr.s_addr =          sin.sin_addr.s_addr =
190                  (strlen(hostaddr_server) > 0 ? inet_addr(hostaddr_server) : INADDR_ANY);                  (strnlen(hostaddr_server, sizeof(hostaddr_server)) > 0 ? inet_addr(hostaddr_server) : INADDR_ANY);
191          sin.sin_port = 0;          sin.sin_port = 0;
192    
193          if (bind(sock, (struct sockaddr *)&sin, sizeof(sin)) < 0)          if (bind(sock, (struct sockaddr *)&sin, sizeof(sin)) < 0)
# Line 197  int bbsnet_connect(int n) Line 202  int bbsnet_connect(int n)
202          sin.sin_addr = *(struct in_addr *)pHost->h_addr_list[0];          sin.sin_addr = *(struct in_addr *)pHost->h_addr_list[0];
203          sin.sin_port = htons(bbsnet_conf[n].port);          sin.sin_port = htons(bbsnet_conf[n].port);
204    
205          strcpy(remote_addr, inet_ntoa(sin.sin_addr));          strncpy(remote_addr, inet_ntoa(sin.sin_addr), sizeof(remote_addr) - 1);
206            remote_addr[sizeof(remote_addr) - 1] = '\0';
207          remote_port = ntohs(sin.sin_port);          remote_port = ntohs(sin.sin_port);
208    
209          prints("\033[1;32m穿梭进度条提示您当前已使用的时间。\033[m\r\n");          prints("\033[1;32m穿梭进度条提示您当前已使用的时间。\033[m\r\n");
# Line 218  int bbsnet_connect(int n) Line 224  int bbsnet_connect(int n)
224                          continue;                          continue;
225                  }                  }
226                  else if (rv == 0)                  else if (rv == 0)
227                    {
228                          break;                          break;
229                    }
230                  else                  else
231                  {                  {
232                          prints("\033[1;31m连接失败!\033[m\r\n");                          prints("\033[1;31m连接失败!\033[m\r\n");
# Line 308  int bbsnet_connect(int n) Line 316  int bbsnet_connect(int n)
316  static int  static int
317  bbsnet_refresh()  bbsnet_refresh()
318  {  {
         int i;  
   
319          clearscr();          clearscr();
320          moveto(1, 0);          moveto(1, 0);
321          prints("╭══════════════════════════════════════╮");          prints("╭═════════════════════════════════════════════════════════════════════════════╮");
322          for (i = 2; i < 19; i++)          for (int i = 2; i < 19; i++)
323          {          {
324                  moveto(i, 0);                  moveto(i, 0);
325                  prints("║");                  prints("║");
# Line 321  bbsnet_refresh() Line 327  bbsnet_refresh()
327                  prints("║");                  prints("║");
328          }          }
329          moveto(19, 0);          moveto(19, 0);
330          prints("║——————————————————————————————————————║");          prints("║—————————————————————————————————————————————————————————————————————————————║");
331          moveto(22, 0);          moveto(22, 0);
332          prints("╰══════════════════════════════════════╯");          prints("╰═════════════════════════════════════════════════════════════════════════════╯");
333          moveto(23, 0);          moveto(23, 0);
334          prints(" [\x1b[1;32mCtrl+C\x1b[m]退出");          prints(" [\x1b[1;32mCtrl+C\x1b[m]退出");
335    
# Line 344  int bbsnet_selchange(int new_pos) Line 350  int bbsnet_selchange(int new_pos)
350          clrtoeol();          clrtoeol();
351          prints("║\x1b[1m连往:\x1b[1;33m%-20s", bbsnet_conf[new_pos].ip);          prints("║\x1b[1m连往:\x1b[1;33m%-20s", bbsnet_conf[new_pos].ip);
352          if (bbsnet_conf[new_pos].port != 23)          if (bbsnet_conf[new_pos].port != 23)
353            {
354                  prints("  %d", bbsnet_conf[new_pos].port);                  prints("  %d", bbsnet_conf[new_pos].port);
355            }
356          prints("\x1b[m");          prints("\x1b[m");
357          moveto(21, 79);          moveto(21, 79);
358          prints("║");          prints("║");
# Line 356  int bbsnet_selchange(int new_pos) Line 364  int bbsnet_selchange(int new_pos)
364  int bbs_net()  int bbs_net()
365  {  {
366          int ch, pos, i;          int ch, pos, i;
         char file_config[256];  
367    
368          strcpy(file_config, app_home_dir);          load_bbsnet_conf(CONF_BBSNET);
         strcat(file_config, "conf/bbsnet.conf");  
   
         load_bbsnet_conf(file_config);  
369    
370          BBS_last_access_tm = time(0);          BBS_last_access_tm = time(0);
371    
# Line 394  int bbs_net() Line 398  int bbs_net()
398                          break;                          break;
399                  case KEY_UP:                  case KEY_UP:
400                          for (i = 0; i < STATION_PER_LINE; i++)                          for (i = 0; i < STATION_PER_LINE; i++)
401                            {
402                                  menu_control(&bbsnet_menu, KEY_UP);                                  menu_control(&bbsnet_menu, KEY_UP);
403                            }
404                          pos = bbsnet_menu.p_menu[0]->item_cur_pos;                          pos = bbsnet_menu.p_menu[0]->item_cur_pos;
405                          bbsnet_selchange(pos);                          bbsnet_selchange(pos);
406                          break;                          break;
407                  case KEY_DOWN:                  case KEY_DOWN:
408                          for (i = 0; i < STATION_PER_LINE; i++)                          for (i = 0; i < STATION_PER_LINE; i++)
409                            {
410                                  menu_control(&bbsnet_menu, KEY_DOWN);                                  menu_control(&bbsnet_menu, KEY_DOWN);
411                            }
412                          pos = bbsnet_menu.p_menu[0]->item_cur_pos;                          pos = bbsnet_menu.p_menu[0]->item_cur_pos;
413                          bbsnet_selchange(pos);                          bbsnet_selchange(pos);
414                          break;                          break;


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

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