AdvertiseClient Class Reference

Maintains a connection to the AdvertiseServer. More...

#include <AdvertiseClient.h>

Inheritance diagram for AdvertiseClient:

Inheritance graph
[legend]
Collaboration diagram for AdvertiseClient:

Collaboration graph
[legend]

List of all members.

Public Member Functions

bool Start (void)
 Because this uses a TransportUDP connection it will call XPURL::RegisterDefaultTransports().
bool StartLAN (void)
 This starts this class to only advertise and find sessions on the LAN.
void SetServer (const XPAddress &address)
bool AdvertiseSession (const char *url, const char *userData="")
bool RulesChanged (void)
 The user may call this notify the server that the session rules have changed. This then causes a new rules list to be requested by CallbackWantRules.
bool PlayersChanged (void)
 The user may call this notify the server that the session players list has changed. This then causes a new players list to be requested by CallbackWantPlayers.
bool StopAdvertiseSession (void)
 Stop advertising the session.
bool GetListings (const size_t maxResults=10, const size_t offset=0, const char *filter=0)
bool StopListings (void)
 Stop the current request for listings.
bool RequestRules (const int serverIndex)
 Request the rules for a specific server. CallbackRulesBegin etc will be called when the rules have been fetched.
bool RequestPlayers (const int serverIndex)
 Request the players for a specific server. CallbackPlayersBegin etc will be called when the rules have been fetched.
bool RequestLatency (const int serverIndex)
bool GetAnyActivePings (void) const
 Returns true if there are any pings active.
bool AddRule (const char *rule, const char *userData="")
 This must only be called during CallbackWantRules().
bool AddPlayer (const char *name, const char *userData="", const int loginID=UserInfo::kAnyLoginID)
bool SendReliableMessage (const int serverIndex, const void *data, const int length)

Protected Member Functions

virtual void CallbackConnectionEstablished (Transport *transport)
 User extendible callbacks.
virtual void CallbackWantRules (void)
 This is called by AdvertiseClient when the user needs to supply rules for the currently advertised server.
virtual void CallbackWantPlayers (void)
 This is called by AdvertiseClient when the user needs to supply players for the currently advertised server.
virtual void CallbackGotServerIndex (const int serverIndex)
 This is called when the server index is known for the currently advertised server.
virtual void CallbackListingsBegin (void)
 This is called at the start when the listings are refreshed.
virtual void CallbackListingsEntry (const int serverIndex, const int hostLoginID, const char *url, const char *userData, const float age, const XPAddress &address)
 This is called when there is a listings entry.
virtual void CallbackListingsComplete (void)
 This is called when there are no more listings.
virtual void CallbackRulesBegin (const int serverIndex)
 This is called the start when the rules for a server index are updated.
virtual void CallbackRule (const int serverIndex, const char *rule, const char *userData)
 This is called when there is a rule for a server index.
virtual void CallbackRulesComplete (const int serverIndex)
 This is called when there are no more rules for a server index.
virtual void CallbackPlayersBegin (const int serverIndex)
 This is called the start when the players for a server index are updated.
virtual void CallbackPlayer (const int serverIndex, const char *name, const char *userData, const int loginID)
 This is called when there is a player for a server index.
virtual void CallbackPlayersComplete (const int serverIndex)
 This is called when there are no more players for a server index.
virtual void CallbackLatencyTo (const int serverIndex, const float latency, const float packetLossPercent)
virtual void CallbackMessageReceived (const int sourceLoginID, const void *data, const int length)
void CallbackTidy (void)
bool CallbackPoll (void)
bool CallbackParseValidMessage (Transport *transport, DynamicMessageHelper &message, const size_t length)

Protected Attributes

XPAddress mServerAddress
bool mIsAdvertising
std::string mCurrentURL
std::string mCurrentUserData
bool mDoingListing
bool mWantRules
bool mDoingRules
bool mWantPlayers
bool mDoingPlayers
XPSocketUrgentmBroadcast
std::string mBroadcastURL
std::string mBroadcastData
std::map< int,
XPAddress
mGotReplyFrom
int mBroadcastServerID
XPAddress mCurrentReply
int mCurrentNOnce
float mRequestListingTime
std::list< std::pair
< float, int > > 
mRequestRulesTimes
std::list< std::pair
< float, int > > 
mRequestPlayersTimes
PingServer mPingServer
bool mServerAddressSet

