3 * Module purpose is to save, load, and update changes into the account table or file.
4 * Licensed under GNU GPL.
5 * For more information, see LICENCE in the main folder.
6 * @author Athena Dev Teams < r15k
7 * @author rAthena Dev Team
10 #ifndef __ACCOUNT_H_INCLUDED__
11 #define __ACCOUNT_H_INCLUDED__
17 #include "../common/cbasetypes.h"
18 #include "../common/mmo.h" // ACCOUNT_REG2_NUM
19 #include "../config/core.h"
21 typedef struct AccountDB AccountDB;
22 typedef struct AccountDBIterator AccountDBIterator;
26 AccountDB* account_db_sql(void);
30 char userid[NAME_LENGTH];
31 char pass[32+1]; // 23+1 for plaintext, 32+1 for md5-ed passwords
32 char sex; // gender (M/F/S)
33 char email[40]; // e-mail (by default: a@a.com)
34 unsigned int group_id; // player group id
35 uint8 char_slots; // this accounts maximum character slots (maximum is limited to MAX_CHARS define in char server)
36 unsigned int state; // packet 0x006a value + 1 (0: compte OK)
37 time_t unban_time; // (timestamp): ban time limit of the account (0 = no ban)
38 time_t expiration_time; // (timestamp): validity limit of the account (0 = unlimited)
39 unsigned int logincount;// number of successful auth attempts
40 char lastlogin[24]; // date+time of last successful login
41 char last_ip[16]; // save of last IP of connection
42 char birthdate[10+1]; // assigned birth date (format: YYYY-MM-DD)
43 char pincode[PINCODE_LENGTH+1]; // pincode system
44 time_t pincode_change; // (timestamp): last time of pincode change
52 struct AccountDBIterator {
53 /// Destroys this iterator, releasing all allocated memory (including itself).
55 /// @param self Iterator
56 void (*destroy)(AccountDBIterator* self);
58 /// Fetches the next account in the database.
59 /// Fills acc with the account data.
60 /// @param self Iterator
61 /// @param acc Account data
62 /// @return true if successful
63 bool (*next)(AccountDBIterator* self, struct mmo_account* acc);
68 /// Initializes this database, making it ready for use.
69 /// Call this after setting the properties.
71 /// @param self Database
72 /// @return true if successful
73 bool (*init)(AccountDB* self);
75 /// Destroys this database, releasing all allocated memory (including itself).
77 /// @param self Database
78 void (*destroy)(AccountDB* self);
80 /// Gets a property from this database.
81 /// These read-only properties must be implemented:
83 /// @param self Database
84 /// @param key Property name
85 /// @param buf Buffer for the value
86 /// @param buflen Buffer length
87 /// @return true if successful
88 bool (*get_property)(AccountDB* self, const char* key, char* buf, size_t buflen);
90 /// Sets a property in this database.
92 /// @param self Database
93 /// @param key Property name
94 /// @param value Property value
95 /// @return true if successful
96 bool (*set_property)(AccountDB* self, const char* key, const char* value);
98 /// Creates a new account in this database.
99 /// If acc->account_id is not -1, the provided value will be used.
100 /// Otherwise the account_id will be auto-generated and written to acc->account_id.
102 /// @param self Database
103 /// @param acc Account data
104 /// @return true if successful
105 bool (*create)(AccountDB* self, struct mmo_account* acc);
107 /// Removes an account from this database.
109 /// @param self Database
110 /// @param account_id Account id
111 /// @return true if successful
112 bool (*remove)(AccountDB* self, const uint32 account_id);
114 /// Modifies the data of an existing account.
115 /// Uses acc->account_id to identify the account.
117 /// @param self Database
118 /// @param acc Account data
119 /// @return true if successful
120 bool (*save)(AccountDB* self, const struct mmo_account* acc);
122 /// Finds an account with account_id and copies it to acc.
124 /// @param self Database
125 /// @param acc Pointer that receives the account data
126 /// @param account_id Target account id
127 /// @return true if successful
128 bool (*load_num)(AccountDB* self, struct mmo_account* acc, const uint32 account_id);
130 /// Finds an account with userid and copies it to acc.
132 /// @param self Database
133 /// @param acc Pointer that receives the account data
134 /// @param userid Target username
135 /// @return true if successful
136 bool (*load_str)(AccountDB* self, struct mmo_account* acc, const char* userid);
138 /// Returns a new forward iterator.
140 /// @param self Database
142 AccountDBIterator* (*iterator)(AccountDB* self);
145 void mmo_send_global_accreg(AccountDB* self, int fd, int account_id, int char_id);
146 void mmo_save_global_accreg(AccountDB* self, int fd, int account_id, int char_id);
152 #endif // __ACCOUNT_H_INCLUDED__