y_users.inc 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /**--------------------------------------------------------------------------**\
  2. ===================================
  3. y_users - Registration functions.
  4. ===================================
  5. Description:
  6. Provides access to a user system for registering and saving users.
  7. Legal:
  8. Version: MPL 1.1
  9. The contents of this file are subject to the Mozilla Public License Version
  10. 1.1 (the "License"); you may not use this file except in compliance with
  11. the License. You may obtain a copy of the License at
  12. http://www.mozilla.org/MPL/
  13. Software distributed under the License is distributed on an "AS IS" basis,
  14. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  15. for the specific language governing rights and limitations under the
  16. License.
  17. The Original Code is the YSI malloc include.
  18. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  19. Portions created by the Initial Developer are Copyright (C) 2011
  20. the Initial Developer. All Rights Reserved.
  21. Contributors:
  22. ZeeX, koolk, JoeBullet/Google63, g_aSlice/Slice
  23. Thanks:
  24. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  25. ZeeX - Very productive conversations.
  26. koolk - IsPlayerinAreaEx code.
  27. TheAlpha - Danish translation.
  28. breadfish - German translation.
  29. Fireburn - Dutch translation.
  30. yom - French translation.
  31. 50p - Polish translation.
  32. Zamaroht - Spanish translation.
  33. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes
  34. for me to strive to better.
  35. Pixels^ - Running XScripters where the idea was born.
  36. Matite - Pestering me to release it and using it.
  37. Very special thanks to:
  38. Thiadmer - PAWN, whose limits continue to amaze me!
  39. Kye/Kalcor - SA:MP.
  40. SA:MP Team past, present and future - SA:MP.
  41. Version:
  42. 2.2
  43. Changelog:
  44. 02/02/13:
  45. Added bits and join timestamp to preload data.
  46. Added backwards compatible salting to the hash.
  47. 15/11/11:
  48. Added comments.
  49. Added language to the top-level player data (needed for login).
  50. 11/11/11:
  51. First version.
  52. Functions:
  53. Public
  54. -
  55. Core:
  56. -
  57. Stock:
  58. -
  59. Static:
  60. -
  61. Inline:
  62. -
  63. API:
  64. -
  65. Callbacks:
  66. -
  67. Definitions:
  68. -
  69. Enums:
  70. -
  71. Macros:
  72. -
  73. Tags:
  74. -
  75. Variables:
  76. Global:
  77. -
  78. Static:
  79. -
  80. Commands:
  81. -
  82. Compile options:
  83. -
  84. Operators:
  85. -
  86. </remarks>
  87. \**--------------------------------------------------------------------------**/
  88. #if !defined MODE_NAME
  89. #error Please define "MODE_NAME" before including y_users.
  90. #endif
  91. #include <a_samp>
  92. forward OnPlayerLogin(playerid, uid);
  93. forward OnPlayerLogout(playerid, uid);
  94. //#if !defined HAS_USER_CALLBACKS
  95. // #define HAS_USER_CALLBACKS
  96. //#endif
  97. #include "internal\y_version"
  98. #include "y_text"
  99. #include "y_remote"
  100. #include "y_debug"
  101. #include "y_ini"
  102. #include "y_utils"
  103. #include "y_timers"
  104. #define YSIM_U_DISABLE
  105. #include "y_master"
  106. #define MAX_INDEX_LENGTH 8
  107. #include "internal\y_plugins"
  108. #include "internal\y_natives"
  109. #include "y_hooks"
  110. #if defined PP_ADLER32
  111. //#define MAX_PASSWORD_LENGTH 11
  112. #error Adler32 sucks!
  113. #elseif defined PP_MD5
  114. #if defined MD5_Hash
  115. #define MAX_PASSWORD_LENGTH 32
  116. #else
  117. #error Could not find MD5_Hash.
  118. #endif
  119. #elseif defined PP_SHA1
  120. #error SHA1 unsupported.
  121. #elseif defined PP_YSI
  122. #define MAX_PASSWORD_LENGTH 16
  123. #elseif defined PP_WP || defined PP_WHIRLPOOL
  124. #if defined _YSI_PLUGINS_WHIRLPOOL
  125. #define MAX_PASSWORD_LENGTH 128
  126. #else
  127. #error Could not find WP_Hash.
  128. #endif
  129. #else
  130. #error Default hash removed: See YSI topic for details.
  131. //#define PP_YSI
  132. //#define MAX_PASSWORD_LENGTH 16
  133. #endif
  134. //#define INDEX_DATA_LINE_LENGTH (MAX_INDEX_LENGTH + 1 + MAX_PLAYER_NAME + 1 + MAX_PASSWORD_LENGTH + 3 + 3 + 9 + 9)
  135. // MAX_INDEX_LENGTH - The player's ID.
  136. // 1 - Space.
  137. // MAX_PLAYER_NAME - The player's name.
  138. // 1 - Space.
  139. // MAX_PASSWORD_LENGTH - The password hash.
  140. // 1 - Space.
  141. // 2 - Language.
  142. // 1 - Space.
  143. // 8 - Free HEX bits.
  144. // 1 - Space.
  145. // 8 - Join timestamp.
  146. // 3 - Newline + Null.
  147. const
  148. INDEX_DATA_LINE_LENGTH = MAX_INDEX_LENGTH + 1 + MAX_PLAYER_NAME + 1 + MAX_PASSWORD_LENGTH + 1 + 2 + 1 + 8 + 1 + 8 + 3;
  149. #if !defined USER_FILE_PATH
  150. #if defined YSI_TESTS
  151. // Create a separate path for any test data so that we don't ruin any
  152. // live user data.
  153. #define USER_FILE_PATH "YSI/test_users/"
  154. #define USER_FILE_LENGTH 15
  155. #else
  156. #define USER_FILE_PATH "YSI/users/"
  157. #define USER_FILE_LENGTH 10
  158. #endif
  159. #endif
  160. #define OnUserData[%0](%1) @yU_%0(%1)
  161. #define PINI:%0(%1) forward OnUserData[%0](%1);public OnUserData[%0](%1)
  162. foreign Player_TryRegister(playerid, string:password[]);
  163. foreign Player_TryLogin(playerid, string:password[]);
  164. foreign Player_TryGroup(playerid, string:other[], string:password[]);
  165. foreign Player_ChangePassword(playerid, string:password[]);
  166. foreign Player_ForceGroup(playerid, string:other[]);
  167. foreign Player_ForceLogin(playerid);
  168. foreign Player_ChangeLanguage(playerid, string:code[]);
  169. #if defined USERS_USE_MYSQL
  170. #if _YSI_PLUGINS_MYSQL == 7
  171. #include "y_users/blueg7"
  172. #elseif _YSI_PLUGINS_MYSQL == 6
  173. #include "y_users/blueg6"
  174. #elseif _YSI_PLUGINS_MYSQL == 7
  175. #include "y_users/stricken"
  176. #else
  177. #error No MySQL plugin found.
  178. #endif
  179. #elseif defined USERS_USE_SQLITE
  180. #include "y_users/sqlite"
  181. #else
  182. #include "y_users/ini"
  183. #endif
  184. #if defined YSI_TESTS
  185. #include "y_testing"
  186. #include "y_users/tests"
  187. #endif
  188. #include "internal\y_grouprevert"