ReplicaNet and RNLobby
1
|
#include <CodeServer.h>
Classes | |
class | CodeEntry |
Public Types | |
enum | Reply { kReply_ValidKey = 0, kReply_UnspecifiedError, kReply_InvalidKey, kReply_KeyInUse, kReply_Timeout, kReply_CorruptReply } |
enum | { kDefaultPort = 4003 } |
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 XPAddress &address=XPAddress(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) |
int | GetNumRequests (void) const |
Returns the total number of codes queries. | |
int | GetNumFailed (void) const |
Returns the total number of codes queries that were returned as kReply_InvalidKey. | |
Protected Attributes | |
RegistryManagerMap < std::string, CodeEntry, CodeEntry::ThisLess > | mCodes |
MutexClass | mCodesMutex |
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.
bool 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.
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(). |
|
inlinevirtual |
This callback may be used to alter data after it has been received and before the data is processed.
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. |
|
inlinevirtual |
This callback may be used to alter any data in a reply, just before it gets sent.
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. |
|
inlinevirtual |
This callback may be used to alter the actual key queried before it is matched with the database.
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. |
|
inlinevirtual |
This callback may be used to alter the CodeServer::Reply.
reply | The reply from the key query. |
userSuppliedReply | The user supplied reply. |
nOnce1 | The first reply nonce. |
nOnce2 | The second reply nonce. |
|
inlinevirtual |
This callback reports how long an query and reply took starting from when packet data was received until the packet data is sent.
seconds | The time in seconds. |
|
inlinevirtual |
This callback may be used to ascertain the version of the request made.
version | The version of the request. |
float GetCodeTimeout | ( | void | ) | const |
Gets the value configured by SetCodeTimeout()
bool 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.
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. |
bool RemoveCode | ( | const char * | code = 0 | ) |
Removes codes from the database in memory. This function may be used when the code server has been started.
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. |
void 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.
time | The time in seconds. The default value is (60.0f * 30.0f) which is 30 minutes. |
void 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.
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. |
Starts the code server thread and processes code queries. If not already started the network hardware is started.
bool Stop | ( | bool | hardware = false | ) |
Stops the code server thread and stops processing code queries.
hardware | If true this stops the network hardware. The default is false. |