SmartFoxServer 3 C++ Client API 3.1.0-beta
Client API for SmartFoxServer 3
Loading...
Searching...
No Matches
sfs3::SmartFox Class Reference

The main class of the SmartFoxServer 3 API. More...

#include <SmartFox.h>

Inheritance diagram for sfs3::SmartFox:
[legend]

Public Member Functions

Result connect (ConfigData cfgData)
 Attempts to connect to the server.
void connectUdp ()
 Starts the UDP protocol, with a handshake with the server.
void disconnect ()
 Disconnects from the server.
void disconnectUdp ()
 Closes the current UDP connection.
Result send (core::BaseRequest &req)
 Sends a request to the server.
Result send (core::BaseRequest &&req)
bool isConnected ()
bool isUdpConnected ()
ConfigDataconfigData ()
core::RoomManagergetRoomManager ()
 Returns a reference to the Room Manager.
core::UserManagergetUserManager ()
 Returns a reference to the User Manager.
core::buddy::BuddyManagergetBuddyManager ()
 Returns a reference to the Buddy Manager.
std::string getVersion ()
std::optional< std::string > getSessionToken ()
 Returns the current session token.
std::shared_ptr< entities::RoomgetLastJoinedRoom () const
 Returns the object of the last Room joined by the client, if any.
std::vector< std::shared_ptr< entities::Room > > getJoinedRooms ()
 Returns the Rooms currently joined by the client.
std::string getConnectionMode ()
 Returns the current connection mode, after a connection is established.
std::optional< std::string > getHttpUploadURI ()
 Returns the HTTP/HTTPS address that can be used to upload files to SmartFoxServer, with an HTTP POST request.
void enableLagMonitor (bool enabled, int interval=core::LagMonitor::DEFAULT_INTERVAL, int queueSize=core::LagMonitor::DEFAULT_QUEUE_SIZE)
 Enables the automatic monitoring of the latency between client and server.
std::shared_ptr< entities::UsergetMySelf () const
 Returns the User object that represents this client on the server.
void processEvents ()
 Processes all the queued events and calls the related handlers, in the current thread.
int reconnectionSeconds ()
void killConnection ()
 Simulates an unexpected loss of the connection, to test the reconnection system.
void setClientDetails (std::string platformId, std::string version)
 Sets custom client details, used to collect statistics about the client platform with the SmartFox Analytics Module.
Public Member Functions inherited from sfs3::event::Listenable< event::SFSEvent >
void addEventListener (event::SFSEvent evtType, event::EventListener listener)
 Adds a listener that handles one event type.
void removeEventListener (event::SFSEvent evtType)
 Removes the listener of one event type.
void removeAllEventListeners ()
 Removes all the listeners that were added.

Detailed Description

The main class of the SmartFoxServer 3 API.

It connects the client to a SmartFoxServer instance and dispatches all the asynchronous events. Developers always interact with the remote server through this object.

One instance models one session cycle: connect, play, disconnect. After a disconnection the instance is spent: discard it and create a new one if you need another session.

NOTE: in all the examples in this documentation, sfs always refers to a SmartFox instance.

Author
The gotoAndPlay() Team, www.smartfoxserver.com

Member Function Documentation

◆ connect()

Result sfs3::SmartFox::connect ( ConfigData cfgData)

Attempts to connect to the server.

The connection is made in the background. The result is notified with an event::SFSEvent::CONNECTION event.

Parameters
cfgDatathe connection settings
Returns
a failed Result, with a message, if the settings are not valid; success if the connection attempt started
See also
ConfigData

◆ connectUdp()

void sfs3::SmartFox::connectUdp ( )

Starts the UDP protocol, with a handshake with the server.

The result is notified with an event::SFSEvent::UDP_CONNECTION event.

You can call this method at any time, provided that a TCP connection to the server is already established and you are logged in. After a successful start, UDP requests can be sent at any time.

For more information see the SFS3 documentation, under Advanced Topics > Using the UDP Protocol.

◆ disconnect()

void sfs3::SmartFox::disconnect ( )

Disconnects from the server.

Triggers an event::SFSEvent::CONNECTION_LOST event.

◆ disconnectUdp()

void sfs3::SmartFox::disconnectUdp ( )

Closes the current UDP connection.

Triggers an event::SFSEvent::UDP_CONNECTION_LOST event.

◆ send() [1/2]

Result sfs3::SmartFox::send ( core::BaseRequest & req)

Sends a request to the server.

All the available request objects are in the requests namespace.

Parameters
reqthe request to send
Returns
a failed Result, with a message, if the client is not connected or the request is not valid; success if the request was sent

◆ send() [2/2]

Result sfs3::SmartFox::send ( core::BaseRequest && req)

◆ isConnected()

bool sfs3::SmartFox::isConnected ( )
Returns
true if there is an active TCP connection to the server, false otherwise

◆ isUdpConnected()

bool sfs3::SmartFox::isUdpConnected ( )
Returns
true if there is an active UDP connection to the server, false otherwise

◆ configData()

ConfigData & sfs3::SmartFox::configData ( )
inline
Returns
the client connection settings
See also
ConfigData

◆ getRoomManager()

core::RoomManager & sfs3::SmartFox::getRoomManager ( )
inline

