Photon C++ Client API
5.0.7.3
|
Public Member Functions | |
Client (Listener &listener, const Common::JString &applicationID, const Common::JString &appVersion, nByte connectionProtocol=Photon::ConnectionProtocol::DEFAULT, nByte serializationProtocol=Common::SerializationProtocol::DEFAULT) | |
virtual | ~Client (void) |
virtual bool | connect (const AuthenticationValues &authenticationValues=AuthenticationValues(), const Common::JString &nameServerAddress=M_NAMESERVER) |
virtual void | disconnect (void) |
virtual void | service (bool dispatchIncomingCommands=true) |
virtual void | serviceBasic (void) |
virtual bool | sendOutgoingCommands (void) |
virtual bool | sendAcksOnly (void) |
virtual bool | dispatchIncomingCommands (void) |
virtual void | fetchServerTimestamp (void) |
virtual void | resetTrafficStats (void) |
virtual void | resetTrafficStatsMaximumCounters (void) |
virtual Common::JString | vitalStatsToString (bool all) const |
virtual bool | opSubscribe (const Common::JVector< Common::JString > &channels, int messagesFromHistory=0) |
virtual bool | opUnsubscribe (const Common::JVector< Common::JString > &channels) |
template<typename Ftype > | |
bool | opPublishMessage (const Common::JString &channelName, const Ftype &message) |
template<typename Ftype > | |
bool | opPublishMessage (const Common::JString &channelName, const Ftype pMessageArray, int arrSize) |
template<typename Ftype > | |
bool | opPublishMessage (const Common::JString &channelName, const Ftype pMessageArray, const int *pArrSizes) |
template<typename Ftype > | |
bool | opSendPrivateMessage (const Common::JString &userName, const Ftype &message, bool encrypt=false) |
template<typename Ftype > | |
bool | opSendPrivateMessage (const Common::JString &userName, const Ftype pMessageArray, int arrSize, bool encrypt=false) |
template<typename Ftype > | |
bool | opSendPrivateMessage (const Common::JString &userName, const Ftype pMessageArray, const int *pArrSizes, bool encrypt=false) |
virtual bool | opSetOnlineStatus (int status) |
template<typename Ftype > | |
bool | opSetOnlineStatus (int status, const Ftype &message) |
template<typename Ftype > | |
bool | opSetOnlineStatus (int status, const Ftype pMessageArray, int arrSize) |
template<typename Ftype > | |
bool | opSetOnlineStatus (int status, const Ftype pMessageArray, const int *pArrSizes) |
virtual bool | opAddFriends (const Common::JVector< Common::JString > &userIDs) |
virtual bool | opRemoveFriends (const Common::JVector< Common::JString > &userIDs) |
int | getServerTimeOffset (void) const |
int | getServerTime (void) const |
int | getBytesOut (void) const |
int | getBytesIn (void) const |
int | getByteCountCurrentDispatch (void) const |
int | getByteCountLastOperation (void) const |
int | getSentCountAllowance (void) const |
void | setSentCountAllowance (int sentCountAllowance) |
int | getTimePingInterval (void) const |
void | setTimePingInterval (int timePingInterval) |
int | getRoundTripTime (void) const |
int | getRoundTripTimeVariance (void) const |
int | getTimestampOfLastSocketReceive (void) const |
int | getDebugOutputLevel (void) const |
bool | setDebugOutputLevel (int debugLevel) |
const Common::LogFormatOptions & | getLogFormatOptions (void) const |
void | setLogFormatOptions (const Common::LogFormatOptions &formatOptions) |
int | getIncomingReliableCommandsCount (void) const |
short | getPeerID (void) const |
int | getDisconnectTimeout (void) const |
void | setDisconnectTimeout (int disconnectTimeout) |
int | getQueuedIncomingCommands (void) const |
int | getQueuedOutgoingCommands (void) const |
bool | getIsPayloadEncryptionAvailable (void) const |
int | getResentReliableCommands (void) const |
int | getLimitOfUnreliableCommands (void) const |
void | setLimitOfUnreliableCommands (int value) |
bool | getCRCEnabled (void) const |
void | setCRCEnabled (bool crcEnabled) |
int | getPacketLossByCRC (void) const |
bool | getTrafficStatsEnabled (void) const |
void | setTrafficStatsEnabled (bool trafficStatsEnabled) |
int | getTrafficStatsElapsedMs (void) const |
const Photon::TrafficStats & | getTrafficStatsIncoming (void) const |
const Photon::TrafficStats & | getTrafficStatsOutgoing (void) const |
const Photon::TrafficStatsGameLevel & | getTrafficStatsGameLevel (void) const |
nByte | getQuickResendAttempts (void) const |
void | setQuickResendAttempts (nByte quickResendAttempts) |
nByte | getChannelCountUserChannels (void) const |
const Common::JString & | getUserID (void) const |
int | getState (void) const |
int | getDisconnectedCause (void) const |
const Common::JString & | getRegion (void) const |
void | setRegion (const Common::JString ®ion) |
const Common::JVector< Channel * > & | getPublicChannels (void) const |
const Common::JVector< Channel * > & | getPrivateChannels (void) const |
const Channel * | getPublicChannel (const Common::JString &channelName) const |
const Channel * | getPrivateChannel (const Common::JString &userName) const |
Static Public Member Functions | |
static short | getPeerCount (void) |
Central class of the Photon Chat API to connect, handle channels and messages.
This class must be instantiated with a Chat::Listener instance to get the callbacks and with application id that is setup as Photon Chat application. Integrate it into your game loop by calling service() regularly. Call connect() with an Name Server address. Note: Connect covers multiple messages between this client and the servers. A short workflow will connect you to a Chat server. Each Chat::Client resembles a user in chat. Before you send messages in any public channel, that channel must be subscribed. Private channels represent private chats and created automatically on private message sent or received. getPublicChannels() returns list of subscribed channels, containing messages and senders. getPrivateChannels() contains all incoming and sent private messages.
Client | ( | Listener & | listener, |
const Common::JString & | applicationID, | ||
const Common::JString & | appVersion, | ||
nByte | connectionProtocol = Photon::ConnectionProtocol::DEFAULT , |
||
nByte | serializationProtocol = Common::SerializationProtocol::DEFAULT |
||
) |
|
virtual |
Destructor.
|
virtual |
Initiates a connection to the Photon name server. After a successful connection the client automatically connects to a chat front end server and goes to ConnectedToFrontEnd state. After that the client can subscribe to channels and send and receive messages.
authenticationValues | a user's authentication values used during connect for Custom Authentication with Photon. |
nameServerAddress | used to specify a name server address different from the public Photon Cloud name server |
|
virtual |
Disconnects from servers.
|
virtual |
This function executes the PhotonPeer internal processes. Call this regularly!
This function is meant to be called frequently, like once per game loop. It handles the internal calls for keeping the PhotonPeer communication alive, and will take care of sending all local outgoing acknowledgements and messages, as well as dispatching incoming messages to the application and firing the corresponding callbacks. Internally service() calls the following functions:
service() is provided for convenience. If you need to tweak the performance, you can ignore service() and call its three subfunctions directly with individual time intervals, to gain more control over the internal communication process. For instance, calling sendOutgoingCommands() more rarely will result in less packets to be generated, as more commands will be accumulated into a single packet. See sendOutgoingCommands() for more information on efficiency.
For situations where you want to keep the connection alive, but can't process incoming messages (e.g. when loading a level), you can temporarily pass false for parameter dispatchIncomingCommands to skip the calls to dispatchIncomingCommands(). Incoming commands will be stored in the incoming queue until they are dispatched again.
dispatchIncomingCommands | true = dispatchIncomingCommands() will be called; false = dispatchIncomingCommands() won't be called, default is true |
|
virtual |
This function takes care of exchanging data with the system's network layer.
You only need to call this function in case you choose not to use service(), but call the subfunctions of service() directly. Please see the documentation of service() for more information.
serviceBasic() is called from within service(). If you decide not to use service(), then serviceBasic() needs to be called frequently, like once per game loop.
|
virtual |
This function initiates the transmission of outgoing commands.
Any Photon function that generates messages will store these messages as a "command" in an outgoing queue for later transmission. Commands can either be explicitly created operations generated for example by opCustom() or internally generated messages like acknowledgements for reliable messages from other players. sendOutgoingCommands() will initiate the data transmission by passing the outgoing commands to the system's sockets for immediate transmission.
In case of UDP sendOutgoingCommands() will also split the commands into multiple packets if needed and aggregate multiple commands together into one packet, if possible. Because of the latter calling sendOutgoingcommands() more rarely will result in less overhead, as there will be fewer packets for the clients to be sent and processed. The underlying platform can also limit the frequency in which outgoing packets can be sent and received. The downside of lower sending frequencies is a higher latency, until messages are exchanged and acknowledged, which may lead to a jerky gameplay.
To help you keeping track of the incoming and outgoing queues at development time and adjust your sending frequency, there will be a warning message sent to your debugReturn callback if a queue has exceeded the warning threshold.
Usually you don't have to call sendOutgoingCommands() this explicitly, as this is done within service().
|
virtual |
Sends only ACKs (UDP) or Ping (TCP, WS and WSS) instead of queued outgoing commands. Useful to pause sending actual data.
|
virtual |
Checks for incoming commands waiting in the queue, and dispatches a single command to the application.
Dispatching means, that if the command is an operation response or an event, the appropriate callback function will be called). dispatchIncomingCommands() will also take care of generating and queuing acknowledgments for incoming reliable commands. Please note that this function will only dispatch one command per all. If you want to dispatch every single command which is waiting in the queue, call dipatchIncomingCommands() within a while loop, until its return code is false.
|
virtual |
This will fetch the server's timestamp and update the approximation for getServerTime() and getServerTimeOffset().
The server time approximation will NOT become more accurate by repeated calls. Accuracy currently depends on a single roundtrip which is done as fast as possible.
The command used for this is immediately acknowledged by the server. This makes sure the roundtriptime is low and the timestamp + roundtriptime / 2 is close to the original value.
|
virtual |
Creates new instances of TrafficStats and starts a new timer for those.
|
virtual |
Resets traffic stats values that can be maxed out.
|
virtual |
Returns a string of the most interesting connection statistics. When you have issues on the client side, these might contain hints about the issue's cause.
all | If true, Incoming and Outgoing low-level stats are included in the string. |
|
virtual |
Sends a request to subscribe the client to the specified channels, optionally fetching messages newer than a specific ID.
channels | list of channels to subscribe to. |
messagesFromHistory | 0: no history. 1 and higher: number of messages in history. -1: all history. |
|
virtual |
Unsubscribes the client from a list of channels.
The client will remove these channels from the PublicChannels dictionary immediately, if it could send the operation.
channels | list of channels to unsubscribe from. |
template< typename Ftype > bool opPublishMessage | ( | const Common::JString & | channelName, |
const Ftype & | message | ||
) |
Sends a message to the specified public channel.
channelName | channel name |
message | message to send |
template< typename Ftype > bool opPublishMessage | ( | const Common::JString & | channelName, |
const Ftype | pMessageArray, | ||
int | arrSize | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
channelName | channel name |
pMessageArray | message to send |
arrSize | the number of elements in pParameterArray |
template< typename Ftype > bool opPublishMessage | ( | const Common::JString & | channelName, |
const Ftype | pMessageArray, | ||
const int * | pArrSizes | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
channelName | channel name |
pMessageArray | message to send |
pArrSizes | an array holding the number of elements for each dimension of pParameterArray |
template< typename Ftype > bool opSendPrivateMessage | ( | const Common::JString & | userName, |
const Ftype & | message, | ||
bool | encrypt = false |
||
) |
Sends a private message to the specified user and creates a private channel for the conversation with that user if that channel does not exist yet.
userName | user name |
message | message to send |
encrypt | true to send the message encrypted, false (default) to send it unencrypted |
template< typename Ftype > bool opSendPrivateMessage | ( | const Common::JString & | userName, |
const Ftype | pMessageArray, | ||
int | arrSize, | ||
bool | encrypt = false |
||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
userName | user name |
pMessageArray | message to send |
arrSize | the number of elements in pParameterArray |
encrypt | true to send the message encrypted, false (default) to send it unencrypted |
template< typename Ftype > bool opSendPrivateMessage | ( | const Common::JString & | userName, |
const Ftype | pMessageArray, | ||
const int * | pArrSizes, | ||
bool | encrypt = false |
||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
userName | user name |
pMessageArray | message to send |
pArrSizes | an array holding the number of elements for each dimension of pParameterArray |
encrypt | true to send the message encrypted, false (default) to send it unencrypted |
|
virtual |
Sets the user's status (pre-defined or custom) and a status message.
The predefined status values can be found in namespace UserStatus. States UserStatus::INVISIBLE and UserStatus::OFFLINE will make you offline for everyone and send no message.
status | predefined states are in namespace UserStatus. Other values can be used at will |
template< typename Ftype > bool opSetOnlineStatus | ( | int | status, |
const Ftype & | message | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
status | predefined states are in namespace UserStatus. Other values can be used at will |
message | optional status message |
template< typename Ftype > bool opSetOnlineStatus | ( | int | status, |
const Ftype | pMessageArray, | ||
int | arrSize | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
status | predefined states are in namespace UserStatus. Other values can be used at will |
pMessageArray | optional status message |
arrSize | the number of elements in pParameterArray |
template< typename Ftype > bool opSetOnlineStatus | ( | int | status, |
const Ftype | pMessageArray, | ||
const int * | pArrSizes | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
status | predefined states are in namespace UserStatus. Other values can be used at will |
pMessageArray | optional status message |
pArrSizes | an array holding the number of elements for each dimension of pParameterArray |
|
virtual |
Adds users to the list on the Chat Server which will send you status updates for those.
userIDs | list of friend user names |
|
virtual |
Removes users from the list on the Chat Server which will send you status updates for those.
userIDs | list of friend user names |
int getServerTimeOffset | ( | void | ) | const |
In real-time games it's often useful to relate game events to a global common timeline, that's valid for all players and independent from derivations throughout the clients' system times. The Photon Server's System Time can serve as this reference time. The serverTimeOffset represents the difference between the client's local system time and the Photon server's system time.
ServerTime = serverTimeOffset + GETTIMEMS()
The serverTimeOffset is fetched shortly after connect by Photon. Use GETTIMEMS() to get your local time in ms. You can let Photon refetch the offset by calling fetchServerTimestamp(). The ServerTimeOffset will be 0 until shortly after initial connect.
int getServerTime | ( | void | ) | const |
int getBytesOut | ( | void | ) | const |
int getBytesIn | ( | void | ) | const |
int getByteCountCurrentDispatch | ( | void | ) | const |
int getByteCountLastOperation | ( | void | ) | const |
int getSentCountAllowance | ( | void | ) | const |
This is udp specific and will always return 0 for other protocols.
void setSentCountAllowance | ( | int | sentCountAllowance | ) |
Sets the number of re-send retries before a peer is considered lost/disconnected.
This is udp specific and will do nothing at all for other protocols.
sentCountAllowance | the new number of re/-send retries before a peer is considered lost/disconnected. |
int getTimePingInterval | ( | void | ) | const |
void setTimePingInterval | ( | int | timePingInterval | ) |
Sets the time threshold in milliseconds since the last reliable command, before a ping will be sent.
timePingInterval | time threshold in milliseconds since the last reliable command, before a ping will be sent. |
int getRoundTripTime | ( | void | ) | const |
This is, what is commonly called a ping time or just a ping.
int getRoundTripTimeVariance | ( | void | ) | const |
int getTimestampOfLastSocketReceive | ( | void | ) | const |
int getDebugOutputLevel | ( | void | ) | const |
Returns the current level of debug information that's passed on to BaseListener::debugReturn().
bool setDebugOutputLevel | ( | int | debugLevel | ) |
Sets the current level of debug information that's passed on to BaseListener::debugReturn().
debugLevel | one of the values in DebugLevel |
const LogFormatOptions & getLogFormatOptions | ( | void | ) | const |
void setLogFormatOptions | ( | const Common::LogFormatOptions & | formatOptions | ) |
Sets the log format options to the supplied value.
formatOptions | the new value to which the log format options will be set |
int getIncomingReliableCommandsCount | ( | void | ) | const |
short getPeerID | ( | void | ) | const |
int getDisconnectTimeout | ( | void | ) | const |
void setDisconnectTimeout | ( | int | disconnectTimeout | ) |
Sets the maximum time ins milliseconds for making re-send retries before a peer is considered lost/disconnected.
disconnectTimeout | resend max time in ms before a peer is considered lost/disconnected |
int getQueuedIncomingCommands | ( | void | ) | const |
int getQueuedOutgoingCommands | ( | void | ) | const |
bool getIsPayloadEncryptionAvailable | ( | void | ) | const |
int getResentReliableCommands | ( | void | ) | const |
int getLimitOfUnreliableCommands | ( | void | ) | const |
void setLimitOfUnreliableCommands | ( | int | value | ) |
Sets the limit for the queue of received unreliable commands. This works only in UDP. This limit is applied when you call dispatchIncomingCommands. If this client (already) received more than this limit, it will throw away the older ones instead of dispatching them. This can produce bigger gaps for unreliable commands but your client catches up faster. This can be useful when the client couldn't dispatch anything for some time (cause it was in a room but loading a level). If set to 20, the incoming unreliable queues are truncated to 20. If 0, all received unreliable commands will be dispatched. This is a "per channel" value, so each channel can hold commands up to specified limit. This value interacts with dispatchIncomingCommands(): If that is called less often, more commands get skipped.
bool getCRCEnabled | ( | void | ) | const |
void setCRCEnabled | ( | bool | crcEnabled | ) |
Enables or disables CRC. While not connected, this controls if the next connection(s) should use a per-package CRC checksum. If the client is in another state than 'connected', then this function has no effect except for logging an error.
While turned on, the client and server will add a CRC checksum to every sent package. The checksum enables both sides to detect and ignore packages that were corrupted during transfer. Corrupted packages have the same impact as lost packages: They require a re-send, adding a delay and could lead to timeouts. Building the checksum has a low processing overhead but increases integrity of sent and received data. Packages discarded due to failed CRC checks are counted in PhotonPeer.PacketLossByCRC.
int getPacketLossByCRC | ( | void | ) | const |
bool getTrafficStatsEnabled | ( | void | ) | const |
void setTrafficStatsEnabled | ( | bool | trafficStatsEnabled | ) |
Enables or disables the traffic statistics of a peer. Default trafficStatsEnabled: false (disabled).
int getTrafficStatsElapsedMs | ( | void | ) | const |
const Photon::TrafficStats & getTrafficStatsIncoming | ( | void | ) | const |
const Photon::TrafficStats & getTrafficStatsOutgoing | ( | void | ) | const |
const Photon::TrafficStatsGameLevel & getTrafficStatsGameLevel | ( | void | ) | const |
nByte getQuickResendAttempts | ( | void | ) | const |
void setQuickResendAttempts | ( | nByte | quickResendAttempts | ) |
Sets the number of resend attempts for a reliable command can be done in quick succession (after RoundTripTime+4*RoundTripTimeVariance).
nByte getChannelCountUserChannels | ( | void | ) | const |
The IDs from 0 to getChannelCountUserChannels()-1 can be passed as channelID to operations that offer this parameter.
|
static |
const JString & getUserID | ( | void | ) | const |
Returns the unique user id.
int getState | ( | void | ) | const |
Returns client state
int getDisconnectedCause | ( | void | ) | const |
Returns cause of last disconnect event.
const JString & getRegion | ( | void | ) | const |
Returns chat (Name Server) region.
void setRegion | ( | const Common::JString & | region | ) |
Sets chat (Name Server) region. Set it before connect() call.
region | region |
Returns list of subscribed public channels.
Returns list of private chats that client currently has.
const Channel * getPublicChannel | ( | const Common::JString & | channelName | ) | const |
Search subscribed public channels by channel name.
channelName | channel name to search |
const Channel * getPrivateChannel | ( | const Common::JString & | userName | ) | const |
Search private chat by user name.
userName | user name to search |