67 #define NUM_ACCOUNT_FIELDS 6 108 #define ACCOUNT_FILE "accounts" 138 LOG(
llevError,
"Unable to allocate an account_struct!\n");
167 LOG(
llevError,
"account_load_entries(): Called when accounts has been set.\n");
180 if (buf[0] ==
'#')
continue;
187 ac->
last_login = strtoul(tmp[2], (
char**)NULL, 10);
193 if (fields>4) ac->
created = strtoul(tmp[4], (
char**)NULL, 10);
204 for (cp = tmp[3]; *cp !=
'\0'; cp++) {
245 fprintf(fp,
":%u:\n", (uint32_t) ac->
created);
270 fprintf(fp,
"# IMPORTANT: Do not edit this file while the server is running. This file is\n" 271 "# only read when the server starts, and any changes will be overwritten when\n" 272 "# the server exits.\n");
273 fprintf(fp,
"# Format:\n");
274 fprintf(fp,
"# Account name:Password:Account last used:Characters (semicolon separated):created:expansion\n");
281 if (ac->num_characters || (ac->created > (time(NULL) - 86400)))
299 if (!
strcasecmp(ac->name, account_name))
return ac->name;
323 ac->last_login = time(NULL);
362 const char *cp = str;
365 if (!isalnum(*str))
return 1;
366 for (; *str !=
'\0'; ++str) {
367 if (!isprint(*str))
return 1;
378 if (isspace(*(str-1)))
return 1;
379 if ((str - cp) >
MAX_NAME)
return 2;
448 ac->character_names[ac->num_characters] =
strdup_local(player_name);
449 ac->num_characters++;
477 if (account_name == NULL)
486 for (i=0; i<ac->num_characters; i++) {
487 if (!strcmp(ac->character_names[i], player_name)) {
488 free(ac->character_names[i]);
492 ac->character_names[i] = ac->character_names[i+1];
497 ac->num_characters--;
522 if (!
strcasecmp(ac->name, account_name))
return ac->character_names;
534 for (
auto ch : chars) {
535 if (strcmp(ch->name, name) == 0) {
555 for (
int i = 0; i < ac->num_characters; i++) {
559 lc->
name = ac->character_names[i];
584 for (i=0; i<ac->num_characters; i++) {
585 if (!strcmp(ac->character_names[i], charname)) {
628 const char *current_password,
const char *new_password) {
641 if (current_password != NULL && !
check_password(current_password, ac->password)) {
void bufferreader_destroy(BufferReader *br)
Destroy a BufferReader.
void LOG(LogLevel logLevel, const char *format,...)
Logs a message to stderr, or to file.
bool check_password(const char *typed, const char *crypted)
Hash a password and compare it to the stored version.
int num_characters
Number of characters on this account.
char * password
Password for this account.
linked_char * account_get_additional_chars(const char *account_name, const Account_Chars *chars, int *count)
Get a list of character names linked to the specified account which are not listed in chars...
static int char_in_list(const char *name, const std::vector< Account_Char *> chars)
Check if a character name is in a list or not.
#define NUM_ACCOUNT_FIELDS
Number of fields in the accounts file.
int account_is_logged_in(const char *name)
This checkes if an account is logged in.
void account_logout(const char *account_name)
Remove 'account_name' from the list of logged in accounts.
Global type definitions and header inclusions.
int account_change_password(const char *account_name, const char *current_password, const char *new_password)
Change an account password.
static std::vector< account_struct * > accounts
list of all accounts.
time_t created
When character was created.
time_t last_login
Last time this account was logged in.
void accounts_clear(void)
This is used purely by the test harness - by clearing the accounts, it can then verify that the data ...
static account_struct * account_alloc()
Allocate a new account_struct item.
size_t split_string(char *str, char *array[], size_t array_size, char sep)
Splits a string delimited by passed in sep value into characters into an array of strings...
int account_check_string(const char *str)
Checks a string to make sure it does not have any invalid characters.
FILE * of_open(OutputFile *of, const char *fname)
Opens an output file.
int account_login(const char *account_name, const char *account_password)
Check if the given account exists, and whether the password is correct.
char ** account_get_players_for_account(const char *account_name)
Returns an array of strings for the characters on this account - the array is null terminated...
BufferReader * bufferreader_init_from_file(BufferReader *br, const char *filepath, const char *failureMessage, LogLevel failureLevel)
Initialize or create a BufferReader from a file path.
const char * account_exists(const char *account_name)
Checks the existing accounts, and see if this account exists.
void account_password(char *buf, int len, socket_struct *ns)
Handles the account password change.
int strcasecmp(const char *s1, const char *s2)
struct linked_char * next
static std::set< std::string > accounts_logged_in
Set of accounts names that are currently logged in.
struct Settings settings
Global settings.
static void account_write_entry(FILE *fp, account_struct *ac)
This writes a single account entry to the given filepointer.
void fatal(enum fatal_error err)
fatal() is meant to be called whenever a fatal signal is intercepted.
#define MAX_BUF
Used for all kinds of things.
Structure handling character information for an account.
int account_new(const char *account_name, const char *account_password)
Adds an account.
void accounts_save(void)
Save all the account information.
static void ensure_available_characters(account_struct *account, int count)
Ensure an account can handle at least the specified count of character names.
void accounts_load(void)
This loads all the account entries into memory.
Object structure, the core of Crossfire.
static int accounts_loaded
Whether the account information was loaded or not.
const char * localdir
Read/write data files.
int of_close(OutputFile *of)
Closes an output file.
Structure that holds account data.
int allocated_characters
Number of allocated items in character_names.
Functions for creating text output files.
char ** character_names
Character names associated with this account, +1 added to allow for NULL termination.
const char * account_get_account_for_char(const char *charname)
This looks at all the accounts and sees if charname is associated with any of them.
char * bufferreader_next_line(BufferReader *br)
Return the next line in the buffer, as separated by a newline.
char const * newhash(char const *password)
#define ACCOUNT_FILE
Name of the accounts file.
int account_remove_player(const char *account_name, const char *player_name)
Removes a player name from an account.
int account_link(const char *account_name, const char *player_name)
Adds a player name to an account.
std::vector< Account_Char * > chars
Characters of the account.