Planeshift
Public Member Functions

psCharacterLoader Class Reference

This class controls loading and saving Characters and Character specific data to and from an iDatabase. More...

#include <pscharacterloader.h>

List of all members.

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)
psCharacterLoadCharacterData (PID pid, bool forceReload)
 Loads data for a character from the database and constructs and fills a new psCharacter object with the data.
psCharacterListLoadCharacterList (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.
psCharacterQuickLoadCharacterData (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.

Detailed Description

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.


Constructor & Destructor Documentation

psCharacterLoader::psCharacterLoader ( )

Construct a new psCharacterLoader, optionally specifying an iDatabase interface to use for database calls.

psCharacterLoader::~psCharacterLoader ( )

Destructor.


Member Function Documentation

bool psCharacterLoader::AccountOwner ( const char *  characterName,
AccountID  accountID 
)

Checks to see if the character name is owned by a particular ID.

Parameters:
characterNameThe character name we want to check
accountIDThe account this character should belong to.
Returns:
true If the character name given belongs to the accountID given.
bool psCharacterLoader::DeleteCharacterData ( PID  pid,
csString &  error 
)

Deletes character data to the database.

This function call does not need to block for database access.

Parameters:
pidThe unique ID of the character to erase data for. Usually obtained from the account.
errorA error message in case character could not be deleted.
Returns:
true - Delete progressing. false - Could not delete.
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.

Parameters:
character_nameThe name of the character we are looking for
excludeNPCsIf we should exclude NPC's from the search.
Returns:
The ID of the character or 0 if not found
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.

Parameters:
accountIDThe account the character is supposedly on
character_nameThe name of the character we are looking for
Returns:
The ID of the character or 0 if not found
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.

Note:
This function call must block for database access. It will need to be redesigned for deferred database in the future.
Parameters:
pidThe unique ID of the character to load data for. Usually obtained from the account.
forceReloadIgnores (and empties) the cache if set to true.
Returns:
Pointer to a newly created psCharacter object, or NULL if the data could not be loaded.
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.

Note:
This function call must block for database access. It will need to be redesigned for deferred database in the future.
Parameters:
accountidA numeric account identifier with which this character should be associated.
chardataPointer to a psCharacter object containing the Character data to be stored as a new character.
Returns:
true - Save progressing. false - Could not save. When this function returns the UID member of the chardata structure will contain the unique id for this character >0 if and only if the save was successful.
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.

Parameters:
chardataPointer 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().
actorA pointer to the actor.
charRecordOnlyShould only char record be saved.
Returns:
true - Save progressing. false - Could not save.
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.


The documentation for this class was generated from the following file: