Pyrogenesis  trunk
Classes | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
XmppClient Class Reference

#include <XmppClient.h>

Inheritance diagram for XmppClient:
Inheritance graph
[legend]
Collaboration diagram for XmppClient:
Collaboration graph
[legend]

Classes

struct  GUIMessage
 

Public Member Functions

 XmppClient (const std::string &sUsername, const std::string &sPassword, const std::string &sRoom, const std::string &sNick, const int historyRequestSize=0, const bool regOpt=false)
 Construct the XMPP client. More...
 
virtual ~XmppClient ()
 Destroy the xmpp client. More...
 
void connect ()
 Network. More...
 
void disconnect ()
 
void recv ()
 
void SendIqGetGameList ()
 Request a listing of active games from the server. More...
 
void SendIqGetBoardList ()
 Request the leaderboard data from the server. More...
 
void SendIqGetRatingList ()
 Request the rating data from the server. More...
 
void SendIqGetProfile (const std::string &player)
 Request the profile data from the server. More...
 
void SendIqGameReport (ScriptInterface &scriptInterface, JS::HandleValue data)
 Send game report containing numerous game properties to the server. More...
 
void SendIqRegisterGame (ScriptInterface &scriptInterface, JS::HandleValue data)
 Send a request to register a game to the server. More...
 
void SendIqUnregisterGame ()
 Send a request to unregister a game to the server. More...
 
void SendIqChangeStateGame (const std::string &nbp, const std::string &players)
 Send a request to change the state of a registered game on the server. More...
 
void SetNick (const std::string &nick)
 Request nick change, real change via mucRoomHandler. More...
 
void GetNick (std::string &nick)
 Get current nickname. More...
 
void kick (const std::string &nick, const std::string &reason)
 Kick a player from the current room. More...
 
void ban (const std::string &nick, const std::string &reason)
 Ban a player from the current room. More...
 
void SetPresence (const std::string &presence)
 Change the xmpp presence of the client. More...
 
void GetPresence (const std::string &nickname, std::string &presence)
 Get the current xmpp presence of the given nick. More...
 
void GetRole (const std::string &nickname, std::string &role)
 Get the current xmpp role of the given nick. More...
 
void GetSubject (std::string &subject)
 Get current subject. More...
 
void GUIGetPlayerList (ScriptInterface &scriptInterface, JS::MutableHandleValue ret)
 Handle requests from the GUI for the list of players. More...
 
void GUIGetGameList (ScriptInterface &scriptInterface, JS::MutableHandleValue ret)
 Handle requests from the GUI for the list of all active games. More...
 
void GUIGetBoardList (ScriptInterface &scriptInterface, JS::MutableHandleValue ret)
 Handle requests from the GUI for leaderboard data. More...
 
void GUIGetProfile (ScriptInterface &scriptInterface, JS::MutableHandleValue ret)
 Handle requests from the GUI for profile data. More...
 
ScriptInterfaceGetScriptInterface ()
 
void GuiPollMessage (ScriptInterface &scriptInterface, JS::MutableHandleValue ret)
 Send GUI message queue when queried. More...
 
void SendMUCMessage (const std::string &message)
 Send a standard MUC textual message. More...
 
void ClearPresenceUpdates ()
 Clears all presence updates from the message queue. More...
 
int GetMucMessageCount ()
 Used in order to update the GUI only once when multiple updates are queued. More...
 
- Public Member Functions inherited from IXmppClient
virtual ~IXmppClient ()
 
- Public Member Functions inherited from glooxwrapper::ConnectionListener
virtual ~ConnectionListener ()
 
- Public Member Functions inherited from glooxwrapper::MUCRoomHandler
virtual ~MUCRoomHandler ()
 
- Public Member Functions inherited from glooxwrapper::IqHandler
virtual ~IqHandler ()
 
- Public Member Functions inherited from glooxwrapper::RegistrationHandler
virtual ~RegistrationHandler ()
 
