char.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #ifndef _CHAR_SQL_H_
  4. #define _CHAR_SQL_H_
  5. #define DB_NAME_LEN 256 //max len of dbs
  6. #include "../config/core.h"
  7. #include "../common/core.h" // CORE_ST_LAST
  8. #include "../common/msg_conf.h"
  9. #include "../common/mmo.h"
  10. extern int login_fd; //login file descriptor
  11. extern int char_fd; //char file descriptor
  12. #define MAX_STARTPOINT 5
  13. #define MAX_STARTITEM 32
  14. enum E_CHARSERVER_ST {
  15. CHARSERVER_ST_RUNNING = CORE_ST_LAST,
  16. CHARSERVER_ST_STARTING,
  17. CHARSERVER_ST_SHUTDOWN,
  18. CHARSERVER_ST_LAST
  19. };
  20. enum {
  21. TABLE_INVENTORY,
  22. TABLE_CART,
  23. TABLE_STORAGE,
  24. TABLE_GUILD_STORAGE,
  25. };
  26. enum e_char_delete {
  27. CHAR_DEL_EMAIL = 1,
  28. CHAR_DEL_BIRTHDATE
  29. };
  30. struct Schema_Config {
  31. int db_use_sqldbs;
  32. char db_path[1024];
  33. char char_db[DB_NAME_LEN];
  34. char scdata_db[DB_NAME_LEN];
  35. char skillcooldown_db[DB_NAME_LEN];
  36. char cart_db[DB_NAME_LEN];
  37. char inventory_db[DB_NAME_LEN];
  38. char charlog_db[DB_NAME_LEN];
  39. char storage_db[DB_NAME_LEN];
  40. char interlog_db[DB_NAME_LEN];
  41. char skill_db[DB_NAME_LEN];
  42. char memo_db[DB_NAME_LEN];
  43. char guild_db[DB_NAME_LEN];
  44. char guild_alliance_db[DB_NAME_LEN];
  45. char guild_castle_db[DB_NAME_LEN];
  46. char guild_expulsion_db[DB_NAME_LEN];
  47. char guild_member_db[DB_NAME_LEN];
  48. char guild_position_db[DB_NAME_LEN];
  49. char guild_skill_db[DB_NAME_LEN];
  50. char guild_storage_db[DB_NAME_LEN];
  51. char party_db[DB_NAME_LEN];
  52. char pet_db[DB_NAME_LEN];
  53. char mail_db[DB_NAME_LEN]; // MAIL SYSTEM
  54. char auction_db[DB_NAME_LEN]; // Auctions System
  55. char friend_db[DB_NAME_LEN];
  56. char hotkey_db[DB_NAME_LEN];
  57. char quest_db[DB_NAME_LEN];
  58. char homunculus_db[DB_NAME_LEN];
  59. char skill_homunculus_db[DB_NAME_LEN];
  60. char mercenary_db[DB_NAME_LEN];
  61. char mercenary_owner_db[DB_NAME_LEN];
  62. char ragsrvinfo_db[DB_NAME_LEN];
  63. char elemental_db[DB_NAME_LEN];
  64. char bonus_script_db[DB_NAME_LEN];
  65. char acc_reg_num_table[DB_NAME_LEN];
  66. char acc_reg_str_table[DB_NAME_LEN];
  67. char char_reg_str_table[DB_NAME_LEN];
  68. char char_reg_num_table[DB_NAME_LEN];
  69. };
  70. extern struct Schema_Config schema_config;
  71. #if PACKETVER_SUPPORTS_PINCODE
  72. /// Pincode system
  73. enum pincode_state {
  74. PINCODE_OK = 0,
  75. PINCODE_ASK = 1,
  76. PINCODE_NOTSET = 2,
  77. PINCODE_EXPIRED = 3,
  78. PINCODE_NEW = 4,
  79. PINCODE_ILLEGAL = 5,
  80. #if 0
  81. PINCODE_KSSN = 6, // Not supported since we do not store KSSN
  82. #endif
  83. PINCODE_PASSED = 7,
  84. PINCODE_WRONG = 8,
  85. PINCODE_MAXSTATE
  86. };
  87. struct Pincode_Config {
  88. bool pincode_enabled;
  89. int pincode_changetime;
  90. int pincode_maxtry;
  91. bool pincode_force;
  92. bool pincode_allow_repeated;
  93. bool pincode_allow_sequential;
  94. };
  95. #endif
  96. struct CharMove_Config {
  97. bool char_move_enabled;
  98. bool char_movetoused;
  99. bool char_moves_unlimited;
  100. };
  101. struct Char_Config {
  102. int char_per_account; //Maximum chars per account (default unlimited) [Sirius]
  103. int char_del_level; //From which level u can delete character [Lupus]
  104. int char_del_delay; //minimum delay before effectly do the deletion
  105. bool name_ignoring_case; // Allow or not identical name for characters but with a different case by [Yor]
  106. char unknown_char_name[NAME_LENGTH]; // Name to use when the requested name cannot be determined
  107. char char_name_letters[1024]; // list of letters/symbols allowed (or not) in a character name. by [Yor]
  108. int char_name_option; // Option to know which letters/symbols are authorised in the name of a character (0: all, 1: only those in char_name_letters, 2: all EXCEPT those in char_name_letters) by [Yor]
  109. int char_del_option; // Character deletion type, email = 1, birthdate = 2 (default)
  110. };
  111. #define TRIM_CHARS "\255\xA0\032\t\x0A\x0D " //The following characters are trimmed regardless because they cause confusion and problems on the servers. [Skotlex]
  112. struct CharServ_Config {
  113. char userid[24];
  114. char passwd[24];
  115. char server_name[20];
  116. char wisp_server_name[NAME_LENGTH];
  117. char login_ip_str[128];
  118. uint32 login_ip;
  119. uint16 login_port;
  120. char char_ip_str[128];
  121. uint32 char_ip;
  122. char bind_ip_str[128];
  123. uint32 bind_ip;
  124. uint16 char_port;
  125. int char_maintenance;
  126. bool char_new;
  127. int char_new_display;
  128. struct CharMove_Config charmove_config;
  129. struct Char_Config char_config;
  130. #if PACKETVER_SUPPORTS_PINCODE
  131. struct Pincode_Config pincode_config;
  132. #endif
  133. int save_log; // show loading/saving messages
  134. int log_char; // loggin char or not [devil]
  135. int log_inter; // loggin inter or not [devil]
  136. int char_check_db; ///cheking sql-table at begining ?
  137. struct point start_point[MAX_STARTPOINT], start_point_doram[MAX_STARTPOINT]; // Initial position the player will spawn on the server
  138. short start_point_count, start_point_count_doram; // Number of positions read
  139. struct startitem start_items[MAX_STARTITEM], start_items_doram[MAX_STARTITEM]; // Initial items the player with spawn with on the server
  140. int console;
  141. int max_connect_user;
  142. int gm_allow_group;
  143. int autosave_interval;
  144. int start_zeny;
  145. int guild_exp_rate;
  146. char default_map[MAP_NAME_LENGTH];
  147. unsigned short default_map_x;
  148. unsigned short default_map_y;
  149. };
  150. extern struct CharServ_Config charserv_config;
  151. #define MAX_MAP_SERVERS 30 //how many mapserver a char server can handle
  152. struct mmo_map_server {
  153. int fd;
  154. uint32 ip;
  155. uint16 port;
  156. int users;
  157. unsigned short map[MAX_MAP_PER_SERVER];
  158. };
  159. extern struct mmo_map_server map_server[MAX_MAP_SERVERS];
  160. #define AUTH_TIMEOUT 30000
  161. struct auth_node {
  162. uint32 account_id;
  163. uint32 char_id;
  164. uint32 login_id1;
  165. uint32 login_id2;
  166. uint32 ip;
  167. int sex;
  168. time_t expiration_time; // # of seconds 1/1/1970 (timestamp): Validity limit of the account (0 = unlimited)
  169. int group_id;
  170. unsigned changing_mapservers : 1;
  171. uint8 version;
  172. };
  173. DBMap* char_get_authdb(); // uint32 account_id -> struct auth_node*
  174. struct online_char_data {
  175. uint32 account_id;
  176. uint32 char_id;
  177. int fd;
  178. int waiting_disconnect;
  179. short server; // -2: unknown server, -1: not connected, 0+: id of server
  180. bool pincode_success;
  181. };
  182. DBMap* char_get_onlinedb(); // uint32 account_id -> struct online_char_data*
  183. struct char_session_data {
  184. bool auth; // whether the session is authed or not
  185. uint32 account_id, login_id1, login_id2;
  186. int sex;
  187. int found_char[MAX_CHARS]; // ids of chars on this account
  188. char email[40]; // e-mail (default: a@a.com) by [Yor]
  189. time_t expiration_time; // # of seconds 1/1/1970 (timestamp): Validity limit of the account (0 = unlimited)
  190. int group_id; // permission
  191. uint8 char_slots; // total number of characters that can be created
  192. uint8 chars_vip;
  193. uint8 chars_billing;
  194. uint32 version;
  195. uint8 clienttype;
  196. char new_name[NAME_LENGTH];
  197. char birthdate[10+1]; // YYYY-MM-DD
  198. // Pincode system
  199. char pincode[PINCODE_LENGTH+1];
  200. uint32 pincode_seed;
  201. time_t pincode_change;
  202. uint16 pincode_try;
  203. // Addon system
  204. unsigned int char_moves[MAX_CHARS]; // character moves left
  205. uint8 isvip;
  206. time_t unban_time[MAX_CHARS];
  207. int charblock_timer;
  208. uint8 flag; // &1 - Retrieving guild bound items
  209. };
  210. struct mmo_charstatus;
  211. DBMap* char_get_chardb(); // uint32 char_id -> struct mmo_charstatus*
  212. //Custom limits for the fame lists. [Skotlex]
  213. extern int fame_list_size_chemist;
  214. extern int fame_list_size_smith;
  215. extern int fame_list_size_taekwon;
  216. // Char-server-side stored fame lists [DracoRPG]
  217. extern struct fame_list smith_fame_list[MAX_FAME_LIST];
  218. extern struct fame_list chemist_fame_list[MAX_FAME_LIST];
  219. extern struct fame_list taekwon_fame_list[MAX_FAME_LIST];
  220. #define DEFAULT_AUTOSAVE_INTERVAL 300*1000
  221. #define MAX_CHAR_BUF 150 //Max size (for WFIFOHEAD calls)
  222. int char_search_mapserver(unsigned short map, uint32 ip, uint16 port);
  223. int char_lan_subnetcheck(uint32 ip);
  224. int char_count_users(void);
  225. DBData char_create_online_data(DBKey key, va_list args);
  226. int char_db_setoffline(DBKey key, DBData *data, va_list ap);
  227. void char_set_char_online(int map_id, uint32 char_id, uint32 account_id);
  228. void char_set_char_offline(uint32 char_id, uint32 account_id);
  229. void char_set_all_offline(int id);
  230. void char_disconnect_player(uint32 account_id);
  231. int char_chardb_waiting_disconnect(int tid, unsigned int tick, int id, intptr_t data);
  232. int char_mmo_gender(const struct char_session_data *sd, const struct mmo_charstatus *p, char sex);
  233. int char_mmo_char_tobuf(uint8* buffer, struct mmo_charstatus* p);
  234. int char_mmo_char_tosql(uint32 char_id, struct mmo_charstatus* p);
  235. int char_mmo_char_fromsql(uint32 char_id, struct mmo_charstatus* p, bool load_everything);
  236. int char_mmo_chars_fromsql(struct char_session_data* sd, uint8* buf);
  237. int char_delete_char_sql(uint32 char_id);
  238. int char_rename_char_sql(struct char_session_data *sd, uint32 char_id);
  239. int char_divorce_char_sql(int partner_id1, int partner_id2);
  240. int char_memitemdata_to_sql(const struct item items[], int max, int id, int tableswitch);
  241. void disconnect_player(uint32 account_id);
  242. int char_married(int pl1,int pl2);
  243. int char_child(int parent_id, int child_id);
  244. int char_family(int pl1,int pl2,int pl3);
  245. int char_request_accreg2(uint32 account_id, uint32 char_id);
  246. //extern bool char_gm_read;
  247. int char_loadName(uint32 char_id, char* name);
  248. int char_check_char_name(char * name, char * esc_name);
  249. void char_pincode_decrypt( uint32 userSeed, char* pin );
  250. int char_pincode_compare( int fd, struct char_session_data* sd, char* pin );
  251. void char_auth_ok(int fd, struct char_session_data *sd);
  252. void char_set_charselect(uint32 account_id);
  253. void char_read_fame_list(void);
  254. #if PACKETVER >= 20151001
  255. int char_make_new_char_sql(struct char_session_data* sd, char* name_, int slot, int hair_color, int hair_style, short start_job, short unknown, int sex);
  256. #elif PACKETVER >= 20120307
  257. int char_make_new_char_sql(struct char_session_data* sd, char* name_, int slot, int hair_color, int hair_style);
  258. #else
  259. int char_make_new_char_sql(struct char_session_data* sd, char* name_, int str, int agi, int vit, int int_, int dex, int luk, int slot, int hair_color, int hair_style);
  260. #endif
  261. void char_set_session_flag_(int account_id, int val, bool set);
  262. #define char_set_session_flag(account_id, val) ( char_set_session_flag_((account_id), (val), true) )
  263. #define char_unset_session_flag(account_id, val) ( char_set_session_flag_((account_id), (val), false) )
  264. //For use in packets that depend on an sd being present [Skotlex]
  265. #define FIFOSD_CHECK(rest) { if(RFIFOREST(fd) < rest) return 0; if (sd==NULL || !sd->auth) { RFIFOSKIP(fd,rest); return 0; } }
  266. #define msg_config_read(cfgName) char_msg_config_read(cfgName)
  267. #define msg_txt(msg_number) char_msg_txt(msg_number)
  268. #define do_final_msg() char_do_final_msg()
  269. int char_msg_config_read(char *cfgName);
  270. const char* char_msg_txt(int msg_number);
  271. void char_do_final_msg(void);
  272. bool char_config_read(const char* cfgName, bool normal);
  273. #endif /* _CHAR_SQL_H_ */