Main Page | Class List | Directories | File List | Class Members

RNReplicaNet::RNLobby::CodeServer Class Reference

#include <CodeServer.h>

List of all members.

Public Types

enum  Reply {
  kReply_ValidKey = 0, kReply_UnspecifiedError, kReply_InvalidKey, kReply_KeyInUse,
  kReply_Timeout, kReply_CorruptReply
}
enum  { kDefaultPort = 20001 }

Public Member Functions

bool ReadCodeFile (const char *filename, const bool duplicateCodeCheck=false)
bool AddCode (const char *code, const bool duplicateCodeCheck=false, const int userSuppliedReply=0)
bool RemoveCode (const char *code=0)
bool Start (const int UDPPort=CodeServer::kDefaultPort)
bool Stop (bool hardware=false)
void SetEncryptionKey (const void *data, const int length)
void SetCodeTimeout (const float time=(60.0f *30.0f))
float GetCodeTimeout (void) const
virtual void CallbackDataReceived (void *data, int &length, const int maxLength, XPAddress &address)
virtual void CallbackVersion (const int version)
virtual void CallbackKeyData (char *keyData, const int maxLength, int &nOnce1, int &nOnce2, bool &updateDatabase)
virtual void CallbackQueryReply (Reply &reply, int &userSuppliedReply, int &nOnce1, int &nOnce2)
virtual void CallbackDataSend (void *data, int &length, const int maxLength, XPAddress &address)
virtual void CallbackQueryReplyTime (const float seconds)

Protected Attributes

RegistryManagerMap< std::string,
CodeEntry, CodeEntry::ThisLess > 
mCodes
MutexClass mCodesMutex

Classes

class  CodeEntry


Detailed Description

This code server uses a UDP socket to respond to queries for the validity of codes. The codes are stored in a file with one code per line. Use the RNLobby::CodeClient class to make queries to this server.


Member Function Documentation

bool RNReplicaNet::RNLobby::CodeServer::AddCode const char *  code,
const bool  duplicateCodeCheck = false,
const int  userSuppliedReply = 0
 

Adds a code to the database in memory. Each code must be no longer than 255 characters. This function may be used when the code server has been started.

Parameters:
code The code to add.
duplicateCodeCheck If this is true then the code is checked to make sure it is not a duplicate code already stored in the database. The default is false, which disables the duplicate code check and makes adding codes slightly faster.
userSuppliedReply This is returned from CodeClient::GetUserSuppliedReply(). This is useful if the key server wishes to communicate that the key has billing problems, been suspended etc. To update userReply for an existing key you may enable duplicateCodeCheck or use RemoveCode() and AddCode().
Returns:
Success returns true, failure returns false.

virtual void RNReplicaNet::RNLobby::CodeServer::CallbackDataReceived void *  data,
int &  length,
const int  maxLength,
XPAddress &  address
[inline, virtual]
 

This callback may be used to alter data after it has been received and before the data is processed.

Parameters:
data The pointer to the data.
length The length of the data. If the output length changes then this variable can be used to pass the value back by reference. A returned length of zero discards the packet.
maxLength The maximum length of the data buffer. Parameter length must not be greater than this value.
address The network address for this data packet. The contents of the address may be changed if required.

virtual void RNReplicaNet::RNLobby::CodeServer::CallbackDataSend void *  data,
int &  length,
const int  maxLength,
XPAddress &  address
[inline, virtual]
 

This callback may be used to alter any data in a reply, just before it gets sent.

Parameters:
data The pointer to the data.
length The length of the data. If the output length changes then this variable can be used to pass the value back by reference. A returned length of zero discards the packet.
maxLength The maximum length of the data buffer. Parameter length must not be greater than this value.
address The network address for this data packet. The contents of the address may be changed if required.

virtual void RNReplicaNet::RNLobby::CodeServer::CallbackKeyData char *  keyData,
const int  maxLength,
int &  nOnce1,
int &  nOnce2,
bool &  updateDatabase
[inline, virtual]
 

