Crossfire Server, Trunk  R20513
Macros | Functions
account_char.c File Reference

This file contains logic of dealing with characters that associated with an account. More...

#include "global.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "account_char.h"
#include "object.h"
#include "output_file.h"
#include "sproto.h"
Include dependency graph for account_char.c:

Go to the source code of this file.

Macros

#define ACCOUNT_DIR   "account"
 Name of the directory containing account information. More...
 
#define NUM_ACCOUNT_CHAR_FIELDS   8
 Number of fields in the accounts file. More...
 

Functions

Account_Characcount_char_add (Account_Char *chars, player *pl)
 This adds a player to the list of accounts. More...
 
void account_char_free (Account_Char *chars)
 This frees all data associated with the character information. More...
 
Account_Characcount_char_load (const char *account_name)
 For a given account name, load the character information and return it. More...
 
Account_Characcount_char_remove (Account_Char *chars, const char *pl_name)
 This removes a character on this account. More...
 
void account_char_save (const char *account, Account_Char *chars)
 Saves the character information for the given account. More...
 
int make_perma_dead (object *op)
 This will edit the character account information so that the character that just died in permadeath will be listed as such in the accounts file. More...
 
int unmake_perma_dead (char *account, char *player)
 This will edit the character account information so that the character that was just resurrected in permadeath will be listed as such in the accounts file. More...
 

Detailed Description

This file contains logic of dealing with characters that associated with an account.

The main purpose of this file is to retrieve and store information about characters to communicate this to the player. For example, the amount of experience, class, race, etc of the character.

In order to help performance, this information is stored in a file for each account. In this way, opening one file and reading the data gets the information needed - much more efficient than opening and reading many player files. In general, this information is only loaded/used when the account is logged in, and the data is stored in the socket structure.

Format of the file is: Account Name:Class:Race:Level:Face (text form):Party:Map Mark:Fighter:Orc:18:warrior.111:foobar:Scorn

Addtional fields can be added as necessary.

Note about characters vs players: In many parts of the code, a character may be called a player, but that is misleading, since a player suggests the person sitting at the computer, and they play a character. In the past, there was a 1:1 mapping between players and characters, but with accounts, there can be several characters associated with an account, and it will be more typical that the account maps 1:1 with a player. As such, saying this account has 10 players may be confusing or misconstrued - what is really the case is that this account has 10 characters.

Definition in file account_char.c.

Macro Definition Documentation

#define ACCOUNT_DIR   "account"

Name of the directory containing account information.

I can not ever see a reason why this name would not work, but may as well still make it easy to change it. FixMe: Shouldn't something like this go in the settings file?

Definition at line 67 of file account_char.c.

Referenced by account_char_load(), and account_char_save().

#define NUM_ACCOUNT_CHAR_FIELDS   8

Number of fields in the accounts file.

These are colon seperated

Definition at line 58 of file account_char.c.

Referenced by account_char_load().

Function Documentation

Account_Char* account_char_add ( Account_Char chars,
player pl 
)

This adds a player to the list of accounts.

We check to see if the player has already been added to this account - if so, we just update the infromation. Note that all strings are filled in, even if that may just be a blank field. This simplifies a lot of the code instead of having to deal with NULL values. Note that this routine is also used to update existing entries - if the character already exists, we update it, otherwise it is added.

Parameters
charsExisting list of characters for account. May be NULL.
plPlayer structure to add
Returns
Returns new list of characters for account.

Definition at line 192 of file account_char.c.

References add_string(), obj::arch, account_char_struct::character_class, archt::clone, account_char_struct::face, obj::face, free_string(), account_char_struct::isDead, account_char_struct::level, obj::level, account_char_struct::map, obj::map, pl::maplevel, new_face_struct::name, account_char_struct::name, obj::name, mapdef::name, account_char_struct::next, pl::ob, account_char_struct::party, pl::party, party_struct::partyname, and account_char_struct::race.

Referenced by save_player(), and START_TEST().

