aboutsummaryrefslogtreecommitdiffstats
path: root/src/user.h
blob: f84e3e1dc4e5ac2cf5e9ce512722a9cdb6dc12e6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef L2SU_USER_H_INCLUDED
#define L2SU_USER_H_INCLUDED

#include "uuid/uuid.h"
#include "macros.h"

#include <time.h>

#define L2_PROFILE_NAME_STRLEN (16)

typedef void *l2_user_profile_properties_iter_t;

struct l2_user_profile_property {
  char *name;
  char *value;
  char *signature;
};

struct l2_user_profile {
  uuid_t uuid;
  char name[L2_PROFILE_NAME_STRLEN + 1];

  size_t nproperties;
  struct l2_user_profile_property *properties;
};

typedef struct l2_user_session_tag l2_user_session_t;

struct l2_user {
  struct l2_user_profile profile;
  l2_user_session_t *session; /* NULL for offline users */

  char *nickname;

  struct l2_user *next, *prev;
};

int l2_user_load(void);
int l2_user_save(void);

void l2_user_init(struct l2_user *user);
void l2_user_free(struct l2_user *user);
struct l2_user *l2_user_clone(const struct l2_user *user);

void l2_user_add(struct l2_user *user);

/* does NOT free the user */
void l2_user_delete(struct l2_user *user);

l2_user_session_t *l2_user_session_new(void);

/* returns 1 if refresh succeeded, 0 if the session needs login, or -1 if there was an error */
int l2_user_session_refresh(l2_user_session_t *session);

/* interactively login (probably not a good general interface but whatever) */
int l2_user_session_login(l2_user_session_t *session);

int l2_user_update_profile(struct l2_user *user);

int l2_user_session_fill_subst(l2_user_session_t *session, void *subst);
char *l2_user_properties_serialize(const struct l2_user_profile *profile, bool legacy);

#endif /* include guard */