This callback may be used to alter the actual key queried before it is matched with the database.

Parameters:
keyData The pointer to a null terminated char string.
maxLength The maximum length of the data buffer, including the null termination character.
nOnce1 The first nonce.
nOnce2 The second nonce.
updateDatabase This defaults to true, meaning that the query will update the database with the results of the search. If this is changed to be false the query will only be read only. A read only query does not require correct nonce values to be able to return kReply_ValidKey.

virtual void RNReplicaNet::RNLobby::CodeServer::CallbackQueryReply Reply &  reply,
int &  userSuppliedReply,
int &  nOnce1,
int &  nOnce2
[inline, virtual]
 

This callback may be used to alter the CodeServer::Reply.

Parameters:
reply The reply from the key query.
userSuppliedReply The user supplied reply.
nOnce1 The first reply nonce.
nOnce2 The second reply nonce.

virtual void RNReplicaNet::RNLobby::CodeServer::CallbackQueryReplyTime const float  seconds  )  [inline, virtual]
 

This callback reports how long an query and reply took starting from when packet data was received until the packet data is sent.

Parameters:
seconds The time in seconds.

virtual void RNReplicaNet::RNLobby::CodeServer::CallbackVersion const int  version  )  [inline, virtual]
 

This callback may be used to ascertain the version of the request made.

Parameters:
version The version of the request.

float RNReplicaNet::RNLobby::CodeServer::GetCodeTimeout void   )  const
 

Gets the value configured by SetCodeTimeout()

Returns:
The value configured by SetCodeTimeout()

bool RNReplicaNet::RNLobby::CodeServer::ReadCodeFile const char *  filename,
const bool  duplicateCodeCheck = false
 

Reads codes from a file and stores the codes in a database in memory. Each code must be in a separate line. This function may be used when the code server has been started. Each call to this function will add codes to the database held in memory. Each code must be no longer than 255 characters.

Parameters:
filename The filename to read.
duplicateCodeCheck If this is true then each code is checked to make sure it is not a duplicate code already stored in the database. The default is false, which disables the duplicate code check and makes adding codes slightly faster.
Returns:
Success returns true, failure returns false.

bool RNReplicaNet::RNLobby::CodeServer::RemoveCode const char *  code = 0  ) 
 

Removes codes from the database in memory. This function may be used when the code server has been started.

Parameters:
code If the code is supplied the code is removed from the database in memory. If there is no code supplied then all codes are removed from the database in memory.
Returns:
Success returns true, failure returns false.

void RNReplicaNet::RNLobby::CodeServer::SetCodeTimeout const float  time = (60.0f *30.0f)  ) 
 

This sets the time period that a code will be flagged as being used and kReply_KeyInUse will be returned from CodeClient::GetReply(). After this time period has elapsed a request to validate the same code will be allowed.

Parameters:
time The time in seconds. The default value is (60.0f * 30.0f) which is 30 minutes.

void RNReplicaNet::RNLobby::CodeServer::SetEncryptionKey const void *  data,
const int  length
 

Sets the encryption key to be used by all queries for this server. The same key must be used with any RNLobby::CodeClient querying this server. The default encryption key is the same for RNLobby::CodeServer and RNLobby::CodeClient.

Parameters:
data The data to use as a seed for the key. This can be NULL to use the default key.
length The length of the data to use for creating the key.

bool RNReplicaNet::RNLobby::CodeServer::Start const int  UDPPort = CodeServer::kDefaultPort  ) 
 

Starts the code server thread and processes code queries. If not already started the network hardware is started.

Returns:
Success returns true, failure returns false.

bool RNReplicaNet::RNLobby::CodeServer::Stop bool  hardware = false  ) 
 

Stops the code server thread and stops processing code queries.

Parameters:
hardware If true this stops the network hardware. The default is false.
Returns:
Success returns true, failure returns false.


The documentation for this class was generated from the following file:
Generated on Sun Oct 30 01:12:44 2005 for RNLobby by  doxygen 1.4.1