Aw server world change

From ActiveWiki
Revision as of 04:26, 11 April 2009 by Macavity (talk | contribs) (It will broadcast an event to admin instances when successful)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


Minimum requirements
Added in version 3.1
SDKbuild 18
Worldbuild 28


int aw_server_world_change (int id)

Description

Changes an existing world configuration in a world server.

Callback

AW_CALLBACK_ADMIN_WORLD_RESULT

Notes

This method changes the configuration of the world with a matching id.

If successful then an AW_EVENT_ADMIN_WORLD_INFO with information about the world configuration is sent to all the admin instances.

Arguments

id
Unique id number of a particular world configuration.

Argument attributes

AW_SERVER_ENABLED
AW_SERVER_NAME
AW_SERVER_PASSWORD
AW_SERVER_REGISTRY
AW_SERVER_CARETAKERS

Return values

RC_SUCCESS (1) (2)
RC_NOT_INITIALIZED (1)
RC_NO_INSTANCE (1)
RC_NO_CONNECTION (1)
Network connection to the world is down.
RC_UNAUTHORIZED (2)
Only world server administration instances are allowed to use this method.
RC_NO_SUCH_WORLD (2)
No world configuration with a matching id was found.

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

(2) Returned from the world server; and is passed to any installed callback handler.

Returned attributes

AW_SERVER_ID
AW_SERVER_INSTANCE
AW_SERVER_NAME

Usage

Add a new caretaker to an existing world.

int world_id;
int enabled;
char name[256];
char password[256];
char registry[256];
char caretakers[256 + 20];
int found;

void handle_world_info (void)
{
  if (aw_int (AW_SERVER_ID) == world_id)
  {
    strcpy (name, aw_string (AW_SERVER_NAME));
    strcpy (password, aw_string (AW_SERVER_PASSWORD));
    strcpy (registry, aw_string (AW_SERVER_REGISTRY));
    strcpy (name, aw_string (AW_SERVER_CARETAKERS));
    enabled = aw_bool (AW_SERVER_ENABLED);
    found = 1;
  }
}

void add_caretaker (int world, int caretaker)
{
  int rc;
  
  /* first we have to find the world  */
  
  world_id = world;
  
  aw_callback_set (AW_CALLBACK_ADMIN_WORLD_LIST, NULL);
  aw_event_set (AW_EVENT_ADMIN_WORLD_INFO, handle_world_info);
  
  aw_int_set (AW_SERVER_ID, 0);
  
  found = 0;
  
  do
    aw_server_world_list ();
  while (!found && aw_bool (AW_SERVER_MORE));
  
  if (!found)
  {
    printf ("Could not find world %d.\n", world);
    return;
  }   
  
  /* found the world, now add the caretaker */
  sprintf (caretakers + strlen (caretakers), " %d", caretaker);
  if (strlen (caretakers) > 255)
    printf ("Unable to add caretaker: too many caretakers!\n");
  else
  {
    aw_string_set (AW_SERVER_NAME, name);
    aw_string_set (AW_SERVER_PASSWORD, password);
    aw_string_set (AW_SERVER_REGISTRY, registry);
    aw_string_set (AW_SERVER_CARETAKERS, caretakers);
    aw_bool_set (AW_SERVER_ENABLED, enabled);
    
    rc = aw_server_world_change (world);
    if (rc != RC_SUCCESS)
      printf ("Unable to change world (reason %d)\n", rc);
    else
      printf ("Caretaker %d added to world %s.\n", caretaker, name);
  }
}

See also