Go to the documentation of this file.
68 #define NUM_ACCOUNT_FIELDS 6
109 #define ACCOUNT_FILE "accounts"
139 LOG(
llevError,
"Unable to allocate an account_struct!\n");
142 ac->last_login = time(NULL);
143 ac->created =
ac->last_login;
168 LOG(
llevError,
"account_load_entries(): Called when accounts has been set.\n");
181 if (
buf[0] ==
'#')
continue;
188 ac->last_login = strtoul(
tmp[2], (
char**)NULL, 10);
194 if (fields>4)
ac->created = strtoul(
tmp[4], (
char**)NULL, 10);
196 ac->created =
ac->last_login;
204 ac->num_characters=1;
205 for (cp =
tmp[3]; *cp !=
'\0'; cp++) {
206 if (*cp ==
';')
ac->num_characters++;
214 for (i=0; i<
ac->num_characters; i++) {
239 fprintf(fp,
"%s:%s:%u:",
ac->name,
ac->password, (uint32_t)
ac->last_login);
240 for (i=0; i<
ac->num_characters; i++) {
242 fprintf(fp,
";%s",
ac->character_names[i]);
244 fprintf(fp,
"%s",
ac->character_names[i]);
246 fprintf(fp,
":%u:\n", (uint32_t)
ac->created);
271 fprintf(fp,
"# IMPORTANT: Do not edit this file while the server is running. This file is\n"
272 "# only read when the server starts, and any changes will be overwritten when\n"
273 "# the server exits.\n");
274 fprintf(fp,
"# Format:\n");
275 fprintf(fp,
"# Account name:Password:Account last used:Characters (semicolon separated):created:expansion\n");
282 if (
ac->num_characters || (
ac->created > (time(NULL) - 86400)))
324 ac->last_login = time(NULL);
363 const char *cp =
str;
366 if (!isalnum(*
str))
return 1;
367 for (; *
str !=
'\0'; ++
str) {
368 if (!isprint(*
str))
return 1;
379 if (isspace(*(
str-1)))
return 1;
450 ac->num_characters++;
478 if (account_name == NULL)
487 for (i=0; i<
ac->num_characters; i++) {
488 if (!strcmp(
ac->character_names[i], player_name)) {
489 free(
ac->character_names[i]);
493 ac->character_names[i] =
ac->character_names[i+1];
498 ac->num_characters--;
523 if (!
strcasecmp(
ac->name, account_name))
return ac->character_names;
535 for (
auto ch : chars) {
536 if (strcmp(ch->name,
name) == 0) {
556 for (
int i = 0; i <
ac->num_characters; i++) {
560 lc->
name =
ac->character_names[i];
585 for (i=0; i<
ac->num_characters; i++) {
586 if (!strcmp(
ac->character_names[i],
charname)) {
629 const char *current_password,
const char *new_password) {
642 if (current_password != NULL && !
check_password(current_password,
ac->password)) {
char ** account_get_players_for_account(const char *account_name)
void account_logout(const char *account_name)
static account_struct * account_alloc()
void LOG(LogLevel logLevel, const char *format,...)
int of_close(OutputFile *of)
FILE * of_open(OutputFile *of, const char *fname)
char const * newhash(char const *password)
linked_char * account_get_additional_chars(const char *account_name, const Account_Chars *chars, int *count)
void bufferreader_destroy(BufferReader *br)
const char * account_exists(const char *account_name)
static int accounts_loaded
int account_remove_player(const char *account_name, const char *player_name)
static std::vector< account_struct * > accounts
static int char_in_list(const char *name, const std::vector< Account_Char * > chars)
std::vector< Account_Char * > chars
void accounts_clear(void)
void account_password(char *buf, int len, socket_struct *ns)
BufferReader * bufferreader_init_from_file(BufferReader *br, const char *filepath, const char *failureMessage, LogLevel failureLevel)
size_t split_string(char *str, char *array[], size_t array_size, char sep)
#define NUM_ACCOUNT_FIELDS
struct linked_char * next
void fatal(enum fatal_error err)
static void ensure_available_characters(account_struct *account, int count)
static std::set< std::string > accounts_logged_in
int strcasecmp(const char *s1, const char *s2)
const char * account_get_account_for_char(const char *charname)
bool check_password(const char *typed, const char *crypted)
int account_is_logged_in(const char *name)
int account_change_password(const char *account_name, const char *current_password, const char *new_password)
static void account_write_entry(FILE *fp, account_struct *ac)
int account_link(const char *account_name, const char *player_name)
int account_login(const char *account_name, const char *account_password)
int account_check_string(const char *str)
int account_new(const char *account_name, const char *account_password)
char * bufferreader_next_line(BufferReader *br)