Esempio n. 1
0
int mushDoorOpen(DESC *d, int nArgs, char *args[], int id) {
  dbref loc, player = d->player;
  int sock, i_found, retval;
  char *t_buff, *t_bufptr, *s_addy, *s_port, *s_strtok;

  i_found = 1;
  t_bufptr = t_buff = alloc_lbuf("mush_doors");
  s_port = s_strtok = NULL;
  retval = parse_dynhelp(player, player, 0, (char *)"doors", args[0], t_buff, t_bufptr, 1); 
  if ( t_buff && *t_buff && 
       ((strstr(t_buff, (char *)"No entry for") != NULL) ||
        (strstr(t_buff, (char *)"Here are the entries which match") != NULL) ||
        (strstr(t_buff, (char *)"Sorry, that file") != NULL)) ) 
     i_found = 0;
  loc = Location(player);
  if ( i_found && *t_buff && args[0] && *args[0]) {
     s_addy = strtok_r(t_buff, " \t\r\n", &s_strtok);
     if ( s_addy )
        s_port = strtok_r(NULL, " \t\r\n", &s_strtok);
     if ( s_addy && s_port )
        sock = door_tcp_connect(s_addy, s_port, d, id);
     else
        sock = -1;
     if (sock < 0) {
       queue_string(desc_in_use, "Mush connection failed\r\n");
       free_lbuf(t_buff);
       return -1;
     } else {
       queue_string(desc_in_use, "*** CONNECTED ***\r\n");
     }
  } else if ( !i_found || (i_found && args[0] && *args[0]) ) {
     if ( strstr(t_buff, (char *)"Sorry, that file") != NULL )
        queue_string(desc_in_use, "There are currently no mush doors configured.\r\n");
     else
        queue_string(desc_in_use, "Unrecognized mush.  Can not establish connection.\r\n");
     free_lbuf(t_buff);
     return -1;
  } else if ( i_found && (!args[0] || !*args[0]) && t_buff ) {
     queue_string(desc_in_use, t_buff);
  }
  free_lbuf(t_buff);
  return 1;
}
Esempio n. 2
0
int empire_init(DESC *d, int nargs, char *args[], int id)
{
  int sock_req;
  char buf[1024], buf2[80];
  char *pt, *pt2, *country, *password;

  // get country and password
  if ((nargs != 2) || (*args[0] == '\0') || (*args[1] == '\0')) {
    queue_string(d,"Bad arguments to empire door.");
    return -1;
  } 
  country = args[0];
  password = args[1];
  sprintf(buf2, "%s %s", "localhost", "1665");

/*pt = doorparm("empire"); */
  pt = buf2;

  if (*pt == '\0') {
    queue_string(desc_in_use, "Read of door parameters failed.\r\n");
    return -1;
  }
  pt2 = strchr(pt,' ');
  if (pt2 == NULL) {
    queue_string(desc_in_use, "Bad format in door parameters file.\r\n");
    return -1;
  }
  *pt2 = '\0';
  sock_req = door_tcp_connect(pt,pt2+1, d, id);

  if (sock_req < 0) {
    queue_string(desc_in_use, "Connection to empire server failed.\r\n");
    return -1;
  }

  if (!expect(sock_req, C_INIT, buf)) {
    queue_string(desc_in_use, "Login to empire server failed (stage 1).\r\n");
    close(sock_req);
    return -1;
  }
  strcpy(buf,Name(desc_in_use->player));
  strcat(buf,"@");
  strcat(buf,mudconf.mud_name);
  if (!sendcmd(sock_req, USER, buf)) {
    queue_string(desc_in_use, "Login to empire server failed (stage 2).\r\n");
    goto abort;
  }
  if (!expect(sock_req, C_CMDOK, buf)) {
    queue_string(desc_in_use, "Login to empire server failed (stage 3).\r\n");
    goto abort;
  }
  if (!sendcmd(sock_req, COUN, country)) {
    queue_string(desc_in_use, "Login to empire server failed (stage 4).\r\n");
    goto abort;
  }
  if (!expect(sock_req, C_CMDOK, buf)) {
    queue_string(desc_in_use, "Login to empire server failed. Posible bad country name. (stage 5).\r\n");
    goto abort;
  }
  if (!sendcmd(sock_req, PASS, password)) {
    queue_string(desc_in_use, "Login to empire server failed (stage 6).\r\n");
    goto abort;
  }
  if (!expect(sock_req, C_CMDOK, buf)) {
    queue_string(desc_in_use, "Login to empire server failed. Posible bad password. (stage 7).\r\n");
    goto abort;
  }
  if (!sendcmd(sock_req, PLAY, (char *)0)) {
    queue_string(desc_in_use, "Login to empire server failed (stage 8).\r\n");
    goto abort;
  }
  if (!expect(sock_req, C_INIT, buf)) {
    queue_string(desc_in_use, buf);
    queue_string(desc_in_use, "\r\n");
    queue_string(desc_in_use, "Login to empire server failed. (stage 9).\r\n");
    goto abort;
  }

  queue_string(desc_in_use, "\r\n\t-=O=-\r\n");
  process_output(desc_in_use);
  return 1;

 abort:
  free_lbuf(d->door_lbuf);
  free_mbuf(d->door_mbuf);
  close(sock_req);
  return -1;
}