 |
Crossfire Server, Trunk
1.75.0
|
Go to the documentation of this file.
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;
182 if (
buf[0] == 0)
continue;
185 LOG(
llevDebug,
"Ignoring accounts entry without account name: %s\n",
buf);
191 LOG(
llevWarn,
"Parse failure for line in %s starting with: %s\n", fname,
buf);
198 ac->
last_login = strtoul(tmp[2], (
char**)NULL, 10);
204 if (fields>4) ac->
created = strtoul(tmp[4], (
char**)NULL, 10);
215 for (cp = tmp[3]; *cp !=
'\0'; cp++) {
256 fprintf(fp,
":%" PRIu64
":\n", (uint64_t)ac->
created);
281 fprintf(fp,
"# IMPORTANT: Do not edit this file while the server is running. This file is\n"
282 "# only read when the server starts, and any changes will be overwritten when\n"
283 "# the server exits.\n");
284 fprintf(fp,
"# Format:\n");
285 fprintf(fp,
"# Account name:Password:Account last used:Characters (semicolon separated):created:expansion\n");
292 if (ac->num_characters || (ac->created > (
time(NULL) - 86400)))
310 if (!
strcasecmp(ac->name, account_name))
return ac->name;
334 ac->last_login =
time(NULL);
373 const char *cp = str;
376 if (!isalnum(*str))
return 1;
377 for (; *str !=
'\0'; ++str) {
378 if (!isprint(*str))
return 1;
389 if (isspace(*(str-1)))
return 1;
390 if ((str - cp) >
MAX_NAME)
return 2;
459 ac->character_names[ac->num_characters] =
strdup_local(player_name);
460 ac->num_characters++;
488 if (account_name == NULL)
497 for (i=0; i<ac->num_characters; i++) {
498 if (!strcmp(ac->character_names[i], player_name)) {
499 free(ac->character_names[i]);
503 ac->character_names[i] = ac->character_names[i+1];
508 ac->num_characters--;
533 if (!
strcasecmp(ac->name, account_name))
return ac->character_names;
545 for (
auto ch : chars) {
546 if (strcmp(ch->name,
name) == 0) {
566 for (
int i = 0; i < ac->num_characters; i++) {
570 lc->
name = ac->character_names[i];
595 for (i=0; i<ac->num_characters; i++) {
596 if (!strcmp(ac->character_names[i], charname)) {
639 const char *current_password,
const char *new_password) {
652 if (current_password != NULL && !
check_password(current_password, ac->password)) {
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.
struct Settings settings
Global settings.
void account_logout(const char *account_name)
Remove 'account_name' from the list of logged in accounts.
Structure that holds account data.
static account_struct * account_alloc()
Allocate a new account_struct item.
@ llevError
Problems requiring server admin to fix.
void LOG(LogLevel logLevel, const char *format,...)
Logs a message to stderr, or to file.
int of_close(OutputFile *of)
Closes an output file.
FILE * of_open(OutputFile *of, const char *fname)
Opens an output file.
char const * newhash(char const *password)
same as sound ncom command like but with extra the client want tick commands so it knows animation timing the client wants to be informed of pickup mode changes Mode will be sent when the player successfully logs and afterward any time the value is but over time
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.
void accounts_save(void)
Save all the account information.
time_t created
When character was created.
void bufferreader_destroy(BufferReader *br)
Destroy a BufferReader.
@ llevWarn
Warnings or major code issues.
const char * account_exists(const char *account_name)
Checks the existing accounts, and see if this account exists.
static int accounts_loaded
Whether the account information was loaded or not.
int num_characters
Number of characters on this account.
int account_remove_player(const char *account_name, const char *player_name)
Removes a player name from an account.
static std::vector< account_struct * > accounts
list of all accounts.
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.
Plugin animator file specs[Config] name
std::vector< Account_Char * > chars
Characters of the account.
void accounts_clear(void)
This is used purely by the test harness - by clearing the accounts, it can then verify that the data ...
void account_password(char *buf, int len, socket_struct *ns)
Handles the account password change.
BufferReader * bufferreader_init_from_file(BufferReader *br, const char *filepath, const char *failureMessage, LogLevel failureLevel)
Initialize or create a BufferReader from a file path.
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.
time_t last_login
Last time this account was logged in.
#define NUM_ACCOUNT_FIELDS
Number of fields in the accounts file.
struct linked_char * next
#define ACCOUNT_FILE
Name of the accounts file.
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.
static void ensure_available_characters(account_struct *account, int count)
Ensure an account can handle at least the specified count of character names.
int allocated_characters
Number of allocated items in character_names.
static std::set< std::string > accounts_logged_in
Set of accounts names that are currently logged in.
int strcasecmp(const char *s1, const char *s2)
Structure handling character information for an account.
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.
bool check_password(const char *typed, const char *crypted)
Hash a password and compare it to the stored version.
int account_is_logged_in(const char *name)
This checkes if an account is logged in.
char ** character_names
Character names associated with this account, +1 added to allow for NULL termination.
int account_change_password(const char *account_name, const char *current_password, const char *new_password)
Change an account password.
static void account_write_entry(FILE *fp, account_struct *ac)
This writes a single account entry to the given filepointer.
int account_link(const char *account_name, const char *player_name)
Adds a player name to an account.
int account_login(const char *account_name, const char *account_password)
Check if the given account exists, and whether the password is correct.
void accounts_load(void)
This loads all the account entries into memory.
@ llevDebug
Only for debugging purposes.
int account_check_string(const char *str)
Checks a string to make sure it does not have any invalid characters.
int account_new(const char *account_name, const char *account_password)
Adds an account.
char * password
Password for this account.
char * bufferreader_next_line(BufferReader *br)
Return the next line in the buffer, as separated by a newline.
const char * localdir
Read/write data files.