Planeshift
|
This class controls loading and saving Characters and Character specific data to and from an iDatabase. More...
#include <pscharacterloader.h>
Public Member Functions | |
bool | AccountOwner (const char *characterName, AccountID accountID) |
Checks to see if the character name is owned by a particular ID. | |
bool | DeleteCharacterData (PID pid, csString &error) |
Deletes character data to the database. | |
PID | FindCharacterID (const char *character_name, bool excludeNPCs=true) |
This function finds a character's ID given a character name. | |
PID | FindCharacterID (AccountID accountID, const char *character_name) |
This function finds a character's ID given a character name and the ID of the account that this character is supposed to be on. | |
bool | Initialize () |
Initializes settings related to this class. | |
unsigned int | InsertNewCharacterData (const char **fieldnames, psStringArray &fieldvalues) |
psCharacter ** | LoadAllNPCCharacterData (psSectorInfo *sector, int &count) |
psCharacter * | LoadCharacterData (PID pid, bool forceReload) |
Loads data for a character from the database and constructs and fills a new psCharacter object with the data. | |
psCharacterList * | LoadCharacterList (AccountID accountid) |
Loads the names of characters for a given account for charpick screen on login. | |
bool | NewCharacterData (AccountID accountid, psCharacter *chardata) |
Creates a new character entry to store the provided character data. | |
bool | NewNPCCharacterData (AccountID accountid, psCharacter *chardata) |
psCharacterLoader () | |
Construct a new psCharacterLoader, optionally specifying an iDatabase interface to use for database calls. | |
psCharacter * | QuickLoadCharacterData (PID pid, bool noInventory) |
Load just enough of the character data to know what it looks like (for selection screen). | |
bool | SaveCharacterData (psCharacter *chardata, gemActor *actor, bool charRecordOnly=false) |
Saves character data to the database. | |
bool | UpdateCharacterSkill (PID pid, unsigned int skill_id, unsigned int skill_z, unsigned int skill_y, unsigned int skill_rank) |
Update the skill in the database. | |
~psCharacterLoader () | |
Destructor. |
This class controls loading and saving Characters and Character specific data to and from an iDatabase.
The class's primary goal is to keep the lower level psdatabase from knowing too much about how tables relate and to keep the higher level psCharacter, psItem, etc from knowing how the data is stored at all. A secondary goal of the interface is that it should allow for delayed processing in the future with minimal changes. As the project grows in players and complexity the amount of data passing to and from the server will grow as well. It will become unacceptable to wait for the database to respond to each and every query before continuing processing other tasks. In order to achieve this, three conditions must be met: 1) Calls that access the database server must be able to return immediately. 2) Calls that store data in the database must make a local copy of the data to be stored so that the original data may continue to be modified by the server unrestricted. 3) Calls that retrieve data from the database must have a mechanism to check for retrieved data or errors.
While these are not all currently met, the design is such that it would take only minor restructuring to meet them all.
Definition at line 84 of file pscharacterloader.h.
psCharacterLoader::psCharacterLoader | ( | ) |
Construct a new psCharacterLoader, optionally specifying an iDatabase interface to use for database calls.
psCharacterLoader::~psCharacterLoader | ( | ) |
Destructor.
bool psCharacterLoader::AccountOwner | ( | const char * | characterName, |
AccountID | accountID | ||
) |
Checks to see if the character name is owned by a particular ID.
characterName | The character name we want to check |
accountID | The account this character should belong to. |
bool psCharacterLoader::DeleteCharacterData | ( | PID | pid, |
csString & | error | ||
) |
Deletes character data to the database.
This function call does not need to block for database access.
pid | The unique ID of the character to erase data for. Usually obtained from the account. |
error | A error message in case character could not be deleted. |
PID psCharacterLoader::FindCharacterID | ( | const char * | character_name, |
bool | excludeNPCs = true |
||
) |
This function finds a character's ID given a character name.
We go straight to the database currently for this information.
character_name | The name of the character we are looking for |
excludeNPCs | If we should exclude NPC's from the search. |
PID psCharacterLoader::FindCharacterID | ( | AccountID | accountID, |
const char * | character_name | ||
) |
This function finds a character's ID given a character name and the ID of the account that this character is supposed to be on.
We go straight to the database currently for this information.
accountID | The account the character is supposedly on |
character_name | The name of the character we are looking for |
bool psCharacterLoader::Initialize | ( | ) |
Initializes settings related to this class.
Call this before using any functions.
unsigned int psCharacterLoader::InsertNewCharacterData | ( | const char ** | fieldnames, |
psStringArray & | fieldvalues | ||
) |
psCharacter** psCharacterLoader::LoadAllNPCCharacterData | ( | psSectorInfo * | sector, |
int & | count | ||
) |
psCharacter* psCharacterLoader::LoadCharacterData | ( | PID | pid, |
bool | forceReload | ||
) |
Loads data for a character from the database and constructs and fills a new psCharacter object with the data.
pid | The unique ID of the character to load data for. Usually obtained from the account. |
forceReload | Ignores (and empties) the cache if set to true. |
psCharacterList* psCharacterLoader::LoadCharacterList | ( | AccountID | accountid | ) |
Loads the names of characters for a given account for charpick screen on login.
bool psCharacterLoader::NewCharacterData | ( | AccountID | accountid, |
psCharacter * | chardata | ||
) |
Creates a new character entry to store the provided character data.
accountid | A numeric account identifier with which this character should be associated. |
chardata | Pointer to a psCharacter object containing the Character data to be stored as a new character. |
bool psCharacterLoader::NewNPCCharacterData | ( | AccountID | accountid, |
psCharacter * | chardata | ||
) |
psCharacter* psCharacterLoader::QuickLoadCharacterData | ( | PID | pid, |
bool | noInventory | ||
) |
Load just enough of the character data to know what it looks like (for selection screen).
bool psCharacterLoader::SaveCharacterData | ( | psCharacter * | chardata, |
gemActor * | actor, | ||
bool | charRecordOnly = false |
||
) |
Saves character data to the database.
This function call does not need to block for database access. It can copy the psCharacter object and related sub-objects and verify some integrity of the data before queueing a database write and returning true.
chardata | Pointer to a psCharacter object containing the Character data to be updated. The uid member of chardata must be valid and unique. The UID value can only be set by creating a new character and calling NewCharacterData(). |
actor | A pointer to the actor. |
charRecordOnly | Should only char record be saved. |
bool psCharacterLoader::UpdateCharacterSkill | ( | PID | pid, |
unsigned int | skill_id, | ||
unsigned int | skill_z, | ||
unsigned int | skill_y, | ||
unsigned int | skill_rank | ||
) |
Update the skill in the database.