Here is the call graph for this function:

Here is the caller graph for this function:

void account_char_free ( Account_Char chars)

This frees all data associated with the character information.

Parameters
charsData to free. The caller should make sure it no longer uses any data in this list.

Definition at line 332 of file account_char.c.

References account_char_struct::character_class, account_char_struct::face, free_string(), account_char_struct::map, account_char_struct::name, account_char_struct::next, account_struct::next, account_char_struct::party, and account_char_struct::race.

Referenced by account_add_player_cmd(), free_newsocket(), key_confirm_quit(), and START_TEST().

Here is the call graph for this function:

Here is the caller graph for this function:

Account_Char* account_char_load ( const char *  account_name)

For a given account name, load the character information and return it.

It is the responsibility of the caller to call account_char_free() on the returned value to free it.

Parameters
account_nameName of the account. The name should be validated before this routine is called (eg, passed checks for legitimate characters and logged in)
Returns
linked list of the character data.

Definition at line 79 of file account_char.c.

References ACCOUNT_DIR, add_string(), llevError, llevInfo, Settings::localdir, LOG(), MAX_BUF, NUM_ACCOUNT_CHAR_FIELDS, settings, snprintf, split_string(), and VERY_BIG_BUF.

Referenced by account_add_player_cmd(), make_perma_dead(), send_account_players(), START_TEST(), and unmake_perma_dead().

Here is the call graph for this function:

Here is the caller graph for this function:

Account_Char* account_char_remove ( Account_Char chars,
const char *  pl_name 
)

This removes a character on this account.

This is typically used when a character has been deleted, and not for general cleanup

Parameters
charsExisting list of characters for account.
pl_nameThe name of the character
Returns
Returns new list of characters for account.

Definition at line 296 of file account_char.c.

References account_char_struct::character_class, account_char_struct::face, free_string(), account_char_struct::map, account_char_struct::name, account_char_struct::next, account_char_struct::party, and account_char_struct::race.

Referenced by account_add_player_cmd(), key_confirm_quit(), and START_TEST().

Here is the call graph for this function:

Here is the caller graph for this function:

void account_char_save ( const char *  account,
Account_Char chars 
)

Saves the character information for the given account.

Parameters
accountaccount name to save data for.
charspreviously loaded/generated list of character information for this account.

Definition at line 145 of file account_char.c.

References ACCOUNT_DIR, account_char_struct::character_class, account_char_struct::face, account_char_struct::isDead, account_char_struct::level, Settings::localdir, account_char_struct::map, MAX_BUF, account_char_struct::name, account_char_struct::next, of_close(), of_open(), account_char_struct::party, account_char_struct::race, settings, snprintf, and unlink.

Referenced by account_add_player_cmd(), free_newsocket(), key_confirm_quit(), make_perma_dead(), save_player(), START_TEST(), and unmake_perma_dead().

Here is the call graph for this function:

Here is the caller graph for this function:

int make_perma_dead ( object op)

This will edit the character account information so that the character that just died in permadeath will be listed as such in the accounts file.

Parameters
opThe player experiencing permadeath.
Returns
0 for success, 1 for failure

Definition at line 357 of file account_char.c.

References account_char_load(), account_char_save(), socket_struct::account_name, obj::contr, get_player(), account_char_struct::isDead, account_char_struct::name, obj::name, account_char_struct::next, and pl::socket.

Referenced by dead_player().

Here is the call graph for this function:

Here is the caller graph for this function:

int unmake_perma_dead ( char *  account,
char *  player 
)

This will edit the character account information so that the character that was just resurrected in permadeath will be listed as such in the accounts file.

Parameters
accountThe account of the resurrected character.
playerThe name of the resurrected character.
Returns
0 for success, 1 for failure

Definition at line 397 of file account_char.c.

References account_char_load(), account_char_save(), account_char_struct::isDead, account_char_struct::name, and account_char_struct::next.

Referenced by resurrect_player().

Here is the call graph for this function:

Here is the caller graph for this function: