AW EVENT WORLD ATTRIBUTES

From ActiveWiki
Jump to navigation Jump to search


Minimum requirements
Added in version 2.1
SDKbuild 13


AW_EVENT_WORLD_ATTRIBUTES

Description

Received world attributes.

Notes

This event is received and processed even when an instance is not subscribing to it. Which means that the received attributes will be kept up to date.

If a callback handler has been registered for AW_CALLBACK_ENTER then it will be called before the event handler. Which means that the attributes are valid within the callback handler provided that the rc parameter is RC_SUCCESS.

An instance must subscribe to AW_EVENT_WORLD_DISCONNECT in order to distinguish re-entering a world versus changes being made to the world attributes.

Triggers

Description Triggered by ...self/other Broadcasted ...to entered/neighbors/admins
Instance successfully enters a world aw_enter Self No
Instance successfully sets a world aw_server_world_set Self No
Instance automatically re-enters a world after disconnection aw_wait
any blocking method call
Self No
Changes to the world attributes aw_world_attributes_change
aw_world_attributes_reset
Both Yes Yes/Yes/Yes
User sent world attributes to the instance aw_world_attributes_send Both No

Attributes

AW_ATTRIB_SENDER_SESSION
AW_WORLD_*

Usage

Print the world title on entry and when world attributes are changed or sent.

void handle_world_attributes (void)
{
  printf ("The title is %s\n", aw_string (AW_WORLD_TITLE));
}

aw_event_set (AW_EVENT_WORLD_ATTRIBUTES, handle_world_attributes);

Print the reason for why world attributes were received.

int entering;
int re_entering;

void handle_world_attributes (void)
{
  if (entering)
  {
    printf ("Entered the world\n");
    entering = 0;
  }
  else if (re_entering)
  {
    printf ("Re-entered the world\n");
    re_entering = 0;
  }
  else if (aw_int (AW_ATTRIB_SENDER_SESSION))
  {
    printf ("World attributes sent from session #%d\n", aw_int (AW_ATTRIB_SENDER_SESSION));
  }
  else
  {
    printf ("World attributes changed\n");
  }
}

void handle_world_disconnect (void)
{
  int rc = aw_int (AW_DISCONNECT_REASON);
  
  printf ("Disconnected from the world due to reason #%d\n", rc);
  
  switch (rc)
  {
   case RC_EJECTED:
   case RC_NOT_WELCOME:
     re_entering = 0;
     break;
   default:
     /* automatic re-entering of the world will occur */
     re_entering = 1;
     break;
  }
}

aw_event_set (AW_EVENT_WORLD_ATTRIBUTES, handle_world_attributes);
aw_event_set (AW_EVENT_WORLD_DISCONNECT, handle_world_disconnect);

/* ... */

entering = 1;
aw_enter (world);

Triggered by