Advertisement
Guest User

Untitled

a guest
Jun 15th, 2018
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.50 KB | None | 0 0
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3.  
  4. #ifndef __ACCOUNT_H_INCLUDED__
  5. #define __ACCOUNT_H_INCLUDED__
  6.  
  7. #include "../common/cbasetypes.h"
  8. #include "../common/mmo.h" // ACCOUNT_REG2_NUM
  9.  
  10. typedef struct AccountDB AccountDB;
  11. typedef struct AccountDBIterator AccountDBIterator;
  12.  
  13.  
  14. // standard engines
  15. #ifdef WITH_TXT
  16. AccountDB* account_db_txt(void);
  17. #endif
  18. #ifdef WITH_SQL
  19. AccountDB* account_db_sql(void);
  20. #endif
  21. // extra engines (will probably use the other txt functions)
  22. #define ACCOUNTDB_CONSTRUCTOR_(engine) account_db_##engine
  23. #define ACCOUNTDB_CONSTRUCTOR(engine) ACCOUNTDB_CONSTRUCTOR_(engine)
  24. #ifdef ACCOUNTDB_ENGINE_0
  25. AccountDB* ACCOUNTDB_CONSTRUCTOR(ACCOUNTDB_ENGINE_0)(void);
  26. #endif
  27. #ifdef ACCOUNTDB_ENGINE_1
  28. AccountDB* ACCOUNTDB_CONSTRUCTOR(ACCOUNTDB_ENGINE_1)(void);
  29. #endif
  30. #ifdef ACCOUNTDB_ENGINE_2
  31. AccountDB* ACCOUNTDB_CONSTRUCTOR(ACCOUNTDB_ENGINE_2)(void);
  32. #endif
  33. #ifdef ACCOUNTDB_ENGINE_3
  34. AccountDB* ACCOUNTDB_CONSTRUCTOR(ACCOUNTDB_ENGINE_3)(void);
  35. #endif
  36. #ifdef ACCOUNTDB_ENGINE_4
  37. AccountDB* ACCOUNTDB_CONSTRUCTOR(ACCOUNTDB_ENGINE_4)(void);
  38. #endif
  39.  
  40.  
  41. struct mmo_account
  42. {
  43. int account_id;
  44. char userid[NAME_LENGTH];
  45. char pass[32+1]; // 23+1 for plaintext, 32+1 for md5-ed passwords
  46. char sex; // gender (M/F/S)
  47. char email[40]; // e-mail (by default: a@a.com)
  48. int level; // GM level
  49. unsigned int state; // packet 0x006a value + 1 (0: compte OK)
  50. time_t unban_time; // (timestamp): ban time limit of the account (0 = no ban)
  51. time_t expiration_time; // (timestamp): validity limit of the account (0 = unlimited)
  52. unsigned int logincount;// number of successful auth attempts
  53. char lastlogin[24]; // date+time of last successful login
  54. char last_ip[16]; // save of last IP of connection
  55. char birthdate[10+1]; // assigned birth date (format: YYYY-MM-DD, default: 0000-00-00)
  56. int account_reg2_num;
  57. struct global_reg account_reg2[ACCOUNT_REG2_NUM]; // account script variables (stored on login server)
  58. };
  59.  
  60.  
  61. struct AccountDBIterator
  62. {
  63. /// Destroys this iterator, releasing all allocated memory (including itself).
  64. ///
  65. /// @param self Iterator
  66. void (*destroy)(AccountDBIterator* self);
  67.  
  68. /// Fetches the next account in the database.
  69. /// Fills acc with the account data.
  70. /// @param self Iterator
  71. /// @param acc Account data
  72. /// @return true if successful
  73. bool (*next)(AccountDBIterator* self, struct mmo_account* acc);
  74. };
  75.  
  76.  
  77. struct AccountDB
  78. {
  79. /// Initializes this database, making it ready for use.
  80. /// Call this after setting the properties.
  81. ///
  82. /// @param self Database
  83. /// @return true if successful
  84. bool (*init)(AccountDB* self);
  85.  
  86. /// Destroys this database, releasing all allocated memory (including itself).
  87. ///
  88. /// @param self Database
  89. void (*destroy)(AccountDB* self);
  90.  
  91. /// Gets a property from this database.
  92. /// These read-only properties must be implemented:
  93. /// "engine.name" -> "txt", "sql", ...
  94. /// "engine.version" -> internal version
  95. /// "engine.comment" -> anything (suggestion: description or specs of the engine)
  96. ///
  97. /// @param self Database
  98. /// @param key Property name
  99. /// @param buf Buffer for the value
  100. /// @param buflen Buffer length
  101. /// @return true if successful
  102. bool (*get_property)(AccountDB* self, const char* key, char* buf, size_t buflen);
  103.  
  104. /// Sets a property in this database.
  105. ///
  106. /// @param self Database
  107. /// @param key Property name
  108. /// @param value Property value
  109. /// @return true if successful
  110. bool (*set_property)(AccountDB* self, const char* key, const char* value);
  111.  
  112. /// Creates a new account in this database.
  113. /// If acc->account_id is not -1, the provided value will be used.
  114. /// Otherwise the account_id will be auto-generated and written to acc->account_id.
  115. ///
  116. /// @param self Database
  117. /// @param acc Account data
  118. /// @return true if successful
  119. bool (*create)(AccountDB* self, struct mmo_account* acc);
  120.  
  121. /// Removes an account from this database.
  122. ///
  123. /// @param self Database
  124. /// @param account_id Account id
  125. /// @return true if successful
  126. bool (*remove)(AccountDB* self, const int account_id);
  127.  
  128. /// Modifies the data of an existing account.
  129. /// Uses acc->account_id to identify the account.
  130. ///
  131. /// @param self Database
  132. /// @param acc Account data
  133. /// @return true if successful
  134. bool (*save)(AccountDB* self, const struct mmo_account* acc);
  135.  
  136. /// Finds an account with account_id and copies it to acc.
  137. ///
  138. /// @param self Database
  139. /// @param acc Pointer that receives the account data
  140. /// @param account_id Target account id
  141. /// @return true if successful
  142. bool (*load_num)(AccountDB* self, struct mmo_account* acc, const int account_id);
  143.  
  144. /// Finds an account with userid and copies it to acc.
  145. ///
  146. /// @param self Database
  147. /// @param acc Pointer that receives the account data
  148. /// @param userid Target username
  149. /// @return true if successful
  150. bool (*load_str)(AccountDB* self, struct mmo_account* acc, const char* userid);
  151.  
  152. /// Returns a new forward iterator.
  153. ///
  154. /// @param self Database
  155. /// @return Iterator
  156. AccountDBIterator* (*iterator)(AccountDB* self);
  157. };
  158.  
  159. // (^~_~^) Gepard Shield Start
  160.  
  161. void account_gepard_update_last_unique_id(int account_id, unsigned int unique_id);
  162. bool account_gepard_check_unique_id(int fd, struct socket_data* s);
  163. int account_gepard_check_license_version(struct socket_data* s, int fd, int group_id);
  164.  
  165. // (^~_~^) Gepard Shield End
  166.  
  167. #endif // __ACCOUNT_H_INCLUDED__
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement