Aw server world start

From ActiveWiki
Revision as of 04:39, 11 April 2009 by Macavity (talk | contribs)
(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_start (int id)

Description

Starts a world.

Callback

AW_CALLBACK_ADMIN_WORLD_RESULT

Notes

This method changes the state of a world in the AW_SERVER_STOPPED state (as indicated by the attribute AW_SERVER_STATE) to AW_SERVER_STARTING. It will fail if the world is in any state other than AW_SERVER_STOPPED. A server in the AW_SERVER_STARTING state will attempt to start by sending its name and password to the universe server. If the world identifier is valid, the world will start and its state will become AW_SERVER_RUNNING. If the start attempt fails, AW_SERVER_STATE will return to AW_SERVER_STOPPED and AW_SERVER_START_RC will indicate the reason for the failure.

The various changes in a world's state resulting from this call will be indicated by the event AW_EVENT_ADMIN_WORLD_INFO.

Arguments

id
Unique id number of a particular world configuration.

Argument attributes

None

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.
RC_ALREADY_STARTED (2) (3)
Already started.
RC_WORLD_DISABLED (2) (3)
World is disabled.

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

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

(3) Not used in version 4.1 and later.

Returned attributes

AW_SERVER_ID
AW_SERVER_INSTANCE
AW_SERVER_NAME

Usage

Restart any stopped worlds in the current world server.

void handle_admin_result (int rc)
{
  if (rc != RC_SUCCESS)
    printf ("Unable to start world (reason %d)\n", rc);
}

void handle_world_info (void)
{
  /* if a world is stopped, try to start it. */
  /* Note: it is okay to call aw_server_world_start here
     since we have installed a handler for the callback to put it
     into asynchronous mode. It's not safe to call synchronous
     methods from within event handlers. */
  
  if (aw_int (AW_SERVER_STATE) == AW_SERVER_STOPPED))
    aw_server_world_start (aw_int (AW_SERVER_ID));
}

void start_stopped_worlds (void)
{
  int rc;
  
  /* restart any worlds in the stopped state */
  aw_callback_set (AW_CALLBACK_ADMIN_WORLD_LIST, NULL);
  aw_callback_set (AW_CALLBACK_ADMIN_WORLD_RESULT, handle_admin_result);
  aw_event_set (AW_EVENT_ADMIN_WORLD_INFO, handle_world_info);
  
  aw_int_set (AW_SERVER_ID, 0);
  
  do
  {
    rc = aw_server_world_list ();
    if (rc != RC_SUCCESS)
    {
      printf ("Unable to query world list (reason %d)\n", rc);
      break;
    }
  }
  while (aw_bool (AW_SERVER_MORE));
}

See also