Returns a reference to the Room Manager.

This manager is used internally by the API. The reference returned here gives access to the list of Rooms and Groups.

Returns
the Room Manager

◆ getUserManager()

core::UserManager & sfs3::SmartFox::getUserManager ( )
inline

Returns a reference to the User Manager.

This manager is used internally by the API. The reference returned here gives access to the list of users.

Returns
the User Manager

◆ getBuddyManager()

core::buddy::BuddyManager & sfs3::SmartFox::getBuddyManager ( )
inline

Returns a reference to the Buddy Manager.

This manager is used internally by the API. The reference returned here gives access to the buddy list and to the related buddy variables.

Returns
the Buddy Manager
See also
entities::Buddy
entities::BuddyVariable

◆ getVersion()

std::string sfs3::SmartFox::getVersion ( )
inline
Returns
the current version of the SmartFoxServer 3 Client API

◆ getSessionToken()

std::optional< std::string > sfs3::SmartFox::getSessionToken ( )
inline

Returns the current session token.

The session token is a unique string sent by the server to the client after the initial handshake. It is empty before the handshake is complete.

Returns
the current session token

◆ getLastJoinedRoom()

std::shared_ptr< entities::Room > sfs3::SmartFox::getLastJoinedRoom ( ) const
inline

Returns the object of the last Room joined by the client, if any.

It is null if no Room was joined yet. Use a requests::JoinRoomRequest to join a Room. After a disconnection it still returns the last joined Room.

Returns
the last joined Room
See also
SmartFox::getJoinedRooms
requests::JoinRoomRequest

◆ getJoinedRooms()

std::vector< std::shared_ptr< entities::Room > > sfs3::SmartFox::getJoinedRooms ( )
inline

Returns the Rooms currently joined by the client.

NOTE: this is the same list returned by core::RoomManager::getJoinedRooms.

Returns
the list of joined Rooms
See also
SmartFox::getLastJoinedRoom
SmartFox::getRoomManager
entities::Room
requests::JoinRoomRequest

◆ getConnectionMode()

std::string sfs3::SmartFox::getConnectionMode ( )

Returns the current connection mode, after a connection is established.

The possible values are "Socket", "HTTP" and "N/A" when there is no connection.

Returns
the current connection mode

◆ getHttpUploadURI()

std::optional< std::string > sfs3::SmartFox::getHttpUploadURI ( )

Returns the HTTP/HTTPS address that can be used to upload files to SmartFoxServer, with an HTTP POST request.

It is empty if the client is not connected and logged in.

For more information on client side uploads see the online documentation, under Advanced Topics > File Uploads.

Returns
the HTTP/HTTPS address to upload files with a POST request

◆ enableLagMonitor()

void sfs3::SmartFox::enableLagMonitor ( bool enabled,
int interval = core::LagMonitor::DEFAULT_INTERVAL,
int queueSize = core::LagMonitor::DEFAULT_QUEUE_SIZE )

Enables the automatic monitoring of the latency between client and server.

While turned on, the event::SFSEvent::PING_PONG event is dispatched continuously, providing the average of the last queueSize measured lag values, plus the highest and lowest values recorded. Re-enabling an already running monitor restarts it, discarding the previous measurements.

NOTE: the lag monitoring can only be enabled after having connected and logged in successfully.

Parameters
enabledThe lag monitoring status: true to start the monitoring, false to stop it.
intervalSeconds to pause between each query (recommended 3-4s); values below 1 are raised to 1.
queueSizeThe amount of values stored temporarily and used to calculate the average lag.
See also
event::SFSEvent::PING_PONG

◆ getMySelf()

std::shared_ptr< entities::User > sfs3::SmartFox::getMySelf ( ) const
inline

Returns the User object that represents this client on the server.

The object is created after a successful login, so it is null before the login, or if the login request failed. It is null again after a logout, while after a disconnection it still returns the last User object.

Returns
the User object of this client
See also
entities::User::isItMe
requests::LoginRequest

◆ processEvents()

void sfs3::SmartFox::processEvents ( )

Processes all the queued events and calls the related handlers, in the current thread.

This is useful when you work in a game engine's main loop, where the game objects must be accessed from the same thread.

NOTE: this method does nothing when ConfigData::threadSafeMode is off, because in that mode the API dispatches the events by itself.

See also
ConfigData::threadSafeMode

◆ reconnectionSeconds()

int sfs3::SmartFox::reconnectionSeconds ( )
inline
Returns
the number of seconds available to complete a reconnection after the connection drops

◆ killConnection()

void sfs3::SmartFox::killConnection ( )

Simulates an unexpected loss of the connection, to test the reconnection system.

For more information see the online SmartFoxServer 3 documentation, under Development Basics > Reconnection system.

◆ setClientDetails()

void sfs3::SmartFox::setClientDetails ( std::string platformId,
std::string version )

Sets custom client details, used to collect statistics about the client platform with the SmartFox Analytics Module.

By default the generic "C++ Client API" label is used as the platform, with no version.

You must call this method before the connection is started. The two strings together must be shorter than 256 characters.

Parameters
platformIdthe id of the platform (e.g. "Unreal")
versionthe version of the platform

The documentation for this class was generated from the following files:
  • SmartFox.h
  • SmartFox.cpp