OSDN Git Service

First version
[st-ro/stro.git] / src / login / account.h
1 /**
2  * @file account.h
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
8  */
9
10 #ifndef __ACCOUNT_H_INCLUDED__
11 #define __ACCOUNT_H_INCLUDED__
12
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16
17 #include "../common/cbasetypes.h"
18 #include "../common/mmo.h" // ACCOUNT_REG2_NUM
19 #include "../config/core.h"
20
21 typedef struct AccountDB AccountDB;
22 typedef struct AccountDBIterator AccountDBIterator;
23
24
25 // standard engines
26 AccountDB* account_db_sql(void);
27
28 struct mmo_account {
29         uint32 account_id;
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
45 #ifdef VIP_ENABLE
46         int old_group;
47         time_t vip_time;
48 #endif
49 };
50
51
52 struct AccountDBIterator {
53         /// Destroys this iterator, releasing all allocated memory (including itself).
54         ///
55         /// @param self Iterator
56         void (*destroy)(AccountDBIterator* self);
57
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);
64 };
65
66
67 struct AccountDB {
68         /// Initializes this database, making it ready for use.
69         /// Call this after setting the properties.
70         ///
71         /// @param self Database
72         /// @return true if successful
73         bool (*init)(AccountDB* self);
74
75         /// Destroys this database, releasing all allocated memory (including itself).
76         ///
77         /// @param self Database
78         void (*destroy)(AccountDB* self);
79
80         /// Gets a property from this database.
81         /// These read-only properties must be implemented:
82         ///
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);
89
90         /// Sets a property in this database.
91         ///
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);
97
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.
101         ///
102         /// @param self Database
103         /// @param acc Account data
104         /// @return true if successful
105         bool (*create)(AccountDB* self, struct mmo_account* acc);
106
107         /// Removes an account from this database.
108         ///
109         /// @param self Database
110         /// @param account_id Account id
111         /// @return true if successful
112         bool (*remove)(AccountDB* self, const uint32 account_id);
113
114         /// Modifies the data of an existing account.
115         /// Uses acc->account_id to identify the account.
116         ///
117         /// @param self Database
118         /// @param acc Account data
119         /// @return true if successful
120         bool (*save)(AccountDB* self, const struct mmo_account* acc);
121
122         /// Finds an account with account_id and copies it to acc.
123         ///
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);
129
130         /// Finds an account with userid and copies it to acc.
131         ///
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);
137
138         /// Returns a new forward iterator.
139         ///
140         /// @param self Database
141         /// @return Iterator
142         AccountDBIterator* (*iterator)(AccountDB* self);
143 };
144
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);
147
148 #ifdef __cplusplus
149 }
150 #endif
151
152 #endif // __ACCOUNT_H_INCLUDED__