Aw cav change

From ActiveWiki
Revision as of 11:17, 2 November 2008 by Macavity (talk | contribs) (Cleanup)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


Minimum requirements
Added in version 4.2
SDKbuild 70


int aw_cav_change (void)

Description

Changes the custom universe avatar definition of a user.

Callback

AW_CALLBACK_CAV_RESULT

Notes

It is possible for the custom avatar definition to have an uncompressed size of up to 40940 bytes. It can be 0 bytes long which would cause this method to set an empty AW_CAV_DEFINITION. The maximum compressed size is 4094 bytes.

Arguments

None

Argument attributes

AW_CAV_CITIZEN
Citizen number, set to 0 for tourists and bots.
AW_CAV_SESSION
Session number, must be specified for tourists and bots.
AW_CAV_DEFINITION
Compressed custom avatar definition.

Return values

RC_SUCCESS (1) (2)
RC_NO_CONNECTION (1)
The connection to the universe is down.
RC_UNAUTHORIZED
Instance must be owned by the root account (citizen #1 - universe administrator) to allow changing another user.
RC_NO_SUCH_SESSION (2)
RC_UNABLE_TO_UPDATE_CAV (2)
Unable to update the custom universe avatar.

(1) Possible return values when a callback is installed.

(2) Returned by the universe server.

Returned attributes

AW_CAV_CITIZEN
AW_CAV_SESSION

Usage

/* load a custom avatar preset which was made using the browser */
int cav_set (char *path)
{
  FILE *stream;
  unsigned char src[40940];
  unsigned int src_len = sizeof (src);
  unsigned char dst[4094];
  unsigned int dst_len = sizeof (dst);
  int rc;
  
  stream = fopen (path, "r");
  if (!stream)
  {
    printf ("Unable to open CAV preset file\n");
    return -1;
  }
  src_len = fread (src, 1, sizeof (src), stream);
  fclose (stream);
  
  rc = aw_zip (dst, &dst_len, src, src_len);
  if (rc != RC_SUCCESS)
  {
    printf ("Unable to compress CAV definition (reason %d)\n", rc);
    return rc;
  }
  
  /* change custom avatar of the current instance */
  aw_int_set (AW_CAV_CITIZEN, 0);
  aw_int_set (AW_CAV_SESSION, aw_session ());
  aw_data_set (AW_CAV_DEFINITION, (char*)dst, dst_len);
  
  rc = aw_cav_change ();
  if (rc != RC_SUCCESS)
  {
    printf ("Unable to change CAV definition (reason %d)\n", rc);
    return rc;
  }
  
  return RC_SUCCESS;
}

/* wear custom universe avatar */
aw_int_set (AW_MY_TYPE, AW_CUSTOM_AVATAR);
aw_state_change ();

See also