Pyrogenesis  trunk
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Types | 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  SPlayer
 

Public Member Functions

 XmppClient (const ScriptInterface *scriptInterface, 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 TraceMember (JSTracer *trc)
 
void connect ()
 Network. More...
 
void disconnect ()
 
bool isConnected ()
 
void recv ()
 
void SendIqGetBoardList ()
 Request the leaderboard data from the server. More...
 
void SendIqGetProfile (const std::string &player)
 Request the profile data from the server. More...
 
void SendIqGameReport (const ScriptRequest &rq, JS::HandleValue data)
 Send game report containing numerous game properties to the server. More...
 
void SendIqRegisterGame (const ScriptRequest &rq, JS::HandleValue data)
 Send a request to register a game to the server. More...
 
void SendIqGetConnectionData (const std::string &jid, const std::string &password, const std::string &clientSalt, bool localIP)
 Request the Connection data (ip, port...) from 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 SendIqLobbyAuth (const std::string &to, const std::string &token)
 Send lobby authentication token. More...
 
void SetNick (const std::string &nick)
 Request nick change, real change via mucRoomHandler. More...
 
std::string GetNick () const
 Get current nickname. More...
 
std::string GetJID () const
 
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...
 
const char * GetPresence (const std::string &nickname)
 Get the current xmpp presence of the given nick. More...
 
const char * GetRole (const std::string &nickname)
 Get the current xmpp role of the given nick. More...
 
std::wstring GetRating (const std::string &nickname)
 Get the most recent received rating of the given nick. More...
 
const std::wstring & GetSubject ()
 Get current subject. More...
 
JS::Value GUIGetPlayerList (const ScriptRequest &rq)
 Handle requests from the GUI for the list of players. More...
 
JS::Value GUIGetGameList (const ScriptRequest &rq)
 Handle requests from the GUI for the list of all active games. More...
 
JS::Value GUIGetBoardList (const ScriptRequest &rq)
 Handle requests from the GUI for leaderboard data. More...
 
JS::Value GUIGetProfile (const ScriptRequest &rq)
 Handle requests from the GUI for profile data. More...
 
void SendStunEndpointToHost (const std::string &ip, u16 port, const std::string &hostJID)
 
JS::Value GuiPollNewMessages (const ScriptInterface &guiInterface)
 
JS::Value GuiPollHistoricMessages (const ScriptInterface &guiInterface)
 
bool GuiPollHasPlayerListUpdate ()
 
void SendMUCMessage (const std::string &message)
 Send a standard MUC textual message. 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
 
- Public Member Functions inherited from glooxwrapper::Jingle::SessionHandler
virtual ~SessionHandler ()
 

Static Public Member Functions

static void Trace (JSTracer *trc, void *data)
 
static const char * GetPresenceString (const gloox::Presence::PresenceType presenceType)
 Convert gloox values to string or time. More...
 
static const char * GetRoleString (const gloox::MUCRoomRole role)
 Convert a gloox role type to an untranslated string literal to be used as an identifier by the scripts. More...
 
static std::string StanzaErrorToString (gloox::StanzaError err)
 Convert a gloox stanza error type to string. More...
 
static std::string RegistrationResultToString (gloox::RegistrationResult res)
 Convert a gloox registration result enum to string Keep in sync with Gloox documentation. More...
 
static std::string ConnectionErrorToString (gloox::ConnectionError err)
 Convert a gloox connection error enum to string Keep in sync with Gloox documentation. More...
 
static std::string CertificateErrorToString (gloox::CertStatus status)
 Translates a gloox certificate error codes, i.e. More...
 
static std::time_t ComputeTimestamp (const glooxwrapper::Message &msg)
 Parse and return the timestamp of a historic chat message and return the current time for new chat messages. More...
 
- Static Public Member Functions inherited from IXmppClient
static IXmppClientcreate (const ScriptInterface *scriptInterface, const std::string &sUsername, const std::string &sPassword, const std::string &sRoom, const std::string &sNick, const int historyRequestSize=0, bool regOpt=false)
 

Protected Member Functions

virtual void handleMUCParticipantPresence (glooxwrapper::MUCRoom &room, const glooxwrapper::MUCRoomParticipant, const glooxwrapper::Presence &)
 Update local data when a user changes presence. More...
 
virtual void handleMUCError (glooxwrapper::MUCRoom &room, 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 &room, 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...
 
virtual void handleSessionAction (gloox::Jingle::Action action, glooxwrapper::Jingle::Session &session, const glooxwrapper::Jingle::Session::Jingle &jingle)
 
virtual void handleSessionInitiation (glooxwrapper::Jingle::Session &session, const glooxwrapper::Jingle::Session::Jingle &jingle)
 
template<typename... Args>
void CreateGUIMessage (const std::string &type, const std::string &level, const std::time_t time, Args const &... args)
 

Private Types

using PlayerMap = std::map< glooxwrapper::string, SPlayer >
 

Private Member Functions

 NONCOPYABLE (XmppClient)
 

Private Attributes

glooxwrapper::Clientm_client
 
glooxwrapper::MUCRoomm_mucRoom
 
glooxwrapper::Registrationm_registration
 
glooxwrapper::SessionManagerm_sessionManager
 
std::string m_username
 
std::string m_password
 
std::string m_server
 
std::string m_room
 
std::string m_nick
 
std::string m_xpartamuppId
 
std::string m_echelonId
 
std::string m_connectionDataJid
 
std::string m_connectionDataIqId
 
gloox::CertStatus m_certStatus
 
bool m_initialLoadComplete
 
bool m_isConnected
 
PlayerMap m_PlayerMap
 Map of players. More...
 
bool m_PlayerMapUpdate
 Whether or not the playermap has changed since the last time the GUI checked. 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...
 
const ScriptInterfacem_ScriptInterface
 ScriptInterface to root the values. More...
 
std::deque< JS::Heap< JS::Value > > m_GuiMessageQueue
 Queue of messages for the GUI. More...
 
std::vector< JS::Heap< JS::Value > > m_HistoricGuiMessages
 Cache of all GUI messages received since the login. More...
 
std::wstring m_Subject
 Current room subject/topic. More...
 

Member Typedef Documentation

◆ PlayerMap

Constructor & Destructor Documentation

◆ XmppClient()

XmppClient::XmppClient ( const ScriptInterface scriptInterface,
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
scriptInterface- ScriptInterface to be used for storing GUI messages. Can be left blank for non-visual applications.
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::~XmppClient ( )
virtual

Destroy the xmpp client.

Member Function Documentation

◆ ban()

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.

◆ CertificateErrorToString()

std::string XmppClient::CertificateErrorToString ( gloox::CertStatus  status)
static

Translates a gloox certificate error codes, i.e.

gloox certificate statuses except CertOk. Keep in sync with specifications.

◆ ComputeTimestamp()

std::time_t XmppClient::ComputeTimestamp ( const glooxwrapper::Message msg)
static

Parse and return the timestamp of a historic chat message and return the current time for new chat messages.

Historic chat messages are implement as DelayedDelivers as specified in XEP-0203. Hence, their timestamp MUST be in UTC and conform to the DateTime format XEP-0082.

Returns
Seconds since the epoch.

◆ connect()

void XmppClient::connect ( )
virtual

Network.

Implements IXmppClient.

◆ ConnectionErrorToString()

std::string XmppClient::ConnectionErrorToString ( gloox::ConnectionError  err)
static

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

Parameters
errError to be converted
Returns
Converted error string

◆ CreateGUIMessage()

template<typename... Args>
void XmppClient::CreateGUIMessage ( const std::string &  type,
const std::string &  level,
const std::time_t  time,
Args const &...  args 
)
protected

◆ disconnect()

void XmppClient::disconnect ( )
virtual

Implements IXmppClient.

◆ GetJID()

std::string XmppClient::GetJID ( ) const
virtual

Implements IXmppClient.

◆ GetNick()

std::string XmppClient::GetNick ( ) const
virtual

Get current nickname.

Implements IXmppClient.

◆ GetPresence()

const char * XmppClient::GetPresence ( const std::string &  nickname)
virtual

Get the current xmpp presence of the given nick.

Implements IXmppClient.

◆ GetPresenceString()

const char * XmppClient::GetPresenceString ( const gloox::Presence::PresenceType  presenceType)
static

Convert gloox values to string or time.

Convert a gloox presence type to an untranslated string literal to be used as an identifier by the scripts.

◆ GetRating()

std::wstring XmppClient::GetRating ( const std::string &  nick)
virtual

Get the most recent received rating of the given nick.

Notice that this doesn't request a rating profile if it hasn't been received yet.

Implements IXmppClient.

◆ GetRole()

const char * XmppClient::GetRole ( const std::string &  nickname)
virtual

Get the current xmpp role of the given nick.

Implements IXmppClient.

◆ GetRoleString()

const char * XmppClient::GetRoleString ( const gloox::MUCRoomRole  role)
static

Convert a gloox role type to an untranslated string literal to be used as an identifier by the scripts.

◆ GetSubject()

const std::wstring & XmppClient::GetSubject ( )
virtual

Get current subject.

Implements IXmppClient.

◆ GUIGetBoardList()

JS::Value XmppClient::GUIGetBoardList ( const ScriptRequest rq)
virtual

Handle requests from the GUI for leaderboard data.

Returns
A JS array containing all known leaderboard data

Implements IXmppClient.

◆ GUIGetGameList()

JS::Value XmppClient::GUIGetGameList ( const ScriptRequest rq)
virtual

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

Returns
A JS array containing all known games

Implements IXmppClient.

◆ GUIGetPlayerList()

JS::Value XmppClient::GUIGetPlayerList ( const ScriptRequest rq)
virtual

Handle requests from the GUI for the list of players.

Returns
A JS array containing all known players and their presences

Implements IXmppClient.

◆ GUIGetProfile()

JS::Value XmppClient::GUIGetProfile ( const ScriptRequest rq)
virtual

Handle requests from the GUI for profile data.

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

Implements IXmppClient.

◆ GuiPollHasPlayerListUpdate()

bool XmppClient::GuiPollHasPlayerListUpdate ( )
virtual

Implements IXmppClient.

◆ GuiPollHistoricMessages()

JS::Value XmppClient::GuiPollHistoricMessages ( const ScriptInterface guiInterface)
virtual

Implements IXmppClient.

◆ GuiPollNewMessages()

JS::Value XmppClient::GuiPollNewMessages ( const ScriptInterface guiInterface)
virtual

Implements IXmppClient.

◆ handleAlreadyRegistered()

void XmppClient::handleAlreadyRegistered ( const glooxwrapper::JID )
protectedvirtual

◆ handleDataForm()

void XmppClient::handleDataForm ( const glooxwrapper::JID ,
const glooxwrapper::DataForm &   
)
protectedvirtual

◆ handleIq()

bool XmppClient::handleIq ( const glooxwrapper::IQ iq)
protectedvirtual

Handle portions of messages containing custom stanza extensions.

Implements glooxwrapper::IqHandler.

◆ handleIqID()

virtual void XmppClient::handleIqID ( const glooxwrapper::IQ ,
int   
)
inlineprotectedvirtual

◆ handleLog()

void XmppClient::handleLog ( gloox::LogLevel  level,
gloox::LogArea  area,
const std::string &  message 
)
protectedvirtual

Log (debug) Handler.

◆ handleMessage()

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

Handle a private message.

◆ handleMUCError()

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

Handle MUC room errors.

Implements glooxwrapper::MUCRoomHandler.

◆ handleMUCMessage()

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

Handle a room message.

Implements glooxwrapper::MUCRoomHandler.

◆ handleMUCParticipantPresence()

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

Update local data when a user changes presence.

Implements glooxwrapper::MUCRoomHandler.

◆ handleMUCSubject()

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

Update local cache when subject changes.

Implements glooxwrapper::MUCRoomHandler.

◆ handleOOB()

void XmppClient::handleOOB ( const glooxwrapper::JID ,
const glooxwrapper::OOB &  oob 
)
protectedvirtual

◆ handleRegistrationFields()

void XmppClient::handleRegistrationFields ( const glooxwrapper::JID ,
int  fields,
glooxwrapper::string  instructions 
)
protectedvirtual

◆ handleRegistrationResult()

void XmppClient::handleRegistrationResult ( const glooxwrapper::JID ,
gloox::RegistrationResult  result 
)
protectedvirtual

◆ handleSessionAction()

void XmppClient::handleSessionAction ( gloox::Jingle::Action  action,
glooxwrapper::Jingle::Session session,
const glooxwrapper::Jingle::Session::Jingle jingle 
)
protectedvirtual

◆ handleSessionInitiation()

void XmppClient::handleSessionInitiation ( glooxwrapper::Jingle::Session session,
const glooxwrapper::Jingle::Session::Jingle jingle 
)
protectedvirtual

◆ isConnected()

bool XmppClient::isConnected ( )
virtual

Implements IXmppClient.

◆ kick()

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.

◆ NONCOPYABLE()

XmppClient::NONCOPYABLE ( XmppClient  )
private

◆ onConnect()

void XmppClient::onConnect ( )
protectedvirtual

Handle connection.

Implements glooxwrapper::ConnectionListener.

◆ onDisconnect()

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

Handle disconnection.

Implements glooxwrapper::ConnectionListener.

◆ onTLSConnect()

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

Handle TLS connection.

Implements glooxwrapper::ConnectionListener.

◆ recv()

void XmppClient::recv ( )
virtual

Implements IXmppClient.

◆ RegistrationResultToString()

std::string XmppClient::RegistrationResultToString ( gloox::RegistrationResult  res)
static

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

Parameters
errEnum to be converted
Returns
Converted string

◆ SendIqChangeStateGame()

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.

◆ SendIqGameReport()

void XmppClient::SendIqGameReport ( const ScriptRequest rq,
JS::HandleValue  data 
)
virtual

Send game report containing numerous game properties to the server.

Parameters
dataA JS array of game statistics

Implements IXmppClient.

◆ SendIqGetBoardList()

void XmppClient::SendIqGetBoardList ( )
virtual

Request the leaderboard data from the server.

Implements IXmppClient.

◆ SendIqGetConnectionData()

void XmppClient::SendIqGetConnectionData ( const std::string &  jid,
const std::string &  password,
const std::string &  clientSalt,
bool  localIP 
)
virtual

Request the Connection data (ip, port...) from the server.

Implements IXmppClient.

◆ SendIqGetProfile()

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

Request the profile data from the server.

Implements IXmppClient.

◆ SendIqLobbyAuth()

void XmppClient::SendIqLobbyAuth ( const std::string &  to,
const std::string &  token 
)
virtual

Send lobby authentication token.

Implements IXmppClient.

◆ SendIqRegisterGame()

void XmppClient::SendIqRegisterGame ( const ScriptRequest rq,
JS::HandleValue  data 
)
virtual

Send a request to register a game to the server.

Parameters
dataA JS array of game attributes

Implements IXmppClient.

◆ SendIqUnregisterGame()

void XmppClient::SendIqUnregisterGame ( )
virtual

Send a request to unregister a game to the server.

Implements IXmppClient.

◆ SendMUCMessage()

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

Send a standard MUC textual message.

Implements IXmppClient.

◆ SendStunEndpointToHost()

void XmppClient::SendStunEndpointToHost ( const std::string &  ip,
u16  port,
const std::string &  hostJID 
)
virtual

Implements IXmppClient.

◆ SetNick()

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

Request nick change, real change via mucRoomHandler.

Parameters
nickDesired nickname

Implements IXmppClient.

◆ SetPresence()

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

Change the xmpp presence of the client.

Parameters
presenceA string containing the desired presence

Implements IXmppClient.

◆ StanzaErrorToString()

std::string XmppClient::StanzaErrorToString ( gloox::StanzaError  err)
static

Convert a gloox stanza error type to string.

Keep in sync with Gloox documentation

Parameters
errError to be converted
Returns
Converted error string

◆ Trace()

static void XmppClient::Trace ( JSTracer *  trc,
void *  data 
)
inlinestatic

◆ TraceMember()

void XmppClient::TraceMember ( JSTracer *  trc)

Member Data Documentation

◆ m_BoardList

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

List of rankings.

◆ m_certStatus

gloox::CertStatus XmppClient::m_certStatus
private

◆ m_client

glooxwrapper::Client* XmppClient::m_client
private

◆ m_connectionDataIqId

std::string XmppClient::m_connectionDataIqId
private

◆ m_connectionDataJid

std::string XmppClient::m_connectionDataJid
private

◆ m_echelonId

std::string XmppClient::m_echelonId
private

◆ m_GameList

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

List of games.

◆ m_GuiMessageQueue

std::deque<JS::Heap<JS::Value> > XmppClient::m_GuiMessageQueue
private

Queue of messages for the GUI.

◆ m_HistoricGuiMessages

std::vector<JS::Heap<JS::Value> > XmppClient::m_HistoricGuiMessages
private

Cache of all GUI messages received since the login.

◆ m_initialLoadComplete

bool XmppClient::m_initialLoadComplete
private

◆ m_isConnected

bool XmppClient::m_isConnected
private

◆ m_mucRoom

glooxwrapper::MUCRoom* XmppClient::m_mucRoom
private

◆ m_nick

std::string XmppClient::m_nick
private

◆ m_password

std::string XmppClient::m_password
private

◆ m_PlayerMap

PlayerMap XmppClient::m_PlayerMap
private

Map of players.

◆ m_PlayerMapUpdate

bool XmppClient::m_PlayerMapUpdate
private

Whether or not the playermap has changed since the last time the GUI checked.

◆ m_Profile

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

Profile data.

◆ m_registration

glooxwrapper::Registration* XmppClient::m_registration
private

◆ m_room

std::string XmppClient::m_room
private

◆ m_ScriptInterface

const ScriptInterface* XmppClient::m_ScriptInterface
private

ScriptInterface to root the values.

◆ m_server

std::string XmppClient::m_server
private

◆ m_sessionManager

glooxwrapper::SessionManager* XmppClient::m_sessionManager
private

◆ m_Subject

std::wstring XmppClient::m_Subject
private

Current room subject/topic.

◆ m_username

std::string XmppClient::m_username
private

◆ m_xpartamuppId

std::string XmppClient::m_xpartamuppId
private

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