bw logo

Chapter 3. Directory Structure for Service Scripting

Services are scripted objects that are similar to base-only entities. They are designed to integrate additional functionality with the game server. This functionality typically involves external processes.

Each service type is implemented as a collection of Python scripts, and an XML-based definition file that ties the scripts together. These scripts are located in the resource tree under the folder scripts (i.e., <res>/scripts , where <res> is the virtual tree defined ~/.bwmachined.conf).

The list below summarises the important files and directories for services in <res>:

  • <res> Resource tree defined in ~/.bwmachined.conf .

    • scripts Folder containing all service files.

      • services.xml Lists all services to load into the server at start-up time.

      • base Folder contains Python scripts for entities with a base component.

      • common Folder listed in the Python search path for all components. Used for common game code.

        • lib Folder listed in the Python search path for all components. Used for common game code.

      • service Folder contains Python scripts for services to be run on ServiceApps.

      • service_defs Contains an XML .def file for each service listed in file <res>/scripts/services.xml.

        • <service>.def Service definition file. There is one such file for each service defined in <res>/scripts/services.xml.

3.1. The services.xml File

The file <res>/scripts/services.xml is used by the BigWorld engine to determine the types of services available for use.

The file contains a list of Services as elements, as children of the root node:

<root>
    <Service1/>
    <Service2/>
</root>

3.2. The Service Definition File

The service definition file <res>/scripts/service_defs/<service>.def determines how your scripts communicate in BigWorld. This allows the BigWorld system to abstract the tasks of sending and receiving messages into simply calling different script methods on your services. In a sense, the definition file provides an interface to your service, and the Python scripts provide the implementation.

Each service type has a corresponding definition file, named after the service's type name followed by the extension '.def'. For example, a NoteStore service type would have a file called NoteStore.def.

The following file is a 'minimal' service definition file, to aid in quickly defining a new service:

<root>
  <Methods> 1
     <!-- declaration --> 
   </Methods>
</root>

<res>/scripts/service_defs/<service>.def Minimal service definition file

1

For details, see Methods.

3.3. The Service Script Files

BigWorld Technology handles the processing of all services in the Service execution context. Therefore, a script file for each service type is provided for this context.

For example, a NoteStore service will have one script file with the implementation of the class, located at <res>/scripts/service/NoteStore.py

The service's base class defined in the script file is BigWorld.Service, since the file represents the Service execution context.

The start of the script for a NoteStore service could be implemented as below:

import BigWorld

class NoteStore( BigWorld.Service ):
  def __init__( self ):
    BigWorld.Service.__init__( self )

<res>/scripts/service/NoteStore.py Service script file