virtual void handleDataForm (const JID &from, const DataForm &form)=0
 
virtual void handleOOB (const JID &from, const OOB &oob)=0
 
- Public Member Functions inherited from glooxwrapper::MessageHandler
virtual ~MessageHandler ()
 
virtual void handleMessage (const Message &msg, MessageSession *session=0)=0
 

Protected Member Functions

virtual void handleMUCParticipantPresence (glooxwrapper::MUCRoom *, const glooxwrapper::MUCRoomParticipant, const glooxwrapper::Presence &)
 Update local data when a user changes presence. More...
 
virtual void handleMUCError (glooxwrapper::MUCRoom *, gloox::StanzaError)
 Handle MUC room errors. More...
 
virtual void handleMUCMessage (glooxwrapper::MUCRoom *room, const glooxwrapper::Message &msg, bool priv)
 Handle a room message. More...
 
virtual void handleMUCSubject (glooxwrapper::MUCRoom *, const glooxwrapper::string &nick, const glooxwrapper::string &subject)
 Update local cache when subject changes. More...
 
virtual void handleLog (gloox::LogLevel level, gloox::LogArea area, const std::string &message)
 Log (debug) Handler. More...
 
virtual void onConnect ()
 Handle connection. More...
 
virtual void onDisconnect (gloox::ConnectionError e)
 Handle disconnection. More...
 
virtual bool onTLSConnect (const glooxwrapper::CertInfo &info)
 Handle TLS connection. More...
 
virtual bool handleIq (const glooxwrapper::IQ &iq)
 Handle portions of messages containing custom stanza extensions. More...
 
virtual void handleIqID (const glooxwrapper::IQ &, int)
 
virtual void handleRegistrationFields (const glooxwrapper::JID &, int fields, glooxwrapper::string instructions)
 
virtual void handleRegistrationResult (const glooxwrapper::JID &, gloox::RegistrationResult result)
 
virtual void handleAlreadyRegistered (const glooxwrapper::JID &)
 
virtual void handleDataForm (const glooxwrapper::JID &, const glooxwrapper::DataForm &)
 
virtual void handleOOB (const glooxwrapper::JID &, const glooxwrapper::OOB &oob)
 
virtual void handleMessage (const glooxwrapper::Message &msg, glooxwrapper::MessageSession *session)
 Handle a private message. More...
 
void GetPresenceString (const gloox::Presence::PresenceType p, std::string &presence) const
 Convert a gloox presence type to string. More...
 
void GetRoleString (const gloox::MUCRoomRole r, std::string &role) const
 Convert a gloox role type to string. More...
 
std::string StanzaErrorToString (gloox::StanzaError err) const
 Convert a gloox stanza error type to string. More...
 
std::string ConnectionErrorToString (gloox::ConnectionError err) const
 Convert a gloox connection error enum to string Keep in sync with Gloox documentation. More...
 
std::string RegistrationResultToString (gloox::RegistrationResult res) const
 Convert a gloox registration result enum to string Keep in sync with Gloox documentation. More...
 
void PushGuiMessage (XmppClient::GUIMessage message)
 Push a message onto the GUI queue. More...
 
void CreateGUIMessage (const std::string &type, const std::string &level, const std::string &text="", const std::string &data="")
 Create a new detail message for the GUI. More...
 

Private Member Functions

 NONCOPYABLE (XmppClient)
 

Private Attributes

glooxwrapper::Clientm_client
 
glooxwrapper::MUCRoomm_mucRoom
 
glooxwrapper::Registrationm_registration
 
std::string m_username
 
std::string m_password
 
std::string m_nick
 
std::string m_xpartamuppId
 
bool m_initialLoadComplete
 
std::map< std::string, std::vector< std::string > > m_PlayerMap
 Map of players. More...
 
std::vector< const glooxwrapper::Tag * > m_GameList
 List of games. More...
 
