|
SmartFoxServer 3 C++ Client API 3.1.0-beta
Client API for SmartFoxServer 3
|
The main class of the SmartFoxServer 3 API. More...
#include <SmartFox.h>
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 () |
| ConfigData & | configData () |
| core::RoomManager & | getRoomManager () |
| Returns a reference to the Room Manager. | |
| core::UserManager & | getUserManager () |
| Returns a reference to the User Manager. | |
| core::buddy::BuddyManager & | getBuddyManager () |
| Returns a reference to the Buddy Manager. | |
| std::string | getVersion () |
| std::optional< std::string > | getSessionToken () |
| Returns the current session token. | |
| std::shared_ptr< entities::Room > | getLastJoinedRoom () 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::User > | getMySelf () 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. | |
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.
| 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.
| cfgData | the connection settings |
| 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.
| void sfs3::SmartFox::disconnect | ( | ) |
Disconnects from the server.
Triggers an event::SFSEvent::CONNECTION_LOST event.
| void sfs3::SmartFox::disconnectUdp | ( | ) |
Closes the current UDP connection.
Triggers an event::SFSEvent::UDP_CONNECTION_LOST event.
| Result sfs3::SmartFox::send | ( | core::BaseRequest & | req | ) |
Sends a request to the server.
All the available request objects are in the requests namespace.
| req | the request to send |
| Result sfs3::SmartFox::send | ( | core::BaseRequest && | req | ) |
| bool sfs3::SmartFox::isConnected | ( | ) |
| bool sfs3::SmartFox::isUdpConnected | ( | ) |
|
inline |
|
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.
|
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.
|
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.
|
inline |
|
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.
|
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.
|
inline |
Returns the Rooms currently joined by the client.
NOTE: this is the same list returned by core::RoomManager::getJoinedRooms.
| 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.
| 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.
| 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.
| enabled | The lag monitoring status: true to start the monitoring, false to stop it. |
| interval | Seconds to pause between each query (recommended 3-4s); values below 1 are raised to 1. |
| queueSize | The amount of values stored temporarily and used to calculate the average lag. |
|
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.
| 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.
|
inline |
| 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.
| 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.
| platformId | the id of the platform (e.g. "Unreal") |
| version | the version of the platform |