Example #1
0
void empire_prompt(DESC *d)
{
  char buf[1024];

  if (d->door_int1 == C_PROMPT)
    queue_string(d,"\r\n");
  sprintf(buf,"%s%s\r\n",d->door_mbuf,d->door_lbuf);
  queue_string(d,buf);
  process_output(d);
}
Example #2
0
char *make_guest(DESC * d)
{
	int i;
	dbref player, p2;
	static char name[50];

	/*
	 * Nuke extra guests as new guests connect. 
	 */

	for(i = 0; i < mudconf.number_guests; i++) {
		sprintf(name, "%s%d", mudconf.guest_prefix, i + 1);
		p2 = lookup_player(GOD, name, 0);
		if(p2 != NOTHING && !Connected(p2))
			destroy_guest(p2);
	}

	/*
	 * Locate a free guest ID, and eat it. 
	 */

	for(i = 0; i < mudconf.number_guests; i++) {
		sprintf(name, "%s%d", mudconf.guest_prefix, i + 1);
		player = lookup_player(GOD, name, 0);
		if(player == NOTHING)
			break;
	}

	if(i == mudconf.number_guests) {
		queue_string(d,
					 "GAME: All guest ID's are busy, please try again later.\n");
		return NULL;
	}
	sprintf(name, "%s%d", mudconf.guest_prefix, i + 1);
	player = create_guest(name, mudconf.guest_prefix);

	if(player == NOTHING) {
		queue_string(d,
					 "GAME: Error creating guest ID, please try again later.\n");
		log_text(tprintf
				 ("GUEST: Error creating guest ID. '%s' already exists.\n",
				  name));
		return NULL;
	}
	return Name(player);
}
Example #3
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;
}
Example #4
0
void empire_output(DESC *d, int code, char *buf)
{
  switch (code) {
    case C_NOECHO:
      break;	/* maybe do something later */
    case C_FLUSH:
      process_output(d);
      break;
    case C_ABORT:
      queue_string(d,"Aborted\r\n");
      break;
    case C_CMDERR:
    case C_BADCMD:
      queue_string(d,"Error; ");
      break;
    case C_EXIT:
      queue_string(d,"Exit: ");
      break;
    case C_FLASH:
      queue_string(d,"\r\n");
      break;
    default:
      break;
  }
  queue_string(d, buf);
  if (code != C_FLUSH)
    queue_string(d,"\r\n");
  else
    process_output(d);
}
Example #5
0
void cbox_write(const char* text)
{
    // blocking serial output to telemetry port
    int16_t status;
    status = queue_string(text);
    if (status && (serial_interrupt_stopped == 1))
    {
        serial_interrupt_stopped = 0;
        udb_serial_start_sending_data();
    }
    // wait for completion
    while (!serial_interrupt_stopped)
    {
    }
}
Example #6
0
int empire_from_empsrv(DESC *d, char *text)
{
  char *pt1, *pt2, *pt3, *tstrtokr;
  int code;

  pt1 = strtok_r(text,"\n", &tstrtokr);
  if (pt1 != NULL) {
    do {
      pt2 = pt1;
      while (*pt2 && !isspace((int)*pt2))
	pt2++;
      *pt2++ = '\0';
      if (isalpha((int)*pt1))
	code = 10 + (*pt1 - 'a');
      else
	code = *pt1 - '0';
      switch (code) {
	case C_PROMPT:
	  if (sscanf(pt2,"%d %d", &(d->door_int2), &(d->door_int3)) != 2)
	    queue_string(d, "empire: bad server prompt.\r\n");
	  d->door_int1 = code;
	  sprintf(d->door_lbuf, "[%d:%d] Command : ", d->door_int2, d->door_int3);
	  empire_prompt(d);
	  break;
	case C_REDIR:
	  queue_string(d,"empire: redirection not supported.\r\n");
	  break;
	case C_PIPE:
	  queue_string(d,"empire: pipe not supported.\r\n");
	  break;
	case C_FLUSH:
	  d->door_int1 = code;
	  strcpy(d->door_lbuf, pt2);
	  empire_prompt(d);
	  break;
	case C_EXECUTE:
	  pt3 = alloc_lbuf("door_exec_temp");
	  if (pt3 == NULL) {
	    queue_string(d,"Door exec failed.\r\n");
	    break;
	  }
	  strcpy(pt3,pt2);
	  do_command(d,pt3);
	  free_lbuf(pt3);
	  if (!(d->flags & DS_HAS_DOOR)) {
	    queue_string(d,"Exec send EOF failed; Empire door was closed.\r\n");
	    return -1;
	  }
	  else if (WRITE(d->door_desc,"ctld\n", 5) < 5) {
	    queue_string(d,"Exec send EOF failed\r\n");
	    return -1;
	  }
	  break;
	case C_INFORM:
	  if (*pt2) {
	    pt2[strlen(pt2)-1] = '\0';
	    sprintf(d->door_mbuf, "(%s)", pt2+1);
	    empire_prompt(d);
	  }
	  else
	    *(d->door_mbuf) = '\0';
	  break;
	default:
	  empire_output(d, code, pt2);
	  break;
      }
    } while ((pt1 = strtok_r(NULL,"\n", &tstrtokr)) != NULL);
  }
  return 1;
}
Example #7
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;
}