bw logo

Chapter 4. Implementation

This chapter outlines the important components of BigWorld's XMPP example that is included with FantasyDemo. It is not intended as a complete discussion of the implementation, more of a guide to assist you in working through the parts of the code most relevant to your needs.

Python source code relevant to the FantasyDemo example can be found under the fantasydemo/res/scripts/ directory. Specific files are outlined below in more detail as each component is discussed.

The BigWorld XMPP example can be broken down into four components that are worth discussing individually.

  • XMPP Module

  • XMPP Roster

  • Avatar Implementation

  • XMPP Event Notifier

4.1. XMPP Module

Location: fantasydemo/res/scripts/base/xmpp/

At the time of implementing the XMPP example there were no Python XMPP modules available with a suitable license for redistributing with BigWorld. As a result BigWorld implemented an small module for communicating with an XMPP server which can be found in the afore mentioned directory.

4.1.1. xmpp.Connection

This module class implements the basic communication with an XMPP server. It is responsible for talking XMPP over the wire and communicating the results via the xmpp.Connection.ConnectionHandler interface.

4.1.2. xmpp.Client

Any object that wishes to communicate with an XMPP server can inherit from xmpp.Client and implement concrete versions of the onXmpp* methods to receive notifications from the server in response to roster events.

This implementation also passes through a connection handler (see xmpp.Connection.ConnectionHandler) in xmppConnect rather than implementing the methods itself to allow each user of the XMPP client to implement its own connection based functionality.

4.1.3. xmpp.Parser

This class offers basic XML parsing to separate data received from the XMPP server into useable pieces. This class is only used by the xmpp.Connection class as part of its communication with the XMPP server.

4.1.4. xmpp.Stanzas

This file provides a set of template XML blocks that are used by the xmpp.Connection object for communicating with the XMPP server.

4.1.5. xmpp.Service

xmpp.Service implements a simple initialisation routine to test that an XMPP server that has been specified in the configuration file exists and is ready to communicate.

4.2. XMPP Roster

Location: fantasydemo/res/scripts/common/XMPPRoster.py

The XMPPRoster class offers a generic storage location for friends that exist in a users XMPP roster[1].

The XMPPRoster specifically handles the possibility that multiple transports are in use (eg: XMPP / MSN / ICQ) and allows querying for friends across all transports.

4.3. Avatar Implementation

Location: fantasydemo/res/scripts/base/Avatar.py, fantasydemo/res/scripts/client/Avatar.py, fantasydemo/res/scripts/entity_defs/interfaces/XMPPClient.def

4.3.1. Base Implementation

The Base Avatar class simply inherits from xmpp.Client and implements xmpp.Connection.ConnectionHandler interface which is then provided to xmppConnect.

The only point of note with the usage of xmpp.Client is that because of the xmpp.Connection socket, it is not possible to backup xmpp.Client.xmppConnection. Thus if an entity that implements xmpp.Client is restored, it needs to re-establish the XMPP client connection in the onRestore method.

4.3.2. XMPPClient Interface

This interface is provided as a simple way to pass through Client calls to the xmpp.Client methods that the Avatar base entity has available due to its inheritance.

4.4. XMPP Event Notifier

Location: fantasydemo/res/scripts/base/XMPPEventNotifier.py

The XMPP Event Notifier is very similar to the Avatar example, in that it uses an xmpp.Client to communicate with the XMPP server, however it does not have the same need to inherit from the xmpp.Client as it is not a Proxy and will not need the XMPPClient interface.



[1] The XMPP specification refers to a friends list as a roster to generalise the concept of a collection of users.