ReplicaNet and RNLobby  1
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
StatClient Class Reference

Maintains a connection to the StatServer. More...

#include <StatClient.h>

Inheritance diagram for StatClient:
Inheritance graph
[legend]
Collaboration diagram for StatClient:
Collaboration graph
[legend]

Public Member Functions

bool Start (void)
 Because this uses a TransportUDP connection it will call XPURL::RegisterDefaultTransports()
 
void SetServer (const XPAddress &address)
 
bool WantToUpload (const char *userNonce, const int scriptID)
 
bool UploadData (const void *data, const int size)
 
bool BeginSession (const int scriptID)
 Begins a statistics tracking session.
 
bool UpdatePairsBegin (const char *userNonce)
 For a supplied user nonce begin updating value pairs.
 
bool UpdatePairsValue (const char *name, const char *value=0)
 Sends a value pair to the server. The name and value string is limited to 128 chars. (StatServerPrivate::kMaximumPairValueSize)
 
bool UpdatePairsValue (const char *name, const int value)
 Sends a value pair to the server. The name is limited to 128 chars. (StatServerPrivate::kMaximumPairValueSize)
 
bool UpdatePairsValue (const char *name, const float value)
 Sends a value pair to the server. The name is limited to 128 chars. (StatServerPrivate::kMaximumPairValueSize)
 
bool UpdatePairsEnd (void)
 End updating the current batch of value pairs.
 
bool EndSession (void)
 
- Public Member Functions inherited from BaseTransportServer
void SetEncryptionKey (const void *data, const int length)
 
virtual bool StartWithTransport (Transport *transport, const bool allowDelete=true, const bool isListen=true)
 
virtual bool Stop (void)
 
size_t GetNumConnections (void) const
 Returns the number of active connections.
 
size_t GetNumTotalSessions (void) const
 Returns the total number of connections.
 
bool SetAsDisconnecting (Transport *transport)
 This will put the connection into a list pending disconnection after a timeout period.
 
- Public Member Functions inherited from ThreadClass
 ThreadClass ()
 
virtual ~ThreadClass ()
 
void Sleep (int milliseconds)
 
- Public Member Functions inherited from MutexClass
 MutexClass ()
 
virtual ~MutexClass ()
 
void Lock (void)
 
void UnLock (void)
 
- Public Member Functions inherited from Thread
 Thread ()
 
virtual ~Thread ()
 
void Begin (ThreadClass *threaded_class)
 
void Terminate (void)
 
bool GetTerminated (void)
 
bool GetEverTerminated (void)
 
bool GetIsRunning (void) const
 
void SetPreferredProcessor (int processor=kReplicaNetPreferredProcessorOSChoice)
 
int GetPreferredProcessor (void)
 

Protected Member Functions

virtual void CallbackConnectionEstablished (Transport *transport)
 User extensible callbacks. More...
 
virtual void CallbackUploadAuthenticationFailure (void)
 A virtual callback that is triggered when the userNonce from WantToUpload() fails the authentication check.
 
virtual void CallbackUploadAuthenticationSuccess (void)
 A virtual callback that is triggered when the userNonce from WantToUpload() passes the authentication check.
 
virtual void CallbackUploadACK (const int scriptID)
 A virtual callback that is triggered when UploadData() succeeds.
 
virtual void CallbackBeginSession ()
 A virtual callback that is triggered when the StatServer processes the BeginSession() request.
 
virtual void CallbackEndSession ()
 
virtual void CallbackEndSessionScriptNotFound ()
 
virtual void CallbackEndSessionScriptNotCompleted ()
 
void CallbackTidy (void)
 
bool CallbackPoll (void)
 
bool CallbackParseValidMessage (Transport *transport, DynamicMessageHelper &message, const size_t length)
 
void InitInternalState (void)
 
- Protected Member Functions inherited from BaseTransportServer
virtual bool PackageAndSendData (Transport *transport, const DynamicMessageHelper &message)
 The class mutex is locked during the context of this function.
 
virtual bool CallbackParsePacketData (Transport *transport, void *data, size_t &length, DynamicMessageHelper &result, Entry &entry)
 
virtual void CallbackAccepted (Transport *transport)
 Called when the server accepts a connection or when a non-listen class instance connection gets a first valid reply from the server.
 
virtual void CallbackDisconnected (Transport *transport)
 Called when the transport is disconnected. This is also called if there is a problem trying to connect. It is therefore possible for a non-listen class instance to receive this callback without a corresponding CallbackAccepted()
 
virtual void CallbackDataReceived (DynamicMessageHelper &message)
 
