login.hpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. // Copyright (c) rAthena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #ifndef LOGIN_HPP
  4. #define LOGIN_HPP
  5. #include <memory>
  6. #include "../common/cbasetypes.hpp"
  7. #include "../common/core.hpp" // CORE_ST_LAST
  8. #include "../common/mmo.hpp" // NAME_LENGTH,SEX_*
  9. #include "../common/timer.hpp"
  10. #include "../config/core.hpp"
  11. #include "account.hpp"
  12. enum E_LOGINSERVER_ST {
  13. LOGINSERVER_ST_RUNNING = CORE_ST_LAST,
  14. LOGINSERVER_ST_STARTING,
  15. LOGINSERVER_ST_SHUTDOWN,
  16. LOGINSERVER_ST_LAST
  17. };
  18. /// supported encryption types: 1- passwordencrypt, 2- passwordencrypt2, 3- both
  19. #define PASSWORDENC 3
  20. ///Struct of 1 client connected to login-serv
  21. struct login_session_data {
  22. uint32 account_id; ///also GID
  23. long login_id1;
  24. long login_id2;
  25. char sex; /// 'F','M','S'
  26. char userid[NAME_LENGTH]; /// account name
  27. char passwd[PASSWD_LENGTH]; // 23+1 for plaintext, 32+1 for md5-ed passwords
  28. int passwdenc; /// was the passwd transmited encrypted or clear ?
  29. char md5key[20]; /// md5 key of session (each connection could be encrypted with a md5 key)
  30. uint16 md5keylen; /// len of the md5 key
  31. char lastlogin[24]; ///date when last logged, Y-M-D HH:MM:SS
  32. uint8 group_id; ///groupid of account
  33. uint8 clienttype; /// ???
  34. uint8 client_hash[16]; ///hash of client
  35. int has_client_hash; ///client ha sent an hash
  36. int fd; ///socket of client
  37. };
  38. #define MAX_SERVERS 30 //max number of mapserv that could be attach
  39. ///Struct describing 1 char-serv attach to us
  40. struct mmo_char_server {
  41. char name[20]; ///char-serv name
  42. int fd; ///char-serv socket (well actually file descriptor)
  43. uint32 ip; ///char-serv IP
  44. uint16 port; ///char-serv rt
  45. uint16 users; /// user count on this server
  46. uint16 type; /// 0=normal, 1=maintenance, 2=over 18, 3=paying, 4=P2P
  47. uint16 new_; /// should display as 'new'?
  48. };
  49. extern struct mmo_char_server ch_server[MAX_SERVERS];
  50. struct client_hash_node {
  51. unsigned int group_id; //inferior or egal group to apply restriction
  52. uint8 hash[16]; ///hash required for that groupid or below
  53. struct client_hash_node *next; ///next entry
  54. };
  55. struct Login_Config {
  56. uint32 login_ip; /// the address to bind to
  57. uint16 login_port; /// the port to bind to
  58. unsigned int ipban_cleanup_interval; /// interval (in seconds) to clean up expired IP bans
  59. unsigned int ip_sync_interval; /// interval (in minutes) to execute a DNS/IP update (for dynamic IPs)
  60. bool log_login; /// whether to log login server actions or not
  61. char date_format[32]; /// date format used in messages
  62. bool console; /// console input system enabled?
  63. bool new_account_flag,new_acc_length_limit; /// autoregistration via _M/_F ? / if yes minimum length is 4?
  64. int start_limited_time; /// new account expiration time (-1: unlimited)
  65. bool use_md5_passwds; /// work with password hashes instead of plaintext passwords?
  66. int group_id_to_connect; /// required group id to connect
  67. int min_group_id_to_connect; /// minimum group id to connect
  68. bool ipban; /// perform IP blocking (via contents of `ipbanlist`) ?
  69. bool dynamic_pass_failure_ban; /// automatic IP blocking due to failed login attempts ?
  70. unsigned int dynamic_pass_failure_ban_interval; /// how far to scan the loginlog for password failures in minutes
  71. unsigned int dynamic_pass_failure_ban_limit; /// number of failures needed to trigger the ipban
  72. unsigned int dynamic_pass_failure_ban_duration; /// duration of the ipban in minutes
  73. bool use_dnsbl; /// dns blacklist blocking ?
  74. char dnsbl_servs[1024]; /// comma-separated list of dnsbl servers
  75. int allowed_regs; /// max number of registration
  76. int time_allowed; /// registration interval in seconds
  77. int client_hash_check; /// flags for checking client md5
  78. struct client_hash_node *client_hash_nodes; /// linked list containing md5 hash for each gm group
  79. char loginconf_name[256]; /// name of main config file
  80. char msgconf_name[256]; /// name of msg_conf config file
  81. char lanconf_name[256]; /// name of lan config file
  82. bool usercount_disable; /// Disable colorization and description in general?
  83. int usercount_low; /// Amount of users that will display in green
  84. int usercount_medium; /// Amount of users that will display in yellow
  85. int usercount_high; /// Amount of users that will display in red
  86. int char_per_account; /// number of characters an account can have
  87. #ifdef VIP_ENABLE
  88. struct {
  89. unsigned int group; /// VIP group ID
  90. unsigned int char_increase; /// number of char-slot to increase in VIP state
  91. } vip_sys;
  92. #endif
  93. };
  94. extern struct Login_Config login_config;
  95. #define sex_num2str(num) ( (num == SEX_FEMALE ) ? 'F' : (num == SEX_MALE ) ? 'M' : 'S' )
  96. #define sex_str2num(str) ( (str == 'F' ) ? SEX_FEMALE : (str == 'M' ) ? SEX_MALE : SEX_SERVER )
  97. #define msg_config_read(cfgName) login_msg_config_read(cfgName)
  98. #define msg_txt(msg_number) login_msg_txt(msg_number)
  99. #define do_final_msg() login_do_final_msg()
  100. int login_msg_config_read(char *cfgName);
  101. const char* login_msg_txt(int msg_number);
  102. void login_do_final_msg(void);
  103. bool login_config_read(const char* cfgName, bool normal);
  104. /// Online User Database [Wizputer]
  105. struct online_login_data {
  106. uint32 account_id;
  107. int waiting_disconnect;
  108. int char_server;
  109. };
  110. /// Auth database
  111. #define AUTH_TIMEOUT 30000
  112. struct auth_node {
  113. uint32 account_id;
  114. uint32 login_id1;
  115. uint32 login_id2;
  116. uint32 ip;
  117. char sex;
  118. uint8 clienttype;
  119. };
  120. ///Accessors
  121. AccountDB* login_get_accounts_db(void);
  122. struct online_login_data* login_get_online_user( uint32 account_id );
  123. /**
  124. * Function to add a user in online_db.
  125. * Checking if the user is already registered in the db.
  126. * Stop disconnection timer if set.
  127. * @param char_server: id of char-serv on wich the player is
  128. * @param account_id: the account identifier
  129. * @return the new|registered online data
  130. */
  131. struct online_login_data* login_add_online_user(int char_server, uint32 account_id);
  132. /**
  133. * Function to remove a user from online_db.
  134. * Checking if user was already scheduled for deletion, and remove that timer if found.
  135. * @param account_id: the account identifier
  136. */
  137. void login_remove_online_user(uint32 account_id);
  138. struct auth_node* login_get_auth_node( uint32 account_id );
  139. struct auth_node* login_add_auth_node( struct login_session_data* sd, uint32 ip );
  140. void login_remove_auth_node( uint32 account_id );
  141. /**
  142. * Timered function to disconnect a user from login.
  143. * This is done either after auth_ok or kicked by char-server.
  144. * Removing user from auth_db and online_db.
  145. * Delay is AUTH_TIMEOUT by default.
  146. * @param tid: timer id
  147. * @param tick: tick of execution
  148. * @param id: user account id
  149. * @param data: unused
  150. * @return :0
  151. */
  152. TIMER_FUNC(login_waiting_disconnect_timer);
  153. void login_online_db_setoffline( int char_server );
  154. /**
  155. * Test to determine if an IP come from LAN or WAN.
  156. * @param ip: ip to check if in auth network
  157. * @return 0 if from wan, or subnet_char_ip if lan
  158. */
  159. int lan_subnetcheck(uint32 ip);
  160. /**
  161. * Create a new account and save it in db/sql.
  162. * @param userid: string for user login
  163. * @param pass: string for user pass
  164. * @param sex: should be M|F|S (todo make an enum ?)
  165. * @param last_ip:
  166. * @return :
  167. * -1: success
  168. * 0: unregistered id (wrong sex fail to create in db);
  169. * 1: incorrect pass or userid (userid|pass too short or already exist);
  170. * 3: registration limit exceeded;
  171. */
  172. int login_mmo_auth_new(const char* userid, const char* pass, const char sex, const char* last_ip);
  173. /**
  174. * Check/authentication of a connection.
  175. * @param sd: string (atm:md5key or dbpass)
  176. * @param isServer: string (atm:md5key or dbpass)
  177. * @return :
  178. * -1: success
  179. * 0: unregistered id;
  180. * 1: incorrect pass;
  181. * 2: expired id
  182. * 3: blacklisted (or registration limit exceeded if new acc);
  183. * 5: invalid client_version|hash;
  184. * 6: banned
  185. * x: acc state (TODO document me deeper)
  186. */
  187. int login_mmo_auth(struct login_session_data* sd, bool isServer);
  188. int login_get_usercount( int users );
  189. #endif /* LOGIN_HPP */