Crossfire Server, Trunk
|
#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"
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_Chars * | account_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 std::vector< Account_Chars * > | chars_loaded |
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.cpp.
#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.cpp.
#define NUM_ACCOUNT_CHAR_FIELDS 8 |
Number of fields in the accounts file. These are colon separated
Definition at line 60 of file account_char.cpp.
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.
chars | Existing list of characters for account. May be NULL. |
pl | Player structure to add |
Definition at line 207 of file account_char.cpp.
References add_string(), Account_Char::character_class, Account_Chars::chars, Account_Char::face, free_string(), Account_Char::isDead, Account_Char::level, Account_Char::map, Account_Char::name, Account_Char::party, altar_valkyrie::pl, and Account_Char::race.
Referenced by save_player(), and START_TEST().
void account_char_free | ( | Account_Chars * | chars | ) |
This frees all data associated with the character information.
chars | Data to free. The caller should make sure it no longer uses any data in this list. |
Definition at line 345 of file account_char.cpp.
References Account_Chars::account_name, Account_Chars::chars, chars_loaded, free_string(), and Account_Chars::ref_count.
Referenced by make_perma_dead(), and unmake_perma_dead().
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.
account_name | Name of the account. The name should be validated before this routine is called (eg, passed checks for legitimate characters and logged in) |
Definition at line 135 of file account_char.cpp.
References curse_on_apply::ac, account_char_load_from_file(), add_string(), chars_loaded, and Account_Chars::ref_count.
Referenced by make_perma_dead(), and unmake_perma_dead().
|
static |
Load characters for a Account_Chars structure.
chars | where to load into, the chars field is silently erased. |
Definition at line 77 of file account_char.cpp.
References curse_on_apply::ac, ACCOUNT_DIR, Account_Chars::account_name, add_string(), buf, Account_Chars::chars, llevError, llevInfo, Settings::localdir, LOG(), MAX_BUF, NUM_ACCOUNT_CHAR_FIELDS, settings, split_string(), Ice::tmp, and VERY_BIG_BUF.
Referenced by account_char_load().
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
chars | Existing list of characters for account. |
pl_name | The name of the character |
Definition at line 313 of file account_char.cpp.
References Account_Char::character_class, Account_Chars::chars, Account_Char::face, free_string(), Account_Char::map, Account_Char::name, Account_Char::party, and Account_Char::race.
Referenced by account_add_player_cmd(), key_confirm_quit(), kill_player_permadeath(), and START_TEST().
void account_char_save | ( | Account_Chars * | chars | ) |
Saves the character information for the given account.
chars | previously loaded/generated list of character information for this account. |
Definition at line 158 of file account_char.cpp.
References curse_on_apply::ac, ACCOUNT_DIR, Account_Chars::account_name, Account_Chars::chars, Settings::localdir, MAX_BUF, of_close(), of_open(), and settings.
Referenced by make_perma_dead(), and unmake_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.
op | The player experiencing permadeath. |
Definition at line 379 of file account_char.cpp.
References curse_on_apply::ac, account_char_free(), account_char_load(), account_char_save(), Account_Chars::chars, get_player(), give::op, and altar_valkyrie::pl.
Referenced by dead_player().
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.
account | The account of the resurrected character. |
player | The name of the resurrected character. |
Definition at line 421 of file account_char.cpp.
References curse_on_apply::ac, account_char_free(), account_char_load(), account_char_save(), and Account_Chars::chars.
Referenced by resurrect_player().
|
static |
Current character information in use.
Definition at line 71 of file account_char.cpp.
Referenced by account_char_free(), and account_char_load().