Classes

class  PingServer
struct  ServerInfo


Detailed Description

Maintains a connection to the AdvertiseServer.

Member Function Documentation

void SetServer ( const XPAddress address  ) 

Sets the address and port of the server. The default for the instance of the class is localhost and port AdvertiseServer::kDefaultPort

Parameters:
address The new address and port number to use for the server

bool AdvertiseSession ( const char *  url,
const char *  userData = "" 
)

One advertised session for each instance of this class. This can be called with any updated details as often as required. Typically this will be used to advertise the exported URL from a NATUDP transport or a ReplicaNet/XPSession session using NATUDP. If using ReplicaNet or XPSession and the instance is a session master (ReplicaNet::IsMaster() == true) or using a NATUDP transport it is a good idea to regularly export the url and call this function with the details. This is because the url can change as the NAT resolution processes does its work. Please see Example11 for details.

bool GetListings ( const size_t  maxResults = 10,
const size_t  offset = 0,
const char *  filter = 0 
)

Gets listings with an optional filter. Using a filter query increases the load on the database depending on how many filters are used.

Parameters:
filter An optional filter to use that is applied at the server before sending data to the client. The filter consists of logical expressions separated by a new-line. For example: Setting a filter to be "rule.needPass = 1\nrule.dedicated = 0" will only return servers that have the rules called needPass and dedicated which are equal to 1 and 0 respectively.

bool RequestLatency ( const int  serverIndex  ) 

Requests the latency to a specific server to be calculated. CallbackLatencyTo will be called when the latency has been calculated.
Depending on how the server is configured and the firewall/NAT used this operation may take a long time to complete or may never complete indicating the server couldn't be reached or there is significant packet loss.

bool AddPlayer ( const char *  name,
const char *  userData = "",
const int  loginID = UserInfo::kAnyLoginID 
)

Adds a player to an advertised server. This must only be called during CallbackWantPlayers()

Parameters:
userID This userID may be the same as the userID from UserClient::GetLoginID(), this is left to the user to implement if required.

bool SendReliableMessage ( const int  serverIndex,
const void *  data,
const int  length 
)

Sends a reliable message to a server index. The message arrives via CallbackMessageReceived(). Zero length message are not sent. The maximum size of the message that can be sent is 512 bytes.

Returns:
false indicates there was an error sending the message, for example the server index may be unknown.

virtual void CallbackConnectionEstablished ( Transport transport  )  [inline, protected, virtual]

User extendible callbacks.

This callback is not triggered during a LAN session query.

virtual void CallbackLatencyTo ( const int  serverIndex,
const float  latency,
const float  packetLossPercent 
) [inline, protected, virtual]

This is called when the latency to a server index has been calculated.

Parameters:
latency This is the time taken in seconds for a packet to reach the machine that is advertising the server index. This is half round trip ping time.
packetLossPercent The packet loss percentage.

virtual void CallbackMessageReceived ( const int  sourceLoginID,
const void *  data,
const int  length 
) [inline, protected, virtual]

This is called when a user defined message is received.

Parameters:
sourceLoginID The source loginID of the packet.
message The message that was sent.

void CallbackTidy ( void   )  [protected, virtual]

This callback may be used to tidy allocation of objects when the thread terminates. The class mutex is locked when executing this callback.

Reimplemented from BaseTransportServer.

bool CallbackPoll ( void   )  [protected, virtual]

Called from the scope of the thread but without the class mutex being locked. This can be called with or without a valid mTransport

Reimplemented from BaseTransportServer.

bool CallbackParseValidMessage ( Transport transport,
DynamicMessageHelper message,
const size_t  length 
) [protected, virtual]

Called from the scope of the thread but without the class mutex being locked. If a MessageHelper::Exception() is caught by this server class the connection will be terminated.

Reimplemented from BaseTransportServer.


Generated on Sat Jun 28 22:02:30 2008 for ReplicaNet and RNLobby by  doxygen 1.5.3