virtual void CallbackDataSend (DynamicMessageHelper &message)
 
virtual void CallbackQueryReplyTime (const float seconds)
 
int ThreadEntry (void)
 
void GenerateNewNonce (void)
 
int GetConnectionNOnce (Transport *transport=0, const Entry *entry=0)
 Gets the connection's NOnce with respect to a Transport.
 
int CalculateConnectionNOnce (Transport *transport)
 
const EntryFindEntry (Transport *transport)
 
- Protected Member Functions inherited from ThreadClass
void DoQuitNow (const int returnCode)
 
void CheckQuit (void)
 

Protected Attributes

XPAddress mServerAddress
 
bool mServerAddressSet
 
bool mCanUpload
 
bool mInASession
 
bool mUpdatingPairs
 
- Protected Attributes inherited from BaseTransportServer
TransportmTransport
 
bool mAllowDelete
 
int mNOnce
 
std::map< Transport *, EntrymConnected
 
bool mIsListen
 
bool mClientGotAPacket
 
bool mClientIsStable
 
Entry mClientEntry
 
size_t mNumConnections
 
size_t mNumTotalConnections
 

Additional Inherited Members

- Public Types inherited from MutexClass
enum  { kNoOwnerThread = -1 }
 
- Static Public Member Functions inherited from BaseTransportServer
static SysTimeType FloatTime (void)
 
- Static Public Member Functions inherited from Thread
static int CallThreadEntry (ThreadClass *thread_class)
 
static int GetCurrentProcessorNumber (void)
 
static size_t GetNumAllocated (void)
 
static size_t GetNumActive (void)
 
- Static Protected Member Functions inherited from ThreadClass
static size_t GetNumAllocated (void)
 

Detailed Description

Maintains a connection to the StatServer.

Member Function Documentation

virtual void CallbackConnectionEstablished ( Transport transport)
inlineprotectedvirtual

User extensible callbacks.

A virtual callback that is triggered when the StatClient connects the the StatServer.

virtual void CallbackEndSession ( )
inlineprotectedvirtual

A virtual callback that is triggered when the StatServer has finished processing the session. Even if there is an error processing the session this callback is called.

virtual void CallbackEndSessionScriptNotCompleted ( )
inlineprotectedvirtual

A virtual callback that is triggered when the StatServer is unable to complete a script. Most likely due to an exception or the script taking too long to execute. This is called before CallbackEndSession()

virtual void CallbackEndSessionScriptNotFound ( )
inlineprotectedvirtual

A virtual callback that is triggered when the StatServer is unable to find the script. This is called before CallbackEndSession()

bool CallbackParseValidMessage ( Transport transport,
DynamicMessageHelper message,
const size_t  length 
)
protectedvirtual

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.

bool CallbackPoll ( void  )
protectedvirtual

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.

void CallbackTidy ( void  )
protectedvirtual

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 EndSession ( void  )

End the statistics tracking session and start the script processing on the StatServer. On the StatServer for each authenticated player this calls the script function ProcessPlayer with the loginID in its own thread. The script function ProcessGame is also called once in its own thread. Each player and tracking session thread has an allocated 2000 script cycles to complete the work and update stats. It is a good idea to use the RNSimpleScriptDebugger to measure how many cycles each function takes. An example script, note the standard include header BootStat of the AsmBranch commands (each 5 bytes) for the script entry point. This BootStat file can instead be included first in the input file list.

    #include <BootStat>

    DefProc ProcessPlayer(loginID)
    EndProc

    DefProc ProcessGame()
    EndProc

Using this standard script it is possible to use the debugger to call the second branch using the command line, using 5 (5 bytes for the AsmBranch) as the start address:

RNSimpleScriptDebugger.exe script.bin 5 script.bnd 
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 StatServer::kDefaultPort or the address resolved by a successful BackendClient::Start().

Parameters
addressThe new address and port number to use for the server
bool UploadData ( const void *  data,
const int  size 
)

Following a successful request to WantToUpload() this function must be used to transfer script data to the server.

Parameters
dataThe data to send.
sizeThe size of the data to send. Currently there is a limit of 64 kilobytes (65536 bytes) (StatServerPrivate::kMaximumScriptSize).
bool WantToUpload ( const char *  userNonce,
const int  scriptID 
)

Using a user nonce, returned from UserClient::RequestUserNonce(), request to upload a script with the corresponding ID. CallbackUploadAuthenticationFailure() is called if the userNonce authentication fails. CallbackUploadAuthenticationSuccess() is called if the userNonce authentication succeeds.