Table of Contents
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
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.
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.
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.
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.
This file provides a set of template XML blocks that are used by
the xmpp.Connection
object for communicating with
the XMPP server.
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.
Location:
fantasydemo/res/scripts/base/Avatar.py
,
fantasydemo/res/scripts/client/Avatar.py
,
fantasydemo/res/scripts/entity_defs/interfaces/XMPPClient.def
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.
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.