Exemple #1
0
static char *
quick_space_unparse(dbref object)
{
  static char buff[BUFFER_LEN], *bp;

  switch (object) {
  case NOTHING:
    strcpy(buff, T("*NOTHING*"));
    break;
  case AMBIGUOUS:
    strcpy(buff, T("*VARIABLE*"));
    break;
  case HOME:
    strcpy(buff, T("*HOME*"));
    break;
  default:
    bp = buff;
    safe_format(buff, &bp, "%s(#%d%s)",
		Name(object), object, unparse_flags(object, GOD));
    *bp = '\0';
  }

  return buff;
}
Exemple #2
0
/** Populate a ufun_attrib struct from an obj/attr pair.
 * \verbatim Given an attribute [<object>/]<name> pair (which may include #lambda),
 * fetch its value, owner (thing), and pe_flags, and store in the struct
 * pointed to by ufun
 * \endverbatim
 * \param attrstring The obj/name of attribute.
 * \param executor Dbref of the executing object.
 * \param ufun Pointer to an allocated ufun_attrib struct to fill in.
 * \param flags A bitwise or of desired UFUN_* flags.
 * \return 0 on failure, true on success.
 */
bool
fetch_ufun_attrib(const char *attrstring, dbref executor, ufun_attrib * ufun,
                  int flags)
{
  char *thingname, *attrname;
  char astring[BUFFER_LEN];
  ATTR *attrib;

  if (!ufun)
    return 0;

  ufun->contents[0] = '\0';
  ufun->errmess = (char *) "";
  ufun->thing = executor;
  ufun->pe_flags = PE_UDEFAULT;
  ufun->ufun_flags = flags;

  ufun->thing = executor;
  thingname = NULL;

  if (!attrstring)
    return 0;
  strncpy(astring, attrstring, BUFFER_LEN);

  /* Split obj/attr */
  if ((flags & UFUN_OBJECT) && ((attrname = strchr(astring, '/')) != NULL)) {
    thingname = astring;
    *(attrname++) = '\0';
  } else {
    attrname = astring;
  }

  if (thingname && (flags & UFUN_LAMBDA)
      && (strcasecmp(thingname, "#lambda") == 0
          || strncasecmp(thingname, "#apply", 6) == 0)) {
    /* It's a lambda. */

    ufun->ufun_flags &= ~UFUN_NAME;
    ufun->thing = executor;
    if (strcasecmp(thingname, "#lambda") == 0)
      mush_strncpy(ufun->contents, attrname, BUFFER_LEN);
    else {                      /* #apply */
      char *ucb = ufun->contents;
      unsigned nargs = 1, n;

      thingname += 6;

      if (*thingname)
        nargs = parse_uinteger(thingname);

      /* Limit between 1 and 10 arguments (%0-%9) */
      if (nargs == 0)
        nargs = 1;
      if (nargs > 10)
        nargs = 10;

      safe_str(attrname, ufun->contents, &ucb);
      safe_chr('(', ufun->contents, &ucb);
      for (n = 0; n < nargs; n++) {
        if (n > 0)
          safe_chr(',', ufun->contents, &ucb);
        safe_format(ufun->contents, &ucb, "%%%u", n);
      }
      safe_chr(')', ufun->contents, &ucb);
      *ucb = '\0';
    }

    ufun->attrname[0] = '\0';
    return 1;
  }

  if (thingname) {
    /* Attribute is on something else. */
    ufun->thing =
      noisy_match_result(executor, thingname, NOTYPE, MAT_EVERYTHING);
    if (!GoodObject(ufun->thing)) {
      ufun->errmess = (char *) "#-1 INVALID OBJECT";
      return 0;
    }
  }

  attrib = (ATTR *) atr_get(ufun->thing, upcasestr(attrname));
  if (attrib && AF_Internal(attrib)) {
    /* Regardless of whether we're doing permission checks, we should
     * never be showing internal attributes here */
    attrib = NULL;
  }

  /* An empty attrib is the same as no attrib. */
  if (attrib == NULL) {
    if (flags & UFUN_REQUIRE_ATTR) {
      if (!(flags & UFUN_IGNORE_PERMS) && !Can_Examine(executor, ufun->thing))
        ufun->errmess = e_atrperm;
      return 0;
    } else {
      mush_strncpy(ufun->attrname, attrname, ATTRIBUTE_NAME_LIMIT + 1);
      return 1;
    }
  }
  if (!(flags & UFUN_IGNORE_PERMS)
      && !Can_Read_Attr(executor, ufun->thing, attrib)) {
    ufun->errmess = e_atrperm;
    return 0;
  }
  if (!(flags & UFUN_IGNORE_PERMS)
      && !CanEvalAttr(executor, ufun->thing, attrib)) {
    ufun->errmess = e_perm;
    return 0;
  }

  /* DEBUG attributes */
  if (AF_NoDebug(attrib))
    ufun->pe_flags |= PE_NODEBUG;       /* No_Debug overrides Debug */
  else if (AF_Debug(attrib))
    ufun->pe_flags |= PE_DEBUG;

  if (flags & UFUN_NAME) {
    if (attrib->flags & AF_NONAME)
      ufun->ufun_flags &= ~UFUN_NAME;
    else if (attrib->flags & AF_NOSPACE)
      ufun->ufun_flags |= UFUN_NAME_NOSPACE;
  }

  /* Populate the ufun object */
  mush_strncpy(ufun->contents, atr_value(attrib), BUFFER_LEN);
  mush_strncpy(ufun->attrname, AL_NAME(attrib), ATTRIBUTE_NAME_LIMIT + 1);

  /* We're good */
  return 1;
}
Exemple #3
0
void get_ship_attribute(hship *ship, char *which, char *buff, char **bp)
{
  int len, i;
  
  if (!ship)
  {
    safe_str("#-1 INVALID OBJECT", buff, bp);
    return;
  }
  
  if (!which)
  {
    safe_str("#-1 INVALID ATTRIBUTE", buff, bp);
    return;
  }
  
  len = strlen(which);
  if (len < 1)
  {
    safe_str("#-1 INVALID ATTRIBUTE", buff, bp);
    return;
  }
  
  if (!strncasecmp("OBJNUM", which, len))
  {
    safe_dbref(ship->objnum, buff, bp);
  }
  else if (!strncasecmp("NAME", which, len))
  {
    safe_str(ship_name(ship), buff, bp);
  }
  else if (!strncasecmp("TYPE", which, len))
  {
    if (HasFlag(ship->type, HS_DRONE))
      safe_str("DRONE", buff, bp);
    else
      safe_str("SHIP", buff, bp);
  }
  else if (!strncasecmp("UNIVERSE", which, len))
  {
    if (ship->uid)
      safe_dbref(ship->uid->objnum, buff, bp);
    else
      safe_dbref(NOTHING, buff, bp);
  }
  else if (!strncasecmp("X", which, len))
  {
    safe_integer(ship->x, buff, bp);
  }
  else if (!strncasecmp("Y", which, len))
  {
    safe_integer(ship->y, buff, bp);
  }
  else if (!strncasecmp("Z", which, len))
  {
    safe_integer(ship->z, buff, bp);
  }
  else if (!strncasecmp("SPEED", which, len))
  {
    safe_number(ship->speed, buff, bp);
  }
  else if (!strncasecmp("XYHEAD", which, len))
  {
    safe_integer(rint(ship->xyhead), buff, bp);
  }
  else if (!strncasecmp("ZHEAD", which, len))
  {
    safe_integer(rint(ship->zhead), buff, bp);
  }
  else if (!strncasecmp("LOCK", which, len))
  {
    if (ship->lock)
      safe_integer(ship->lock->cnum, buff, bp);
    else
      safe_str("#-1", buff, bp);
  }
  else if (!strncasecmp("WAYPOINT", which, len))
  {
    if (ship->wp_contact && ship->wp_contact->contact)
    {
      if (HasFlag(ship->wp_contact->type, HS_ANY_CELESTIAL))
      {
        safe_format(buff, bp, "#%d %.0f %.0f %.0f", ContactObj(ship->wp_contact), ContactCelestial(ship->wp_contact)->x,
              ContactCelestial(ship->wp_contact)->y, ContactCelestial(ship->wp_contact)->z);
      }
      else if (HasFlag(ship->wp_contact->type, HS_ANY_SHIP))
      {
        safe_format(buff, bp, "#%d %.0f %.0f %.0f", ContactObj(ship->wp_contact), ContactShip(ship->wp_contact)->x,
              ContactShip(ship->wp_contact)->y, ContactShip(ship->wp_contact)->z);
      }
    }
  }
  else if (!strncasecmp("CONSOLES", which, len))
  {
    for (i = 0; i < ship->nconsoles; i++)
    {
      if (i > 0)
        safe_str(" ", buff, bp);
      
      safe_dbref(ship->console[i].objnum, buff, bp);
    }
  }
  else if (!strncasecmp("LANDED", which, len))
  {
    if (ship->landed)
      safe_dbref(ship->landed->objnum, buff, bp);
    else
      safe_dbref(NOTHING, buff, bp);
  }
  else if (!strncasecmp("DOCKED", which, len))
  {
    if (ship->docked)
      safe_dbref(ship->docked->objnum, buff, bp);
    else
      safe_dbref(NOTHING, buff, bp);
  }
  else if (!strncasecmp("LINKED", which, len))
  {
    if (ship->linked)
      safe_dbref(ship->linked->objnum, buff, bp);
    else
      safe_dbref(NOTHING, buff, bp);
  }
  else if (!strncasecmp("ZHEAD", which, len))
  {
    safe_integer(rint(ship->zhead), buff, bp);
  }
  else if (!strncasecmp("NAVMODE", which, len))
  {
    safe_str(STR(hs_nav_modes, HasFlag(ship->type, HS_ANY_MODE)), buff, bp);
  }
  else if (!strncasecmp("AFTERBURNING", which, len))
  {
    if (HasFlag(ship->type, HS_AFTERBURNING))
      safe_integer(1, buff, bp);
    else
      safe_integer(0, buff, bp);
  }
  else if (!strncasecmp("SHIELD", which, len))
  {
    safe_integer(rint(ship->shield.energy / get_stat(ship, SYS_MAX_CAPACITY) * 100.0), buff, bp);
  }
  else if (!strncasecmp("HULL", which, len))
  {
    safe_integer(rint(ship->hull.energy / get_stat(ship, SYS_MAX_ARMOR) * 100.0), buff, bp);
  }
  else if (!strncasecmp("ENGINE", which, len))
  {
    safe_integer(rint(ship->engine.energy / get_stat(ship, SYS_MAX_HEAT) * 100.0), buff, bp);
  }
  else if (!strncasecmp("REACTOR", which, len))
  {
    safe_integer(rint(ship->reactor.energy / get_stat(ship, SYS_MAX_ENERGY) * 100.0), buff, bp);
  }
  else if (!strncasecmp("COMPUTER", which, len))
  {
    safe_integer(rint(ship->computer.energy / get_stat(ship, SYS_MAX_MEMORY) * 100.0), buff, bp);
  }
  else if (!strncasecmp("SENSOR", which, len))
  {
    safe_integer(rint(ship->sensor.energy / get_stat(ship, SYS_MAX_FOCUS) * 100.0), buff, bp);
  }
  else
  {
    safe_str("#-1 INVALID ATTRIBUTE", buff, bp);
  }

  return;
}