Crossfire Server, Trunk
account_char.c File Reference
#include "global.h"
#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "account_char.h"
#include "object.h"
#include "output_file.h"
#include "sproto.h"
#include "player.h"
+ Include dependency graph for account_char.c:

Go to the source code of this file.

Macros

#define ACCOUNT_DIR   "account"
 
#define NUM_ACCOUNT_CHAR_FIELDS   8
 

Functions

void account_char_add (Account_Chars *chars, player *pl)
 
void account_char_free (Account_Chars *chars)
 
Account_Charsaccount_char_load (const char *account_name)
 
static void account_char_load_from_file (Account_Chars *chars)
 
void account_char_remove (Account_Chars *chars, const char *pl_name)
 
void account_char_save (Account_Chars *chars)
 
int make_perma_dead (object *op)
 
int unmake_perma_dead (char *account, char *player)
 

Variables

static Account_Chars ** chars_loaded = NULL
 
static size_t chars_loaded_allocated = 0
 
static size_t chars_loaded_count = 0
 

Detailed Description

This file contains logic of dealing with characters that are 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

◆ ACCOUNT_DIR

#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 69 of file account_char.c.

◆ NUM_ACCOUNT_CHAR_FIELDS

#define NUM_ACCOUNT_CHAR_FIELDS   8

Number of fields in the accounts file. These are colon seperated

Definition at line 60 of file account_char.c.

Function Documentation

◆ account_char_add()

void account_char_add ( Account_Chars 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

Definition at line 225 of file account_char.c.

References add_string(), obj::arch, account_char_struct::character_class, account_chars_struct::chars, 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, account_char_struct::name, Face::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:

◆ account_char_free()

void account_char_free ( Account_Chars 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 362 of file account_char.c.

References account_chars_struct::account_name, account_char_struct::character_class, account_chars_struct::chars, chars_loaded, chars_loaded_count, account_char_struct::face, free_string(), account_char_struct::map, account_char_struct::name, account_char_struct::next, give::next, account_char_struct::party, account_char_struct::race, and account_chars_struct::ref_count.

Referenced by make_perma_dead(), and unmake_perma_dead().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ account_char_load()

Account_Chars* 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
Character data.

Definition at line 147 of file account_char.c.

References curse_on_apply::ac, account_char_load_from_file(), add_string(), chars_loaded, chars_loaded_allocated, chars_loaded_count, fatal(), llevError, LOG(), OUT_OF_MEMORY, and account_chars_struct::ref_count.

Referenced by make_perma_dead(), and unmake_perma_dead().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ account_char_load_from_file()

static void account_char_load_from_file ( Account_Chars chars)
static

Load characters for a Account_Chars structure.

Parameters
charswhere to load into, the chars field is silently erased.

Definition at line 79 of file account_char.c.

References curse_on_apply::ac, ACCOUNT_DIR, account_chars_struct::account_name, add_string(), buf, account_chars_struct::chars, llevError, llevInfo, Settings::localdir, LOG(), MAX_BUF, account_char_struct::next, NUM_ACCOUNT_CHAR_FIELDS, settings, split_string(), Ice::tmp, and VERY_BIG_BUF.

Referenced by account_char_load().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ account_char_remove()

void account_char_remove ( Account_Chars 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 328 of file account_char.c.

References account_char_struct::character_class, account_chars_struct::chars, 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:

◆ account_char_save()

void account_char_save ( Account_Chars chars)

Saves the character information for the given account.

Parameters
charspreviously loaded/generated list of character information for this account.

Definition at line 179 of file account_char.c.

References curse_on_apply::ac, ACCOUNT_DIR, account_chars_struct::account_name, account_chars_struct::chars, Settings::localdir, MAX_BUF, of_close(), of_open(), and settings.

Referenced by make_perma_dead(), and unmake_perma_dead().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ make_perma_dead()

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 404 of file account_char.c.

References curse_on_apply::ac, account_char_free(), account_char_load(), account_char_save(), socket_struct::account_name, account_chars_struct::chars, get_player(), give::op, and pl::socket.

Referenced by dead_player().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unmake_perma_dead()

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 446 of file account_char.c.

References curse_on_apply::ac, account_char_free(), account_char_load(), account_char_save(), and account_chars_struct::chars.

Referenced by resurrect_player().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ chars_loaded

Account_Chars** chars_loaded = NULL
static

Current character information in use.

Definition at line 71 of file account_char.c.

Referenced by account_char_free(), and account_char_load().

◆ chars_loaded_allocated

size_t chars_loaded_allocated = 0
static

Allocated length of chars_loaded.

Definition at line 73 of file account_char.c.

Referenced by account_char_load().

◆ chars_loaded_count

size_t chars_loaded_count = 0
static

Number of used items in chars_loaded.

Definition at line 72 of file account_char.c.

Referenced by account_char_free(), and account_char_load().