std::vector< const glooxwrapper::Tag * > m_BoardList
 List of rankings. More...
 
std::vector< const glooxwrapper::Tag * > m_Profile
 Profile data. More...
 
std::deque< GUIMessagem_GuiMessageQueue
 Queue of messages for the GUI. More...
 
std::string m_Subject
 Current room subject/topic. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from IXmppClient
static IXmppClientcreate (const std::string &sUsername, const std::string &sPassword, const std::string &sRoom, const std::string &sNick, const int historyRequestSize=0, bool regOpt=false)
 

Constructor & Destructor Documentation

XmppClient::XmppClient ( const std::string &  sUsername,
const std::string &  sPassword,
const std::string &  sRoom,
const std::string &  sNick,
const int  historyRequestSize = 0,
const bool  regOpt = false 
)

Construct the XMPP client.

Parameters
sUsernameUsername to login with of register.
sPasswordPassword to login with or register.
sRoomMUC room to join.
sNickNick to join with.
historyRequestSizeNumber of stanzas of room history to request.
regOptIf we are just registering or not.
XmppClient::~XmppClient ( )
virtual

Destroy the xmpp client.

Member Function Documentation

void XmppClient::ban ( const std::string &  nick,
const std::string &  reason 
)
virtual

Ban a player from the current room.

Parameters
nickNickname to be banned
reasonReason the player was banned

Implements IXmppClient.

void XmppClient::ClearPresenceUpdates ( )
virtual

Clears all presence updates from the message queue.

Used when rejoining the lobby, since we don't need to handle past presence changes.

Implements IXmppClient.

void XmppClient::connect ( )
virtual

Network.

Implements IXmppClient.

std::string XmppClient::ConnectionErrorToString ( gloox::ConnectionError  err) const
protected

Convert a gloox connection error enum to string Keep in sync with Gloox documentation.

Parameters
errError to be converted
Returns
Converted error string
void XmppClient::CreateGUIMessage ( const std::string &  type,
const std::string &  level,
const std::string &  text = "",
const std::string &  data = "" 
)
protected

Create a new detail message for the GUI.

Parameters
typeGeneral message type
levelDetailed message type
textBody of the message
dataOptional field, used for auxiliary data
void XmppClient::disconnect ( )
virtual

Implements IXmppClient.

int XmppClient::GetMucMessageCount ( )
virtual

Used in order to update the GUI only once when multiple updates are queued.

Implements IXmppClient.

void XmppClient::GetNick ( std::string &  nick)
virtual

Get current nickname.

Parameters
nickVariable to store the nickname in.

Implements IXmppClient.

void XmppClient::GetPresence ( const std::string &  nick,
std::string &  presence 
)
virtual

Get the current xmpp presence of the given nick.

Parameters
nickNickname to look up presence for
presenceVariable to store the presence in

Implements IXmppClient.

void XmppClient::GetPresenceString ( const gloox::Presence::PresenceType  p,
std::string &  presence 
) const
protected

Convert a gloox presence type to string.

Parameters
pPresence to be converted
presenceVariable to store the converted presence string in
void XmppClient::GetRole ( const std::string &  nick,
std::string &  role 
)
virtual

Get the current xmpp role of the given nick.

Parameters
nickNickname to look up presence for
roleVariable to store the role in

Implements IXmppClient.

void XmppClient::GetRoleString ( const gloox::MUCRoomRole  r,
std::string &  role 
) const
protected

Convert a gloox role type to string.

Parameters
pRole to be converted
presenceVariable to store the converted role string in
ScriptInterface& XmppClient::GetScriptInterface ( )
void XmppClient::GetSubject ( std::string &  subject)
virtual

Get current subject.

Parameters
topicVariable to store subject in.

Implements IXmppClient.

void XmppClient::GUIGetBoardList ( ScriptInterface scriptInterface,
JS::MutableHandleValue  ret 
)
virtual

Handle requests from the GUI for leaderboard data.

Returns
A JS array containing all known leaderboard data

Implements IXmppClient.

void XmppClient::GUIGetGameList ( ScriptInterface scriptInterface,
JS::MutableHandleValue  ret 
)
virtual

Handle requests from the GUI for the list of all active games.

Returns
A JS array containing all known games

Implements IXmppClient.

void XmppClient::GUIGetPlayerList ( ScriptInterface scriptInterface,
JS::MutableHandleValue  ret 
)
virtual

Handle requests from the GUI for the list of players.

Returns
A JS array containing all known players and their presences

Implements IXmppClient.

void XmppClient::GUIGetProfile ( ScriptInterface scriptInterface,
JS::MutableHandleValue  ret 
)
virtual

Handle requests from the GUI for profile data.

Returns
A JS array containing the specific user's profile data

Implements IXmppClient.

void XmppClient::GuiPollMessage ( ScriptInterface scriptInterface,
JS::MutableHandleValue  ret 
)
virtual

Send GUI message queue when queried.

Implements IXmppClient.

void XmppClient::handleAlreadyRegistered ( const glooxwrapper::JID )
protectedvirtual
void XmppClient::handleDataForm ( const glooxwrapper::JID ,
const glooxwrapper::DataForm &   
)
protectedvirtual
bool XmppClient::handleIq ( const glooxwrapper::IQ iq)
protectedvirtual

Handle portions of messages containing custom stanza extensions.

Implements glooxwrapper::IqHandler.

virtual void XmppClient::handleIqID ( const glooxwrapper::IQ ,
int   
)
inlineprotectedvirtual
void XmppClient::handleLog ( gloox::LogLevel  level,
gloox::LogArea  area,
const std::string &  message 
)
protectedvirtual

Log (debug) Handler.

void XmppClient::handleMessage ( const glooxwrapper::Message msg,
glooxwrapper::MessageSession *  session 
)
protectedvirtual

Handle a private message.

void XmppClient::handleMUCError ( glooxwrapper::MUCRoom ,
gloox::StanzaError  err 
)
protectedvirtual

Handle MUC room errors.

Implements glooxwrapper::MUCRoomHandler.

void XmppClient::handleMUCMessage ( glooxwrapper::MUCRoom room,
const glooxwrapper::Message msg,
bool  priv 
)
protectedvirtual

Handle a room message.

Implements glooxwrapper::MUCRoomHandler.

void XmppClient::handleMUCParticipantPresence ( glooxwrapper::MUCRoom ,
const glooxwrapper::MUCRoomParticipant  participant,
const glooxwrapper::Presence presence 
)
protectedvirtual

Update local data when a user changes presence.

Implements glooxwrapper::MUCRoomHandler.

void XmppClient::handleMUCSubject ( glooxwrapper::MUCRoom ,
const glooxwrapper::string nick,
const glooxwrapper::string subject 
)
protectedvirtual

Update local cache when subject changes.

Implements glooxwrapper::MUCRoomHandler.

void XmppClient::handleOOB ( const glooxwrapper::JID ,
const glooxwrapper::OOB &  oob 
)
protectedvirtual
void XmppClient::handleRegistrationFields ( const glooxwrapper::JID ,
int  fields,
glooxwrapper::string  instructions 
)
protectedvirtual
void XmppClient::handleRegistrationResult ( const glooxwrapper::JID ,
gloox::RegistrationResult  result 
)
protectedvirtual
void XmppClient::kick ( const std::string &  nick,
const std::string &  reason 
)
virtual

Kick a player from the current room.

Parameters
nickNickname to be kicked
reasonReason the player was kicked

Implements IXmppClient.

XmppClient::NONCOPYABLE ( XmppClient  )
private
void XmppClient::onConnect ( )
protectedvirtual

Handle connection.

Implements glooxwrapper::ConnectionListener.

void XmppClient::onDisconnect ( gloox::ConnectionError  e)
protectedvirtual

Handle disconnection.

Implements glooxwrapper::ConnectionListener.

bool XmppClient::onTLSConnect ( const glooxwrapper::CertInfo info)
protectedvirtual

Handle TLS connection.

Implements glooxwrapper::ConnectionListener.

void XmppClient::PushGuiMessage ( XmppClient::GUIMessage  message)
protected

Push a message onto the GUI queue.

Parameters
messageMessage to add to the queue
void XmppClient::recv ( )
virtual

Implements IXmppClient.

std::string XmppClient::RegistrationResultToString ( gloox::RegistrationResult  res) const
protected

Convert a gloox registration result enum to string Keep in sync with Gloox documentation.

Parameters
errEnum to be converted
Returns
Converted string
void XmppClient::SendIqChangeStateGame ( const std::string &  nbp,
const std::string &  players 
)
virtual

Send a request to change the state of a registered game on the server.

A game can either be in the 'running' or 'waiting' state - the server decides which - but we need to update the current players that are in-game so the server can make the calculation.

Implements IXmppClient.

void XmppClient::SendIqGameReport ( ScriptInterface scriptInterface,
JS::HandleValue  data 
)
virtual

Send game report containing numerous game properties to the server.

Parameters
dataA JS array of game statistics

Implements IXmppClient.

void XmppClient::SendIqGetBoardList ( )
virtual

Request the leaderboard data from the server.

Implements IXmppClient.

void XmppClient::SendIqGetGameList ( )
virtual

Request a listing of active games from the server.

Implements IXmppClient.

void XmppClient::SendIqGetProfile ( const std::string &  player)
virtual

Request the profile data from the server.

Implements IXmppClient.

void XmppClient::SendIqGetRatingList ( )
virtual

Request the rating data from the server.

Implements IXmppClient.

void XmppClient::SendIqRegisterGame ( ScriptInterface scriptInterface,
JS::HandleValue  data 
)
virtual

Send a request to register a game to the server.

Parameters
dataA JS array of game attributes

Implements IXmppClient.

void XmppClient::SendIqUnregisterGame ( )
virtual

Send a request to unregister a game to the server.

Implements IXmppClient.

void XmppClient::SendMUCMessage ( const std::string &  message)
virtual

Send a standard MUC textual message.

Implements IXmppClient.

void XmppClient::SetNick ( const std::string &  nick)
virtual

Request nick change, real change via mucRoomHandler.

Parameters
nickDesired nickname

Implements IXmppClient.

void XmppClient::SetPresence ( const std::string &  presence)
virtual

Change the xmpp presence of the client.

Parameters
presenceA string containing the desired presence

Implements IXmppClient.

std::string XmppClient::StanzaErrorToString ( gloox::StanzaError  err) const
protected

Convert a gloox stanza error type to string.

Keep in sync with Gloox documentation

Parameters
errError to be converted
Returns
Converted error string

Member Data Documentation

std::vector<const glooxwrapper::Tag*> XmppClient::m_BoardList
private

List of rankings.

glooxwrapper::Client* XmppClient::m_client
private
std::vector<const glooxwrapper::Tag*> XmppClient::m_GameList
private

List of games.

std::deque<GUIMessage> XmppClient::m_GuiMessageQueue
private

Queue of messages for the GUI.

bool XmppClient::m_initialLoadComplete
private
glooxwrapper::MUCRoom* XmppClient::m_mucRoom
private
std::string XmppClient::m_nick
private
std::string XmppClient::m_password
private
std::map<std::string, std::vector<std::string> > XmppClient::m_PlayerMap
private

Map of players.

std::vector<const glooxwrapper::Tag*> XmppClient::m_Profile
private

Profile data.

glooxwrapper::Registration* XmppClient::m_registration
private
std::string XmppClient::m_Subject
private

Current room subject/topic.

std::string XmppClient::m_username
private
std::string XmppClient::m_xpartamuppId
private

The documentation for this class was generated from the following files: